]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iommu/amd: Add NUMA node affinity for IOMMU log buffers
authorLi RongQing <lirongqing@baidu.com>
Wed, 11 Feb 2026 03:58:39 +0000 (22:58 -0500)
committerJoerg Roedel <joerg.roedel@amd.com>
Tue, 17 Mar 2026 12:26:38 +0000 (13:26 +0100)
Currently, PPR Log and GA logs for AMD IOMMU are allocated using
iommu_alloc_pages_sz(), which does not account for NUMA affinity. This can
lead to remote memory access latencies if the memory is allocated on a
different node than the IOMMU hardware.

Switch to iommu_alloc_pages_node_sz() to ensure that these data structures
are allocated on the same NUMA node as the IOMMU device. If the node
information is unavailable, it defaults to NUMA_NO_NODE.

Signed-off-by: Li RongQing <lirongqing@baidu.com>
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Ankit Soni <Ankit.Soni@amd.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
drivers/iommu/amd/init.c

index f3fd7f39efb488893b8c4cda20b504124ebc9b89..56ad020df49497f8834cde0cf168412111764cac 100644 (file)
@@ -848,10 +848,11 @@ static void __init free_command_buffer(struct amd_iommu *iommu)
 void *__init iommu_alloc_4k_pages(struct amd_iommu *iommu, gfp_t gfp,
                                  size_t size)
 {
+       int nid = iommu->dev ? dev_to_node(&iommu->dev->dev) : NUMA_NO_NODE;
        void *buf;
 
        size = PAGE_ALIGN(size);
-       buf = iommu_alloc_pages_sz(gfp, size);
+       buf = iommu_alloc_pages_node_sz(nid, gfp, size);
        if (!buf)
                return NULL;
        if (check_feature(FEATURE_SNP) &&
@@ -954,14 +955,16 @@ static int iommu_ga_log_enable(struct amd_iommu *iommu)
 
 static int iommu_init_ga_log(struct amd_iommu *iommu)
 {
+       int nid = iommu->dev ? dev_to_node(&iommu->dev->dev) : NUMA_NO_NODE;
+
        if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))
                return 0;
 
-       iommu->ga_log = iommu_alloc_pages_sz(GFP_KERNEL, GA_LOG_SIZE);
+       iommu->ga_log = iommu_alloc_pages_node_sz(nid, GFP_KERNEL, GA_LOG_SIZE);
        if (!iommu->ga_log)
                goto err_out;
 
-       iommu->ga_log_tail = iommu_alloc_pages_sz(GFP_KERNEL, 8);
+       iommu->ga_log_tail = iommu_alloc_pages_node_sz(nid, GFP_KERNEL, 8);
        if (!iommu->ga_log_tail)
                goto err_out;