Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3674132rwd; Mon, 22 May 2023 18:34:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7cnT0O17PXq8Up2F+YM3xgQzAmdpDXmoPeTPB28mATyqv/DYOycMLZUB4wZPkt1xYc+DQG X-Received: by 2002:a17:902:f7d6:b0:1aa:fec9:5219 with SMTP id h22-20020a170902f7d600b001aafec95219mr12100457plw.61.1684805648148; Mon, 22 May 2023 18:34:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684805648; cv=none; d=google.com; s=arc-20160816; b=vr19al7zbW1qLACaiOpl3QL3S+mJwN73EtNsaBtHe7BDWa2EjzvnrZpd1NcxCbIohn /s1ZVwllQ6NK1fofKQ5uA5nu7NHr39NpWyq/z1fgsq/EKgWSkS+rYKlF/teLbp1t3bdQ q9dcIyVT+IWqPOMmuJK4ylpJqnCbxEIrZUaz9pCxG1Dqb+YSPotcnggWveQZGv+JJCkk Ofm9JJ5Ml4UZd3881IJjSieepCwWFBtgJUx0nw2tTRavv03zWtHIcjYLhDpN84hM72Oa B/C5stuDAMX9sVILj67Nswmbj8iFUjdHJ7IQmjhUs4qzKSanjZUNacr8y4z8IJcKXPz1 DTQw== 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=msTm3oYdeXIT0hSlyDwQQkvc5wY+Q8yhko13bmJatr8=; b=Mmr9pQSmdPV/SwnrUSe/rrAa5iOU/lJcymsz0BN9B/GN4yzuDJRxP8G2y7kSu/liJk XX/O9MetUiE8E20p+lZKep6Z+mzI0zX3CYYmuR/NFGBlHheuHSSL6vwfyb/2tXoPL4bv wN3IFpXjNRKD1kJMPSOjJjXrQbAm2UBAlMCIrFMXOTp/cHBbAxmlN7mzOeodQkGAEHYY jEipHcuHTovGnrxlcg+svS3JSYNabPs0R9M2XQjIK5FXOSz2ghcj106ultiUPfJMfFvB 5tiinVi9kFNfHmRsJLmkw5d5YYBaipDrTEmN7ZJ5M3XJfZJesLcradboS21LqogMfiaE Fvow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=GVCKc+6r; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12-20020a17090341cc00b001ae6948b4a9si5844109ple.534.2023.05.22.18.33.55; Mon, 22 May 2023 18:34:08 -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=GVCKc+6r; 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 S235205AbjEWAv5 (ORCPT + 99 others); Mon, 22 May 2023 20:51:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232331AbjEWAvm (ORCPT ); Mon, 22 May 2023 20:51:42 -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 71B6E4C3F for ; Mon, 22 May 2023 17:44:59 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-babb7aaa605so5322208276.3 for ; Mon, 22 May 2023 17:44:59 -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=QIb8BqVmpvSIr7HnVXogYInd6JS3on4Oeoi0x3fMuBOJNG6pWo3xmj0xcuTy4TBlKT pLoohja6XEYuVcHzL5CGysbgqm6iy0vKZ7jeUFfUC3/u+M0szgwhVTJM47rP4MckNlbh MI+IYM1SsgsXlMt4HuDA3La0dh33hr0iBr3ofdwKpkm8u/+O9Kb2fKO1Gw4daBhP2i2F VPKpgbDFkVpWR9oByWM0FQi3oTWtYtBDjeyehSYqG32OqxZmcYKhlBmaNylngrMaPkHp nlqx4OhbeFqOWnk26YNBCWNka73mOxPqErCo1gKP7gxrfyXRfFw3HwWtRwryxA5L8Q2T aQvg== X-Gm-Message-State: AC+VfDyYU1+IIGipQf+kyhS2/1ayvuNknJrxZw6afo6kNs4lzWlyPRwE 6E+xfJQmj61VVMcFvCmbPvesywY= 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?q?Qun-wei=20Lin=20=28=E6=9E=97=E7=BE=A4=E5=B4=B4=29?=" , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "surenb@google.com" , "david@redhat.com" , "=?UTF-8?q?Chinwen=20Chang=20=28=E5=BC=B5=E9=8C=A6=E6=96=87=29?=" , "kasan-dev@googlegroups.com" , "=?UTF-8?q?Kuan-Ying=20Lee=20=28=E6=9D=8E=E5=86=A0=E7=A9=8E=29?=" , "=?UTF-8?q?Casper=20Li=20=28=E6=9D=8E=E4=B8=AD=E6=A6=AE=29?=" , "gregkh@linuxfoundation.org" , vincenzo.frascino@arm.com, Alexandru Elisei , will@kernel.org, eugenis@google.com, Steven Price , 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: X-Mailing-List: linux-kernel@vger.kernel.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/I6470efa669e8bd2f841049b8c61= 020c510678965 Cc: # 6.1 Fixes: c145e0b47c77 ("mm: streamline COW logic in do_swap_page()") Reported-by: Qun-wei Lin (=E6=9E=97=E7=BE=A4=E5=B4=B4) Closes: https://lore.kernel.org/all/5050805753ac469e8d727c797c2218a9d780d43= 4.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) } } =20 + /* + * 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 --=20 2.40.1.698.g37aff9b760-goog