Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3657437rwd; Mon, 22 May 2023 18:12:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6uQ8sTHLU/ZhcmQ3dYEHmniZQEBYq7DV/NMdOV0T/BgbZ51BR8F+q3bT4aHxc9gOeuyRJw X-Received: by 2002:a17:902:d382:b0:1ae:3991:e4f9 with SMTP id e2-20020a170902d38200b001ae3991e4f9mr12221346pld.61.1684804320959; Mon, 22 May 2023 18:12:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684804320; cv=none; d=google.com; s=arc-20160816; b=Aw2n1JU5PCcmeJ7ifCEFmXkhaTLb/28HfFXhBkY9rLyaJTDFuy15FFxWg8Tpqy+ESH dE6pbhKq1kb9O0kupg/p8eFfmgg6qxaLVLzbQz9RdLa/ed6/qP4Qu/pffJshaA85fmrQ nuUGPN2t+0edWCb6g3KMX1Tqn+gdAGEilhh+cw8ZJp7ZMM6kdv/Zcgf6+3FXJFqlbv8Z 0/7U0fEMeT94Ck2S//wUACZc2pCFuepHobhKSXC6rZh+dXsci3ImLaRQZ5fpxE3Y+PGm rSqQawcQo5V6XJ7DB1qG1x4MGFRzuEdQIYRuzH6mGa+jue68yTtFVvI43OXxeYuciPvI Sl3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=EOtAXf5wuxpOrHzLJXv+xvDvcqfWad6caZwbz93V+KE=; b=g8XxeMt7XjIxI5w3aRdwkBdf/j5OwkbGNqbd2VBLAuwpq247ocLYUO498NOrDjhKe0 2MNMnHsPYrdepXoV06IzP05+VQ8spKq5grCS4mVuxfG7ElQJm2x00/7IUjX5sabl85RR R+UUZXmQyNKlGeVS1PiRfj+j7hlYFq9i/TOy3NsJYIOzRum/RjBG8Y4oqak5w3NSMncX i7qUeK66rG9YIu/IOpOozq5aeiVPRmUNlwTva+GE8i394iuK1fC940VW/waGzbLjlPws Vppx7ENqm5gbrEneCCuACFKKBu11mrsXWHyiROsr1e8ZzZZatSYxkiyBH0dHmN3/w8NB zX6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=XY4gva+E; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p10-20020a170902eaca00b001adbfba9c29si5202202pld.409.2023.05.22.18.11.45; Mon, 22 May 2023 18:12:00 -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=@google.com header.s=20221208 header.b=XY4gva+E; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234943AbjEWAwI (ORCPT + 99 others); Mon, 22 May 2023 20:52:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234913AbjEWAvq (ORCPT ); Mon, 22 May 2023 20:51:46 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CEEB59C3 for ; Mon, 22 May 2023 17:45:06 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8b0fc0d35so9302004276.0 for ; Mon, 22 May 2023 17:45:06 -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=F2y1SnjQ/eONi2+6vNcXun0zVRGt6pL1cnJxClNL4p4kXKKHsVmr9ThMcW3iKgqhhW Q+m28IaEjZlwzzdOwprco8WiPhyTTW/zZfVGd6GCNgeXWBkWbqHmPI6aP1W7ByXREkYX lsPW2PeccxBDyvApL0AYzLWikfR3J3/ZdvjL3MoMeyGMa/6YPYfxBRq5Yf36+kcoA5BR ig7dwqOn3FCwJc5HHdTaSVlP9QUgcW4prh0tZu1ukRYb07eREt+ZZKhWaZ3kG8wsPCAa DmVuu3OCD2Kk3dofH3lBif8JhvrDQU5HRphIXH5vyN7xZJysvBuj83mS1JeQvj+CCHUr RP1w== X-Gm-Message-State: AC+VfDyP6U8Zkso2ymJzu9MSTrMz6DkLruArpkqSrzOBjfhHKMwOH4aQ m1FBGqGLb+2gBBR360j2UEQyfD4= 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?q?Qun-wei=20Lin=20=28=E6=9E=97=E7=BE=A4=E5=B4=B4=29?=" , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "surenb@google.com" , "david@redhat.com" , "=?UTF-8?q?Chinwen=20Chang=20=28=E5=BC=B5=E9=8C=A6=E6=96=87=29?=" , "kasan-dev@googlegroups.com" , "=?UTF-8?q?Kuan-Ying=20Lee=20=28=E6=9D=8E=E5=86=A0=E7=A9=8E=29?=" , "=?UTF-8?q?Casper=20Li=20=28=E6=9D=8E=E4=B8=AD=E6=A6=AE=29?=" , "gregkh@linuxfoundation.org" , vincenzo.frascino@arm.com, Alexandru Elisei , will@kernel.org, eugenis@google.com, Steven Price Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL 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 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(); -- 2.40.1.698.g37aff9b760-goog