From patchwork Tue Aug 9 11:16:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 73544 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp429580qga; Tue, 9 Aug 2016 04:16:59 -0700 (PDT) X-Received: by 10.66.244.199 with SMTP id xi7mr169858455pac.127.1470741419416; Tue, 09 Aug 2016 04:16:59 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id x21si42295041pfj.106.2016.08.09.04.16.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Aug 2016 04:16:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bX50U-0000WM-To; Tue, 09 Aug 2016 11:15:38 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bX4zc-0007H7-SR for linux-arm-kernel@lists.infradead.org; Tue, 09 Aug 2016 11:14:46 +0000 Received: by mail-wm0-x235.google.com with SMTP id i5so27419853wmg.0 for ; Tue, 09 Aug 2016 04:14:24 -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:in-reply-to:references; bh=uBeoIJKFls+Im7puKx7FOTOnmY606yEa+ipbHTuyKIg=; b=TeefpzYBOHuoD4hCByQqPjOjCeI7qXtT/3nXBWtHIseZcsx9tcwpDeiIrDBp1iJyEV n1FQ3uNjOHfy2eZGbhrWzIYVolVIWgxDVTLCQhn/A8EowKzeM/XYyn7y2o5JBHwrVU5S eHkdyeTwUOSynkuVuWxyaUF5iECrh6bkPQXbA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uBeoIJKFls+Im7puKx7FOTOnmY606yEa+ipbHTuyKIg=; b=I2j9Tq+iYaVghOodsxuk3scBvfrQYB5ff4/tjSFZA0H7sLS5rQF6BIoINDKOlXBWJJ lwNLWIooSpnSreNSQE6jwx4yQTIqmR/jQ8Wywm83F55NMs+sg8hcAMokFQ/3UYRmzp/K tgufDOMhdhSMpbioyNkRQGLPFLP6BpFb698ym+CtsXpG2ek0zASkqA5CecNTC7Y36iJU Zd2bdj43QEs9XlM0OmFaUrkTxvpBOrxJ5PIOX9k0R+AdIXD5m5qPAV31rFBU85Or4WiR 3TN6m6Hjt3tbFGbTW/rs/RRANVZWzBOnFWlq58IgNBvIINaI0myQlm/JPc5viTAgH5tf 7tRQ== X-Gm-Message-State: AEkoouuBCF0lCT8sz3uRb3BNvCYrhwgKqZI435hLXS+IVMzXaDq2j/W100FWIGgVFFTU3RO3 X-Received: by 10.194.104.106 with SMTP id gd10mr60774021wjb.55.1470741263296; Tue, 09 Aug 2016 04:14:23 -0700 (PDT) Received: from localhost.localdomain ([94.18.191.146]) by smtp.gmail.com with ESMTPSA id 190sm2796816wmk.13.2016.08.09.04.14.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Aug 2016 04:14:22 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, Marc Zyngier , Andre Przywara Subject: [PATCH v2 3/3] KVM: arm64: vgic-its: Make updates to propbaser/pendbaser atomic Date: Tue, 9 Aug 2016 13:16:06 +0200 Message-Id: <20160809111606.28744-4-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160809111606.28744-1-christoffer.dall@linaro.org> References: <20160809111606.28744-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160809_041445_240715_B9EC2D73 X-CRM114-Status: GOOD ( 15.24 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:235 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoffer Dall , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org There are two problems with the current implementation of the MMIO handlers for the propbaser and pendbaser: First, the write to the value itself is not guaranteed to be an atomic 64-bit write so two concurrent writes to the structure field could be intermixed. Second, because we do a read-modify-update operation without any synchronization, if we have two 32-bit accesses to separate parts of the register, we can loose one of them. By using the atomic cmpxchg64 we should cover both issues above. Signed-off-by: Christoffer Dall --- Notes: Changes since v1: - Use atomic cmpxchg64 instead of taking a lock virt/kvm/arm/vgic/vgic-mmio-v3.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) -- 2.9.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c b/virt/kvm/arm/vgic/vgic-mmio-v3.c index ff668e0..a50d5ba 100644 --- a/virt/kvm/arm/vgic/vgic-mmio-v3.c +++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c @@ -306,16 +306,18 @@ static void vgic_mmio_write_propbase(struct kvm_vcpu *vcpu, { struct vgic_dist *dist = &vcpu->kvm->arch.vgic; struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; - u64 propbaser = dist->propbaser; + u64 old_propbaser, propbaser; /* Storing a value with LPIs already enabled is undefined */ if (vgic_cpu->lpis_enabled) return; - propbaser = update_64bit_reg(propbaser, addr & 4, len, val); - propbaser = vgic_sanitise_propbaser(propbaser); - - dist->propbaser = propbaser; + do { + old_propbaser = dist->propbaser; + propbaser = old_propbaser; + propbaser = update_64bit_reg(propbaser, addr & 4, len, val); + propbaser = vgic_sanitise_propbaser(propbaser); + } while (cmpxchg64(&dist->propbaser, old_propbaser, propbaser)); } static unsigned long vgic_mmio_read_pendbase(struct kvm_vcpu *vcpu, @@ -331,16 +333,18 @@ static void vgic_mmio_write_pendbase(struct kvm_vcpu *vcpu, unsigned long val) { struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; - u64 pendbaser = vgic_cpu->pendbaser; + u64 old_pendbaser, pendbaser; /* Storing a value with LPIs already enabled is undefined */ if (vgic_cpu->lpis_enabled) return; - pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val); - pendbaser = vgic_sanitise_pendbaser(pendbaser); - - vgic_cpu->pendbaser = pendbaser; + do { + old_pendbaser = vgic_cpu->pendbaser; + pendbaser = old_pendbaser; + pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val); + pendbaser = vgic_sanitise_pendbaser(pendbaser); + } while (cmpxchg64(&vgic_cpu->pendbaser, old_pendbaser, pendbaser)); } /*