Skip to contentSkip to conversation

Add support for AMD IOMMU GAPPI

PATCH Superseded Sairaj Kodilkar 3 participants 19 messages Oct 15 – Oct 22

Subsystems (8)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover Add support for AMD IOMMU GAPPI

Introduction
============
On newer generations of AMD processors, IOMMU AVIC/x2AVIC guest-mode interrupt remapping can use Guest APIC Physical Processor Interrupt (GAPPI) as an alternative host-notification path when device interrupts target a vCPU that is not running (IRTE[IsRun] = 0).

With AVIC enabled, the IOMMU posts device interrupts into the guest virtual APIC backing page. When the vCPU is not running, KVM must additionally be notified so it can schedule the vCPU.

The legacy notification path is the GA log (GALOG): the IOMMU appends vCPU tags to a shared GA log buffer and raises a single GA log interrupt. KVM registers a notifier and scans the buffer to decide which vCPUs to wake. Under heavy interrupt load this adds latency and can overflow the buffer because all wakeups funnel through one interrupt and one shared log.

Guest APIC Physical Processor Interrupt (GAPPI), defined in section 2.2.5.4 of the AMD I/O Virtualization Technology (IOMMU) Specification [1], is an alternative. With GAPPI enabled, the IOMMU still updates the guest vAPIC backing page IRR, but may deliver a physical APIC interrupt directly to IRTE[Destination], using IRTE[GATag][7:0] as the vector. This distributes host wakeup notifications across CPUs instead of centralizing them in a log buffer.

This series programs guest-mode IRTEs accordingly: IRTE[Destination] carries the target host physical APIC ID, IRTE[GATag] is set to POSTED_INTR_WAKEUP_VECTOR, and IRTE[GAPPIDis] / IRTE[GALogIntr] are set based on whether KVM requests host wakeup. GAPPI is selected at boot via the amd_iommu=gappi kernel parameter on capable hardware, otherwise the existing GA log path is unchanged.

SVM/AMD IOMMU interface changes
===============================
The first four patches refactor the SVM/AMD IOMMU interface ahead of GAPPI.

The cpu field is renamed to apicid because it carries the host physical APIC ID for IRTE[Destination], not a Linux CPU number.

The ga_log_intr boolean is renamed to wakeup_intr (and the synthetic AVIC_PHYSICAL_ID_ENTRY_GA_LOG_INTR shadow bit to AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR). wakeup_intr describes KVM's intent (request host wakeup while the vCPU is not running), not a specific hardware mechanism.

A separate is_running boolean is added to IOMMU interface because GAPPI requires a valid apicid in IRTE[Destination] even when the vCPU is not running. The prior encoding (apicid >= 0 means running, apicid == -1 means not running) no longer works once apicid carries the GAPPI destination while IRTE[IsRun] is clear. The IOMMU driver keys IRTE[IsRun] and destination programming off this explicit boolean instead of inferring running state from apicid.

KVM GAPPI wakeup scheme
=======================
SVM follows the Intel posted-interrupt wakeup model already used by VMX. Each pCPU maintains a list of blocked vCPUs that may be woken by a GAPPI delivery to that CPU. When a vCPU blocks while waiting for a device interrupt, SVM enqueues it on the wakeup list of the pCPU on which it was previously running (gappi_cpu) and passes that pCPU's physical APIC ID to the IOMMU to program IRTE[Destination]. The rationale is that the vCPU is likely to run again on the same pCPU, which is common when vCPUs are pinned; targeting GAPPI notifications there reduces unnecessary VMEXITs from GAPPI deliveries on other CPUs. When the vCPU is scheduled in again, it is removed from the list and IRTE[Destination] is updated to the current pCPU.

List maintenance is moved from VMX layer to common KVM layer so that both VMX and SVM layer can share the same list handling code.

Note
====
kvm_pi_enable_wakeup_handler() and kvm_pi_disable_wakeup_handler() take the target pCPU explicitly instead of using vcpu->cpu, because on SVM the two can differ. avic_vcpu_load() returns early while the vCPU is blocking and leaves the target wakeup CPU untouched, but the generic layer still refreshes vcpu->cpu on every load. Using vcpu->cpu would then unlink the vCPU under the wrong per-pCPU lock, so SVM tracks the pCPU it last programmed in svm->gappi_cpu and passes that instead.

Changes since v4
================
Patch 6:
- Initialize gappi_cpu to 0 instead of -1, the list_empty() check handles the initial case when vCPU is not on the wakeup list of CPU 0 [Vasant]

Changes since v3
================
https://lore.kernel.org/all/[email protected]/

Patch 3:
- Make amd_iommu_activate_guest_mode() as wrapper around __amd_iommu_activate_guest_mode() to in order to hardcode is_running flag to "true" for external calls [Sean]

Patch 5:
- Newly introduced, moves wakeup list handling from VMX to the KVM layer

    [Sean]

Patch 6:
- Use common list handling functions introduced in patch 5.
- Remove list addition during pi_update_irte by moving list handling

    functions before list_empty(&svm->ir_list) check.

Changes since v2
================
https://lore.kernel.org/linux-iommu/[email protected]/

Patch[1-6]
- Expand commit messages to explain GAPPI, the interface changes, and the per-CPU wakeup list scheme [Sean].

Patch[1-3]
- Split the monolithic SVM/IOMMU API refactor into four preparatory patches [Sean]
- Rename posted_intr to wakeup_intr to reflect host wakeup intent, not guest interrupt posting [Sean]
- Pass vCPU running status with a extra parameter (is_running) instead of flags.

Patch[4,5]
- Move ga_tag=POSTED_INTR_WAKEUP_VECTOR setting from IOMMU to SVM layer.

Changes since V1:
================
https://lore.kernel.org/all/[email protected]/

Patch4
- Disable interrupts while holding wakeup list lock inside [sashiko] avic_add_vcpu_to_gappi_wakeup_list and avic_remove_vcpu_from_gappi_wakeup_list
- Unregister posted_intr_wakeup_handler during module unload [sashiko]

Patch5
- Disable GAPPI feature during kexec and suspend path [sashiko]

------

[1] https://docs.amd.com/v/u/en-US/48882_3.11_IOMMU_PUB

------

Sairaj Kodilkar (7):
iommu/amd: KVM: SVM: Rename cpu to apicid in IOMMU interface iommu/amd: KVM: SVM: Rename ga_log_intr to wakeup_intr in IOMMU
interface
iommu/amd: KVM: SVM: Add explicit vCPU running state to IOMMU
interface
iommu/amd: Program guest-mode IRTEs for GAPPI wakeup when IRTE[IsRun]

    = 0

KVM: VMX: Factor out wakeup list handling code to KVM
KVM: SVM: Add support for AMD IOMMU Guest APIC Physical Processor
Interrupt (GAPPI)
iommu/amd: Provide kernel command line option to enable GAPPI

 .../admin-guide/kernel-parameters.txt         |   3 +-
 Documentation/arch/x86/iommu.rst              |  22 ++++
 arch/x86/include/asm/irq_remapping.h          |   5 +-
 arch/x86/include/asm/kvm-x86-ops.h            |   1 +
 arch/x86/include/asm/kvm_host.h               |   1 +
 arch/x86/include/asm/svm.h                    |   9 +-
 arch/x86/kvm/svm/avic.c                       |  90 ++++++++++----
 arch/x86/kvm/svm/svm.c                        |   1 +
 arch/x86/kvm/svm/svm.h                        |   4 +
 arch/x86/kvm/vmx/common.h                     |   3 -
 arch/x86/kvm/vmx/main.c                       |   6 +
 arch/x86/kvm/vmx/posted_intr.c                |  82 +------------
 arch/x86/kvm/vmx/tdx.c                        |   1 -
 arch/x86/kvm/vmx/vmx.c                        |  14 +--
 arch/x86/kvm/vmx/x86_ops.h                    |   1 +
 arch/x86/kvm/x86.c                            | 111 ++++++++++++++++++
 drivers/iommu/amd/amd_iommu_types.h           |   6 +-
 drivers/iommu/amd/init.c                      |  31 ++++-
 drivers/iommu/amd/iommu.c                     |  65 ++++++----
 include/linux/amd-iommu.h                     |  16 ++-
 include/linux/kvm_host.h                      |   6 +
 21 files changed, 323 insertions(+), 155 deletions(-)

base-commit: 4056b3c9d3c92ea45955641dbafeb9b960e146ef

Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/7 iommu/amd: KVM: SVM: Rename cpu to apicid in IOMMU interface

The cpu field passed from SVM to the AMD IOMMU driver does not hold a linux CPU number. It carries the host physical APIC ID used to program the IRTE Destination field when the target vCPU is running (IRTE[IsRun] = 1).

Rename the field to apicid everywhere in the IOMMU interface so the name matches the hardware semantics.

No functional change is intended.

---
 arch/x86/include/asm/irq_remapping.h |  2 +-
 arch/x86/kvm/svm/avic.c              | 12 +++++-----
 drivers/iommu/amd/iommu.c            | 35 ++++++++++++++--------------
 include/linux/amd-iommu.h            |  8 +++----
 4 files changed, 29 insertions(+), 28 deletions(-)
arch/x86/include/asm/irq_remapping.h +1 -1
index 37b94f484ef3..263f4df429d8 100644
@@ -35,7 +35,7 @@ struct amd_iommu_pi_data {
 	u64 vapic_addr;		/* Physical address of the vCPU's vAPIC. */
 	u32 ga_tag;
 	u32 vector;		/* Guest vector of the interrupt */
-	int cpu;
+	int apicid;
 	bool ga_log_intr;
 	bool is_guest_mode;
 	void *ir_data;
arch/x86/kvm/svm/avic.c +6 -6
index 96ca39c0045f..5ac5ce4039a6 100644
@@ -960,9 +960,9 @@ int avic_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm,
 		 */
 		entry = svm->avic_physical_id_entry;
 		if (entry & AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK) {
-			pi_data.cpu = entry & AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK;
+			pi_data.apicid = entry & AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK;
 		} else {
-			pi_data.cpu = -1;
+			pi_data.apicid = -1;
 			pi_data.ga_log_intr = entry & AVIC_PHYSICAL_ID_ENTRY_GA_LOG_INTR;
 		}
 
@@ -1015,7 +1015,7 @@ enum avic_vcpu_action {
 	AVIC_START_BLOCKING	= BIT(1),
 };
 
-static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int cpu,
+static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid,
 					    enum avic_vcpu_action action)
 {
 	bool ga_log_intr = (action & AVIC_START_BLOCKING);
@@ -1035,9 +1035,9 @@ static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int cpu,
 		void *data = irqfd->irq_bypass_data;
 
 		if (!(action & AVIC_TOGGLE_ON_OFF))
-			WARN_ON_ONCE(amd_iommu_update_ga(data, cpu, ga_log_intr));
-		else if (cpu >= 0)
-			WARN_ON_ONCE(amd_iommu_activate_guest_mode(data, cpu, ga_log_intr));
+			WARN_ON_ONCE(amd_iommu_update_ga(data, apicid, ga_log_intr));
+		else if (apicid >= 0)
+			WARN_ON_ONCE(amd_iommu_activate_guest_mode(data, apicid, ga_log_intr));
 		else
 			WARN_ON_ONCE(amd_iommu_deactivate_guest_mode(data));
 	}
drivers/iommu/amd/iommu.c +18 -17
index 56262f6b1f70..aa9848d57f6b 100644
@@ -3993,14 +3993,14 @@ static const struct irq_domain_ops amd_ir_domain_ops = {
 	.deactivate = irq_remapping_deactivate,
 };
 
