From patchwork Tue May 23 00:43:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13251300 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 67D76C77B75 for ; Tue, 23 May 2023 00:43:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C87FD6B0072; Mon, 22 May 2023 20:43:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C10C2900003; Mon, 22 May 2023 20:43:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A64E36B0075; Mon, 22 May 2023 20:43:20 -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 8DBBB6B0072 for ; Mon, 22 May 2023 20:43:20 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 630A01A0584 for ; Tue, 23 May 2023 00:43:20 +0000 (UTC) X-FDA: 80819670960.27.2A2EBC7 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf02.hostedemail.com (Postfix) with ESMTP id 8D4888000F for ; Tue, 23 May 2023 00:43:18 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=GVCKc+6r; spf=pass (imf02.hostedemail.com: domain of 3JQxsZAMKCBgD004CC492.0CA96BIL-AA8Jy08.CF4@flex--pcc.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3JQxsZAMKCBgD004CC492.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=1684802598; a=rsa-sha256; cv=none; b=lyiuQ275CeHRDlj71xKbByCxzTPz+9CaLVj+vNVqXhfPkGO1qUvA6x8vi6IK16MrcflgqQ EjM5EqLS+V1AtEnw+58t5b36T6TO0cgfwa/Y4Xm3gEDLB5KLQcSk68ixdEw4hmJIVXBMXb yMc0LB7TN8Oa6WJV9DNQDrCMmTvbrls= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=GVCKc+6r; spf=pass (imf02.hostedemail.com: domain of 3JQxsZAMKCBgD004CC492.0CA96BIL-AA8Jy08.CF4@flex--pcc.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3JQxsZAMKCBgD004CC492.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=1684802598; 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=msTm3oYdeXIT0hSlyDwQQkvc5wY+Q8yhko13bmJatr8=; b=nYlfubNVCU5nVwuK5C/du/jI/vpiKjAHF9Wax8HpHFZxDuhk8sM6HnWOTs1op+2CYGt2mM QbEQPcuZzGY6UPez3rX4jwtQtx0jEy4SOk7NLs1km4O4feLoPZz6jVCX4li25bSxW4oMZM MQjwmaS10RsWBDXsWKb76BuOPS1Tpto= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-babb53e6952so5387455276.0 for ; Mon, 22 May 2023 17:43:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684802597; x=1687394597; 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=msTm3oYdeXIT0hSlyDwQQkvc5wY+Q8yhko13bmJatr8=; b=GVCKc+6rFVLitBZRgjiG8Xp6MHuRDVhZtsHNX/VKvhjNUXI2g+oF9FkWUEYw2KzSxD jp4IhTdFiglLXHuJvOecRUNblTjQqoij5ls5a85sMq/WccA2cWXYiEuTGZE2QPc25z1P I8fzTiWeaDqvG0LuwqBGkTuunNP3dF5yHaQZQWU03AGRfLddIWVSlV0GDW2IfHKUwGIa kJWuZ1I6IkldXrYkOwPS0n6CmraBvOXwhnVIajQXxhcVGPXShTLQ3KiXtaS4Kg9Pbdet qc17JRlFojhHHmnUA1aiDUv9PQDzUO/0c5Sa9DD8d5/h5mOmX7eaqslAsS0IaFcRV2+j ohtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684802597; x=1687394597; 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=msTm3oYdeXIT0hSlyDwQQkvc5wY+Q8yhko13bmJatr8=; b=OHeB5VSM2lgd9tcEZ/ID2kuyIypgrKMTAFL+Z2ThFoG8bmJhg9QjI/SoYe0A6mcbQl PON4Zb5xzr+7ShqfiPhuL2kfq0xx8QkauoX73yekBr+uTAEjkQejixC+MvpLgADnUWuY pWUq56M+RcfIeW0Coaaz2JevW2IAGq+MQwgKtykG5wHcludoQrBwh2kbMHX1kpf1XgWG jWadZ5GW8NZz0XtxurFWzPH0XbIxzBMfF7nm/qOxM05WnTzAvReBcMrUrSEVfjabxD8C EjU/++CJDVRY3VufCmcfzW/F3GBRDQdSbKR9CwEJwyw95IFldsEcLg1wo0tkPJZMhwDI afcQ== X-Gm-Message-State: AC+VfDzC++2S6QQ+PY3cZNCJ69N4wsQsn7iWuJMFd/1K7SMW9ZwglqYQ +3Uco8FMKYpMsRhWaTrg038Hmts= X-Google-Smtp-Source: ACHHUZ6kHjMTCHPdYe9Jo2a981mU1PnCLbxJJT05Im440Cs+gDDAq2rqaJTbIgDZ3JZeNb3/fmzcm8U= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:3d33:90fe:6f02:afdd]) (user=pcc job=sendgmr) by 2002:a25:10d4:0:b0:ba8:181b:2558 with SMTP id 203-20020a2510d4000000b00ba8181b2558mr7332911ybq.4.1684802597761; Mon, 22 May 2023 17:43:17 -0700 (PDT) Date: Mon, 22 May 2023 17:43:08 -0700 In-Reply-To: <20230523004312.1807357-1-pcc@google.com> Message-Id: <20230523004312.1807357-2-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 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-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8D4888000F X-Stat-Signature: dh55mek7bfpj8qy84wjdcjf3qubqso4g X-Rspam-User: X-HE-Tag: 1684802598-927838 X-HE-Meta: U2FsdGVkX19xK2vZ4wrdGjEOKyuwSHhR7Np++bnUJ4zGgxqMfxGOiMTk+wgn1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Z1WC7PQNEcqkhXZlq+CRPuQzwYieFMH4eju08jvDdPGECwAw/FvBg00mLoEueo10DNTtFkwg/sueiQNR923VEcRMZcRAwB/iYHSKqHvp1Ef/of2EK1jatwK+ecUWZRGbB9Kfr/3KpmLz4A+Og9HYH06/9Kpm/CwtP7cLY39eK3GVbyWfPcnksfoJVDrKjtR42lH8qa1O2WkvK1EBel0Ca1/upQJjBKVcCrxZbBuNipNKXK0cvBYPY/M9+trJroQynHRAMWlGvANl6hxkIbaDPR560VJwXQqqV79BrtIhcQfe7lk3lantg904DMuAF8Qz3x6TomWFwufMHQGvacLkenjIm0fHy7d6fWGbRiEiUTmVckUUE3Uxqt3oMZdiGCEG9LP58GA6eG1LjLwmJwL9I6Y/7HfgUT4CQ2zlfgS8unJPHF8CaJ/oF/1kgR9Fqx9hywX+D8bOLLvJfSveLjxNourXKjE1SkoqDm6KSJUZOwNSgT41drXfHPDxWO0obHS74eU/71GF6A566B2dJt013Nk/q7WungQWW6JUncnp8mUnHFRS/s6MMPwogPBNzMP1ZxcP4sKWnPQDC/P5AgxVagXsFuupC8fbbj1+H/mrTgTy42PAaLq+biITomd89uNn5Tn6kXEQxyxUSkItpFxDNo0I5tH6uBfrDxPlTZQzJHrJIyd0MPewkY8j1CO3C+33CUSfd3JMtCJ/W7+qHt+PJNCQ634JmBJP3cKfqBVPb32FDDIW0Ra5i0rOIv8WhKGormxorakald+iTeEbPp+Af0TrE33QwrJdvNlbOtqoN5Q0c6dbH+prQ= 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: David Hildenbrand Acked-by: "Huang, Ying" 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 Tue May 23 00:43:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13251301 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 04D36C77B75 for ; Tue, 23 May 2023 00:43:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 905B3900003; Mon, 22 May 2023 20:43:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 84059280001; Mon, 22 May 2023 20:43:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69380900004; Mon, 22 May 2023 20:43:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5A228900003 for ; Mon, 22 May 2023 20:43:23 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2E78780587 for ; Tue, 23 May 2023 00:43:23 +0000 (UTC) X-FDA: 80819671086.13.72C0CF9 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf14.hostedemail.com (Postfix) with ESMTP id 5F298100006 for ; Tue, 23 May 2023 00:43:21 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="bdogDu/L"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of 3KAxsZAMKCBsG337FF7C5.3FDC9ELO-DDBM13B.FI7@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3KAxsZAMKCBsG337FF7C5.3FDC9ELO-DDBM13B.FI7@flex--pcc.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684802601; 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=bX87CylYnN+5c55ItUvtBMTDdL52LhDBMQG45ADuUIs=; b=rbqP86GcE0aAyrd4YzacRX4kFBvTjGHOusgKSqW5tf03wzu4Zfb29B3/XxynKip0ZBUkq3 loeJdsNoq1HUxVGJWA1IVE/are7CQ9P9MMlIXF442d0yD6MBkX2Nsi9uRc755F2SLVGTfO bWhdxgCGiGtlnfsuhIYMKB4Y2z7na70= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="bdogDu/L"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of 3KAxsZAMKCBsG337FF7C5.3FDC9ELO-DDBM13B.FI7@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3KAxsZAMKCBsG337FF7C5.3FDC9ELO-DDBM13B.FI7@flex--pcc.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684802601; a=rsa-sha256; cv=none; b=qJdCAcDkgPNrVdTkU0FGVDHRCqQ6Z7CDEacQdcYbIdZ0SDklCBIzdZOP+FJbjKdE4VfMBK WD2JgpAcJ2OEjbKfUnW3Xz2kXhdVO6l0ekDUp5O5CfbNLXRQ/h0oQXGw6UOuC1eOiByXKF SB++DQ/+jRwlp8EGByPVdg+qKrBJGo4= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ba8c9e9e164so8222808276.2 for ; Mon, 22 May 2023 17:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684802600; x=1687394600; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bX87CylYnN+5c55ItUvtBMTDdL52LhDBMQG45ADuUIs=; b=bdogDu/LWKIXK0xhj/mHEXmPSLZDQ4wTkCFpl5MS9xXgMH/lrIKDBgMm2OVW0088Ob UUXOUas2bD7bxDVYmP+pP6qAeeNNcNNzpyrJngzal1hujSvkuKEu7+oTZMvffng5FsBp gwlthK4wI9AiO+Fdzy5ned4Ve4n2qyJlWIgHIhgxohsY1Qw8A0XJY+vCXRNI9cCOvTZk GipdqA6ZJmCkCppBtgmsiSQUIm6BRaEmUEy2YBmPt0Mrmuq/dUUS0r0t46hxsqR6HbX9 qaAwcxK6iWLJ/y3GzsvNuhSXXmpx/eIa9uHJFpCvIlk4HbNQJ1mX497oATiIBKnqBGwO uixA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684802600; x=1687394600; 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=bX87CylYnN+5c55ItUvtBMTDdL52LhDBMQG45ADuUIs=; b=Sho56kz/fIQJYhze5dNEeWDl2CW2SVCZExThRLwEnFVZofoxNvyQxdxO5ZXkFWvJ19 4DprovnxnJ9mdnjTxNk6/LKYaioJZ+yzIQ7QPEi8fXfPS9CtWGetyIX+QiFfFHsOXYeF BtoyERyzdcIMa/BKf2p9dNUC+LsSDNCeBBBwkQc5lPWI6MWoXIXxOoahjulDv2gpbu4C rlq+LWfM1uYfMyi6n8zdD2qsPi3qjJKHq+KhFUTlDW2K576WDLORUCQULvWx/N1bhUDF n07EG0fdYf4lLk9i7DSYzj9Pa38gBbyL2dlnIB9dI5Y06kS3zGzCkiLiVDGlsKSNXeV4 XjHA== X-Gm-Message-State: AC+VfDzEjQKM/JCSTF5WKijgCLZD4H2iPKC/oOaB23y6NZQMdMRaHxk9 WQx754OIc+QFH/WoMocYekp3IwY= X-Google-Smtp-Source: ACHHUZ7h2YrRQhx18dwlYMT7aHixdC7I8JgE0ax2zPvocyh8XVLX5phmGOcIHrUfvAqU9QnxAXjxEvs= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:3d33:90fe:6f02:afdd]) (user=pcc job=sendgmr) by 2002:a25:d55:0:b0:ba8:9455:85b9 with SMTP id 82-20020a250d55000000b00ba8945585b9mr5274091ybn.4.1684802600447; Mon, 22 May 2023 17:43:20 -0700 (PDT) Date: Mon, 22 May 2023 17:43:09 -0700 In-Reply-To: <20230523004312.1807357-1-pcc@google.com> Message-Id: <20230523004312.1807357-3-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 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-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 5F298100006 X-Stat-Signature: dwm947soayruuspigs1y3kx4cqaagwjr X-Rspam-User: X-HE-Tag: 1684802601-868574 X-HE-Meta: U2FsdGVkX1+srnGUtgP+cEpKj3MCJk0vChk9QyclhN9ygjY7jL3CM8ZqJ8MS9NvEwUbY9pdTsxuO3AUX6S4x9DcD+z2dlYwRmFlWVEIW7RCOQ+fucQw9GeNqIuw/oOhGFNl3JZUyhXEf2gcaov4XaUk0NYntHzIBvLLwrhd8GwxDKZOhleoFE2VUjJm7GtBT+9Q9QKhxb2SBAH3qffKNugSv4Phctbjp5TMhEx78lUYX9WDHd/WGsbcmch9Gli+N469jVVYbCvK6dIETOzSLjkuoCYVr24cKvMtTi43JREdciy4L+ffqYwFL7ynOj3Mw8auBvDehN5EtMzUpS69JmJNdewjiZGyxmD9c6ZUm3e4ekkqWYNvNtla46Gl50Vygjv7i9flbbtTGxOVsbcHov3HN8s63fv0EWI+JVVULWxYXC+cBi9+NrGlidG/PwDvZN8BReOlfbpS3w26FT8iFN27dlTAjAVGIDy4d0/0tKCY/+SSg8sQ+oM2YutRqTiKazaTyeF2McrkK8diPCtFw85T3ZJxqlc61v/84guwDIDfU21ZY8g4LCDkKzyYkfeomj/bKSKI7GpH990M8EzFpdLDXofKQo/35NRIYVMnVHdpsLdU7CoOIqCWNrjZrVaJg1wse29MxSKrlURA6gugjH/B2rJRzZqjy550B6MKB1Q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QZdRGrqEM5iGSOXLKcTHc06r/w2OMj6GW8BCYL2+42i4hCWI6ay42G48VzTZo= 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 Suggested-by: David Hildenbrand Acked-by: David Hildenbrand Acked-by: "Huang, Ying" 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 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+1PqaxmJcD2hlQS3KWfQ1M+bFEzyj7O8z7ZGy+cGdIuUmTE65SB/lanlWTjUW/nC1tEAMI9GyIVVAqKtLvsVNmEhekR+Pad7VZY91JkHRSyXwxp9zbEx+WMSVODi91sieCdC9HPUvmB1ASS/2YIT5qAjrPg/zKN7qG3IivnEl/5WuN/ex+XH9NtXrfqFWXUy6IOCT/GPriejh6lX+PUiN6W6MrwDrXE99+VryqKsuacT0KLDt8Cwk8f9Py04OwskbguYhhiL2t7cXZm9GZGw72Iv7tytKgE6K/E1gPheQV69QDRfaVy7H3OYq0p3ByV8tuaRMHrnoxlJv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J7/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();