linux/drivers
Isaac J. Manjarres ce4d9a1ea3 of: reserved_mem: Have kmemleak ignore dynamically allocated reserved mem
Patch series "Fix kmemleak crashes when scanning CMA regions", v2.

When trying to boot a device with an ARM64 kernel with the following
config options enabled:

CONFIG_DEBUG_PAGEALLOC=y
CONFIG_DEBUG_PAGEALLOC_ENABLE_DEFAULT=y
CONFIG_DEBUG_KMEMLEAK=y

a crash is encountered when kmemleak starts to scan the list of gray
or allocated objects that it maintains. Upon closer inspection, it was
observed that these page-faults always occurred when kmemleak attempted
to scan a CMA region.

At the moment, kmemleak is made aware of CMA regions that are specified
through the devicetree to be dynamically allocated within a range of
addresses. However, kmemleak should not need to scan CMA regions or any
reserved memory region, as those regions can be used for DMA transfers
between drivers and peripherals, and thus wouldn't contain anything
useful for kmemleak.

Additionally, since CMA regions are unmapped from the kernel's address
space when they are freed to the buddy allocator at boot when
CONFIG_DEBUG_PAGEALLOC is enabled, kmemleak shouldn't attempt to access
those memory regions, as that will trigger a crash. Thus, kmemleak
should ignore all dynamically allocated reserved memory regions.


This patch (of 1):

Currently, kmemleak ignores dynamically allocated reserved memory regions
that don't have a kernel mapping.  However, regions that do retain a
kernel mapping (e.g.  CMA regions) do get scanned by kmemleak.

This is not ideal for two reasons:

1  kmemleak works by scanning memory regions for pointers to allocated
   objects to determine if those objects have been leaked or not. 
   However, reserved memory regions can be used between drivers and
   peripherals for DMA transfers, and thus, would not contain pointers to
   allocated objects, making it unnecessary for kmemleak to scan these
   reserved memory regions.

2  When CONFIG_DEBUG_PAGEALLOC is enabled, along with kmemleak, the
   CMA reserved memory regions are unmapped from the kernel's address
   space when they are freed to buddy at boot.  These CMA reserved regions
   are still tracked by kmemleak, however, and when kmemleak attempts to
   scan them, a crash will happen, as accessing the CMA region will result
   in a page-fault, since the regions are unmapped.

Thus, use kmemleak_ignore_phys() for all dynamically allocated reserved
memory regions, instead of those that do not have a kernel mapping
associated with them.

