Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp872713pxj; Tue, 18 May 2021 16:29:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyn8gMlAyXGpPZHoLEpmjDqXKBbbhSnLBcfYlZRMXPM7urP4fB5b6yYPw2ywRPywlwicnAU X-Received: by 2002:a17:906:5fd1:: with SMTP id k17mr8388208ejv.78.1621380557741; Tue, 18 May 2021 16:29:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621380557; cv=none; d=google.com; s=arc-20160816; b=TSpJRtxwE3BH3poUwWFaMeAhZoZ00RVvbxyqpnf/DYoXPPyoIXUtvKZfcJXxXzsKH4 A5lqdn7OsKIg2frDe+UzlxCutrPzfCOScCBBfYGTGK7qzTnG3lLHb3R9XEZN7n1i9I88 ymvBGOmXw2A8Hhe5w0ZVOQyGp3bTQNrNH29UcGx1facbRlKFsjnx9jumPaJxqCJrj5n8 eX93ZJYOeF7HgapwdSMJMSDtWNV+GXGQekzeYIgikjdoYoSVzbhDKd2mwDYSlq3f4mNo bsPNPlamOXri9M49bvk3ZU+Zcndvd242A1fJMKWPL9NBTlQnWl0LP/U9m4z3p+ir+dmw 4woA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=EfKCKWBlWMB6WX2+gtYhC171DsA3+5IpegRuV4Mh9HU=; b=xy/x3pzs+Qr9y7HSu54f9fFDvVvREqr9viHTPlMUHEP2GgKysDAUIcOaxrvSS3PRSa H+ZDUgQGxbYVhW+CjnhNOnZHl5Vy3B+9otB9U6I2ylQdlFeipgZy0iA8TwBuwxhMgPSw PZ91m7zABGqdJ+d03Vo1PjW5tC2o6m4PFqrWmUFWZBMvrRmAjH8KPpggGIfCBLkgVXAD yTgKMoa94keWhGCYSMU6qGmWz6gKeZLQuePOwGdL4wjuXAn7bS6lmTKjlTcZo3KyVRho Do2OaP5hhEzW+NCPYcsquSWbHkh4hFmqmO3LKdZ9nqQLjtX3u5beRE+kQxvSjkv39CuB PjmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Dc8Fi3Cx; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w9si20185838edx.381.2021.05.18.16.28.33; Tue, 18 May 2021 16:29:17 -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=@chromium.org header.s=google header.b=Dc8Fi3Cx; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236964AbhEQSOe (ORCPT + 99 others); Mon, 17 May 2021 14:14:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243988AbhEQSOe (ORCPT ); Mon, 17 May 2021 14:14:34 -0400 Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FECAC061756 for ; Mon, 17 May 2021 11:13:17 -0700 (PDT) Received: by mail-ot1-x32a.google.com with SMTP id i23-20020a9d68d70000b02902dc19ed4c15so6399519oto.0 for ; Mon, 17 May 2021 11:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EfKCKWBlWMB6WX2+gtYhC171DsA3+5IpegRuV4Mh9HU=; b=Dc8Fi3CxSz/2Frmp7p/Ljzs3veaW9TpCZJGgQ4e6DcOz+Fqyg3dNGp8K0JmlghN9fC rV0WWGPTdqxPArPg6Qro/+2M+bLWTmATE+NM9MXiBcfNtkpzMD0jtD+r4IPiWZiHZtJx QJ0EFp6RkY5XHBuNFWud3yVeiF/7o9S/SCytM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EfKCKWBlWMB6WX2+gtYhC171DsA3+5IpegRuV4Mh9HU=; b=cOp9vZq+FkuNH0gZwtrqQvqZGMhdSc5/rLV0fdJz0MvMqBtv89zjV/oAwO9jpRN5aY tS1z0OKHr3zLV30Yxr5DOa/GWFQ+kThhHCl+b30YGg97pQPA7WRCi5mviGhRKBCEopNo A836Twa/1yx019MkBtuDR6fj+KQSeU30n8EeEO8y1UwsqJa/OJBet3Wvthq2O1JwxEXm vC167QRQGGOBHi+MMkp0MVEk/B+BCjM34hfKnXxwL/kUKZ0QvrsiXjs/gJovqLQBbljX 86UjxkTpz4WF6ppQtGlRdV2BSqxRfRGjKX/n0G4fob0u46pmkAKA8SW6r0Acfmxtk7gX jKeg== X-Gm-Message-State: AOAM533Xw6szjgG4j39xWS6LRiz4RKGQsfnYjpvT6Q5neZuNMkgH+ZLY f0RBaSw00Du8zg/fg5D3jdthR+SNaAZYkUvnWePjdMwYsSE= X-Received: by 2002:a9d:2966:: with SMTP id d93mr743560otb.56.1621275196944; Mon, 17 May 2021 11:13:16 -0700 (PDT) MIME-Version: 1.0 References: <1621260028-6467-1-git-send-email-wanpengli@tencent.com> In-Reply-To: <1621260028-6467-1-git-send-email-wanpengli@tencent.com> From: Venkatesh Srinivas Date: Mon, 17 May 2021 11:13:23 -0700 Message-ID: Subject: Re: [PATCH v3 1/5] KVM: exit halt polling on need_resched() for both book3s and generic halt-polling To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Ben Segall , David Matlack , Paul Mackerras , Suraj Jitindar Singh Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 17, 2021 at 7:01 AM Wanpeng Li wrote: > > From: Wanpeng Li > > Inspired by commit 262de4102c7bb8 (kvm: exit halt polling on need_resched() > as well), CFS_BANDWIDTH throttling will use resched_task() when there is just > one task to get the task to block. It was likely allowing VMs to overrun their > quota when halt polling. Due to PPC implements an arch specific halt polling > logic, we should add the need_resched() checking there as well. This > patch adds a helper function that to be shared between book3s and generic > halt-polling loop. > > Cc: Ben Segall > Cc: Venkatesh Srinivas > Cc: Jim Mattson > Cc: David Matlack > Cc: Paul Mackerras > Cc: Suraj Jitindar Singh > Signed-off-by: Wanpeng Li > --- > v2 -> v3: > * add a helper function > v1 -> v2: > * update patch description > > arch/powerpc/kvm/book3s_hv.c | 2 +- > include/linux/kvm_host.h | 2 ++ > virt/kvm/kvm_main.c | 9 +++++++-- > 3 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c > index 28a80d240b76..360165df345b 100644 > --- a/arch/powerpc/kvm/book3s_hv.c > +++ b/arch/powerpc/kvm/book3s_hv.c > @@ -3936,7 +3936,7 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) > break; > } > cur = ktime_get(); > - } while (single_task_running() && ktime_before(cur, stop)); > + } while (kvm_vcpu_can_block(cur, stop)); > > spin_lock(&vc->lock); > vc->vcore_state = VCORE_INACTIVE; > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 2f34487e21f2..bf4fd60c4699 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -1583,4 +1583,6 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu) > /* Max number of entries allowed for each kvm dirty ring */ > #define KVM_DIRTY_RING_MAX_ENTRIES 65536 > > +bool kvm_vcpu_can_block(ktime_t cur, ktime_t stop); > + > #endif > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 6b4feb92dc79..c81080667fd1 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -2945,6 +2945,12 @@ update_halt_poll_stats(struct kvm_vcpu *vcpu, u64 poll_ns, bool waited) > vcpu->stat.halt_poll_success_ns += poll_ns; > } > > + > +bool kvm_vcpu_can_block(ktime_t cur, ktime_t stop) > +{ > + return single_task_running() && !need_resched() && ktime_before(cur, stop); > +} > + > /* > * The vCPU has executed a HLT instruction with in-kernel mode enabled. > */ > @@ -2973,8 +2979,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) > goto out; > } > poll_end = cur = ktime_get(); > - } while (single_task_running() && !need_resched() && > - ktime_before(cur, stop)); > + } while (kvm_vcpu_can_block(cur, stop)); > } > > prepare_to_rcuwait(&vcpu->wait); > -- > 2.25.1 > Reviewed-by: Venkatesh Srinivas