-static void __amd_iommu_update_ga(struct irte_ga *entry, int cpu,
+static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid,
 				  bool ga_log_intr)
 {
-	if (cpu >= 0) {
+	if (apicid >= 0) {
 		entry->lo.fields_vapic.destination =
-					APICID_TO_IRTE_DEST_LO(cpu);
+					APICID_TO_IRTE_DEST_LO(apicid);
 		entry->hi.fields.destination =
-					APICID_TO_IRTE_DEST_HI(cpu);
+					APICID_TO_IRTE_DEST_HI(apicid);
 		entry->lo.fields_vapic.is_run = true;
 		entry->lo.fields_vapic.ga_log_intr = false;
 	} else {
@@ -4013,20 +4013,21 @@ static void __amd_iommu_update_ga(struct irte_ga *entry, int cpu,
  * Update the pCPU information for an IRTE that is configured to post IRQs to
  * a vCPU, without issuing an IOMMU invalidation for the IRTE.
  *
- * If the vCPU is associated with a pCPU (@cpu >= 0), configure the Destination
- * with the pCPU's APIC ID, set IsRun, and clear GALogIntr.  If the vCPU isn't
- * associated with a pCPU (@cpu < 0), clear IsRun and set/clear GALogIntr based
- * on input from the caller (e.g. KVM only requests GALogIntr when the vCPU is
- * blocking and requires a notification wake event).  I.e. treat vCPUs that are
- * associated with a pCPU as running.  This API is intended to be used when a
- * vCPU is scheduled in/out (or stops running for any reason), to do a fast
- * update of IsRun, GALogIntr, and (conditionally) Destination.
+ * If the vCPU is associated with a pCPU (@apicid >= 0), configure the
+ * Destination with the pCPU's APIC ID, set IsRun, and clear GALogIntr.  If the
+ * vCPU isn't associated with a pCPU (@apicid < 0), clear IsRun and set/clear
+ * GALogIntr based on input from the caller (e.g. KVM only requests GALogIntr
+ * when the vCPU is blocking and requires a notification wake event).  I.e.
+ * treat vCPUs that are associated with a pCPU as running.  This API is
+ * intended to be used when a vCPU is scheduled in/out (or stops running for
+ * any reason), to do a fast update of IsRun, GALogIntr, and (conditionally)
+ * Destination.
  *
  * Per the IOMMU spec, the Destination, IsRun, and GATag fields are not cached
  * and thus don't require an invalidation to ensure the IOMMU consumes fresh
  * information.
  */
-int amd_iommu_update_ga(void *data, int cpu, bool ga_log_intr)
+int amd_iommu_update_ga(void *data, int apicid, bool ga_log_intr)
 {
 	struct amd_ir_data *ir_data = (struct amd_ir_data *)data;
 	struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
@@ -4040,14 +4041,14 @@ int amd_iommu_update_ga(void *data, int cpu, bool ga_log_intr)
 	if (!ir_data->iommu)
 		return -ENODEV;
 
-	__amd_iommu_update_ga(entry, cpu, ga_log_intr);
+	__amd_iommu_update_ga(entry, apicid, ga_log_intr);
 
 	return __modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid,
 				ir_data->irq_2_irte.index, entry);
 }
 EXPORT_SYMBOL(amd_iommu_update_ga);
 
-int amd_iommu_activate_guest_mode(void *data, int cpu, bool ga_log_intr)
+int amd_iommu_activate_guest_mode(void *data, int apicid, bool ga_log_intr)
 {
 	struct amd_ir_data *ir_data = (struct amd_ir_data *)data;
 	struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
@@ -4070,7 +4071,7 @@ int amd_iommu_activate_guest_mode(void *data, int cpu, bool ga_log_intr)
 	entry->hi.fields.vector            = ir_data->ga_vector;
 	entry->lo.fields_vapic.ga_tag      = ir_data->ga_tag;
 
-	__amd_iommu_update_ga(entry, cpu, ga_log_intr);
+	__amd_iommu_update_ga(entry, apicid, ga_log_intr);
 
 	return modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid,
 			      ir_data->irq_2_irte.index, entry);
@@ -4141,7 +4142,7 @@ static int amd_ir_set_vcpu_affinity(struct irq_data *data, void *info)
 		ir_data->ga_vector = pi_data->vector;
 		ir_data->ga_tag = pi_data->ga_tag;
 		if (pi_data->is_guest_mode)
-			ret = amd_iommu_activate_guest_mode(ir_data, pi_data->cpu,
+			ret = amd_iommu_activate_guest_mode(ir_data, pi_data->apicid,
 							    pi_data->ga_log_intr);
 		else
 			ret = amd_iommu_deactivate_guest_mode(ir_data);
include/linux/amd-iommu.h +4 -4
index edcee9f5335a..2c6232aefafa 100644
@@ -30,8 +30,8 @@ static inline void amd_iommu_detect(void) { }
 /* IOMMU AVIC Function */
 extern int amd_iommu_register_ga_log_notifier(int (*notifier)(u32));
 
-extern int amd_iommu_update_ga(void *data, int cpu, bool ga_log_intr);
-extern int amd_iommu_activate_guest_mode(void *data, int cpu, bool ga_log_intr);
+extern int amd_iommu_update_ga(void *data, int apicid, bool ga_log_intr);
+extern int amd_iommu_activate_guest_mode(void *data, int apicid, bool ga_log_intr);
 extern int amd_iommu_deactivate_guest_mode(void *data);
 
 #else /* defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) */
@@ -42,12 +42,12 @@ amd_iommu_register_ga_log_notifier(int (*notifier)(u32))
 	return 0;
 }
 
-static inline int amd_iommu_update_ga(void *data, int cpu, bool ga_log_intr)
+static inline int amd_iommu_update_ga(void *data, int apicid, bool ga_log_intr)
 {
 	return 0;
 }
 
-static inline int amd_iommu_activate_guest_mode(void *data, int cpu, bool ga_log_intr)
+static inline int amd_iommu_activate_guest_mode(void *data, int apicid, bool ga_log_intr)
 {
 	return 0;
 }

base-commit: 4056b3c9d3c92ea45955641dbafeb9b960e146ef

Signature · 1 line
2.34.1
#2 lore raw

PATCH v5 2/7 iommu/amd: KVM: SVM: Rename ga_log_intr to wakeup_intr in IOMMU interface

In reply to Sairaj Kodilkar

When AVIC is enabled, device interrupts are posted into the guest virtual APIC backing page regardless of vCPU running state. When the vCPU is not running, KVM may additionally need the IOMMU to notify the host so the vCPU can be woken, historically via the GA log mechanism.

The existing ga_log_intr name is tied to one specific hardware mechanism. Guest APIC Physical Processor Interrupt (GAPPI) provides an alternative host-notification path when the vCPU is not running, i.e., IRTE[IsRun] = 0. The KVM-side intent is the same in both cases: request host wakeup notification while the vCPU is blocked.

Rename ga_log_intr to wakeup_intr in the IOMMU API to describe KVM's intent rather than a single hardware knob. The IOMMU driver still maps wakeup_intr to IRTE[GALogIntr] in this patch; GAPPI support is added in following patches.

Similarly rename the synthetic AVIC physical ID table shadow bit from AVIC_PHYSICAL_ID_ENTRY_GA_LOG_INTR to AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR.

No functional change is intended.

---
 arch/x86/include/asm/irq_remapping.h |  2 +-
 arch/x86/include/asm/svm.h           |  9 +++++----
 arch/x86/kvm/svm/avic.c              | 26 +++++++++++++-------------
 drivers/iommu/amd/iommu.c            | 16 ++++++++--------
 include/linux/amd-iommu.h            |  8 ++++----
 5 files changed, 31 insertions(+), 30 deletions(-)
arch/x86/include/asm/irq_remapping.h +1 -1
index 263f4df429d8..789e3e154600 100644
@@ -36,7 +36,7 @@ struct amd_iommu_pi_data {
 	u32 ga_tag;
 	u32 vector;		/* Guest vector of the interrupt */
 	int apicid;
-	bool ga_log_intr;
+	bool wakeup_intr;
 	bool is_guest_mode;
 	void *ir_data;
 };
arch/x86/include/asm/svm.h +5 -4
index aa63431ba92c..3de222d6ae15 100644
@@ -260,11 +260,12 @@ struct __attribute__ ((__packed__)) vmcb_control_area {
 #define AVIC_LOGICAL_ID_ENTRY_VALID_MASK		(1 << 31)
 
 /*
- * GA_LOG_INTR is a synthetic flag that's never propagated to hardware-visible
- * tables.  GA_LOG_INTR is set if the vCPU needs device posted IRQs to generate
- * GA log interrupts to wake the vCPU (because it's blocking or about to block).
+ * WAKEUP_INTR is a synthetic flag that's never propagated to hardware-visible
+ * tables.  WAKEUP_INTR is set if the vCPU needs device posted IRQs to generate
+ * GA log/GAPPI interrupts to wake the vCPU (because it's blocking or about to
+ * block).
  */
-#define AVIC_PHYSICAL_ID_ENTRY_GA_LOG_INTR		BIT_ULL(61)
+#define AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR		BIT_ULL(61)
 
 #define AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK	GENMASK_ULL(11, 0)
 #define AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK	GENMASK_ULL(51, 12)
arch/x86/kvm/svm/avic.c +13 -13
index 5ac5ce4039a6..edbdb5d75062 100644
@@ -963,7 +963,7 @@ int avic_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm,
 			pi_data.apicid = entry & AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK;
 		} else {
 			pi_data.apicid = -1;
-			pi_data.ga_log_intr = entry & AVIC_PHYSICAL_ID_ENTRY_GA_LOG_INTR;
+			pi_data.wakeup_intr = entry & AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR;
 		}
 
 		ret = irq_set_vcpu_affinity(host_irq, &pi_data);
@@ -1002,15 +1002,15 @@ enum avic_vcpu_action {
 	 * No unique action is required to deal with a vCPU that stops/starts
 	 * running.  A vCPU that starts running by definition stops blocking as
 	 * well, and a vCPU that stops running can't have been blocking, i.e.
-	 * doesn't need to toggle GALogIntr.
+	 * doesn't need to toggle host wakeup notification.
 	 */
 	AVIC_START_RUNNING	= 0,
 	AVIC_STOP_RUNNING	= 0,
 
 	/*
-	 * When a vCPU starts blocking, KVM needs to set the GALogIntr flag
-	 * int all associated IRTEs so that KVM can wake the vCPU if an IRQ is
-	 * sent to the vCPU.
+	 * When a vCPU starts blocking, KVM needs to request host wakeup
+	 * notification in all associated IRTEs so that KVM can wake the vCPU
+	 * if an IRQ is sent to the vCPU.
 	 */
 	AVIC_START_BLOCKING	= BIT(1),
 };
@@ -1018,7 +1018,7 @@ enum avic_vcpu_action {
 static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid,
 					    enum avic_vcpu_action action)
 {
-	bool ga_log_intr = (action & AVIC_START_BLOCKING);
+	bool wakeup_intr = (action & AVIC_START_BLOCKING);
 	struct vcpu_svm *svm = to_svm(vcpu);
 	struct kvm_kernel_irqfd *irqfd;
 
@@ -1035,9 +1035,9 @@ static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid,
 		void *data = irqfd->irq_bypass_data;
 
 		if (!(action & AVIC_TOGGLE_ON_OFF))
-			WARN_ON_ONCE(amd_iommu_update_ga(data, apicid, ga_log_intr));
+			WARN_ON_ONCE(amd_iommu_update_ga(data, apicid, wakeup_intr));
 		else if (apicid >= 0)
-			WARN_ON_ONCE(amd_iommu_activate_guest_mode(data, apicid, ga_log_intr));
+			WARN_ON_ONCE(amd_iommu_activate_guest_mode(data, apicid, wakeup_intr));
 		else
 			WARN_ON_ONCE(amd_iommu_deactivate_guest_mode(data));
 	}
@@ -1073,7 +1073,7 @@ static void __avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu,
 	WARN_ON_ONCE(entry & AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK);
 
 	entry &= ~(AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK |
-		   AVIC_PHYSICAL_ID_ENTRY_GA_LOG_INTR);
+		   AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR);
 	entry |= (h_physical_id & AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK);
 	entry |= AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK;
 
@@ -1134,7 +1134,7 @@ static void __avic_vcpu_put(struct kvm_vcpu *vcpu, enum avic_vcpu_action action)
 
 	avic_update_iommu_vcpu_affinity(vcpu, -1, action);
 
-	WARN_ON_ONCE(entry & AVIC_PHYSICAL_ID_ENTRY_GA_LOG_INTR);
+	WARN_ON_ONCE(entry & AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR);
 
 	/*
 	 * Keep the previous APIC ID in the entry so that a rogue doorbell from
@@ -1146,11 +1146,11 @@ static void __avic_vcpu_put(struct kvm_vcpu *vcpu, enum avic_vcpu_action action)
 		WRITE_ONCE(kvm_svm->avic_physical_id_table[vcpu->vcpu_id], entry);
 
 	/*
-	 * Note!  Don't set AVIC_PHYSICAL_ID_ENTRY_GA_LOG_INTR in the table as
+	 * Note!  Don't set AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR in the table as
 	 * it's a synthetic flag that usurps an unused should-be-zero bit.
 	 */
 	if (action & AVIC_START_BLOCKING)
-		entry |= AVIC_PHYSICAL_ID_ENTRY_GA_LOG_INTR;
+		entry |= AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR;
 
 	svm->avic_physical_id_entry = entry;
 
@@ -1182,7 +1182,7 @@ void avic_vcpu_put(struct kvm_vcpu *vcpu)
 		 * The vCPU was preempted while blocking, ensure its IRTEs are
 		 * configured to generate GA Log Interrupts.
 		 */
-		if (!(WARN_ON_ONCE(!(entry & AVIC_PHYSICAL_ID_ENTRY_GA_LOG_INTR))))
+		if (!(WARN_ON_ONCE(!(entry & AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR))))
 			return;
 	}
 
drivers/iommu/amd/iommu.c +8 -8
index aa9848d57f6b..878567708737 100644
@@ -3994,7 +3994,7 @@ static const struct irq_domain_ops amd_ir_domain_ops = {
 };
 
 static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid,
-				  bool ga_log_intr)
+				  bool wakeup_intr)
 {
 	if (apicid >= 0) {
 		entry->lo.fields_vapic.destination =
@@ -4005,7 +4005,7 @@ static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid,
 		entry->lo.fields_vapic.ga_log_intr = false;
 	} else {
 		entry->lo.fields_vapic.is_run = false;
-		entry->lo.fields_vapic.ga_log_intr = ga_log_intr;
+		entry->lo.fields_vapic.ga_log_intr = wakeup_intr;
 	}
 }
 
@@ -4016,7 +4016,7 @@ static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid,
  * If the vCPU is associated with a pCPU (@apicid >= 0), configure the
  * Destination with the pCPU's APIC ID, set IsRun, and clear GALogIntr.  If the
  * vCPU isn't associated with a pCPU (@apicid < 0), clear IsRun and set/clear
- * GALogIntr based on input from the caller (e.g. KVM only requests GALogIntr
+ * GALogIntr based on input from the caller (e.g. KVM only requests wakeup_intr
  * when the vCPU is blocking and requires a notification wake event).  I.e.
  * treat vCPUs that are associated with a pCPU as running.  This API is
  * intended to be used when a vCPU is scheduled in/out (or stops running for
@@ -4027,7 +4027,7 @@ static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid,
  * and thus don't require an invalidation to ensure the IOMMU consumes fresh
  * information.
  */
-int amd_iommu_update_ga(void *data, int apicid, bool ga_log_intr)
+int amd_iommu_update_ga(void *data, int apicid, bool wakeup_intr)
 {
 	struct amd_ir_data *ir_data = (struct amd_ir_data *)data;
 	struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
@@ -4041,14 +4041,14 @@ int amd_iommu_update_ga(void *data, int apicid, bool ga_log_intr)
 	if (!ir_data->iommu)
 		return -ENODEV;
 
-	__amd_iommu_update_ga(entry, apicid, ga_log_intr);
+	__amd_iommu_update_ga(entry, apicid, wakeup_intr);
 
 	return __modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid,
 				ir_data->irq_2_irte.index, entry);
 }
 EXPORT_SYMBOL(amd_iommu_update_ga);
 
-int amd_iommu_activate_guest_mode(void *data, int apicid, bool ga_log_intr)
+int amd_iommu_activate_guest_mode(void *data, int apicid, bool wakeup_intr)
 {
 	struct amd_ir_data *ir_data = (struct amd_ir_data *)data;
 	struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
@@ -4071,7 +4071,7 @@ int amd_iommu_activate_guest_mode(void *data, int apicid, bool ga_log_intr)
 	entry->hi.fields.vector            = ir_data->ga_vector;
 	entry->lo.fields_vapic.ga_tag      = ir_data->ga_tag;
 
-	__amd_iommu_update_ga(entry, apicid, ga_log_intr);
+	__amd_iommu_update_ga(entry, apicid, wakeup_intr);
 
 	return modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid,
 			      ir_data->irq_2_irte.index, entry);
@@ -4143,7 +4143,7 @@ static int amd_ir_set_vcpu_affinity(struct irq_data *data, void *info)
 		ir_data->ga_tag = pi_data->ga_tag;
 		if (pi_data->is_guest_mode)
 			ret = amd_iommu_activate_guest_mode(ir_data, pi_data->apicid,
-							    pi_data->ga_log_intr);
+							    pi_data->wakeup_intr);
 		else
 			ret = amd_iommu_deactivate_guest_mode(ir_data);
 	} else {
include/linux/amd-iommu.h +4 -4
index 2c6232aefafa..e20c909edc56 100644
@@ -30,8 +30,8 @@ static inline void amd_iommu_detect(void) { }
 /* IOMMU AVIC Function */
 extern int amd_iommu_register_ga_log_notifier(int (*notifier)(u32));
 
-extern int amd_iommu_update_ga(void *data, int apicid, bool ga_log_intr);
-extern int amd_iommu_activate_guest_mode(void *data, int apicid, bool ga_log_intr);
+extern int amd_iommu_update_ga(void *data, int apicid, bool wakeup_intr);
+extern int amd_iommu_activate_guest_mode(void *data, int apicid, bool wakeup_intr);
 extern int amd_iommu_deactivate_guest_mode(void *data);
 
 #else /* defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) */
@@ -42,12 +42,12 @@ amd_iommu_register_ga_log_notifier(int (*notifier)(u32))
 	return 0;
 }
 
