From patchwork Wed Aug 2 14:28:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9876865 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3B7BE60390 for ; Wed, 2 Aug 2017 14:28:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B932205F7 for ; Wed, 2 Aug 2017 14:28:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F45826E49; Wed, 2 Aug 2017 14:28:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 972F9205F7 for ; Wed, 2 Aug 2017 14:28:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752598AbdHBO2w (ORCPT ); Wed, 2 Aug 2017 10:28:52 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:37385 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751067AbdHBO2v (ORCPT ); Wed, 2 Aug 2017 10:28:51 -0400 Received: by mail-wm0-f42.google.com with SMTP id t201so43313226wmt.0 for ; Wed, 02 Aug 2017 07:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=oO4h6lS2IoiG0JRzsM/I8kK40bSMtjWYDWb7S8gga4c=; b=Qty2BLUZ92tk6BbrQCuXah02M1qXpa7QhbIjuYOPCpowPpEWeXLpO1WZqgYbM/BnTw 3xTuDoHx+kUvfXcqrEwtfnlw7tqrOKwiEzcLcZ8IOx1Gp2fby87YXj7mWbnEu5kjnal4 eKpCQSOXyT9jk4Xn4iMkiVgrAU3t9OGwpk2RM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oO4h6lS2IoiG0JRzsM/I8kK40bSMtjWYDWb7S8gga4c=; b=t1b/DmDWun/mPjRB93eGKC/dudSCpdhXl6g658ms/A4gpp5ZZ6bIB2YdIvy9nGBRqg fCOV1AiWmdug0ZGNFNMctY7/LH+FnCbWN42WwKJhwgUB0n1OhriDH9SaxrHg2vCm2W48 C2GLpfTHfKNflvCPQgFxlwXph8XLM7nrbMJ7couTg4COSMulyFbI8EIR/GZUKvlzqwlU Sy0iw1Fo4T7vwa1qKxgxtlA1YP0oXDzEqZt1Ea9LjAL0JYvHuhcMOLpifd7xf0M7EzIm TQynxMM5H+2j/dt2Kh7hAqf46DeaO87ZEzIH/m8XrIdBjDK/XDJze7I3WlicmEmVio6q n9Tw== X-Gm-Message-State: AIVw112UeflGc7wSeZmE95HTpYmQL/Dhfp+KEULaNRvnW0HaccNklVMZ uE3Z+CSG7xoO5z5h5DGyRA== X-Received: by 10.80.137.45 with SMTP id e42mr21583840ede.67.1501684130362; Wed, 02 Aug 2017 07:28:50 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id s3sm4716183edb.28.2017.08.02.07.28.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Aug 2017 07:28:49 -0700 (PDT) From: Christoffer Dall To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: Marc Zyngier , Andre Przywara , Christoffer Dall , Catalin Marinas Subject: [PATCH] KVM: arm/arm64: vgic: Use READ_ONCE fo cmpxchg Date: Wed, 2 Aug 2017 16:28:42 +0200 Message-Id: <20170802142842.9494-1-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is a small chance that the compiler could generate separate loads for the dist->propbaser which could be modified from another CPU. As we want to make sure we atomically update the entire value, and don't race with other updates, guarantee that the cmpxchg operation compares against the original value. Cc: Catalin Marinas Signed-off-by: Christoffer Dall Acked-by: Catalin Marinas --- virt/kvm/arm/vgic/vgic-mmio-v3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c b/virt/kvm/arm/vgic/vgic-mmio-v3.c index 714fa39..408ef06 100644 --- a/virt/kvm/arm/vgic/vgic-mmio-v3.c +++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c @@ -369,7 +369,7 @@ static void vgic_mmio_write_propbase(struct kvm_vcpu *vcpu, return; do { - old_propbaser = dist->propbaser; + old_propbaser = READ_ONCE(dist->propbaser); propbaser = old_propbaser; propbaser = update_64bit_reg(propbaser, addr & 4, len, val); propbaser = vgic_sanitise_propbaser(propbaser); @@ -397,7 +397,7 @@ static void vgic_mmio_write_pendbase(struct kvm_vcpu *vcpu, return; do { - old_pendbaser = vgic_cpu->pendbaser; + old_pendbaser = READ_ONCE(vgic_cpu->pendbaser); pendbaser = old_pendbaser; pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val); pendbaser = vgic_sanitise_pendbaser(pendbaser);