x86/kaslr: P2PDMA is one of a class of ZONE_DEVICE-KASLR collisions
Subsystems (5)
PATCH 1/1 x86/kaslr: P2PDMA is one of a class of ZONE_DEVICE-KASLR collisions
Commit 7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow. ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for the CONFIG_DEVICE_PRIVATE and CONFIG_PCI_P2PDMA cases.
A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution like arch/x86/boot/compressed/acpi.c needs to deploy.
--- drivers/pci/Kconfig | 6 ------ mm/Kconfig | 12 ++++++++---- arch/x86/mm/kaslr.c | 10 +++++----- 3 files changed, 13 insertions(+), 15 deletions(-)
drivers/pci/Kconfig +0 -6
@@ -207,12 +207,6 @@ config PCI_P2PDMA P2P DMA transactions must be between devices behind the same root port. - Enabling this option will reduce the entropy of x86 KASLR memory - regions. For example - on a 46 bit system, the entropy goes down - from 16 bits to 15 bits. The actual reduction in entropy depends - on the physical address bits, on processor features, kernel config - (5 level page table) and physical memory present on the system. - If unsure, say N. config PCI_LABEL
mm/Kconfig +8 -4
@@ -1128,10 +1128,14 @@ config ZONE_DEVICE Device memory hotplug support allows for establishing pmem, or other device driver discovered memory regions, in the memmap. This allows pfn_to_page() lookups of otherwise - "device-physical" addresses which is needed for using a DAX - mapping in an O_DIRECT operation, among other things. - - If FS_DAX is enabled, then say Y. + "device-physical" addresses which is needed for DAX, PCI_P2PDMA, and + DEVICE_PRIVATE features among others. + + Enabling this option will reduce the entropy of x86 KASLR memory + regions. For example - on a 46 bit system, the entropy goes down + from 16 bits to 15 bits. The actual reduction in entropy depends + on the physical address bits, on processor features, kernel config + (5 level page table) and physical memory present on the system. # # Helpers to mirror range of the CPU page tables of a process into device page
arch/x86/mm/kaslr.c +5 -5
@@ -115,12 +115,12 @@ void __init kernel_randomize_memory(void)/* * Adapt physical memory region size based on available memory, -* except when CONFIG_PCI_P2PDMA is enabled. P2PDMA exposes the -* device BAR space assuming the direct map space is large enough -* for creating a ZONE_DEVICE mapping in the direct map corresponding -* to the physical BAR address. +* except when CONFIG_ZONE_DEVICE is enabled. ZONE_DEVICE wants to map +* any physical address into the direct-map. KASLR wants to reliably +* steal some physical address bits. Those design choices are in direct +* conflict. */ -if (!IS_ENABLED (CONFIG_PCI_P2PDMA ) && (memory_tb < kaslr_regions[0 ].size_tb)) +if (!IS_ENABLED (CONFIG_ZONE_DEVICE ) && (memory_tb < kaslr_regions[0 ].size_tb)) kaslr_regions[0 ].size_tb = memory_tb;/*
base-commit: 6146a0f1dfae5d37442a9ddcba012add260bceb0
Signature · 1 line
2.51.0
Quoted 23 lines · Dan Williams
Commit
7ffb791423c7("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow.ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for theCONFIG_DEVICE_PRIVATEandCONFIG_PCI_P2PDMAcases.A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before
kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution likearch/x86/boot/compressed/acpi.cneeds to deploy.Cc Balbir Singh <[email protected]>Cc Ingo Molnar <[email protected]>Cc Kees Cook <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Logan Gunthorpe <[email protected]>Cc Andrew Morton <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lorenzo Stoakes <[email protected]>
Quoted 8 lines
Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Cc "Yasunori Gotou (Fujitsu)" <[email protected]>Fixes 7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86 systems")Signed-off-by Dan Williams <[email protected]>
P2PDMA requires ZONE_DEVICE, Most distros have P2PDMA enabled, you mention smaller devices - are you referring to kernels/distros where P2PDMA is not enabled and only ZONE_DEVICE is?
Balbir
Quoted 33 lines · Balbir Singh
Quoted 23 lines · Dan Williams
Commit
7ffb791423c7("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow.ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for theCONFIG_DEVICE_PRIVATEandCONFIG_PCI_P2PDMAcases.A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before
kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution likearch/x86/boot/compressed/acpi.cneeds to deploy.Cc Balbir Singh <[email protected]>Cc Ingo Molnar <[email protected]>Cc Kees Cook <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Logan Gunthorpe <[email protected]>Cc Andrew Morton <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lorenzo Stoakes <[email protected]>Quoted 8 lines
Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Cc "Yasunori Gotou (Fujitsu)" <[email protected]>Fixes 7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86 systems")Signed-off-by Dan Williams <[email protected]>
Quoted 3 lines
P2PDMA requires
ZONE_DEVICE, Most distros have P2PDMA enabled, you mention smaller devices - are you referring to kernels/distros where P2PDMA is not enabled and onlyZONE_DEVICEis?
There are 2 considerations
- Occasions where P2PDMA is disabled, but ZONE_DEVICE is enabled.
I started looking at this after a report about CXL failures with KASLR. I do not have the kernel configuration for that end user report, but I can only a imagine it was indeed a case of CONFIG_PCI_P2PDMA=n and CONFIG_DEV_DAX_CXL=y
- Occasions where ZONE_DEVICE and memory hotplug are enabled, but ACPI does not publish any hotplug or CXL memory ranges, and BIOS did not find any large PCI devices at initial scan.
In this case even the default 10 TB padding is overkill and more address bits could be consumed for KASLR entropy.
Balbir Singh
Reviewed-byQuoted 47 lines · On 11/11/25 10:34, [email protected] wrote:
Quoted 33 lines · Balbir Singh
Quoted 23 lines · Dan Williams
Commit
7ffb791423c7("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow.ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for theCONFIG_DEVICE_PRIVATEandCONFIG_PCI_P2PDMAcases.A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before
kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution likearch/x86/boot/compressed/acpi.cneeds to deploy.Cc Balbir Singh <[email protected]>Cc Ingo Molnar <[email protected]>Cc Kees Cook <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Logan Gunthorpe <[email protected]>Cc Andrew Morton <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lorenzo Stoakes <[email protected]>Quoted 8 lines
Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Cc "Yasunori Gotou (Fujitsu)" <[email protected]>Fixes 7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86 systems")Signed-off-by Dan Williams <[email protected]>Quoted 3 lines
P2PDMA requires
ZONE_DEVICE, Most distros have P2PDMA enabled, you mention smaller devices - are you referring to kernels/distros where P2PDMA is not enabled and onlyZONE_DEVICEis?There are 2 considerations
- Occasions where P2PDMA is disabled, but
ZONE_DEVICEis enabled.I started looking at this after a report about CXL failures with KASLR. I do not have the kernel configuration for that end user report, but I can only a imagine it was indeed a case of
CONFIG_PCI_P2PDMA=nandCONFIG_DEV_DAX_CXL=y
Quoted 6 lines
- Occasions where
ZONE_DEVICEand memory hotplug are enabled, but ACPI does not publish any hotplug or CXL memory ranges, and BIOS did not find any large PCI devices at initial scan.In this case even the default 10 TB padding is overkill and more address bits could be consumed for KASLR entropy.
Makes sense!
Yasunori Gotou (Fujitsu)
Tested-byHello,
Quoted 41 lines
Quoted 6 lines · Balbir Singh
Quoted 5 lines · Dan Williams
Commit
7ffb791423c7("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow.ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for theCONFIG_DEVICE_PRIVATEand
CONFIG_PCI_P2PDMAcases.Quoted 7 lines
Quoted 7 lines
A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before
kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution likearch/x86/boot/compressed/acpi.cneeds todeploy.
Quoted 21 lines
Quoted 18 lines
Cc Balbir Singh <[email protected]>Cc Ingo Molnar <[email protected]>Cc Kees Cook <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Logan Gunthorpe <[email protected]>Cc Andrew Morton <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Cc "Yasunori Gotou (Fujitsu)" <[email protected]>Fixes 7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86Quoted 2 lines
systems")
Signed-off-by Dan Williams <[email protected]>Quoted 3 lines
P2PDMA requires
ZONE_DEVICE, Most distros have P2PDMA enabled, you mention smaller devices - are you referring to kernels/distros where P2PDMA is not enabled and onlyZONE_DEVICEis?
Quoted 8 lines
There are 2 considerations
- Occasions where P2PDMA is disabled, but
ZONE_DEVICEis enabled.I started looking at this after a report about CXL failures with KASLR. I do not have the kernel configuration for that end user report, but I can only a imagine it was indeed a case of
CONFIG_PCI_P2PDMA=nandCONFIG_DEV_DAX_CXL=y
I believe I am the first to report CXL failures with KASLR.
To be honest, after checking this patch, I realized that the distribution I am using hasn't applied commit 7ffb791423c7 yet.
Therefore, I tested both P2PDMA and ZONE_DEVICE patches, and both worked successfully to allocate physical memory for CXL in my box
Thanks a lot!
----
Yasunori Goto
Mike Rapoport
reviewerQuoted 87 lines · Dan Williams
Commit
7ffb791423c7("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow.ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for theCONFIG_DEVICE_PRIVATEandCONFIG_PCI_P2PDMAcases.A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before
kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution likearch/x86/boot/compressed/acpi.cneeds to deploy.Cc Balbir Singh <[email protected]>Cc Ingo Molnar <[email protected]>Cc Kees Cook <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Logan Gunthorpe <[email protected]>Cc Andrew Morton <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Cc "Yasunori Gotou (Fujitsu)" <[email protected]>Fixes 7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86 systems")Signed-off-by Dan Williams <[email protected]>--- drivers/pci/Kconfig | 6 ------ mm/Kconfig | 12 ++++++++---- arch/x86/mm/kaslr.c | 10 +++++----- 3 files changed, 13 insertions(+), 15 deletions(-)drivers/pci/Kconfig +0
-6@@ -207,12 +207,6 @@ config PCI_P2PDMA P2P DMA transactions must be between devices behind the same root port. - Enabling this option will reduce the entropy of x86 KASLR memory - regions. For example - on a 46 bit system, the entropy goes down - from 16 bits to 15 bits. The actual reduction in entropy depends - on the physical address bits, on processor features, kernel config - (5 level page table) and physical memory present on the system. - If unsure, say N. config PCI_LABELmm/Kconfig +8
-4@@ -1128,10 +1128,14 @@ config ZONE_DEVICE Device memory hotplug support allows for establishing pmem, or other device driver discovered memory regions, in the memmap. This allows pfn_to_page() lookups of otherwise - "device-physical" addresses which is needed for using a DAX - mapping in an O_DIRECT operation, among other things. - - If FS_DAX is enabled, then say Y. + "device-physical" addresses which is needed for DAX, PCI_P2PDMA, and + DEVICE_PRIVATE features among others. + + Enabling this option will reduce the entropy of x86 KASLR memory + regions. For example - on a 46 bit system, the entropy goes down + from 16 bits to 15 bits. The actual reduction in entropy depends + on the physical address bits, on processor features, kernel config + (5 level page table) and physical memory present on the system. # # Helpers to mirror range of the CPU page tables of a process into device pagearch/x86/mm/kaslr.c +0
-2@@ -115,12 +115,12 @@ void __init kernel_randomize_memory(void)/* * Adapt physical memory region size based on available memory, -* except when CONFIG_PCI_P2PDMA is enabled. P2PDMA exposes the -* device BAR space assuming the direct map space is large enough
arch/x86/mm/kaslr.c void __init kernel_randomize_memory(void) · line 124
Quoted 10 lines
arch/x86/mm/kaslr.c +5
-3-* for creating a ZONE_DEVICE mapping in the direct map corresponding -* to the physical BAR address. +* except when CONFIG_ZONE_DEVICE is enabled. ZONE_DEVICE wants to map +* any physical address into the direct-map. KASLR wants to reliably +* steal some physical address bits. Those design choices are in direct +* conflict. */ -if (!IS_ENABLED (CONFIG_PCI_P2PDMA ) && (memory_tb < kaslr_regions[0 ].size_tb)) +if (!IS_ENABLED (CONFIG_ZONE_DEVICE ) && (memory_tb < kaslr_regions[0 ].size_tb)) kaslr_regions[0 ].size_tb = memory_tb;
A stupid question, why we adjust virtual kaslr to actual physical memory size at all rather than always use maximal addressable size?
Quoted 6 lines
arch/x86/mm/kaslr.c +0
-0/* base-commit:
6146a0f1dfae5d37442a9ddcba012add260bceb0Signature · 1 line
2.51.0
Signature · 2 lines
Sincerely yours, Mike.
Quoted 32 lines · Mike Rapoport
Quoted 31 lines · Dan Williams
Commit
7ffb791423c7("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow.ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for theCONFIG_DEVICE_PRIVATEandCONFIG_PCI_P2PDMAcases.A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before
kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution likearch/x86/boot/compressed/acpi.cneeds to deploy.Cc Balbir Singh <[email protected]>Cc Ingo Molnar <[email protected]>Cc Kees Cook <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Logan Gunthorpe <[email protected]>Cc Andrew Morton <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Cc "Yasunori Gotou (Fujitsu)" <[email protected]>Fixes 7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86 systems")Signed-off-by Dan Williams <[email protected]>
[..]
Quoted 16 lines
Quoted 16 lines
# Helpers to mirror range of the CPU page tables of a process into device page
arch/x86/mm/kaslr.c +3
-4@@ -115,12 +115,12 @@ void __init kernel_randomize_memory(void)/* * Adapt physical memory region size based on available memory, -* except when CONFIG_PCI_P2PDMA is enabled. P2PDMA exposes the -* device BAR space assuming the direct map space is large enough -* for creating a ZONE_DEVICE mapping in the direct map corresponding -* to the physical BAR address. +* except when CONFIG_ZONE_DEVICE is enabled. ZONE_DEVICE wants to map +* any physical address into the direct-map. KASLR wants to reliably +* steal some physical address bits. Those design choices are in direct
Quoted 8 lines
arch/x86/mm/kaslr.c void __init kernel_randomize_memory(void) · line 124
Quoted 5 lines
arch/x86/mm/kaslr.c +2
-1+* conflict. */ -if (!IS_ENABLED (CONFIG_PCI_P2PDMA ) && (memory_tb < kaslr_regions[0 ].size_tb)) +if (!IS_ENABLED (CONFIG_ZONE_DEVICE ) && (memory_tb < kaslr_regions[0 ].size_tb)) kaslr_regions[0 ].size_tb = memory_tb;A stupid question, why we adjust virtual kaslr to actual physical memory size at all rather than always use maximal addressable size?
My understanding is that KASLR wants to maximize the known unused portions of the physical address space to incresase entropy. So a policy of always excludie max addressable size == minimum entropy. At least that is my view from 7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86 systems"), someone from the KASLR implementation side could correct me.
Quoted 93 lines · Mike Rapoport
Quoted 92 lines · Dan Williams
Commit
7ffb791423c7("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow.ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for theCONFIG_DEVICE_PRIVATEandCONFIG_PCI_P2PDMAcases.A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before
kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution likearch/x86/boot/compressed/acpi.cneeds to deploy.Cc Balbir Singh <[email protected]>Cc Ingo Molnar <[email protected]>Cc Kees Cook <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Logan Gunthorpe <[email protected]>Cc Andrew Morton <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Cc "Yasunori Gotou (Fujitsu)" <[email protected]>Fixes 7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86 systems")Signed-off-by Dan Williams <[email protected]>--- drivers/pci/Kconfig | 6 ------ mm/Kconfig | 12 ++++++++---- arch/x86/mm/kaslr.c | 10 +++++----- 3 files changed, 13 insertions(+), 15 deletions(-)drivers/pci/Kconfig +0
-6@@ -207,12 +207,6 @@ config PCI_P2PDMA P2P DMA transactions must be between devices behind the same root port. - Enabling this option will reduce the entropy of x86 KASLR memory - regions. For example - on a 46 bit system, the entropy goes down - from 16 bits to 15 bits. The actual reduction in entropy depends - on the physical address bits, on processor features, kernel config - (5 level page table) and physical memory present on the system. - If unsure, say N. config PCI_LABELmm/Kconfig +8
-4@@ -1128,10 +1128,14 @@ config ZONE_DEVICE Device memory hotplug support allows for establishing pmem, or other device driver discovered memory regions, in the memmap. This allows pfn_to_page() lookups of otherwise - "device-physical" addresses which is needed for using a DAX - mapping in an O_DIRECT operation, among other things. - - If FS_DAX is enabled, then say Y. + "device-physical" addresses which is needed for DAX, PCI_P2PDMA, and + DEVICE_PRIVATE features among others. + + Enabling this option will reduce the entropy of x86 KASLR memory + regions. For example - on a 46 bit system, the entropy goes down + from 16 bits to 15 bits. The actual reduction in entropy depends + on the physical address bits, on processor features, kernel config + (5 level page table) and physical memory present on the system. # # Helpers to mirror range of the CPU page tables of a process into device pagearch/x86/mm/kaslr.c +3
-4@@ -115,12 +115,12 @@ void __init kernel_randomize_memory(void)/* * Adapt physical memory region size based on available memory, -* except when CONFIG_PCI_P2PDMA is enabled. P2PDMA exposes the -* device BAR space assuming the direct map space is large enough -* for creating a ZONE_DEVICE mapping in the direct map corresponding -* to the physical BAR address. +* except when CONFIG_ZONE_DEVICE is enabled. ZONE_DEVICE wants to map +* any physical address into the direct-map. KASLR wants to reliably +* steal some physical address bits. Those design choices are in direct
Quoted 8 lines
arch/x86/mm/kaslr.c void __init kernel_randomize_memory(void) · line 124
Quoted 5 lines
arch/x86/mm/kaslr.c +2
-1+* conflict. */ -if (!IS_ENABLED (CONFIG_PCI_P2PDMA ) && (memory_tb < kaslr_regions[0 ].size_tb)) +if (!IS_ENABLED (CONFIG_ZONE_DEVICE ) && (memory_tb < kaslr_regions[0 ].size_tb)) kaslr_regions[0 ].size_tb = memory_tb;A stupid question, why we adjust virtual kaslr to actual physical memory size at all rather than always use maximal addressable size?
The original changelog that introduced the changes has a detailed explanation, IIRC.
Balbir
The subject probably wants to be something along the lines of:
x86/kaslr: Recognize all ZONE_DEVICE users as physaddr consumers
Quoted 5 lines · Dan Williams
Commit
7ffb791423c7("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow.ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for theCONFIG_DEVICE_PRIVATEandCONFIG_PCI_P2PDMAcases.
This should probably also mention the fact that:
config PCI_P2PDMA
depends on ZONE_DEVICE
It would also be nice to point out how the "too narrow" check had an impact on real ZONE_DEVICE but !PCI_P2PDMA users. This isn't just a theoretical problem, right?
Quoted 6 lines
A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before
kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution likearch/x86/boot/compressed/acpi.cneeds to deploy.
Yeah, a more flexible runtime solution would be highly preferred over the existing solution built around config options. But this is really orthogonal to the bug fix here.
With the changelog fixes above:
Oh, and does this need to be cc:stable@?
Quoted 3 lines · Dave Hansen
The subject probably wants to be something along the lines of:
x86/kaslr: Recognize all
ZONE_DEVICEusers as physaddr consumers
...works for me.
Quoted 8 lines · Dan Williams
Quoted 5 lines
Commit
7ffb791423c7("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow.ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for theCONFIG_DEVICE_PRIVATEandCONFIG_PCI_P2PDMAcases.
Quoted 8 lines
This should probably also mention the fact that:
config
PCI_P2PDMA
depends onZONE_DEVICEIt would also be nice to point out how the "too narrow" check had an impact on real
ZONE_DEVICEbut !PCI_P2PDMA users. This isn't just a theoretical problem, right?
Yasunori filled in a detail [1] that I did not have when creating the patch, specifically that when he enountered the CXL collision with KASLR he was running on a kernel before commit 7ffb791423c7 ("x86/kaslr:
Reduce KASLR entropy on most x86 systems").
Either way, a pre-7ffb791423c7 kernel and a kernel with CONFIG_PCI_P2PDMA=n would fail the same way. Yasunori confirmed that current kernel with CONFIG_PCI_P2PDMA=y, or this patch solved the problem for him.
See below for a reworked patch with these changes.
Quoted 12 lines
Quoted 7 lines
A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before
kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution likearch/x86/boot/compressed/acpi.cneeds to deploy.Yeah, a more flexible runtime solution would be highly preferred over the existing solution built around config options. But this is really orthogonal to the bug fix here.
Quoted 5 lines
With the changelog fixes above:
Acked-by Dave Hansen <[email protected]>Oh, and does this need to be cc:stable@?
Yes, especially because it would create a dependency on 7ffb791423c7 also being backported and that would have helped Yasunori avoid this problem (for CONFIG_PCI_P2PDMA=y builds at least).
-- >8 --
From d2f4b9ac915ce35e2ec842548ae1ccb4f1690b04 Mon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Thu, 6 Nov 2025 15:13:50 -0800
Subject: [PATCH v2] x86/kaslr: Recognize all ZONE_DEVICE users as physaddr
consumers
Commit 7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow. The effect being mitigated in that commit is caused by ZONE_DEVICE which PCI_P2PDMA has a dependency. ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for the DEVICE_PRIVATE and PCI_P2PDMA cases. Update the mitigation, limit KASLR entropy, to apply in all ZONE_DEVICE=y cases.
Distro kernels typically have PCI_P2PDMA=y, so the practical exposure of this problem is limited to the PCI_P2PDMA=n case.
A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution like arch/x86/boot/compressed/acpi.c needs to deploy.
--- drivers/pci/Kconfig | 6 ------ mm/Kconfig | 12 ++++++++---- arch/x86/mm/kaslr.c | 10 +++++----- 3 files changed, 13 insertions(+), 15 deletions(-)
drivers/pci/Kconfig +0 -6
@@ -207,12 +207,6 @@ config PCI_P2PDMA P2P DMA transactions must be between devices behind the same root port. - Enabling this option will reduce the entropy of x86 KASLR memory - regions. For example - on a 46 bit system, the entropy goes down - from 16 bits to 15 bits. The actual reduction in entropy depends - on the physical address bits, on processor features, kernel config - (5 level page table) and physical memory present on the system. - If unsure, say N. config PCI_LABEL
mm/Kconfig +8 -4
@@ -1128,10 +1128,14 @@ config ZONE_DEVICE Device memory hotplug support allows for establishing pmem, or other device driver discovered memory regions, in the memmap. This allows pfn_to_page() lookups of otherwise - "device-physical" addresses which is needed for using a DAX - mapping in an O_DIRECT operation, among other things. - - If FS_DAX is enabled, then say Y. + "device-physical" addresses which is needed for DAX, PCI_P2PDMA, and + DEVICE_PRIVATE features among others. + + Enabling this option will reduce the entropy of x86 KASLR memory + regions. For example - on a 46 bit system, the entropy goes down + from 16 bits to 15 bits. The actual reduction in entropy depends + on the physical address bits, on processor features, kernel config + (5 level page table) and physical memory present on the system. # # Helpers to mirror range of the CPU page tables of a process into device page
arch/x86/mm/kaslr.c +5 -5
@@ -115,12 +115,12 @@ void __init kernel_randomize_memory(void)/* * Adapt physical memory region size based on available memory, -* except when CONFIG_PCI_P2PDMA is enabled. P2PDMA exposes the -* device BAR space assuming the direct map space is large enough -* for creating a ZONE_DEVICE mapping in the direct map corresponding -* to the physical BAR address. +* except when CONFIG_ZONE_DEVICE is enabled. ZONE_DEVICE wants to map +* any physical address into the direct-map. KASLR wants to reliably +* steal some physical address bits. Those design choices are in direct +* conflict. */ -if (!IS_ENABLED (CONFIG_PCI_P2PDMA ) && (memory_tb < kaslr_regions[0 ].size_tb)) +if (!IS_ENABLED (CONFIG_ZONE_DEVICE ) && (memory_tb < kaslr_regions[0 ].size_tb)) kaslr_regions[0 ].size_tb = memory_tb;/*
Signature · 1 line
2.51.1
Dave Jiang
AppliedQuoted 96 lines · On 12/1/25 2:29 PM, [email protected] wrote:
Quoted 3 lines · Dave Hansen
The subject probably wants to be something along the lines of:
x86/kaslr: Recognize all
ZONE_DEVICEusers as physaddr consumers...works for me.
Quoted 8 lines · Dan Williams
Quoted 5 lines
Commit
7ffb791423c7("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow.ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for theCONFIG_DEVICE_PRIVATEandCONFIG_PCI_P2PDMAcases.Quoted 8 lines
This should probably also mention the fact that:
config
PCI_P2PDMA
depends onZONE_DEVICEIt would also be nice to point out how the "too narrow" check had an impact on real
ZONE_DEVICEbut !PCI_P2PDMA users. This isn't just a theoretical problem, right?Yasunori filled in a detail [1] that I did not have when creating the patch, specifically that when he enountered the CXL collision with KASLR he was running on a kernel before commit
7ffb791423c7("x86/kaslr:
Reduce KASLR entropy on most x86 systems").Either way, a pre-7ffb791423c7 kernel and a kernel with
CONFIG_PCI_P2PDMA=nwould fail the same way. Yasunori confirmed that current kernel withCONFIG_PCI_P2PDMA=y, or this patch solved the problem for him.See below for a reworked patch with these changes.
Quoted 12 lines
Quoted 7 lines
A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before
kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution likearch/x86/boot/compressed/acpi.cneeds to deploy.Yeah, a more flexible runtime solution would be highly preferred over the existing solution built around config options. But this is really orthogonal to the bug fix here.
Quoted 5 lines
With the changelog fixes above:
Acked-by Dave Hansen <[email protected]>Oh, and does this need to be cc:stable@?
Yes, especially because it would create a dependency on
7ffb791423c7also being backported and that would have helped Yasunori avoid this problem (forCONFIG_PCI_P2PDMA=ybuilds at least).-- >8 --
Fromd2f4b9ac915ce35e2ec842548ae1ccb4f1690b04Mon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Thu, 6 Nov 2025 15:13:50 -0800
Subject: [PATCH v2] x86/kaslr: Recognize allZONE_DEVICEusers as physaddr
consumersCommit
7ffb791423c7("x86/kaslr: Reduce KASLR entropy on most x86 systems") is too narrow. The effect being mitigated in that commit is caused byZONE_DEVICEwhichPCI_P2PDMAhas a dependency.ZONE_DEVICE, in general, lets any physical address be added to the direct-map. I.e. not only ACPI hotplug ranges, CXL Memory Windows, or EFI Specific Purpose Memory, but also any PCI MMIO range for theDEVICE_PRIVATEandPCI_P2PDMAcases. Update the mitigation, limit KASLR entropy, to apply in all ZONE_DEVICE=y cases.Distro kernels typically have PCI_P2PDMA=y, so the practical exposure of this problem is limited to the PCI_P2PDMA=n case.
A potential path to recover entropy would be to walk ACPI and determine the limits for hotplug and PCI MMIO before
kernel_randomize_memory(). On smaller systems that could yield some KASLR address bits. This needs additional investigation to determine if some limited ACPI table scanning can happen this early without an open coded solution likearch/x86/boot/compressed/acpi.cneeds to deploy.Cc Ingo Molnar <[email protected]>Cc Kees Cook <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Logan Gunthorpe <[email protected]>Cc Andrew Morton <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>
Quoted 8 lines
Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Fixes 7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86 systems")Cc <[email protected]>Signed-off-by Dan Williams <[email protected]>Reviewed-by Balbir Singh <[email protected]>Tested-by Yasunori Goto <[email protected]>Acked-by Dave Hansen <[email protected]>
Applied to cxl/fixes269031b15c1433ff39e30fa7ea3ab8f0be9d6ae2
DJ
Quoted 68 lines
--- drivers/pci/Kconfig | 6 ------ mm/Kconfig | 12 ++++++++---- arch/x86/mm/kaslr.c | 10 +++++----- 3 files changed, 13 insertions(+), 15 deletions(-)drivers/pci/Kconfig +0
-6@@ -207,12 +207,6 @@ config PCI_P2PDMA P2P DMA transactions must be between devices behind the same root port. - Enabling this option will reduce the entropy of x86 KASLR memory - regions. For example - on a 46 bit system, the entropy goes down - from 16 bits to 15 bits. The actual reduction in entropy depends - on the physical address bits, on processor features, kernel config - (5 level page table) and physical memory present on the system. - If unsure, say N. config PCI_LABELmm/Kconfig +8
-4@@ -1128,10 +1128,14 @@ config ZONE_DEVICE Device memory hotplug support allows for establishing pmem, or other device driver discovered memory regions, in the memmap. This allows pfn_to_page() lookups of otherwise - "device-physical" addresses which is needed for using a DAX - mapping in an O_DIRECT operation, among other things. - - If FS_DAX is enabled, then say Y. + "device-physical" addresses which is needed for DAX, PCI_P2PDMA, and + DEVICE_PRIVATE features among others. + + Enabling this option will reduce the entropy of x86 KASLR memory + regions. For example - on a 46 bit system, the entropy goes down + from 16 bits to 15 bits. The actual reduction in entropy depends + on the physical address bits, on processor features, kernel config + (5 level page table) and physical memory present on the system. # # Helpers to mirror range of the CPU page tables of a process into device pagearch/x86/mm/kaslr.c +5
-5@@ -115,12 +115,12 @@ void __init kernel_randomize_memory(void)/* * Adapt physical memory region size based on available memory, -* except when CONFIG_PCI_P2PDMA is enabled. P2PDMA exposes the -* device BAR space assuming the direct map space is large enough -* for creating a ZONE_DEVICE mapping in the direct map corresponding -* to the physical BAR address. +* except when CONFIG_ZONE_DEVICE is enabled. ZONE_DEVICE wants to map +* any physical address into the direct-map. KASLR wants to reliably +* steal some physical address bits. Those design choices are in direct +* conflict. */ -if (!IS_ENABLED (CONFIG_PCI_P2PDMA ) && (memory_tb < kaslr_regions[0 ].size_tb)) +if (!IS_ENABLED (CONFIG_ZONE_DEVICE ) && (memory_tb < kaslr_regions[0 ].size_tb)) kaslr_regions[0 ].size_tb = memory_tb;/*