Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3703282imu; Mon, 28 Jan 2019 09:18:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN6L6n4f0eH9ru6Sp8GsrmABtf1G7RatyTFcGhD93+DD3c4Mf1cyI6TYQh6hg7t3NGbdevAu X-Received: by 2002:a62:c101:: with SMTP id i1mr22635791pfg.80.1548695910276; Mon, 28 Jan 2019 09:18:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548695910; cv=none; d=google.com; s=arc-20160816; b=LzwKQpvcFI8IhWSec9b1F0N0eUQFRoPydn8154uAznJmvYZsQ896aifs/hdMQhzAcY JLjJrWEvz5hiOfU75ysqbrJCDi8nmufQ+T+xvrydqYo7rJ3KlpSGdJKwD2FvrbX8L+jc sQqavh6q1lWcXcUvU4B6o8G76VbHxEUE6fRmD9dzu/OejF6vJzupIyusMobRvjeV/fJo Ui3vhoDm/7ozPhMe//yj2u7VewpGvHVi6LU/lp/Ovuu2V8GAxdka6YYBFQtK43PQzZ0I XQekZr9HVAZtHqM4W0TIduqsrxh/C7/tsT/dSgv4HvzHS40/8DhYEyHSwFmuubcQW9yF Yc4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Bcb0dgyyPVsdwIIsKu5pDLIApVo+aZA0wOxeth+JtXs=; b=WBNwZJooTPziToGfQyT5raJQzweDXXGipD8dy8oJZOnzvrGSxIit3VEfLyHKEzXOfV EvJaYpG3vXrj+fQyoCF3UceWphVoUFTbI4mdHpmEBpVnUEbERA5erbfQaXg+wHxOUtLF 3AV1fcURhLc4O/AnhxH+rHGaxoDbLtC9hE2F8+kcDrGTMyF+potOdglYXMPgf4Y6NHG4 g602zdN7BgbVce1S5iVUhJkNWAt9QyzIwwlhd7KVgAI3PQf0a8CK4eqHJYu23Q2FSUCr +Tr+lBL+EQ3U1qcO/2KOBwABl2xCDy+AuSwKiI1OmxLB24lvJhNl4UF5VFJAX6e7t2Ez U8dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=A9WjqXDP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si8284446plk.328.2019.01.28.09.18.14; Mon, 28 Jan 2019 09:18:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=A9WjqXDP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731866AbfA1QFd (ORCPT + 99 others); Mon, 28 Jan 2019 11:05:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:52242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731332AbfA1QF3 (ORCPT ); Mon, 28 Jan 2019 11:05:29 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C433B21848; Mon, 28 Jan 2019 16:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691528; bh=J+FQa65m/ev2b7ugboknUaeK6jTud4j4t7MidPa669I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A9WjqXDP0jBQyh8dzr/2yO2jEeiDw2wsoPZptQ1yVhBJmc79NOf77zLdedpAmojBy 5Zqd/AKC/5jABvxxxV8oYPY/WK5qtoSJo6SMIdNLwbhMffHmlRGx187O3CqjrRTFH5 ee8p1S87rfJsHk71dk+pKtf9CvE0VVs09vJyF4cw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Will Deacon , Robin Murphy , Sasha Levin , iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 4.19 130/258] iommu/arm-smmu-v3: Use explicit mb() when moving cons pointer Date: Mon, 28 Jan 2019 10:57:16 -0500 Message-Id: <20190128155924.51521-130-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will Deacon [ Upstream commit a868e8530441286342f90c1fd9c5f24de3aa2880 ] After removing an entry from a queue (e.g. reading an event in arm_smmu_evtq_thread()) it is necessary to advance the MMIO consumer pointer to free the queue slot back to the SMMU. A memory barrier is required here so that all reads targetting the queue entry have completed before the consumer pointer is updated. The implementation of queue_inc_cons() relies on a writel() to complete the previous reads, but this is incorrect because writel() is only guaranteed to complete prior writes. This patch replaces the call to writel() with an mb(); writel_relaxed() sequence, which gives us the read->write ordering which we require. Cc: Robin Murphy Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- drivers/iommu/arm-smmu-v3.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 4afb9cb99ea3..9ae3678844eb 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -688,7 +688,13 @@ static void queue_inc_cons(struct arm_smmu_queue *q) u32 cons = (Q_WRP(q, q->cons) | Q_IDX(q, q->cons)) + 1; q->cons = Q_OVF(q, q->cons) | Q_WRP(q, cons) | Q_IDX(q, cons); - writel(q->cons, q->cons_reg); + + /* + * Ensure that all CPU accesses (reads and writes) to the queue + * are complete before we update the cons pointer. + */ + mb(); + writel_relaxed(q->cons, q->cons_reg); } static int queue_sync_prod(struct arm_smmu_queue *q) -- 2.19.1