From patchwork Fri May 12 23:57:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13239992 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 7A125C7EE24 for ; Fri, 12 May 2023 23:58:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 108AF6B0074; Fri, 12 May 2023 19:58:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BAEB6B0078; Fri, 12 May 2023 19:58:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E75856B007B; Fri, 12 May 2023 19:58:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D71AA6B0074 for ; Fri, 12 May 2023 19:58:20 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B0DA8AD1D1 for ; Fri, 12 May 2023 23:58:20 +0000 (UTC) X-FDA: 80783269560.21.3179124 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf21.hostedemail.com (Postfix) with ESMTP id EC6BB1C0008 for ; Fri, 12 May 2023 23:58:17 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=xk2Ibde3; spf=pass (imf21.hostedemail.com: domain of 3mdJeZAMKCOITGGKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--pcc.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3mdJeZAMKCOITGGKSSKPI.GSQPMRYb-QQOZEGO.SVK@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=1683935898; 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=XwMV83qzB00xUe1xka9Kex2X8Ec2jkmSilor+2INk6I=; b=hoXQPwm6eKMpwlE/ffdnArAq29/vm+Ntek3jHZLQ0y3sdniGbUgdPT397pcAvaGvdiNCQG HtU4AiLOGu4lXWjQKSMs6UGhRs3wtYs8A+N23uwPNife9xDa0/UDzgxO8YgvNK8gGPsu2s OECidsMQ8VyAYn5Voa21JHqR1AxAafc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683935898; a=rsa-sha256; cv=none; b=jBMfun9JWkVrQIkwI5iDIVaKDxlsYlQzZXcVEoDX/2x3v7D9/ee9ycHgDVKQk3FNq4kOE5 y4zRWyzyRgfo2U1eU1moBI08TA4D7EFkNXYa4bjnKh4G/tPg4qZyd6icLa5gRmG6VX/23a UVHBtE+rG3S72XryAz99kDQVHjxbMg0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=xk2Ibde3; spf=pass (imf21.hostedemail.com: domain of 3mdJeZAMKCOITGGKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--pcc.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3mdJeZAMKCOITGGKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-ba237aec108so9950819276.3 for ; Fri, 12 May 2023 16:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683935897; x=1686527897; 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=XwMV83qzB00xUe1xka9Kex2X8Ec2jkmSilor+2INk6I=; b=xk2Ibde3e8u/s1FXz5MjnaikjmFzTVuGbTz673xLExz96TfA9SY9JBEhrH4pDcD4kc lJcaoTYG0RcJgWFZFSCaY33HyZj2N01rZHV90M6ATudVtPlhyiI8LL94cSLE8hlDZsK1 ohmUhbm4cTQwXS7bDVKRWaW81vYw/Zs2XgvQtpjyOpS39KbdeTP0PlNP0LVOEJX0BiKd Gp/2PGuqyiqk4rIboKMupJ2lV3A59cCft+4hG9Pnr7dP/E1pUxUHHsAIktr3S1az7xY9 Y7C7SJ3J766Sa8Y3zSYkAveN2OM091uDtEnFY90+chuUo5dWOIKtYgSwr2SEMxwfaVJk l+/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683935897; x=1686527897; 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=XwMV83qzB00xUe1xka9Kex2X8Ec2jkmSilor+2INk6I=; b=Ca/CDFUCOEfhKsPYfMzTgvx9dHljnQZPCxciEMMU3Xz7tIHVfOgZod6zn66Z5Qa5Oh I4tf9AaUPbeO3plcB/quYo8Q0N4bfTw5ZUGDNgk2TAOiNt70imJt04i1VTJN06V1+IeI WfJbKLUXB7309K8Gym0msXZjleAhC3jw0K3JeZxfS5BBx9ddmPVN2fKyoGI2pHsnNg9B I6s5Lg1GpZ4EPlyU8+UG+0MfAItLkbJwAqXdhCra0uDyJHru9rt8ynp6RTEv6Sl8h/Ep N1Fz+2GgUAI4xaIN6TJEvZRehyzHUIbKVy1DurT8hKZFpXDzU2qIR4ZdBZp1emTKB9f6 NF5A== X-Gm-Message-State: AC+VfDwGv22uhlPrefZ5P6T1pkwanwkULKEMAemVDo2VTk5A1Uif3XfY jkhIt7mcJFWABYn2RoDlj/lgeoQ= X-Google-Smtp-Source: ACHHUZ5fNzBCdsm//w4GJKGotggr/NOqYy/clxbht/ilkykWu8XfrBS2AXyT1QiZkNq0D7bzCiaesqo= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:ff6:108b:739d:6a1c]) (user=pcc job=sendgmr) by 2002:a25:d18a:0:b0:ba7:29a9:a471 with SMTP id i132-20020a25d18a000000b00ba729a9a471mr1565248ybg.0.1683935897117; Fri, 12 May 2023 16:58:17 -0700 (PDT) Date: Fri, 12 May 2023 16:57:51 -0700 In-Reply-To: <20230512235755.1589034-1-pcc@google.com> Message-Id: <20230512235755.1589034-3-pcc@google.com> Mime-Version: 1.0 References: <20230512235755.1589034-1-pcc@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH 2/3] mm: Call arch_swap_restore() from arch_do_swap_page() and deprecate the latter 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: ejpwperuygzbxr6yhyn66ocpgrx1nhaa X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EC6BB1C0008 X-Rspam-User: X-HE-Tag: 1683935897-694209 X-HE-Meta: U2FsdGVkX1/BaSZShXirjv+pVf2DhP4XuN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hmXPoJyfNU7LlOKqujsOF6NC0jYkkZxrgHOJUvwd18svi2c1iracpTwgBDw5ILJpU2mVkxQ/X8yhkMZF6SnoUqEhVRYMkvY14kYihKyK3XLOqntj8Xoy+oqbjuFgD+Z2vt0nIFgsYXk5/pBgX28wFG8HI6hITpA/WW9Bpw5dZUvtnaUeHWahXiy7cJGeq8x9/pxdpo3PlERdpXtJB1ZJlunkPJc3htwO1EsBdFfqgdKmr7uE5Hw6tzQdHN3lvp6Zh8OetTYKII7qfo64a3595+mCnE2IadiFJlwzHogQ0dFIHDl+gVjy2/IGyl/Zp+Uy7pHh3E57EnXnlHAL28NHCrYEFX1WVDZpbPfnPTunGMZL/qYaM5b8hz775fA1PwX1Ww1aO1p1ZY02sbiBYph7JBQvoOGY3BXg80WBlV+j8p52vMAV7cGdLCZv9jGrTfEhXmUUPF7UXnKaD7rVYsU1v4B7bBvsBY4Ds5aKEWMVwxK4PQy7snsPR5nwb6Vkw8Ivv4dk1lHKyP/880vKs1VW5o3etrHGxPOe2yQWyw+RG3D6QmtZSacAplpqgXZLlIFZk7hISbprUtf+SjifNV4pfthcBydxMzj+GWbjFX2w4FYKUu3o7upFed+E95cmhF5oyYMDQ7E+evJweHdwYiTNjjS4d0zEttrvNHrdKLc2InkdXdszdNFPTl9tCwOEQ4T7XZCyApRYxIJCd4ZuUT+Y++nMNVJgB84BTKlac4B1+QzsG 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: The previous patch made it possible for MTE to restore tags before they are freed by hooking arch_do_swap_page(). However, the arch_do_swap_page() hook API is incompatible with swap restoration in circumstances where we do not have an mm or a vma, such as swapoff with swapped out shmem, and I expect that ADI will currently fail to restore tags in these circumstances. This implies that arch-specific metadata stores ought to be indexed by swap index, as MTE does, rather than by mm and vma, as ADI does, and we should discourage hooking arch_do_swap_page(), preferring to hook arch_swap_restore() instead, as MTE already does. Therefore, instead of directly hooking arch_do_swap_page() for MTE, deprecate that hook, change its default implementation to call arch_swap_restore() and rely on the existing implementation of the latter for MTE. Fixes: c145e0b47c77 ("mm: streamline COW logic in do_swap_page()") Link: https://linux-review.googlesource.com/id/Id2f1ad76eaf606ae210e1d2dd0b7fe287e5f7d87 Signed-off-by: Peter Collingbourne Reported-by: Qun-wei Lin (林群崴) Link: https://lore.kernel.org/all/5050805753ac469e8d727c797c2218a9d780d434.camel@mediatek.com/ Cc: # 6.1 --- include/linux/pgtable.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index c63cd44777ec..fc0259cf60fb 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -740,6 +740,12 @@ static inline int pgd_same(pgd_t pgd_a, pgd_t pgd_b) set_pgd(pgdp, pgd); \ }) +#ifndef __HAVE_ARCH_SWAP_RESTORE +static inline void arch_swap_restore(swp_entry_t entry, struct folio *folio) +{ +} +#endif + #ifndef __HAVE_ARCH_DO_SWAP_PAGE /* * Some architectures support metadata associated with a page. When a @@ -748,14 +754,14 @@ static inline int pgd_same(pgd_t pgd_a, pgd_t pgd_b) * processors support an ADI (Application Data Integrity) tag for the * page as metadata for the page. arch_do_swap_page() can restore this * metadata when a page is swapped back in. + * + * This hook is deprecated. Architectures should hook arch_swap_restore() + * instead, because this hook is not called on all code paths that can + * swap in a page, particularly those where mm and vma are not available + * (e.g. swapoff for shmem pages). */ -static inline void arch_do_swap_page(struct mm_struct *mm, - struct vm_area_struct *vma, - unsigned long addr, - pte_t pte, pte_t oldpte) -{ - -} +#define arch_do_swap_page(mm, vma, addr, pte, oldpte) \ + arch_swap_restore(pte_to_swp_entry(oldpte), page_folio(pte_page(pte))) #endif #ifndef __HAVE_ARCH_UNMAP_ONE @@ -798,12 +804,6 @@ static inline void arch_swap_invalidate_area(int type) } #endif -#ifndef __HAVE_ARCH_SWAP_RESTORE -static inline void arch_swap_restore(swp_entry_t entry, struct folio *folio) -{ -} -#endif - #ifndef __HAVE_ARCH_PGD_OFFSET_GATE #define pgd_offset_gate(mm, addr) pgd_offset(mm, addr) #endif