Module Name:    src
Committed By:   mlelstv
Date:           Wed Aug  9 16:44:40 UTC 2017

Modified Files:
        src/sys/dev: ld.c ldvar.h
        src/sys/dev/i2o: ld_iop.c
        src/sys/dev/ic: ld_cac.c ld_nvme.c
        src/sys/dev/pci: ld_virtio.c
        src/sys/dev/sdmmc: ld_sdmmc.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/dev/ld.c
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/ldvar.h
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/i2o/ld_iop.c
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/ic/ld_cac.c
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/ic/ld_nvme.c
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/pci/ld_virtio.c
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/sdmmc/ld_sdmmc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ld.c
diff -u src/sys/dev/ld.c:1.101 src/sys/dev/ld.c:1.102
--- src/sys/dev/ld.c:1.101	Thu Apr 27 17:07:22 2017
+++ src/sys/dev/ld.c	Wed Aug  9 16:44:39 2017
@@ -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 @@ ld_diskstart(device_t dev, struct buf *b
 	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 @@ ld_diskstart(device_t dev, struct buf *b
 
 	mutex_exit(&sc->sc_mutex);
 
+	if ((sc->sc_flags & LDF_MPSAFE) == 0)
+		KERNEL_UNLOCK_ONE(curlwp);
+
 	return error;
 }
 
@@ -589,11 +595,22 @@ static int
 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

Index: src/sys/dev/ldvar.h
diff -u src/sys/dev/ldvar.h:1.30 src/sys/dev/ldvar.h:1.31
--- src/sys/dev/ldvar.h:1.30	Thu Apr 27 17:07:22 2017
+++ src/sys/dev/ldvar.h	Wed Aug  9 16:44:39 2017
@@ -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 @@ struct ld_softc {
 #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 *);

Index: src/sys/dev/i2o/ld_iop.c
diff -u src/sys/dev/i2o/ld_iop.c:1.38 src/sys/dev/i2o/ld_iop.c:1.39
--- src/sys/dev/i2o/ld_iop.c:1.38	Wed Aug  9 16:09:16 2017
+++ src/sys/dev/i2o/ld_iop.c	Wed Aug  9 16:44:39 2017
@@ -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_iop_attach(device_t parent, device_t 
 	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 @@ ld_iop_attach(device_t parent, device_t 
 
 	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

Index: src/sys/dev/ic/ld_cac.c
diff -u src/sys/dev/ic/ld_cac.c:1.30 src/sys/dev/ic/ld_cac.c:1.31
--- src/sys/dev/ic/ld_cac.c:1.30	Tue Sep 27 03:33:32 2016
+++ src/sys/dev/ic/ld_cac.c	Wed Aug  9 16:44:40 2017
@@ -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 @@ ld_cac_attach(device_t parent, device_t 
 	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);
 }
 

Index: src/sys/dev/ic/ld_nvme.c
diff -u src/sys/dev/ic/ld_nvme.c:1.16 src/sys/dev/ic/ld_nvme.c:1.17
--- src/sys/dev/ic/ld_nvme.c:1.16	Thu Apr 27 17:07:22 2017
+++ src/sys/dev/ic/ld_nvme.c	Wed Aug  9 16:44:40 2017
@@ -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 <non...@netbsd.org>
@@ -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_nvme_attach(device_t parent, device_t
 	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");
 }
 

Index: src/sys/dev/pci/ld_virtio.c
diff -u src/sys/dev/pci/ld_virtio.c:1.15 src/sys/dev/pci/ld_virtio.c:1.16
--- src/sys/dev/pci/ld_virtio.c:1.15	Sat Mar 25 18:02:06 2017
+++ src/sys/dev/pci/ld_virtio.c	Wed Aug  9 16:44:40 2017
@@ -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_virtio_attach(device_t parent, device
 	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;

Index: src/sys/dev/sdmmc/ld_sdmmc.c
diff -u src/sys/dev/sdmmc/ld_sdmmc.c:1.31 src/sys/dev/sdmmc/ld_sdmmc.c:1.32
--- src/sys/dev/sdmmc/ld_sdmmc.c:1.31	Sun Jul 16 17:11:46 2017
+++ src/sys/dev/sdmmc/ld_sdmmc.c	Wed Aug  9 16:44:40 2017
@@ -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 @@ ld_sdmmc_attach(device_t parent, device_
 	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;

Reply via email to