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 01A83C433EF for ; Sat, 11 Jun 2022 19:40:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85DD18D011C; Sat, 11 Jun 2022 15:40:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 80D678D0115; Sat, 11 Jun 2022 15:40:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AEEE8D011C; Sat, 11 Jun 2022 15:40:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5A47A8D0115 for ; Sat, 11 Jun 2022 15:40:33 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 227F75BF for ; Sat, 11 Jun 2022 19:40:33 +0000 (UTC) X-FDA: 79566971946.28.A1927E6 Received: from mail-il1-f175.google.com (mail-il1-f175.google.com [209.85.166.175]) by imf27.hostedemail.com (Postfix) with ESMTP id B3A1B40084 for ; Sat, 11 Jun 2022 19:40:32 +0000 (UTC) Received: by mail-il1-f175.google.com with SMTP id s1so1668985ilj.0 for ; Sat, 11 Jun 2022 12:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=D/iWT1ffpAiqKeZEKWNPE0TbgJINcSFHsUDvoFFTC2Q=; b=H3jVLSQg8MaYawoukDO/3dOGdbmK8rp0BLdKQjJkIFb7hst9B2tWyiBGMWQuenduGU KyAYRmQ0MbmOriuYdbQQofvRHfBa0ECHOG/QoxeZVy/NjJmC2zcYSRjX7q5ZwtRDovgG jhE9K8SCyr7gZpCp/Dsl0DeouwX1gQK/vb+IpD69Nu7q4QSZXKI/uiFyIKav8n83BTwi aswTZJFzlUjV+Gdidzp3dgZg1fEDzQv8e3ZjPA1qBqVCQOo7XcMtjqsXHQV2fAUuitOw Vzqf9+Zuq2xlGIOxY2oTFeyNfWhKHPaGSh+Yx01c+E0fOH6BbB6K1F5zsyNJ50O1/m7v bh+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=D/iWT1ffpAiqKeZEKWNPE0TbgJINcSFHsUDvoFFTC2Q=; b=vCsPW47yJa8/ttfwK2/3Xr5U3CtjRDfDyg7XazYuD9taTfthGHyfQ1Gr3Pyf0HnKvj Ki5HNBY9yrr3Q+UtlII9zdXGr2xelxVywaDygxIUCoNQ9LbRxzCJY5J+qK1WoMEkB45L MbAchcZXimizLrY0KnrGvHRk7FytJa1Owqg0CwnXUNJuEYfPFWj8Bd1eEKq6gzGiDMrX QT56hXOrqXZ0onvoIwZKEwpnLIkkm43tYIeqvndnyevwWd01K/MdjUYxa9pIEAW8ooiI RBaVPccpugm4mjVw3+AzcuYVJmoem1nakznZPqeAxP74cd2153COlpC+trdY9SsEW5eM Twpw== X-Gm-Message-State: AOAM531jijZh57OCsWe2zAy9yzU15RSK+y3B2+6QKthhpyjxtvCq/E4N GHQg+6egUwsp1ccDlab24OREdWQE9A+yZ/8p+KU= X-Google-Smtp-Source: ABdhPJzArXxVZJAYT9XpIxvTkuBrqcDdJYVFpWnkuItpWI2lfIbrfsQZ2cZV5TAGUj4Y2HGYp0f9YjSUlPZ6ATMnu6c= X-Received: by 2002:a05:6e02:1c2a:b0:2d1:9e4c:203d with SMTP id m10-20020a056e021c2a00b002d19e4c203dmr27203069ilh.235.1654976432141; Sat, 11 Jun 2022 12:40:32 -0700 (PDT) MIME-Version: 1.0 References: <20220610152141.2148929-1-catalin.marinas@arm.com> <20220610152141.2148929-5-catalin.marinas@arm.com> In-Reply-To: <20220610152141.2148929-5-catalin.marinas@arm.com> From: Andrey Konovalov Date: Sat, 11 Jun 2022 21:40:21 +0200 Message-ID: Subject: Re: [PATCH v2 4/4] arm64: kasan: Revert "arm64: mte: reset the page tag in page->flags" To: Catalin Marinas Cc: Andrey Ryabinin , Will Deacon , Vincenzo Frascino , Peter Collingbourne , kasan-dev , Linux Memory Management List , Linux ARM Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654976432; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=D/iWT1ffpAiqKeZEKWNPE0TbgJINcSFHsUDvoFFTC2Q=; b=ekGOPE/C5vER+PM4gVpE5LZqVsq/3MBvVeSJZ8xyv0xqt0z16XzZ+kfiLKIUqwJ7M2YAL8 98kipl1iiOwUho30I2rW0J/Ax+gwDpm6bm19KrwCh4f5N4ywcGQLhKI2TIhUHFm0o5wkIL R9rEYe7IIzSA4h0q39JfxXojQtasDPM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654976432; a=rsa-sha256; cv=none; b=Xmm+/YHwIt2jvqgDiGr55/CDenXD0B7Moth3DsTVi7T4bFbR5ARrsTFkTp7Tjj9nQIoKZM 1t50bbSfqt9lN8vZK9/+PI2ZDBc4oLfW63W1sqSV5kv/wFosG72VIKqJrtcOa10udT+GxT QjWmU/LLARbf2lLkRH2bMS7DoYk1gSc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=H3jVLSQg; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.166.175 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=H3jVLSQg; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.166.175 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com X-Rspamd-Server: rspam08 X-Rspam-User: X-Stat-Signature: qw8umynfhqgbrjjk6zgcumfxpg3k7mu3 X-Rspamd-Queue-Id: B3A1B40084 X-HE-Tag: 1654976432-587241 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 Fri, Jun 10, 2022 at 5:21 PM 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 > --- > 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; Acked-by: Andrey Konovalov