From: Sairaj Kodilkar <sarunkod@amd.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: <sarunkod@amd.com>, <kvm@vger.kernel.org>
Subject: Re: [RFC PATCH v3 3/6] iommu/amd: KVM: SVM: Add explicit vCPU running state to IOMMU interface
Date: Mon, 10 Aug 2026 10:36:53 +0530 [thread overview]
Message-ID: <6a742247-ad0d-41b2-8bef-19ed342ec57a@amd.com> (raw)
In-Reply-To: <20260713110858.EAEF31F000E9@smtp.kernel.org>
On 7/13/2026 4:38 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] KVM continues to infer the vCPU running state via `is_running = apicid >= 0`, completely defeating the purpose of the newly decoupled IOMMU API.
> --
>
> --- Patch [3]: [RFC PATCH v3 3/6] iommu/amd: KVM: SVM: Add explicit vCPU running state to IOMMU interface ---
> commit bbb2175fc26e0d5c105e610aeee4bcf1fe796a2d
> Author: Sairaj Kodilkar <sarunkod@amd.com>
> iommu/amd: KVM: SVM: Add explicit vCPU running state to IOMMU interface
>
> This commit adds an explicit is_running parameter to the AMD IOMMU guest
> mode interface. It states that this decoupling is necessary for GAPPI to
> pass a valid destination apicid when a vCPU is not running. The change
> intends to allow KVM to pass the vCPU running state explicitly rather than
> inferring it from the apicid value.
>
>> diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
>> index 8e87a7f2f64f7..3b2d92a587098 100644
>> --- a/arch/x86/kvm/svm/avic.c
>> +++ b/arch/x86/kvm/svm/avic.c
> [ ... ]
>> @@ -1008,6 +1010,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;
>
> [Severity: Medium]
> Does this assignment defeat the purpose of the API decoupling described
> in the commit message?
>
> The commit message states that KVM must supply a valid apicid even when
> the vCPU is not running, and that we can no longer derive the vCPU running
> state from the apicid alone.
>
> However, by defining is_running as apicid >= 0 here in
> avic_update_iommu_vcpu_affinity(), aren't we continuing to infer the
> running state directly from the apicid?
>
> If a caller attempts to pass a valid GAPPI destination APIC ID for a
> scheduled-out vCPU, won't this helper erroneously force is_running to true?
> Because of this hardcoded logic, other KVM paths handling scheduled-out
> vCPUs would be forced to continue passing -1 for the APIC ID rather than
> a valid GAPPI destination.
>
No — this does not defeat the API decoupling. The change is that the
IOMMU driver no longer infers vCPU running state from apicid.
Previously, __amd_iommu_update_ga() used apicid >= 0 to decide
IRTE[IsRun] and destination programming. That breaks with GAPPI, where a
scheduled-out vCPU still needs a valid IRTE[Destination] while
IRTE[IsRun] is clear. The new API takes an explicit is_running parameter
so the IOMMU can program both fields independently.
The is_running = apicid >= 0 assignment in
avic_update_iommu_vcpu_affinity() is internal SVM logic, not part of the
IOMMU API. That helper is private to avic.c and only called from
__avic_vcpu_load() (running pCPU APIC ID) and __avic_vcpu_put() (apicid
= -1). Within SVM, apicid == -1 still means the vCPU is not running.
When GAPPI is enabled on that path, SVM derives the GAPPI destination
from gappi_cpu, substitutes it into apicid, and calls the IOMMU with
is_running = false.
Scheduled-out callers pass -1 to this helper by convention; SVM
translates that into (valid GAPPI apicid, is_running = false) before
reaching the IOMMU. The inference moved from the IOMMU layer to SVM,
where vCPU lifecycle is already known. avic_pi_update_irte() follows the
same model: it sets is_running explicitly and fills GAPPI apicid
separately when the vCPU is not running.
Thanks
Sairaj
>> struct vcpu_svm *svm = to_svm(vcpu);
>> struct kvm_kernel_irqfd *irqfd;
>>
> [ ... ]
>> @@ -1024,9 +1027,10 @@ 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_activate_guest_mode(data, apicid, wakeup_intr));
>> + 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,
>> + is_running));
>> else
>> WARN_ON_ONCE(amd_iommu_deactivate_guest_mode(data));
>> }
>
next prev parent reply other threads:[~2026-08-10 5:07 UTC|newest]
Thread overview: 21+ 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-08-10 5:06 ` Sairaj Kodilkar [this message]
2026-08-11 0:34 ` Sean Christopherson
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-08-10 5:14 ` Sairaj Kodilkar
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-08-11 0:40 ` Sean Christopherson
2026-08-10 5:54 ` Sairaj Kodilkar
2026-08-11 0:43 ` Sean Christopherson
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
2026-08-10 6:12 ` Sairaj Kodilkar
2026-08-10 9:21 ` [RFC PATCH v3 0/6] Add support for AMD IOMMU GAPPI Sairaj Kodilkar
2026-08-11 0:48 ` Sean Christopherson
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=6a742247-ad0d-41b2-8bef-19ed342ec57a@amd.com \
--to=sarunkod@amd.com \
--cc=kvm@vger.kernel.org \
--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.