Source-Changes-HG archive

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

[src/trunk]: src/sys/dev While ld(4) is MP safe, many backends are not.



details:   https://anonhg.NetBSD.org/src/rev/384028f0c416
branches:  trunk
changeset: 355675:384028f0c416
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Wed Aug 09 16:44:39 2017 +0000

description:
While ld(4) is MP safe, many backends are not.

Add a flag for backends that are MP safe. Take KERNEL_LOCK when calling
into a backend that doesn't have the flag set. Do the same for the
discard routine.

Fixes PR 52462.

diffstat:

 sys/dev/i2o/ld_iop.c     |   7 ++++---
 sys/dev/ic/ld_cac.c      |   6 +++---
 sys/dev/ic/ld_nvme.c     |   6 +++---
 sys/dev/ld.c             |  23 ++++++++++++++++++++---
 sys/dev/ldvar.h          |   3 ++-
 sys/dev/pci/ld_virtio.c  |   6 +++---
 sys/dev/sdmmc/ld_sdmmc.c |   6 +++---
 7 files changed, 38 insertions(+), 19 deletions(-)

diffs (222 lines):

diff -r 3d7f490470bf -r 384028f0c416 sys/dev/i2o/ld_iop.c
--- a/sys/dev/i2o/ld_iop.c      Wed Aug 09 16:09:16 2017 +0000
+++ b/sys/dev/i2o/ld_iop.c      Wed Aug 09 16:44:39 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ld_iop.c,v 1.38 2017/08/09 16:09:16 mlelstv Exp $      */
+/*     $NetBSD: ld_iop.c,v 1.39 2017/08/09 16:44:39 mlelstv Exp $      */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_iop.c,v 1.38 2017/08/09 16:09:16 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_iop.c,v 1.39 2017/08/09 16:44:39 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -171,6 +171,7 @@
        ld->sc_dump = ld_iop_dump;
        ld->sc_ioctl = ld_iop_ioctl;
        ld->sc_start = ld_iop_start;
+       ld->sc_flags = LDF_MPSAFE;
 
        /* Say what the device is. */
        printf(":");
@@ -221,7 +222,7 @@
 
        if ((le32toh(param.p.bdi.capabilities) & I2O_RBS_CAP_REMOVABLE_MEDIA)
            != 0) {
-               /* ld->sc_flags = LDF_REMOVABLE; */
+               /* ld->sc_flags |= LDF_REMOVABLE; */
                fixedstr = "removable";
                enable = 0;
        } else
diff -r 3d7f490470bf -r 384028f0c416 sys/dev/ic/ld_cac.c
--- a/sys/dev/ic/ld_cac.c       Wed Aug 09 16:09:16 2017 +0000
+++ b/sys/dev/ic/ld_cac.c       Wed Aug 09 16:44:39 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ld_cac.c,v 1.30 2016/09/27 03:33:32 pgoyette Exp $     */
+/*     $NetBSD: ld_cac.c,v 1.31 2017/08/09 16:44:40 mlelstv Exp $      */
 
 /*-
  * Copyright (c) 2000, 2006 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_cac.c,v 1.30 2016/09/27 03:33:32 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_cac.c,v 1.31 2017/08/09 16:44:40 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -131,7 +131,7 @@
        aprint_normal(": %s array\n", type);
 
        /* XXX We should verify this... */
-       ld->sc_flags = LDF_ENABLED;
+       ld->sc_flags = LDF_ENABLED | LDF_MPSAFE;
        ldattach(ld, BUFQ_DISK_DEFAULT_STRAT);
 }
 
