Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp889313pxb; Wed, 27 Oct 2021 14:32:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/sQPUrRXdV3KKgUQVHu7R7uLQUX5dP/44qcyG50VuHrdB/YTpcOIBfQkrGcx7qU71fINJ X-Received: by 2002:a05:6402:504:: with SMTP id m4mr518345edv.202.1635370229082; Wed, 27 Oct 2021 14:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635370229; cv=none; d=google.com; s=arc-20160816; b=gRxHz0Mp6bb8lh8V85biIwJV2zS/lW3xpv4hdQs1/SJbDUgo6V/Y++iED5qZpXEbIN pyvbRsoLsD6SnjwhJMGO/uM/QSO8jvC6VgU1JY+NDvqG+DO8t5MPSW1oAzjX0cdvRi1L 8hC99A4UwE2jqvLCDK2atNpSWftgwghh5jZC2MYnmEsEG5h4rDvgEGgGA3p8FCmITLfN NQYj3IsUyAP0Yvthxrc4S9TVq+jh2vCgKyVxgp211YPh3cROtwIokfGECnjZPCiH/Noy zqJKea6fTulrBu5g2w5OFLoYwhmGCW83dyExH3FaCKKU+wcsBR6JE8nKJLktr0O7eB+b DfoA== 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=LMqODRZlF8nHhJs02sWnsNzJB8DCwjwV772Lcvk4X9o=; b=YlvTvvCbcTj1Pag7dlSd+dsAvOuo9KJ39mIyKUd8pZPA37vhelNQrP5Xcy1d6BMb/t 9+Hh9/q9SUEQyIPWUXioJW4uU3hpYT4sIIg8KH4/xKcJ/ZSJ7agIwcswmz1ZN/q4uGnJ n+Wqb5aSPDsLxYN1/w/+27I0JEd6wcY7tby+6Gf4uhGGjN2O1B9XhVWU+vlygJNX/7Zu 81IpmhWB3Z59gAVe0xVWhETd8xQhc0Q7k3f/V+3rNBN/ObAqP1BVHeJqQ62WQRY6pKrN xEk6pCJF7k13JOn/Bk0I2U7xqzSvmRTLXQsSdQN1AUvOVaeih5dADjbXd0ZfD3+gAxxX U0Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=iWwrbnSH; 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 v20si1226959eda.303.2021.10.27.14.30.05; Wed, 27 Oct 2021 14:30:29 -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=20210112 header.b=iWwrbnSH; 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 S242525AbhJ0O3N (ORCPT + 97 others); Wed, 27 Oct 2021 10:29:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238191AbhJ0O3J (ORCPT ); Wed, 27 Oct 2021 10:29:09 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB584C061767 for ; Wed, 27 Oct 2021 07:26:43 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id oa12-20020a17090b1bcc00b0019f715462a8so2209471pjb.3 for ; Wed, 27 Oct 2021 07:26:43 -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=LMqODRZlF8nHhJs02sWnsNzJB8DCwjwV772Lcvk4X9o=; b=iWwrbnSH9Fky5OxBApAzRFVpTKOaMHDs7Xrzkqa4bfHRvpB9pNrmqtwX5XStYSbIol NG6pr6of1LmRK/X8yeBvBQ0Fz8uYI6sCKWIvgmckbalOjA8rZIStxifaaVVG+5EdlLz8 2ckfTI/AHFWKc1rHQsrwcPVdrkLnqwK/drtGVgppY9agtMGjOEk436kI8PMz0SqSkGNT dkWDCvrzCBVDPIbGEr6AdGS2sCg8RuoXUFOHg6zS7uI1OSE10fKTNRuuwKsMoNZNiFkf iPVMGJAgypYBjZDhK8mjFm7rCt98R0DWG7pkzdEiPhkk3mMy819HFjaZfkrakLKQ8KAR Wy0Q== 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=LMqODRZlF8nHhJs02sWnsNzJB8DCwjwV772Lcvk4X9o=; b=1DYvrWlKccH0vZ/cqOvMevPhljgCXOQSLHrqfvdp4JCgeBtI+bqTUsmwvOwjMAlP0q 5c9qDQ3f07jj2E84rcHOS7tUG68MRh0r5TZlbIMAqzP1HTCiU2XnyACoFevQVubP/fAP MmWLvCfZ/2dlLspV1r90+w5MOcCECHYQQXM38q5r1lwi/Y8jZTdgyCcnNw0hk8lwB2a0 FOBKR/57QFYXls9tqKQiQuy3BfdO8PiX1Dt0gpGmUGdbo17di/c8HGjq88T+1ubvuL0L JiUi0fuXDnCV8iI4P3/rlcNC4+g27Ba3nA7/orMJks4bXfCO58ejwY78NzSCs8CbMt5k fSmg== X-Gm-Message-State: AOAM532BiqTsS6HYqXCoMgyNGjm33hmmKIpjTuh+MWnhWuUV1fNlbeLF o5WqFvxyz1G/8JjyGNZXHfOGSA== X-Received: by 2002:a17:90b:11c2:: with SMTP id gv2mr5997881pjb.133.1635344802985; Wed, 27 Oct 2021 07:26:42 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id n12sm37080pgh.55.2021.10.27.07.26.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 07:26:42 -0700 (PDT) Date: Wed, 27 Oct 2021 14:26:38 +0000 From: Sean Christopherson To: Paolo Bonzini Cc: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , 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, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , Oliver Upton , Jing Zhang Subject: Re: [PATCH v2 24/43] KVM: VMX: Drop pointless PI.NDST update when blocking Message-ID: References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-25-seanjc@google.com> <18e6a656-f583-0ad4-6770-9678be3f5cf4@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <18e6a656-f583-0ad4-6770-9678be3f5cf4@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 25, 2021, Paolo Bonzini wrote: > On 09/10/21 04:12, Sean Christopherson wrote: > > Don't update Posted Interrupt's NDST, a.k.a. the target pCPU, in the > > pre-block path, as NDST is guaranteed to be up-to-date. The comment > > about the vCPU being preempted during the update is simply wrong, as the > > update path runs with IRQs disabled (from before snapshotting vcpu->cpu, > > until after the update completes). > > Right, it didn't as of commit bf9f6ac8d74969690df1485b33b7c238ca9f2269 (when > VT-d posted interrupts were introduced). > > The interrupt disable/enable pair was added in the same commit that > motivated the introduction of the sanity checks: Ya, I found that commit when digging around for different commit in the series and forgot to come back to this changelog. I'll incorporate this info into the next version. > commit 8b306e2f3c41939ea528e6174c88cfbfff893ce1 > Author: Paolo Bonzini > Date: Tue Jun 6 12:57:05 2017 +0200 > > KVM: VMX: avoid double list add with VT-d posted interrupts > > In some cases, for example involving hot-unplug of assigned > devices, pi_post_block can forget to remove the vCPU from the > blocked_vcpu_list. When this happens, the next call to > pi_pre_block corrupts the list. > > Fix this in two ways. First, check vcpu->pre_pcpu in pi_pre_block > and WARN instead of adding the element twice in the list. Second, > always do the list removal in pi_post_block if vcpu->pre_pcpu is > set (not -1). > > The new code keeps interrupts disabled for the whole duration of > pi_pre_block/pi_post_block. This is not strictly necessary, but > easier to follow. For the same reason, PI.ON is checked only > after the cmpxchg, and to handle it we just call the post-block > code. This removes duplication of the list removal code. > > At the time, I didn't notice the now useless NDST update. > > Paolo > > > The vCPU can get preempted_before_ the update starts, but not during. > > And if the vCPU is preempted before, vmx_vcpu_pi_load() is responsible > > for updating NDST when the vCPU is scheduled back in. In that case, the > > check against the wakeup vector in vmx_vcpu_pi_load() cannot be true as > > that would require the notification vector to have been set to the wakeup > > vector_before_ blocking. > > > > Opportunistically switch to using vcpu->cpu for the list/lock lookups, > > which presumably used pre_pcpu only for some phantom preemption logic. >