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 2C423C43219 for ; Mon, 27 Sep 2021 15:00:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1121461178 for ; Mon, 27 Sep 2021 15:00:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234988AbhI0PBf (ORCPT ); Mon, 27 Sep 2021 11:01:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234965AbhI0PBc (ORCPT ); Mon, 27 Sep 2021 11:01:32 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44205C06176C for ; Mon, 27 Sep 2021 07:59:53 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id r2so18052276pgl.10 for ; Mon, 27 Sep 2021 07:59:53 -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=8d5KqXA5Mi92PwzZc0N/pdrf/YfLC80LCsk313TOlF8=; b=m7Sxwd73+QIO2WuPaGefD2VV92Ixlana/rvgLp3fywdfnLLEysnYWnlbrJZMSHvky2 P+dNFDKl+i/DMSPcDLNPjzckqkQLgh9pdU/c3JQwnIagXzSzhgOa+ncEZvwMUJLQWG1m fybm6n4GY1o2I/TIIMUtFfjJTQU9KFbL0J/XoEro7oVzMh1zw+XmI5tRZQQeuZDe42Dg Tmmp6oePrkChYyER1Tnna/qEz55zzNMH1ZMLBsrMQL84AaEtkyNXBlm2Xx+ZucKX/mXL yMhzhoMAfnJyECqCajIjTuZBzhOpC4zX9voYjWadeZj+T2l75O1okb7Y4J7XHlu7WdkY kHUg== 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=8d5KqXA5Mi92PwzZc0N/pdrf/YfLC80LCsk313TOlF8=; b=wu+5C/b8ly+KMLJ9Mow4fDW//JjYjIK5MiSb+rPr2Eruq/U8NJO7VkaGXC02zSSWMA rzOkRtR8ppOtLErC7NIeHgcpIbligPEKb+Sat5SVZvtxxVUZXM+PEvUSJvhc9NVkcWu9 ZX/qNB+EKxPoxv+9A+C5Y+mX6YckU7jZGpCQE/5fMn+nyBtknV6pzf0pik1Whrc84wjs 17+RNPXUlO0jmRk9PeKl9T2EbUNSnrINKsftYIxSK2qhOlqaMswjuxf8lGlJcP7e2VIZ zlPuZkkhdg8RTClI3Bm4SAHHjfSHcT2EgnW3uKBXQzCLDGbS1joM9R/ZIttgwmeHO69s pkOw== X-Gm-Message-State: AOAM531xA/vaq2WJSOf07/oQ+AvGBPqu64YLdQY0ERtK4Yy9qN9kBQOF D0+Zj8eE3Az2kkx0OVbVvK1nuQ== X-Google-Smtp-Source: ABdhPJyg70ia4mflauFBTnYYkPuZeGu0PUo7u3KrQoV6hyYnlf5Ujo4gsfK+PdoDvaYqAOyRoeDCGg== X-Received: by 2002:a63:e057:: with SMTP id n23mr107748pgj.183.1632754792472; Mon, 27 Sep 2021 07:59:52 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id n14sm19177569pgd.48.2021.09.27.07.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 07:59:51 -0700 (PDT) Date: Mon, 27 Sep 2021 14:59:47 +0000 From: Sean Christopherson To: Christian Borntraeger Cc: Paolo Bonzini , David Matlack , Jon Cargille , Jim Mattson , James Morse , Alexandru Elisei , Suzuki K Poulose , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , 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 , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Janosch Frank Subject: Re: disabling halt polling broken? (was Re: [PATCH 00/14] KVM: Halt-polling fixes, cleanups and a new stat) Message-ID: References: <20210925005528.1145584-1-seanjc@google.com> <03f2f5ab-e809-2ba5-bd98-3393c3b843d2@de.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <03f2f5ab-e809-2ba5-bd98-3393c3b843d2@de.ibm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 27, 2021, Christian Borntraeger wrote: > While looking into this series, > > I realized that Davids patch > > commit acd05785e48c01edb2c4f4d014d28478b5f19fb5 > Author: David Matlack > AuthorDate: Fri Apr 17 15:14:46 2020 -0700 > Commit: Paolo Bonzini > CommitDate: Fri Apr 24 12:53:17 2020 -0400 > > kvm: add capability for halt polling > > broke the possibility for an admin to disable halt polling for already running KVM guests. > In past times doing > echo 0 > /sys/module/kvm/parameters/halt_poll_ns > > stopped polling system wide. > Now all KVM guests will use the halt_poll_ns value that was active during > startup - even those that do not use KVM_CAP_HALT_POLL. > > I guess this was not intended? Ouch. I would go so far as to say that halt_poll_ns should be a hard limit on the capability. What about having the per-VM variable track only the capability, and then use the module param to cap the max when doing adjustments? E.g. add a variant of this early in the series? diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 80f78daa6b8d..f50e4e31a0cf 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1078,8 +1078,6 @@ static struct kvm *kvm_create_vm(unsigned long type) goto out_err_no_arch_destroy_vm; } - kvm->max_halt_poll_ns = halt_poll_ns; - r = kvm_arch_init_vm(kvm, type); if (r) goto out_err_no_arch_destroy_vm; @@ -3136,7 +3134,8 @@ void kvm_sigset_deactivate(struct kvm_vcpu *vcpu) sigemptyset(¤t->real_blocked); } -static void grow_halt_poll_ns(struct kvm_vcpu *vcpu) +static void grow_halt_poll_ns(struct kvm_vcpu *vcpu, + unsigned int max_halt_poll_ns) { unsigned int old, val, grow, grow_start; @@ -3150,8 +3149,8 @@ static void grow_halt_poll_ns(struct kvm_vcpu *vcpu) if (val < grow_start) val = grow_start; - if (val > vcpu->kvm->max_halt_poll_ns) - val = vcpu->kvm->max_halt_poll_ns; + if (val > max_halt_poll_ns) + val = max_halt_poll_ns; vcpu->halt_poll_ns = val; out: @@ -3261,6 +3260,7 @@ void kvm_vcpu_halt(struct kvm_vcpu *vcpu) { bool halt_poll_allowed = !kvm_arch_no_poll(vcpu); bool do_halt_poll = halt_poll_allowed && vcpu->halt_poll_ns; + unsigned int max_halt_poll_ns; ktime_t start, cur, poll_end; bool waited = false; u64 halt_ns; @@ -3304,19 +3304,25 @@ void kvm_vcpu_halt(struct kvm_vcpu *vcpu) update_halt_poll_stats(vcpu, start, poll_end, !waited); if (halt_poll_allowed) { + max_halt_poll_ns = vcpu->kvm->max_halt_poll_ns; + if (max_halt_poll_ns) + max_halt_poll_ns = min(max_halt_poll_ns, halt_poll_ns); + else + max_halt_poll_ns = halt_poll_ns; + if (!vcpu_valid_wakeup(vcpu)) { shrink_halt_poll_ns(vcpu); - } else if (vcpu->kvm->max_halt_poll_ns) { + } else if (max_halt_poll_ns) { if (halt_ns <= vcpu->halt_poll_ns) ; /* we had a long block, shrink polling */ else if (vcpu->halt_poll_ns && - halt_ns > vcpu->kvm->max_halt_poll_ns) + halt_ns > max_halt_poll_ns) shrink_halt_poll_ns(vcpu); /* we had a short halt and our poll time is too small */ - else if (vcpu->halt_poll_ns < vcpu->kvm->max_halt_poll_ns && - halt_ns < vcpu->kvm->max_halt_poll_ns) - grow_halt_poll_ns(vcpu); + else if (vcpu->halt_poll_ns < max_halt_poll_ns && + halt_ns < max_halt_poll_ns) + grow_halt_poll_ns(vcpu, max_halt_poll_ns); } else { vcpu->halt_poll_ns = 0; } 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 B1E7EC4332F for ; Mon, 27 Sep 2021 14:59:58 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 2CEB860FF2 for ; Mon, 27 Sep 2021 14:59:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2CEB860FF2 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 9E37B4B0A3; Mon, 27 Sep 2021 10:59:57 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mgIjPDm2+wWO; Mon, 27 Sep 2021 10:59:56 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 7DFE240667; Mon, 27 Sep 2021 10:59:56 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id CACEC4A524 for ; Mon, 27 Sep 2021 10:59:54 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MbSlTxvphzSe for ; Mon, 27 Sep 2021 10:59:53 -0400 (EDT) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id B4637405EE for ; Mon, 27 Sep 2021 10:59:53 -0400 (EDT) Received: by mail-pg1-f177.google.com with SMTP id s75so1538895pgs.5 for ; Mon, 27 Sep 2021 07:59:53 -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=8d5KqXA5Mi92PwzZc0N/pdrf/YfLC80LCsk313TOlF8=; b=m7Sxwd73+QIO2WuPaGefD2VV92Ixlana/rvgLp3fywdfnLLEysnYWnlbrJZMSHvky2 P+dNFDKl+i/DMSPcDLNPjzckqkQLgh9pdU/c3JQwnIagXzSzhgOa+ncEZvwMUJLQWG1m fybm6n4GY1o2I/TIIMUtFfjJTQU9KFbL0J/XoEro7oVzMh1zw+XmI5tRZQQeuZDe42Dg Tmmp6oePrkChYyER1Tnna/qEz55zzNMH1ZMLBsrMQL84AaEtkyNXBlm2Xx+ZucKX/mXL yMhzhoMAfnJyECqCajIjTuZBzhOpC4zX9voYjWadeZj+T2l75O1okb7Y4J7XHlu7WdkY kHUg== 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=8d5KqXA5Mi92PwzZc0N/pdrf/YfLC80LCsk313TOlF8=; b=IHwN0bJFyNKAYZWlpVqaOmnpTUrUnWYBTbRk6kcc12e6eBFUQOoiWYwJCun1FM4Oxc RITNbgHGf1TEPiAXY94WAeHRlnMPOvCX6JpnhdEbxDLhSt7QJJMERhLi5iJlbWuNPoei sw3wFCssm3orYqkouJvbWVOfNa8mntjUrU5VpTmK2Zq4h82wkWrjLdslxK1mi7awS3oB 0xwU4p4WJnPBl71D+WkMWD57hh+zFs0qzbHCV/UOdGvoRaYf3yZ6o7n3jatqoXObzWmO l2ncZyKh4RVyd1f0RCgh5rysSgayVozSNVFzkX9+encWKb0UxcfybJ9x+SsVREtcDxh6 lAlg== X-Gm-Message-State: AOAM532DZ0kmsYnHAXQshzvK/eSw/Bv5PfroJX8pDmgtN/LUyh8CJmja Dli5nrHLpAlmEv+N5WeMx0GczA== X-Google-Smtp-Source: ABdhPJyg70ia4mflauFBTnYYkPuZeGu0PUo7u3KrQoV6hyYnlf5Ujo4gsfK+PdoDvaYqAOyRoeDCGg== X-Received: by 2002:a63:e057:: with SMTP id n23mr107748pgj.183.1632754792472; Mon, 27 Sep 2021 07:59:52 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id n14sm19177569pgd.48.2021.09.27.07.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 07:59:51 -0700 (PDT) Date: Mon, 27 Sep 2021 14:59:47 +0000 From: Sean Christopherson To: Christian Borntraeger Subject: Re: disabling halt polling broken? (was Re: [PATCH 00/14] KVM: Halt-polling fixes, cleanups and a new stat) Message-ID: References: <20210925005528.1145584-1-seanjc@google.com> <03f2f5ab-e809-2ba5-bd98-3393c3b843d2@de.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <03f2f5ab-e809-2ba5-bd98-3393c3b843d2@de.ibm.com> Cc: Wanpeng Li , kvm@vger.kernel.org, David Hildenbrand , linux-kernel@vger.kernel.org, Paul Mackerras , Claudio Imbrenda , kvmarm@lists.cs.columbia.edu, Janosch Frank , Marc Zyngier , Joerg Roedel , Huacai Chen , Aleksandar Markovic , Jon Cargille , kvm-ppc@vger.kernel.org, David Matlack , linux-arm-kernel@lists.infradead.org, Jim Mattson , Cornelia Huck , linux-mips@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Mon, Sep 27, 2021, Christian Borntraeger wrote: > While looking into this series, > > I realized that Davids patch > > commit acd05785e48c01edb2c4f4d014d28478b5f19fb5 > Author: David Matlack > AuthorDate: Fri Apr 17 15:14:46 2020 -0700 > Commit: Paolo Bonzini > CommitDate: Fri Apr 24 12:53:17 2020 -0400 > > kvm: add capability for halt polling > > broke the possibility for an admin to disable halt polling for already running KVM guests. > In past times doing > echo 0 > /sys/module/kvm/parameters/halt_poll_ns > > stopped polling system wide. > Now all KVM guests will use the halt_poll_ns value that was active during > startup - even those that do not use KVM_CAP_HALT_POLL. > > I guess this was not intended? Ouch. I would go so far as to say that halt_poll_ns should be a hard limit on the capability. What about having the per-VM variable track only the capability, and then use the module param to cap the max when doing adjustments? E.g. add a variant of this early in the series? diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 80f78daa6b8d..f50e4e31a0cf 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1078,8 +1078,6 @@ static struct kvm *kvm_create_vm(unsigned long type) goto out_err_no_arch_destroy_vm; } - kvm->max_halt_poll_ns = halt_poll_ns; - r = kvm_arch_init_vm(kvm, type); if (r) goto out_err_no_arch_destroy_vm; @@ -3136,7 +3134,8 @@ void kvm_sigset_deactivate(struct kvm_vcpu *vcpu) sigemptyset(¤t->real_blocked); } -static void grow_halt_poll_ns(struct kvm_vcpu *vcpu) +static void grow_halt_poll_ns(struct kvm_vcpu *vcpu, + unsigned int max_halt_poll_ns) { unsigned int old, val, grow, grow_start; @@ -3150,8 +3149,8 @@ static void grow_halt_poll_ns(struct kvm_vcpu *vcpu) if (val < grow_start) val = grow_start; - if (val > vcpu->kvm->max_halt_poll_ns) - val = vcpu->kvm->max_halt_poll_ns; + if (val > max_halt_poll_ns) + val = max_halt_poll_ns; vcpu->halt_poll_ns = val; out: @@ -3261,6 +3260,7 @@ void kvm_vcpu_halt(struct kvm_vcpu *vcpu) { bool halt_poll_allowed = !kvm_arch_no_poll(vcpu); bool do_halt_poll = halt_poll_allowed && vcpu->halt_poll_ns; + unsigned int max_halt_poll_ns; ktime_t start, cur, poll_end; bool waited = false; u64 halt_ns; @@ -3304,19 +3304,25 @@ void kvm_vcpu_halt(struct kvm_vcpu *vcpu) update_halt_poll_stats(vcpu, start, poll_end, !waited); if (halt_poll_allowed) { + max_halt_poll_ns = vcpu->kvm->max_halt_poll_ns; + if (max_halt_poll_ns) + max_halt_poll_ns = min(max_halt_poll_ns, halt_poll_ns); + else + max_halt_poll_ns = halt_poll_ns; + if (!vcpu_valid_wakeup(vcpu)) { shrink_halt_poll_ns(vcpu); - } else if (vcpu->kvm->max_halt_poll_ns) { + } else if (max_halt_poll_ns) { if (halt_ns <= vcpu->halt_poll_ns) ; /* we had a long block, shrink polling */ else if (vcpu->halt_poll_ns && - halt_ns > vcpu->kvm->max_halt_poll_ns) + halt_ns > max_halt_poll_ns) shrink_halt_poll_ns(vcpu); /* we had a short halt and our poll time is too small */ - else if (vcpu->halt_poll_ns < vcpu->kvm->max_halt_poll_ns && - halt_ns < vcpu->kvm->max_halt_poll_ns) - grow_halt_poll_ns(vcpu); + else if (vcpu->halt_poll_ns < max_halt_poll_ns && + halt_ns < max_halt_poll_ns) + grow_halt_poll_ns(vcpu, max_halt_poll_ns); } else { vcpu->halt_poll_ns = 0; } _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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 510F3C433F5 for ; Mon, 27 Sep 2021 15:02:31 +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 188A760F39 for ; Mon, 27 Sep 2021 15:02:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 188A760F39 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=f/GZh5EHtd1CG56Ohp1bfLNWRWKJAUdYfbStgGzYl+k=; b=KjhvcZSLX4Ep+9 rhNeMzwzyJMv57WVSd6WxGwBfO6TXWAUXi+aEyfeLWDVZEn4TUnrSc4EbJfGoKezm8yWCzxflWahj JRcRlgz0wQ/ZNwDHujD3SNO90Khjk+Pkier777QzoukQ+wvBhVsB32uijXP03R2IKQw7HCk1cu8qe 6Fx9WkTffEMwcVrlWrqFVpx70L+0EPPNcr59gEJNOfxFgAQrwCZzmOI7ccT8QwH4CYoIfhzaL9YqY k/Zug5DabE3TqaUnExLO2Gg0NgndKgPYTUwbm3v/mUfTdUQAd1qNh2gsLEpt9Pmg0K+CXtoTDYMw7 V3VhY2p3/GdWz2V5tEXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mUs6o-002zWD-5Q; Mon, 27 Sep 2021 14:59:58 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mUs6k-002zV5-N1 for linux-arm-kernel@lists.infradead.org; Mon, 27 Sep 2021 14:59:56 +0000 Received: by mail-pf1-x435.google.com with SMTP id y8so16104839pfa.7 for ; Mon, 27 Sep 2021 07:59:53 -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=8d5KqXA5Mi92PwzZc0N/pdrf/YfLC80LCsk313TOlF8=; b=m7Sxwd73+QIO2WuPaGefD2VV92Ixlana/rvgLp3fywdfnLLEysnYWnlbrJZMSHvky2 P+dNFDKl+i/DMSPcDLNPjzckqkQLgh9pdU/c3JQwnIagXzSzhgOa+ncEZvwMUJLQWG1m fybm6n4GY1o2I/TIIMUtFfjJTQU9KFbL0J/XoEro7oVzMh1zw+XmI5tRZQQeuZDe42Dg Tmmp6oePrkChYyER1Tnna/qEz55zzNMH1ZMLBsrMQL84AaEtkyNXBlm2Xx+ZucKX/mXL yMhzhoMAfnJyECqCajIjTuZBzhOpC4zX9voYjWadeZj+T2l75O1okb7Y4J7XHlu7WdkY kHUg== 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=8d5KqXA5Mi92PwzZc0N/pdrf/YfLC80LCsk313TOlF8=; b=JEHg4576DJxLkZu09+XswnqTeQd1NnxaeA16yFc5m4jRt3l5hsVlV9oIK6/G26hkf3 jq7QjgUQE+N7EOVEESFiz1H8mGN7v10i7j3t6CO6jA66ch9KOOk8NPHTi06GZAPKETpC zo5A+zs9hWnXD4LED3pKdmjYKtNx5g1LT9KEx9dnGjFMDbuRFQ90ann6pjHjrDpXh7lS lqRLWwcEtbGfzaGgoRpKJp30hxNjIuS5cEEgidfCXdl5fK7QwgH518qrBl0uKofYoKVy GalwwdKGdnKr1R1WnSn0IS+rKRBc7qFPLFjxufcRM7+YWsyr19qcKOnr4YUZRUxEQHII 4x1g== X-Gm-Message-State: AOAM530O6xjGsPY7bOZFItUm/jOVfm++Uw2X62cB5iqKJy3x1F+6mCFY nmdBVOcd/YZkNFaqHyeocM+NZg== X-Google-Smtp-Source: ABdhPJyg70ia4mflauFBTnYYkPuZeGu0PUo7u3KrQoV6hyYnlf5Ujo4gsfK+PdoDvaYqAOyRoeDCGg== X-Received: by 2002:a63:e057:: with SMTP id n23mr107748pgj.183.1632754792472; Mon, 27 Sep 2021 07:59:52 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id n14sm19177569pgd.48.2021.09.27.07.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 07:59:51 -0700 (PDT) Date: Mon, 27 Sep 2021 14:59:47 +0000 From: Sean Christopherson To: Christian Borntraeger Cc: Paolo Bonzini , David Matlack , Jon Cargille , Jim Mattson , James Morse , Alexandru Elisei , Suzuki K Poulose , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , 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 , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Janosch Frank Subject: Re: disabling halt polling broken? (was Re: [PATCH 00/14] KVM: Halt-polling fixes, cleanups and a new stat) Message-ID: References: <20210925005528.1145584-1-seanjc@google.com> <03f2f5ab-e809-2ba5-bd98-3393c3b843d2@de.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <03f2f5ab-e809-2ba5-bd98-3393c3b843d2@de.ibm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210927_075954_797688_B58DD960 X-CRM114-Status: GOOD ( 20.98 ) 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 Mon, Sep 27, 2021, Christian Borntraeger wrote: > While looking into this series, > > I realized that Davids patch > > commit acd05785e48c01edb2c4f4d014d28478b5f19fb5 > Author: David Matlack > AuthorDate: Fri Apr 17 15:14:46 2020 -0700 > Commit: Paolo Bonzini > CommitDate: Fri Apr 24 12:53:17 2020 -0400 > > kvm: add capability for halt polling > > broke the possibility for an admin to disable halt polling for already running KVM guests. > In past times doing > echo 0 > /sys/module/kvm/parameters/halt_poll_ns > > stopped polling system wide. > Now all KVM guests will use the halt_poll_ns value that was active during > startup - even those that do not use KVM_CAP_HALT_POLL. > > I guess this was not intended? Ouch. I would go so far as to say that halt_poll_ns should be a hard limit on the capability. What about having the per-VM variable track only the capability, and then use the module param to cap the max when doing adjustments? E.g. add a variant of this early in the series? diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 80f78daa6b8d..f50e4e31a0cf 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1078,8 +1078,6 @@ static struct kvm *kvm_create_vm(unsigned long type) goto out_err_no_arch_destroy_vm; } - kvm->max_halt_poll_ns = halt_poll_ns; - r = kvm_arch_init_vm(kvm, type); if (r) goto out_err_no_arch_destroy_vm; @@ -3136,7 +3134,8 @@ void kvm_sigset_deactivate(struct kvm_vcpu *vcpu) sigemptyset(¤t->real_blocked); } -static void grow_halt_poll_ns(struct kvm_vcpu *vcpu) +static void grow_halt_poll_ns(struct kvm_vcpu *vcpu, + unsigned int max_halt_poll_ns) { unsigned int old, val, grow, grow_start; @@ -3150,8 +3149,8 @@ static void grow_halt_poll_ns(struct kvm_vcpu *vcpu) if (val < grow_start) val = grow_start; - if (val > vcpu->kvm->max_halt_poll_ns) - val = vcpu->kvm->max_halt_poll_ns; + if (val > max_halt_poll_ns) + val = max_halt_poll_ns; vcpu->halt_poll_ns = val; out: @@ -3261,6 +3260,7 @@ void kvm_vcpu_halt(struct kvm_vcpu *vcpu) { bool halt_poll_allowed = !kvm_arch_no_poll(vcpu); bool do_halt_poll = halt_poll_allowed && vcpu->halt_poll_ns; + unsigned int max_halt_poll_ns; ktime_t start, cur, poll_end; bool waited = false; u64 halt_ns; @@ -3304,19 +3304,25 @@ void kvm_vcpu_halt(struct kvm_vcpu *vcpu) update_halt_poll_stats(vcpu, start, poll_end, !waited); if (halt_poll_allowed) { + max_halt_poll_ns = vcpu->kvm->max_halt_poll_ns; + if (max_halt_poll_ns) + max_halt_poll_ns = min(max_halt_poll_ns, halt_poll_ns); + else + max_halt_poll_ns = halt_poll_ns; + if (!vcpu_valid_wakeup(vcpu)) { shrink_halt_poll_ns(vcpu); - } else if (vcpu->kvm->max_halt_poll_ns) { + } else if (max_halt_poll_ns) { if (halt_ns <= vcpu->halt_poll_ns) ; /* we had a long block, shrink polling */ else if (vcpu->halt_poll_ns && - halt_ns > vcpu->kvm->max_halt_poll_ns) + halt_ns > max_halt_poll_ns) shrink_halt_poll_ns(vcpu); /* we had a short halt and our poll time is too small */ - else if (vcpu->halt_poll_ns < vcpu->kvm->max_halt_poll_ns && - halt_ns < vcpu->kvm->max_halt_poll_ns) - grow_halt_poll_ns(vcpu); + else if (vcpu->halt_poll_ns < max_halt_poll_ns && + halt_ns < max_halt_poll_ns) + grow_halt_poll_ns(vcpu, max_halt_poll_ns); } else { vcpu->halt_poll_ns = 0; } _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Christopherson Date: Mon, 27 Sep 2021 14:59:47 +0000 Subject: Re: disabling halt polling broken? (was Re: [PATCH 00/14] KVM: Halt-polling fixes, cleanups and a ne Message-Id: List-Id: References: <20210925005528.1145584-1-seanjc@google.com> <03f2f5ab-e809-2ba5-bd98-3393c3b843d2@de.ibm.com> In-Reply-To: <03f2f5ab-e809-2ba5-bd98-3393c3b843d2@de.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Christian Borntraeger Cc: Paolo Bonzini , David Matlack , Jon Cargille , Jim Mattson , James Morse , Alexandru Elisei , Suzuki K Poulose , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , 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 , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Janosch Frank On Mon, Sep 27, 2021, Christian Borntraeger wrote: > While looking into this series, > > I realized that Davids patch > > commit acd05785e48c01edb2c4f4d014d28478b5f19fb5 > Author: David Matlack > AuthorDate: Fri Apr 17 15:14:46 2020 -0700 > Commit: Paolo Bonzini > CommitDate: Fri Apr 24 12:53:17 2020 -0400 > > kvm: add capability for halt polling > > broke the possibility for an admin to disable halt polling for already running KVM guests. > In past times doing > echo 0 > /sys/module/kvm/parameters/halt_poll_ns > > stopped polling system wide. > Now all KVM guests will use the halt_poll_ns value that was active during > startup - even those that do not use KVM_CAP_HALT_POLL. > > I guess this was not intended? Ouch. I would go so far as to say that halt_poll_ns should be a hard limit on the capability. What about having the per-VM variable track only the capability, and then use the module param to cap the max when doing adjustments? E.g. add a variant of this early in the series? diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 80f78daa6b8d..f50e4e31a0cf 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1078,8 +1078,6 @@ static struct kvm *kvm_create_vm(unsigned long type) goto out_err_no_arch_destroy_vm; } - kvm->max_halt_poll_ns = halt_poll_ns; - r = kvm_arch_init_vm(kvm, type); if (r) goto out_err_no_arch_destroy_vm; @@ -3136,7 +3134,8 @@ void kvm_sigset_deactivate(struct kvm_vcpu *vcpu) sigemptyset(¤t->real_blocked); } -static void grow_halt_poll_ns(struct kvm_vcpu *vcpu) +static void grow_halt_poll_ns(struct kvm_vcpu *vcpu, + unsigned int max_halt_poll_ns) { unsigned int old, val, grow, grow_start; @@ -3150,8 +3149,8 @@ static void grow_halt_poll_ns(struct kvm_vcpu *vcpu) if (val < grow_start) val = grow_start; - if (val > vcpu->kvm->max_halt_poll_ns) - val = vcpu->kvm->max_halt_poll_ns; + if (val > max_halt_poll_ns) + val = max_halt_poll_ns; vcpu->halt_poll_ns = val; out: @@ -3261,6 +3260,7 @@ void kvm_vcpu_halt(struct kvm_vcpu *vcpu) { bool halt_poll_allowed = !kvm_arch_no_poll(vcpu); bool do_halt_poll = halt_poll_allowed && vcpu->halt_poll_ns; + unsigned int max_halt_poll_ns; ktime_t start, cur, poll_end; bool waited = false; u64 halt_ns; @@ -3304,19 +3304,25 @@ void kvm_vcpu_halt(struct kvm_vcpu *vcpu) update_halt_poll_stats(vcpu, start, poll_end, !waited); if (halt_poll_allowed) { + max_halt_poll_ns = vcpu->kvm->max_halt_poll_ns; + if (max_halt_poll_ns) + max_halt_poll_ns = min(max_halt_poll_ns, halt_poll_ns); + else + max_halt_poll_ns = halt_poll_ns; + if (!vcpu_valid_wakeup(vcpu)) { shrink_halt_poll_ns(vcpu); - } else if (vcpu->kvm->max_halt_poll_ns) { + } else if (max_halt_poll_ns) { if (halt_ns <= vcpu->halt_poll_ns) ; /* we had a long block, shrink polling */ else if (vcpu->halt_poll_ns && - halt_ns > vcpu->kvm->max_halt_poll_ns) + halt_ns > max_halt_poll_ns) shrink_halt_poll_ns(vcpu); /* we had a short halt and our poll time is too small */ - else if (vcpu->halt_poll_ns < vcpu->kvm->max_halt_poll_ns && - halt_ns < vcpu->kvm->max_halt_poll_ns) - grow_halt_poll_ns(vcpu); + else if (vcpu->halt_poll_ns < max_halt_poll_ns && + halt_ns < max_halt_poll_ns) + grow_halt_poll_ns(vcpu, max_halt_poll_ns); } else { vcpu->halt_poll_ns = 0; }