diff -r 3d7f490470bf -r 384028f0c416 sys/dev/ic/ld_nvme.c
--- a/sys/dev/ic/ld_nvme.c      Wed Aug 09 16:09:16 2017 +0000
+++ b/sys/dev/ic/ld_nvme.c      Wed Aug 09 16:44:39 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ld_nvme.c,v 1.16 2017/04/27 17:07:22 jdolecek Exp $    */
+/*     $NetBSD: ld_nvme.c,v 1.17 2017/08/09 16:44:40 mlelstv Exp $     */
 
 /*-
  * Copyright (C) 2016 NONAKA Kimihiro <nonaka%netbsd.org@localhost>
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_nvme.c,v 1.16 2017/04/27 17:07:22 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_nvme.c,v 1.17 2017/08/09 16:44:40 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -128,7 +128,7 @@
        ld->sc_start = ld_nvme_start;
        ld->sc_dump = ld_nvme_dump;
        ld->sc_ioctl = ld_nvme_ioctl;
-       ld->sc_flags = LDF_ENABLED | LDF_NO_RND;
+       ld->sc_flags = LDF_ENABLED | LDF_NO_RND | LDF_MPSAFE;
        ldattach(ld, "fcfs");
 }
 
diff -r 3d7f490470bf -r 384028f0c416 sys/dev/ld.c
--- a/sys/dev/ld.c      Wed Aug 09 16:09:16 2017 +0000
+++ b/sys/dev/ld.c      Wed Aug 09 16:44:39 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ld.c,v 1.101 2017/04/27 17:07:22 jdolecek Exp $        */
+/*     $NetBSD: ld.c,v 1.102 2017/08/09 16:44:39 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.101 2017/04/27 17:07:22 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.102 2017/08/09 16:44:39 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -419,6 +419,9 @@
        if (sc->sc_queuecnt >= sc->sc_maxqueuecnt)
                return EAGAIN;
 
+       if ((sc->sc_flags & LDF_MPSAFE) == 0)
+               KERNEL_LOCK(1, curlwp);
+
        mutex_enter(&sc->sc_mutex);
 
        if (sc->sc_queuecnt >= sc->sc_maxqueuecnt)
@@ -431,6 +434,9 @@
 
        mutex_exit(&sc->sc_mutex);
 
+       if ((sc->sc_flags & LDF_MPSAFE) == 0)
+               KERNEL_UNLOCK_ONE(curlwp);
+
        return error;
 }
 
@@ -589,11 +595,22 @@
 ld_discard(device_t dev, off_t pos, off_t len)
 {
        struct ld_softc *sc = device_private(dev);
+       int rc;
 
        if (sc->sc_discard == NULL)
                return (ENODEV);
 
-       return (*sc->sc_discard)(sc, pos, len);
+       if ((sc->sc_flags & LDF_MPSAFE) == 0)
+               KERNEL_LOCK(1, curlwp);
+       mutex_enter(&sc->sc_mutex);
+
+       rc = (*sc->sc_discard)(sc, pos, len);
+
+       mutex_exit(&sc->sc_mutex);
+       if ((sc->sc_flags & LDF_MPSAFE) == 0)
+               KERNEL_UNLOCK_ONE(curlwp);
+
+       return rc;
 }
 
 static int
diff -r 3d7f490470bf -r 384028f0c416 sys/dev/ldvar.h
--- a/sys/dev/ldvar.h   Wed Aug 09 16:09:16 2017 +0000
+++ b/sys/dev/ldvar.h   Wed Aug 09 16:44:39 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ldvar.h,v 1.30 2017/04/27 17:07:22 jdolecek Exp $      */
+/*     $NetBSD: ldvar.h,v 1.31 2017/08/09 16:44:39 mlelstv Exp $       */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -68,6 +68,7 @@
 #define        LDF_ENABLED     0x001           /* device enabled */
 #define        LDF_DRAIN       0x020           /* maxqueuecnt has changed; drain */
 #define        LDF_NO_RND      0x040           /* do not attach rnd source */
+#define        LDF_MPSAFE      0x080           /* backend is MPSAFE */
 
 int    ldadjqparam(struct ld_softc *, int);
 void   ldattach(struct ld_softc *, const char *);
diff -r 3d7f490470bf -r 384028f0c416 sys/dev/pci/ld_virtio.c
--- a/sys/dev/pci/ld_virtio.c   Wed Aug 09 16:09:16 2017 +0000
+++ b/sys/dev/pci/ld_virtio.c   Wed Aug 09 16:44:39 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ld_virtio.c,v 1.15 2017/03/25 18:02:06 jdolecek Exp $  */
+/*     $NetBSD: ld_virtio.c,v 1.16 2017/08/09 16:44:40 mlelstv Exp $   */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.15 2017/03/25 18:02:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.16 2017/08/09 16:44:40 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -345,7 +345,7 @@
        ld->sc_dump = ld_virtio_dump;
        ld->sc_start = ld_virtio_start;
 
-       ld->sc_flags = LDF_ENABLED;
+       ld->sc_flags = LDF_ENABLED | LDF_MPSAFE;
        ldattach(ld, BUFQ_DISK_DEFAULT_STRAT);
 
        return;
diff -r 3d7f490470bf -r 384028f0c416 sys/dev/sdmmc/ld_sdmmc.c
--- a/sys/dev/sdmmc/ld_sdmmc.c  Wed Aug 09 16:09:16 2017 +0000
+++ b/sys/dev/sdmmc/ld_sdmmc.c  Wed Aug 09 16:44:39 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ld_sdmmc.c,v 1.31 2017/07/16 17:11:46 jmcneill Exp $   */
+/*     $NetBSD: ld_sdmmc.c,v 1.32 2017/08/09 16:44:40 mlelstv Exp $    */
 
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v 1.31 2017/07/16 17:11:46 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v 1.32 2017/08/09 16:44:40 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -144,7 +144,7 @@
        sc->sc_hwunit = 0;      /* always 0? */
        sc->sc_sf = sa->sf;
 
-       ld->sc_flags = LDF_ENABLED;
+       ld->sc_flags = LDF_ENABLED | LDF_MPSAFE;
        ld->sc_secperunit = sc->sc_sf->csd.capacity;
        ld->sc_secsize = SDMMC_SECTOR_SIZE;
        ld->sc_maxxfer = MAXPHYS;



Home | Main Index | Thread Index | Old Index