From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6709C433F5 for ; Tue, 28 Sep 2021 22:05:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 82B6C6137A for ; Tue, 28 Sep 2021 22:05:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 82B6C6137A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xP6unt39juMnP3pM1mTS9By9KrHwhXfE0ArOKMhk5Lo=; b=E6CjjPy69fGl1c sx+w6vg4dRF002/F9YY2rmwcPI7S4MEPkg0Mu0rHz5viF+OXfKQC4yeFfdfvwXBRWqkYrvcHdT42B LuWKilx1bIYBfxDfZZhWuLiUAsTGd93b9CUTJxs28/8Ff4CEIhZDmuvvTUMSn9zvBZiEVNoGQkeFT ycB7oFBIRcZmoDOsv4C5ta9E17Fh4U+3sFl0/URHxtowYXt8nM49vV1vxGjQR1aItnvNMWoJAhR1z lLxKxq59JgSME1g1xwbQWQSmLwELhPj9nFEBeWBdHJzNyRZmUlx2sjsVIEjz0dilgNSDiBxfGftjn 21MbVghTqoFznSH5A/XQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVLC6-008wfR-FX; Tue, 28 Sep 2021 22:03:22 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVLC2-008we8-6u for linux-arm-kernel@lists.infradead.org; Tue, 28 Sep 2021 22:03:19 +0000 Received: by mail-pg1-x529.google.com with SMTP id h3so516073pgb.7 for ; Tue, 28 Sep 2021 15:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=HhWJHJzwSlwok1AmtMjKCRhZCZC7gZ0nzg2WuvY1qEE=; b=tigZj4v4CeD0329C4UL89vBMNZKnQ83w87+ZjG/BkopVGCTWeqLcdLtmMMMyBh4mY7 7Dg9uin+BfDKQe3/AO/kBYz/oYXaVu1zZluev925ki7GPxG9RsFR+LVM6CwXOErqWOQ1 pcncNiTkf8gIAQ18xmLQoQFFSVJjeL/kv9WgotyouEYXoN9oN4CFt1v1v3hF+tD2MuSP 4hRr4rqTnaTfyQu2hB8T0n1Sl6+dT/y/KrjaEze5I0PN5XK1QLwnll8S68T9w3WOhivA 8src448DI7RUYdTJ7WPFB9p1z6qh3ARAEdVyO8+kHbRNjGL0an+DZUP9EMoHBQVa5OH2 UFig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=HhWJHJzwSlwok1AmtMjKCRhZCZC7gZ0nzg2WuvY1qEE=; b=qM5NHsHs9azc9f1MAZfHaxz/F8y+bB5gb3cAg8AwJ5hCmBIn2a90emyM9VVXPGTW7U nCSkhAt8FawDNVnjJNBXK39XBru6DXWbWTHFZRFhwDC5AkA4A5ikmOOVwPoIP38MBprp 1CNkyuSuoi2drjq2BoaxSVrE2+qCLriEDZHg16KAF51YUUpeegi8E/IHSmrTrx6J9vTG bq/UJonGX8yge/NlPJ6fgc5AcYY2lM/5lbrEWPTGwliXKXEJQhPUNHHI/iX6sNwEHKHA 0Lvl9R/6+TVD4cKVZk7Bn4ZwyS8Bmo/JVcIlB4RrgrrdRJv8t2MWsh/WGaLVA0xB45g6 eUWw== X-Gm-Message-State: AOAM530UdrHq3u7ypJZgE3etmLVUX+XauWi+B7p11oBJTA13DBZKrUqR mUWZ9SNXOGxm2j8IYCGuDw8gxA== X-Google-Smtp-Source: ABdhPJz8FBfuYulYfix3SaPNrNClCNKJqQQmFIru90iSEGa1D9tLSPPzdOByJRFDeYbge7PjxYA/EA== X-Received: by 2002:aa7:980a:0:b0:43e:670:8505 with SMTP id e10-20020aa7980a000000b0043e06708505mr7905502pfl.74.1632866597392; Tue, 28 Sep 2021 15:03:17 -0700 (PDT) Received: from google.com (254.80.82.34.bc.googleusercontent.com. [34.82.80.254]) by smtp.gmail.com with ESMTPSA id t33sm129606pfg.71.2021.09.28.15.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 15:03:16 -0700 (PDT) Date: Tue, 28 Sep 2021 22:03:13 +0000 From: David Matlack To: Sean Christopherson Cc: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Christian Borntraeger , Janosch Frank , Paolo Bonzini , James Morse , Alexandru Elisei , Suzuki K Poulose , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, linux-kernel@vger.kernel.org, Jing Zhang Subject: Re: [PATCH 10/14] KVM: Split out a kvm_vcpu_block() helper from kvm_vcpu_halt() Message-ID: References: <20210925005528.1145584-1-seanjc@google.com> <20210925005528.1145584-11-seanjc@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210925005528.1145584-11-seanjc@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210928_150318_287399_49AB2101 X-CRM114-Status: GOOD ( 27.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Sep 24, 2021 at 05:55:24PM -0700, Sean Christopherson wrote: > Factor out the "block" part of kvm_vcpu_halt() so that x86 can emulate > non-halt wait/sleep/block conditions that should not be subjected to > halt-polling. > > No functional change intended. > > Signed-off-by: Sean Christopherson Reviewed-by: David Matlack > --- > include/linux/kvm_host.h | 1 + > virt/kvm/kvm_main.c | 50 ++++++++++++++++++++++++++++------------ > 2 files changed, 36 insertions(+), 15 deletions(-) > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index d2a8be3fb9ba..655c2b24db2d 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -966,6 +966,7 @@ void kvm_sigset_activate(struct kvm_vcpu *vcpu); > void kvm_sigset_deactivate(struct kvm_vcpu *vcpu); > > void kvm_vcpu_halt(struct kvm_vcpu *vcpu); > +bool kvm_vcpu_block(struct kvm_vcpu *vcpu); > void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu); > void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu); > bool kvm_vcpu_wake_up(struct kvm_vcpu *vcpu); > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 280cf1dca7db..fe34457530c2 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -3199,6 +3199,34 @@ static int kvm_vcpu_check_block(struct kvm_vcpu *vcpu) > return ret; > } > > +/* > + * Block the vCPU until the vCPU is runnable, an event arrives, or a signal is > + * pending. This is mostly used when halting a vCPU, but may also be used > + * directly for other vCPU non-runnable states, e.g. x86's Wait-For-SIPI. > + */ > +bool kvm_vcpu_block(struct kvm_vcpu *vcpu) > +{ > + bool waited = false; > + > + kvm_arch_vcpu_blocking(vcpu); > + > + prepare_to_rcuwait(&vcpu->wait); > + for (;;) { > + set_current_state(TASK_INTERRUPTIBLE); > + > + if (kvm_vcpu_check_block(vcpu) < 0) > + break; > + > + waited = true; > + schedule(); > + } > + finish_rcuwait(&vcpu->wait); > + > + kvm_arch_vcpu_unblocking(vcpu); > + > + return waited; > +} > + > static inline void update_halt_poll_stats(struct kvm_vcpu *vcpu, ktime_t start, > ktime_t end, bool success) > { > @@ -3221,6 +3249,12 @@ static inline void update_halt_poll_stats(struct kvm_vcpu *vcpu, ktime_t start, > } > } > > +/* > + * Emulate a vCPU halt condition, e.g. HLT on x86, WFI on arm, etc... If halt > + * polling is enabled, busy wait for a short time before blocking to avoid the > + * expensive block+unblock sequence if a wake event arrives soon after the vCPU > + * is halted. > + */ > void kvm_vcpu_halt(struct kvm_vcpu *vcpu) > { > bool halt_poll_allowed = !kvm_arch_no_poll(vcpu); > @@ -3245,21 +3279,7 @@ void kvm_vcpu_halt(struct kvm_vcpu *vcpu) > } while (kvm_vcpu_can_poll(cur, stop)); > } > > - kvm_arch_vcpu_blocking(vcpu); > - > - prepare_to_rcuwait(&vcpu->wait); > - for (;;) { > - set_current_state(TASK_INTERRUPTIBLE); > - > - if (kvm_vcpu_check_block(vcpu) < 0) > - break; > - > - waited = true; > - schedule(); > - } > - finish_rcuwait(&vcpu->wait); > - > - kvm_arch_vcpu_unblocking(vcpu); > + waited = kvm_vcpu_block(vcpu); > > cur = ktime_get(); > if (waited) { > -- > 2.33.0.685.g46640cef36-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel