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 E0D5BC433F5 for ; Thu, 28 Oct 2021 10:59:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD35C610F8 for ; Thu, 28 Oct 2021 10:59:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230216AbhJ1LB2 (ORCPT ); Thu, 28 Oct 2021 07:01:28 -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 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 E76A9C433F5 for ; Thu, 28 Oct 2021 10:59:09 +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 AA052610FC for ; Thu, 28 Oct 2021 10:59:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AA052610FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.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:MIME-Version:References:In-Reply-To: Date:Cc:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WHKezOmuNo1LfJhy64hCwnZgeV3I9zAOcwvC2SLKG0k=; b=AlnNmLR+X1pERw 5DRWrcq4exUGFg578fktNWsS4F83irRxsllca80aFBSL7hCHvvetOIDzMoJ97NeM884CK/GxMvh0m i42260aUJomb/P9Uh3DxGL71JGKWaXSOFThxrs7bGStg1D68+7gUpYdr2H8sybm4nq6YckzNWccfa OIsBXyh39Xk8fy6V7qDN6v5dNg6F9QOS0Olwlokuc5/XrSX9UW1JK3CmL6cokcprFVB1WCIY65cPu tUYZv0vlHCM4GF1fky2Tw4gwqk6KvGrUAZidRjhXCi8Lx4hhXmznilfrkR0eB7SnBS2j7N+dTld9A cZvbmt0VZpJPpO/EZwHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mg37f-007cGe-0S; Thu, 28 Oct 2021 10:59:03 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mg37c-007cFQ-Ni for linux-riscv@lists.infradead.org; Thu, 28 Oct 2021 10:59:02 +0000 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> User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211028_035900_884136_0CC187EB X-CRM114-Status: GOOD ( 19.07 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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 B26C8C433EF for ; Thu, 28 Oct 2021 11:00:23 +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 764FA610FC for ; Thu, 28 Oct 2021 11:00:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 764FA610FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.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:MIME-Version:References:In-Reply-To: Date:Cc:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9q6vmjYAeERNlcQDt+l2LrHsCU5OOIW4/znZ7aGsMSQ=; b=1ZcdMKtY/D+Zn9 VLdHax04wtaCuxbIYvUyuXIA8IXkualtnG4pM9BlAx3hRJQflheGmT5GTQxaqp5tW8nGSHdw954Uv 1pTq6maXN3ewlzIkmS8UKYwjLXfNupj6X/jtOaghBPaMNL1iMeC0eGLn/MQUeW63oeXCJb4J1lLPg DGae6KzZEcErUn/qQfkm0yzPdtG7LEKHNjjKxnSpRhgjMKDfJI1NTmGAXVgJ/osqhpXZAyGul0WPO jOFMAZK1rq7MHouRtPsY+dENs/KQQFe6wBsNdAyw7GJlFb+/pwGubZT47dER5+PVMO+UkHC1xY/QD wf+LOwjiqOiZQPgrYphA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mg37h-007cHB-SY; Thu, 28 Oct 2021 10:59:06 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mg37c-007cFO-Nj for linux-arm-kernel@lists.infradead.org; Thu, 28 Oct 2021 10:59:03 +0000 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> User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211028_035900_888694_4CFC1D5E X-CRM114-Status: GOOD ( 20.07 ) 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 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 _______________________________________________ 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 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 D295DC433F5 for ; Thu, 28 Oct 2021 14:09:19 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 7F22161107 for ; Thu, 28 Oct 2021 14:09:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7F22161107 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.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 2FD4B4B1E6; Thu, 28 Oct 2021 10:09:19 -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=@redhat.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 AbuAueY0Nk27; Thu, 28 Oct 2021 10:09:17 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 4FE184B1E9; Thu, 28 Oct 2021 10:09:15 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id F18DF4B1AB for ; Thu, 28 Oct 2021 06:59:00 -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 MkTSQ4NwFGSx for ; Thu, 28 Oct 2021 06:58:59 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mm01.cs.columbia.edu (Postfix) with ESMTP id CB7524B168 for ; Thu, 28 Oct 2021 06:58:59 -0400 (EDT) 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 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> User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mailman-Approved-At: Thu, 28 Oct 2021 10:09:13 -0400 Cc: Wanpeng Li , kvm@vger.kernel.org, David Hildenbrand , linux-kernel@vger.kernel.org, Atish Patra , linux-riscv@lists.infradead.org, Claudio Imbrenda , kvmarm@lists.cs.columbia.edu, Joerg Roedel , kvm-ppc@vger.kernel.org, David Matlack , linux-arm-kernel@lists.infradead.org, Jim Mattson , Cornelia Huck , linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, 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 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 _______________________________________________ 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 From: Maxim Levitsky Date: Thu, 28 Oct 2021 10:58:40 +0000 Subject: Re: [PATCH v2 26/43] KVM: VMX: Read Posted Interrupt "control" exactly once per loop iteration Message-Id: List-Id: References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-27-seanjc@google.com> In-Reply-To: <20211009021236.4122790-27-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 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