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