All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sairaj Kodilkar" <sarunkod@amd.com>
Cc: kvm@vger.kernel.org
Subject: Re: [RFC PATCH v3 6/6] iommu/amd: Provide kernel command line option to enable GAPPI
Date: Mon, 13 Jul 2026 11:11:25 +0000	[thread overview]
Message-ID: <20260713111125.9DC2F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260713105033.15405-7-sarunkod@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Critical] Unconditional enablement of GA log on overflow in kexec/kdump environments with GAPPI leads to critical DMA memory corruption.

Pre-existing issues:
- [High] Lockless read-modify-write of the IOMMU MMIO control register causes a race condition that can permanently disable IOMMU interrupts or GAPPI.
--

--- Patch [6]: [RFC PATCH v3 6/6] iommu/amd: Provide kernel command line option to enable GAPPI ---
commit 38ebc4ddc54202efd2ae74234b7ee4169af3e39a
Author: Sairaj Kodilkar <sarunkod@amd.com>

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

This commit adds a kernel parameter to enable GAPPI for AMD IOMMUs when
the GAPPISup extended feature bit is set. It also modifies initialization
code to handle GAPPI alongside the existing GALOG feature.

> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index 2e1889f8a9e42..7d2b1c24f6ecc 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c

[ ... ]

> @@ -2999,6 +3002,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);

[Severity: High]
This is a pre-existing issue, but does this unlocked modification of the
IOMMU MMIO control register cause a race condition that could disable
interrupts or other features?

The iommu_feature_disable() function performs a read-modify-write without
holding iommu->lock:

drivers/iommu/amd/init.c:iommu_feature_set() {
    ctrl = readq(iommu->mmio_base +  MMIO_CONTROL_OFFSET);
    ctrl &= ~((u64)mask << shift);
    ctrl |= ((u64)val << shift) & ((u64)mask << shift);
    writeq(ctrl, iommu->mmio_base +  MMIO_CONTROL_OFFSET);
}

During initialization, the IRQ thread could be running concurrently. If a log
overflow occurs, the IRQ thread calls amd_iommu_restart_log() which also
invokes iommu_feature_disable().

Since this read-modify-write isn't synchronized, could concurrent
modifications silently overwrite each other?

> +
>  		/*
>  		 * Disable GALog if already running. It could have been enabled

[ ... ]

> @@ -3038,10 +3048,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;
>  

[Severity: Critical]
If the system is booted into a kdump kernel with GAPPI enabled, could this
lead to the IOMMU writing to stale physical memory from the previous kernel?

When GAPPI is used, iommu_init_ga_log() is skipped, meaning the ga_log buffer
is not allocated. However, if the previous kernel crashed with a pending GA
log overflow, the hardware's overflow status bit remains set.

Once shared IOMMU interrupts are enabled, the pending overflow status triggers
the interrupt thread:

drivers/iommu/amd/iommu.c:amd_iommu_int_thread_galog() {
    amd_iommu_handle_irq(data, "GA", MMIO_STATUS_GALOG_INT_MASK,
                         MMIO_STATUS_GALOG_OVERFLOW_MASK,
                         iommu_poll_ga_log, amd_iommu_restart_ga_log);
}

This calls amd_iommu_restart_ga_log() which unconditionally enables
CONTROL_GALOG_EN:

drivers/iommu/amd/init.c:amd_iommu_restart_ga_log() {
    amd_iommu_restart_log(iommu, "GA", CONTROL_GAINT_EN,
                          CONTROL_GALOG_EN, MMIO_STATUS_GALOG_RUN_MASK,
                          MMIO_STATUS_GALOG_OVERFLOW_MASK);
}

Since CONTROL_GALOG_EN is re-enabled without checking if GAPPI is active or
if the log memory was allocated, will the IOMMU resume writing GA log
entries to the uninitialized physical address left by the crashed kernel?

>  		iommu_feature_enable(iommu, CONTROL_GAM_EN);
>  		if (amd_iommu_snp_en)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260713105033.15405-1-sarunkod@amd.com?part=6

      reply	other threads:[~2026-07-13 11:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13 10:50 [RFC PATCH v3 0/6] Add support for AMD IOMMU GAPPI Sairaj Kodilkar
2026-07-13 10:50 ` [RFC PATCH v3 1/6] iommu/amd: KVM: SVM: Rename cpu to apicid in IOMMU interface Sairaj Kodilkar
2026-07-13 10:50 ` [RFC PATCH v3 2/6] iommu/amd: KVM: SVM: Rename ga_log_intr to wakeup_intr " Sairaj Kodilkar
2026-07-13 10:50 ` [RFC PATCH v3 3/6] iommu/amd: KVM: SVM: Add explicit vCPU running state to " Sairaj Kodilkar
2026-07-13 11:08   ` sashiko-bot
2026-07-13 10:50 ` [RFC PATCH v3 4/6] iommu/amd: Program guest-mode IRTEs for GAPPI wakeup when IRTE[IsRun] = 0 Sairaj Kodilkar
2026-07-13 11:07   ` sashiko-bot
2026-07-13 10:50 ` [RFC PATCH v3 5/6] KVM: SVM: Add support for AMD IOMMU Guest APIC Physical Processor Interrupt (GAPPI) Sairaj Kodilkar
2026-07-13 11:11   ` sashiko-bot
2026-07-13 12:56     ` Sairaj Kodilkar
2026-07-13 10:50 ` [RFC PATCH v3 6/6] iommu/amd: Provide kernel command line option to enable GAPPI Sairaj Kodilkar
2026-07-13 11:11   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260713111125.9DC2F1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sarunkod@amd.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.