Message ID | 20230516023514.2643054-2-pcc@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp129084vqo; Mon, 15 May 2023 19:54:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4tKcnGG7SLyaC/Dx27MNgGcilgn3Ln+4j+2X3SLNd9i0D60QO84NyrEUFxmR0q+qv/U3AL X-Received: by 2002:a17:90a:d711:b0:250:43a6:fb02 with SMTP id y17-20020a17090ad71100b0025043a6fb02mr33356519pju.20.1684205677739; Mon, 15 May 2023 19:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684205677; cv=none; d=google.com; s=arc-20160816; b=IBGW04KfRgTPfmK8RbQGbK+rYqatHpS3tCfnOiPKV8inNA+kg0CA10xGpbGf+HSzAy McPSG233U9LIfXlxekrUoiZiciRAh68/R2zKw79jCCSFTcWYVOLQPWk+Z4OKI/Sj0jYX IRkQAcNFJxsjqd3oA1KYUCV8gMUZbnxrZUuavhbS8akV4CzCNHwI2qc4vyZRI9QtVTTQ wBVGXPHIPL/MAFGiF2+HAV1LuGcLXJqTgkPfQ8TZu1wUllWe/ddSgbhVojSih0Y+lcB9 KIptoxxV87xRC+OqpnZCNbb/cPErdM9dJ6we+jvrILQvEIYckZM/5GqoQmLN/twI0nuY LFcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :references:mime-version:message-id:in-reply-to:date:dkim-signature; bh=BNa4l1F+5QMrqUAe4k1x2vD+9zG0bZzdq9LlZrfkoEE=; b=NnXuXJFmXT8VtImQv8mA7qwGz0GG+W7xM+6qsdur6r+bw5ujvaf8qr9cB8QJSklMZx gl0PhKdM3RF4GcJV3J/46pIVwVByocaJjc6p3EbjtmOXrSj2kyI1c1zyyPhJKlLLfTDI Mbo6b5qhj8mP8iBWm3XlGQYrMZkKyLffQ0VTIFKQvQiMPCGQcdaK4f3im+b7JvD2Yy5Z Zpcp3fLcUxwaeSu73VnWgQ5+MKoA0H4SpdiyK/NNo4/sN64c4eBeDL+Qq6rUGJkqaIu0 /OIbXiMICuY5oIpBTZXNzSXtGpMLRVWmtazsIHq9kOVqJaiAdR9cV7K1V5ivgHWnSoDM Jlvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=5CElQQQJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12-20020a17090a4bcc00b0024696599329si780251pjl.77.2023.05.15.19.54.25; Mon, 15 May 2023 19:54:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=5CElQQQJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229809AbjEPCf1 (ORCPT <rfc822;peekingduck44@gmail.com> + 99 others); Mon, 15 May 2023 22:35:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbjEPCfY (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 15 May 2023 22:35:24 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B57531FE1 for <linux-kernel@vger.kernel.org>; Mon, 15 May 2023 19:35:23 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b9a7e3fc659so30154502276.1 for <linux-kernel@vger.kernel.org>; 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=Ipoo87Gjd0ZwrUFeVDuaxwo7rhuuvg6bKM0wczurUTNGFOSe2fJlMC5+WiE10VRfcz N+uIpUkrelYe7pyrjqdg8N9RvOnYIWfxwVFL8NUnKK3nqT04rlTtJn4hIBdX+m8WArW4 j2s+FpQX9py4uf958NeAF0e9Cq9usgtbPmH9HC9nENBQNiYH8DbqrW016+8dmWmKWwKy gP3peibcoLhT6IaR4ag7sG3wldm6fNCOu/u+5vGOaUbKApbIzggjScjl7RGz4JwQmRE9 rCg3iwBSyzW2TRxIbXH+FmyjXVg3cp9ADPgFA8QymHiVPq8pLkgm+Ifvz4tX4wxwpRQb 0ByQ== X-Gm-Message-State: AC+VfDwFA8HgfjMYp3CeKUWNY4mAgeKqHab10w85WPznTucL7sEr4OwN nB4EYdTUQQvBI5qBebjTYLUZ500= 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 <pcc@google.com> To: Catalin Marinas <catalin.marinas@arm.com> Cc: Peter Collingbourne <pcc@google.com>, " =?utf-8?b?UXVuLXdlaSBMaW4gKA==?= =?utf-8?b?5p6X576k5bS0KQ==?= " <Qun-wei.Lin@mediatek.com>, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "surenb@google.com" <surenb@google.com>, "david@redhat.com" <david@redhat.com>, " =?utf-8?b?Q2hpbndlbiBDaGFuZyAo5by1?= =?utf-8?b?6Yym5paHKQ==?= " <chinwen.chang@mediatek.com>, "kasan-dev@googlegroups.com" <kasan-dev@googlegroups.com>, " =?utf-8?b?S3Vh?= =?utf-8?b?bi1ZaW5nIExlZSAo5p2O5Yag56mOKQ==?= " <Kuan-Ying.Lee@mediatek.com>, " =?utf-8?b?Q2FzcGVyIExpICjmnY7kuK3mpq4p?= " <casper.li@mediatek.com>, "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>, vincenzo.frascino@arm.com, Alexandru Elisei <alexandru.elisei@arm.com>, will@kernel.org, eugenis@google.com, Steven Price <steven.price@arm.com>, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766017652948182963?= X-GMAIL-MSGID: =?utf-8?q?1766017652948182963?= |
Series |
mm: Fix bug affecting swapping in MTE tagged pages
|
|
Commit Message
Peter Collingbourne
May 16, 2023, 2:35 a.m. UTC
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 <pcc@google.com>
Link: https://linux-review.googlesource.com/id/I6470efa669e8bd2f841049b8c61020c510678965
Cc: <stable@vger.kernel.org> # 6.1
Fixes: c145e0b47c77 ("mm: streamline COW logic in do_swap_page()")
Reported-by: Qun-wei Lin (林群崴) <Qun-wei.Lin@mediatek.com>
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(+)
Comments
On 16.05.23 04:35, Peter Collingbourne wrote: > 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 <pcc@google.com> > Link: https://linux-review.googlesource.com/id/I6470efa669e8bd2f841049b8c61020c510678965 > Cc: <stable@vger.kernel.org> # 6.1 > Fixes: c145e0b47c77 ("mm: streamline COW logic in do_swap_page()") > Reported-by: Qun-wei Lin (林群崴) <Qun-wei.Lin@mediatek.com> > 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 Looks much better to me, thanks :) ... staring at unuse_pte(), I suspect it also doesn't take care of MTE tags and needs fixing?
On Tue, May 16, 2023 at 5:49 AM David Hildenbrand <david@redhat.com> wrote: > > On 16.05.23 04:35, Peter Collingbourne wrote: > > 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 <pcc@google.com> > > Link: https://linux-review.googlesource.com/id/I6470efa669e8bd2f841049b8c61020c510678965 > > Cc: <stable@vger.kernel.org> # 6.1 > > Fixes: c145e0b47c77 ("mm: streamline COW logic in do_swap_page()") > > Reported-by: Qun-wei Lin (林群崴) <Qun-wei.Lin@mediatek.com> > > 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 > > Looks much better to me, thanks :) > > ... staring at unuse_pte(), I suspect it also doesn't take care of MTE > tags and needs fixing? Nice catch, I've fixed it in v3. I don't think there are any other cases like this. I looked for code that decrements the MM_SWAPENTS counter and we're already covering all of them. Peter
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