WSL2-Linux-Kernel/drivers
David Hildenbrand 848e19ad3c drivers/base/memory.c: drop the mem_sysfs_mutex
The mem_sysfs_mutex isn't really helpful.  Also, it's not really clear
what the mutex protects at all.

The device lists of the memory subsystem are protected separately.  We
don't need that mutex when looking up.  creating, or removing
independent devices.  find_memory_block_by_id() will perform locking on
its own and grab a reference of the returned device.

At the time memory_dev_init() is called, we cannot have concurrent
hot(un)plug operations yet - we're still fairly early during boot.  We
don't need any locking.

The creation/removal of memory block devices should be protected on a
higher level - especially using the device hotplug lock to avoid
documented issues (see Documentation/core-api/memory-hotplug.rst) - or
if that is reworked, using similar locking.

Protecting in the context of these functions only doesn't really make
sense.  Especially, if we would have a situation where the same memory
blocks are created/deleted at the same time, there is something horribly
going wrong (imagining adding/removing a DIMM at the same time from two
call paths) - after the functions succeeded something else in the
callers would blow up (e.g., create_memory_block_devices() succeeded but
there are no memory block devices anymore).

All relevant call paths (except when adding memory early during boot via
ACPI, which is now documented) hold the device hotplug lock when adding
memory, and when removing memory.  Let's document that instead.

Add a simple safety net to create_memory_block_devices() in case we
would actually remove memory blocks while adding them, so we'll never
dereference a NULL pointer.  Simplify memory_dev_init() now that the
lock is gone.

Link: http://lkml.kernel.org/r/20190925082621.4927-1-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Oscar Salvador <osalvador@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-12-01 12:59:04 -08:00
..
accessibility
acpi dma-mapping updates for 5.5-rc1 2019-11-28 11:16:43 -08:00
amba
android
ata dma-mapping updates for 5.5-rc1 2019-11-28 11:16:43 -08:00
atm
auxdisplay
base drivers/base/memory.c: drop the mem_sysfs_mutex 2019-12-01 12:59:04 -08:00
bcma
block Printk changes for 5.5 2019-11-25 19:40:40 -08:00
bluetooth
bus Staging / IIO patches for 5.5-rc1 2019-11-27 10:57:52 -08:00
cdrom Printk changes for 5.5 2019-11-25 19:40:40 -08:00
char Char/Misc driver patches for 5.5-rc1 2019-11-27 10:53:50 -08:00
clk
clocksource First set of RISC-V updates for v5.5-rc1 2019-11-27 11:27:59 -08:00
connector
counter
cpufreq Power management updates for 5.5-rc1 2019-11-26 19:06:44 -08:00
cpuidle
crypto Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next 2019-11-25 20:02:57 -08:00
dax
dca
devfreq
dio
dma
dma-buf
edac
eisa
extcon Char/Misc driver patches for 5.5-rc1 2019-11-27 10:53:50 -08:00
firewire
firmware Char/Misc driver patches for 5.5-rc1 2019-11-27 10:53:50 -08:00
fpga
fsi
gnss
gpio Driver core patches for 5.5-rc1 2019-11-27 11:06:20 -08:00
gpu hmm related patches for 5.5 2019-11-30 10:33:14 -08:00
greybus
hid
hsi
hv hv_balloon: use generic_online_page() 2019-12-01 12:59:04 -08:00
hwmon hwmon updates for v5.5 2019-11-27 09:58:49 -08:00
hwspinlock
hwtracing
i2c Driver core patches for 5.5-rc1 2019-11-27 11:06:20 -08:00
i3c
ide Printk changes for 5.5 2019-11-25 19:40:40 -08:00
idle
iio Staging / IIO patches for 5.5-rc1 2019-11-27 10:57:52 -08:00
infiniband hmm related patches for 5.5 2019-11-30 10:33:14 -08:00
input
interconnect
iommu dma-mapping updates for 5.5-rc1 2019-11-28 11:16:43 -08:00
ipack
irqchip First set of RISC-V updates for v5.5-rc1 2019-11-27 11:27:59 -08:00
isdn Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next 2019-11-25 20:02:57 -08:00
leds
lightnvm
macintosh Merge branch 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-11-26 15:23:14 -08:00
mailbox
mcb
md
media drm main pull for 5.5-rc1 2019-11-27 17:45:48 -08:00
memory
memstick
message
mfd power supply and reset changes for the v5.5 series 2019-11-27 09:55:39 -08:00
misc drm main pull for 5.5-rc1 2019-11-27 17:45:48 -08:00
mmc Driver core patches for 5.5-rc1 2019-11-27 11:06:20 -08:00
mtd
mux
net Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2019-11-27 17:17:40 -08:00
nfc
ntb
nubus
nvdimm
nvme
nvmem Char/Misc driver patches for 5.5-rc1 2019-11-27 10:53:50 -08:00
of dma-mapping updates for 5.5-rc1 2019-11-28 11:16:43 -08:00
opp
oprofile Printk changes for 5.5 2019-11-25 19:40:40 -08:00
parisc
parport
pci
pcmcia
perf
phy Char/Misc driver patches for 5.5-rc1 2019-11-27 10:53:50 -08:00
pinctrl This is the bulk of pin control changes for the v5.5 kernel 2019-11-27 10:00:33 -08:00
platform Char/Misc driver patches for 5.5-rc1 2019-11-27 10:53:50 -08:00
pnp
power power supply and reset changes for the v5.5 series 2019-11-27 09:55:39 -08:00
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390 Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next 2019-11-25 20:02:57 -08:00
sbus
scsi Merge branch 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-11-26 15:42:43 -08:00
sfi
sh
siox
slimbus
soc
soundwire
spi
spmi
ssb
staging Staging / IIO patches for 5.5-rc1 2019-11-27 10:57:52 -08:00
target
tc
tee
thermal
thunderbolt
tty First set of RISC-V updates for v5.5-rc1 2019-11-27 11:27:59 -08:00
uio
usb dma-mapping updates for 5.5-rc1 2019-11-28 11:16:43 -08:00
vfio
vhost
video drm main pull for 5.5-rc1 2019-11-27 17:45:48 -08:00
virt
virtio
visorbus
vlynq
vme
w1
watchdog
xen hmm related patches for 5.5 2019-11-30 10:33:14 -08:00
zorro
Kconfig
Makefile