Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2894724rwb; Mon, 15 Aug 2022 13:30:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Z654YiZjq2ZINLYhUHk3ULgucDHo+KFmQWmw7/v1sR5AWF89VqZEmEj4H9trXcSjc3PXc X-Received: by 2002:a17:907:2719:b0:730:a5e7:9da7 with SMTP id w25-20020a170907271900b00730a5e79da7mr11780263ejk.26.1660595421728; Mon, 15 Aug 2022 13:30:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660595421; cv=none; d=google.com; s=arc-20160816; b=mtNsCRLRvBR8smz0zXtv4IAshbqrKs7IcqN3e1oMGriZ6ZbxLLdvE7LXXKodxY+f4v 1tR1SN+a2w8H3Pjw3jwXpUlKSTUpdBD8XpusTS9hWQf5F2ccmaOIeX5TaTRxLXR7r/bH o4znvD6dTW6auaJAmrGnkQkln3HZojn8KBaZT4bkYOd5yMClvnipaFDdyo4fvdoP8Lh+ Tdvhrq3BAfXpFfKPqwqs6ZR/AvbPeTNsb/TWSq4IqLSnjZQDR5+IqJYomNOZK3Dd3Zbw Q7UP2vtAor3bs3qNezPXc6lD4p92P0enBUWUg1e+g4v7SVPEZ8VpmrM7mV4JzaIatm98 RYHg== 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=CoBb6j1X0XubWePvZDFmLWzwD999yN/MmYOQQVvooXA=; b=H8Ucq9R1avba8e1/2hGM8zPVf5vP6RwopQDaRlKyztJj43DaeuoGthDEB0kUTnLW5+ Luk86NuXK74FsDMlKWXzniSVos5WeB3JIgEKLAYO5pSYIDyEoYsyOc/F+uDqKyp8cSuj JHh47Uy4OpjnnnZb4UMl94gUJK2SM+VSrq77lwk1SKsEVQsd0fKc0VP7m7m2tKGlAoQR 4ojYiEx9AF9ywMoc/VfUh1kl/4WQ3HqnMdfd5o6JqQSdfs6K/refMNZ9R32bnBN3rxtw K5F1TGqDw2enpWtYAwtRHh9BDqWOlJerqLAokM4W1ETJL41zr2d+SeMhgedG6uXop+dV 4VSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=We8ukadP; 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 f12-20020aa7d84c000000b0043cb2fabd05si7404810eds.326.2022.08.15.13.29.50; Mon, 15 Aug 2022 13:30:21 -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=We8ukadP; 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 S1347249AbiHOU1U (ORCPT + 99 others); Mon, 15 Aug 2022 16:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346913AbiHOUVe (ORCPT ); Mon, 15 Aug 2022 16:21:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C268698C83; Mon, 15 Aug 2022 12:01:02 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 1720E61281; Mon, 15 Aug 2022 19:01:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C3F0C433D6; Mon, 15 Aug 2022 19:01:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590061; bh=vNUtB1P/IFS9iU1uA3u5SiDX2rmwure8KH5yPxre4No=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=We8ukadPaZi7gPRa2aIsi2l2rQ63WK9yS67nqCHdoaqz/60uwQ+DAgqASeckAg20v I5+KbxgIqfH//62dI0dO8PD0ziqHNnko+AWHhTaXGp9ICBQHABN6KZ3bkIZ/HJzsa0 DZQQr1/sC/0YJwg6ueNvIbXZvjhLA0o0HWhPb4Dk= 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.18 0139/1095] arm64: kasan: Revert "arm64: mte: reset the page tag in page->flags" Date: Mon, 15 Aug 2022 19:52:18 +0200 Message-Id: <20220815180435.331228321@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 6328308be272..7754ef328657 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 d502703e8373..d565ae25e48f 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -47,15 +47,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