Skip to content

Commit 6f161a0

Browse files
author
CKI KWF Bot
committed
Merge: x86: Reduce KASLR entropy
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7462 JIRA: https://issues.redhat.com/browse/RHEL-117031 The following error is seen on Nvidia systems: <4>[ 1062.336158] NVRM: VM: nv_alloc_pages:3801: 0x0000000021ac81f7, 32 page(s), count = 1, flags = 0x00000004, page_table = 0x00000000677eb7bb <3>[ 1062.339224] nvidia-uvm: uvm_pmm_gpu.c:3480 devmem_init[pid:6006] request_free_mem_region() err -34 <3>[ 1062.339530] nvidia-uvm: uvm_gpu.c:1311 init_gpu[pid:6006] PMM initialization failed: Failure: Generic Error [NV_ERR_GENERIC], GPU ID 1: GPU-de9f6996-a0bf-2443-d0b7-eca4d994dab2 UVM-GI-de9f6996-a0bf-2443-d0b7-eca4d994dab2 Nvidia's documention [1] points out that the problem has been fixed upstream. After discussions with Nvidia, they pointed out two commits (backported in this changeset) that will resolve the issue. This fix has been tested by the reporter. [1] https://docs.nvidia.com/cuda/archive/13.0.0/cuda-toolkit-release-notes/index.html#known-issues Signed-off-by: Prarit Bhargava <prarit@redhat.com> Approved-by: David Arcari <darcari@redhat.com> Approved-by: Rafael Aquini <raquini@redhat.com> Approved-by: Lucas Zampieri <lzampier@redhat.com> Approved-by: Eder Zulian <ezulian@redhat.com> Approved-by: John W. Linville <linville@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents 277c09e + 1f2bcdb commit 6f161a0

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

arch/x86/mm/init_64.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,18 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
967967
ret = __add_pages(nid, start_pfn, nr_pages, params);
968968
WARN_ON_ONCE(ret);
969969

970-
/* update max_pfn, max_low_pfn and high_memory */
971-
update_end_of_memory_vars(start_pfn << PAGE_SHIFT,
972-
nr_pages << PAGE_SHIFT);
970+
/*
971+
* Special case: add_pages() is called by memremap_pages() for adding device
972+
* private pages. Do not bump up max_pfn in the device private path,
973+
* because max_pfn changes affect dma_addressing_limited().
974+
*
975+
* dma_addressing_limited() returning true when max_pfn is the device's
976+
* addressable memory can force device drivers to use bounce buffers
977+
* and impact their performance negatively:
978+
*/
979+
if (!params->pgmap)
980+
/* update max_pfn, max_low_pfn and high_memory */
981+
update_end_of_memory_vars(start_pfn << PAGE_SHIFT, nr_pages << PAGE_SHIFT);
973982

974983
return ret;
975984
}

arch/x86/mm/kaslr.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,14 @@ void __init kernel_randomize_memory(void)
109109
memory_tb = DIV_ROUND_UP(max_pfn << PAGE_SHIFT, 1UL << TB_SHIFT) +
110110
CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING;
111111

112-
/* Adapt physical memory region size based on available memory */
113-
if (memory_tb < kaslr_regions[0].size_tb)
112+
/*
113+
* Adapt physical memory region size based on available memory,
114+
* except when CONFIG_PCI_P2PDMA is enabled. P2PDMA exposes the
115+
* device BAR space assuming the direct map space is large enough
116+
* for creating a ZONE_DEVICE mapping in the direct map corresponding
117+
* to the physical BAR address.
118+
*/
119+
if (!IS_ENABLED(CONFIG_PCI_P2PDMA) && (memory_tb < kaslr_regions[0].size_tb))
114120
kaslr_regions[0].size_tb = memory_tb;
115121

116122
/*

drivers/pci/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ config PCI_P2PDMA
194194
P2P DMA transactions must be between devices behind the same root
195195
port.
196196

197+
Enabling this option will reduce the entropy of x86 KASLR memory
198+
regions. For example - on a 46 bit system, the entropy goes down
199+
from 16 bits to 15 bits. The actual reduction in entropy depends
200+
on the physical address bits, on processor features, kernel config
201+
(5 level page table) and physical memory present on the system.
202+
197203
If unsure, say N.
198204

199205
config PCI_LABEL

kernel/dma/mapping.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ EXPORT_SYMBOL(dma_set_coherent_mask);
936936
* the system, else %false. Lack of addressing bits is the prime reason for
937937
* bounce buffering, but might not be the only one.
938938
*/
939-
bool dma_addressing_limited(struct device *dev)
939+
static bool __dma_addressing_limited(struct device *dev)
940940
{
941941
const struct dma_map_ops *ops = get_dma_ops(dev);
942942

@@ -948,6 +948,15 @@ bool dma_addressing_limited(struct device *dev)
948948
return false;
949949
return !dma_direct_all_ram_mapped(dev);
950950
}
951+
952+
bool dma_addressing_limited(struct device *dev)
953+
{
954+
if (!__dma_addressing_limited(dev))
955+
return false;
956+
957+
dev_dbg(dev, "device is DMA addressing limited\n");
958+
return true;
959+
}
951960
EXPORT_SYMBOL_GPL(dma_addressing_limited);
952961

953962
size_t dma_max_mapping_size(struct device *dev)

0 commit comments

Comments
 (0)