-static inline int amd_iommu_update_ga(void *data, int apicid, bool ga_log_intr)
+static inline int amd_iommu_update_ga(void *data, int apicid, bool wakeup_intr)
 {
 	return 0;
 }
 
-static inline int amd_iommu_activate_guest_mode(void *data, int apicid, bool ga_log_intr)
+static inline int amd_iommu_activate_guest_mode(void *data, int apicid, bool wakeup_intr)
 {
 	return 0;
 }
Signature · 1 line
2.34.1
#3 lore raw

PATCH v5 3/7 iommu/amd: KVM: SVM: Add explicit vCPU running state to IOMMU interface

In reply to Sairaj Kodilkar

Guest APIC Physical Processor Interrupt (GAPPI) is an AMD IOMMU mechanism for notifying the host when a device interrupt targets a non-running vCPU (IRTE[IsRun] = 0). Unlike the GA log path, GAPPI delivers a physical APIC interrupt directly to the host CPU described by IRTE[Destination], with the vector carried in IRTE[GATag], while still posting the interrupt into the guest virtual APIC backing page as usual.

In GAPPI mode, the IOMMU delivers the notification to the host CPU using the physical APIC ID in IRTE[Destination] and the vector in IRTE[GATag]. KVM must therefore supply a valid apicid even when the vCPU is not running. The prior interface inferred running state from apicid: apicid >= 0 meant running and apicid == -1 meant not running. That encoding breaks once apicid carries the GAPPI destination while the vCPU is not running; the IOMMU driver can no longer derive vCPU running state from apicid alone and needs an explicit indication from KVM.

Add an explicit is_running indication to the IOMMU interface so that SVM can pass vCPU running state to the IOMMU.

SVM calls amd_iommu_activate_guest_mode() only when the vCPU is running, so keep is_running out of the exported prototype and make it a thin wrapper that hardcodes is_running = true. The IOMMU internal caller, amd_ir_set_vcpu_affinity(), calls __amd_iommu_activate_guest_mode() directly and passes the running state supplied by KVM, i.e. it handles both a running and a non-running vCPU.

No functional change is intended.

---
 arch/x86/include/asm/irq_remapping.h |  1 +
 arch/x86/kvm/svm/avic.c              |  7 ++++--
 drivers/iommu/amd/iommu.c            | 34 ++++++++++++++++------------
 include/linux/amd-iommu.h            |  6 +++--
 4 files changed, 30 insertions(+), 18 deletions(-)
arch/x86/include/asm/irq_remapping.h +1 -0
index 789e3e154600..af0cdfa32c44 100644
@@ -37,6 +37,7 @@ struct amd_iommu_pi_data {
 	u32 vector;		/* Guest vector of the interrupt */
 	int apicid;
 	bool wakeup_intr;
+	bool is_running;
 	bool is_guest_mode;
 	void *ir_data;
 };
arch/x86/kvm/svm/avic.c +5 -2
index edbdb5d75062..8b1fa5bded3d 100644
@@ -961,9 +961,11 @@ int avic_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm,
 		entry = svm->avic_physical_id_entry;
 		if (entry & AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK) {
 			pi_data.apicid = entry & AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK;
+			pi_data.is_running = true;
 		} else {
 			pi_data.apicid = -1;
 			pi_data.wakeup_intr = entry & AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR;
+			pi_data.is_running = false;
 		}
 
 		ret = irq_set_vcpu_affinity(host_irq, &pi_data);
@@ -1019,6 +1021,7 @@ static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid,
 					    enum avic_vcpu_action action)
 {
 	bool wakeup_intr = (action & AVIC_START_BLOCKING);
+	bool is_running = apicid >= 0;
 	struct vcpu_svm *svm = to_svm(vcpu);
 	struct kvm_kernel_irqfd *irqfd;
 
@@ -1035,8 +1038,8 @@ static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid,
 		void *data = irqfd->irq_bypass_data;
 
 		if (!(action & AVIC_TOGGLE_ON_OFF))
-			WARN_ON_ONCE(amd_iommu_update_ga(data, apicid, wakeup_intr));
-		else if (apicid >= 0)
+			WARN_ON_ONCE(amd_iommu_update_ga(data, apicid, wakeup_intr, is_running));
+		else if (is_running)
 			WARN_ON_ONCE(amd_iommu_activate_guest_mode(data, apicid, wakeup_intr));
 		else
 			WARN_ON_ONCE(amd_iommu_deactivate_guest_mode(data));
drivers/iommu/amd/iommu.c +20 -14
index 878567708737..c0eec32ee3cb 100644
@@ -3994,9 +3994,9 @@ static const struct irq_domain_ops amd_ir_domain_ops = {
 };
 
 static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid,
-				  bool wakeup_intr)
+				  bool wakeup_intr, bool is_running)
 {
-	if (apicid >= 0) {
+	if (is_running) {
 		entry->lo.fields_vapic.destination =
 					APICID_TO_IRTE_DEST_LO(apicid);
 		entry->hi.fields.destination =
@@ -4013,12 +4013,11 @@ static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid,
  * Update the pCPU information for an IRTE that is configured to post IRQs to
  * a vCPU, without issuing an IOMMU invalidation for the IRTE.
  *
- * If the vCPU is associated with a pCPU (@apicid >= 0), configure the
- * Destination with the pCPU's APIC ID, set IsRun, and clear GALogIntr.  If the
- * vCPU isn't associated with a pCPU (@apicid < 0), clear IsRun and set/clear
- * GALogIntr based on input from the caller (e.g. KVM only requests wakeup_intr
- * when the vCPU is blocking and requires a notification wake event).  I.e.
- * treat vCPUs that are associated with a pCPU as running.  This API is
+ * If the vCPU is scheduled to run on pCPU (@is_running = 1), configure the
+ * Destination with the pCPU's APIC ID, set IsRun, and clear GALogIntr. If the
+ * vCPU is scheduled out (@is_running = 0), clear IsRun and set/clear GALogIntr
+ * based on input from the caller (e.g. KVM only requests wakeup_intr when the
+ * vCPU is blocking and requires a notification wake event). This API is
  * intended to be used when a vCPU is scheduled in/out (or stops running for
  * any reason), to do a fast update of IsRun, GALogIntr, and (conditionally)
  * Destination.
@@ -4027,7 +4026,7 @@ static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid,
  * and thus don't require an invalidation to ensure the IOMMU consumes fresh
  * information.
  */
-int amd_iommu_update_ga(void *data, int apicid, bool wakeup_intr)
+int amd_iommu_update_ga(void *data, int apicid, bool wakeup_intr, bool is_running)
 {
 	struct amd_ir_data *ir_data = (struct amd_ir_data *)data;
 	struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
@@ -4041,14 +4040,15 @@ int amd_iommu_update_ga(void *data, int apicid, bool wakeup_intr)
 	if (!ir_data->iommu)
 		return -ENODEV;
 
-	__amd_iommu_update_ga(entry, apicid, wakeup_intr);
+	__amd_iommu_update_ga(entry, apicid, wakeup_intr, is_running);
 
 	return __modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid,
 				ir_data->irq_2_irte.index, entry);
 }
 EXPORT_SYMBOL(amd_iommu_update_ga);
 
-int amd_iommu_activate_guest_mode(void *data, int apicid, bool wakeup_intr)
+static int __amd_iommu_activate_guest_mode(void *data, int apicid, bool wakeup_intr,
+					   bool is_running)
 {
 	struct amd_ir_data *ir_data = (struct amd_ir_data *)data;
 	struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
@@ -4071,11 +4071,16 @@ int amd_iommu_activate_guest_mode(void *data, int apicid, bool wakeup_intr)
 	entry->hi.fields.vector            = ir_data->ga_vector;
 	entry->lo.fields_vapic.ga_tag      = ir_data->ga_tag;
 
-	__amd_iommu_update_ga(entry, apicid, wakeup_intr);
+	__amd_iommu_update_ga(entry, apicid, wakeup_intr, is_running);
 
 	return modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid,
 			      ir_data->irq_2_irte.index, entry);
 }
+
+int amd_iommu_activate_guest_mode(void *data, int apicid, bool wakeup_intr)
+{
+	return __amd_iommu_activate_guest_mode(data, apicid, wakeup_intr, true);
+}
 EXPORT_SYMBOL(amd_iommu_activate_guest_mode);
 
 int amd_iommu_deactivate_guest_mode(void *data)
@@ -4142,8 +4147,9 @@ static int amd_ir_set_vcpu_affinity(struct irq_data *data, void *info)
 		ir_data->ga_vector = pi_data->vector;
 		ir_data->ga_tag = pi_data->ga_tag;
 		if (pi_data->is_guest_mode)
-			ret = amd_iommu_activate_guest_mode(ir_data, pi_data->apicid,
-							    pi_data->wakeup_intr);
+			ret = __amd_iommu_activate_guest_mode(ir_data, pi_data->apicid,
+							      pi_data->wakeup_intr,
+							      pi_data->is_running);
 		else
 			ret = amd_iommu_deactivate_guest_mode(ir_data);
 	} else {
include/linux/amd-iommu.h +4 -2
index e20c909edc56..a5f1bd6db0ee 100644
@@ -30,7 +30,8 @@ static inline void amd_iommu_detect(void) { }
 /* IOMMU AVIC Function */
 extern int amd_iommu_register_ga_log_notifier(int (*notifier)(u32));
 
-extern int amd_iommu_update_ga(void *data, int apicid, bool wakeup_intr);
+extern int amd_iommu_update_ga(void *data, int apicid, bool wakeup_intr,
+			       bool is_running);
 extern int amd_iommu_activate_guest_mode(void *data, int apicid, bool wakeup_intr);
 extern int amd_iommu_deactivate_guest_mode(void *data);
 
@@ -42,7 +43,8 @@ amd_iommu_register_ga_log_notifier(int (*notifier)(u32))
 	return 0;
 }
 
-static inline int amd_iommu_update_ga(void *data, int apicid, bool wakeup_intr)
+static inline int amd_iommu_update_ga(void *data, int apicid, bool wakeup_intr,
+				      bool is_running)
 {
 	return 0;
 }
Signature · 1 line
2.34.1
#4 lore raw

PATCH v5 4/7 iommu/amd: Program guest-mode IRTEs for GAPPI wakeup when IRTE[IsRun] = 0

In reply to Sairaj Kodilkar

Guest APIC Physical Processor Interrupt (GAPPI) is an alternative to the GA log for notifying the host when a device interrupt targets a non-running vCPU (IRTE[IsRun] = 0). Per the AMD IOMMU specification [1] (section 2.2.5.4), with GAPPI enabled the IOMMU delivers a physical APIC interrupt to the CPU described by IRTE[Destination], using IRTE[GATag][7:0] as the vector, while still updating the guest vAPIC backing page IRR as usual.

The AMD IOMMU also allows suppressing GAPPI interrupts using the IRTE[GAPPIDis] bit when the GAPPIDisSup feature is available in extended feature register 2. The AMD IOMMU driver sets this bit when the wakeup_intr flag is not set by KVM.

Note: amd_iommu_gappi is currently false; a later patch enables it via the kernel command line.

[1] https://docs.amd.com/v/u/en-US/48882_3.11_IOMMU_PUB

---
 drivers/iommu/amd/amd_iommu_types.h |  4 +++-
 drivers/iommu/amd/init.c            |  3 +++
 drivers/iommu/amd/iommu.c           | 30 +++++++++++++++++++----------
 include/linux/amd-iommu.h           |  6 ++++++
 4 files changed, 32 insertions(+), 11 deletions(-)
drivers/iommu/amd/amd_iommu_types.h +3 -1
index 8241ef922519..b89a2b3df0a4 100644
@@ -97,6 +97,7 @@
 /* Extended Feature 2 Bits */
 #define FEATURE_SEVSNPIO_SUP	BIT_ULL(1)
 #define FEATURE_GCR3TRPMODE	BIT_ULL(3)
+#define FEATURE_GAPPIDISSUP	BIT_ULL(4)
 #define FEATURE_SNPAVICSUP	GENMASK_ULL(7, 5)
 #define FEATURE_SNPAVICSUP_GAM(x) \
 	(FIELD_GET(FEATURE_SNPAVICSUP, x) == 0x1)
