All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fuad Tabba" <fuad.tabba@linux.dev>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH 2/3] KVM: arm64: Reject KVM_RUN on a vCPU that's no longer initialized
Date: Mon, 30 Nov 2026 14:55:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-241445@kernel.org> (raw)
In-Reply-To: <20261130144438.3176276-3-fuad.tabba@linux.dev>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] KVM: arm64: stolen time underflow in kvm_update_stolen_time()
  [1]
--

commit bfa878fdb69c60cb82e53267508c4265191ade79
Author: Fuad Tabba <fuad.tabba@linux.dev>

KVM: arm64: Reject KVM_RUN on a vCPU that's no longer initialized

This commit restores the kvm_vcpu_initialized() check in
kvm_arch_vcpu_ioctl_run() so that KVM_RUN returns -ENOEXEC if a vCPU has
been marked uninitialized after its first run.

> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index cfaaadd97233f..6c2d3811f2814 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -1417,6 +1417,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
>  	struct kvm_run *run = vcpu->run;
>  	int ret;
>  
> +	if (unlikely(!kvm_vcpu_initialized(vcpu)))
> +		return -ENOEXEC;
> +
>  	if (run->exit_reason == KVM_EXIT_MMIO) {
>  		ret = kvm_handle_mmio_return(vcpu);
>  		if (ret <= 0)

[Severity: High]
This problem wasn't introduced by this patch, but can
vcpu->arch.steal.last_steal underflow in kvm_update_stolen_time() [1]
when a vCPU migrates to a new host thread?

When a new thread runs a vCPU that has already run once,
kvm_arch_vcpu_run_pid_change() returns early without resetting
vcpu->arch.steal.last_steal to the new task's run_delay:

arch/arm64/kvm/arm.c:kvm_arch_vcpu_run_pid_change() {
	...
	if (likely(vcpu_has_run_once(vcpu)))
		return 0;
	...
}

On the next guest entry, kvm_update_stolen_time() subtracts the previous
thread's cached run_delay from the new thread's
current->sched_info.run_delay:

arch/arm64/kvm/pvtime.c:kvm_update_stolen_time() {
	...
	if (!kvm_get_guest(kvm, base + offset, steal)) {
		steal = le64_to_cpu(steal);
		vcpu->arch.steal.last_steal = READ_ONCE(current->sched_info.run_delay);
		steal += vcpu->arch.steal.last_steal - last_steal;
		kvm_put_guest(kvm, base + offset, cpu_to_le64(steal));
	}
	...
}

If the new thread has accumulated less runqueue delay than the old thread,
the unsigned subtraction wraps around and writes a bogus stolen_time value
to guest memory, corrupting guest CPU time accounting.

[1] https://sashiko.dev/#/bug/linux-9029bf19-3622-4a26-a158-ad236ad8cc5f

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130144438.3176276-1-fuad.tabba@linux.dev?part=2

  reply	other threads:[~2026-11-30 14:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 14:44 [PATCH 0/3] KVM: arm64: Fixes for a vCPU caught in a disallowed AArch32 mode Fuad Tabba
2026-11-30 14:44 ` [PATCH 1/3] KVM: arm64: Don't call kvm_setup_vcpu() again once a vCPU has run Fuad Tabba
2026-11-30 14:44 ` [PATCH 2/3] KVM: arm64: Reject KVM_RUN on a vCPU that's no longer initialized Fuad Tabba
2026-11-30 14:55   ` sashiko-bot [this message]
2026-11-30 15:11     ` Fuad Tabba
2026-11-30 14:44 ` [PATCH 3/3] KVM: arm64: Don't run a protected vCPU that was caught in AArch32 Fuad Tabba

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=sashiko-outbox-241445@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fuad.tabba@linux.dev \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@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.