From patchwork Mon Dec 9 18:23:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13900188 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 5CC56E7717D for ; Mon, 9 Dec 2024 18:23:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFD048D009C; Mon, 9 Dec 2024 13:23:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E84D48D0058; Mon, 9 Dec 2024 13:23:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAFDA8D009C; Mon, 9 Dec 2024 13:23:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9B1058D0058 for ; Mon, 9 Dec 2024 13:23:52 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 59FDEA093D for ; Mon, 9 Dec 2024 18:23:52 +0000 (UTC) X-FDA: 82876244094.29.35606E8 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2070.outbound.protection.outlook.com [40.107.244.70]) by imf20.hostedemail.com (Postfix) with ESMTP id 5EA1A1C0003 for ; Mon, 9 Dec 2024 18:23:27 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=OzqNGcXF; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf20.hostedemail.com: domain of ziy@nvidia.com designates 40.107.244.70 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1733768610; a=rsa-sha256; cv=pass; b=BU9zvW2WDZIdJOOhh7RGx7PPrfXiZJo7FzgyyHcwj3jmML6W8DEbkHdmbmeJ8r2/dqxBJn CJa+sxVjKjGlVcdl5g/2GgyX6mSMuUebq2qNC942K2z9NRX40Ap0n+zicgeDL+w6kT30Cv zFFLQ+LjU1NtBUPovm27d/FnCBmV6Zg= ARC-Authentication-Results: i=2; imf20.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=OzqNGcXF; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf20.hostedemail.com: domain of ziy@nvidia.com designates 40.107.244.70 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733768610; 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=0aRe51ucj+XlZojf/byPAJX0T4BItCc1xHjUV04rccw=; b=4pJEU2g1Oq9Iy8JlNaIdPW2ZByxpyZwwbWUjN2rvUBxhddPizGHSJV+SxJbusK2xAgB4G5 Psh8EkmRBkiPF/t9qe0dtBrWwtsQViJaCcyo+QVail0OPMxRQ8kx+KXik6IiEhP3vlw1Dt 0vPLegtIx4BZrptFTsxEtqff7AooeFg= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ncthLPGUhndRbuOtRUZ0+42Y/+QtInYROsbBHzixKDhL+jQqdA+oz2zbiSKNBY47TV8K/SeB4pURgSOh9EfQsyyZJb5bckrsicyNY6fqDzblCbsQWiQsUimRxnRMSA2l6+vgptnqs5MvtmunUsYUfBxVljnlZHP1nYfX90vDEenu6Dd/xdePiFNbkTSCFnkOqD7E0DRf1Hqxf5Iy9KWjg74cAF6yn4bc7jvfzjX4mrHLp7Y5FLrvF8w/NklpaykrqgMlfMYv9HNs61NQ3ONYeDjxraeQSmTy+mQEMwJDIcOUxvjui1jqF8HpI5Bu7OlTctyHxSI4REV31mD3QGs9bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0aRe51ucj+XlZojf/byPAJX0T4BItCc1xHjUV04rccw=; b=iRFuWUI3J7aK5nXvEn3PU8P78/k5CT8pVc+zNEUK6h2cuH/nTkceFSLHyY6bYUZrL3jRTfWFVubc3SAtfGLdYd1Vq9L6BsVG4/J2CdKoifk/BCf04/mmILpwCd86VKV20+l/uGmODsPQedPlncycuUOQt8UbFMZ3l07rhN9ox4H/Mwwo9JTGyerjtWtsY2O/Yfhw2a4Q7uF/SZKqAZNQzju7egmN8Ayg4dfOZiMxvuLZtBrr6L62DfawIC1LhyfCYW7VnuI6qF9F1DmQ6hT9N0ZxHBNeHCHV7KK7ezgz6QoGWIWVmjj/860i5C0LBz7hs3Ij1UsqUegqW41pTs0hvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0aRe51ucj+XlZojf/byPAJX0T4BItCc1xHjUV04rccw=; b=OzqNGcXFZrITm9n1UhAeWEJzQ1oBK+wvsilDM7G9PsEycyi64YuUZCnDlQZiMaDd7EnnGjGDqfN9J8dG3c+/OoO0dD5c26ykCJBw9w7IfS2Apip83jGPlOzd5vxNS893VkfAEz1rASfjO2LCNrx4u4B4TnyEA0Hdcx/ykMirK56S8MLZ1bEITCdoh37roaSeYdmrVvCNfGJ6oUkvluJw4N08P+D9c0aN1nMvRmayPuuO2Z3h/nqV0VJSBttDBEgx+AruWtPI31gDuOPUnX2iR3ooXO5TA/oK9UOeC8K/+Babf/nPkjPg+jO5hRBP0JTdTVjxDC83FDvG4ohD/0262A== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by MN2PR12MB4487.namprd12.prod.outlook.com (2603:10b6:208:264::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Mon, 9 Dec 2024 18:23:32 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8230.016; Mon, 9 Dec 2024 18:23:32 +0000 From: Zi Yan To: linux-mm@kvack.org, Andrew Morton , Geert Uytterhoeven , Mathieu Desnoyers Cc: Vlastimil Babka , David Hildenbrand , "Matthew Wilcox (Oracle)" , Miaohe Lin , Kefeng Wang , John Hubbard , "Huang, Ying" , Ryan Roberts , Alexander Potapenko , Kees Cook , Vineet Gupta , linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, Zi Yan , Geert Uytterhoeven Subject: [PATCH mm-hotfixes v5 2/2] mm: use clear_user_(high)page() for arch with special user folio handling Date: Mon, 9 Dec 2024 13:23:26 -0500 Message-ID: <20241209182326.2955963-2-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241209182326.2955963-1-ziy@nvidia.com> References: <20241209182326.2955963-1-ziy@nvidia.com> X-ClientProxiedBy: MN0PR03CA0028.namprd03.prod.outlook.com (2603:10b6:208:52f::16) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|MN2PR12MB4487:EE_ X-MS-Office365-Filtering-Correlation-Id: b817a1c7-a0e4-4c59-2c4e-08dd187e9622 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: pxjxwHXlHrvuRoGY22/ksxcWrF3XPxCy9BZjMgeM1Q4f73cP4E/1VK+bfW5k4ZatWh2WY3cTzG8VWd6TVBaNsSJkPANYJgw6WO0pTeIkz696jlmL0t6NnMbvnIcsIeUMbRtJOMhnICoUU7dvrsWSdJEED9Aru9n8qPD2Ib8HJefQJ+pRJ6qY2Fq8iGFqYWSD3r7oysdHc8iKa82JJ+fGRGODhoRLPJ0rTYs4pxjzBjgV5pOT4dyL9UZRDymt0V7gevrcEkY7kkdjCchm1vi30+F8F7sX84nhvUDxpGmjITWSWfpEEabFKAFpoPmpKfQL/sb3gNKZmoohZCA7Xuc1qBjrLoJgL9GM2pxQbc0Z59XDJMz2EDV8gc4iNh+tOFlWeuY7DuqT6xsvpG5dFjVQe2QUXi4EaEfcL+ciwBOTUwnkSkFXmAUUtWRg2pwWg8zm+uHZ0ZcOwG+aG6mH6+HLsWHHSiVOcyJfxWi0yDKZQuWpGe1XS9k6A/EAKaFDWmh8mmd7mu8mK9blXg9Yfx2iNawbDgIVWI+LvKQo74tk6skMKB1Rjz+p1O8OBUYdzE1shdOmwdsnIYXBsxI51mVPZ6ES+LeXKXK3jyYmW2yru/6agnRFrWS3eB3W0KNVxa+fv28OWl9KaeDZFvJ5mQPZOteambMvWkykXmHeTBTDepgZaMOghuocSZnf70rAlGiLxXzJbps1raQx7/Q8RM7llNfkxl0tWeU1QCFsqBDizxf6rrZ7FWrD/CpWtDmOcLZshf5fr1w9wXbw9Gxo+rSe5ho/CbgLkjvNIcUCLeb8hjT7wcmymwHSX7lQWud8Xswt143PEdF1Pt6Ok+1Oo1rfFODrMTmjFpQgDv8xUOkCdqYsA4QOwPzVzhi5xqBg9GZLhXPnKhmbh4dO7kS22CHSaAE/RdWXhWTXWNBD1M265CQA5NvvInnA/1m3xjd0ro78m339PMdcLZkkOrm60ExZhcoT68rmtgUuni3TZlUIJIvM7aL7pXWvXorCELSYFhno5cMR9RqbEEgLmbnUUbJ1uA2R28KAkiNJvEJITG6XpnpBHonUwsSd4u2U8jWlQaUXk9Yoi0DaDggluZL0t0ROR5gDNP9enRL6kYfAv2aneaASJyJ79U06Dm8FR/flo30UY+gxAJJOqXxzCjzYcj19U5d0MVVbUaIrhlln+naX03l1Fvh0fMC8mkBXsKv0b7iJtFjShkBqyQs2alh8cv4veCz2rXX22EbSCzox4kS6ZDgzif59IAUadUQYfGLR7nIaZdHI+Kn6OzU2dMPvei5q6nrVOxzzdJc3bqUIOmowDsYLjyJMHzVUCleK2twoq4K2CTfdJHbmFlUF2ap7Nl9ZmOYCL2NSybKCc0tRHOcoE64= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wueGeFTKEdYil4ikEUaSIvYGrCypNGvuP6PKEy7s9U+vAeW/J5bojjItXVItalHbqAI8kaTt5ORrQDAXn/93QIXu6P29/udpqp1kpw5+ajzBmwujJBRwPPxNrDJM3v8WpZdyq/3iwxsn1B30HxWL4NKDrkwZssEvwft3Kw4MTbyEnNJ4XAQWMDN4WyFxCOQBoR9ej6x8Pubaq6GOgDtuqf8bxxniyeh5udNphGZG7YxePRDBTeTIDDePrlfH535i5+mTp4X4LE5B2Jm1MsBdspoDHYXGfp4n7rUD6Hy1Nmz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C4sTGphlYsastHig3eVM8mQT0F3qt7WXP87OT3o/HxfulJrOXUakNAgXWyI5wmOuGlMl5J6/4fiRZclrmMer1UJwS/LMLcERbfIKsRH0HtZ+7rc4/fhY8SDSS9n6ZshJTHG9C6hEW9+gdvk4wAkjDS7xrRaFX9KEvSvPa7jKju6JNsvmIQ03B9NVho+ZHz0K47mAaEFQ6uYuIBV9u4I10= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b817a1c7-a0e4-4c59-2c4e-08dd187e9622 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 18:23:32.1531 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2D/Cc3PUJn50Bprvk8/9fGf31vXdeVKjxjpPJkneXWsAehbx24Bu46NNf5mRQDe5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4487 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5EA1A1C0003 X-Stat-Signature: jnrgnunaw8g64ui1a5oorkqrbzupmf7r X-Rspam-User: X-HE-Tag: 1733768607-440626 X-HE-Meta: U2FsdGVkX1+dnoIFHHJxqiU2brUCJVUOJNgLw2z+gi9ICvgaDlS1+BJsFmH3W9n3xe1dp8NNT/j6jMIwWetcyzXs5Dk4WbzuDDgar3dbvM3oQGPLFNdLDJd1obyVETrsJTOUG69QUibWVTx5EAD1/8Prqc/o8lbln49164f7l0lxLcrLqFruabpTOQrktqCZfrQ5TS7X5czNMULlzcadWNcbQVy1qaKm7LTo1MdygQNt7sPzOnX5apoR9Be8sQqtzBCAyc30W3g3/olO9ZN51C2QD14woRoSzMMUPS+Q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RTsLYKG3vCJmClm/ZxkILCZ2p2td8GxrOyouEtCwxtvxgtkomZW5HMsjmYluqjA2vAyXcnn5y0dIxghcgWIvn2YBwoOvpuZQxftBLmXT5QBBEn5MX4ZDzotgK3IDHZ0v/p5j7kOtSx80= 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: List-Subscribe: List-Unsubscribe: Some architectures have special handling after clearing user folios: architectures, which set cpu_dcache_is_aliasing() to true, require flushing dcache; arc, which sets cpu_icache_is_aliasing() to true, changes folio->flags to make icache coherent to dcache. So __GFP_ZERO using only clear_page() is not enough to zero user folios and clear_user_(high)page() must be used. Otherwise, user data will be corrupted. Fix it by always clearing user folios with clear_user_(high)page() when cpu_dcache_is_aliasing() is true or cpu_icache_is_aliasing() is true. Rename alloc_zeroed() to user_alloc_needs_zeroing() and invert the logic to clarify its intend. Fixes: 5708d96da20b ("mm: avoid zeroing user movable page twice with init_on_alloc=1") Reported-by: Geert Uytterhoeven Closes: https://lore.kernel.org/linux-mm/CAMuHMdV1hRp_NtR5YnJo=HsfgKQeH91J537Gh4gKk3PFZhSkbA@mail.gmail.com/ Tested-by: Geert Uytterhoeven Signed-off-by: Zi Yan Acked-by: Vlastimil Babka --- include/linux/highmem.h | 8 +++++++- include/linux/mm.h | 18 ++++++++++++++++++ mm/huge_memory.c | 9 +++++---- mm/internal.h | 6 ------ mm/memory.c | 10 +++++----- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 6e452bd8e7e3..5c6bea81a90e 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -224,7 +224,13 @@ static inline struct folio *vma_alloc_zeroed_movable_folio(struct vm_area_struct *vma, unsigned long vaddr) { - return vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma, vaddr); + struct folio *folio; + + folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vaddr); + if (folio && user_alloc_needs_zeroing()) + clear_user_highpage(&folio->page, vaddr); + + return folio; } #endif diff --git a/include/linux/mm.h b/include/linux/mm.h index c39c4945946c..6c853b0c4f91 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -31,6 +31,7 @@ #include #include #include +#include struct mempolicy; struct anon_vma; @@ -4175,6 +4176,23 @@ static inline int do_mseal(unsigned long start, size_t len_in, unsigned long fla } #endif +/* + * user_alloc_needs_zeroing checks if a user folio from page allocator needs to + * be zeroed or not. + */ +static inline bool user_alloc_needs_zeroing(void) +{ + /* + * for user folios, arch with cache aliasing requires cache flush and + * arc changes folio->flags to make icache coherent with dcache, so + * always return false to make caller use + * clear_user_page()/clear_user_highpage(). + */ + return cpu_dcache_is_aliasing() || cpu_icache_is_aliasing() || + !static_branch_maybe(CONFIG_INIT_ON_ALLOC_DEFAULT_ON, + &init_on_alloc); +} + int arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user *status); int arch_set_shadow_stack_status(struct task_struct *t, unsigned long status); int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ee335d96fc39..9bb351caa619 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1176,11 +1176,12 @@ static struct folio *vma_alloc_anon_folio_pmd(struct vm_area_struct *vma, folio_throttle_swaprate(folio, gfp); /* - * When a folio is not zeroed during allocation (__GFP_ZERO not used), - * folio_zero_user() is used to make sure that the page corresponding - * to the faulting address will be hot in the cache after zeroing. + * When a folio is not zeroed during allocation (__GFP_ZERO not used) + * or user folios require special handling, folio_zero_user() is used to + * make sure that the page corresponding to the faulting address will be + * hot in the cache after zeroing. */ - if (!alloc_zeroed()) + if (user_alloc_needs_zeroing()) folio_zero_user(folio, addr); /* * The memory barrier inside __folio_mark_uptodate makes sure that diff --git a/mm/internal.h b/mm/internal.h index cb8d8e8e3ffa..3bd08bafad04 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1285,12 +1285,6 @@ void touch_pud(struct vm_area_struct *vma, unsigned long addr, void touch_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmd, bool write); -static inline bool alloc_zeroed(void) -{ - return static_branch_maybe(CONFIG_INIT_ON_ALLOC_DEFAULT_ON, - &init_on_alloc); -} - /* * Parses a string with mem suffixes into its order. Useful to parse kernel * parameters. diff --git a/mm/memory.c b/mm/memory.c index 75c2dfd04f72..da8b2e8ab796 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4733,12 +4733,12 @@ static struct folio *alloc_anon_folio(struct vm_fault *vmf) folio_throttle_swaprate(folio, gfp); /* * When a folio is not zeroed during allocation - * (__GFP_ZERO not used), folio_zero_user() is used - * to make sure that the page corresponding to the - * faulting address will be hot in the cache after - * zeroing. + * (__GFP_ZERO not used) or user folios require special + * handling, folio_zero_user() is used to make sure + * that the page corresponding to the faulting address + * will be hot in the cache after zeroing. */ - if (!alloc_zeroed()) + if (user_alloc_needs_zeroing()) folio_zero_user(folio, vmf->address); return folio; }