]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iommu/amd: WARN if KVM calls GA IRTE helpers without virtual APIC support
authorSean Christopherson <seanjc@google.com>
Wed, 11 Jun 2025 22:45:59 +0000 (15:45 -0700)
committerSean Christopherson <seanjc@google.com>
Mon, 23 Jun 2025 16:50:48 +0000 (09:50 -0700)
WARN if KVM attempts to update IRTE entries when virtual APIC isn't fully
supported, as KVM should guard all such calls on IRQ posting being enabled.

Link: https://lore.kernel.org/r/20250611224604.313496-58-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
drivers/iommu/amd/iommu.c

index 6149aece0eacf808dde752a257532b8f6eade7b3..4b0cc249771f5baf8f92a5dfc6f12c507c2ca10b 100644 (file)
@@ -3836,8 +3836,10 @@ int amd_iommu_update_ga(int cpu, void *data)
        struct amd_ir_data *ir_data = (struct amd_ir_data *)data;
        struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
 
-       if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) ||
-           !entry || !entry->lo.fields_vapic.guest_mode)
+       if (WARN_ON_ONCE(!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)))
+               return -EINVAL;
+
+       if (!entry || !entry->lo.fields_vapic.guest_mode)
                return 0;
 
        if (!ir_data->iommu)
@@ -3856,7 +3858,10 @@ int amd_iommu_activate_guest_mode(void *data, int cpu)
        struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
        u64 valid;
 
-       if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) || !entry)
+       if (WARN_ON_ONCE(!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)))
+               return -EINVAL;
+
+       if (!entry)
                return 0;
 
        valid = entry->lo.fields_vapic.valid;
@@ -3885,8 +3890,10 @@ int amd_iommu_deactivate_guest_mode(void *data)
        struct irq_cfg *cfg = ir_data->cfg;
        u64 valid;
 
-       if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) ||
-           !entry || !entry->lo.fields_vapic.guest_mode)
+       if (WARN_ON_ONCE(!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)))
+               return -EINVAL;
+
+       if (!entry || !entry->lo.fields_vapic.guest_mode)
                return 0;
 
        valid = entry->lo.fields_remap.valid;