@@ -982,7 +983,8 @@ union irte_ga_lo {
 		    no_fault	: 1,
 		    /* ------ */
 		    ga_log_intr	: 1,
-		    rsvd1	: 3,
+		    rsvd1	: 2,
+		    gappi_dis	: 1,
 		    is_run	: 1,
 		    /* ------ */
 		    guest_mode	: 1,
drivers/iommu/amd/init.c +3 -0
index 8a410d4aa370..ef23e0755c32 100644
@@ -160,6 +160,9 @@ u8 amd_iommu_hpt_vasize;
 /* Guest page table level */
 int amd_iommu_gpt_level = PAGE_MODE_4_LEVEL;
 
+bool amd_iommu_gappi;
+EXPORT_SYMBOL(amd_iommu_gappi);
+
 int amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_VAPIC;
 static int amd_iommu_xt_mode = IRQ_REMAP_XAPIC_MODE;
 
drivers/iommu/amd/iommu.c +20 -10
index c0eec32ee3cb..7ceb6bf508f0 100644
@@ -4004,8 +4004,18 @@ static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid,
 		entry->lo.fields_vapic.is_run = true;
 		entry->lo.fields_vapic.ga_log_intr = false;
 	} else {
-		entry->lo.fields_vapic.is_run = false;
-		entry->lo.fields_vapic.ga_log_intr = wakeup_intr;
+		if (amd_iommu_gappi) {
+			entry->lo.fields_vapic.gappi_dis = !wakeup_intr &&
+						check_feature2(FEATURE_GAPPIDISSUP);
+			entry->lo.fields_vapic.is_run = false;
+			entry->lo.fields_vapic.destination =
+						APICID_TO_IRTE_DEST_LO(apicid);
+			entry->hi.fields.destination =
+						APICID_TO_IRTE_DEST_HI(apicid);
+		} else {
+			entry->lo.fields_vapic.is_run = false;
+			entry->lo.fields_vapic.ga_log_intr = wakeup_intr;
+		}
 	}
 }
 
@@ -4016,15 +4026,15 @@ static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid,
  * If the vCPU is scheduled to run on pCPU (@is_running = 1), configure the
  * Destination with the pCPU's APIC ID, set IsRun, and clear GALogIntr. If the
  * vCPU is scheduled out (@is_running = 0), clear IsRun and set/clear GALogIntr
- * based on input from the caller (e.g. KVM only requests wakeup_intr when the
- * vCPU is blocking and requires a notification wake event). This API is
- * intended to be used when a vCPU is scheduled in/out (or stops running for
- * any reason), to do a fast update of IsRun, GALogIntr, and (conditionally)
- * Destination.
+ * and GAPPIDis based on input from the caller (e.g. KVM only requests
+ * wakeup_intr when the vCPU is blocking and requires a notification wake
+ * event). This API is intended to be used when a vCPU is scheduled in/out (or
+ * stops running for any reason), to do a fast update of IsRun, GALogIntr,
+ * GAPPIDis and (conditionally) Destination.
  *
- * Per the IOMMU spec, the Destination, IsRun, and GATag fields are not cached
- * and thus don't require an invalidation to ensure the IOMMU consumes fresh
- * information.
+ * Per the IOMMU spec, the Destination, IsRun, GATag and GAPPIDis fields are
+ * not cached and thus don't require an invalidation to ensure the IOMMU
+ * consumes fresh information.
  */
 int amd_iommu_update_ga(void *data, int apicid, bool wakeup_intr, bool is_running)
 {
include/linux/amd-iommu.h +6 -0
index a5f1bd6db0ee..de228140ce6e 100644
@@ -35,6 +35,9 @@ extern int amd_iommu_update_ga(void *data, int apicid, bool wakeup_intr,
 extern int amd_iommu_activate_guest_mode(void *data, int apicid, bool wakeup_intr);
 extern int amd_iommu_deactivate_guest_mode(void *data);
 
+/* IOMMU AVIC Flag */
+extern bool amd_iommu_gappi;
+
 #else /* defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) */
 
 static inline int
@@ -58,6 +61,9 @@ static inline int amd_iommu_deactivate_guest_mode(void *data)
 {
 	return 0;
 }
+
+#define amd_iommu_gappi false
+
 #endif /* defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) */
 
 int amd_iommu_get_num_iommus(void);
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v5 4/7] iommu/amd: Program guest-mode IRTEs for GAPPI wakeup when IRTE[IsRun] = 0

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] iommu/amd: stale gappi_dis hardware flag in IRTE when is_running=true --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] iommu/amd: stale gappi_dis hardware flag in IRTE when is_running=true --

commit fed3ee87aa05f53cbc2ccd8dd9c45c2a8ad8bb44
Author: Sairaj Kodilkar <[email protected]>

iommu/amd: Program guest-mode IRTEs for GAPPI wakeup when IRTE[IsRun] = 0

This commit enables programming the IRTE for Guest APIC Physical Processor Interrupt (GAPPI) wakeup when a vCPU is not running. It allows suppressing these interrupts using the IRTE[GAPPIDis] bit when KVM does not request a wakeup interrupt.

drivers/iommu/amd/iommu.c static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid, · line 4005

Quoted 7 lines
drivers/iommu/amd/iommu.c +0 -0
index c0eec32ee3cb6..7ceb6bf508f03 100644
@@ -4004,8 +4004,18 @@ static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid,
 		entry->lo.fields_vapic.is_run = true;
 		entry->lo.fields_vapic.ga_log_intr = false;

[Severity: Low]
When a vCPU transitions to the running state, ga_log_intr is explicitly cleared here. Does gappi_dis also need to be cleared?

If a vCPU transitions to is_running=false with wakeup_intr=false, gappi_dis can be set to 1 in the newly added else branch below. When the vCPU transitions back to is_running=true, this code path is taken, but it leaves the gappi_dis bit stale.

Could this cause unintended interrupt suppression or hardware state mismatches if the IOMMU hardware evaluates the bit unexpectedly?

Quoted 17 lines
drivers/iommu/amd/iommu.c +12 -2
 	} else {
-		entry->lo.fields_vapic.is_run = false;
-		entry->lo.fields_vapic.ga_log_intr = wakeup_intr;
+		if (amd_iommu_gappi) {
+			entry->lo.fields_vapic.gappi_dis = !wakeup_intr &&
+						check_feature2(FEATURE_GAPPIDISSUP);
+			entry->lo.fields_vapic.is_run = false;
+			entry->lo.fields_vapic.destination =
+						APICID_TO_IRTE_DEST_LO(apicid);
+			entry->hi.fields.destination =
+						APICID_TO_IRTE_DEST_HI(apicid);
+		} else {
+			entry->lo.fields_vapic.is_run = false;
+			entry->lo.fields_vapic.ga_log_intr = wakeup_intr;
+		}
 	}
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#6 lore raw

Re: [PATCH v5 4/7] iommu/amd: Program guest-mode IRTEs for GAPPI wakeup when IRTE[IsRun] = 0

Quoted 26 lines · On 10/15/2026 12:33 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] iommu/amd: stale gappi_dis hardware flag in IRTE when is_running=true --

commit fed3ee87aa05f53cbc2ccd8dd9c45c2a8ad8bb44
Author: Sairaj Kodilkar <[email protected]>

iommu/amd: Program guest-mode IRTEs for GAPPI wakeup when IRTE[IsRun] = 0

This commit enables programming the IRTE for Guest APIC Physical Processor Interrupt (GAPPI) wakeup when a vCPU is not running. It allows suppressing these interrupts using the IRTE[GAPPIDis] bit when KVM does not request a wakeup interrupt.

drivers/iommu/amd/iommu.c static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid, · line 4005

Quoted 7 lines
drivers/iommu/amd/iommu.c +0 -0
index c0eec32ee3cb6..7ceb6bf508f03 100644
@@ -4004,8 +4004,18 @@ static void __amd_iommu_update_ga(struct irte_ga *entry, int apicid,
 		entry->lo.fields_vapic.is_run = true;
 		entry->lo.fields_vapic.ga_log_intr = false;

[Severity: Low]
When a vCPU transitions to the running state, ga_log_intr is explicitly cleared here. Does gappi_dis also need to be cleared?

Quoted 8 lines

If a vCPU transitions to is_running=false with wakeup_intr=false, gappi_dis can be set to 1 in the newly added else branch below. When the vCPU transitions back to is_running=true, this code path is taken, but it leaves the gappi_dis bit stale.

Could this cause unintended interrupt suppression or hardware state mismatches if the IOMMU hardware evaluates the bit unexpectedly?

The gappi_dis bit is evaluated only when is_run is false and is otherwise ignored, hence it is safe to not assign gappi_dis=1 when vCPU transitions to running state.

Thanks
Sairaj

Quoted 18 lines
Quoted 17 lines
drivers/iommu/amd/iommu.c +12 -2
 	} else {
-		entry->lo.fields_vapic.is_run = false;
-		entry->lo.fields_vapic.ga_log_intr = wakeup_intr;
+		if (amd_iommu_gappi) {
+			entry->lo.fields_vapic.gappi_dis = !wakeup_intr &&
+						check_feature2(FEATURE_GAPPIDISSUP);
+			entry->lo.fields_vapic.is_run = false;
+			entry->lo.fields_vapic.destination =
+						APICID_TO_IRTE_DEST_LO(apicid);
+			entry->hi.fields.destination =
+						APICID_TO_IRTE_DEST_HI(apicid);
+		} else {
+			entry->lo.fields_vapic.is_run = false;
+			entry->lo.fields_vapic.ga_log_intr = wakeup_intr;
+		}
 	}
 }
#7 lore raw

Re: [PATCH v5 4/7] iommu/amd: Program guest-mode IRTEs for GAPPI wakeup when IRTE[IsRun] = 0

In reply to Sairaj Kodilkar
kernel test robot noticed the following build errors:

Hi Sairaj,

kernel test robot noticed the following build errors:

[auto build test ERROR on 4056b3c9d3c92ea45955641dbafeb9b960e146ef]

