From patchwork Wed May 17 02:21:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13244071 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 1204BC7EE2C for ; Wed, 17 May 2023 02:21:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8476F900003; Tue, 16 May 2023 22:21:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F7B7280001; Tue, 16 May 2023 22:21:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67292900005; Tue, 16 May 2023 22:21:28 -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 56E1F900003 for ; Tue, 16 May 2023 22:21:28 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2F9FC1603A9 for ; Wed, 17 May 2023 02:21:28 +0000 (UTC) X-FDA: 80798145456.08.043C5DB Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf25.hostedemail.com (Postfix) with ESMTP id 60BDCA000C for ; Wed, 17 May 2023 02:21:26 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="kU3u/jVP"; spf=pass (imf25.hostedemail.com: domain of 3JTpkZAMKCFQByy2AA270.yA8749GJ-886Hwy6.AD2@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3JTpkZAMKCFQByy2AA270.yA8749GJ-886Hwy6.AD2@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684290086; 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:dkim-signature; bh=icy+EhZ3UBgzX+LkBKZmwy9I7D5yLVOL3MyBuUnW0II=; b=qe1BrUuYrZ0FXshJTeE51rtdD2tf3zcZPihQ1OmQVw0YujrPOttMGK9DA/E8/80sjwcw/T QxWkSAtCRwGkx2IZkgMwEexcL5RqBLApNK6sXT96CCbL7f2rye8PDb9rNSMiUL45AbxHMP rW4XrNykEg8Ew1ykUS1xUD6ijxvP5Sc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684290086; a=rsa-sha256; cv=none; b=nXYzLot/T53Z6MUcOc/dZfdm4XE+pgY3T6toXiQz4aotTmTapEJp+5ypJOHtCl70toJ/Gu IxV1Kp846R2peDtU9U0aVXah00zV3dRUD0qPV7WIOmdGVMmx7gzWM6NfhAy2koI/zatXwU VT1G7XXn4lWr83gXTnUhLabaZA9BcSs= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="kU3u/jVP"; spf=pass (imf25.hostedemail.com: domain of 3JTpkZAMKCFQByy2AA270.yA8749GJ-886Hwy6.AD2@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3JTpkZAMKCFQByy2AA270.yA8749GJ-886Hwy6.AD2@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ba718f5cd50so252323276.0 for ; Tue, 16 May 2023 19:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684290085; x=1686882085; h=content-transfer-encoding:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:from:to:cc:subject:date :message-id:reply-to; bh=icy+EhZ3UBgzX+LkBKZmwy9I7D5yLVOL3MyBuUnW0II=; b=kU3u/jVPNbJOPkDSOv1M9xE9gA7eqoTFhSdZQD4qt7SNgcYJYLu77i/2peyYkaoM+E 1CklaeTAYSmTwv8Km5dGKi7C0WCfutgqDI2sGNHRkPp+sdYNdJ963Ikhl8N6lfTWY03r Jc0A1tNgoUDHR5FiwBDbsHV8XCGmQ1kAqZSfPSuC5DautA1wUknPrMKD4FBEPRXJM1cI zDV47+hqam9u7nttpZOONvGIAgOZpyS9w/3N1M0W8GoFsxZc0Tu51VmRu5U30nbsUdLv KRfdPlHe57ebRvFOgibo1B8s53lcdE03PGn3ebRw8zfKd/8XLAR3q4VID38yQeldPd39 cHzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684290085; x=1686882085; h=content-transfer-encoding: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=icy+EhZ3UBgzX+LkBKZmwy9I7D5yLVOL3MyBuUnW0II=; b=DcvakaD+5bTJ7J2CD6OV8pmtVAjTfV81S4lP2DWKhUB4WOSVZTSSMLsl65Ph8DVrd7 N4NE67JN9l2YLAoykU1SprgoQW40uUGpAnba5Koj2EfhaytK1VuGLasoyHvwdsnLEbHn uCDiEYi7h3t2Yq90JlUxGVdGfpGFiZ27PLd9SuSQxIdPY9/hVZi1CH0yYez6aWy+HFFa d/kN/OzQA8VVsST5Od9jnUsWJqCRKx2xYm1jXORvYnqVLFVaQVPzFlSuhRteq0cqtcjJ aKStveafVCSKkllapoA8Ql+RnsazuMzfIBla/N/9E0YJzJSR65EsN0YDlFkJ5zMdwFK7 aY7w== X-Gm-Message-State: AC+VfDwjYOSvcqamnDxu4Zu6RJ0trhXdwRE8tqge7Htd8pJIF9OTriCZ Notz+muZMF+pLS/8tJGAdZR3yZk= X-Google-Smtp-Source: ACHHUZ6HltqTMi815u6+g2acsl5ZG5UZd+Y+2Rbyffv/trwosDfbc8rLxY0NJ38GbW8keQ8pFoFL1ds= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:b3a7:7c59:b96b:adaa]) (user=pcc job=sendgmr) by 2002:a5b:309:0:b0:ba6:a54d:1cae with SMTP id j9-20020a5b0309000000b00ba6a54d1caemr8869621ybp.0.1684290085477; Tue, 16 May 2023 19:21:25 -0700 (PDT) Date: Tue, 16 May 2023 19:21:11 -0700 In-Reply-To: <20230517022115.3033604-1-pcc@google.com> Message-Id: <20230517022115.3033604-2-pcc@google.com> Mime-Version: 1.0 References: <20230517022115.3033604-1-pcc@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v3 1/3] mm: Call arch_swap_restore() from do_swap_page() 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 , stable@vger.kernel.org X-Stat-Signature: p3syt7kxshrfn7w4mrd57xtu3cu6hok8 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 60BDCA000C X-HE-Tag: 1684290086-704434 X-HE-Meta: U2FsdGVkX19xyak4fHFQ0Nr98PWzG+kZoge7ewSPTC7HH6w1UnX2vUe1QSkJ8mEqyuOzV0LwWm7Ut9W9Cm1aMmOb/uD2f3jJQvSXSgS+Owm0Dx1pmVueWinthZG+l+0nH027CrhU5TfdHeRDHZVkidDBA+eOdiHBQwK3MioHb5eIHLqAT5iW28svIRmNwj79dWGir3PdvsyNKax2lNoA3WQe0L5jmNmxihsMWxIo71ho1mNziURLu1vY3FEXAfARf0szTxLmLlXFGE3bcyhmSbYAEXkfN0WENyNOPSFZ6aN77SaPBaNtrzLTztvJfLXjIHEP+fTzfhCJgVUIW4OgkGI1s0lB4CLxvg3tIM7AHG3m3usHWSaQf4/K6N9CnlESD7yE6g1isDUAQYORRL1gocUlwW5Z/x2D12NKpykOJfVo5EGSyw2UlgiPcesdR/Ntjb1rCtwyxy0KRf4ygIuzWbBeHnn9/t8KagVXeJZsUnU9TKPX8lPE4EsoQIIRKC0nooqX3Q4AQZQuRsEf7cXIdRG7z01CbcPopwSl7uZmUSPOlfQmD+KatUzA4SuTrql+9vCpWur7a994vO8cD8iWwftyRXHKxhnRyK5IZ1UpOP6O3MtlPA5J/1DA7q4WjyCmoZbmeZlow4k1XZO6mXoRKExiqmpDgMq2fWV+BRgPHps4xhcjKQbbjEdV7wthkQftdaPV6a+OANpJ7Adk3/oTObdHPX5OjYQ40S4eMHeQrpaSetW2e+IIwMRWEUyWIB7/Ldf9e7PjhfoglAsWa++YT3Tosk+mWeUy+anaDERPicPbtgCRBZp5I8ucq8azFTLbS/gssjQJZ5ywyFcCJ1YslNxzaafRKRYCuVtJWN5cRaQ+GhEig0L1GBch+gVz77K5NQtPMExszbzFed7dr2/EFNavbGZx/RIYQbO80FxnlbTzcM6EEUq4Komb/E+qja6ajtRqOEH8dRqhZJ9dLRl +hLBxCfP Wd85NBDDC8Ev6lQ0nFY8TVV12zxPNZc/GFJiOQqbMnBKNFE3L4Fd7Gd99uPt2dIv8D5vUFbD6fOtpEHfjDhhbH7kJtON0YFMkvezYmDU9Ugljl1iwTbtVdYKTcQAbSzeqm8z1PzCCFqai6E63SVlUgCOc1kzelquL/aHR1Rr/VKlkOzOsgVuA2JSiTnxtwzPGsM8c6vm/yhWInzglZfaQRaXyjz6f94rhXycys2qgXPzgmAoWYlxVssyGMnlMLr+la7EEeQkSdDpnt2tinc8LrzVEDAc4BpuZVz9Q2BDZlX9tLhEq6B2VpfoGFLifv8E6zXSB19Lc87Hx57fza0watam2rFqYylZBI25zIAic7pMDvdAYUkOrLnsKU36M0CXjjjRrolZFyzIfoedscouPaW7XODg1eZx0FwVXP6kNR8K4y3Prd08Rl8rA0p31wr0/6WWlGmmwFh1DldVeDe3sZ0elhbznQ2VioEZAfVN61Rk7eqlg58EroKowzKu1hmlu6sxLYWnmevMog+UcexCdSXvc3ldfZP+OI8mDxU/8iKpqZm+cburS3tarm8lSLFXumldivzC/kdmIKeZ670QH1ekvKCjlIB5bQUia7Cw8MriKGF3MbQlaRly/e+vsYBPD+CUiX40/c3o2UDRjx+fU3hdWQNuA8xHca/p17BXsD7dPfK611jcqdHOKLM6NAYD+IgkQpjSWHGJdGXEwtgUM7t0kiEkj9YXl/OngYMRSDpwz6XgedeL6HufBBDmyuOeyuS0716rIp4LVlvF7+Oi/skJq76OrCeYAbuZJMoZLi/zDQtTSkSLPRfC1337ZyWn8f9kJMQUTwn8Qprr8xFI7ELKOwTdtjn/yFv4t 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: Commit c145e0b47c77 ("mm: streamline COW logic in do_swap_page()") moved the call to swap_free() before the call to set_pte_at(), which meant that the MTE tags could end up being freed before set_pte_at() had a chance to restore them. Fix it by adding a call to the arch_swap_restore() hook before the call to swap_free(). Signed-off-by: Peter Collingbourne Link: https://linux-review.googlesource.com/id/I6470efa669e8bd2f841049b8c61020c510678965 Cc: # 6.1 Fixes: c145e0b47c77 ("mm: streamline COW logic in do_swap_page()") Reported-by: Qun-wei Lin (林群崴) Closes: https://lore.kernel.org/all/5050805753ac469e8d727c797c2218a9d780d434.camel@mediatek.com/ Acked-by: "Huang, Ying" Acked-by: David Hildenbrand Reviewed-by: Steven Price Acked-by: Catalin Marinas --- v2: - Call arch_swap_restore() directly instead of via arch_do_swap_page() mm/memory.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index f69fbc251198..fc25764016b3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3932,6 +3932,13 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) } } + /* + * Some architectures may have to restore extra metadata to the page + * when reading from swap. This metadata may be indexed by swap entry + * so this must be called before swap_free(). + */ + arch_swap_restore(entry, folio); + /* * Remove the swap entry and conditionally try to free up the swapcache. * We're already holding a reference on the page but haven't mapped it From patchwork Wed May 17 02:21:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13244072 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 7CBDBC7EE24 for ; Wed, 17 May 2023 02:21:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED70B280002; Tue, 16 May 2023 22:21:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E6188280001; Tue, 16 May 2023 22:21:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB31A280002; Tue, 16 May 2023 22:21:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BBA0B280001 for ; Tue, 16 May 2023 22:21:30 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 736C740444 for ; Wed, 17 May 2023 02:21:30 +0000 (UTC) X-FDA: 80798145540.30.5A803C9 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf11.hostedemail.com (Postfix) with ESMTP id 97B7C4000F for ; Wed, 17 May 2023 02:21:28 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=pXVJppsk; spf=pass (imf11.hostedemail.com: domain of 3JzpkZAMKCFYD004CC492.0CA96BIL-AA8Jy08.CF4@flex--pcc.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3JzpkZAMKCFYD004CC492.0CA96BIL-AA8Jy08.CF4@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684290088; 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=DmZ7qJu2QJbmubDEgRMJhswdry7Qhukww11ZPOJRgvs=; b=Jh7Cy4GvRW+jGbttzfJ0bocF1xujNusGoP5wGPmeBhrKx28YC3LmTrx5dBABlfuDaUhMDc ycATNC9JydTA1ht54rCxuG7nzy8ih671Yvuz6yi8C4aGDq92HrX/mgMmyoZYBPPnFNg8cq NlVM/GQb89en5qnRsVDv2gn+mKLJHOw= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=pXVJppsk; spf=pass (imf11.hostedemail.com: domain of 3JzpkZAMKCFYD004CC492.0CA96BIL-AA8Jy08.CF4@flex--pcc.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3JzpkZAMKCFYD004CC492.0CA96BIL-AA8Jy08.CF4@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684290088; a=rsa-sha256; cv=none; b=aCJEXul4wgmsjtanra9pNlQKMe95NRoeSAa9hKTR9/hWeoW+//h/Yz17YJNSLyXzM8fqnT Op+TH6+hJ2NHLyxvv/OL5yhs9UFoOgxWbUJDaDxnc5J0WunmVC5azUCMAQ3suGgJkQmmCg QkWP7++3NLYDMwh+ufnUmjHkA9DRvV0= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-ba237aec108so144253276.3 for ; Tue, 16 May 2023 19:21:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684290087; x=1686882087; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DmZ7qJu2QJbmubDEgRMJhswdry7Qhukww11ZPOJRgvs=; b=pXVJppsksfHh4I2n3d8xVcufhKZZlJjnCny+rmQ4mjQKI0AW/cCK2hASK83KfSiYpL SwH5TVvYpvNqffEsNvDPgC+nhgLYFM3KaqHCuYbPaIFzls2lqfx0JYU50+6NVWzrME9W 1mfRz5hwNYEvKHUFnlT4dknNheNNzedfdZLSkBZlu7QlWmiIOdq/l+RcVRDobfHZBP0c 7otPYVh11OT4odfN5rNmMB6Xfe/sUmOnKNfozY8i+NNWwTSKo6jWbGtluyHsGeqrt/Um gaSjHg7Sh7LXhrO/UUQMLAjulMUlLvxOhNHHmrBn6+ZKABwqhlZs4QhdwbdE4TaSFaoL o8HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684290087; x=1686882087; 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=DmZ7qJu2QJbmubDEgRMJhswdry7Qhukww11ZPOJRgvs=; b=kcyAhGTgTNKleFXhSzgvXeVFWPZef3mnuRnpdELrBkSxhMfNldRUnv6GrEI0jcJvDE OUmS5KXhqHzgGK1l7A+puTbmy797Bf4F1SpiB4A9Yjoh5t6dAYVkqC/VRo1eAff+bmtS PTOOzvYLx7qhiCDo/UlTWGBLH+7AlN3MZqSjEqS7mutZ6Pl80eMpUvudtFUe+MAMo+cO w6H4dQYHZEHBRNkAAH8BGhXoC3ieOghGDj76Euw3ZVO6McAW68TZiDlIh1iUXvrfK5Qs jfY2rIyC28b0X2VuaStnncxfr4g4qWFlAgEtkYH5WlkGVD2Nzx79MPFrHUL5h3OlD5TO bsOA== X-Gm-Message-State: AC+VfDyrGipX8qs8xljJ+CJkL+KEYGoXbXxecqoPa7ZoNO1AHdZT2ysV WgQyHwGx5h+ik6AHeoG8CJIR/Hs= X-Google-Smtp-Source: ACHHUZ5CS7mk6mAM2fYvrtpJa+GCdOe26eXVwKAHAWQiAcvcFXtzYZLVtM0rm9Ojto/ISeUmGRcWqts= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:b3a7:7c59:b96b:adaa]) (user=pcc job=sendgmr) by 2002:a25:8407:0:b0:ba8:4b22:4e8a with SMTP id u7-20020a258407000000b00ba84b224e8amr1065312ybk.0.1684290087741; Tue, 16 May 2023 19:21:27 -0700 (PDT) Date: Tue, 16 May 2023 19:21:12 -0700 In-Reply-To: <20230517022115.3033604-1-pcc@google.com> Message-Id: <20230517022115.3033604-3-pcc@google.com> Mime-Version: 1.0 References: <20230517022115.3033604-1-pcc@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v3 2/3] mm: Call arch_swap_restore() from unuse_pte() 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-Stat-Signature: qxggsph3zh6qbbs8jnmkm8sosjuwabrs X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 97B7C4000F X-Rspam-User: X-HE-Tag: 1684290088-202520 X-HE-Meta: U2FsdGVkX18bqaM8MLE1GGEQ5ZXkI+788lsfGnuqvHkIWfzxuhy/2CeEG+4ubudyRDybf6oW/rDUGgmS1yd80QCjXmdrLuzZU8zrxXRFyFJXZ0LldD/mqvMfrXTRG28zYn2al/Kknk5b21Pn1CfjAMev4LM9A2F57vB3wWRLb2yMQg4ARUTRQUSTqCycK0LUjxCIb+Rw5+WMC7FmJ4Ly2j6PbT9SHxht0vvrGu1ZxhlRxjnlwylypXwDqJdRK0VTYv4YoCC4NgCAjkonPirrIjRb7D07kKkwsD6pAGdLB6+YjLRqYOqBow78efmzT4Vbg6kF6wOCwavznxAM3u8TamXUDuZigZ4gObAE71gw26Ipi8l3A+rkrB0T8yPJWlTwSt6093vDKc+r5nP5FpZ7Jl3Yg6rQJKgPoeD7T8ZzBdd/oF5m6LLWJ7u272T+pzS7RwUr3t/rxgudFLXQI2HGL/APpKDDtwbPNOTYh/+ysfaOSMkk7T6aGHbGomGE5ESgt9CFO3XQGP7DS781OWMUnfc2pMPJoIBXM7hUMCJUA6LF1glsLJZZqKpAwP7yHJiwqAdhiZvG4ggiM+12QVUZ7AJs9BQOHl3DUs216JYWbWzqHHS9oEE2gKQQ/A2Qe3/DYsO+6cYVGS+7IEngZI85jlAuWkskCVMpQq3jcOgAnUeQXUTgNQNjkHJn1t3GGCct3/sycafF8pjYvMApT7dIbrqDpliZCtue/BmT5L/1SkhW+wy190AndwvkmfJZEz4KZhgdHyvF7500XTJownNf9Gj1+oBQjYsQcd0+yzln4SF0fZ1J1R5IQwHyfooKSqlg2F3Dkj2EldtjI044MbaomUl4ckwHdnJ1SJ0ky/RwWNQZOziXa7TZdlqe7Mq08J6sHzDCR1gg2EmsWDvmwHmXjX4TqmYCTdzulybO3VmPStddyj15Rmj6VjnBC7xiWCp9TSpZXLiwKh5JPFS+ybS HuFdkINY 96D6t0zqRF2RUWyFVfsJSnOmNo8A75trCNFI65N+t+sTCqsSybncvDZnI0/KoMqA+KLVooe7YSVA1Mpmyh7u5/E7TaOi5Nw/dy3ZpfKAoa77o+q3eisZuEuar/sS9lg6izkcUG+WK7RbwESOwJCTJeVFkYxpj3iGCDoyQFudQQR9pgvTdFkKEEL4oEnUks9CMrkfvtZII554IOAtiRp/Ih23g9NicuLj3PqWYru3TfkUhh1r+xrj9OJ9OhaplNqWsTVPdgfNSWr3DN/rHY1Ztlt/6vcJ3p/oSbjvWzBYRVSZQAAAAyfjdx15BfXOgipWwA4bilgLfztgeR27YusDkCGeRw4jBzLmcSVrIaoZk+vSpHrcAtfYpH843ngrmN0rnz0Zdk5F3snR94XUp1t9eScwl1zTtDDu14dJjwVtoUJVbdXV/8OyxQyKttpUkOR/O6g0BJF+Jf6Vm2qBwAn0rd1K5CCVfCl5CJRqaa3YHf3/eBYxEvZPpg/5JMr6zIjyFoOYIsdm2koaT54uV9Jq4OceTYaMDwaBtO4WZQXOm9nmyrm0BOqx9mrqg0lT5lk8ROjqLcd4iLX/jrbhfhM7imMIbWFYsM8cnPBPZbKmXBjq1yInMf2xmS5h9GhnvMY6s3zg1bmNM55f9rACXXCQ3vFkWwzcvotN8+lllXMgIl3c7cXk2kxFNJlfGxeecI2IfPtUvEmvFjjlHbU4Reg66Nypkf0JdsK3NS81V 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: We would like to move away from requiring architectures to restore metadata from swap in the set_pte_at() implementation, as this is not only error-prone but adds complexity to the arch-specific code. This requires us to call arch_swap_restore() before calling swap_free() whenever pages are restored from swap. We are currently doing so everywhere except in unuse_pte(); do so there as well. Signed-off-by: Peter Collingbourne Link: https://linux-review.googlesource.com/id/I68276653e612d64cde271ce1b5a99ae05d6bbc4f Acked-by: David Hildenbrand Reviewed-by: Steven Price Acked-by: Catalin Marinas --- mm/swapfile.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/swapfile.c b/mm/swapfile.c index 274bbf797480..e9843fadecd6 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1794,6 +1794,13 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, goto setpte; } + /* + * Some architectures may have to restore extra metadata to the page + * when reading from swap. This metadata may be indexed by swap entry + * so this must be called before swap_free(). + */ + arch_swap_restore(entry, page_folio(page)); + /* See do_swap_page() */ BUG_ON(!PageAnon(page) && PageMappedToDisk(page)); BUG_ON(PageAnon(page) && PageAnonExclusive(page)); From patchwork Wed May 17 02:21:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13244073 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 6046CC7EE24 for ; Wed, 17 May 2023 02:21:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFE54280003; Tue, 16 May 2023 22:21:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8ABD280001; Tue, 16 May 2023 22:21:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2860280003; Tue, 16 May 2023 22:21:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C387D280001 for ; Tue, 16 May 2023 22:21:33 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 95ED21C6D23 for ; Wed, 17 May 2023 02:21:33 +0000 (UTC) X-FDA: 80798145666.19.0541EB0 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf03.hostedemail.com (Postfix) with ESMTP id D04772000A for ; Wed, 17 May 2023 02:21:30 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=nS7ih6tl; spf=pass (imf03.hostedemail.com: domain of 3KTpkZAMKCFgF226EE6B4.2ECB8DKN-CCAL02A.EH6@flex--pcc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3KTpkZAMKCFgF226EE6B4.2ECB8DKN-CCAL02A.EH6@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684290090; a=rsa-sha256; cv=none; b=lCdT18NMPxGPLRFR9/KNufbGc5nQyv8To6/hzLQcyKGR35zIS3a57iteTkuh0JNlkRSwt4 8DYR7Jlm+MnF5ZCgDOb2KkEVSpSrKAQCPY9rYyDLB4bUTEcsMv6bj8ImV79HxcYa2mJjj9 f+fEEomyw1FTxI+bA5OC/ETHdwobw0M= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=nS7ih6tl; spf=pass (imf03.hostedemail.com: domain of 3KTpkZAMKCFgF226EE6B4.2ECB8DKN-CCAL02A.EH6@flex--pcc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3KTpkZAMKCFgF226EE6B4.2ECB8DKN-CCAL02A.EH6@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684290090; 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=rrlZpn5lxQz0wYWidXhNS5k4qYdBDD7AOOGwfPiDsdQ=; b=2bbH1yypoNiHw6BQAj8cXL6mKAGsfyHHh9I7ogMHATG1FwONi35vFxSNnxbwqvjDvRcK3v oy/jVLlIJuCOHs3+UzL11hbCzm5qafWhjQqkdpfb/i/Acn53bpIRZAqwrRarVfwv37jLl2 YtZrU0Avgx9rz+LXpWnGaZoZzJ4PMb0= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-561b742276fso2675477b3.1 for ; Tue, 16 May 2023 19:21:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684290090; x=1686882090; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rrlZpn5lxQz0wYWidXhNS5k4qYdBDD7AOOGwfPiDsdQ=; b=nS7ih6tlhFuvsMZlYwq74HbaDFXcOaTcEpDv9JgzLfbOcJeYHe55FxK9/JT/+cQbri Mn6JAGOT1VNNKqihdxteunOmx5PruJg2/fGmmxtN3oJJTqr4S4WMMQ0nGGzH9yNCitD0 Kqebqjin+DuMmuu1ErU226+1fL8do4fC3XsOIDYwtzvXNYfy2fVo4kDBR9Dx2K31khL6 UbHaRwmvEWWPO7TJUQ+CmLPQ8R7iMGPQ8aPuRy4ci2qpyyMDXCg6i23WhA35RidSAMDh 2IbzmeSuiKtMSP2SW/XYy9SByGadBaD56U2heVCkkevaE6uaQskw46S6Abvm/vT+UB+O 0DLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684290090; x=1686882090; 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=rrlZpn5lxQz0wYWidXhNS5k4qYdBDD7AOOGwfPiDsdQ=; b=cfgak2C7ziomTuZ6hgEA6bNQEYL5GK1zxtVttG4/Uqq2AfI5KfwZqGGY7/I79jXTfS 9rzYz2XWGyOYGTvAswe84Dp+JGJSFYKIIumtkWb3eLZkQEXrxVdjZ3WtCGJXh5mPx1f9 eJd5xDqShUAGaxq2zspJrkNReJ3AyvlagLFO6xukdP3iShel6FBCQmWIOsOS7JRz4n+C KBimT3Ew8UXNtlFCVaKtrRZB5MiZa3hbJs4cxsEPGNl66wNlkKDvCCeLwpxJW5uGA3oV vFCUr0px1VcY7XFvXxIl+ts0DembMtEvXuD12iys37PaFjCnveJsYNDeWt62AAAHIU7/ CkTA== X-Gm-Message-State: AC+VfDw0nbLl58XJRs4bwkrKuIT/DgXJOHlSR7MSEfW+rsRYxjT6Aj3k 8WUxjoAqRJqEYdh2Vucc6pqfWk8= X-Google-Smtp-Source: ACHHUZ7bLZybv9LVeL4X5M5xX1h96wUcd50pNUsrXoFbzJBGVtFUeHzy5iTZQluDbjMVvEYQTCD10jE= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:b3a7:7c59:b96b:adaa]) (user=pcc job=sendgmr) by 2002:a81:ae54:0:b0:559:f89f:bc81 with SMTP id g20-20020a81ae54000000b00559f89fbc81mr23166501ywk.6.1684290089941; Tue, 16 May 2023 19:21:29 -0700 (PDT) Date: Tue, 16 May 2023 19:21:13 -0700 In-Reply-To: <20230517022115.3033604-1-pcc@google.com> Message-Id: <20230517022115.3033604-4-pcc@google.com> Mime-Version: 1.0 References: <20230517022115.3033604-1-pcc@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v3 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-Rspam-User: X-Stat-Signature: 8m68ykbz1jckw6e877hrf9tkckahzoea X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D04772000A X-HE-Tag: 1684290090-690556 X-HE-Meta: U2FsdGVkX19plUMkYmwxOmUnjJzoAm2FIW9CXUrQQRR3WNr95vpsO9jkO/+2jzoDn2RiV1FMqhXx2NZ0AzN/NGU8SOokdXQNysfbxxCt7bQM13Loj7sWEqGUsZzF1VmYPAD+nAkvr0i1gQHu7yLYqte+RmGg4Y/sMwTopgLH/iov8EtgJTIaLKUnTzfDntgU76o7WykNNJ+TRZnUGXLC+07FKBbNM0Ht2MDcQ3X9WK0Fr9RjlL4fJGx+fDy8yx0AoKVAJETCkG0ausKzCgmUMpsR1unspsVS8iZuImnd9RYVDK/SnUaXNvUc5Ay4lHjLcsbl5ANQ2ggH41X8oWGAMKDgi2vmwCjOo5F/hM1AyPhbObpzixFOv7P1jAgXVezLbwa/tNIL7Id37OSed9oI5e7cOAtHu1VZkcgXppze7WADBqgtz1zgD1+uwTb6/Q4L0k3BvtjxGFKUF2aGmLZu5tRCdxWC2GISzuoLC22/7rX67hps3fUceLU1WsM0TNcKIsNfsyFJ8pXBnELE0vZwZaZ7jOeIlSLRnBdAWHw7PHxZoAbjWfbGLiB/MXIMzsuq1cW6PJ5lPyUySULoYnfqtKC77I08CKz08C+MlXavqLXvvNv1VE8599EZ7/RSalSe0dWiTo7MaQM75FkKZng7MOLoPmqVeVlnjudrG1AEpl0Ld+Eb6g3thJK4Yvm4tzJRPbrTXaA6sTCznA1nTzOBKbwPgYfnua50EDgE4d77xGxVAFKFypBPks6CqPWcnsXYxO4E6L005SVPgNomDF9rzYwOYi5+FzQcKZHE2GyKR7YsmX+tI9e6mQrh0gLhiFFZvxiBi8pLONMRpoaOJ0C9BX6PVBTAbjP8gPyqoUW6xLZGC0WIM5ejw+IT6RCGl0MvnLWctAE/l7TqR0ajX5NiuzkxXWYQPTnD6Eh6HyS0nTjhVnAsIzZbu9i+dEFK1rNoURi6cI1GHqBop7pum5P WVGV2jas sEJ4t3EwIj01FPQF/afbUFC/yC5OrhS6Y7E/akoMN2t0yZ1P3Gn3SHmmzlGM4r/+t8XXZIPpEHivlDc8CjMv1Y1OtnPnMl7w2/b71VUuvGUD5AYGb7ptXojRb6YEpwQpRxDe+U00+iV0BPt7kyjZKn5ZoR/qDh1zuUKi85hcRlar/5Hgen8TRkPdEZ7cyAXDpgPypxe21bsdTgdOxe6SxTPqi8CG9GtLl0wlg9zAFQRLqkZpak0WgHWbq+2djiF5wHiZ0J+G9awjo+G80bTfzyVuHTH4r7cGptH+ETAlXup8wWX8CplE6YPUm74QYuT83aZAX3TBpo6OaaFxX3AgUb+a5xiQs1z49Oh7iE6IbsCKJF7vrIluXSqxUr3zxT01jogohvTE490PNiy0Wn9cmRk+2HZU5rM7nklH7hdJorpV9QmoAbg0UmUZKwXawbMHiJFBSUObMtyIE7WgxNgxB/aPqteQLKcVmygm4auLeiGCCu74MgI9RIBb1SaPoWpgS/7KRVfY7DVS/DMqi/4+S3SS/Gg4J6ICkcRWlB5wMOYEhhT3Ue37L2P8K7nWfB0eTbQYPCihpIat4x1ygXwZMdsQeSPkjZr3BNgAwjMZ433gc/cSKMqivwT+f5uJ7aL9qCjXrAL6MP1SBfFXiCH0w5TCwBqkO7xAVDG09M9ZNwRCab0dJh0d0cXKxlQ== 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. Because we can now rely on the page being locked, we no longer need to handle the case where a page is having its tags restored by multiple tasks concurrently, so we can slightly simplify the logic in mte_restore_tags(). Signed-off-by: Peter Collingbourne Link: https://linux-review.googlesource.com/id/I8ad54476f3b2d0144ccd8ce0c1d7a2963e5ff6f3 Reviewed-by: Steven Price Reviewed-by: Catalin Marinas --- 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 ++++++-------------------------- arch/arm64/mm/mteswap.c | 7 +++--- 4 files changed, 14 insertions(+), 48 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(); diff --git a/arch/arm64/mm/mteswap.c b/arch/arm64/mm/mteswap.c index cd508ba80ab1..3a78bf1b1364 100644 --- a/arch/arm64/mm/mteswap.c +++ b/arch/arm64/mm/mteswap.c @@ -53,10 +53,9 @@ void mte_restore_tags(swp_entry_t entry, struct page *page) if (!tags) return; - if (try_page_mte_tagging(page)) { - mte_restore_page_tags(page_address(page), tags); - set_page_mte_tagged(page); - } + WARN_ON_ONCE(!try_page_mte_tagging(page)); + mte_restore_page_tags(page_address(page), tags); + set_page_mte_tagged(page); } void mte_invalidate_tags(int type, pgoff_t offset)