From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCC6F44D6A3; Thu, 8 Jan 2026 14:19:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767881955; cv=none; b=Zc/ChbdKeqf9fKV/n8q2snnqYx6umQWwsyo1B/M+beZQagGdwKL49A3r/bWXvL53CRVeFjGdztEsr2qMa62VdXuSLyg8fCFc7rZysCneTrBawcUXIbEEIgraGjIEKOLdR2PlEBg+t288LoHkj7axA6qZdtDQ8HUnj4zIKY2cAJU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767881955; c=relaxed/simple; bh=Kmij4qyDrN8Z0vImiN8j8I9vDenr/lmN1w+0d4gtGj4=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=iZJhewwN4GMWiuuw+Or0Fs2qiBecCHw7150i1A+3QEwotTbXE+dG+z8UxmZFrQe+gHQ2eHuvLnwl0EBMLaLfQR9XlZ9e7ygW6vk+Aiiz08l9Bde4k8PvdD89rOX+0/vlgFnLCqJH1pjDXVMGSp9V4SsxvlUe/jP9e9jkn04htBc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lpcp3w7g; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lpcp3w7g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 369ECC116C6; Thu, 8 Jan 2026 14:19:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767881955; bh=Kmij4qyDrN8Z0vImiN8j8I9vDenr/lmN1w+0d4gtGj4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lpcp3w7g4XxQeU/e4Cup0Ls3LdTAVUc+FH8WBXDZJURrCvMO1FVHzQCNO+mnfqsvT P6Ilbu/knDjXmRjn5IrVFb9ZTyfxturMu96i/CgkGjB81hd7C703TvIzUT3uHZ/nkT WefCRw9MQxWjRjV0Ta+utaWiRlozOOCx566yQTL3I9yz4RBXL2zlH0cuoB70hb7+wK Sa77JV4SLIaPJ8fpxoV0Sq2LBw2sQDwSIxBIpiWCxZpigX5T4hIYlcJXFuNqnk/jz5 iUsvxN+uW0N0rUGtrGd41eDk1GIAtRzyjgnIb9KSeQ1l5+VWLo8tOTqOntdai0nIQf gfKIvLlT1lE7w== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vdqr3-00000000R22-0vOA; Thu, 08 Jan 2026 14:19:13 +0000 Date: Thu, 08 Jan 2026 14:19:12 +0000 Message-ID: <861pk0mbkv.wl-maz@kernel.org> From: Marc Zyngier To: Suzuki K Poulose 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 In-Reply-To: <20250930103130.197534-2-suzuki.poulose@arm.com> References: <20250930103130.197534-1-suzuki.poulose@arm.com> <20250930103130.197534-2-suzuki.poulose@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: suzuki.poulose@arm.com, 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 X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Tue, 30 Sep 2025 11:31:15 +0100, Suzuki K Poulose 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 > Cc: Oliver Upton > Link: https://lore.kernel.org/all/20230918104028.GA17744@willie-the-truck/ > Signed-off-by: Suzuki K Poulose > --- > 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.