url:    https://github.com/intel-lab-lkp/linux/commits/Sairaj-Kodilkar/iommu-amd-KVM-SVM-Rename-cpu-to-apicid-in-IOMMU-interface/20261015-121509
base:   4056b3c9d3c92ea45955641dbafeb9b960e146ef
patch link:    https://lore.kernel.org/r/20261015064515.10700-5-sarunkod%40amd.com
patch subject: [PATCH v5 4/7] iommu/amd: Program guest-mode IRTEs for GAPPI wakeup when IRTE[IsRun] = 0
config: x86_64-randconfig-1017-20261016 (https://download.01.org/0day-ci/archive/20261016/[email protected]/config)
compiler: clang version 22.1.8 (https://github.com/llvm/llvm-project ca7933e47d3a3451d81e72ac174dcb5aa28b59d1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261016/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/iommu/amd/init.c:163:6: error: redefinition of 'false' as different kind of symbol
     163 | bool amd_iommu_gappi;
         |      ^
   include/linux/amd-iommu.h:65:25: note: expanded from macro 'amd_iommu_gappi'
      65 | #define amd_iommu_gappi false
         |                         ^
   include/linux/stddef.h:11:2: note: previous definition is here
      11 |         false   = 0,
         |         ^
   drivers/iommu/amd/init.c:164:15: error: redefinition of 'false' as different kind of symbol
     164 | EXPORT_SYMBOL(amd_iommu_gappi);
         |               ^
   include/linux/amd-iommu.h:65:25: note: expanded from macro 'amd_iommu_gappi'
      65 | #define amd_iommu_gappi false
         |                         ^
   include/linux/stddef.h:11:2: note: previous definition is here
      11 |         false   = 0,
         |         ^
>> drivers/iommu/amd/init.c:164:1: error: cannot take the address of an rvalue of type 'int'
     164 | EXPORT_SYMBOL(amd_iommu_gappi);
         | ^             ~~~~~~~~~~~~~~~
   include/linux/export.h:89:29: note: expanded from macro 'EXPORT_SYMBOL'
      89 | #define EXPORT_SYMBOL(sym)              _EXPORT_SYMBOL(sym, "")
         |                                         ^              ~~~
   include/linux/export.h:86:38: note: expanded from macro '_EXPORT_SYMBOL'
      86 | #define _EXPORT_SYMBOL(sym, license)    __EXPORT_SYMBOL(sym, license, "")
         |                                         ^               ~~~
   include/linux/export.h:77:2: note: expanded from macro '__EXPORT_SYMBOL'
      77 |         __ADDRESSABLE(sym)                                      \
         |         ^             ~~~
   include/linux/compiler.h:276:2: note: expanded from macro '__ADDRESSABLE'
     276 |         ___ADDRESSABLE(sym, __section(".discard.addressable"))
         |         ^              ~~~
   include/linux/compiler.h:273:63: note: expanded from macro '___ADDRESSABLE'
     273 |         __UNIQUE_ID(__PASTE(addressable_, sym)) = (void *)(uintptr_t)&sym;
         |                                                                      ^~~~

3 errors generated.

vim +/false +163 drivers/iommu/amd/init.c

162

 > 163	bool amd_iommu_gappi;
 > 164	EXPORT_SYMBOL(amd_iommu_gappi);

165

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#8 lore raw

PATCH v5 5/7 KVM: VMX: Factor out wakeup list handling code to KVM

In reply to Sairaj Kodilkar

VMX maintains a per-pCPU list of blocked vCPUs so that they can be woken when a device interrupt arrives while the vCPU is not running. The vCPU is queued on the list of the pCPU it last ran on and its notification vector is switched to POSTED_INTR_WAKEUP_VECTOR, so the handler for that vector walks the local list and wakes the vCPUs that have a notification pending.

Guest APIC Physical Processor Interrupt (GAPPI) needs the same infrastructure on AMD. When a device interrupt targets a non-running vCPU (IRTE[IsRun] = 0), the IOMMU delivers a physical APIC interrupt to IRTE[Destination] using IRTE[GATag][7:0] as the vector, which KVM programs to POSTED_INTR_WAKEUP_VECTOR. SVM therefore requires the same per-pCPU list of blocked vCPUs that VMX already has. Hence Move the per-pCPU list, its lock, the wakeup handler and the per-CPU initialization from VMX to common KVM x86 code.

Intel and AMD determine whether a queued vCPU has a notification pending in different ways. Hence, introduce a new kvm_x86_ops callback vcpu_irq_pending(), which the wakeup handler uses to decide whether a vCPU needs to be woken.

---
 arch/x86/include/asm/kvm-x86-ops.h |   1 +
 arch/x86/include/asm/kvm_host.h    |   1 +
 arch/x86/kvm/vmx/common.h          |   3 -
 arch/x86/kvm/vmx/main.c            |   6 ++
 arch/x86/kvm/vmx/posted_intr.c     |  82 +--------------------
 arch/x86/kvm/vmx/tdx.c             |   1 -
 arch/x86/kvm/vmx/vmx.c             |  14 ++--
 arch/x86/kvm/vmx/x86_ops.h         |   1 +
 arch/x86/kvm/x86.c                 | 111 +++++++++++++++++++++++++++++
 include/linux/kvm_host.h           |   6 ++
 10 files changed, 135 insertions(+), 91 deletions(-)
arch/x86/include/asm/kvm-x86-ops.h +1 -0
index e213c9ae3e30..5d337f9336c5 100644
@@ -30,6 +30,7 @@ KVM_X86_OP(vcpu_reset)
 KVM_X86_OP(prepare_switch_to_guest)
 KVM_X86_OP(vcpu_load)
 KVM_X86_OP(vcpu_put)
+KVM_X86_OP_OPTIONAL(vcpu_irq_pending)
 KVM_X86_OP(update_exception_bitmap)
 KVM_X86_OP(get_msr)
 KVM_X86_OP(set_msr)
arch/x86/include/asm/kvm_host.h +1 -0
index 683bb8bf43a9..51ed472c5ec3 100644
@@ -1529,6 +1529,7 @@ struct kvm_x86_ops {
 	void (*prepare_switch_to_guest)(struct kvm_vcpu *vcpu);
 	void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);
 	void (*vcpu_put)(struct kvm_vcpu *vcpu);
+	bool (*vcpu_irq_pending)(struct kvm_vcpu *vcpu);
 
 	/*
 	 * Mask of DEBUGCTL bits that are owned by the host, i.e. that need to
arch/x86/kvm/vmx/common.h +0 -3
index 08005676702c..5762d90a9531 100644
@@ -34,9 +34,6 @@ struct vcpu_vt {
 	/* Posted interrupt descriptor */
 	struct pi_desc pi_desc;
 
-	/* Used if this vCPU is waiting for PI notification wakeup. */
-	struct list_head pi_wakeup_list;
-
 	union vmx_exit_reason exit_reason;
 
 	unsigned long	exit_qualification;
arch/x86/kvm/vmx/main.c +6 -0
index 4c52ab8d0786..af5808eacc72 100644
@@ -108,6 +108,11 @@ static void vt_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 	vmx_vcpu_load(vcpu, cpu);
 }
 
+static bool vt_vcpu_irq_pending(struct kvm_vcpu *vcpu)
+{
+	return vmx_vcpu_irq_pending(vcpu);
+}
+
 static void vt_update_cpu_dirty_logging(struct kvm_vcpu *vcpu)
 {
 	/*
@@ -912,6 +917,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
 	.prepare_switch_to_guest = vt_op(prepare_switch_to_guest),
 	.vcpu_load = vt_op(vcpu_load),
 	.vcpu_put = vt_op(vcpu_put),
+	.vcpu_irq_pending = vt_op(vcpu_irq_pending),
 
 	.HOST_OWNED_DEBUGCTL = VMX_HOST_OWNED_DEBUGCTL_BITS,
 
arch/x86/kvm/vmx/posted_intr.c +2 -80

114 lines not on this page · raw message

arch/x86/kvm/vmx/tdx.c +0 -1
index 00850a3a77d6..1ba73b1379a7 100644
@@ -683,7 +683,6 @@ int tdx_vcpu_create(struct kvm_vcpu *vcpu)
 
 	fpstate_set_confidential(&vcpu->arch.guest_fpu);
 	vcpu->arch.apic->guest_apic_protected = true;
-	INIT_LIST_HEAD(&tdx->vt.pi_wakeup_list);
 
 	vcpu->arch.efer = EFER_SCE | EFER_LME | EFER_LMA | EFER_NX;
 
arch/x86/kvm/vmx/vmx.c +7 -7
index 612ab07d4100..3359f2481d77 100644
@@ -1587,6 +1587,13 @@ void vmx_vcpu_put(struct kvm_vcpu *vcpu)
 	vmx_prepare_switch_to_host(to_vmx(vcpu));
 }
 
+bool vmx_vcpu_irq_pending(struct kvm_vcpu *vcpu)
+{
+	struct vcpu_vt *vt = to_vt(vcpu);
+
+	return pi_test_on(&vt->pi_desc);
+}
+
 static void vmx_switch_loaded_vmcs(struct kvm_vcpu *vcpu,
 				   struct loaded_vmcs *vmcs)
 {
@@ -7667,8 +7674,6 @@ int vmx_vcpu_create(struct kvm_vcpu *vcpu)
 	BUILD_BUG_ON(offsetof(struct vcpu_vmx, vcpu) != 0);
 	vmx = to_vmx(vcpu);
 
-	INIT_LIST_HEAD(&vmx->vt.pi_wakeup_list);
-
 	err = -ENOMEM;
 
 	vmx->vpid = allocate_vpid();
@@ -8548,8 +8553,6 @@ void vmx_migrate_timers(struct kvm_vcpu *vcpu)
 
 void vmx_hardware_unsetup(void)
 {
-	kvm_set_posted_intr_wakeup_handler(NULL);
-
 	if (nested)
 		nested_vmx_hardware_unsetup();
 }
@@ -8830,7 +8833,6 @@ __init int vmx_hardware_setup(void)
 	}
 	vmx_nested_ops.enabled = nested;
 
-	kvm_set_posted_intr_wakeup_handler(pi_wakeup_handler);
 
 	/*
 	 * On Intel CPUs that lack self-snoop feature, letting the guest control
@@ -8900,8 +8902,6 @@ int __init vmx_init(void)
 
 	for_each_possible_cpu(cpu) {
 		INIT_LIST_HEAD(&per_cpu(loaded_vmcss_on_cpu, cpu));
-
-		pi_init_cpu(cpu);
 	}
 
 	vmx_check_vmcs12_offsets();
arch/x86/kvm/vmx/x86_ops.h +1 -0
index 054fd14bb2e1..114dd8bb48b9 100644
@@ -26,6 +26,7 @@ void vmx_vcpu_free(struct kvm_vcpu *vcpu);
 void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event);
 void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
 void vmx_vcpu_put(struct kvm_vcpu *vcpu);
+bool vmx_vcpu_irq_pending(struct kvm_vcpu *vcpu);
 int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath);
 void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu);
 int vmx_skip_emulated_instruction(struct kvm_vcpu *vcpu);
arch/x86/kvm/x86.c +111 -0

151 lines not on this page · raw message

include/linux/kvm_host.h +6 -0
index c844def6dd95..efea016e8186 100644
@@ -398,6 +398,9 @@ struct kvm_vcpu {
 	 */
 	struct kvm_memory_slot *last_used_slot;
 	u64 last_used_slot_gen;
+
+	/* Used if this vCPU is waiting for PI notification wakeup. */
+	struct list_head pi_wakeup_list;
 };
 
 /*
@@ -2651,4 +2654,7 @@ long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
 				    struct kvm_pre_fault_memory *range);
 #endif
 
+void kvm_pi_enable_wakeup_handler(struct kvm_vcpu *vcpu, int cpu);
+void kvm_pi_disable_wakeup_handler(struct kvm_vcpu *vcpu, int cpu);
+
 #endif
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH v5 5/7] KVM: VMX: Factor out wakeup list handling code to KVM

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] kvm: uninitialized return value from vcpu_irq_pending due to KVM_X86_OP_OPTIONAL --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] kvm: uninitialized return value from vcpu_irq_pending due to KVM_X86_OP_OPTIONAL --

commit 56cc0b2c3b271017f40149e674efc58c033886d7
Author: Sairaj Kodilkar <[email protected]>

KVM: VMX: Factor out wakeup list handling code to KVM

This commit moves the per-pCPU list of blocked vCPUs and the wakeup handler from VMX to common KVM x86 code to support AMD. It introduces a new optional vcpu_irq_pending callback so Intel and AMD can determine if a queued vCPU has a notification pending.

arch/x86/include/asm/kvm-x86-ops.h KVM_X86_OP(vcpu_reset) · line 33

Quoted 9 lines
arch/x86/include/asm/kvm-x86-ops.h +1 -0
index e213c9ae3e301..5d337f9336c5d 100644
@@ -30,6 +30,7 @@ KVM_X86_OP(vcpu_reset)
 KVM_X86_OP(prepare_switch_to_guest)
 KVM_X86_OP(vcpu_load)
 KVM_X86_OP(vcpu_put)
+KVM_X86_OP_OPTIONAL(vcpu_irq_pending)

[Severity: Medium]
Since vcpu_irq_pending() returns a boolean, should this be declared with KVM_X86_OP_OPTIONAL_RET0 instead?

For optional KVM operations, if the active vendor module does not implement the callback, KVM patches the static call site to a dummy trampoline. Because KVM_X86_OP_OPTIONAL is used here, the trampoline does not clear the return register.

[ ... ]

Quoted 4 lines
arch/x86/kvm/x86.c +0 -0
index aad065d035fbb..0c637a18bcfa4 100644

[ ... ]

Quoted 1 line
arch/x86/kvm/x86.c +0 -0
@@ -2688,6 +2709,79 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)

[ ... ]

arch/x86/kvm/x86.c void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) · line 2773

Quoted 13 lines
arch/x86/kvm/x86.c +13 -0
+/*
+ * Handler for POSTED_INTERRUPT_WAKEUP_VECTOR.
+ */
+static void kvm_pi_wakeup_handler(void)
+{
+	int cpu = smp_processor_id();
+	struct list_head *wakeup_list = &per_cpu(wakeup_vcpus_on_cpu, cpu);
+	raw_spinlock_t *spinlock = &per_cpu(wakeup_vcpus_on_cpu_lock, cpu);
+	struct kvm_vcpu *vcpu;
+
+	raw_spin_lock(spinlock);
+	list_for_each_entry(vcpu, wakeup_list, pi_wakeup_list) {
+		if (kvm_x86_call(vcpu_irq_pending)(vcpu))

[Severity: Medium]
Could this evaluate uninitialized garbage if the vendor omits the callback?

Because KVM_X86_OP_OPTIONAL does not clear the return register, this check will read whatever was left in the register. This could lead to unpredictable behavior, such as spurious vCPU wakeups or missed wakeups on platforms lacking the implementation.

Quoted 4 lines
arch/x86/kvm/x86.c +4 -0
+			kvm_vcpu_wake_up(vcpu);
+	}
+	raw_spin_unlock(spinlock);
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#10 lore raw

Re: [PATCH v5 5/7] KVM: VMX: Factor out wakeup list handling code to KVM

Quoted 28 lines · On 10/15/2026 12:30 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] kvm: uninitialized return value from vcpu_irq_pending due to KVM_X86_OP_OPTIONAL --

commit 56cc0b2c3b271017f40149e674efc58c033886d7
Author: Sairaj Kodilkar <[email protected]>

KVM: VMX: Factor out wakeup list handling code to KVM

This commit moves the per-pCPU list of blocked vCPUs and the wakeup handler from VMX to common KVM x86 code to support AMD. It introduces a new optional vcpu_irq_pending callback so Intel and AMD can determine if a queued vCPU has a notification pending.

arch/x86/include/asm/kvm-x86-ops.h KVM_X86_OP(vcpu_reset) · line 33

Quoted 9 lines
arch/x86/include/asm/kvm-x86-ops.h +1 -0
index e213c9ae3e301..5d337f9336c5d 100644
@@ -30,6 +30,7 @@ KVM_X86_OP(vcpu_reset)
 KVM_X86_OP(prepare_switch_to_guest)
 KVM_X86_OP(vcpu_load)
 KVM_X86_OP(vcpu_put)
+KVM_X86_OP_OPTIONAL(vcpu_irq_pending)

[Severity: Medium]
Since vcpu_irq_pending() returns a boolean, should this be declared with KVM_X86_OP_OPTIONAL_RET0 instead?

Quoted 5 lines

For optional KVM operations, if the active vendor module does not implement the callback, KVM patches the static call site to a dummy trampoline. Because KVM_X86_OP_OPTIONAL is used here, the trampoline does not clear the return register.

Yes this is a valid concern, it should be OPTIONAL_RET0.

Thanks
Sairaj

Quoted 40 lines

[ ... ]

Quoted 4 lines
arch/x86/kvm/x86.c +0 -0
index aad065d035fbb..0c637a18bcfa4 100644

[ ... ]

Quoted 1 line
arch/x86/kvm/x86.c +0 -0
@@ -2688,6 +2709,79 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)

[ ... ]

arch/x86/kvm/x86.c void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) · line 2773

Quoted 13 lines
arch/x86/kvm/x86.c +13 -0
+/*
+ * Handler for POSTED_INTERRUPT_WAKEUP_VECTOR.
+ */
+static void kvm_pi_wakeup_handler(void)
+{
+	int cpu = smp_processor_id();
+	struct list_head *wakeup_list = &per_cpu(wakeup_vcpus_on_cpu, cpu);
+	raw_spinlock_t *spinlock = &per_cpu(wakeup_vcpus_on_cpu_lock, cpu);
+	struct kvm_vcpu *vcpu;
+
+	raw_spin_lock(spinlock);
+	list_for_each_entry(vcpu, wakeup_list, pi_wakeup_list) {
+		if (kvm_x86_call(vcpu_irq_pending)(vcpu))

[Severity: Medium]
Could this evaluate uninitialized garbage if the vendor omits the callback?

Because KVM_X86_OP_OPTIONAL does not clear the return register, this check will read whatever was left in the register. This could lead to unpredictable behavior, such as spurious vCPU wakeups or missed wakeups on platforms lacking the implementation.

Quoted 4 lines
arch/x86/kvm/x86.c +4 -0
+			kvm_vcpu_wake_up(vcpu);
+	}
+	raw_spin_unlock(spinlock);
+}
#11 lore raw

PATCH v5 6/7 KVM: SVM: Add support for AMD IOMMU Guest APIC Physical Processor Interrupt (GAPPI)

In reply to Sairaj Kodilkar

With AVIC guest-mode interrupt remapping, device interrupts are posted into the guest vAPIC backing page by the IOMMU. When the vCPU is not running (IRTE[IsRun] = 0), KVM must still be notified to schedule it. The legacy path uses the GA log.

GAPPI (Guest APIC Physical Processor Interrupt) is an alternative to the GA log mechanism provided by the AMD IOMMU. With GAPPI enabled, the IOMMU still updates the vAPIC backing page IRR, but the host wakeup notification is delivered as a physical APIC interrupt to IRTE[Destination], using IRTE[GATag][7:0] as the vector (POSTED_INTR_WAKEUP_VECTOR).

