Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-6-1]: src/sys/miscfs/specfs Pull up following revision(s) (reques...



details:   https://anonhg.NetBSD.org/src/rev/e2fdb2c9d636
branches:  netbsd-6-1
changeset: 776131:e2fdb2c9d636
user:      snj <snj%NetBSD.org@localhost>
date:      Tue May 10 23:14:45 2016 +0000

description:
Pull up following revision(s) (requested by hannken in ticket #1376):
        sys/miscfs/specfs/spec_vnops.c: revisions 1.161, 1.162 via patch
Whhen spec_strategy() extracts v_rdev take care to avoid a
race with spec_revoke.
Fixes PR kern/50467 Panic from disconnecting phone while reading its contents
--
Avoid a race with spec_revoke for the assertion too.
Final fix for PR kern/50467 Panic from disconnecting phone while reading
its contents

diffstat:

 sys/miscfs/specfs/spec_vnops.c |  45 +++++++++++++++++++++++++++++------------
 1 files changed, 32 insertions(+), 13 deletions(-)

diffs (74 lines):

diff -r 7f1cc9f3b531 -r e2fdb2c9d636 sys/miscfs/specfs/spec_vnops.c
--- a/sys/miscfs/specfs/spec_vnops.c    Sun May 08 21:59:43 2016 +0000
+++ b/sys/miscfs/specfs/spec_vnops.c    Tue May 10 23:14:45 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: spec_vnops.c,v 1.134.8.1 2012/05/07 03:01:14 riz Exp $ */
+/*     $NetBSD: spec_vnops.c,v 1.134.8.1.6.1 2016/05/10 23:14:45 snj Exp $     */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.134.8.1 2012/05/07 03:01:14 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.134.8.1.6.1 2016/05/10 23:14:45 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -886,25 +886,44 @@
        } */ *ap = v;
        struct vnode *vp = ap->a_vp;
        struct buf *bp = ap->a_bp;
+       dev_t dev;
        int error;
 
-       KASSERT(vp == vp->v_specnode->sn_dev->sd_bdevvp);
+       dev = NODEV;
+
+       /*
+        * Extract all the info we need from the vnode, taking care to
+        * avoid a race with VOP_REVOKE().
+        */
 
-       error = 0;
-       bp->b_dev = vp->v_rdev;
+       mutex_enter(vp->v_interlock);
+       if ((vp->v_iflag & VI_XLOCK) == 0 && vp->v_specnode != NULL) {
+               KASSERT(vp == vp->v_specnode->sn_dev->sd_bdevvp);
+               dev = vp->v_rdev;
+       }
+       mutex_exit(vp->v_interlock);
 
-       if (!(bp->b_flags & B_READ))
+       if (dev == NODEV) {
+               error = ENXIO;
+               goto out;
+       }
+       bp->b_dev = dev;
+
+       if (!(bp->b_flags & B_READ)) {
                error = fscow_run(bp, false);
-
-       if (error) {
-               bp->b_error = error;
-               biodone(bp);
-               return (error);
+               if (error)
+                       goto out;
        }
-
        bdev_strategy(bp);
 
-       return (0);
+       return 0;
+
+out:
+       bp->b_error = error;
+       bp->b_resid = bp->b_bcount;
+       biodone(bp);
+
+       return error;
 }
 
 int



Home | Main Index | Thread Index | Old Index