From e6aae7e6820f4defd89a810052e3678a2230a5ca Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Tue, 21 Dec 2021 20:36:56 +0000 Subject: [PATCH] scsi(4): Take kernel lock around entry into autoconf. This code paths is entered by kthreads marked MP-safe, not just from autoconf. I'm not sure this is sufficient -- it's not clear to me whether anything prevents concurrently scanning the same target. Someone with a better understanding of scsi(4) locking will have to audit this. (For example, maybe it is guaranteed only to happen only either (a) in autoconf, or (b) in a thread that doesn't start until autoconf is done. But I don't know.) --- sys/dev/scsipi/scsiconf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sys/dev/scsipi/scsiconf.c b/sys/dev/scsipi/scsiconf.c index 943c6c936a81..ae84256ccd17 100644 --- a/sys/dev/scsipi/scsiconf.c +++ b/sys/dev/scsipi/scsiconf.c @@ -1012,6 +1012,7 @@ scsi_probe_device(struct scsibus_softc *sc, int target, int lun) locs[SCSIBUSCF_TARGET] = target; locs[SCSIBUSCF_LUN] = lun; + KERNEL_LOCK(1, NULL); if ((cf = config_search(sc->sc_dev, &sa, CFARGS(.submatch = config_stdsubmatch, .locators = locs))) != NULL) { @@ -1034,9 +1035,11 @@ scsi_probe_device(struct scsibus_softc *sc, int target, int lun) */ config_attach(sc->sc_dev, cf, &sa, scsibusprint, CFARGS(.locators = locs)); + KERNEL_UNLOCK_ONE(NULL); } else { scsibusprint(&sa, device_xname(sc->sc_dev)); aprint_normal(" not configured\n"); + KERNEL_UNLOCK_ONE(NULL); goto bad; } -- 2.33.0