Kernel KVM virtualization development
 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 v2 5/5] iommu/amd: Provide kernel command line option to enable GAPPI
Date: Wed, 08 Jul 2026 09:40:45 +0000	[thread overview]
Message-ID: <20260708094045.E1D851F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260708091408.12106-6-sarunkod@amd.com>

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

New issues:
- [High] Global state `amd_iommu_gappi` remains incorrectly `true` when VAPIC is unsupported or disabled by SNP, causing KVM state corruption.

Pre-existing issues:
- [High] Memory leak and sleeping in atomic context during system resume on the GALog fallback path.
- [High] Resource leak and inconsistent VAPIC state if GALog initialization fails on a secondary IOMMU.
--

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

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

This commit adds a new kernel command line parameter amd_iommu=gappi. It
allows enabling the GAPPI feature if the corresponding extended feature bit
is set in the hardware. It modifies the IOMMU initialization sequence to
configure GAPPI when enabled.

> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index e2da6d5a63c78..a1dd2e8840d6c 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c

[ ... ]

> @@ -3016,10 +3025,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: High]
Does this leave amd_iommu_gappi erroneously set to true if an early return
is taken?

If the kernel is booted with amd_iommu=gappi, the variable is initially
true. In enable_iommus_vapic(), if an early return is taken before reaching
this validation check (for instance, when check_feature(FEATURE_GAM_VAPIC)
returns false, or if forced to disable due to SNP), the function exits
without resetting amd_iommu_gappi to false.

Because the variable remains true, exported subsystems like KVM AVIC might
incorrectly assume hardware GAPPI is active and attempt to use it, which
could lead to state corruption or missed interrupts.

> +
>  	/* 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]
This is a pre-existing issue, but does this early return leave the VAPIC
configuration in an inconsistent state if it fails on a secondary IOMMU?

In enable_iommus_vapic(), if iommu_init_ga_log() or iommu_ga_log_enable()
fails for any IOMMU after the first one, the function returns immediately.
This leaves the global kernel state assuming VAPIC is active, but some
IOMMUs are left unconfigured. It also skips reverting amd_iommu_guest_ir
or cleaning up resources for the previously configured IOMMUs.

[Severity: High]
This isn't a bug introduced by this patch, but can calling
iommu_init_ga_log() here cause a memory leak and a sleeping in atomic
context issue during system resume?

During system resume, syscore_ops.resume runs with local interrupts
disabled. amd_iommu_resume() calls amd_iommu_enable_interrupts(), which
invokes enable_iommus_vapic().

On the GALog fallback path, it unconditionally calls iommu_init_ga_log().
This function then allocates memory using GFP_KERNEL:

drivers/iommu/amd/init.c:iommu_init_ga_log() {
    ...
    iommu->ga_log = iommu_alloc_pages_node_sz(nid, GFP_KERNEL, GA_LOG_SIZE);
    ...
}

Using GFP_KERNEL in atomic context triggers a sleeping in atomic context
bug. In addition, the existing ga_log pointers are overwritten without
being freed, which leaks the previous allocations on every resume cycle.

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

      reply	other threads:[~2026-07-08  9:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  9:14 [RFC PATCH v2 0/5] Add support for AMD IOMMU GAPPI Sairaj Kodilkar
2026-07-08  9:14 ` [RFC PATCH v2 1/5] iommu/amd: kvm/svm: Improve API between SVM and AMD IOMMU Sairaj Kodilkar
2026-07-08 13:36   ` Sean Christopherson
2026-07-09  6:39     ` Sairaj Kodilkar
2026-07-10 17:19       ` Sean Christopherson
2026-07-08  9:14 ` [RFC PATCH v2 2/5] iommu/amd: Configure IRTE to use the GAPPI for posted interrupts Sairaj Kodilkar
2026-07-08  9:37   ` sashiko-bot
2026-07-08  9:14 ` [RFC PATCH v2 3/5] kvm/svm: Introduce per-CPU lock and wakeup queue Sairaj Kodilkar
2026-07-08 13:36   ` Sean Christopherson
2026-07-08  9:14 ` [RFC PATCH v2 4/5] kvm/svm: Update the per-CPU wakeup-list during vCPU load and unload Sairaj Kodilkar
2026-07-08  9:37   ` sashiko-bot
2026-07-08 13:38   ` Sean Christopherson
2026-07-08  9:14 ` [RFC PATCH v2 5/5] iommu/amd: Provide kernel command line option to enable GAPPI Sairaj Kodilkar
2026-07-08  9:40   ` 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=20260708094045.E1D851F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox