Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2408779pxb; Sun, 31 Oct 2021 15:20:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6U0PhrIz+ToiNVTzS3TBZa2AYaxzCH2BqEK1j6vw1+SdO1TUVXT67GZaNfSp3Pgqq9Ghv X-Received: by 2002:a6b:7705:: with SMTP id n5mr923483iom.173.1635718824603; Sun, 31 Oct 2021 15:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635718824; cv=none; d=google.com; s=arc-20160816; b=a2x1Y2mDuufZaVW2PIQ0puwI0/oXGOv6yoDPL8Qo+ozmT/YI5x8E8mEL6iBGGJNWZj BYol3LGHtlkcSBLqmR5EwqrVZWYGADfUWFNKCGoLtBQPKgNp0zsOXOe+132zwpfjdy6+ 9Fla53cI317FppuIe74DFrGjRYfHHQG7hi82ebU3L0fZjlLd1Jo5A8qTIdNKlRgdGp+L Zdftjxy0axW5tfHdqBmzwiQbDv8Hwl8ovFcmsPM+uV46L+tc4SncDjQcjbZB1CgpFHSC 2g+qtkMXkVD7lZNyhrlsB4ghQs1p7TWS5xxi1s2OQejTEq68F7GYKbDvQNUJk+gPNMbN eVXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=C+trWHtpu8oYBXENs5w3b/Qoz24VhlDIgpUGDh1mOJU=; b=M3ordWIS5EIkX0S1OgdMNjW/OdXLogbGWHwtSAtMMeJUUEyllX1Tf9i1GaEqcl4qup nrttIJXdSuO4Fwn6G7i309J//5PyD8ZAahGEOTbDeRKa4CrpWbtBCnTt4/xCeXBoPaLk D9k0zzEsd/3qdy9q0l17eWMJ5SugVxh3npbLD23xkaHaCILx0esG/PninIIBCHEU6Jwa 2fBupSPHI51NFz1fakveH2cJpDog5rAvN58CHPOXYz3khzLPeSjnYX8g6HAMVKMWuITz J4ZFSRjOTG2txduo8lAqhTFzROMI51iQkqAC3xur4iPeiHfcBGXuvYmwb/mfRYC/3RyE GPqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XXocBuzl; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o7si7422252ilo.75.2021.10.31.15.20.12; Sun, 31 Oct 2021 15:20:24 -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=@redhat.com header.s=mimecast20190719 header.b=XXocBuzl; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230274AbhJaWS2 (ORCPT + 99 others); Sun, 31 Oct 2021 18:18:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52942 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbhJaWS0 (ORCPT ); Sun, 31 Oct 2021 18:18:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635718554; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C+trWHtpu8oYBXENs5w3b/Qoz24VhlDIgpUGDh1mOJU=; b=XXocBuzlXFjACAHdBG5qSUSMKgdIodHQ9o5Sk/bbt2jzzUHZOGVB7TJXgq5oJIzXdH0E32 bWc7xUeVxK9zn4TzFunimWXHv9613FpP3Zc4XvPEUk2yE5sl1pbv423W7OZSDNdkomlst2 qzCKVgVC8JOCt9AMIK3DBbv37UJhoYs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-192-WYECgU2fMxmEks3noiYjYA-1; Sun, 31 Oct 2021 18:15:48 -0400 X-MC-Unique: WYECgU2fMxmEks3noiYjYA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6428F801AE3; Sun, 31 Oct 2021 22:15:45 +0000 (UTC) Received: from starship (unknown [10.40.194.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 292202B0B8; Sun, 31 Oct 2021 22:15:28 +0000 (UTC) Message-ID: <592a315a8932b03f601e4c22d5846e97bd4a1103.camel@redhat.com> Subject: Re: [PATCH v2 39/43] KVM: VMX: Don't do full kick when triggering posted interrupt "fails" From: Maxim Levitsky To: Paolo Bonzini , Sean Christopherson 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 Date: Mon, 01 Nov 2021 00:15:26 +0200 In-Reply-To: References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-40-seanjc@google.com> <335822ac-b98b-1eec-4911-34e4d0e99907@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2021-10-28 at 00:09 +0200, Paolo Bonzini wrote: > On 27/10/21 18:04, Sean Christopherson wrote: > > > > + /* > > > > + * The smp_wmb() in kvm_make_request() pairs with the smp_mb_*() > > > > + * after setting vcpu->mode in vcpu_enter_guest(), thus the vCPU > > > > + * is guaranteed to see the event request if triggering a posted > > > > + * interrupt "fails" because vcpu->mode != IN_GUEST_MODE. > > > > > > What this smp_wmb() pair with, is the smp_mb__after_atomic in > > > kvm_check_request(KVM_REQ_EVENT, vcpu). > > > > I don't think that's correct. There is no kvm_check_request() in the relevant path. > > kvm_vcpu_exit_request() uses kvm_request_pending(), which is just a READ_ONCE() > > without a barrier. > > Ok, we are talking about two different set of barriers. This is mine: > > - smp_wmb() in kvm_make_request() pairs with the smp_mb__after_atomic() in > kvm_check_request(); it ensures that everything before the request > (in this case, pi_pending = true) is seen by inject_pending_event. > > - pi_test_and_set_on() orders the write to ON after the write to PIR, > pairing with vmx_sync_pir_to_irr and ensuring that the bit in the PIR is > seen. > > And this is yours: > > - pi_test_and_set_on() _also_ orders the write to ON before the read of > vcpu->mode, pairing with vcpu_enter_guest() > > - kvm_make_request() however does _not_ order the write to > vcpu->requests before the read of vcpu->mode, even though it's needed. > Usually that's handled by kvm_vcpu_exiting_guest_mode(), but in this case > vcpu->mode is read in kvm_vcpu_trigger_posted_interrupt. Yes indeed, kvm_make_request() writes the vcpu->requests after the memory barrier, and then there is no barrier until reading of vcpu->mode in kvm_vcpu_trigger_posted_interrupt. > > So vmx_deliver_nested_posted_interrupt() is missing a smp_mb__after_atomic(). > It's documentation only for x86, but still easily done in v3. > > Paolo > I used this patch as a justification to read Paolo's excellent LWN series of articles on memory barriers, to refresh my knowledge of the memory barriers and understand the above analysis better. https://lwn.net/Articles/844224/ I agree with the above, but this is something that is so easy to make a mistake that I can't be 100% sure. Best regards, Maxim Levitsky