From patchwork Tue May 17 09:35:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 12852190 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 9DAB6C433F5 for ; Tue, 17 May 2022 09:36:41 +0000 (UTC) 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:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=F7iZx8peH8rlyTLW3i9mU2vVBeGf0gRlBkDe0oQTT/4=; b=sXV5vbO9i2jnnr WM2lEgWrUo9EGbxDTsarAu6gu1gqtwFJcrcwsSqu/SHzgTRtFdz0MHrr9jE99wo4ZNU0Lq88xK3B3 lsw/B/8LaTuR97QomgWL5vZOQHKieMjdXuAd0RC5jBqZ7SqiV6ai8HX8NACG0VBJvpZXz+bQfuhxa nSq7AxL1w3f2f8rLh0r4O2fs2Q8GP/BkJwbg/tyIRDzK/T/1Z3dh1VfkD1kqL8HIf4ik+7a6xknKm 7nn+DP7ploxpqzbGYDxarEGGAySzb19VYWL7W+R/1aYhwCw/MB4Waz9wM1JpumBxwDgGIA0bCDvKr LlyoaU704o3pSu+vlhiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqtcD-00Cme6-W0; Tue, 17 May 2022 09:35:42 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqtc9-00Cmck-7I for linux-arm-kernel@lists.infradead.org; Tue, 17 May 2022 09:35:38 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8AEB76135A; Tue, 17 May 2022 09:35:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C59ACC385B8; Tue, 17 May 2022 09:35:34 +0000 (UTC) From: Catalin Marinas To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, Steven Price , Vincenzo Frascino , Vladimir Murzin Subject: [PATCH v2] arm64: mte: Ensure the cleared tags are visible before setting the PTE Date: Tue, 17 May 2022 10:35:32 +0100 Message-Id: <20220517093532.127095-1-catalin.marinas@arm.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220517_023537_353447_4703BD09 X-CRM114-Status: GOOD ( 13.44 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org As an optimisation, only pages mapped with PROT_MTE in user space have the MTE tags zeroed. This is done lazily at the set_pte_at() time via mte_sync_tags(). However, this function is missing a barrier and another CPU may see the PTE updated before the zeroed tags are visible. Add an smp_wmb() barrier if the mapping is Normal Tagged. Signed-off-by: Catalin Marinas Fixes: 34bfeea4a9e9 ("arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE") Cc: # 5.10.x Reported-by: Vladimir Murzin Cc: Will Deacon Tested-by: Vladimir Murzin Reviewed-by: Steven Price Reviewed-by: Vincenzo Frascino --- Changes in v2: - make the barrier unconditional - not including reviewed-by, tested-by tags for v1 as the patch is slightly different arch/arm64/kernel/mte.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 90994aca54f3..d565ae25e48f 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -67,6 +67,9 @@ void mte_sync_tags(pte_t old_pte, pte_t pte) mte_sync_page_tags(page, old_pte, check_swap, pte_is_tagged); } + + /* ensure the tags are visible before the PTE is set */ + smp_wmb(); } int memcmp_pages(struct page *page1, struct page *page2)