Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp744568pxj; Tue, 18 May 2021 13:09:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQTJgWezIG/ZCB+sLz9bCZE2FPSDpZkt/7QOxJ24lN7dEU7Z93udaTrjQYo0CsE1imR2sX X-Received: by 2002:a17:906:33d6:: with SMTP id w22mr7645994eja.222.1621368557947; Tue, 18 May 2021 13:09:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621368557; cv=none; d=google.com; s=arc-20160816; b=Lp2rNCH8oNTYQhO8T0wfiw2pOVnXVaEHIxpARYahkUBLB+Cj4zSeu7wb0NtDbzIXzv MTmawuDcLCFj8ZKGQv7WHGRK5+mEuaPBgdRgxsHsdaTr5WJm133DDk57Jyxguv2GL3AT t4tqFf0Yh4C0n4dSFFMNW/du3v0P/MnnQ8dSq+BVlUCjK5soUqjbNjHesMj9JXxvUZfG EuQchNxILohaF050Gx+Ul10h2y3JDz3hM14bTUrTZVA3PxxqRZPGQTAnUG2M31iSL6Ue tU0snj6+NLjDMWvkqHLmtqxnhuVDbH98lTNp3sP7gB6FQBjL3B9Gse6xr0IsoQU0rzZv vuGg== 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=8XjCzUGwVIiP3+YZrLjLAcXTaHRHGnoKVgLiqwR9S0M=; b=EgKxd20M8W+hF02/jJ5GUSCiK3hbGlgAuH1gl25rfDxD/A9+kE2NlWUUwddPjRUPnL 9IM2uvgJkEip1YDxaF8dCXHeLpeVpbTeEWO0qc7Ec13kNcP6krqOVilrXnrUaNiHGLJF EL19EBqTzU/eiBbQ/5ZF9dsX1NKjt5ZDtRNRsTEpop+GN4+thVJermdCNp8sBGRr5tyi d+zxylF0n0Z3jT+soQLKAE+pEX19lzJGDguyHgEuzubs6GKXqcpXrBrprr1sBGK5oh/6 Q1swvtVNOdHEXJ/fNWMDYCeJBnNsv/eJ6JhVY8dO1tWEN64oG972shr74CwQ4rtPK1Qa B9qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Q6bRC7J4; 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 a26si7683657ejb.272.2021.05.18.13.08.50; Tue, 18 May 2021 13:09: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=@google.com header.s=20161025 header.b=Q6bRC7J4; 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 S240906AbhEQQvR (ORCPT + 99 others); Mon, 17 May 2021 12:51:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239078AbhEQQvG (ORCPT ); Mon, 17 May 2021 12:51:06 -0400 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35D61C07538A for ; Mon, 17 May 2021 09:35:04 -0700 (PDT) Received: by mail-il1-x132.google.com with SMTP id o9so6620066ilh.6 for ; Mon, 17 May 2021 09:35:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8XjCzUGwVIiP3+YZrLjLAcXTaHRHGnoKVgLiqwR9S0M=; b=Q6bRC7J4OtYLgKndA++vo/4BHK+kvEiFv6aZ8jWWH77vI3wtldPu8UuBa/t1erlYQM T9idF8OhWYtD4zivdzckr+jwdarqAhWdL9CsBic6mokrIQJq4owNlFkKFmTYWAlWgF1S buzzozZu0YuX24RDIBlPoWalnO7Y8mpaLV+LZ4JC7Z7vgp4pk/rjuft2exRvDVyZo05N UnayAVciQIo5al9hYnYbt+HnJkklbO7h56O5J6IZfcUnUGM0hJMghwzRvT0ezkG8wAUU 1Q8Is/HVfDrTV5SZUAMLudhbv00hpSn56L6Tm7auH3RSOIUMUJLNHSv9g6ASVHr+kh0D 88HQ== 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=8XjCzUGwVIiP3+YZrLjLAcXTaHRHGnoKVgLiqwR9S0M=; b=Ac0V2EQ+oUge2QfdE0kTVkABZ7UdDXWwEnd0TOSAGenJxs3UUSKrPUzSz6G67pZFFx ZxfTc1gizRGolAfh5/Zs2ioLrzs93MB/emTvUaRrFN08ygpBBVl44R+byDZne29FK7qZ 4kL+VUROqznPk1wQUF+K+AdF9ZpIQ/jHdXIKQ9n7d08x9NxV0MTe+BB6AAV2Ze/gNewK z//RkKRsKT1EdVe/S9Od9FYewpSesT02muVFx+/LAHBx9slsgqTs1Zr+gCcayyJ9KonI NGlT3AO6IerZTpqidlZbaBD6Ocw9d3nw6hppVE0iaNXzlu5l2LWtM67x7L8ppfagZR/r pE7Q== X-Gm-Message-State: AOAM532VYNC/vip4qlVLeVxiSTEJ7td7wyXvKwpFXV4xTUl1VB0GMVvW GBMlLgtFZpRrpku/c0JixPlR4z7/t516QC2ggChvhA== X-Received: by 2002:a92:cda5:: with SMTP id g5mr457366ild.245.1621269303543; Mon, 17 May 2021 09:35:03 -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: David Matlack Date: Mon, 17 May 2021 09:34:38 -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 list , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Ben Segall , Venkatesh Srinivas , 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 Reviewed-by: David Matlack > --- > 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) nit: kvm_vcpu_can_poll() would be a more accurate name for this function. > +{ > + 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 >