Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-8]: src/sys/dev Pull up following revision(s) (requested by mlels...
details: https://anonhg.NetBSD.org/src/rev/8153da56dd4f
branches: netbsd-8
changeset: 851002:8153da56dd4f
user: martin <martin%NetBSD.org@localhost>
date: Fri Sep 01 09:59:10 2017 +0000
description:
Pull up following revision(s) (requested by mlelstv in ticket #261):
sys/dev/sdmmc/ld_sdmmc.c: revision 1.32
sys/dev/sdmmc/ld_sdmmc.c: revision 1.33
sys/dev/sdmmc/ld_sdmmc.c: revision 1.34
sys/dev/sdmmc/sdmmc_mem.c: revision 1.62
sys/dev/i2o/ld_iop.c: revision 1.39
sys/dev/ld.c: revision 1.102
sys/dev/ld.c: revision 1.103
sys/dev/dksubr.c: revision 1.98
sys/dev/dksubr.c: revision 1.99
sys/dev/sdmmc/sdmmcvar.h: revision 1.29
sys/dev/ic/ld_nvme.c: revision 1.17
sys/dev/ldvar.h: revision 1.31
sys/dev/ldvar.h: revision 1.32
sys/dev/ic/ld_cac.c: revision 1.31
sys/dev/pci/ld_virtio.c: revision 1.16
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.
Defer sdmmc discard operations to the sdmmc task queue. Fixes a panic
introduced by ld.c r1.102.
validate length for discard operation and split operation when byte length
doesn't fit into 'int'.
make the sc_discard interface for the ld backend asynchronous and
signal completion through new callback lddiscardend. Use a standard
struct buf to pass disk address and range instead of two off_t values.
make lddiscard synchronous again. This is a requirement of the current
ffs discard code.
Initialize error also in the case where len=0, which just succeeds.
while here, assert that the len is indeed non-negative. this is already
confirmed by sys_fdiscard, but let's be sure.
reported by: GCC, but with different compile flags
diffstat:
sys/dev/dksubr.c | 43 ++++++++++++++++++---------
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 | 46 +++++++++++++++++++++++++++-
sys/dev/ldvar.h | 6 ++-
sys/dev/pci/ld_virtio.c | 6 +-
sys/dev/sdmmc/ld_sdmmc.c | 73 +++++++++++++++++++++++++++++++++++++++++-----
sys/dev/sdmmc/sdmmc_mem.c | 13 ++-----
sys/dev/sdmmc/sdmmcvar.h | 4 +-
10 files changed, 159 insertions(+), 51 deletions(-)
diffs (truncated from 518 to 300 lines):
diff -r 2a454baf9e11 -r 8153da56dd4f sys/dev/dksubr.c
--- a/sys/dev/dksubr.c Fri Sep 01 09:52:40 2017 +0000
+++ b/sys/dev/dksubr.c Fri Sep 01 09:59:10 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dksubr.c,v 1.97 2017/04/27 17:07:22 jdolecek Exp $ */
+/* $NetBSD: dksubr.c,v 1.97.2.1 2017/09/01 09:59:10 martin Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 1999, 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dksubr.c,v 1.97 2017/04/27 17:07:22 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dksubr.c,v 1.97.2.1 2017/09/01 09:59:10 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -497,7 +497,10 @@
const struct dkdriver *dkd = dksc->sc_dkdev.dk_driver;
unsigned secsize = dksc->sc_dkdev.dk_geom.dg_secsize;
struct buf tmp, *bp = &tmp;
- int error;
+ int maxsz;
+ int error = 0;
+
+ KASSERT(len >= 0);
DPRINTF_FOLLOW(("%s(%s, %p, 0x"PRIx64", %jd, %jd)\n", __func__,
dksc->sc_xname, dksc, (intmax_t)pos, (intmax_t)len));
@@ -507,22 +510,32 @@
return ENXIO;
}
- if (secsize == 0 || (pos % secsize) != 0)
+ if (secsize == 0 || (pos % secsize) != 0 || (len % secsize) != 0)
return EINVAL;
- /* enough data to please the bounds checking code */
- bp->b_dev = dev;
- bp->b_blkno = (daddr_t)(pos / secsize);
- bp->b_bcount = len;
- bp->b_flags = B_WRITE;
+ /* largest value that b_bcount can store */
+ maxsz = rounddown(INT_MAX, secsize);
+
+ while (len > 0) {
+ /* enough data to please the bounds checking code */
+ bp->b_dev = dev;
+ bp->b_blkno = (daddr_t)(pos / secsize);
+ bp->b_bcount = min(len, maxsz);
+ bp->b_flags = B_WRITE;
- error = dk_translate(dksc, bp);
- if (error >= 0)
- return error;
+ error = dk_translate(dksc, bp);
+ if (error >= 0)
+ break;
- error = dkd->d_discard(dksc->sc_dev,
- (off_t)bp->b_rawblkno * secsize,
- (off_t)bp->b_bcount);
+ error = dkd->d_discard(dksc->sc_dev,
+ (off_t)bp->b_rawblkno * secsize,
+ (off_t)bp->b_bcount);
+ if (error)
+ break;
+
+ pos += bp->b_bcount;
+ len -= bp->b_bcount;
+ }
return error;
}
diff -r 2a454baf9e11 -r 8153da56dd4f sys/dev/i2o/ld_iop.c
--- a/sys/dev/i2o/ld_iop.c Fri Sep 01 09:52:40 2017 +0000
+++ b/sys/dev/i2o/ld_iop.c Fri Sep 01 09:59:10 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ld_iop.c,v 1.37 2017/02/27 21:32:33 jdolecek Exp $ */
+/* $NetBSD: ld_iop.c,v 1.37.6.1 2017/09/01 09:59:10 martin 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.37 2017/02/27 21:32:33 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_iop.c,v 1.37.6.1 2017/09/01 09:59:10 martin 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 2a454baf9e11 -r 8153da56dd4f sys/dev/ic/ld_cac.c
--- a/sys/dev/ic/ld_cac.c Fri Sep 01 09:52:40 2017 +0000
+++ b/sys/dev/ic/ld_cac.c Fri Sep 01 09:59:10 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.30.8.1 2017/09/01 09:59:11 martin 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.30.8.1 2017/09/01 09:59:11 martin 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 2a454baf9e11 -r 8153da56dd4f sys/dev/ic/ld_nvme.c
--- a/sys/dev/ic/ld_nvme.c Fri Sep 01 09:52:40 2017 +0000
+++ b/sys/dev/ic/ld_nvme.c Fri Sep 01 09:59:10 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.16.2.1 2017/09/01 09:59:11 martin 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.16.2.1 2017/09/01 09:59:11 martin 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 2a454baf9e11 -r 8153da56dd4f sys/dev/ld.c
--- a/sys/dev/ld.c Fri Sep 01 09:52:40 2017 +0000
+++ b/sys/dev/ld.c Fri Sep 01 09:59:10 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.101.2.1 2017/09/01 09:59:10 martin 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.101.2.1 2017/09/01 09:59:10 martin 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,45 @@
ld_discard(device_t dev, off_t pos, off_t len)
{
struct ld_softc *sc = device_private(dev);
+ struct buf dbuf, *bp = &dbuf;
+ int error = 0;
+
+ KASSERT(len <= INT_MAX);
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);
+
+ buf_init(bp);
+ bp->b_vp = NULL;
+ bp->b_data = NULL;
+ bp->b_bufsize = 0;
+ bp->b_rawblkno = pos / sc->sc_secsize;
+ bp->b_bcount = len;
+ bp->b_flags = B_WRITE;
+ bp->b_cflags = BC_BUSY;
+
+ error = (*sc->sc_discard)(sc, bp);
+ if (error == 0)
+ error = biowait(bp);
+
+ buf_destroy(bp);
+
+ if ((sc->sc_flags & LDF_MPSAFE) == 0)
+ KERNEL_UNLOCK_ONE(curlwp);
+
+ return error;
+}
+
+void
+lddiscardend(struct ld_softc *sc, struct buf *bp)
+{
+
+ if (bp->b_error)
+ bp->b_resid = bp->b_bcount;
+ biodone(bp);
}
static int
diff -r 2a454baf9e11 -r 8153da56dd4f sys/dev/ldvar.h
--- a/sys/dev/ldvar.h Fri Sep 01 09:52:40 2017 +0000
+++ b/sys/dev/ldvar.h Fri Sep 01 09:59:10 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.30.2.1 2017/09/01 09:59:10 martin Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -61,18 +61,20 @@
int (*sc_dump)(struct ld_softc *, void *, int, int);
int (*sc_ioctl)(struct ld_softc *, u_long, void *, int32_t, bool);
int (*sc_start)(struct ld_softc *, struct buf *);
- int (*sc_discard)(struct ld_softc *, off_t, off_t);
+ int (*sc_discard)(struct ld_softc *, struct buf *);
};
/* sc_flags */
#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 *);
int ldbegindetach(struct ld_softc *, int);
void ldenddetach(struct ld_softc *);
void lddone(struct ld_softc *, struct buf *);
+void lddiscardend(struct ld_softc *, struct buf *);
#endif /* !_DEV_LDVAR_H_ */
diff -r 2a454baf9e11 -r 8153da56dd4f sys/dev/pci/ld_virtio.c
--- a/sys/dev/pci/ld_virtio.c Fri Sep 01 09:52:40 2017 +0000
+++ b/sys/dev/pci/ld_virtio.c Fri Sep 01 09:59:10 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.15.6.1 2017/09/01 09:59:11 martin 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.15.6.1 2017/09/01 09:59:11 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -345,7 +345,7 @@
ld->sc_dump = ld_virtio_dump;
Home |
Main Index |
Thread Index |
Old Index