Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1670379pxj; Wed, 19 May 2021 11:05:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypEWxiHqB5TVFCyXOaurqFU72Xxasn0oCVlRT9tbs7z6ywFRgzfqVP34Vtz6ScgoW0XLr9 X-Received: by 2002:a05:6402:1109:: with SMTP id u9mr341303edv.174.1621447522198; Wed, 19 May 2021 11:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621447522; cv=none; d=google.com; s=arc-20160816; b=td0fx7o9K5H8bx0tdJfmtCpCTHLwRvYwl7qA7Uk1k+weaweAsD39SZQrWhrnReMk4g Em8/RAKWrhFe+Bp1RzRUG3kg7cC3BHakffSOPFDcv4ghZRRFpUx1yxURVmsGBo6CMh6F JzCMbMbyEhRDrhRXwxKYs2XKUeZL8DzT7CUgfpMNa/O+9kfPUj+dmMGe0Xlogu5nBHUa eDaETEeAO8o2/HlqPZEk2E4dcg6Zwt71K0Vim5hqatrPFkyQEbBmKV8G0W3kyKUbfxpn JiOxW8TkYrnPSeFYkup0xN1Qa3aPQrzCgHpcQBm9A3v4BjPLfXZX8LgkJ272Yecb4eil SwMg== 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=k79vW2u79tJXgve+aRH1VfwPBT0AnMHP2JIefQMqRAs=; b=W91FPlqZIRN5jaUXTOrYedPYcqbn1zwT8t+mkk+/Ek0HCEAjr89Ck7t8G4/OQD0QWW fPAAiMSgFrzOgsnEjtY4ndXAuTteriSmXYncnhpJPtlmbrW+AxQxuagONbroIFb9twdq Gh6oofqxVJbl8YtddmQ2EPqbq8o0ud+nGIPNSwbGv+bsoUYiagbjEQUcxtKsI8DHr+9E 23a7O17Co8cDXeTD86RXu1t97tU8/+ebde6hBB4dIxYUmA6+ZuHHiM+SvsTQH9kRh3gl TSJQBzGusMzAyoHpiLV8gYsAn9cwHenYfqvLAjb8QMAmjdIzXiZ+8PmHIJoX1h/rmuZ7 7vHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kR+59qVE; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ch13si302659ejb.305.2021.05.19.11.04.53; Wed, 19 May 2021 11:05:22 -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=@gmail.com header.s=20161025 header.b=kR+59qVE; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244020AbhERMEr (ORCPT + 99 others); Tue, 18 May 2021 08:04:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243336AbhERMEq (ORCPT ); Tue, 18 May 2021 08:04:46 -0400 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2547C061573; Tue, 18 May 2021 05:03:27 -0700 (PDT) Received: by mail-oi1-x235.google.com with SMTP id x15so9491737oic.13; Tue, 18 May 2021 05:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=k79vW2u79tJXgve+aRH1VfwPBT0AnMHP2JIefQMqRAs=; b=kR+59qVE9ePDScN4+7vEcEnxZwK12VuOtltQkkZMB7XoH5arDmZc9pE0b85wW2yOBp TDCtb3xnJShxG6zUqEPlylwDq3PC89ou1/2MOxkW15s9v6I5wYcpcHcqcvSoNKXePMuB u9l2eyYJFlK4fYpiZ9eBSpYUnfzGxBvkeG/XcPwfDgmXmaW4N4LGn2QgtEb/B0dBCSA1 L7PeAVR57iosmuMrjRVWbi92n0HEwjwvRDGftKkHOtS+Lw6jwzNtn1Gsrw3IDg4bW5wX FfVpwQPEE5kDctmR2Hne5KfKuvN17ICHtdlOLmGcNQdQ50GxEWyUPDfxdx/YwvWoMQIs udOQ== 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=k79vW2u79tJXgve+aRH1VfwPBT0AnMHP2JIefQMqRAs=; b=G52ha7JhPxpR/QWYOZIjyCfw5vvzymiwaTQtaFJEY+tPm7lYFxEsvb7q+4/5b4i19t Z+448sPgYatBDhZxc5xZpsiHIoZrIvvFiOuTfHcT3v3AZSvR8p0mWHicwDbhqgu4Vn3R syhh4yQJFjpR3AvNcTtw6RMJ2y3Hu8yt2PiqrbaKf7Xp7vWnObmJ9pxKaarCkbTG0vcc pOF+GmcXn+upWklYxI7mDa4QMW0A8VjH/z0sPk2BnGre6rVxOE3kCialYVG4opX9d260 /uVORLiC0R3h8/9bEvUcrepVg/PhjyyYGbIOklfkdxzp6NeP1F+ALq+/Fjyuan/ARz6Y 4V2A== X-Gm-Message-State: AOAM533qhngKZAhPuEG8mRS3sMv5DbmpvE2j9ahkXrbmUa1GNEth/nr8 ee+635TFKsf95Grvy+XHDMoTY6OSa5znSa0VdBg= X-Received: by 2002:aca:4343:: with SMTP id q64mr3710079oia.33.1621339407416; Tue, 18 May 2021 05:03:27 -0700 (PDT) MIME-Version: 1.0 References: <1621260028-6467-1-git-send-email-wanpengli@tencent.com> In-Reply-To: From: Wanpeng Li Date: Tue, 18 May 2021 20:03:16 +0800 Message-ID: Subject: Re: [PATCH v3 1/5] KVM: exit halt polling on need_resched() for both book3s and generic halt-polling To: David Matlack Cc: LKML , 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 Tue, 18 May 2021 at 00:35, David Matlack wrote: > > 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. Do it in v4. :) Wanpeng