From patchwork Sat Dec 7 16:55:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13898339 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 A554CE7717B for ; Sat, 7 Dec 2024 16:55:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 340DF6B0339; Sat, 7 Dec 2024 11:55:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C8E56B033B; Sat, 7 Dec 2024 11:55:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CCBE6B033C; Sat, 7 Dec 2024 11:55:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D706C6B0339 for ; Sat, 7 Dec 2024 11:55:33 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 942B0A1F04 for ; Sat, 7 Dec 2024 16:55:33 +0000 (UTC) X-FDA: 82868763306.01.8723C6E Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2067.outbound.protection.outlook.com [40.107.96.67]) by imf17.hostedemail.com (Postfix) with ESMTP id E087140003 for ; Sat, 7 Dec 2024 16:55:16 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=ZHnwWI8t; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf17.hostedemail.com: domain of ziy@nvidia.com designates 40.107.96.67 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733590512; 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=lFymnYIwzybc1lYwKoXrwnk6I4MsTHm/oq5M30dD9SA=; b=MBHeb8H2ZEkHB7O22Cj2WKlgNxTdyASWxk/q4oYxU/EB308vd38EMHEiPqxbnFbDFshf+y vrVz1VB8ua3oTPdNCy8CxW3f/c1lBo5EdoXVefGcTqDy8cUJ5NY65gBAivm+AJ+l2NeFOO YmOrCTUWpB3+xmvvcI6Kk53PAzhsMiU= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1733590512; a=rsa-sha256; cv=pass; b=RMEN9i3zTgoJbMBg0eY0o4a7utuHIwJ0VyaevFwf23llxE6Y6Wx94vLy2vYl0AI/f0hBbf H0Ra/t+XoFCwiTff7JHA5J67nShOmEMVEXpAenaVjHbj596RsDf1aa/u1cG2pUFcJ05ljy di75BzaHprHoSVMd8+ry6VVKex3VCpw= ARC-Authentication-Results: i=2; imf17.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=ZHnwWI8t; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf17.hostedemail.com: domain of ziy@nvidia.com designates 40.107.96.67 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KRDU83OkNRVGutl0w4MmMFptf8/NmNjBGb6n6fli3OL+8O3msTsRQoYxsWMYO2eUd53+GjyxfIjpQX/i5bH0NEpcaEDdTEjqlksmGas9hCw/R44UKA6lsZRtyvcIvIBG/5mebMOIpHaIEN9Kud5v8l2AkD/2GirOPzsrHBeAow+WxKSsfxRY8qjy5232K8aPDPhwnoGPDtQi1O9yYpKdIpdZi7+mqSGGUEvZyx1dj9CdOA081zU524KYPYYcPFWTDDbGfxEHpliWfwX75BSuzOUrjTp7tGlMtFFtUWg6+zYgQ6lTjaYZ+Dbda0SBigvEQUODCmwdtQvW0C0qwU0i1A== 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=lFymnYIwzybc1lYwKoXrwnk6I4MsTHm/oq5M30dD9SA=; b=WfMpszucI8OD2QLMmQdUCjyXD6UzoDuurnWr3Rihe7bXuEqWIc6VX/5z1XcieWIp9aeajr8BmNaZeK/JeboBJzYV4LRdWtcFCYFTT4o3FvfFcwxhoGkLfRdezl2pcy8b2W2Hnc2jY7V3hGXzHcj4YA1RU1ZLOd7Nbezqw92Yvczw0MMFebhU3/6tO3gPaKOWIiqc1MpmCustJX66oFoPUcuz2W316krF0kxIKYNcciXS3/VERFJ6WorrIHsJ6BWtUznFjrzMpKj7Jlu8hL0Ij1jPzgNWpst/yGKHxHLQHjhX8FGCJ8Hmvdjxqc4HkZz93NN9t6hD/2qDsYaBQ+vj6g== 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=lFymnYIwzybc1lYwKoXrwnk6I4MsTHm/oq5M30dD9SA=; b=ZHnwWI8tw1GAvxMP1xppA733jAVQ/gm7+QTbrBOk9AAEu3RFUJmu0Ci7l5bUTiLaVNC2nj1PFEj/+q5ggig//LBcVaZ5z8mxw23mvtCskNZtEm87TSvyCZafausfSp7GDK6AY0Toduw1S6l0lDKuxt09MhwbcJARaqP2d5RVChhK/ZC30071acM9qEJf2tvgsTdRjlr6FaaYBgd0ePsCCV1DMprDhK0Uf0t3e8jbDC2VEvwjTrtqtqW/+VuRKEBHMbcjxbT+Yw+cKe9eumOzrTdG8VF3AIoTVJIqvt3d1BBVOR9B/tUD4ktTWEHhrvz/9WcMg53VmWtKDFKg+fZjyg== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by SJ0PR12MB6735.namprd12.prod.outlook.com (2603:10b6:a03:479::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.12; Sat, 7 Dec 2024 16:55:11 +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; Sat, 7 Dec 2024 16:55:11 +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 v3 2/2] mm: use clear_user_(high)page() for arch with special user folio handling Date: Sat, 7 Dec 2024 11:55:04 -0500 Message-ID: <20241207165504.2852058-2-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241207165504.2852058-1-ziy@nvidia.com> References: <20241207165504.2852058-1-ziy@nvidia.com> X-ClientProxiedBy: BL1P223CA0021.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::26) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|SJ0PR12MB6735:EE_ X-MS-Office365-Filtering-Correlation-Id: af7466e2-8880-4c69-543e-08dd16dfe97e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: zlI+7oHK89o3KMZqk96F14Hc8k8mwdZvpKJKp98yRmJQ6CXx3fLNmldTzaXiyxIOAxf7nqOSofZdMr6gLAkpz1eiddHwP5WxVzidt/FFNLSXdlz8ioLaYMgyc82v0JaoWWt901yVJG/lyhNAHigPVHXnOe/Sc8zwr/GmM9ZUri+t/rzcMZu6HhNDhaJJ4Gjlzkg3mScWkqTP68MJt6De3VhPO177r/Ebxd0ZQDbK36jaBiEBOUcyuCDKSyj9cXv83c0plxdpUM8+dTM/WV5fbL3p+f0xw1oag98M7PxHawTFK8DYI9eIhjWWnJXHTSH52cCe5FuCGTu4rsTfsKZMVg9LmAqcIyIbwH2p+NGBtwt/jcPulvFK3KOS6j2KeYpFFTJYcoYIMu4lOFGjkLoP7qje3HY68Lpe+VxfAcUhF+7GER72jrKk41opT3rcv1vanoY6to0G1jzaiI4On9SVkG39s0lcrmAncdIXYByYgINVVKNuxr/F6WjJ/VY+hg98cYj1DVn4zL+wElCpebeS6Ks+91Rj/qTpMUYIHPlJnpp/5M2qToMIW2o5Eo16jg6t/3OevTjGvrEzPmySQYfazMRA+kRnM4X1iZdlTtblXf371CXXuTu0KNxxU3tYOXaoZJM4FAEVDe1/FU9h978WJuCbjK5P0Jgp5Y5LfMglgo8Zjdrdwt3MACCDQaLwZUjMTevCyDmx+i/UHYqSKjeHEIzhv6+Qsuc/LPLHAFP7l1h0eiEm7ULUXqAuZndkw6EGxpI6GE03JQiO8/vr6A9oJnigltzuXOALHEXaS8kZHkPKnTxbEsyot63gs4BdjvaC/JVbNUcsBJCyL3JzrJ77riEmWOvcI6EqRUJpRk3GFZuX1+tt4YtQDdtifjukj5nXyW9tDDBVnSSgz+9yYmO+LO0XeFhWFJeyHz37w1vVujBpnJS3BgqVgSde0IyZ3m5LBYbZwKttzVHd+GU2CfXavp74swRlXVTCnOsRapMEyLJYM955Y+gGAC7Wnkr2HywyWX+ZVChTed0igEIUTVfWaOvwGep5yDVN/xp1aSr2L7yZir9wepmTyRQD/rPCpSu1z4rlnDRRPQgSNul1rlf1YPPbUrHPZv+8eCbjD/CkD2gWOXL5mr1vCMbb3lVQsbM0X/cGqS0u1tDH0TdJ1Tvp1D08FqLn/p6GsiXuXwY/Qnwsv0lP6lmBMY3+4/fAqq/2QJG5arrBgx4qhFYPrj1BdpFIhXjDBV+rXCdo/wULzUZ8S1iY1BSipq9k1uOFEupgRifdx1Io679fPMoG69gVqtUVJdn20wNJO1SxRFTIvEle5QICDx5lgVcLuFAG41GIdWbBG51Mhl4ix0aIMwdtj2z9PMEqwpNIFMKDJ2Q6BSY= 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)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nRZIhenbTdBVJSHcopmStKGcc4DeMe+3FUunW6jBSAHcJ3XTKWrcFZCxtyxajehpGEVv8hpsZ5VbritZGDseP92+6zJurde9e+CndBCSnPmvm4jWAAOxCDf/fOoXZQGShgsrh9DKWrxJGA/+y9LbNqETez8HawkH6xblFOTogfjWFsnoHR41NOsKyaW3rR9xIfR/LhoosMwcvYCSyozvOpQIbQYuXryPQPf5a9XihbJAMlYlhvbvgo8ScLTNFUUTpyA8GNg4VxR+q8+7ePTusJyhcPqpr0OxSn5VpG1kCTbsojovuxaTF8QsUct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ztxa56wH2JBG8ghQtr6WbHifPoLUdRv3t3W9KCMUXcY6AIsDBqhVg3F0CSyUeic5PHDh3fiCbv5toJIMb+7nAgqNtqpaslT8AZOEaz4dUnitp6h5Nr9jQ7BIlbOWx11CMAn5n8qtco4c9KH1Y7e/xm3xvUr/VdwuzTD5eU4I/5r90dCH1fxRLu5Oa/hD0K5NX62S875vqcJrLpyR5xO8+jw9aXF X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: af7466e2-8880-4c69-543e-08dd16dfe97e X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2024 16:55:10.8389 (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: zJPdy7woxaLIwUhFOFwDNMQwlkScUHWjgGUAfWRhYEoV3vNRimhLVbBi0A1iPnpQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6735 X-Rspamd-Queue-Id: E087140003 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 1xqjtm8nuozt8raunk7z9owswpes81ap X-HE-Tag: 1733590516-376966 X-HE-Meta: U2FsdGVkX1/D3Yxqj/N90Rxl7sAPQ3z1g++4gxNwvvFghEcGkzmxoPjKUF/3rZtbTkWcNHU5VwStWu3WOlnXkP+kzPhAMVTpKY44DN4xDgWGY1MCv+plC2WqCzTgqHBFiuHiIhQ1OLbvEGSDsEg8/Y+wPazJD4NbH8ACpSLppM0TY232P0CQ1h2mcEohwkMqyXRB8I4aduRVKVwqfv2MmzQUFGjNteieh7KJIfqcPKIj8XT6iMc2kgk27pdml52tE2Sx+aF8hwOTtaIeVOeIt3SAA2rjY6CVfV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4MW4lPfAEFWL0Wog1MzjZhaeVp3heXdm1SUZ0GbYnXPbThJ/pY+VCx72PGGgRp0t5/VSi5JhR2LRzfx1Nad70QL17D/M8sceCqBC5pkIWemuGvXq0grmS/ByvVe+t1kA5ah/TyJD3b/7RvFwyUtnup0GQceAxBZ8= 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: For architectures setting cpu_dcache_is_aliasing() to true, which require flushing dcache, and arc setting cpu_icache_is_aliasing() to true changes folio->flags to make icache coherent to dcache after clearing a user folio, __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 alloc_need_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 --- 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..d9beb8371daa 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 && alloc_need_zeroing()) + clear_user_highpage(&folio->page, vaddr); + + return folio; } #endif diff --git a/include/linux/mm.h b/include/linux/mm.h index c39c4945946c..72d644cc8d9d 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 +/* + * alloc_need_zeroing checks if a user folio from page allocator needs to be + * zeroed or not. + */ +static inline bool alloc_need_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..107130a5413a 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 (alloc_need_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..cf1611791856 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 (alloc_need_zeroing()) folio_zero_user(folio, vmf->address); return folio; }