Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1447054pxb; Thu, 28 Oct 2021 04:00:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygajfymZjrOMNS4ELKXjddWgFecIbV3TAMDIopTyUBt0zciBZD1CZhEaXSk3i92/WZRMUz X-Received: by 2002:a63:725c:: with SMTP id c28mr2637812pgn.126.1635418857639; Thu, 28 Oct 2021 04:00:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635418857; cv=none; d=google.com; s=arc-20160816; b=Z4B+lj2FoD/9tPmFf01s4oIR84PC/LxE8iu5x+WhPBqlFwdEyrJPZYSEkICwrsoZfH YR/PRAJ+B8kKDHPYEpPUT5oq1a4a0eHXBSe8mg4HWvrKvqCSHPaXml2Xw8GCxPZ/dG35 TZmeG8MAto/UDStFX742ch4Q4UiuX4C+5/8D+9mORo0YpjUWWFHVzdb4z28AjB1LQxIW cobvyk9D3hL2dZotF1BvoWhpo2M2Xa+QkHQSizOzn1deim2WbYnGPxAkZeYZNJvjZoyr K47T9726Z89uJgOGKuR5qbCYzt9aQHk1DUNGJkyxCNzAZs13udlklKzeRcxyaOYQr0lw 38pQ== 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=BSSD6JYIIX/+OAHh3pR71NKYzpuBAvVzGPZ/3rAMc5k=; b=LwG9Qhr0b7ofdgDi6mPvSq182UlpTFf7Eq9z4QVnN+1cqUbHZJ3Ur+GtV7kgHv1fp/ yj2lpUz5sETcE2YYS7sNfHeKhbBBkEF5hVF/wP7PA7H8DHH11Z+H+tpektu1tUFyqtiT clJI2ihl3JAsGKTguX5GdXg1I2ly225kzO3iV/XUGPLxO7EUJsEUAzNDpmIKZnjM9z4E uVRJprbPGW0P0lZHhB7cYctgCsVisaf/BqJ3yD/tOE9TvUXqS+3Btc0mSlaTlhGFh7XO WRulhu7DrA9gzbdnfGEQdwazFt5HBxuLvFXboMG5PN6mBKTnJCa6I4O6/njPnkSze4JE 5vNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aygBQ52F; 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 i10si3368957pla.290.2021.10.28.04.00.44; Thu, 28 Oct 2021 04:00:57 -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=aygBQ52F; 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 S230201AbhJ1LB1 (ORCPT + 99 others); Thu, 28 Oct 2021 07:01:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52762 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbhJ1LB0 (ORCPT ); Thu, 28 Oct 2021 07:01:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635418739; 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=BSSD6JYIIX/+OAHh3pR71NKYzpuBAvVzGPZ/3rAMc5k=; b=aygBQ52FdVuXhyMYAXyAnpMixAhee9mwMA5CGVvAD4A63S61wvsAOCepyVBmb4kQONsAPh oRz7p1w0xZB/uvADqhApVX+sN8TCwoFKGxDRj/1jupGU3Yx7BWW5ZKOXJ4lc98PvZqkp5T 333mfIMalZNY9zJ7d1FglKjeXD6S5K8= 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-486-pBYTSTgoPK2ouWzH2IV0xA-1; Thu, 28 Oct 2021 06:58:56 -0400 X-MC-Unique: pBYTSTgoPK2ouWzH2IV0xA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0C6BC10A8E02; Thu, 28 Oct 2021 10:58:53 +0000 (UTC) Received: from starship (unknown [10.40.194.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9D4B19D9F; Thu, 28 Oct 2021 10:58:41 +0000 (UTC) Message-ID: Subject: Re: [PATCH v2 26/43] KVM: VMX: Read Posted Interrupt "control" exactly once per loop iteration From: Maxim Levitsky To: Sean Christopherson , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Paolo Bonzini Cc: 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: Thu, 28 Oct 2021 13:58:40 +0300 In-Reply-To: <20211009021236.4122790-27-seanjc@google.com> References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-27-seanjc@google.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.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2021-10-08 at 19:12 -0700, Sean Christopherson wrote: > Use READ_ONCE() when loading the posted interrupt descriptor control > field to ensure "old" and "new" have the same base value. If the > compiler emits separate loads, and loads into "new" before "old", KVM > could theoretically drop the ON bit if it were set between the loads. > > Fixes: 28b835d60fcc ("KVM: Update Posted-Interrupts Descriptor when vCPU is preempted") > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/vmx/posted_intr.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c > index 414ea6972b5c..fea343dcc011 100644 > --- a/arch/x86/kvm/vmx/posted_intr.c > +++ b/arch/x86/kvm/vmx/posted_intr.c > @@ -53,7 +53,7 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) > > /* The full case. */ > do { > - old.control = new.control = pi_desc->control; > + old.control = new.control = READ_ONCE(pi_desc->control); > > dest = cpu_physical_id(cpu); > > @@ -104,7 +104,7 @@ static void __pi_post_block(struct kvm_vcpu *vcpu) > "Wakeup handler not enabled while the vCPU was blocking"); > > do { > - old.control = new.control = pi_desc->control; > + old.control = new.control = READ_ONCE(pi_desc->control); > > dest = cpu_physical_id(vcpu->cpu); > > @@ -160,7 +160,7 @@ int pi_pre_block(struct kvm_vcpu *vcpu) > "Posted Interrupt Suppress Notification set before blocking"); > > do { > - old.control = new.control = pi_desc->control; > + old.control = new.control = READ_ONCE(pi_desc->control); > > /* set 'NV' to 'wakeup vector' */ > new.nv = POSTED_INTR_WAKEUP_VECTOR; I wish there was a way to mark fields in a struct, as requiring 'READ_ONCE' on them so that compiler would complain if this isn't done, or automatically use 'READ_ONCE' logic. Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky