linux/drivers/scsi
Linus Torvalds 8ca09d5fa3 cpumask: fix incorrect cpumask scanning result checks
It turns out that commit 596ff4a09b ("cpumask: re-introduce
constant-sized cpumask optimizations") exposed a number of cases of
drivers not checking the result of "cpumask_next()" and friends
correctly.

The documented correct check for "no more cpus in the cpumask" is to
check for the result being equal or larger than the number of possible
CPU ids, exactly _because_ we've always done those constant-sized
cpumask scans using a widened type before.  So the return value of a
cpumask scan should be checked with

	if (cpu >= nr_cpu_ids)
		...

because the cpumask scan did not necessarily stop exactly *at* that
maximum CPU id.

But a few cases ended up instead using checks like

	if (cpu == nr_cpumask_bits)
		...

which used that internal "widened" number of bits.  And that used to
work pretty much by accident (ok, in this case "by accident" is simply
because it matched the historical internal implementation of the cpumask
scanning, so it was more of a "intentionally using implementation
details rather than an accident").

But the extended constant-sized optimizations then did that internal
implementation differently, and now that code that did things wrong but
matched the old implementation no longer worked at all.

Which then causes subsequent odd problems due to using what ends up
being an invalid CPU ID.

Most of these cases require either unusual hardware or special uses to
hit, but the random.c one triggers quite easily.

All you really need is to have a sufficiently small CONFIG_NR_CPUS value
for the bit scanning optimization to be triggered, but not enough CPUs
to then actually fill that widened cpumask.  At that point, the cpumask
scanning will return the NR_CPUS constant, which is _not_ the same as
nr_cpumask_bits.

This just does the mindless fix with

   sed -i 's/== nr_cpumask_bits/>= nr_cpu_ids/'

to fix the incorrect uses.

The ones in the SCSI lpfc driver in particular could probably be fixed
more cleanly by just removing that repeated pattern entirely, but I am
not emptionally invested enough in that driver to care.

Reported-and-tested-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/lkml/481b19b5-83a0-4793-b4fd-194ad7b978c3@roeck-us.net/
Reported-and-tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/lkml/CAMuHMdUKo_Sf7TjKzcNDa8Ve+6QrK+P8nSQrSQ=6LTRmcBKNww@mail.gmail.com/
Reported-by: Vernon Yang <vernon2gm@gmail.com>
Link: https://lore.kernel.org/lkml/20230306160651.2016767-1-vernon2gm@gmail.com/
Cc: Yury Norov <yury.norov@gmail.com>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-03-06 12:15:13 -08:00
..
aacraid scsi: aacraid: Allocate cmd_priv with scsicmd 2023-02-08 18:49:48 -05:00
aic7xxx scsi: aic79xx: Use __ro_after_init explicitly 2022-09-15 22:01:24 -04:00
aic94xx scsi: aic94xx: Add missing check for dma_map_single() 2023-02-08 19:12:25 -05:00
arcmsr
arm scsi: arm: Move the SCSI pointer to private command data 2022-02-22 21:11:03 -05:00
be2iscsi scsi: iscsi: Remove iscsi_get_task back_lock requirement 2022-06-21 21:19:23 -04:00
bfa scsi: bfa: Replace one-element array with flexible-array member 2022-11-17 18:15:45 +00:00
bnx2fc scsi: bnx2fc: Avoid using get_cpu() in bnx2fc_cmd_alloc() 2022-05-16 21:26:50 -04:00
bnx2i scsi: iscsi: Fix session removal on shutdown 2022-06-21 21:14:54 -04:00
csiostor scsi: csiostor: Remove unused variable 'n' 2022-11-08 03:40:54 +00:00
cxgbi scsi: cxgbi: Remove unneeded version.h include 2023-02-21 22:00:51 -05:00
cxlflash - Daniel Verkamp has contributed a memfd series ("mm/memfd: add 2023-02-23 17:09:35 -08:00
device_handler SCSI misc on 20230222 2023-02-22 13:41:41 -08:00
elx scsi: elx: libefc_sli: Use "/*" for non-kernel-doc comment 2023-01-23 20:53:43 -05:00
esas2r scsi: esas2r: Introduce scsi_template_proc_dir() 2022-10-18 03:17:09 +00:00
fcoe SCSI misc on 20221213 2022-12-14 08:58:51 -08:00
fnic SCSI misc on 20220804 2022-08-04 19:47:37 -07:00
hisi_sas scsi: hisi_sas: Set a port invalid only if there are no devices attached when refreshing port id 2023-01-12 00:08:03 -05:00
ibmvscsi scsi: ibmvfc: Avoid path failures during live migration 2022-11-07 18:57:39 +00:00
ibmvscsi_tgt scsi: ibmvscsi_tgt: Fix repeated words in comment 2022-09-15 22:30:26 -04:00
isci scsi: isci: Fix typo in comment 2022-05-23 23:24:10 -04:00
libfc scsi: libfc: Include the correct header 2022-12-01 03:03:36 +00:00
libsas SCSI misc on 20230222 2023-02-22 13:41:41 -08:00
lpfc cpumask: fix incorrect cpumask scanning result checks 2023-03-06 12:15:13 -08:00
megaraid scsi: megaraid_sas: Add flexible array member for SGLs 2023-01-18 18:22:22 -05:00
mpi3mr SCSI misc on 20230303 2023-03-03 14:41:50 -08:00
mpt3sas SCSI misc on 20230222 2023-02-22 13:41:41 -08:00
mvsas scsi: mvsas: Use sas_task_find_rq() for tagging 2022-10-22 03:02:52 +00:00
pcmcia scsi: pcmcia: nsp_cs: Remove unused variable i 2022-10-27 02:15:46 +00:00
pm8001 scsi: pm8001: Use sysfs_emit() in show function callbacks 2023-01-11 21:53:34 -05:00
qedf scsi: qedf: Remove set but unused variable 'page' 2022-10-22 03:09:45 +00:00
qedi scsi: qedi: Remove unneeded version.h include 2023-02-21 22:00:51 -05:00
qla2xxx scsi: scsi_transport_fc: Add an additional flag to fc_host_fpin_rcv() 2023-02-21 18:03:29 -05:00
qla4xxx scsi: core: Change the return type of .eh_timed_out() 2022-10-22 03:25:59 +00:00
smartpqi scsi: smartpqi: Replace one-element array with flexible-array member 2023-02-08 19:03:43 -05:00
snic scsi: snic: Fix memory leak with using debugfs_lookup() 2023-02-08 18:49:59 -05:00
sym53c8xx_2 scsi: sym53c8xx_2: Remove redundant "with" 2022-06-21 21:41:19 -04:00
.gitignore
3w-9xxx.c scsi: 3w-9xxx: Avoid disabling device if failing to enable it 2022-09-06 22:22:24 -04:00
3w-9xxx.h
3w-sas.c scsi: 3w-sas: Replace 1-element arrays with flexible array members 2023-01-12 00:09:52 -05:00
3w-sas.h scsi: 3w-sas: Replace 1-element arrays with flexible array members 2023-01-12 00:09:52 -05:00
3w-xxxx.c scsi: 3w-xxxx: Replace one-element array with flexible-array member 2022-09-25 13:06:00 -04:00
3w-xxxx.h scsi: 3w-xxxx: Replace one-element array with flexible-array member 2022-09-25 13:06:00 -04:00
53c700.c scsi: 53c700: Stop clearing SCSI pointer fields 2022-02-22 21:11:03 -05:00
53c700.h
53c700.scr
53c700_d.h_shipped
a100u2w.c scsi: a100u2w: Fix a kernel-doc warning 2021-11-29 23:02:13 -05:00
a100u2w.h
a2091.c scsi: a2091: Convert m68k WD33C93 drivers to DMA API 2022-07-07 17:01:22 -04:00
a2091.h
a3000.c scsi: a3000: Convert m68k WD33C93 drivers to DMA API 2022-07-07 17:01:22 -04:00
a3000.h
a4000t.c
advansys.c scsi: advansys: Move the SCSI pointer to private command data 2022-02-22 21:11:03 -05:00
aha152x.c scsi: aha152x: Stop using struct scsi_pointer 2022-03-29 23:42:18 -04:00
aha152x.h
aha1542.c scsi: aha1542: Remove unneeded semicolon 2022-04-25 23:25:11 -04:00
aha1542.h
aha1740.c scsi: Remove drivers/scsi/scsi.h 2022-02-22 21:11:02 -05:00
aha1740.h
am53c974.c
atari_scsi.c scsi: NCR5380: Add SCp members to struct NCR5380_cmd 2022-02-22 21:11:03 -05:00
atp870u.c scsi: atp870u: Fix a kernel-doc warning 2021-11-29 23:02:13 -05:00
atp870u.h
BusLogic.c scsi: BusLogic: Remove variable 'adapter_count' 2022-11-08 03:01:12 +00:00
BusLogic.h
bvme6000_scsi.c
ch.c scsi: ch: Convert to scsi_execute_cmd() 2023-01-13 21:34:08 -05:00
constants.c
dc395x.c scsi: dc395x: Fix a missing check on list iterator 2022-04-26 08:51:56 -04:00
dc395x.h
dmx3191d.c scsi: NCR5380: Remove the NCR5380_CMD_SIZE macro 2022-02-22 21:11:03 -05:00
esp_scsi.c scsi: esp_scsi: Stop using the SCSI pointer 2022-02-22 21:11:04 -05:00
esp_scsi.h scsi: esp_scsi: Stop using the SCSI pointer 2022-02-22 21:11:04 -05:00
fdomain.c scsi: fdomain: Move the SCSI pointer to private command data 2022-02-22 21:11:04 -05:00
fdomain.h
fdomain_isa.c
fdomain_pci.c
FlashPoint.c scsi: FlashPoint: Remove redundant variable bm_int_st 2022-08-01 19:52:03 -04:00
g_NCR5380.c scsi: NCR5380: Add SCp members to struct NCR5380_cmd 2022-02-22 21:11:03 -05:00
gvp11.c scsi: gvp11.c: Fix DMA mask calculation error 2022-07-13 23:18:26 -04:00
gvp11.h
hosts.c scsi: core: Remove the /proc/scsi/${proc_name} directory earlier 2023-02-21 22:00:51 -05:00
hpsa.c scsi: hpsa: Fix allocation size for scsi_host_alloc() 2023-01-18 18:59:46 -05:00
hpsa.h
hpsa_cmd.h
hptiop.c scsi: hptiop: Use struct_size() helper in code related to struct hpt_iop_request_scsi_command 2022-09-25 13:02:23 -04:00
hptiop.h scsi: hptiop: Replace one-element array with flexible-array member in struct hpt_iop_request_ioctl_command() 2022-09-25 13:04:17 -04:00
imm.c scsi: imm: Move the SCSI pointer to private command data 2022-02-22 21:11:04 -05:00
imm.h scsi: imm: Move the SCSI pointer to private command data 2022-02-22 21:11:04 -05:00
initio.c scsi: initio: Remove redundant assignment to pointer scb 2022-08-31 23:39:57 -04:00
initio.h scsi: initio: Stop using the SCSI pointer 2022-02-22 21:11:05 -05:00
ipr.c SCSI misc on 20230303 2023-03-03 14:41:50 -08:00
ipr.h
ips.c scsi: ips: Replace kmap_atomic() with kmap_local_page() 2023-01-18 18:41:12 -05:00
ips.h
iscsi_boot_sysfs.c
iscsi_tcp.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2023-01-27 22:56:18 -08:00
iscsi_tcp.h scsi: iscsi: iscsi_tcp: Fix null-ptr-deref while calling getpeername() 2022-09-25 14:27:47 -04:00
jazz_esp.c
Kconfig scsi: core: Make SCSI_MOD depend on BLOCK for cleaner .config files 2022-09-25 12:46:59 -04:00
lasi700.c
libiscsi.c scsi: iscsi_tcp: Fix UAF during logout when accessing the shost ipaddress 2023-01-18 19:14:56 -05:00
libiscsi_tcp.c scsi: iscsi: Remove iscsi_get_task back_lock requirement 2022-06-21 21:19:23 -04:00
mac53c94.c scsi: mac53c94: Fix warning comparing pointer to 0 2022-04-25 23:23:05 -04:00
mac53c94.h scsi: mac53c94: Stop using struct scsi_pointer 2022-02-27 21:35:30 -05:00
mac_esp.c
mac_scsi.c scsi: NCR5380: Add SCp members to struct NCR5380_cmd 2022-02-22 21:11:03 -05:00
Makefile scsi: dpt_i2o: Remove obsolete driver 2022-06-27 22:56:21 -04:00
megaraid.c scsi: megaraid: Fix error check return value of register_chrdev() 2022-04-26 09:02:44 -04:00
megaraid.h scsi: megaraid: Stop using the SCSI pointer 2022-02-22 21:11:05 -05:00
mesh.c powerpc/powermac: Remove empty function note_scsi_host() 2022-06-26 10:29:44 +10:00
mesh.h scsi: mesh: Stop using struct scsi_pointer 2022-02-27 21:34:02 -05:00
mvme16x_scsi.c
mvme147.c scsi: wd33c93: Move the SCSI pointer to private command data 2022-02-22 21:11:07 -05:00
mvme147.h
mvumi.c scsi: mvumi: Replace 1-element arrays with flexible array members 2023-01-12 00:11:11 -05:00
mvumi.h scsi: mvumi: Replace 1-element arrays with flexible array members 2023-01-12 00:11:11 -05:00
myrb.c scsi: myrb: Fix up null pointer access on myrb_cleanup() 2022-05-23 23:24:10 -04:00
myrb.h
myrs.c scsi: myrs: Fix crash in error case 2022-01-25 00:09:41 -05:00
myrs.h
ncr53c8xx.c scsi: zalon: Stop using the SCSI pointer 2022-02-22 21:11:07 -05:00
ncr53c8xx.h scsi: zalon: Stop using the SCSI pointer 2022-02-22 21:11:07 -05:00
NCR5380.c scsi: NCR5380: Fix repeated words in comment 2022-11-08 02:57:01 +00:00
NCR5380.h scsi: NCR5380: Add SCp members to struct NCR5380_cmd 2022-02-22 21:11:03 -05:00
nsp32.c scsi: nsp32: Stop using the SCSI pointer 2022-02-22 21:11:06 -05:00
nsp32.h scsi: nsp32: Stop using the SCSI pointer 2022-02-22 21:11:06 -05:00
nsp32_debug.c
nsp32_io.h
pmcraid.c scsi: pmcraid: Fix missing resource cleanup in error case 2022-06-07 22:05:14 -04:00
pmcraid.h scsi: pmcraid: Remove the PMCRAID_PASSTHROUGH_IOCTL ioctl implementation 2022-03-29 23:32:26 -04:00
ppa.c scsi: ppa: Move the SCSI pointer to private command data 2022-02-22 21:11:06 -05:00
ppa.h
ps3rom.c
qla1280.c scsi: qla1280: Remove redundant variable 2022-05-19 20:26:21 -04:00
qla1280.h scsi: qla1280: Move the SCSI pointer to private command data 2022-02-22 21:11:06 -05:00
qlogicfas.c scsi: Remove drivers/scsi/scsi.h 2022-02-22 21:11:02 -05:00
qlogicfas408.c scsi: Remove drivers/scsi/scsi.h 2022-02-22 21:11:02 -05:00
qlogicfas408.h
qlogicpti.c scsi: qlogicpti: Fix dma_map_sg() check 2022-09-06 22:14:14 -04:00
qlogicpti.h
raid_class.c
script_asm.pl
scsi.c SCSI misc on 20230222 2023-02-22 13:41:41 -08:00
scsi_bsg.c scsi: bsg: Drop needless assignment in scsi_bsg_sg_io_fn() 2022-03-15 14:05:02 -04:00
scsi_common.c
scsi_debug.c Merge branch '6.2/scsi-queue' into 6.2/scsi-fixes 2022-12-30 16:29:34 +00:00
scsi_debugfs.c scsi: core: Remove struct scsi_request 2022-03-01 22:21:50 -05:00
scsi_debugfs.h
scsi_devinfo.c
scsi_dh.c
scsi_error.c Merge branch '6.2/scsi-queue' into 6.2/scsi-fixes 2022-12-30 16:29:34 +00:00
scsi_ioctl.c scsi: core: Convert to scsi_execute_cmd() 2023-01-13 21:34:09 -05:00
scsi_lib.c scsi: core: Extend struct scsi_exec_args 2023-02-21 22:00:51 -05:00
scsi_lib_dma.c
scsi_logging.c scsi: core: scsi_logging: Fix a BUG 2022-03-29 23:29:19 -04:00
scsi_logging.h
scsi_netlink.c
scsi_pm.c scsi: block: pm: Always set request queue runtime active in blk_post_runtime_resume() 2021-12-22 23:38:29 -05:00
scsi_priv.h scsi: core: Introduce a new list for SCSI proc directory entries 2022-10-18 03:17:09 +00:00
scsi_proc.c scsi: core: Introduce a new list for SCSI proc directory entries 2022-10-18 03:17:09 +00:00
scsi_sas_internal.h
scsi_scan.c SCSI misc on 20230222 2023-02-22 13:41:41 -08:00
scsi_sysctl.c
scsi_sysfs.c Driver core changes for 6.3-rc1 2023-02-24 12:58:55 -08:00
scsi_trace.c
scsi_transport_api.h
scsi_transport_fc.c scsi: scsi_transport_fc: Add an additional flag to fc_host_fpin_rcv() 2023-02-21 18:03:29 -05:00
scsi_transport_iscsi.c Merge branch '6.2/scsi-queue' into 6.2/scsi-fixes 2022-12-30 16:29:34 +00:00
scsi_transport_sas.c scsi: scsi_transport_sas: Fix error handling in sas_phy_add() 2022-11-08 01:52:52 +00:00
scsi_transport_spi.c scsi: spi: Convert to scsi_execute_cmd() 2023-01-13 21:34:09 -05:00
scsi_transport_srp.c scsi: core: Change the return type of .eh_timed_out() 2022-10-22 03:25:59 +00:00
scsicam.c scsicam: Fix use of page cache 2022-05-08 14:28:18 -04:00
sd.c SCSI misc on 20230303 2023-03-03 14:41:50 -08:00
sd.h scsi: sd: Revert "Rework asynchronous resume support" 2022-08-22 22:45:25 -04:00
sd_dif.c scsi: sd: Update DIX config every time sd_revalidate_disk() is called 2023-02-21 22:00:32 -05:00
sd_trace.h scsi: sd: sd_zbc: Trace zone append emulation 2022-12-01 03:13:55 +00:00
sd_zbc.c scsi: zbc: Convert to scsi_execute_cmd() 2023-01-13 21:34:09 -05:00
sense_codes.h
ses.c scsi: ses: Don't attach if enclosure has no components 2023-02-21 17:44:06 -05:00
sg.c mm: replace vma->vm_flags direct modifications with modifier calls 2023-02-09 16:51:39 -08:00
sgiwd93.c scsi: wd33c93: Move the SCSI pointer to private command data 2022-02-22 21:11:07 -05:00
sim710.c
sni_53c710.c
sr.c scsi: sr: Convert to scsi_execute_cmd() 2023-01-13 21:34:09 -05:00
sr.h sr: implement ->free_disk to simplify refcounting 2022-03-08 19:40:01 -07:00
sr_ioctl.c scsi: sr: Convert to scsi_execute_cmd() 2023-01-13 21:34:09 -05:00
sr_vendor.c scsi: sr: Don't use GFP_DMA 2021-12-22 23:41:13 -05:00
st.c SCSI misc on 20221007 2022-10-07 12:33:18 -07:00
st.h scsi: don't use disk->private_data to find the scsi_driver 2022-03-08 19:40:00 -07:00
st_options.h
stex.c scsi: stex: Properly zero out the passthrough command structure 2022-09-25 14:15:03 -04:00
storvsc_drv.c hyperv-next for v6.3. 2023-02-21 16:59:23 -08:00
sun3_scsi.c scsi: NCR5380: Add SCp members to struct NCR5380_cmd 2022-02-22 21:11:03 -05:00
sun3_scsi_vme.c
sun3x_esp.c
sun_esp.c
virtio_scsi.c virtio,vhost,vdpa: features, fixes 2023-02-25 11:48:02 -08:00
vmw_pvscsi.c scsi: vmw_pvscsi: No need to clear memory after a dma_alloc_coherent() call 2022-04-06 23:01:54 -04:00
vmw_pvscsi.h scsi: vmw_pvscsi: Expand vcpuHint to 16 bits 2022-06-07 21:30:56 -04:00
wd33c93.c scsi: wd33c93: Remove dead code related to the long-gone config WD33C93_PIO 2022-09-25 13:29:53 -04:00
wd33c93.h scsi: wd33c93: Remove dead code related to the long-gone config WD33C93_PIO 2022-09-25 13:29:53 -04:00
wd719x.c scsi: wd719x: Return proper error code when dma_set_mask() fails 2022-03-01 23:56:28 -05:00
wd719x.h scsi: wd719x: Stop using the SCSI pointer 2022-02-22 21:11:07 -05:00
xen-scsifront.c xen: make remove callback of xen driver void returned 2022-12-15 16:06:10 +01:00
zalon.c scsi: zalon: Stop using the SCSI pointer 2022-02-22 21:11:07 -05:00
zorro7xx.c scsi: zorro7xx: Fix a resource leak in zorro7xx_remove_one() 2022-03-30 00:05:42 -04:00
zorro_esp.c