Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3018325rwb; Mon, 15 Aug 2022 16:15:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR7AwwQghTRT7kbS1Bc2L1gmdZhOOVHUcP7qdBf5TRrWq4X2OBuuXCblObIIecAELyNBTeSJ X-Received: by 2002:a05:6402:f25:b0:43d:e499:e32e with SMTP id i37-20020a0564020f2500b0043de499e32emr16162327eda.2.1660605306828; Mon, 15 Aug 2022 16:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605306; cv=none; d=google.com; s=arc-20160816; b=GlHCMyp5Fgw5oG7p7u4NB6Oqx1XiW1eNfTCXaCpsulKAnR+lltbg4Vg17DJDSIimdc NhsCi3Gb+N8iHlPmxFw5NmnCv4Tsf+FnfkRW3AdAJ5kgBtJDHlAUCs8eCwkea3BBn2F4 5ODBMXIudeFnfX5uLsO85y1E2ElACLTExVOJogcHaRzaedX8yGuttZUM+DhhgsjPUCFv 9Fr+ZestQMtDh3aFFO5xnYOq4Liz0f66ksgwzbHlTARESQ/bARqJAf22JFgqK6skCKMi dHaG3WQWz57XTzbGML1ucbi5INXxbGI8rf05F97O/vj9pP8wKRVW0CmH9re8re16EzCV ldwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TKTVfFSgCRzJknEc/Hlpkw5HzZasf/ddTfHcHzEzXyc=; b=I3L85RmxBBr3MB2ZzxcTCY4wJ4kMyzzaLxfriZJtIRXNuKiygpshAJY+LFOt6PFOCd RZjj+htS0qyDZyfgfLaLQFvCQUBMuC24nEEHQw9De96/BkEDUaqjrPyFFkfm42KDk49K U4v9xBg9r2tzslQtYeexq75gmBqd5weC8Hxwt8lK43yTtbvJt3fGwDIlQWrb4p7IT0s0 Un2ths7K0ogMvUt72N4amVtqCCKdjCoVJvsHRhaLmf1LJbd/AcvWHBX9Bl4aPUJr638a s8wX2CQj9kw0hIa8Db1zUwqdp8sFXlZBCOmYdR/wiYRrPW8+0qkM5mLL0pC+X9gcPaj7 6vFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qrNUMcQt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb23-20020a1709071c9700b0073101ba70bdsi8705639ejc.927.2022.08.15.16.14.20; Mon, 15 Aug 2022 16:15:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qrNUMcQt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350409AbiHOWbo (ORCPT + 99 others); Mon, 15 Aug 2022 18:31:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350211AbiHOW01 (ORCPT ); Mon, 15 Aug 2022 18:26:27 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6914741D14; Mon, 15 Aug 2022 12:45:10 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id EE1ABB81145; Mon, 15 Aug 2022 19:45:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53F25C433D6; Mon, 15 Aug 2022 19:45:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592707; bh=UHJdW9c1sxzkkfsqewEfIRKTxn7cA7ASal24VdsM6Z8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qrNUMcQtz+loyutUYfd//H/6f95StYTCVHANvjVrxOTXhxQ2RhuWVFQ32NDaiD0l1 Pl9JP/KgdDLxo73M5L8LkbcCA8fZIvQuZKAl+FaprIKHNyaHa4Rq0TdIHhXzUjuLZQ pI3pUpJ73jGi1gW0V80mvyiV4OK3nWPDqqA6Vcs4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , Will Deacon , Vincenzo Frascino , Andrey Konovalov , Peter Collingbourne , Sasha Levin Subject: [PATCH 5.19 0153/1157] arm64: kasan: Revert "arm64: mte: reset the page tag in page->flags" Date: Mon, 15 Aug 2022 19:51:49 +0200 Message-Id: <20220815180445.783635938@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Catalin Marinas [ Upstream commit 20794545c14692094a882d2221c251c4573e6adf ] This reverts commit e5b8d9218951e59df986f627ec93569a0d22149b. Pages mapped in user-space with PROT_MTE have the allocation tags either zeroed or copied/restored to some user values. In order for the kernel to access such pages via page_address(), resetting the tag in page->flags was necessary. This tag resetting was deferred to set_pte_at() -> mte_sync_page_tags() but it can race with another CPU reading the flags (via page_to_virt()): P0 (mte_sync_page_tags): P1 (memcpy from virt_to_page): Rflags!=0xff Wflags=0xff DMB (doesn't help) Wtags=0 Rtags=0 // fault Since now the post_alloc_hook() function resets the page->flags tag when unpoisoning is skipped for user pages (including the __GFP_ZEROTAGS case), revert the arm64 commit calling page_kasan_tag_reset(). Signed-off-by: Catalin Marinas Cc: Will Deacon Cc: Vincenzo Frascino Cc: Andrey Konovalov Cc: Peter Collingbourne Reviewed-by: Vincenzo Frascino Acked-by: Andrey Konovalov Link: https://lore.kernel.org/r/20220610152141.2148929-5-catalin.marinas@arm.com Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/kernel/hibernate.c | 5 ----- arch/arm64/kernel/mte.c | 9 --------- arch/arm64/mm/copypage.c | 9 --------- arch/arm64/mm/mteswap.c | 9 --------- 4 files changed, 32 deletions(-) diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index 2e248342476e..af5df48ba915 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -300,11 +300,6 @@ static void swsusp_mte_restore_tags(void) unsigned long pfn = xa_state.xa_index; struct page *page = pfn_to_online_page(pfn); - /* - * It is not required to invoke page_kasan_tag_reset(page) - * at this point since the tags stored in page->flags are - * already restored. - */ mte_restore_page_tags(page_address(page), tags); mte_free_tag_storage(tags); diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index f6b00743c399..b2b730233274 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -48,15 +48,6 @@ static void mte_sync_page_tags(struct page *page, pte_t old_pte, if (!pte_is_tagged) return; - page_kasan_tag_reset(page); - /* - * We need smp_wmb() in between setting the flags and clearing the - * tags because if another thread reads page->flags and builds a - * tagged address out of it, there is an actual dependency to the - * memory access, but on the current thread we do not guarantee that - * the new page->flags are visible before the tags were updated. - */ - smp_wmb(); mte_clear_page_tags(page_address(page)); } diff --git a/arch/arm64/mm/copypage.c b/arch/arm64/mm/copypage.c index 0dea80bf6de4..24913271e898 100644 --- a/arch/arm64/mm/copypage.c +++ b/arch/arm64/mm/copypage.c @@ -23,15 +23,6 @@ void copy_highpage(struct page *to, struct page *from) if (system_supports_mte() && test_bit(PG_mte_tagged, &from->flags)) { set_bit(PG_mte_tagged, &to->flags); - page_kasan_tag_reset(to); - /* - * We need smp_wmb() in between setting the flags and clearing the - * tags because if another thread reads page->flags and builds a - * tagged address out of it, there is an actual dependency to the - * memory access, but on the current thread we do not guarantee that - * the new page->flags are visible before the tags were updated. - */ - smp_wmb(); mte_copy_page_tags(kto, kfrom); } } diff --git a/arch/arm64/mm/mteswap.c b/arch/arm64/mm/mteswap.c index a9e50e930484..4334dec93bd4 100644 --- a/arch/arm64/mm/mteswap.c +++ b/arch/arm64/mm/mteswap.c @@ -53,15 +53,6 @@ bool mte_restore_tags(swp_entry_t entry, struct page *page) if (!tags) return false; - page_kasan_tag_reset(page); - /* - * We need smp_wmb() in between setting the flags and clearing the - * tags because if another thread reads page->flags and builds a - * tagged address out of it, there is an actual dependency to the - * memory access, but on the current thread we do not guarantee that - * the new page->flags are visible before the tags were updated. - */ - smp_wmb(); mte_restore_page_tags(page_address(page), tags); return true; -- 2.35.1