From: Marc Zyngier <maz@kernel.org>
To: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, will@kernel.org,
oliver.upton@linux.dev, alexandru.elisei@arm.com,
aneesh.kumar@kernel.org, steven.price@arm.com, tabba@google.com
Subject: Re: [PATCH kvmtool v4 01/15] Allow pausing the VM from vcpu thread
Date: Thu, 08 Jan 2026 14:19:12 +0000 [thread overview]
Message-ID: <861pk0mbkv.wl-maz@kernel.org> (raw)
In-Reply-To: <20250930103130.197534-2-suzuki.poulose@arm.com>
On Tue, 30 Sep 2025 11:31:15 +0100,
Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>
> Pausing the VM from a vCPU thread doesn't work today, as it waits indefinitely
> for a signal that never comes. By using the "current_kvm_cpu", enlighten the
> kvm__pause() to skip the current CPU and do it inline. This also brings in a
> restriction that a following kvm__continue() must be called from the same vCPU
> thread.
>
> Cc: Will Deacon <will@kernel.org>
> Cc: Oliver Upton <oliver.upton@linux.dev>
> Link: https://lore.kernel.org/all/20230918104028.GA17744@willie-the-truck/
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
> kvm.c | 35 +++++++++++++++++++++++++++++++----
> 1 file changed, 31 insertions(+), 4 deletions(-)
>
> diff --git a/kvm.c b/kvm.c
> index 07089cf1..cc25ecdb 100644
> --- a/kvm.c
> +++ b/kvm.c
> @@ -59,6 +59,8 @@ const char *kvm_exit_reasons[] = {
>
> static int pause_event;
> static DEFINE_MUTEX(pause_lock);
> +static struct kvm_cpu *pause_req_cpu;
> +
> extern struct kvm_ext kvm_req_ext[];
>
> static char kvm_dir[PATH_MAX];
> @@ -573,9 +575,25 @@ void kvm__reboot(struct kvm *kvm)
>
> void kvm__continue(struct kvm *kvm)
> {
> + /*
> + * We must ensure that the resume request comes from the same context
> + * as the one requested the pause, especially if it was issued from a
> + * vCPU thread.
> + */
> + if (current_kvm_cpu) {
> + if (pause_req_cpu != current_kvm_cpu ||
> + !current_kvm_cpu->paused)
> + die("Trying to resume VM from invalid context");
> + current_kvm_cpu->paused = 0;
> + }
> mutex_unlock(&pause_lock);
> }
>
> +/*
> + * Mark all active CPUs as paused, until kvm__continue() is issued.
> + * NOTE: If this is called from a cpu thread, kvm__continue() must
> + * be called from the same thread.
> + */
> void kvm__pause(struct kvm *kvm)
> {
> int i, paused_vcpus = 0;
> @@ -590,10 +608,17 @@ void kvm__pause(struct kvm *kvm)
> if (pause_event < 0)
> die("Failed creating pause notification event");
> for (i = 0; i < kvm->nrcpus; i++) {
> - if (kvm->cpus[i]->is_running && kvm->cpus[i]->paused == 0)
> - pthread_kill(kvm->cpus[i]->thread, SIGKVMPAUSE);
> - else
> - paused_vcpus++;
> + if (kvm->cpus[i]->is_running && kvm->cpus[i]->paused == 0) {
> + if (current_kvm_cpu != kvm->cpus[i]) {
> + pthread_kill(kvm->cpus[i]->thread, SIGKVMPAUSE);
> + continue;
> + } else if (current_kvm_cpu) {
> + current_kvm_cpu->paused = 1;
> + pause_req_cpu = current_kvm_cpu;
This is also set as we leave the function. Why do we need to set it
twice?
> + /* fall through to update our count */
> + }
> + }
> + paused_vcpus++;
> }
>
> while (paused_vcpus < kvm->nrcpus) {
> @@ -604,6 +629,8 @@ void kvm__pause(struct kvm *kvm)
> paused_vcpus += cur_read;
> }
> close(pause_event);
> + /* Remember the context requesting pause */
> + pause_req_cpu = current_kvm_cpu;
> }
>
> void kvm__notify_paused(void)
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2026-01-08 14:19 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-30 10:31 [PATCH kvmtool 00/15] arm64: Handle PSCI calls in userspace Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 01/15] Allow pausing the VM from vcpu thread Suzuki K Poulose
2026-01-08 14:19 ` Marc Zyngier [this message]
2025-09-30 10:31 ` [PATCH kvmtool v4 02/15] update_headers: arm64: Track psci.h for PSCI definitions Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 03/15] update headers: Linux v6.17-rc7 Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 04/15] Import arm-smccc.h from Linux 6.16-rc1 Suzuki K Poulose
2025-09-30 10:37 ` Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 04/15] Import arm-smccc.h from Linux 6.17-rc7 Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 05/15] arm64: Stash kvm_vcpu_init for later use Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 06/15] arm64: Use KVM_SET_MP_STATE ioctl to power off non-boot vCPUs Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 07/15] arm64: Expose ARM64_CORE_REG() for general use Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 08/15] arm64: Add support for finding vCPU for given MPIDR Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 09/15] arm64: Add skeleton implementation for PSCI Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 10/15] arm64: psci: Implement CPU_SUSPEND Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 11/15] arm64: psci: Implement CPU_ON Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 12/15] arm64: psci: Implement AFFINITY_INFO Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 13/15] arm64: psci: Implement MIGRATE_INFO_TYPE Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 14/15] arm64: psci: Implement SYSTEM_{OFF,RESET} Suzuki K Poulose
2025-09-30 10:31 ` [PATCH kvmtool v4 15/15] arm64: smccc: Start sending PSCI to userspace Suzuki K Poulose
2026-01-08 14:14 ` Marc Zyngier
2026-01-08 14:23 ` Suzuki K Poulose
2026-01-09 2:36 ` Aneesh Kumar K.V
2026-01-09 10:21 ` Suzuki K Poulose
2026-01-09 10:43 ` Aneesh Kumar K.V
2026-01-09 17:14 ` Suzuki K Poulose
2026-01-08 14:19 ` [PATCH kvmtool 00/15] arm64: Handle PSCI calls in userspace Marc Zyngier
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=861pk0mbkv.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=alexandru.elisei@arm.com \
--cc=aneesh.kumar@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=oliver.upton@linux.dev \
--cc=steven.price@arm.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=will@kernel.org \
/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.