From patchwork Tue May 16 02:35:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13242482 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 6A5BAC7EE23 for ; Tue, 16 May 2023 02:35:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 045BF900004; Mon, 15 May 2023 22:35:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F376E900002; Mon, 15 May 2023 22:35:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB092900004; Mon, 15 May 2023 22:35:25 -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 C8A36900002 for ; Mon, 15 May 2023 22:35:25 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A0889AF463 for ; Tue, 16 May 2023 02:35:25 +0000 (UTC) X-FDA: 80794551810.23.B38F1CA Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf15.hostedemail.com (Postfix) with ESMTP id CEB46A000A for ; Tue, 16 May 2023 02:35:23 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=5CElQQQJ; spf=pass (imf15.hostedemail.com: domain of 36utiZAMKCHckXXbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=36utiZAMKCHckXXbjjbgZ.Xjhgdips-hhfqVXf.jmb@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=1684204523; 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=BNa4l1F+5QMrqUAe4k1x2vD+9zG0bZzdq9LlZrfkoEE=; b=oxKGbhr/w6RwUdlJIaBIJVgaV1VWCFYs1VHbWGrhtbgV7se7K7/MZ3VBcp6L28tG7xMQK8 eMwwjbCyPB4xMns5ZqZR1mQ10J1IvJFFuhseI+8wTFzKcRx5eXIBgFth82JhpRSJW1DUPG oyD4V16urrIZ47MBXi3wrH+ttTlSa7g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684204523; a=rsa-sha256; cv=none; b=04YIcCaRHKjr5+IWpM7WD4yECw+S8Aal+G0TqCE7GUTPuANE2uPj0vl1CNITRacJgYt73D cDoyT8CYmA56ZDewOcPxt77xCVuledaI14oZ0TLlq/PAN87TQYGbdkjBybKqvqtrkAB30j uX5TRkPyojLL95UZvWvPkYj9oc629Mw= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=5CElQQQJ; spf=pass (imf15.hostedemail.com: domain of 36utiZAMKCHckXXbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=36utiZAMKCHckXXbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-b9a829a3de0so30149987276.2 for ; Mon, 15 May 2023 19:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684204523; x=1686796523; 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=BNa4l1F+5QMrqUAe4k1x2vD+9zG0bZzdq9LlZrfkoEE=; b=5CElQQQJT/aTXqmIkBL5nk8ZqROWxHVeiTpJhgNNP6gAWJxiEdiM9NRKcz3h9LcW3E 6iQOSor97QYs0lfZ6derwYy+EoBPTPG0wrSAhW6MB+C8I2ulfFpVq0xWstKnv/gCOSI3 sTayVf/EDsxUwV0fRpbyEQMKAl72VTxZxebOOXGkY9Zo/GRaXgJzrZb8R3DJyyI3TILH gbJgCWXVuSYD5aavaLo40em5VxUV5CUuQmcRhtfE7LKpENGuSe0F4bGretjtH/Hk+Er8 ZzXcJDrPpAVybe+zFrgxXOsiLxl2HMfrPhFvpy1NLp3M2k09zHnGgLcbjVvYkYgEHIGy lFdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684204523; x=1686796523; 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=BNa4l1F+5QMrqUAe4k1x2vD+9zG0bZzdq9LlZrfkoEE=; b=GW3YeczBamcZiL9Qf/ElgpDN4gq6Zq6zdynEIgHeXeE7VTq6qWFNqOsQRvaZQIrJ7Q gmhvl42mtFe650jM0gLiodfe9WxEeXSz3EtGWXoDWqmtt3W0F4sTlr84ska8H4hKQnNb JflaBJ19d2id6eiEzVCv4lGBcvmlH0KQ4k2q+c+zGtHOeFw+lSuZE6ItrAJFg28b476T nfKCyqu+joIcqC9H3CUGmVhoia6CRNbHkowo9mU/OOeq8E+7zG657CfrAh41IpE6fQpK fQ28mtaavMlgFTfba2RpKlGWkcifkg+zT1ZB4sLwczSiDIeSt/6EZA4U5c8u7p6fJDXj CXEw== X-Gm-Message-State: AC+VfDyFH7knEsWokbmriuuUfXNLZToUrDuvOPSifUzQ2wSDugpDdvTo tCkfqhu8alJ8seqa2O6Laxp1YYI= X-Google-Smtp-Source: ACHHUZ5++OLyfAEF8T2icYgWUbhVixyck2Y9LW7OB4tG8eRNkSZySF8iIX6XNzPK6UHQZ30i8umUU5Y= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:c825:9c0b:b4be:8ee4]) (user=pcc job=sendgmr) by 2002:a25:d8cd:0:b0:b9a:703d:e650 with SMTP id p196-20020a25d8cd000000b00b9a703de650mr15802130ybg.7.1684204522988; Mon, 15 May 2023 19:35:22 -0700 (PDT) Date: Mon, 15 May 2023 19:35:12 -0700 In-Reply-To: <20230516023514.2643054-1-pcc@google.com> Message-Id: <20230516023514.2643054-2-pcc@google.com> Mime-Version: 1.0 References: <20230516023514.2643054-1-pcc@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v2 1/2] 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-Queue-Id: CEB46A000A X-Stat-Signature: kg4qfhwhcwabne8pby3sxw7wr8i6i1ii X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1684204523-527772 X-HE-Meta: U2FsdGVkX188Zfy/ptwAUgnIco7NrxvqmYPzflNwv7TB1bP1Y08P0oq6+dJ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MYi++XCjWuwuF5QpcvlzLdF3pD69+TJWjprUM/ply0PcTzKLssQ8NX1laXTT4LYqqrtZImVmXw/Oh+DNNao+cOF0tHFAkm5Z08nUYBnIAtmXpxDb3yH5JKbriSq182yUjLjISEVnszvxn4XKTQCu1O5KGmrXerOyuVdpiJNAH+XT92IqzTzwuMQxANHgT77L5U+Xsv4jhum5QDe9qMxTCUGweZEEXkH6Mrkxr8GtMb9DEpBkJ0eVZysJMpUfDxcPwflSgTO8DguR7tHr+JVJAYKQLj8Dqf6DhBlYzVqs0h3J4Te5eAUr5+gNYpjU/5PhEPruK6hrkZvfREAqzvo+FVItAaNlHltrqzigi4ImlK2N11R0Wb3wkAYXxU0OSkACPtn0COQcOwtFpSGFIio70PWHeiifGdijoqf1tcORk7TD2ORcTymHeocc+9K3NooaHj9Gc9Wd364PhV+Su5xFaYYkQooq9L/ePLMXuNhafG4HTpDBzdU3po/eOyXikPEZziWIRGnsmHSp6sf6+AxPiSacQtV+6UALlPNGJv6z87w+WnaP8Vols55l9RkvoWoTjN4IqrFpSv+Wi8TyoFvllvYYFwC4GND3aWN1XHfqwIyHY58ba/cRLjJR10QxHdshTFH9OwyPU+SZcjyp4OIdxJBja4h7kQPE6Wh25WhIQt2KDs+09hHptiOzf7XgpkPyNbxWSpD1+Hcmxn2pwWXyOB0wSO1DQJ+D 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 (林群崴) Link: https://lore.kernel.org/all/5050805753ac469e8d727c797c2218a9d780d434.camel@mediatek.com/ --- 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 01a23ad48a04..a2d9e6952d31 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3914,6 +3914,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