SVM follows the Intel posted-interrupt wakeup model. Each pCPU maintains a list of blocked vCPUs that may be woken by a GAPPI delivery to that CPU. When a vCPU blocks while waiting for an interrupt, SVM enqueues it on the wakeup list of the pCPU on which it was previously running and passes that same pCPU's physical APIC ID to the IOMMU to program IRTE[Destination]. The rationale is that the vCPU is likely to run again on the same pCPU, which is common when vCPUs are pinned; targeting GAPPI notifications there reduces unnecessary VMEXITs from GAPPI deliveries on other CPUs. SVM registers the GAPPI handler via kvm_set_posted_intr_wakeup_handler(). On delivery, it walks the local vCPU list and wakes vCPUs with a pending IRR.

All GAPPI logic is gated on amd_iommu_gappi. Without it, KVM and the IOMMU falls back to the legacy GA log mechanism for vCPU wakeup.

---
 arch/x86/kvm/svm/avic.c | 53 ++++++++++++++++++++++++++++++++++-------
 arch/x86/kvm/svm/svm.c  |  1 +
 arch/x86/kvm/svm/svm.h  |  4 ++++
 3 files changed, 50 insertions(+), 8 deletions(-)
arch/x86/kvm/svm/avic.c +45 -8
index 8b1fa5bded3d..054b89c3cb0f 100644
@@ -877,6 +877,8 @@ int avic_init_vcpu(struct vcpu_svm *svm)
 	INIT_LIST_HEAD(&svm->ir_list);
 	raw_spin_lock_init(&svm->ir_list_lock);
 
+	svm->gappi_cpu = 0;
+
 	if (!enable_apicv || !irqchip_in_kernel(vcpu->kvm))
 		return 0;
 
@@ -895,6 +897,17 @@ void avic_vcpu_free(struct kvm_vcpu *vcpu)
 
 	if (kvm_svm->avic_physical_id_table && avic_is_addressable_vcpu(vcpu))
 		WRITE_ONCE(kvm_svm->avic_physical_id_table[vcpu->vcpu_id], 0);
+
+	if (amd_iommu_gappi) {
+		struct vcpu_svm *svm = to_svm(vcpu);
+		unsigned long flags;
+
+		local_irq_save(flags);
+
+		kvm_pi_disable_wakeup_handler(vcpu, svm->gappi_cpu);
+
+		local_irq_restore(flags);
+	}
 }
 
 void avic_apicv_post_state_restore(struct kvm_vcpu *vcpu)
@@ -934,8 +947,6 @@ int avic_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm,
 		 * if AVIC is enabled/uninhibited in the future.
 		 */
 		struct amd_iommu_pi_data pi_data = {
-			.ga_tag = AVIC_GATAG(to_kvm_svm(kvm)->avic_vm_id,
-					     vcpu->vcpu_idx),
 			.is_guest_mode = kvm_vcpu_apicv_active(vcpu),
 			.vapic_addr = avic_get_backing_page_address(to_svm(vcpu)),
 			.vector = vector,
@@ -958,6 +969,12 @@ int avic_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm,
 		 * scheduled out, KVM will update the pCPU info when the vCPU
 		 * is awakened and/or scheduled in.  See also avic_vcpu_load().
 		 */
+		if (amd_iommu_gappi)
+			pi_data.ga_tag = POSTED_INTR_WAKEUP_VECTOR;
+		else
+			pi_data.ga_tag = AVIC_GATAG(to_kvm_svm(kvm)->avic_vm_id,
+						    vcpu->vcpu_idx);
+
 		entry = svm->avic_physical_id_entry;
 		if (entry & AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK) {
 			pi_data.apicid = entry & AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK;
@@ -966,6 +983,9 @@ int avic_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm,
 			pi_data.apicid = -1;
 			pi_data.wakeup_intr = entry & AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR;
 			pi_data.is_running = false;
+
+			if (amd_iommu_gappi)
+				pi_data.apicid = cpu_physical_id(svm->gappi_cpu);
 		}
 
 		ret = irq_set_vcpu_affinity(host_irq, &pi_data);
@@ -1018,7 +1038,7 @@ enum avic_vcpu_action {
 };
 
 static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid,
-					    enum avic_vcpu_action action)
+					    int cpu, enum avic_vcpu_action action)
 {
 	bool wakeup_intr = (action & AVIC_START_BLOCKING);
 	bool is_running = apicid >= 0;
@@ -1027,6 +1047,14 @@ static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid,
 
 	lockdep_assert_held(&svm->ir_list_lock);
 
+	if (amd_iommu_gappi && is_running) {
+		kvm_pi_disable_wakeup_handler(vcpu, svm->gappi_cpu);
+		svm->gappi_cpu = cpu; /* Store cpu number as target for GAPPI */
+	} else if (amd_iommu_gappi) {
+		apicid = cpu_physical_id(svm->gappi_cpu);
+		kvm_pi_enable_wakeup_handler(vcpu, svm->gappi_cpu);
+	}
+
 	/*
 	 * Here, we go through the per-vcpu ir_list to update all existing
 	 * interrupt remapping table entry targeting this vcpu.
@@ -1093,7 +1121,7 @@ static void __avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu,
 
 	WRITE_ONCE(kvm_svm->avic_physical_id_table[vcpu->vcpu_id], entry);
 
-	avic_update_iommu_vcpu_affinity(vcpu, h_physical_id, action);
+	avic_update_iommu_vcpu_affinity(vcpu, h_physical_id, cpu, action);
 
 	raw_spin_unlock_irqrestore(&svm->ir_list_lock, flags);
 }
@@ -1135,7 +1163,7 @@ static void __avic_vcpu_put(struct kvm_vcpu *vcpu, enum avic_vcpu_action action)
 	 */
 	raw_spin_lock_irqsave(&svm->ir_list_lock, flags);
 
-	avic_update_iommu_vcpu_affinity(vcpu, -1, action);
+	avic_update_iommu_vcpu_affinity(vcpu, -1, -1, action);
 
 	WARN_ON_ONCE(entry & AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR);
 
@@ -1183,7 +1211,7 @@ void avic_vcpu_put(struct kvm_vcpu *vcpu)
 
 		/*
 		 * The vCPU was preempted while blocking, ensure its IRTEs are
-		 * configured to generate GA Log Interrupts.
+		 * configured to request host wakeup notification.
 		 */
 		if (!(WARN_ON_ONCE(!(entry & AVIC_PHYSICAL_ID_ENTRY_WAKEUP_INTR))))
 			return;
@@ -1308,6 +1336,13 @@ static bool __init avic_want_avic_enabled(void)
 	return true;
 }
 
+bool avic_vcpu_irq_pending(struct kvm_vcpu *vcpu)
+{
+	struct vcpu_svm *svm = to_svm(vcpu);
+
+	return kvm_lapic_find_highest_irr(&svm->vcpu) >= 0;
+}
+
 /*
  * Note:
  * - The module param avic enable both xAPIC and x2APIC mode.
@@ -1351,6 +1386,8 @@ bool __init avic_hardware_setup(void)
 
 void avic_hardware_unsetup(void)
 {
-	if (avic)
-		amd_iommu_register_ga_log_notifier(NULL);
+	if (!avic)
+		return;
+
+	amd_iommu_register_ga_log_notifier(NULL);
 }
arch/x86/kvm/svm/svm.c +1 -0
index c054803d4673..cd0d8e8c386e 100644
@@ -5352,6 +5352,7 @@ struct kvm_x86_ops svm_x86_ops __initdata = {
 	.vcpu_put = svm_vcpu_put,
 	.vcpu_blocking = avic_vcpu_blocking,
 	.vcpu_unblocking = avic_vcpu_unblocking,
+	.vcpu_irq_pending = avic_vcpu_irq_pending,
 
 	.update_exception_bitmap = svm_update_exception_bitmap,
 	.get_feature_msr = svm_get_feature_msr,
arch/x86/kvm/svm/svm.h +4 -0
index 29bde741874a..58d4e85e30fe 100644
@@ -368,6 +368,9 @@ struct vcpu_svm {
 
 	/* Guest GIF value, used when vGIF is not enabled */
 	bool guest_gif;
+
+	/* GAPPI related fields */
+	int gappi_cpu;
 };
 
 struct svm_cpu_data {
@@ -958,6 +961,7 @@ int avic_init_vcpu(struct vcpu_svm *svm);
 void avic_vcpu_free(struct kvm_vcpu *vcpu);
 void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
 void avic_vcpu_put(struct kvm_vcpu *vcpu);
+bool avic_vcpu_irq_pending(struct kvm_vcpu *vcpu);
 void avic_apicv_post_state_restore(struct kvm_vcpu *vcpu);
 void avic_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu);
 int avic_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm,
Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH v5 6/7] KVM: SVM: Add support for AMD IOMMU Guest APIC Physical Processor Interrupt (GAPPI)

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] kvm: svm: vCPU leaked on GAPPI pi_wakeup_list when AVIC deactivated --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] kvm: svm: vCPU leaked on GAPPI pi_wakeup_list when AVIC deactivated --

commit cd7fa3c00904984a2127bee934d4e48326ead7a8
Author: Sairaj Kodilkar <[email protected]>

KVM: SVM: Add support for AMD IOMMU Guest APIC Physical Processor Interrupt (GAPPI)

With AVIC guest-mode interrupt remapping, device interrupts are posted into the guest vAPIC backing page by the IOMMU. When the vCPU is not running (IRTE[IsRun] = 0), KVM must still be notified to schedule it. The legacy path uses the GA log.

Quoted 4 lines
arch/x86/kvm/svm/avic.c +0 -0
index 8b1fa5bded3db..054b89c3cb0f9 100644

[ ... ]

Quoted 11 lines
arch/x86/kvm/svm/avic.c +1 -1
@@ -1018,7 +1038,7 @@ enum avic_vcpu_action {
 };
 
 static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid,
-					    enum avic_vcpu_action action)
+					    int cpu, enum avic_vcpu_action action)
 {
 	bool wakeup_intr = (action & AVIC_START_BLOCKING);
 	bool is_running = apicid >= 0;
@@ -1027,6 +1047,14 @@ static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid,
 

arch/x86/kvm/svm/avic.c static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid, · line 1057

Quoted 10 lines
arch/x86/kvm/svm/avic.c +8 -0
 	lockdep_assert_held(&svm->ir_list_lock);
 
+	if (amd_iommu_gappi && is_running) {
+		kvm_pi_disable_wakeup_handler(vcpu, svm->gappi_cpu);
+		svm->gappi_cpu = cpu; /* Store cpu number as target for GAPPI */
+	} else if (amd_iommu_gappi) {
+		apicid = cpu_physical_id(svm->gappi_cpu);
+		kvm_pi_enable_wakeup_handler(vcpu, svm->gappi_cpu);
+	}
+

[Severity: Medium]
Does this unconditionally add the vCPU to the pi_wakeup_list when is_running is false, even during AVIC_DEACTIVATE?

When AVIC is deactivated via avic_refresh_apicv_exec_ctrl(), it calls __avic_vcpu_put(AVIC_DEACTIVATE), which in turn calls avic_update_iommu_vcpu_affinity() with a target apicid of -1 (so is_running is false). This causes KVM to add the vCPU to the pi_wakeup_list of svm->gappi_cpu.

Since AVIC is deactivated, the IOMMU falls back to legacy mode later in this function:

	if (!(action & AVIC_TOGGLE_ON_OFF))
		WARN_ON_ONCE(amd_iommu_update_ga(...));
	else if (is_running)
		WARN_ON_ONCE(amd_iommu_activate_guest_mode(...));
	else
		WARN_ON_ONCE(amd_iommu_deactivate_guest_mode(data));

Because the IOMMU is reverted to legacy mode, it will not send GAPPI interrupts for this vCPU.

However, the vCPU remains indefinitely on the per-CPU pi_wakeup_list because subsequent context switches (via svm_vcpu_load()) ignore deactivated vCPUs and will never call kvm_pi_disable_wakeup_handler().

Could this cause KVM to unnecessarily traverse the leaked vCPU on every GAPPI interrupt targeted at that pCPU from other active VMs, wasting CPU cycles and risking spurious wakeups?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#13 lore raw

Re: [PATCH v5 6/7] KVM: SVM: Add support for AMD IOMMU Guest APIC Physical Processor Interrupt (GAPPI)

Quoted 64 lines · On 10/15/2026 12:35 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] kvm: svm: vCPU leaked on GAPPI pi_wakeup_list when AVIC deactivated --

commit cd7fa3c00904984a2127bee934d4e48326ead7a8
Author: Sairaj Kodilkar <[email protected]>

KVM: SVM: Add support for AMD IOMMU Guest APIC Physical Processor Interrupt (GAPPI)

With AVIC guest-mode interrupt remapping, device interrupts are posted into the guest vAPIC backing page by the IOMMU. When the vCPU is not running (IRTE[IsRun] = 0), KVM must still be notified to schedule it. The legacy path uses the GA log.

Quoted 4 lines
arch/x86/kvm/svm/avic.c +0 -0
index 8b1fa5bded3db..054b89c3cb0f9 100644

[ ... ]

Quoted 11 lines
arch/x86/kvm/svm/avic.c +1 -1
@@ -1018,7 +1038,7 @@ enum avic_vcpu_action {
 };
 
 static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid,