Link: https://lkml.kernel.org/r/20230208232001.2052777-1-isaacmanjarres@google.com
Link: https://lkml.kernel.org/r/20230208232001.2052777-2-isaacmanjarres@google.com
Fixes: a7259df767 ("memblock: make memblock_find_in_range method private")
Signed-off-by: Isaac J. Manjarres <isaacmanjarres@google.com>
Acked-by: Mike Rapoport (IBM) <rppt@kernel.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Kirill A. Shutemov <kirill.shtuemov@linux.intel.com>
Cc: Nick Kossifidis <mick@ics.forth.gr>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Cc: Saravana Kannan <saravanak@google.com>
Cc: <stable@vger.kernel.org>	[5.15+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-02-09 15:56:51 -08:00
..
accel Fix mismerge due to devnode now taking a 'const *' device 2022-12-16 13:04:15 -06:00
accessibility
acpi Merge branches 'acpi-resource' and 'acpi-video' 2023-01-13 11:11:05 +01:00
amba ARM updates for 6.2 2022-12-13 15:22:14 -08:00
android
ata ata: pata_cs5535: Don't build on UML 2023-01-14 07:38:48 +09:00
atm treewide: Convert del_timer*() to timer_shutdown*() 2022-12-25 13:38:09 -08:00
auxdisplay
base Kbuild updates for v6.2 2022-12-19 12:33:32 -06:00
bcma
block xen: branch for v6.2-rc4 2023-01-12 17:02:20 -06:00
bluetooth treewide: Convert del_timer*() to timer_shutdown*() 2022-12-25 13:38:09 -08:00
bus Char/Misc driver changes for 6.2-rc1 2022-12-16 03:49:24 -08:00
cdrom
char xen: branch for v6.2-rc4 2023-01-12 17:02:20 -06:00
clk A pile of clk driver updates with a small tracepoint patch to the clk core this 2022-12-13 13:46:07 -08:00
clocksource Updates for timers, timekeeping and drivers: 2022-12-12 12:52:02 -08:00
comedi
connector
counter
cpufreq cpufreq: amd-pstate: fix kernel hang issue while amd-pstate unregistering 2023-01-10 20:31:08 +01:00
cpuidle powerpc updates for 6.2 2022-12-19 07:13:33 -06:00
crypto MTD changes: 2023-01-12 05:56:06 -06:00
cxl cxl/region: Fix memdev reuse check 2022-12-08 13:03:47 -08:00
dax
dca
devfreq PM / devfreq: event: use devm_platform_get_and_ioremap_resource() 2022-12-05 21:57:20 +09:00
dio
dma dmaengine updates for v6.2 2022-12-19 08:54:17 -06:00
dma-buf Merge drm/drm-fixes into drm-misc-fixes 2023-01-03 08:32:12 +01:00
edac EDAC/highbank: Fix memory leak in highbank_mc_probe() 2023-01-03 17:03:57 +01:00
eisa
extcon Char/Misc driver changes for 6.2-rc1 2022-12-16 03:49:24 -08:00
firewire
firmware kernel hardening fixes for v6.2-rc4 2023-01-14 10:04:00 -06:00
fpga Char/Misc driver changes for 6.2-rc1 2022-12-16 03:49:24 -08:00
fsi
gnss
gpio gpio: sifive: Fix refcount leak in sifive_gpio_probe 2023-01-02 13:01:14 +01:00
gpu drm fixes for 6.2-rc4 2023-01-13 07:18:59 -06:00
greybus
hid treewide: Convert del_timer*() to timer_shutdown*() 2022-12-25 13:38:09 -08:00
hsi
hte
hv Networking changes for 6.2. 2022-12-13 15:47:48 -08:00
hwmon hwmon updates for v6.2 merge window 2022-12-13 13:09:38 -08:00
hwspinlock
hwtracing
i2c Core got a new helper 'i2c_client_get_device_id', designware got some 2022-12-15 14:47:10 -08:00
i3c i3c: export SETDASA method 2022-12-11 21:25:58 +01:00
idle
iio Char/Misc driver changes for 6.2-rc1 2022-12-16 03:49:24 -08:00
infiniband RDMA/mlx5: Fix validation of max_rd_atomic caps for DC 2023-01-01 09:40:35 +02:00
input xen: branch for v6.2-rc4 2023-01-12 17:02:20 -06:00
interconnect
iommu iommu/mediatek-v1: Fix an error handling path in mtk_iommu_v1_probe() 2023-01-13 13:46:32 +01:00
ipack
irqchip RISC-V Patches for the 6.2 Merge Window, Part 1 2022-12-14 15:23:49 -08:00
isdn treewide: Convert del_timer*() to timer_shutdown*() 2022-12-25 13:38:09 -08:00
leds treewide: Convert del_timer*() to timer_shutdown*() 2022-12-25 13:38:09 -08:00
macintosh
mailbox - qcom: enable sc8280xp, sm8550 and sm4250 support 2022-12-21 09:31:18 -08:00
mcb mcb: mcb-parse: fix error handing in chameleon_parse_gdd() 2022-12-02 17:48:04 +01:00
md block: handle bio_split_to_limits() NULL return 2023-01-04 09:05:23 -07:00
media treewide: Convert del_timer*() to timer_shutdown*() 2022-12-25 13:38:09 -08:00
memory ARM updates for 6.2 2022-12-13 15:22:14 -08:00
memstick memstick/mspro_block: Convert to use sysfs_emit()/sysfs_emit_at() APIs 2022-12-09 10:29:58 +01:00
message
mfd - New Drivers 2022-12-21 09:19:24 -08:00
misc kernel hardening fixes for v6.2-rc1 2022-12-23 12:00:24 -08:00
mmc MMC core: 2022-12-13 13:41:26 -08:00
most
mtd mtd: cfi: allow building spi-intel standalone 2023-01-02 12:08:53 +01:00
mux
net Including fixes from rxrpc. 2023-01-12 18:20:44 -06:00
nfc nfc: pn533: Wait for out_urb's completion in pn533_usb_send_frame() 2023-01-09 07:34:13 +00:00
ntb
nubus
nvdimm nvdimm/region: Move cache management to the region driver 2022-12-02 23:52:32 -08:00
nvme block-6.2-2023-01-13 2023-01-13 17:41:19 -06:00
nvmem Char/Misc driver changes for 6.2-rc1 2022-12-16 03:49:24 -08:00
of of: reserved_mem: Have kmemleak ignore dynamically allocated reserved mem 2023-02-09 15:56:51 -08:00
opp
parisc parisc: led: Fix potential null-ptr-deref in start_task() 2022-12-17 23:19:38 +01:00
parport
pci pci-v6.2-fixes-1 2023-01-13 17:32:22 -06:00
pcmcia treewide: Convert del_timer*() to timer_shutdown*() 2022-12-25 13:38:09 -08:00
peci
perf RISC-V Patches for the 6.2 Merge Window, Part 1 2022-12-14 15:23:49 -08:00
phy phy-for-6.2 2022-12-19 08:40:58 -06:00
pinctrl Pin control changes for the v6.2 kernel cycle: 2022-12-13 13:03:06 -08:00
platform platform/x86: thinkpad_acpi: Fix profile mode display in AMT mode 2023-01-13 11:40:30 +01:00
pnp
power power supply and reset changes for the v6.2 series 2022-12-17 08:39:31 -06:00
powercap powercap: idle_inject: Fix warnings with make W=1 2022-12-02 20:49:49 +01:00
pps
ps3
ptp Networking changes for 6.2. 2022-12-13 15:47:48 -08:00
pwm pwm: Changes for v6.2-rc1 2022-12-21 09:41:28 -08:00
rapidio rapidio: devices: fix missing put_device in mport_cdev_open 2022-12-11 19:30:20 -08:00
ras
regulator regulator: qcom-rpmh: PM8550 ldo11 regulator is an nldo 2023-01-03 15:54:38 +00:00
remoteproc remoteproc: core: Do pm_relax when in RPROC_OFFLINE state 2022-12-07 11:20:55 -07:00
reset
rpmsg
rtc - New Drivers 2022-12-21 09:19:24 -08:00
s390 block-2023-01-06 2023-01-06 13:12:42 -08:00
sbus
scsi SCSI fixes on 20230114 2023-01-14 07:57:25 -06:00
sh
siox
slimbus
soc ARM: SoC fixes for 6.2 2022-12-19 16:07:59 -06:00
soundwire soundwire updates for 6.2 2022-12-19 08:47:33 -06:00
spi spi: Merge rename of spi-cs-setup-ns DT property 2023-01-11 14:15:22 +00:00
spmi
ssb
staging treewide: Convert del_timer*() to timer_shutdown*() 2022-12-25 13:38:09 -08:00
target SCSI misc on 20221213 2022-12-14 08:58:51 -08:00
tc
tee SoC driver updates for 6.2 2022-12-12 10:17:08 -08:00
thermal thermal: int340x: Add missing attribute for data rate base 2022-12-30 19:48:37 +01:00
thunderbolt
tty xen: branch for v6.2-rc4 2023-01-12 17:02:20 -06:00
ufs Merge branch '6.2/scsi-queue' into 6.2/scsi-fixes 2022-12-30 16:29:34 +00:00
uio
usb xen: branch for v6.2-rc4 2023-01-12 17:02:20 -06:00
vdpa vdpa_sim_net: should not drop the multicast/broadcast packet 2022-12-28 05:28:11 -05:00
vfio Driver Core changes for 6.2-rc1 2022-12-16 03:54:54 -08:00
vhost vhost_vdpa: fix the crash in unmap a large memory 2022-12-28 05:28:11 -05:00
video xen: branch for v6.2-rc4 2023-01-12 17:02:20 -06:00
virt Char/Misc driver changes for 6.2-rc1 2022-12-16 03:49:24 -08:00
virtio virtio: Implementing attribute show with sysfs_emit 2022-12-28 05:28:11 -05:00
vlynq
w1
watchdog linux-watchdog 6.2-rc1 tag 2022-12-17 08:34:01 -06:00
xen xen: branch for v6.2-rc4 2023-01-12 17:02:20 -06:00
zorro
Kconfig
Makefile