From: Sean Christopherson Date: Sat, 15 Mar 2025 03:09:28 +0000 (-0700) Subject: iommu/amd: Explicitly bail from enable_iommus_vapic() when in legacy mode X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=b30e046cfdcc883c627a1d0ede7e2d10d5c1a22c;p=thirdparty%2Fkernel%2Flinux.git iommu/amd: Explicitly bail from enable_iommus_vapic() when in legacy mode Bail early from enable_iommus_vapic() if IOMMUs are configured for either of the legacy modes, as it's absurdly difficult to see that iommu_ga_log_enable() is guaranteed to fail because iommu_init_ga_log() skips allocating the ga_log. Opportunistically have iommu_ga_log_enable() WARN if it's called without IOMMUs being configured to support AVIC/vAPIC. Cc: Suravee Suthikulpanit Signed-off-by: Sean Christopherson Reviewed-by: Vasant Hegde Signed-off-by: Joerg Roedel --- diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 3bdb380d23e9a..16a4567984b81 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -972,8 +972,8 @@ 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; + if (WARN_ON_ONCE(!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))) + return -EINVAL; iommu->ga_log = iommu_alloc_pages_node_sz(nid, GFP_KERNEL, GA_LOG_SIZE); if (!iommu->ga_log) @@ -3022,8 +3022,10 @@ static void enable_iommus_vapic(void) return; } - if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) && - !check_feature(FEATURE_GAM_VAPIC)) { + if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) + return; + + if (!check_feature(FEATURE_GAM_VAPIC)) { amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA; return; }