From patchwork Tue Jun 20 16:33:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 13286200 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5607EB64D7 for ; Tue, 20 Jun 2023 16:35:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231453AbjFTQf3 (ORCPT ); Tue, 20 Jun 2023 12:35:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231657AbjFTQei (ORCPT ); Tue, 20 Jun 2023 12:34:38 -0400 Received: from out-58.mta0.migadu.com (out-58.mta0.migadu.com [IPv6:2001:41d0:1004:224b::3a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CB1510A for ; Tue, 20 Jun 2023 09:34:38 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1687278876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3gzht6CT1X9IZD7roVpf6k8MHtu0w2z5eWGk4eof8mU=; b=jzkqbC7lHAGbYcCiWYHbOnQJM6LZ7fRWroB49gh9fFxVZ/vL3q6rmNoxc6W94uR0nkK4tk QNFLQD/4a0j6riMSpz6CUWljTdCNX9kRQAtDDZaKfRmti5TqHcQej4kbtWIKYuTfakaiS0 5Az+pR6AFfRi07v/tZfF3XUoCMXO2Uk= From: Oliver Upton To: kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Suzuki K Poulose , Zenghui Yu , Will Deacon , Julien Thierry , Salil Mehta , Oliver Upton Subject: [PATCH v2 11/20] Add helpers to pause the VM from vCPU thread Date: Tue, 20 Jun 2023 11:33:44 -0500 Message-ID: <20230620163353.2688567-12-oliver.upton@linux.dev> In-Reply-To: <20230620163353.2688567-1-oliver.upton@linux.dev> References: <20230620163353.2688567-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Pausing the VM from a vCPU thread is perilous with the current helpers, as it waits indefinitely for a signal that never comes when invoked from a vCPU thread. Instead, add a helper for pausing the VM from a vCPU, working around the issue by explicitly marking the caller as paused before proceeding. Signed-off-by: Oliver Upton --- include/kvm/kvm-cpu.h | 3 +++ kvm-cpu.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/kvm/kvm-cpu.h b/include/kvm/kvm-cpu.h index 0f16f8d..9a4901b 100644 --- a/include/kvm/kvm-cpu.h +++ b/include/kvm/kvm-cpu.h @@ -29,4 +29,7 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu); void kvm_cpu__arch_nmi(struct kvm_cpu *cpu); void kvm_cpu__run_on_all_cpus(struct kvm *kvm, struct kvm_cpu_task *task); +void kvm_cpu__pause_vm(struct kvm_cpu *vcpu); +void kvm_cpu__continue_vm(struct kvm_cpu *vcpu); + #endif /* KVM__KVM_CPU_H */ diff --git a/kvm-cpu.c b/kvm-cpu.c index 7dec088..0fc1efe 100644 --- a/kvm-cpu.c +++ b/kvm-cpu.c @@ -141,6 +141,22 @@ void kvm_cpu__run_on_all_cpus(struct kvm *kvm, struct kvm_cpu_task *task) mutex_unlock(&task_lock); } +void kvm_cpu__pause_vm(struct kvm_cpu *vcpu) +{ + /* + * Mark the calling vCPU as paused to avoid waiting indefinitely for a + * signal exit. + */ + vcpu->paused = true; + kvm__pause(vcpu->kvm); +} + +void kvm_cpu__continue_vm(struct kvm_cpu *vcpu) +{ + vcpu->paused = false; + kvm__continue(vcpu->kvm); +} + int kvm_cpu__start(struct kvm_cpu *cpu) { sigset_t sigset;