-					    enum avic_vcpu_action action)
+					    int cpu, enum avic_vcpu_action action)
 {
 	bool wakeup_intr = (action & AVIC_START_BLOCKING);
 	bool is_running = apicid >= 0;
@@ -1027,6 +1047,14 @@ static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid,
 

arch/x86/kvm/svm/avic.c static void avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int apicid, · line 1057

Quoted 10 lines
arch/x86/kvm/svm/avic.c +8 -0
 	lockdep_assert_held(&svm->ir_list_lock);
 
+	if (amd_iommu_gappi && is_running) {
+		kvm_pi_disable_wakeup_handler(vcpu, svm->gappi_cpu);
+		svm->gappi_cpu = cpu; /* Store cpu number as target for GAPPI */
+	} else if (amd_iommu_gappi) {
+		apicid = cpu_physical_id(svm->gappi_cpu);
+		kvm_pi_enable_wakeup_handler(vcpu, svm->gappi_cpu);
+	}
+

[Severity: Medium]
Does this unconditionally add the vCPU to the pi_wakeup_list when is_running is false, even during AVIC_DEACTIVATE?

When AVIC is deactivated via avic_refresh_apicv_exec_ctrl(), it calls __avic_vcpu_put(AVIC_DEACTIVATE), which in turn calls avic_update_iommu_vcpu_affinity() with a target apicid of -1 (so is_running is false). This causes KVM to add the vCPU to the pi_wakeup_list of svm->gappi_cpu.

Since AVIC is deactivated, the IOMMU falls back to legacy mode later in this function:

	if (!(action & AVIC_TOGGLE_ON_OFF))
		WARN_ON_ONCE(amd_iommu_update_ga(...));
	else if (is_running)
		WARN_ON_ONCE(amd_iommu_activate_guest_mode(...));
	else
		WARN_ON_ONCE(amd_iommu_deactivate_guest_mode(data));

Because the IOMMU is reverted to legacy mode, it will not send GAPPI interrupts for this vCPU.

Quoted 8 lines

However, the vCPU remains indefinitely on the per-CPU pi_wakeup_list because subsequent context switches (via svm_vcpu_load()) ignore deactivated vCPUs and will never call kvm_pi_disable_wakeup_handler().

Could this cause KVM to unnecessarily traverse the leaked vCPU on every GAPPI interrupt targeted at that pCPU from other active VMs, wasting CPU cycles and risking spurious wakeups?

You are right about this, it can cause spurious wakeups. We can simply skip list operations during activate and deactivate.

Thanks
Sairaj

#14 lore raw

PATCH v5 7/7 iommu/amd: Provide kernel command line option to enable GAPPI

In reply to Sairaj Kodilkar

Enable GAPPI when the IOMMU GAPPISup extended feature bit is set and the kernel is booted with the amd_iommu=gappi kernel parameter.

Document the option in Documentation/admin-guide/kernel-parameters.txt and mechanism in Documentation/arch/x86/iommu.rst.

---
 .../admin-guide/kernel-parameters.txt         |  3 +-
 Documentation/arch/x86/iommu.rst              | 22 +++++++++++++++
 drivers/iommu/amd/amd_iommu_types.h           |  2 ++
 drivers/iommu/amd/init.c                      | 28 +++++++++++++++++--
 4 files changed, 51 insertions(+), 4 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +2 -1
index e75344f4e0cd..b260ebef118f 100644
@@ -456,7 +456,8 @@ Kernel parameters
 				          to 4 KiB.
 			v2_pgsizes_only - Limit page-sizes used for v1 page-tables
 				          to 4KiB/2Mib/1GiB.
-
+			gappi           - Use GAPPI instead of GALOG for vCPU
+				          wakeup notification.
 
 	amd_iommu_dump=	[HW,X86-64]
 			Enable AMD IOMMU driver option to dump the ACPI table
Documentation/arch/x86/iommu.rst +22 -0
index 79c33560299b..6bac30f5abbd 100644
@@ -150,3 +150,25 @@ AMD Fault reporting
 
 	AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0007 address=0xffffc02000 flags=0x0000]
 	AMD-Vi: Event logged [IO_PAGE_FAULT device=07:00.0 domain=0x0007 address=0xffffc02000 flags=0x0000]
+
+
+AMD vCPU wakeup Mechanism
+--------------------------
+
+GALOG
+^^^^^
+
+GALOG is a legacy notification path to wakeup the vCPU waiting on an interrupt.
+When IOMMU receives an interrupt destined to vCPU which is scheduled out, it
+updates the vAPIC backing page IRR and appends vCPU tags to a shared GA log
+buffer and raises a single GA log interrupt. IOMMU driver scans this buffer to
+decide which vCPU to wakeup.
+
+GAPPI
+^^^^^
+
+GAPPI is an alternative to GALOG.  With GAPPI enabled, the IOMMU still updates
+the guest vAPIC backing page IRR, but may deliver a physical APIC interrupt
+directly to IRTE[Destination], using IRTE[GATag][7:0] as the vector. This
+distributes host wakeup notifications across CPUs instead of centralizing them
+in a log buffer. This can be enabled by adding option amd_iommu=gappi
drivers/iommu/amd/amd_iommu_types.h +2 -0
index b89a2b3df0a4..51edd617ddca 100644
@@ -78,6 +78,7 @@
 #define FEATURE_X2APIC		BIT_ULL(2)
 #define FEATURE_NX		BIT_ULL(3)
 #define FEATURE_GT		BIT_ULL(4)
+#define FEATURE_GAPPI		BIT_ULL(5)
 #define FEATURE_IA		BIT_ULL(6)
 #define FEATURE_GA		BIT_ULL(7)
 #define FEATURE_HE		BIT_ULL(8)
@@ -178,6 +179,7 @@
 #define CONTROL_EPH_EN		45
 #define CONTROL_XT_EN		50
 #define CONTROL_INTCAPXT_EN	51
+#define CONTROL_GAPPI_EN	55
 #define CONTROL_GCR3TRPMODE	58
 #define CONTROL_IRTCACHEDIS	59
 #define CONTROL_SNPAVIC_EN	61
drivers/iommu/amd/init.c +25 -3
index ef23e0755c32..c536e0b3c4ff 100644
@@ -446,6 +446,9 @@ static void iommu_disable(struct amd_iommu *iommu)
 	iommu_feature_disable(iommu, CONTROL_GALOG_EN);
 	iommu_feature_disable(iommu, CONTROL_GAINT_EN);
 
+	/* Disable IOMMU GAPPI */
+	iommu_feature_disable(iommu, CONTROL_GAPPI_EN);
+
 	/* Disable IOMMU PPR logging */
 	iommu_feature_disable(iommu, CONTROL_PPRLOG_EN);
 	iommu_feature_disable(iommu, CONTROL_PPRINT_EN);
@@ -2984,6 +2987,13 @@ static void enable_iommus_vapic(void)
 	struct amd_iommu *iommu;
 
 	for_each_iommu(iommu) {
+		/*
+		 * Disable GAPPI, do not check amd_iommu_gappi as it may be
+		 * false in new kexec kernel even though previous kernel has
+		 * enabled it.
+		 */
+		iommu_feature_disable(iommu, CONTROL_GAPPI_EN);
+
 		/*
 		 * Disable GALog if already running. It could have been enabled
 		 * in the previous boot before kdump.
@@ -3025,10 +3035,19 @@ static void enable_iommus_vapic(void)
 		return;
 	}
 
+	if (amd_iommu_gappi &&
+	    !(check_feature(FEATURE_GAPPI) &&
+	      AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))) {
+		pr_warn("GAPPI is not supported.\n");
+		amd_iommu_gappi = false;
+	}
+
 	/* Enabling GAM and SNPAVIC support */
 	for_each_iommu(iommu) {
-		if (iommu_init_ga_log(iommu) ||
-		    iommu_ga_log_enable(iommu))
+		if (amd_iommu_gappi)
+			iommu_feature_enable(iommu, CONTROL_GAPPI_EN);
+		else if (iommu_init_ga_log(iommu) ||
+			 iommu_ga_log_enable(iommu))
 			return;
 
 		iommu_feature_enable(iommu, CONTROL_GAM_EN);
@@ -3037,7 +3056,8 @@ static void enable_iommus_vapic(void)
 	}
 
 	amd_iommu_irq_ops.capability |= (1 << IRQ_POSTING_CAP);
-	pr_info("Virtual APIC enabled\n");
+	pr_info("Virtual APIC enabled with %s\n",
+		amd_iommu_gappi ? "GAPPI" : "GALOG");
 #endif
 }
 
@@ -3780,6 +3800,8 @@ static int __init parse_amd_iommu_options(char *str)
 		} else if (strncmp(str, "v2_pgsizes_only", 15) == 0) {
 			pr_info("Restricting V1 page-sizes to 4KiB/2MiB/1GiB");
 			amd_iommu_pgsize_bitmap = AMD_IOMMU_PGSIZES_V2;
+		} else if (strncmp(str, "gappi", 5) == 0) {
+			amd_iommu_gappi = true;
 		} else {
 			pr_notice("Unknown option - '%s'\n", str);
 		}
Signature · 1 line
2.34.1
#15 lore raw

Re: [PATCH v5 7/7] iommu/amd: Provide kernel command line option to enable GAPPI

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] iommu/amd: NULL pointer dereference in iommu_poll_ga_log() with GAPPI - [Medium] iommu/amd…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iommu/amd: NULL pointer dereference in iommu_poll_ga_log() with GAPPI
- [Medium] iommu/amd: amd_iommu_gappi state inconsistent on VAPIC fallback
- [Low] iommu/amd: missing GAPPI in feat_str feature name array
--

commit f3f34d41f6c88bbaa635da8109c52cf22d09f580
Author: Sairaj Kodilkar <[email protected]>

iommu/amd: Provide kernel command line option to enable GAPPI

Enable GAPPI when the IOMMU GAPPISup extended feature bit is set and the kernel is booted with the amd_iommu=gappi kernel parameter.

drivers/iommu/amd/amd_iommu_types.h line 81

Quoted 9 lines
drivers/iommu/amd/amd_iommu_types.h +1 -0
index b89a2b3df0a49..51edd617ddca2 100644
@@ -78,6 +78,7 @@
 #define FEATURE_X2APIC		BIT_ULL(2)
 #define FEATURE_NX		BIT_ULL(3)
 #define FEATURE_GT		BIT_ULL(4)
+#define FEATURE_GAPPI		BIT_ULL(5)

[Severity: Low]
This isn't a functional bug, but FEATURE_GAPPI is defined as bit 5.

In print_iommu_info(), bit 5 is still hardcoded as "[5]" in the feature string array:

drivers/iommu/amd/init.c:print_iommu_info() {
...

	static const char * const feat_str[] = {
		"PreF", "PPR", "X2APIC", "NX", "GT", "[5]",
		"IA", "GA", "HE", "PC"
	};

...
}

Should "[5]" be updated to "GAPPI" so the kernel boot log displays the correct feature name?

[ ... ]

Quoted 4 lines
drivers/iommu/amd/init.c +0 -0
index ef23e0755c32d..c536e0b3c4ff7 100644

[ ... ]

drivers/iommu/amd/init.c static void enable_iommus_vapic(void) · line 3043

Quoted 10 lines
drivers/iommu/amd/init.c +6 -0
@@ -3025,10 +3035,19 @@ static void enable_iommus_vapic(void)
 		return;
 	}
 
+	if (amd_iommu_gappi &&
+	    !(check_feature(FEATURE_GAPPI) &&
+	      AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))) {
+		pr_warn("GAPPI is not supported.\n");
+		amd_iommu_gappi = false;
+	}

[Severity: Medium]
If VAPIC is unsupported or disabled due to SNP, the code returns early just above this diff and falls back to legacy mode:

drivers/iommu/amd/init.c:enable_iommus_vapic() {
...

	if (!check_feature(FEATURE_GAM_VAPIC)) {
		amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
		return;
	}

	if (amd_iommu_snp_en &&
	    !FEATURE_SNPAVICSUP_GAM(amd_iommu_efr2)) {
		pr_warn("Force to disable Virtual APIC due to SNP\n");
		amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
		return;
	}

...
}

These early returns bypass the new fallback check added here that sets amd_iommu_gappi = false.

If KVM subsequently reads the stale amd_iommu_gappi flag and attempts to set up IRTE entries using GAPPI parameters, it calls irq_set_vcpu_affinity() which triggers this check:

drivers/iommu/amd/iommu.c:amd_ir_set_vcpu_affinity() {
...

	if (WARN_ON_ONCE(!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)))
		return -EINVAL;

...
}

Could this result in a kernel warning and failure to configure the affinity since the IOMMU driver actually fell back to legacy mode?

drivers/iommu/amd/init.c static void enable_iommus_vapic(void) · line 3051

Quoted 10 lines
drivers/iommu/amd/init.c +5 -2
+
 	/* Enabling GAM and SNPAVIC support */
 	for_each_iommu(iommu) {
-		if (iommu_init_ga_log(iommu) ||
-		    iommu_ga_log_enable(iommu))
+		if (amd_iommu_gappi)
+			iommu_feature_enable(iommu, CONTROL_GAPPI_EN);
+		else if (iommu_init_ga_log(iommu) ||
+			 iommu_ga_log_enable(iommu))
 			return;

[Severity: High]
If GAPPI is enabled, we skip allocating the GA log, so iommu->ga_log remains NULL.

If the previous kernel used the legacy GA log and left an interrupt pending, or if an unmasked interrupt triggers the handler:

drivers/iommu/amd/iommu.c:iommu_poll_ga_log() {
...

	head = readl(iommu->mmio_base + MMIO_GA_HEAD_OFFSET);
	tail = readl(iommu->mmio_base + MMIO_GA_TAIL_OFFSET);

	while (head != tail) {
		volatile u64 *raw;
...
		raw = (u64 *)(iommu->ga_log + head);
...
		/* Avoid memcpy function-call overhead */
		log_entry = *raw;

...
}

Won't the while loop unconditionally dereference iommu->ga_log which is now NULL, crashing the kernel?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#16 lore raw

Re: [PATCH v5 7/7] iommu/amd: Provide kernel command line option to enable GAPPI

Quoted 88 lines · On 10/15/2026 12:38 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iommu/amd: NULL pointer dereference in iommu_poll_ga_log() with GAPPI
- [Medium] iommu/amd: amd_iommu_gappi state inconsistent on VAPIC fallback
- [Low] iommu/amd: missing GAPPI in feat_str feature name array
--

commit f3f34d41f6c88bbaa635da8109c52cf22d09f580
Author: Sairaj Kodilkar <[email protected]>

iommu/amd: Provide kernel command line option to enable GAPPI

Enable GAPPI when the IOMMU GAPPISup extended feature bit is set and the kernel is booted with the amd_iommu=gappi kernel parameter.

drivers/iommu/amd/amd_iommu_types.h line 81

Quoted 9 lines
drivers/iommu/amd/amd_iommu_types.h +1 -0
index b89a2b3df0a49..51edd617ddca2 100644
@@ -78,6 +78,7 @@
 #define FEATURE_X2APIC		BIT_ULL(2)
 #define FEATURE_NX		BIT_ULL(3)
 #define FEATURE_GT		BIT_ULL(4)
+#define FEATURE_GAPPI		BIT_ULL(5)

[Severity: Low]
This isn't a functional bug, but FEATURE_GAPPI is defined as bit 5.

In print_iommu_info(), bit 5 is still hardcoded as "[5]" in the feature string array:

drivers/iommu/amd/init.c:print_iommu_info() {
...

	static const char * const feat_str[] = {
		"PreF", "PPR", "X2APIC", "NX", "GT", "[5]",
		"IA", "GA", "HE", "PC"
	};

...
}

Should "[5]" be updated to "GAPPI" so the kernel boot log displays the correct feature name?

[ ... ]

Quoted 4 lines
drivers/iommu/amd/init.c +0 -0
index ef23e0755c32d..c536e0b3c4ff7 100644

[ ... ]

drivers/iommu/amd/init.c static void enable_iommus_vapic(void) · line 3043

Quoted 10 lines
drivers/iommu/amd/init.c +6 -0
@@ -3025,10 +3035,19 @@ static void enable_iommus_vapic(void)
 		return;
 	}
 
+	if (amd_iommu_gappi &&
+	    !(check_feature(FEATURE_GAPPI) &&
+	      AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))) {
+		pr_warn("GAPPI is not supported.\n");
+		amd_iommu_gappi = false;
+	}

