Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2184354pxb; Fri, 24 Sep 2021 23:46:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSs8pnzq1uWMISq5kbNZ8M3EqWmaRudKE+SipcSDDrpV1o+VhvzstdI23/ABK9qpODIay/ X-Received: by 2002:a17:906:1ed7:: with SMTP id m23mr15234639ejj.558.1632552398154; Fri, 24 Sep 2021 23:46:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632552398; cv=none; d=google.com; s=arc-20160816; b=DFcJfp1kCwJrZu7yL9QzzqAk7kf2Dv1jMeT3lENT5pSuhgYJ1kWjjAq698Md53euzl USQuacT+L+iCX0bO16PvCVJDeBGEke8VI3HSmLkBUoEzfBFLF6pVXvi0KXeHT1Vr9QwO F8RANHru5L4UKMJg5VwnoMs979+V/RxT9aBTfgPn2BQre6HiNpg/tVaD0vdYxkZiU6lv raTxtpY5O2sjd8y0o9Yc/pE3Qrb551Nl9jWNJBDQPy0FgHggizsHEIxbFIQPfO4XG/F7 u9PE4I9SncXpUja7A24ZFUhShw/1ge4AMBTPITCr5F26okeiZ+JhEjZ11e8/MVx0uq+r IiQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=wCDTOmCATHVhirkJj1e9UGRNdETjcfm809lLJpA1KZ0=; b=ByLYi+I6LyoRQJCs5oXoZJDw+7l8DEzkYl2OPTH2Ojy5OnYeIQbtB3saR91F3NHGVN 8rUEeU2E+yHLzklaODq/nAj97dewupBMo6Rs4D0UFK+8qjKBWC6bttS0rpmwlqwp//Mm HE1Hd3OurMTzfKLx/qaa4l4xTNnuF5qRiZqto/01jF0TxkwCoiWU5NEyCa3GF1DmQtMy Di5W1T864npySgfi9IV4EolwGJNkEk/tPSStIS96Hr6G9NmbbAs3TgKvnF9ggx1/rGNY PN4hgwbuo8S/Byb2IIRWSj246TPLCFALymWnbg07xQANCjKtjL+2j07ZcRWUSIxZuh1c GLMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=NqlSHtDJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f5si11166477ejj.587.2021.09.24.23.46.14; Fri, 24 Sep 2021 23:46:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=NqlSHtDJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346564AbhIYA5c (ORCPT + 99 others); Fri, 24 Sep 2021 20:57:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346490AbhIYA5V (ORCPT ); Fri, 24 Sep 2021 20:57:21 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3D2BC061767 for ; Fri, 24 Sep 2021 17:55:46 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id w10-20020a0cb54a000000b0037a9848b92fso44747096qvd.0 for ; Fri, 24 Sep 2021 17:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=wCDTOmCATHVhirkJj1e9UGRNdETjcfm809lLJpA1KZ0=; b=NqlSHtDJsZY9ynz1iazGvEiDMeqk04glWuzCtUdaZ74/+oO9rjnWS76Uh5TCi8grB+ KwboA6njeSjTV+7uoE02X2FwYEkNPrLAm4qkXIZRVzJuxFafx32Mk5Xow/7WaARh1YAZ aC51w8eW6QKpvfDfIdD1udB75TJ4xUgQM915d2jcceUTh/hDb7mbGAiLnwAyqt0Y+WNF QpBy7FR47VOdDUwc186Fr9j28eODhANC/CUAjZvNZrR7fGsZs3zQzKM9xL4iXSTKlTtT +D4Y310QHpvHJHW02qI33BojoXY3YB8cjH1EF1eQmiciixtCRe97iPAZe1mITqWJtBmk YH1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=wCDTOmCATHVhirkJj1e9UGRNdETjcfm809lLJpA1KZ0=; b=L121/BZauuyW+Mlwjn7qYrK6IwmKVqiAagh5rwFNBEUTN9/k70TMHq0+XS6L5+fHza Sz6pQpsOq/LQ3j9vd1aXuGTYO99gWboa0L2i9vFmLwZiSs92uNmSGG1ll6Twmd6EysWS NMkIcpFD9NqEtb932HMaQZJVcVVLeDzOWqVPwAwQKXUk4Q41JKTsibXu4pxLqCyDTr1j vUp2Cv+Mj6MVKYXgP/bGqmoVXfzUJdWj5DmMCxvgvXZwbpL3TA2K4TfXBe5EXPfCTWB3 2wzABKPbYz+YEZCbki4smcvNu7wUsGPthWPKL83LxEaVSS5aUIKJmis0oDb9igSBzCJH BoPA== X-Gm-Message-State: AOAM5310kZ9W6GjvLFATEtSZXCzoK0cBcXq+bFy4bqvHa1BW6tk9JUUy TAOGqBJoByYynHahPw5Bypdq4UvHkDU= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:4c72:89be:dba3:2bcb]) (user=seanjc job=sendgmr) by 2002:a05:6214:1046:: with SMTP id l6mr4932886qvr.6.1632531346015; Fri, 24 Sep 2021 17:55:46 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 24 Sep 2021 17:55:21 -0700 In-Reply-To: <20210925005528.1145584-1-seanjc@google.com> Message-Id: <20210925005528.1145584-8-seanjc@google.com> Mime-Version: 1.0 References: <20210925005528.1145584-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [PATCH 07/14] KVM: Don't block+unblock when halt-polling is successful From: Sean Christopherson To: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Christian Borntraeger , Janosch Frank , Paolo Bonzini Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Sean Christopherson , 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, David Matlack , Jing Zhang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Invoke the arch hooks for block+unblock if and only if KVM actually attempts to block the vCPU. The only non-nop implementation is on arm64, and if halt-polling is successful, there is no need for arm64 to put/load the vGIC as KVM hasn't relinquished control of the vCPU in any way. The primary motivation is to allow future cleanup to split out "block" from "halt", but this is also likely a small performance boost on arm64 when halt-polling is successful. Adjust the post-block path to update "cur" after unblocking, i.e. include vGIC load time in halt_wait_ns and halt_wait_hist, so that the behavior is consistent. Moving just the pre-block arch hook would result in only the vGIC put latency being included in the halt_wait stats. There is no obvious evidence that one way or the other is correct, so just ensure KVM is consistent. Cc: Marc Zyngier Cc: James Morse Cc: Alexandru Elisei Cc: Suzuki K Poulose Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 2015a1f532ce..f96cda8312f3 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3232,8 +3232,6 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) bool waited = false; u64 block_ns; - kvm_arch_vcpu_blocking(vcpu); - start = cur = poll_end = ktime_get(); if (do_halt_poll) { ktime_t stop = ktime_add_ns(ktime_get(), vcpu->halt_poll_ns); @@ -3250,6 +3248,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) } while (kvm_vcpu_can_poll(cur, stop)); } + kvm_arch_vcpu_blocking(vcpu); prepare_to_rcuwait(&vcpu->wait); for (;;) { @@ -3262,6 +3261,9 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) schedule(); } finish_rcuwait(&vcpu->wait); + + kvm_arch_vcpu_unblocking(vcpu); + cur = ktime_get(); if (waited) { vcpu->stat.generic.halt_wait_ns += @@ -3269,8 +3271,8 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) KVM_STATS_LOG_HIST_UPDATE(vcpu->stat.generic.halt_wait_hist, ktime_to_ns(cur) - ktime_to_ns(poll_end)); } + out: - kvm_arch_vcpu_unblocking(vcpu); block_ns = ktime_to_ns(cur) - ktime_to_ns(start); /* -- 2.33.0.685.g46640cef36-goog