Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Sairaj Kodilkar <sarunkod@amd.com>
To: <sashiko-reviews@lists.linux.dev>, <kvm@vger.kernel.org>
Cc: <sarunkod@amd.com>
Subject: Re: [PATCH v5 5/7] KVM: VMX: Factor out wakeup list handling code to KVM
Date: Mon, 19 Oct 2026 12:05:33 +0530	[thread overview]
Message-ID: <0262aa0a-1835-4359-92c2-e6b336030fe6@amd.com> (raw)
In-Reply-To: <sashiko-outbox-172375@kernel.org>



On 10/15/2026 12:30 PM, sashiko-bot@kernel.org 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 <sarunkod@amd.com>
> 
> 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.
> 
>> diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h
>> index e213c9ae3e301..5d337f9336c5d 100644
>> --- a/arch/x86/include/asm/kvm-x86-ops.h
>> +++ b/arch/x86/include/asm/kvm-x86-ops.h
>> @@ -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.
> 

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

Thanks
Sairaj

> [ ... ]
> 
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index aad065d035fbb..0c637a18bcfa4 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
> 
> [ ... ]
> 
>> @@ -2688,6 +2709,79 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
> 
> [ ... ]
> 
>> +/*
>> + * 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.
> 
>> +			kvm_vcpu_wake_up(vcpu);
>> +	}
>> +	raw_spin_unlock(spinlock);
>> +}
> 


  reply	other threads:[~2026-10-19  6:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  6:45 [PATCH v5 0/7] Add support for AMD IOMMU GAPPI Sairaj Kodilkar
2026-10-15  6:45 ` [PATCH v5 1/7] iommu/amd: KVM: SVM: Rename cpu to apicid in IOMMU interface Sairaj Kodilkar
2026-10-15  6:45 ` [PATCH v5 2/7] iommu/amd: KVM: SVM: Rename ga_log_intr to wakeup_intr " Sairaj Kodilkar
2026-10-15  6:45 ` [PATCH v5 3/7] iommu/amd: KVM: SVM: Add explicit vCPU running state to " Sairaj Kodilkar
2026-10-15  6:45 ` [PATCH v5 4/7] iommu/amd: Program guest-mode IRTEs for GAPPI wakeup when IRTE[IsRun] = 0 Sairaj Kodilkar
2026-10-15  7:03   ` sashiko-bot
2026-10-19  6:31     ` Sairaj Kodilkar
2026-10-16  4:54   ` kernel test robot
2026-10-15  6:45 ` [PATCH v5 5/7] KVM: VMX: Factor out wakeup list handling code to KVM Sairaj Kodilkar
2026-10-15  7:00   ` sashiko-bot
2026-10-19  6:35     ` Sairaj Kodilkar [this message]
2026-10-15  6:45 ` [PATCH v5 6/7] KVM: SVM: Add support for AMD IOMMU Guest APIC Physical Processor Interrupt (GAPPI) Sairaj Kodilkar
2026-10-15  7:05   ` sashiko-bot
2026-10-19  7:44     ` Sairaj Kodilkar
2026-10-15  6:45 ` [PATCH v5 7/7] iommu/amd: Provide kernel command line option to enable GAPPI Sairaj Kodilkar
2026-10-15  7:08   ` sashiko-bot
2026-10-21  8:57     ` Sairaj Kodilkar
2026-10-16  8:23   ` kernel test robot

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=0262aa0a-1835-4359-92c2-e6b336030fe6@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox