Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4201357rwb; Tue, 16 Aug 2022 16:58:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR6KClBqW/lWcWSABvnC8XCpZnUxwvh3Vg8mGLJ+epTZCeHKb6er+ccCRCTm8SfkCyI0byKg X-Received: by 2002:a05:6402:35d6:b0:43d:c3b0:1206 with SMTP id z22-20020a05640235d600b0043dc3b01206mr20891459edc.415.1660694332705; Tue, 16 Aug 2022 16:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660694332; cv=none; d=google.com; s=arc-20160816; b=Zg0B0GnNoJOKB5vA7vICAI5oUjtdkex90Y+GOZ6ln5UY2dmWHKlBfANcLtFmILgB/Q ZzWMkVy7nNBevKz/uN3c4BbItowDhNAL36Y6eyeVjiAQ6P9m2qVthfDzCfVv2XEmOh3n qSlMGRWS//OQOlaVQ9L4hMlyQrE2fdJxRkjj0xxKvAcownLLDpRPfrmsAp26ncdJbqOu SbkC7/JQNV8pFwXwUZmU/2cz+rWQbku0zXBuhoxMzkM2znhDHr5721XOUiw4ocUN0rb/ /nPUj/TcEBiIbihwh7DRXXdHg5rm02oVZHOOm7LnS/HS/f3CWdDYUrk1+EFDY/9RGoA/ 3J5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8ETP/Ktaqcv7tPYq7+lEOPfVoA9Z1uN0o+04/7SipRg=; b=ofm2DjyE0YKib9op5NA+5QfF/MgPS5xzu4JZEvLpSUnQ7g80DyxefFFFS/FK12ebAl MtjV5Kga/nqv+ViKxqJMRMdl4fBJ5UsnwPQTtHadi6w6WYjxluflpnLv3aMv6HX2jPti ZShC+H33/wM5zeDUvDSihzLThfv8IuqDaF5GUk7eF9zP91ZHAg4k4sMdgzG5z+hrWJZW EqG6DL0oTpUK/uF98nCsuGXMYSoveU/of1xSK/XXy/OHNWgncTkQIS0XGoBjLhGEoMiI qneqUQs2N7xJBUQNkE37f/CqClxBtNDk991K1d8BsalVGwHxGNYfa6U/BVYYq0pp1UYh Q76A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="VR/y9hXh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l14-20020a170906794e00b0073111225ba5si11027488ejo.743.2022.08.16.16.58.26; Tue, 16 Aug 2022 16:58:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="VR/y9hXh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S237593AbiHPXeP (ORCPT + 99 others); Tue, 16 Aug 2022 19:34:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiHPXeN (ORCPT ); Tue, 16 Aug 2022 19:34:13 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F18E792E2 for ; Tue, 16 Aug 2022 16:34:12 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id jm11so8347629plb.13 for ; Tue, 16 Aug 2022 16:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=8ETP/Ktaqcv7tPYq7+lEOPfVoA9Z1uN0o+04/7SipRg=; b=VR/y9hXheTvaQXwpdmc6aIoOBdKkd4YAuLUXMf9R4KA4vHDLjusEqQJz2jVpUe9psh PCj+D1X3WyPodqWWl5JMTSBHn053EGaSqAIKVEau966Asj+QzEe5cKnpNDUadkAqgSNm WBykD2Dc1ff99h5mCMZBUEPAxzCrM5YM8kz3Nx1gR4gvVXa9oCRMLeOQzU8+GJf9Mtwe R48Mov/urVKjpceJa/BORjWhntwF6o0uU64rSeQFXPLPawYBeAx9mgZ8Oxwoz3twBVhz zimZJXu7ZbTqfflkVB4xF/UldXd/asNmqTEJmtRbIi3kkkStjpvLwVBbqw8X/Tb5mP4v 8XBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=8ETP/Ktaqcv7tPYq7+lEOPfVoA9Z1uN0o+04/7SipRg=; b=T+YNaJ3QGkOvbwKN7wyAtllilprvwIGhyq9CLLpbov3UeEogJejvixfsf73wSanqCx lYrWro4GqdkO73qfmNmKFh4cxSTbf/hRccsXAphVheRCLi4ALEMmT/xuh+ay7qsgT4dN WfTJnO5L62/IP3vjJMhe0SVgcfG/lQ4ylVFeYtMBc0adgVZb5yYvABKeXspdfeX/T4R9 a7YLIQ2/cXlFrCp5PfYL8TIGsNbXWJ2G9myi95bygqA+zK5CujmDh7DQ7T/qDf98jNxV u1K0D2hmEI6WdWR2mxKjr7pmlGDjt2AOSPzb0KjvP0hrxbna6jf3KVfysled2Yw0/3Ky NQDg== X-Gm-Message-State: ACgBeo1pC25C3dPHYbTN0o/YS/+Bx8v43xZPVdVsWdBsVXgm5L54ajIU 022ym3K6GTP5Z6L4+V1erDGfkA== X-Received: by 2002:a17:90a:c395:b0:1fa:b411:805a with SMTP id h21-20020a17090ac39500b001fab411805amr403844pjt.74.1660692851799; Tue, 16 Aug 2022 16:34:11 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id r13-20020a65498d000000b0041bb35b9e80sm8242500pgs.53.2022.08.16.16.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 16:34:11 -0700 (PDT) Date: Tue, 16 Aug 2022 23:34:07 +0000 From: Sean Christopherson To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, mlevitsk@redhat.com, vkuznets@redhat.com Subject: Re: [PATCH v2 2/9] KVM: x86: remove return value of kvm_vcpu_block Message-ID: References: <20220811210605.402337-1-pbonzini@redhat.com> <20220811210605.402337-3-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220811210605.402337-3-pbonzini@redhat.com> X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,FSL_HELO_FAKE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 11, 2022, Paolo Bonzini wrote: > The return value of kvm_vcpu_block will be repurposed soon to return kvm_vcpu_block() > the state of KVM_REQ_UNHALT. In preparation for that, get rid of the > current return value. It is only used by kvm_vcpu_halt to decide whether kvm_vcpu_halt() > the call resulted in a wait, but the same effect can be obtained with > a single round of polling. > > No functional change intended, apart from practically indistinguishable > changes to the polling behavior. This "breaks" update_halt_poll_stats(). At the very least, it breaks the comment that effectively says "waited" is set if and only if schedule() is called. /* * Note, halt-polling is considered successful so long as the vCPU was * never actually scheduled out, i.e. even if the wake event arrived * after of the halt-polling loop itself, but before the full wait. */ if (do_halt_poll) update_halt_poll_stats(vcpu, start, poll_end, !waited); > @@ -3493,35 +3489,32 @@ 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; > - ktime_t start, cur, poll_end; > + ktime_t start, cur, poll_end, stop; > bool waited = false; > u64 halt_ns; > > start = cur = poll_end = ktime_get(); > - if (do_halt_poll) { > - ktime_t stop = ktime_add_ns(start, vcpu->halt_poll_ns); > + stop = do_halt_poll ? start : ktime_add_ns(start, vcpu->halt_poll_ns); This is inverted, the loop should terminate after the first iteration (stop==start) if halt-polling is _not_ allowed, i.e. do_halt_poll is false. Overall, I don't like this patch. I don't necessarily hate it, but I definitely don't like it. Isn't freeing up the return from kvm_vcpu_check_block() unnecessary? Can't we just do: diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 9f11b505cbee..ccb9f8bdeb18 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10633,7 +10633,7 @@ static inline int vcpu_block(struct kvm_vcpu *vcpu) if (hv_timer) kvm_lapic_switch_to_hv_timer(vcpu); - if (!kvm_check_request(KVM_REQ_UNHALT, vcpu)) + if (!kvm_arch_vcpu_runnable(vcpu)) return 1; } which IMO is more intuitive and doesn't require reworking halt-polling (again). I don't see why KVM cares if a vCPU becomes runnable after detecting that something else caused kvm_vcpu_check_block() to bail. E.g. a pending signal doesn't invalidate a pending vCPU event, and either way KVM is bailing from the run loop.