From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC77BC43334 for ; Thu, 16 Jun 2022 08:44:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76AD96B0073; Thu, 16 Jun 2022 04:44:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F3886B0074; Thu, 16 Jun 2022 04:44:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56DBF6B0075; Thu, 16 Jun 2022 04:44:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 44D446B0073 for ; Thu, 16 Jun 2022 04:44:31 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 20823615BF for ; Thu, 16 Jun 2022 08:44:31 +0000 (UTC) X-FDA: 79583462742.27.DBB51F2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf05.hostedemail.com (Postfix) with ESMTP id B3A3B10008C for ; Thu, 16 Jun 2022 08:44:28 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4127D13D5; Thu, 16 Jun 2022 01:44:28 -0700 (PDT) Received: from [10.57.69.164] (unknown [10.57.69.164]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8B02C3F7F5; Thu, 16 Jun 2022 01:44:26 -0700 (PDT) Message-ID: <266cb1c3-6167-8be2-57cf-4f6cf15ae7d1@arm.com> Date: Thu, 16 Jun 2022 09:44:24 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH v2 4/4] arm64: kasan: Revert "arm64: mte: reset the page tag in page->flags" Content-Language: en-US To: Catalin Marinas , Andrey Ryabinin , Andrey Konovalov Cc: Will Deacon , Peter Collingbourne , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org References: <20220610152141.2148929-1-catalin.marinas@arm.com> <20220610152141.2148929-5-catalin.marinas@arm.com> From: Vincenzo Frascino In-Reply-To: <20220610152141.2148929-5-catalin.marinas@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655369068; a=rsa-sha256; cv=none; b=Ix4cUDveXXZmkMhSng5f/q8zhqrQ8lCWmVMkhr6w0U6cvRBR7AKjIptDBGUM0g357fzyRI PvIkaMZdzluaMTFsYqYkRXDwyj9fCyyU3PdAAwWjsonzOOQ6/sE8cO+ekgASItRjrflN4S YjVxEjfaxYItBn3Xv1yQ6WZoG5BKxks= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of vincenzo.frascino@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=vincenzo.frascino@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655369068; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zGFzUSVc3OuXIfFjyLXIuVxInYV1frPtWAMf8rzZYgo=; b=nr82Ne/ka7D3uFSIgfSNhv0HNxdWBdS8neZ5FDhN128U19wfqpYnTpZntvWe90f3IPXUmZ VYE8pPxOW83l98EKe0jC7TH02lDAvGwy23wipoqQMUD3quTZlVORjSzAx7sZPCsV4J4JV8 6pMn5h1Q8anA420zAVGq6OliK1BAvZw= X-Stat-Signature: fzrcqfkrws1nnygeyqn4kiyhmmdnfuit X-Rspamd-Queue-Id: B3A3B10008C Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of vincenzo.frascino@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=vincenzo.frascino@arm.com; dmarc=pass (policy=none) header.from=arm.com X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1655369068-528827 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 6/10/22 16:21, Catalin Marinas wrote: > 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 > --- > 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 57b30bcf9f21..7ba4d6fd1f72 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; -- Regards, Vincenzo