From patchwork Wed May 17 02:21:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13244071 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 1204BC7EE2C for ; Wed, 17 May 2023 02:21:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8476F900003; Tue, 16 May 2023 22:21:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F7B7280001; Tue, 16 May 2023 22:21:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67292900005; Tue, 16 May 2023 22:21:28 -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 56E1F900003 for ; Tue, 16 May 2023 22:21:28 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2F9FC1603A9 for ; Wed, 17 May 2023 02:21:28 +0000 (UTC) X-FDA: 80798145456.08.043C5DB Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf25.hostedemail.com (Postfix) with ESMTP id 60BDCA000C for ; Wed, 17 May 2023 02:21:26 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="kU3u/jVP"; spf=pass (imf25.hostedemail.com: domain of 3JTpkZAMKCFQByy2AA270.yA8749GJ-886Hwy6.AD2@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3JTpkZAMKCFQByy2AA270.yA8749GJ-886Hwy6.AD2@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=1684290086; 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=icy+EhZ3UBgzX+LkBKZmwy9I7D5yLVOL3MyBuUnW0II=; b=qe1BrUuYrZ0FXshJTeE51rtdD2tf3zcZPihQ1OmQVw0YujrPOttMGK9DA/E8/80sjwcw/T QxWkSAtCRwGkx2IZkgMwEexcL5RqBLApNK6sXT96CCbL7f2rye8PDb9rNSMiUL45AbxHMP rW4XrNykEg8Ew1ykUS1xUD6ijxvP5Sc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684290086; a=rsa-sha256; cv=none; b=nXYzLot/T53Z6MUcOc/dZfdm4XE+pgY3T6toXiQz4aotTmTapEJp+5ypJOHtCl70toJ/Gu IxV1Kp846R2peDtU9U0aVXah00zV3dRUD0qPV7WIOmdGVMmx7gzWM6NfhAy2koI/zatXwU VT1G7XXn4lWr83gXTnUhLabaZA9BcSs= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="kU3u/jVP"; spf=pass (imf25.hostedemail.com: domain of 3JTpkZAMKCFQByy2AA270.yA8749GJ-886Hwy6.AD2@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3JTpkZAMKCFQByy2AA270.yA8749GJ-886Hwy6.AD2@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ba718f5cd50so252323276.0 for ; Tue, 16 May 2023 19:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684290085; x=1686882085; 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=icy+EhZ3UBgzX+LkBKZmwy9I7D5yLVOL3MyBuUnW0II=; b=kU3u/jVPNbJOPkDSOv1M9xE9gA7eqoTFhSdZQD4qt7SNgcYJYLu77i/2peyYkaoM+E 1CklaeTAYSmTwv8Km5dGKi7C0WCfutgqDI2sGNHRkPp+sdYNdJ963Ikhl8N6lfTWY03r Jc0A1tNgoUDHR5FiwBDbsHV8XCGmQ1kAqZSfPSuC5DautA1wUknPrMKD4FBEPRXJM1cI zDV47+hqam9u7nttpZOONvGIAgOZpyS9w/3N1M0W8GoFsxZc0Tu51VmRu5U30nbsUdLv KRfdPlHe57ebRvFOgibo1B8s53lcdE03PGn3ebRw8zfKd/8XLAR3q4VID38yQeldPd39 cHzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684290085; x=1686882085; 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=icy+EhZ3UBgzX+LkBKZmwy9I7D5yLVOL3MyBuUnW0II=; b=DcvakaD+5bTJ7J2CD6OV8pmtVAjTfV81S4lP2DWKhUB4WOSVZTSSMLsl65Ph8DVrd7 N4NE67JN9l2YLAoykU1SprgoQW40uUGpAnba5Koj2EfhaytK1VuGLasoyHvwdsnLEbHn uCDiEYi7h3t2Yq90JlUxGVdGfpGFiZ27PLd9SuSQxIdPY9/hVZi1CH0yYez6aWy+HFFa d/kN/OzQA8VVsST5Od9jnUsWJqCRKx2xYm1jXORvYnqVLFVaQVPzFlSuhRteq0cqtcjJ aKStveafVCSKkllapoA8Ql+RnsazuMzfIBla/N/9E0YJzJSR65EsN0YDlFkJ5zMdwFK7 aY7w== X-Gm-Message-State: AC+VfDwjYOSvcqamnDxu4Zu6RJ0trhXdwRE8tqge7Htd8pJIF9OTriCZ Notz+muZMF+pLS/8tJGAdZR3yZk= X-Google-Smtp-Source: ACHHUZ6HltqTMi815u6+g2acsl5ZG5UZd+Y+2Rbyffv/trwosDfbc8rLxY0NJ38GbW8keQ8pFoFL1ds= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:b3a7:7c59:b96b:adaa]) (user=pcc job=sendgmr) by 2002:a5b:309:0:b0:ba6:a54d:1cae with SMTP id j9-20020a5b0309000000b00ba6a54d1caemr8869621ybp.0.1684290085477; Tue, 16 May 2023 19:21:25 -0700 (PDT) Date: Tue, 16 May 2023 19:21:11 -0700 In-Reply-To: <20230517022115.3033604-1-pcc@google.com> Message-Id: <20230517022115.3033604-2-pcc@google.com> Mime-Version: 1.0 References: <20230517022115.3033604-1-pcc@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v3 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-Stat-Signature: p3syt7kxshrfn7w4mrd57xtu3cu6hok8 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 60BDCA000C X-HE-Tag: 1684290086-704434 X-HE-Meta: U2FsdGVkX19xyak4fHFQ0Nr98PWzG+kZoge7ewSPTC7HH6w1UnX2vUe1QSkJ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COc1kzelquL/aHR1Rr/VKlkOzOsgVuA2JSiTnxtwzPGsM8c6vm/yhWInzglZfaQRaXyjz6f94rhXycys2qgXPzgmAoWYlxVssyGMnlMLr+la7EEeQkSdDpnt2tinc8LrzVEDAc4BpuZVz9Q2BDZlX9tLhEq6B2VpfoGFLifv8E6zXSB19Lc87Hx57fza0watam2rFqYylZBI25zIAic7pMDvdAYUkOrLnsKU36M0CXjjjRrolZFyzIfoedscouPaW7XODg1eZx0FwVXP6kNR8K4y3Prd08Rl8rA0p31wr0/6WWlGmmwFh1DldVeDe3sZ0elhbznQ2VioEZAfVN61Rk7eqlg58EroKowzKu1hmlu6sxLYWnmevMog+UcexCdSXvc3ldfZP+OI8mDxU/8iKpqZm+cburS3tarm8lSLFXumldivzC/kdmIKeZ670QH1ekvKCjlIB5bQUia7Cw8MriKGF3MbQlaRly/e+vsYBPD+CUiX40/c3o2UDRjx+fU3hdWQNuA8xHca/p17BXsD7dPfK611jcqdHOKLM6NAYD+IgkQpjSWHGJdGXEwtgUM7t0kiEkj9YXl/OngYMRSDpwz6XgedeL6HufBBDmyuOeyuS0716rIp4LVlvF7+Oi/skJq76OrCeYAbuZJMoZLi/zDQtTSkSLPRfC1337ZyWn8f9kJMQUTwn8Qprr8xFI7ELKOwTdtjn/yFv4t 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: "Huang, Ying" Acked-by: David Hildenbrand 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