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.
This commit is contained in:
parent
fd946ab215
commit
5b68a5ee6d
|
@ -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 self, void *aux)
|
|||
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 self, void *aux)
|
|||
|
||||
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
|
||||
|
|
|
@ -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 self, void *aux)
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
@ -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 self, void *aux)
|
|||
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");
|
||||
}
|
||||
|
||||
|
|
23
sys/dev/ld.c
23
sys/dev/ld.c
|
@ -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 *bp)
|
|||
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 *bp)
|
|||
|
||||
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
|
||||
|
|
|
@ -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 *);
|
||||
|
|
|
@ -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_t self, void *aux)
|
|||
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;
|
||||
|
|
|
@ -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_t self, void *aux)
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue