From patchwork Tue May 23 00:43:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13251302 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 B4DF1C77B73 for ; Tue, 23 May 2023 00:43:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53594280002; Mon, 22 May 2023 20:43:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BE1F280001; Mon, 22 May 2023 20:43:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36046280002; Mon, 22 May 2023 20:43:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 21F6A280001 for ; Mon, 22 May 2023 20:43:26 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E3272140516 for ; Tue, 23 May 2023 00:43:25 +0000 (UTC) X-FDA: 80819671170.05.A1894AD Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf19.hostedemail.com (Postfix) with ESMTP id 1AFF41A0014 for ; Tue, 23 May 2023 00:43:23 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=XY4gva+E; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3KwxsZAMKCB4J66AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3KwxsZAMKCB4J66AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--pcc.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684802604; 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=EOtAXf5wuxpOrHzLJXv+xvDvcqfWad6caZwbz93V+KE=; b=DEFxQkwXoLhWwE8pVxBWbMlIT75gxxrobfbre4vUheZmJMswPz9HMnAl6nNDRR7cm4dk3T vOO3iEKd9P65gFmVSCzzk9A7ewefzwL52XzPVFL0svNbK2cDISYOuPOpdseXqK8zVWFkRY H8cfwHE6BnFKZQ98wf7Mpzt9S5IAOM4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=XY4gva+E; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3KwxsZAMKCB4J66AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3KwxsZAMKCB4J66AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--pcc.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684802604; a=rsa-sha256; cv=none; b=ERHQFFVIhW299AYz7EBtLsO/E6qDBO4G9jkSYJ4HZvLpF6b5O3T2i0uvJVbIZ7VmeQriyI hXYatKrXo2Nf54ElRaV1nnUmwktUsI7OzIAlRkcFnLEww5NSkQZDEF5I9BZiXGVPfZTB5n 3krtoOygSMfNJXk7V032S0ga7qcEHeg= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ba81b37d9d2so12214281276.3 for ; Mon, 22 May 2023 17:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684802603; x=1687394603; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EOtAXf5wuxpOrHzLJXv+xvDvcqfWad6caZwbz93V+KE=; b=XY4gva+EMnJWXF+00EDsdNDkxlpkR1226CoKPz6GQhTDY3567XIkv/ajSmvDAyOo+4 Jiou7Fwlc1Fc0otUxmqXU52VFuoJpP67ftFJSgZR71Nr4aEEjXMn3N70kQVwxP2IiBty Ft+9Kcmt21IpAznRpT2tBREMHZy8CkXxRpYN/nRYwK0AQffNTuo3WgTPGwyieVsopPY7 LfJwzSI9v2nyw2s5dDstd4fKEgqImzwUpT4HJZBRIW/+uH9pllKQq/N3OUcDKi+t/fWF afpbXeNQPvaPfbjUxLNGDhhVz87f6a1X4WkEQO6CvDL/WbTGb9WvwVqJATiDfSU5wg40 +GqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684802603; x=1687394603; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EOtAXf5wuxpOrHzLJXv+xvDvcqfWad6caZwbz93V+KE=; b=NyMz+UrLaYilj5ZNSQ1MNTlsvYwA+zME+GQ5FmQ5v5wuTqQOvLO2WzlBGGF6dx+oj8 OeLk8TcvEhqHflnFM8bVmpipRV+COz4+DDfqg84Hm9gOGKzoh9PKshSFwoUMV1shOJSu XHHhh2976VNfBOsuHdzZHpcX1Ehf0SVciJlwOX2muzku/GsU70Jzue1wI/lzX7ENKewA SVxFQ0da8bKc0hPa+tXFLaKyo1IjVE4YSUkHlwIKTkgCO5i7ScnQsAi+dOEM7otMnCUc luNB5Q388d/Cd1VC6HTxz/triol6gv328XL+BQBgSOc5PoQGMGjlvJrnLKF5pDEUU3w8 adOQ== X-Gm-Message-State: AC+VfDzvQ5odknBjNSEeTz0NUyS4SF+LEBRujTMSEul5BDtUrQF2YAwa wcEudjKqar+0NJHbxrWKKMyssLo= X-Google-Smtp-Source: ACHHUZ4LYT/h0488/LNagDCbE/4d9JbfsPfBfwGCaVQAcbHO+6coMUy+IC8/AtpQAjPzk27JRmlqI1E= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:3d33:90fe:6f02:afdd]) (user=pcc job=sendgmr) by 2002:a25:fe08:0:b0:ba7:8099:c5f2 with SMTP id k8-20020a25fe08000000b00ba78099c5f2mr5220235ybe.8.1684802603205; Mon, 22 May 2023 17:43:23 -0700 (PDT) Date: Mon, 22 May 2023 17:43:10 -0700 In-Reply-To: <20230523004312.1807357-1-pcc@google.com> Message-Id: <20230523004312.1807357-4-pcc@google.com> Mime-Version: 1.0 References: <20230523004312.1807357-1-pcc@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v4 3/3] arm64: mte: Simplify swap tag restoration logic From: Peter Collingbourne To: Catalin Marinas Cc: Peter Collingbourne , " =?utf-8?b?UXVuLXdlaSBMaW4gKA==?= =?utf-8?b?5p6X576k5bS0KQ==?= " , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "surenb@google.com" , "david@redhat.com" , " =?utf-8?b?Q2hpbndlbiBDaGFuZyAo?= =?utf-8?b?5by16Yym5paHKQ==?= " , "kasan-dev@googlegroups.com" , " =?utf-8?b?S3Vhbi1ZaW5nIExlZSAo5p2O5Yag56mOKQ==?= " , " =?utf-8?b?Q2FzcGVyIExpICjmnY7kuK3mpq4p?= " , "gregkh@linuxfoundation.org" , vincenzo.frascino@arm.com, Alexandru Elisei , will@kernel.org, eugenis@google.com, Steven Price X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 1AFF41A0014 X-Stat-Signature: 8gs4etom9qtt64xy71kqzbqgwi4sg9to X-Rspam-User: X-HE-Tag: 1684802603-469428 X-HE-Meta: U2FsdGVkX19ge15wlSz1LFH3xAVMxLM5/DcgAExBTFdvVsTIVGeDVPYxUXfZYUV8FV1fiWkp/lo/TOAd4gqfT+1PqaxmJcD2hlQS3KWf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N7kAGCwcQVfauMTf8Iu96zBwkm12EMjlJWypaf9fbrEMUQXV9ccfqrzf7r6J87TJLEJeFEv/sYv124FXzDhU3q12DlRJEEhqUf83Z8FnfgBTXfY+EhiEqvlZizbZaOnBd+8ddx9S9cxbY5zCorVJnM2dw6BTaMmOW1KcLZffZPVXUMhlx/lFCdUmz1II8y+76dG1hvpkGxAFyWlJwCXLKQ+e+XAReu8b0AMRnWXnLhsBDlF6JUCG4kOeOXa79FpwuPfO09TrW5w7g2jpHOAB7P4IPJ9EYXwPPMFbYph9pvrwonxwLjcpgm6vRJ7/B7r41I4b5VPA9VTTO1uIdDssEftb0RDOeSJPLBGvgf13+qHyeUXv49Qeh5EnqjHUdQEkXjgtj+/eePNheQ9W0ZTLWo6/jOETJZtkdESjemUbJW2Jjw5OQBTq6cnPe8SNsT3r5mi5riICZXNxYEzuXaTqkyAqimYlroxkQ5QxXp6ECY3kHgOto1N9dTSmhaUWP0ulvg+gEd0/jX8GxtyG4TiVDsjrcB8WTMiEI3UoEjEpr1yAm4E3+TgqA== 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: As a result of the previous two patches, there are no circumstances in which a swapped-in page is installed in a page table without first having arch_swap_restore() called on it. Therefore, we no longer need the logic in set_pte_at() that restores the tags, so remove it. Signed-off-by: Peter Collingbourne Link: https://linux-review.googlesource.com/id/I8ad54476f3b2d0144ccd8ce0c1d7a2963e5ff6f3 Reviewed-by: Steven Price Reviewed-by: Catalin Marinas --- v4: - Rebased onto v6.4-rc3 - Reverted change to arch/arm64/mm/mteswap.c; this change was not valid because swapcache pages can have arch_swap_restore() called on them multiple times v3: - Rebased onto arm64/for-next/fixes, which already has a fix for the issue previously tagged, therefore removed Fixes: tag arch/arm64/include/asm/mte.h | 4 ++-- arch/arm64/include/asm/pgtable.h | 14 ++---------- arch/arm64/kernel/mte.c | 37 ++++++-------------------------- 3 files changed, 11 insertions(+), 44 deletions(-) diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h index c028afb1cd0b..4cedbaa16f41 100644 --- a/arch/arm64/include/asm/mte.h +++ b/arch/arm64/include/asm/mte.h @@ -90,7 +90,7 @@ static inline bool try_page_mte_tagging(struct page *page) } void mte_zero_clear_page_tags(void *addr); -void mte_sync_tags(pte_t old_pte, pte_t pte); +void mte_sync_tags(pte_t pte); void mte_copy_page_tags(void *kto, const void *kfrom); void mte_thread_init_user(void); void mte_thread_switch(struct task_struct *next); @@ -122,7 +122,7 @@ static inline bool try_page_mte_tagging(struct page *page) static inline void mte_zero_clear_page_tags(void *addr) { } -static inline void mte_sync_tags(pte_t old_pte, pte_t pte) +static inline void mte_sync_tags(pte_t pte) { } static inline void mte_copy_page_tags(void *kto, const void *kfrom) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 0bd18de9fd97..e8a252e62b12 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -337,18 +337,8 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr, * don't expose tags (instruction fetches don't check tags). */ if (system_supports_mte() && pte_access_permitted(pte, false) && - !pte_special(pte)) { - pte_t old_pte = READ_ONCE(*ptep); - /* - * We only need to synchronise if the new PTE has tags enabled - * or if swapping in (in which case another mapping may have - * set tags in the past even if this PTE isn't tagged). - * (!pte_none() && !pte_present()) is an open coded version of - * is_swap_pte() - */ - if (pte_tagged(pte) || (!pte_none(old_pte) && !pte_present(old_pte))) - mte_sync_tags(old_pte, pte); - } + !pte_special(pte) && pte_tagged(pte)) + mte_sync_tags(pte); __check_safe_pte_update(mm, ptep, pte); diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 7e89968bd282..c40728046fed 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -35,41 +35,18 @@ DEFINE_STATIC_KEY_FALSE(mte_async_or_asymm_mode); EXPORT_SYMBOL_GPL(mte_async_or_asymm_mode); #endif -static void mte_sync_page_tags(struct page *page, pte_t old_pte, - bool check_swap, bool pte_is_tagged) -{ - if (check_swap && is_swap_pte(old_pte)) { - swp_entry_t entry = pte_to_swp_entry(old_pte); - - if (!non_swap_entry(entry)) - mte_restore_tags(entry, page); - } - - if (!pte_is_tagged) - return; - - if (try_page_mte_tagging(page)) { - mte_clear_page_tags(page_address(page)); - set_page_mte_tagged(page); - } -} - -void mte_sync_tags(pte_t old_pte, pte_t pte) +void mte_sync_tags(pte_t pte) { struct page *page = pte_page(pte); long i, nr_pages = compound_nr(page); - bool check_swap = nr_pages == 1; - bool pte_is_tagged = pte_tagged(pte); - - /* Early out if there's nothing to do */ - if (!check_swap && !pte_is_tagged) - return; /* if PG_mte_tagged is set, tags have already been initialised */ - for (i = 0; i < nr_pages; i++, page++) - if (!page_mte_tagged(page)) - mte_sync_page_tags(page, old_pte, check_swap, - pte_is_tagged); + for (i = 0; i < nr_pages; i++, page++) { + if (try_page_mte_tagging(page)) { + mte_clear_page_tags(page_address(page)); + set_page_mte_tagged(page); + } + } /* ensure the tags are visible before the PTE is set */ smp_wmb();