linux-stable/drivers
Sumanth Korikkar 4666f003af mm/memory_hotplug: add missing mem_hotplug_lock
[ Upstream commit 001002e737 ]

From Documentation/core-api/memory-hotplug.rst:
When adding/removing/onlining/offlining memory or adding/removing
heterogeneous/device memory, we should always hold the mem_hotplug_lock
in write mode to serialise memory hotplug (e.g. access to global/zone
variables).

mhp_(de)init_memmap_on_memory() functions can change zone stats and
struct page content, but they are currently called w/o the
mem_hotplug_lock.

When memory block is being offlined and when kmemleak goes through each
populated zone, the following theoretical race conditions could occur:
CPU 0:					     | CPU 1:
memory_offline()			     |
-> offline_pages()			     |
	-> mem_hotplug_begin()		     |
	   ...				     |
	-> mem_hotplug_done()		     |
					     | kmemleak_scan()
					     | -> get_online_mems()
					     |    ...
-> mhp_deinit_memmap_on_memory()	     |
  [not protected by mem_hotplug_begin/done()]|
  Marks memory section as offline,	     |   Retrieves zone_start_pfn
  poisons vmemmap struct pages and updates   |   and struct page members.
  the zone related data			     |
   					     |    ...
   					     | -> put_online_mems()

Fix this by ensuring mem_hotplug_lock is taken before performing
mhp_init_memmap_on_memory().  Also ensure that
mhp_deinit_memmap_on_memory() holds the lock.

online/offline_pages() are currently only called from
memory_block_online/offline(), so it is safe to move the locking there.