[Severity: Medium]
If VAPIC is unsupported or disabled due to SNP, the code returns early just above this diff and falls back to legacy mode:

drivers/iommu/amd/init.c:enable_iommus_vapic() {
...

	if (!check_feature(FEATURE_GAM_VAPIC)) {
		amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
		return;
	}

	if (amd_iommu_snp_en &&
	    !FEATURE_SNPAVICSUP_GAM(amd_iommu_efr2)) {
		pr_warn("Force to disable Virtual APIC due to SNP\n");
		amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
		return;
	}

...
}

These early returns bypass the new fallback check added here that sets amd_iommu_gappi = false.

If KVM subsequently reads the stale amd_iommu_gappi flag and attempts to set up IRTE entries using GAPPI parameters, it calls irq_set_vcpu_affinity() which triggers this check:

drivers/iommu/amd/iommu.c:amd_ir_set_vcpu_affinity() {
...

Quoted 7 lines
	if (WARN_ON_ONCE(!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)))
		return -EINVAL;

...
}

Could this result in a kernel warning and failure to configure the affinity since the IOMMU driver actually fell back to legacy mode?

The early return will skip setting up IRQ_POSTING_CAP flag, subsequently KVM will use legacy mode interrupt routing (using eventfd) instead of setting up IRQ bypass. Because of which KVM does not call amd_ir_set_vcpu_affinity.

Thanks
Sairaj

Quoted 37 lines

drivers/iommu/amd/init.c static void enable_iommus_vapic(void) · line 3051

Quoted 11 lines
drivers/iommu/amd/init.c +5 -2
+
 	/* Enabling GAM and SNPAVIC support */
 	for_each_iommu(iommu) {
-		if (iommu_init_ga_log(iommu) ||
-		    iommu_ga_log_enable(iommu))
+		if (amd_iommu_gappi)
+			iommu_feature_enable(iommu, CONTROL_GAPPI_EN);
+		else if (iommu_init_ga_log(iommu) ||
+			 iommu_ga_log_enable(iommu))
 			return;

[Severity: High]
If GAPPI is enabled, we skip allocating the GA log, so iommu->ga_log remains NULL.

If the previous kernel used the legacy GA log and left an interrupt pending, or if an unmasked interrupt triggers the handler:

drivers/iommu/amd/iommu.c:iommu_poll_ga_log() {
...

	head = readl(iommu->mmio_base + MMIO_GA_HEAD_OFFSET);
	tail = readl(iommu->mmio_base + MMIO_GA_TAIL_OFFSET);

	while (head != tail) {
		volatile u64 *raw;
...
		raw = (u64 *)(iommu->ga_log + head);
...
		/* Avoid memcpy function-call overhead */
		log_entry = *raw;

...
}

Won't the while loop unconditionally dereference iommu->ga_log which is now NULL, crashing the kernel?

#17 lore raw

Re: [PATCH v5 7/7] iommu/amd: Provide kernel command line option to enable GAPPI

In reply to [email protected]
Quoted 126 lines · On 10/15/2026 12:38 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iommu/amd: NULL pointer dereference in iommu_poll_ga_log() with GAPPI
- [Medium] iommu/amd: amd_iommu_gappi state inconsistent on VAPIC fallback
- [Low] iommu/amd: missing GAPPI in feat_str feature name array
--

commit f3f34d41f6c88bbaa635da8109c52cf22d09f580
Author: Sairaj Kodilkar <[email protected]>

iommu/amd: Provide kernel command line option to enable GAPPI

Enable GAPPI when the IOMMU GAPPISup extended feature bit is set and the kernel is booted with the amd_iommu=gappi kernel parameter.

drivers/iommu/amd/amd_iommu_types.h line 81

Quoted 9 lines
drivers/iommu/amd/amd_iommu_types.h +1 -0
index b89a2b3df0a49..51edd617ddca2 100644
@@ -78,6 +78,7 @@
 #define FEATURE_X2APIC		BIT_ULL(2)
 #define FEATURE_NX		BIT_ULL(3)
 #define FEATURE_GT		BIT_ULL(4)
+#define FEATURE_GAPPI		BIT_ULL(5)

[Severity: Low]
This isn't a functional bug, but FEATURE_GAPPI is defined as bit 5.

In print_iommu_info(), bit 5 is still hardcoded as "[5]" in the feature string array:

drivers/iommu/amd/init.c:print_iommu_info() {
...

	static const char * const feat_str[] = {
		"PreF", "PPR", "X2APIC", "NX", "GT", "[5]",
		"IA", "GA", "HE", "PC"
	};

...
}

Should "[5]" be updated to "GAPPI" so the kernel boot log displays the correct feature name?

[ ... ]

Quoted 4 lines
drivers/iommu/amd/init.c +0 -0
index ef23e0755c32d..c536e0b3c4ff7 100644

[ ... ]

drivers/iommu/amd/init.c static void enable_iommus_vapic(void) · line 3043

Quoted 10 lines
drivers/iommu/amd/init.c +6 -0
@@ -3025,10 +3035,19 @@ static void enable_iommus_vapic(void)
 		return;
 	}
 
+	if (amd_iommu_gappi &&
+	    !(check_feature(FEATURE_GAPPI) &&
+	      AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))) {
+		pr_warn("GAPPI is not supported.\n");
+		amd_iommu_gappi = false;
+	}

[Severity: Medium]
If VAPIC is unsupported or disabled due to SNP, the code returns early just above this diff and falls back to legacy mode:

drivers/iommu/amd/init.c:enable_iommus_vapic() {
...

	if (!check_feature(FEATURE_GAM_VAPIC)) {
		amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
		return;
	}

	if (amd_iommu_snp_en &&
	    !FEATURE_SNPAVICSUP_GAM(amd_iommu_efr2)) {
		pr_warn("Force to disable Virtual APIC due to SNP\n");
		amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
		return;
	}

...
}

These early returns bypass the new fallback check added here that sets amd_iommu_gappi = false.

If KVM subsequently reads the stale amd_iommu_gappi flag and attempts to set up IRTE entries using GAPPI parameters, it calls irq_set_vcpu_affinity() which triggers this check:

drivers/iommu/amd/iommu.c:amd_ir_set_vcpu_affinity() {
...

	if (WARN_ON_ONCE(!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)))
		return -EINVAL;

...
}

Could this result in a kernel warning and failure to configure the affinity since the IOMMU driver actually fell back to legacy mode?

drivers/iommu/amd/init.c static void enable_iommus_vapic(void) · line 3051

Quoted 10 lines
drivers/iommu/amd/init.c +5 -2
+
 	/* Enabling GAM and SNPAVIC support */
 	for_each_iommu(iommu) {
-		if (iommu_init_ga_log(iommu) ||
-		    iommu_ga_log_enable(iommu))
+		if (amd_iommu_gappi)
+			iommu_feature_enable(iommu, CONTROL_GAPPI_EN);
+		else if (iommu_init_ga_log(iommu) ||
+			 iommu_ga_log_enable(iommu))
 			return;

[Severity: High]
If GAPPI is enabled, we skip allocating the GA log, so iommu->ga_log remains NULL.

If the previous kernel used the legacy GA log and left an interrupt pending, or if an unmasked interrupt triggers the handler:

drivers/iommu/amd/iommu.c:iommu_poll_ga_log() {
...

	head = readl(iommu->mmio_base + MMIO_GA_HEAD_OFFSET);
	tail = readl(iommu->mmio_base + MMIO_GA_TAIL_OFFSET);

	while (head != tail) {
		volatile u64 *raw;
...
		raw = (u64 *)(iommu->ga_log + head);
...
		/* Avoid memcpy function-call overhead */
		log_entry = *raw;
Quoted 6 lines

...
}

Won't the while loop unconditionally dereference iommu->ga_log which is now NULL, crashing the kernel?

This is a valid concern. This is a pre-existing bug and can arise if second kernel has IRQ_REMAP disabled or fails to enable ga_log. Hence it is better to address this in a separate series.

Thanks
Sairaj

#18 lore raw

Re: [PATCH v5 7/7] iommu/amd: Provide kernel command line option to enable GAPPI

In reply to Sairaj Kodilkar
kernel test robot noticed the following build errors:

Hi Sairaj,

kernel test robot noticed the following build errors:

[auto build test ERROR on 4056b3c9d3c92ea45955641dbafeb9b960e146ef]

url:    https://github.com/intel-lab-lkp/linux/commits/Sairaj-Kodilkar/iommu-amd-KVM-SVM-Rename-cpu-to-apicid-in-IOMMU-interface/20261015-121509
base:   4056b3c9d3c92ea45955641dbafeb9b960e146ef
patch link:    https://lore.kernel.org/r/20261015064515.10700-8-sarunkod%40amd.com
patch subject: [PATCH v5 7/7] iommu/amd: Provide kernel command line option to enable GAPPI
config: x86_64-randconfig-1017-20261016 (https://download.01.org/0day-ci/archive/20261016/[email protected]/config)
compiler: clang version 22.1.8 (https://github.com/llvm/llvm-project ca7933e47d3a3451d81e72ac174dcb5aa28b59d1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261016/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/iommu/amd/init.c:163:6: error: redefinition of 'false' as different kind of symbol

     163 | bool amd_iommu_gappi;
         |      ^
   include/linux/amd-iommu.h:65:25: note: expanded from macro 'amd_iommu_gappi'
      65 | #define amd_iommu_gappi false
         |                         ^
   include/linux/stddef.h:11:2: note: previous definition is here
      11 |         false   = 0,
         |         ^
   drivers/iommu/amd/init.c:164:15: error: redefinition of 'false' as different kind of symbol
     164 | EXPORT_SYMBOL(amd_iommu_gappi);
         |               ^
   include/linux/amd-iommu.h:65:25: note: expanded from macro 'amd_iommu_gappi'
      65 | #define amd_iommu_gappi false
         |                         ^
   include/linux/stddef.h:11:2: note: previous definition is here
      11 |         false   = 0,
         |         ^
   drivers/iommu/amd/init.c:164:1: error: cannot take the address of an rvalue of type 'int'
     164 | EXPORT_SYMBOL(amd_iommu_gappi);
         | ^             ~~~~~~~~~~~~~~~
   include/linux/export.h:89:29: note: expanded from macro 'EXPORT_SYMBOL'
      89 | #define EXPORT_SYMBOL(sym)              _EXPORT_SYMBOL(sym, "")
         |                                         ^              ~~~
   include/linux/export.h:86:38: note: expanded from macro '_EXPORT_SYMBOL'
      86 | #define _EXPORT_SYMBOL(sym, license)    __EXPORT_SYMBOL(sym, license, "")
         |                                         ^               ~~~
   include/linux/export.h:77:2: note: expanded from macro '__EXPORT_SYMBOL'
      77 |         __ADDRESSABLE(sym)                                      \
         |         ^             ~~~
   include/linux/compiler.h:276:2: note: expanded from macro '__ADDRESSABLE'
     276 |         ___ADDRESSABLE(sym, __section(".discard.addressable"))
         |         ^              ~~~
   include/linux/compiler.h:273:63: note: expanded from macro '___ADDRESSABLE'
     273 |         __UNIQUE_ID(__PASTE(addressable_, sym)) = (void *)(uintptr_t)&sym;
         |                                                                      ^~~~
>> drivers/iommu/amd/init.c:3804:20: error: expression is not assignable
    3804 |                         amd_iommu_gappi = true;
         |                         ~~~~~~~~~~~~~~~ ^

4 errors generated.

vim +3804 drivers/iommu/amd/init.c

3775
3776 static int __init parse_amd_iommu_options(char *str)
3777 {
3778 if (!str)
3779 return -EINVAL;
3780
3781 while (*str) {
3782 if (strncmp(str, "fullflush", 9) == 0) {
3783 pr_warn("amd_iommu=fullflush deprecated; use iommu.strict=1 instead\n");
3784 iommu_set_dma_strict();
3785 } else if (strncmp(str, "force_enable", 12) == 0) {
3786 amd_iommu_force_enable = true;
3787 } else if (strncmp(str, "off", 3) == 0) {
3788 amd_iommu_disabled = true;
3789 } else if (strncmp(str, "force_isolation", 15) == 0) {
3790 amd_iommu_force_isolation = true;
3791 } else if (strncmp(str, "pgtbl_v1", 8) == 0) {
3792 amd_iommu_pgtable = PD_MODE_V1;
3793 } else if (strncmp(str, "pgtbl_v2", 8) == 0) {
3794 amd_iommu_pgtable = PD_MODE_V2;
3795 } else if (strncmp(str, "irtcachedis", 11) == 0) {
3796 amd_iommu_irtcachedis = true;
3797 } else if (strncmp(str, "nohugepages", 11) == 0) {
3798 pr_info("Restricting V1 page-sizes to 4KiB");
3799 amd_iommu_pgsize_bitmap = AMD_IOMMU_PGSIZES_4K;
3800 } else if (strncmp(str, "v2_pgsizes_only", 15) == 0) {
3801 pr_info("Restricting V1 page-sizes to 4KiB/2MiB/1GiB");
3802 amd_iommu_pgsize_bitmap = AMD_IOMMU_PGSIZES_V2;
3803 } else if (strncmp(str, "gappi", 5) == 0) {

> 3804				amd_iommu_gappi = true;

3805 } else {
3806 pr_notice("Unknown option - '%s'\n", str);
3807 }
3808
3809 str += strcspn(str, ",");
3810 while (*str == ',')
3811 str++;
3812 }
3813
3814 return 1;
3815 }
3816

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki