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: 13242484 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4B318C77B7D for ; Tue, 16 May 2023 02:35:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=LPNZ6FWnbOjZHJ/C7ge+FjX408Mr/LVEgOAzLfD8uQ8=; b=znn7V4gXr8sYyQuLZemfejIVM1 Ocaw1WRgdm4OlemcE281J5I+7EDQ3G21gDDEVGpSlGp+N7h08McpEi9FCPG/DwHRjMfjfpOKXBuQz /UwZZ/dxzt5dVc4frEK+mUDejkCbSL1z29vEuhSETVt6OGYxo0lZBqLVJn6+Qt1EvmVnv7PqLY354 M7f3ToIKHdJnvZMUfqWq3rj4T7Cq1lKVvEfTZlKYqSzW5zwAfnBw2gvu2tIlfMgdrOSfEwsZglk0N swLcix/2IKBCguaNsx/vX1HE63jeEM13m05GVxiEs0Fz3oh34Znf8UpymG4bjHi2glv6jZzSzIzSh ZCP68nbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pykXB-0049N8-2M; Tue, 16 May 2023 02:35:29 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pykX8-0049K3-07 for linux-arm-kernel@lists.infradead.org; Tue, 16 May 2023 02:35:27 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba81b24b878so679537276.3 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=e4TsdM+n0o/XFADtYMM4t80BBvzyfLB17brRcHUxpgtijq/GbAE7XGq4KymuUQCzCP YUmxrzrMgCXj98V+xOWCyMgCYRrWrBW9xBdWLC3kpQk1bLFZ95xXnnVLMN0xw/n0r/lc x5LvSKZ3SusES3FBlgsOII7Pouc7PjIXkCo8IH+iXfO0b3nAkDu29L14fkrXMuehf4mw x/UiIz4OCIwfCF19fvNK4R5/9pS1ijhXr2488FnAemhGe9HaRGZ9rl14+F00CwuVHHiD gwhXpacfQjYys1jR1uJhesVBAV9+sKLImvE/UHN4kKqCGN9Nm11wQWxP5ttXtIUA2BLL VM0A== X-Gm-Message-State: AC+VfDxQD7FqrpLBS4N/7aRWdBespC7F7/RbNCCN8NRYTiTAbH54rbKF i6W/bAIQoVVb2uUBTwk8UjxbmMM= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230515_193526_092521_7A2899C4 X-CRM114-Status: GOOD ( 10.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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