Link: https://lkml.kernel.org/r/20231120145354.308999-2-sumanthk@linux.ibm.com
Fixes: a08a2ae346 ("mm,memory_hotplug: allocate memmap from the added memory range")
Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: kernel test robot <lkp@intel.com>
Cc: <stable@vger.kernel.org>	[5.15+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-10 17:10:33 +01:00
..
accessibility
acpi iommu: Avoid more races around device probe 2023-12-13 18:39:17 +01:00
amba
android binder: fix memory leaks of spam and pending work 2023-12-13 18:39:22 +01:00
ata scsi: sd: Fix system start for ATA devices 2023-12-08 08:51:14 +01:00
atm atm: solos-pci: Fix potential deadlock on &tx_queue_lock 2023-12-20 17:00:16 +01:00
auxdisplay auxdisplay: hd44780: move cursor home after clear display command 2023-12-08 08:51:16 +01:00
base mm/memory_hotplug: add missing mem_hotplug_lock 2024-01-10 17:10:33 +01:00
bcma
block loop: deprecate autoloading callback loop_probe() 2024-01-01 12:39:09 +00:00
bluetooth Bluetooth: Fix deadlock in vhci_send_frame 2024-01-01 12:38:57 +00:00
bus bus: ti-sysc: Flush posted write only after srst_udelay 2024-01-01 12:39:07 +00:00
cdrom
char hwrng: geode - fix accessing registers 2023-11-20 11:52:04 +01:00
clk clk: visconti: Fix undefined behavior bug in struct visconti_pll_provider 2023-11-28 17:07:16 +00:00
clocksource clocksource/drivers/timer-atmel-tcb: Fix initialization on SAM9 hardware 2023-11-28 17:06:55 +00:00
comedi
connector
counter counter: microchip-tcb-capture: Fix the use of internal GCLK logic 2023-10-19 23:08:58 +02:00
cpufreq cpufreq: imx6q: Don't disable 792 Mhz OPP unnecessarily 2023-12-08 08:51:19 +01:00
cpuidle
crypto crypto: hisilicon/qm - prevent soft lockup in receive loop 2023-11-28 17:07:00 +00:00
cxl cxl/port: Fix NULL pointer access in devm_cxl_add_port() 2023-11-28 17:07:23 +00:00
dax
dca
devfreq PM / devfreq: rockchip-dfi: Make pmu regmap mandatory 2023-11-20 11:51:54 +01:00
dio
dma dmaengine: stm32-dma: avoid bitfield overflow assertion 2023-12-20 17:00:25 +01:00
dma-buf dma-buf: fix check in dma_resv_add_fence 2023-12-08 08:51:15 +01:00
edac
eisa
extcon
firewire scsi: Change SCSI device boolean fields to single bit flags 2023-12-08 08:51:14 +01:00
firmware firmware: arm_scmi: Fix frequency truncation by promoting multiplier type 2024-01-10 17:10:32 +01:00
fpga
fsi
gnss
gpio gpio: dwapb: mask/unmask IRQ when disable/enale it 2024-01-01 12:39:07 +00:00
gpu drm/i915/dp: Fix passing the correct DPCD_REV for drm_dp_set_phy_test_pattern 2024-01-10 17:10:22 +01:00
greybus
hid HID: i2c-hid: Add IDEA5002 to i2c_hid_acpi_blacklist[] 2024-01-01 12:38:53 +00:00
hsi
hte hte: tegra: Fix missing error code in tegra_hte_test_probe() 2023-11-20 11:51:58 +01:00
hv
hwmon hwmon: (nzxt-kraken2) Fix error handling path in kraken2_probe() 2023-12-13 18:39:14 +01:00
hwspinlock hwspinlock: qcom: add missing regmap config for SFPB MMIO implementation 2023-09-19 12:28:05 +02:00
hwtracing hwtracing: hisi_ptt: Add dummy callback pmu::read() 2023-12-13 18:39:22 +01:00
i2c i2c: aspeed: Handle the coalesced stop conditions with the start conditions. 2024-01-01 12:38:59 +00:00
i3c i3c: master: svc: fix random hot join failure since timeout error 2023-11-28 17:07:17 +00:00
idle intel_idle: add Emerald Rapids Xeon support 2023-10-10 22:00:44 +02:00
iio iio: imu: adis16475: add spi_device_id table 2024-01-05 15:18:37 +01:00
infiniband RDMA/irdma: Avoid free the non-cqp_request scratch 2023-12-13 18:39:15 +01:00
input Input: soc_button_array - add mapping for airplane mode button 2024-01-01 12:39:04 +00:00
interconnect interconnect: qcom: sm8250: Enable sync_state 2024-01-01 12:39:00 +00:00
iommu iommu: Avoid more races around device probe 2023-12-13 18:39:17 +01:00
ipack
irqchip irqchip/stm32-exti: add missing DT IRQ flag translation 2023-11-08 14:10:57 +01:00
isdn
leds leds: trigger: ledtrig-cpu:: Fix 'output may be truncated' issue for 'cpu' 2023-11-20 11:52:08 +01:00
macintosh
mailbox mailbox: qcom-ipcc: fix incorrect num_chans counting 2023-09-19 12:27:58 +02:00
mcb mcb: fix error handling for different scenarios when parsing 2023-11-28 17:07:13 +00:00
md dm-integrity: don't modify bio's immutable bio_vec in integrity_metadata() 2024-01-01 12:39:07 +00:00
media media: qcom: camss: Fix set CSI2_RX_CFG1_VC_MODE when VC is greater than 3 2024-01-10 17:10:31 +01:00
memory
memstick
message
mfd mfd: qcom-spmi-pmic: Fix revid implementation 2023-11-28 17:07:12 +00:00
misc misc: mei: client.c: fix problem of return '-EOVERFLOW' in mei_cl_write 2023-12-13 18:39:23 +01:00
mmc mmc: sdhci-sprd: Fix vqmmc not shutting down after the card was pulled 2023-12-08 08:51:19 +01:00
most
mtd mtd: cfi_cmdset_0001: Byte swap OTP info 2023-11-28 17:07:14 +00:00
mux
net dpaa2-eth: recycle the RX buffer only after all processing done 2024-01-10 17:10:32 +01:00
nfc
ntb
nubus
nvdimm nd_btt: Make BTT lanes preemptible 2023-11-20 11:52:05 +01:00
nvme nvme-pci: fix sleeping function called from interrupt context 2024-01-01 12:38:59 +00:00
nvmem nvmem: imx: correct nregs for i.MX6UL 2023-11-02 09:35:31 +01:00
of of: dynamic: Fix of_reconfig_get_state_change() return value documentation 2023-12-13 18:39:05 +01:00
opp
parisc parisc/power: Fix power soft-off when running on qemu 2023-11-28 17:07:14 +00:00
parport parport: Add support for Brainboxes IX/UC/PX parallel cards 2023-12-13 18:39:26 +01:00
pci Revert "PCI/ASPM: Remove pcie_aspm_pm_state_change()" 2024-01-10 17:10:20 +01:00
pcmcia pcmcia: ds: fix possible name leak in error path in pcmcia_device_add() 2023-11-20 11:52:13 +01:00
peci
perf perf: hisi: Fix use-after-free when register pmu fails 2023-11-20 11:52:01 +01:00
phy phy: mapphone-mdm6600: Fix pinctrl_pm handling for sleep pins 2023-10-25 12:03:16 +02:00
pinctrl pinctrl: starfive: jh7100: ignore disabled device tree nodes 2024-01-01 12:39:07 +00:00
platform Revert "platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe" 2024-01-05 15:18:41 +01:00
pnp
power power: supply: core: Use blocking_notifier_call_chain to avoid RCU complaint 2023-11-08 14:11:02 +01:00
powercap powercap: DTPM: Fix missing cpufreq_cpu_put() calls 2023-12-13 18:39:21 +01:00
pps
ps3
ptp ptp: annotate data-race around q->head and q->tail 2023-11-28 17:07:05 +00:00
pwm pwm: brcmstb: Utilize appropriate clock APIs in suspend/resume 2023-11-20 11:52:15 +01:00
rapidio
ras
regulator regulator: mt6358: Fail probe on unknown chip ID 2023-11-20 11:51:56 +01:00
remoteproc
reset reset: Fix crash when freeing non-existent optional resets 2024-01-01 12:38:53 +00:00
rpmsg
rtc rtc: pcf85363: fix wrong mask/val parameters in regmap_update_bits call 2023-11-20 11:52:13 +01:00
s390 s390/dasd: protect device queue against concurrent access 2023-12-03 07:32:11 +01:00
sbus
scsi scsi: core: Always send batch on reset or error handling command 2024-01-01 12:39:07 +00:00
sh
siox
slimbus
soc pmdomain: imx: Make imx pgc power domain also set the fwnode 2023-11-28 17:07:16 +00:00
soundwire soundwire: stream: fix NULL pointer dereference for multi_link 2023-12-20 17:00:25 +01:00
spi spi: atmel: Fix clock issue when using devices with different polarities 2024-01-05 15:18:38 +01:00
spmi
ssb
staging net: vlan: introduce skb_vlan_eth_hdr() 2023-12-20 17:00:16 +01:00
target scsi: target: core: Fix deadlock due to recursive locking 2023-10-10 22:00:41 +02:00
tc
tee tee: optee: Fix supplicant based device enumeration 2023-12-13 18:39:12 +01:00
thermal thermal: core: prevent potential string overflow 2023-11-20 11:51:54 +01:00
thunderbolt thunderbolt: Fix memory leak in margining_port_remove() 2024-01-01 12:39:08 +00:00
tty serial: 8250_omap: Add earlycon support for the AM654 UART controller 2023-12-13 18:39:28 +01:00
ufs scsi: ufs: core: Leave space for '\0' in utf8 desc string 2023-11-20 11:52:07 +01:00
uio
usb usb: fotg210-hcd: delete an incorrect bounds test 2024-01-05 15:18:37 +01:00
vdpa vdpa/mlx5: preserve CVQ vringh index 2023-12-13 18:39:03 +01:00
vfio vfio/mdev: Fix a null-ptr-deref bug for mdev_unregister_parent() 2023-10-06 14:56:45 +02:00
vhost vhost-vdpa: fix use after free in vhost_vdpa_probe() 2023-11-28 17:07:04 +00:00
video fbdev: imsttfb: fix double free in probe() 2024-01-10 17:10:29 +01:00
virt virt: sevguest: Fix passing a stack buffer as a scatterlist target 2023-11-20 11:52:13 +01:00
virtio virtio_pci: fix the common cfg map size 2023-11-02 09:35:23 +01:00
vlynq
w1
watchdog sbsa_gwdt: Calculate timeout with 64-bit math 2023-11-28 17:07:18 +00:00
xen xen: simplify evtchn_do_upcall() call maze 2023-12-08 08:51:20 +01:00
zorro
Kconfig
Makefile