Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2920006pxb; Fri, 8 Oct 2021 19:19:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsLYE5Dz+KupWoCvCAfuKZ5Oc/CxL5k7RlgCm/xyQmZtZuZrG5u/4e0NxO4ttokWAIYaj0 X-Received: by 2002:a17:906:1405:: with SMTP id p5mr8520531ejc.197.1633745964170; Fri, 08 Oct 2021 19:19:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633745964; cv=none; d=google.com; s=arc-20160816; b=gmPAz449NUmWaC7syAIYWo9beu8vGU3StM1Rl0521x/LCfQHFQcmmuXSqFO2ADZWX9 5AfGMCmwlCg35IML7bcl84H/+KuC+rjeYlJkmY3huIggPfqIYn6rkxCGo/hpeTVEOb0S fYa8s+ZT4b5A5IsXUZf7eRwPKdugM0044MgTCzzTkI2K1QQG0fYSHnCvoV2BWOPOzUrm sCLS0rgS/735ik40G0HZEcJjh6B2RS9SQtbsPThHYXJW2bsYTz6AD+B6HYXhdaJkBNN6 dUX2FZ9gccspGm/+ei4AYVJ0AVP9sti0yxBrE3yVS4kMGLgJXtxUmHElAoZAm8VGyYov R5VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=va765MwNV8lkPK+fPa+/nQPV7Q6ICFe76wXLuhKBR7k=; b=bfX+yGllkEdUz5Eldv/gxVqShOmTLZAaYjQ6CE1QAdfWvyi2DkfiaixkC9pPk4y7yW 6BUodM2H4ybyA3BuIpWzZ5Q3Q3eST+92FkTgr/tpKji8oluwiDStBD/U6sdxvL+bioaz ArvnIhw3iguYuNqSWFs0bsuRm7L8L5O2YYS4MmLpA82wxzITd34B1BqbPlmPET8It6Uw GGp6BsW2hEwsmgnxpZqMnCuo/fuL97mAzmvZOjfXk+2g9RKA/l9q1YCpJepzWzElEKQu eazCu0yhwQ4i3D0LfhdH4rBaz3vb1MtvNeA1SQqrY0nEHpeQ/QkQ9xAvRWcKJT+ICKyM Be+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=B5oLyIOK; 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 e14si1520462edj.549.2021.10.08.19.19.01; Fri, 08 Oct 2021 19:19: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=@google.com header.s=20210112 header.b=B5oLyIOK; 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 S244528AbhJICR2 (ORCPT + 99 others); Fri, 8 Oct 2021 22:17:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244164AbhJICQz (ORCPT ); Fri, 8 Oct 2021 22:16:55 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1314C06139D for ; Fri, 8 Oct 2021 19:13:46 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id i21-20020a253b15000000b005b9c0fbba45so15082821yba.20 for ; Fri, 08 Oct 2021 19:13:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=va765MwNV8lkPK+fPa+/nQPV7Q6ICFe76wXLuhKBR7k=; b=B5oLyIOK5DCmxdgNe+Nl5/eUZ+1dZvr28zFbfb0yUmRDrQAn6gFu0meDWGbooWcwf+ l+waGmWoLOHDfWujUlJgTIfXQBGxvJYpWrTevNrJNk5M8uz1livq3G0CbLqGnwGl0JPm sNTwBIZ8vWCCI3dUoTv7AkcFha93KYIamIUHSTRqHBmzceqRPtYmNYOCGYVyZvVn3Np/ TL6ymtR5bZm6u0h37kbtwh2/3um/F6VSleLNBRjXkJxQwQ6Tl5usknG2mBtpFmrzjKYA RfxJYCWymoaofgRtrejK3tfUhsfLqLitFSkmp9z1zLeMTRzswrj10R8lRDFv/A07PTzr ihYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=va765MwNV8lkPK+fPa+/nQPV7Q6ICFe76wXLuhKBR7k=; b=tmBOexEoWG1Wrs9qDpUtOnfVYAzej0UlzH37Tmef6vCamd/h85C1RrCP0EmP8h8nmH 1dA/rGY//CtOk9CghrInOU7COUXZLlb1i5FRtDs+DPJ7nFCuQ+qmkcjZKBVOLu2/f6Ce 8p8lGDdWjmlNlLCyt2QsTHtOJPiYMxdWxMCNSV3XMwatxkdCHlaFa3mIyntRhTMyHOhO NY/LuGVT7fLbmYonPzQPL8iyjydk5lQyW6yK3SiPsfDD0R972nvpS1I08fhsAfFJ630n gIzGWOZAVUcgPkySOfwlRPYwTDq+c6ZjuF2upTMPD83sQYqqjRLXrH4AYh3qcyQIojNl hBLQ== X-Gm-Message-State: AOAM5301066ZII2f2dLwGigdCjaq2aC2OCAplySp9i0J1PJeVbl/tARm k+oEw7xXhcTx5pSek8X1aSmKfzlkmig= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:e39b:6333:b001:cb]) (user=seanjc job=sendgmr) by 2002:a25:69c7:: with SMTP id e190mr6678164ybc.334.1633745625928; Fri, 08 Oct 2021 19:13:45 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 8 Oct 2021 19:12:19 -0700 In-Reply-To: <20211009021236.4122790-1-seanjc@google.com> Message-Id: <20211009021236.4122790-27-seanjc@google.com> Mime-Version: 1.0 References: <20211009021236.4122790-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v2 26/43] KVM: VMX: Read Posted Interrupt "control" exactly once per loop iteration From: Sean Christopherson To: 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 , Sean Christopherson , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.33.0.882.g93a45727a2-goog