From patchwork Mon Dec 9 18:23:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13900187 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 7DE9AE7717D for ; Mon, 9 Dec 2024 18:23:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F23428D009B; Mon, 9 Dec 2024 13:23:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EABDE8D0058; Mon, 9 Dec 2024 13:23:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD79E8D009B; Mon, 9 Dec 2024 13:23:38 -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 A7EB78D0058 for ; Mon, 9 Dec 2024 13:23:38 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 51542140640 for ; Mon, 9 Dec 2024 18:23:38 +0000 (UTC) X-FDA: 82876243254.18.65E379D Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2066.outbound.protection.outlook.com [40.107.92.66]) by imf19.hostedemail.com (Postfix) with ESMTP id 4C6BD1A000D for ; Mon, 9 Dec 2024 18:23:13 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=oIFUg6SS; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf19.hostedemail.com: domain of ziy@nvidia.com designates 40.107.92.66 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=1733768596; a=rsa-sha256; cv=pass; b=IccXEZ0p1xBn2bwsXVSfgiOGInmZOpN8GS13cMPWq2egugPMq/vIKUIbe/JXDxFhOIJPy7 Xn4LwOsyJeHCPAbA0cq3IlH/zd7c0eXpgumFYcHqNWYI9FpXoPUNjLc7w1EvCbRvT3awQ6 RVYqtGM6NHo2IQ0k0p31Mi3SOsytHhw= ARC-Authentication-Results: i=2; imf19.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=oIFUg6SS; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf19.hostedemail.com: domain of ziy@nvidia.com designates 40.107.92.66 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=1733768596; 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: references:dkim-signature; bh=gAdx0sWVrF3tvqmv26fdliHIY7NPMMMmEaI7/QoWy0g=; b=6TiWE8/sz4BG3geBnCWpp3M6fQ+4rrjEh3CFdeP9zGPMHOZgp2gcjRrP6FOFk9o2hAlTIf Dg2TyowwtEcEfP8ICLM7y59uyDBM74p3N3WJH5mgFea0VWtTbyJEPJdp8DMoHkQ5zigKIg SZIYI9b+U6QAsMQEi6DxQw8hCuu4BEY= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ehCNyhfnGLwAUvul9DrmgCXYE4aOv9/Pn9prRVb06aZxAMDR3ezouOzgQZ0ZMDm4fMkDkeqfQr4RJJvm4P1d92HINyN+ttCeiYw/K1h3b8ZsmkpebNQpk23OJMAbA0nQjSyusB5eNaC00W+w0k64KwbiIcSLUnxnddtPvGPVZAxtgz3dtJbO79VW4RV4xrgBOMwK35QU2aB7ugPZDnWCE70OTklVIgccZP8ulWKTT04dwrtOkbt26tSvd02rtexe/fVdFYpHkSNK1ioj4XumBwt6VMBvZ93LtRHriG6v1niZiJPAoEKBzgP/VRPd+DjlgYs39iiF8dNX8kHoMGIMxw== 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=gAdx0sWVrF3tvqmv26fdliHIY7NPMMMmEaI7/QoWy0g=; b=xCUvDYZ8c/9ifuhT9cnZHDM2MzVSuXTPD57/Ecpz0YVJvJI+aPKb4CpJuoaWMQ3F6N2XCZFmISL3Ki89oWaU8+ppQFhMFHXvh3cP0fgPsE3WwCQ62djScZHrk3fumoTSuOF+FAmGm3C3acJP38LVhEEuKNcj1xPLNZhv9hqSULY+jkMw4itbjGUWwaRe5q8R7enESB6GOHRIRSk7buc7Zbh6Vo9nTM0h7cTgyDyJ3oFo0NCFEvmiyqZhe7AGJByrLG5WC1F9/vuWaJJTlw7MaIyXb4Bs7+rt8H/+qaNwapYLNlBglo4tur6qmy3wh8poSv0xXHwEMPKCPWk5I7RHuw== 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=gAdx0sWVrF3tvqmv26fdliHIY7NPMMMmEaI7/QoWy0g=; b=oIFUg6SSaRGNPhm6+BYUnHaoDCmZNSlcydcdPuUa4hKGCX8uMKLKuqnj2r0EAXFp4OhYZ+1ec1oli0GUcozhvywOS+mKxfUdQuWZHeG1nXV7H2PVgq+1fj1J+6sWrrjdV5EKqLZartyRj+M4pmUjsNJbrmJpcGlhEAtoBBazlor4nQD9YPD4tmfegIm9pDikAyZeQQi7gyfqmX6myCZ5w55g5k6lplGMs971HRJhFM7zuxdj1IFB7iWOOZhrmmfGRi2nlIVNvvbSlNNDiHtacYRbSUj8r6uWVGhQ4HQPkBdOqQSzYg48M3juxdJnwjid+GnFqQHhVeATv0ZR2HP68Q== 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:31 +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:30 +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 Subject: [PATCH mm-hotfixes v5 1/2] Introduce cpu_icache_is_aliasing() across all architectures Date: Mon, 9 Dec 2024 13:23:25 -0500 Message-ID: <20241209182326.2955963-1-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 X-ClientProxiedBy: MN0PR03CA0027.namprd03.prod.outlook.com (2603:10b6:208:52f::33) 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: 1ae158c4-94fe-46ef-abc7-08dd187e9560 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: LCmJh8lpaxhrcTddInlNGX9+TRdJCXDqgdNrz9EeWcUEWBiQnWP5dW4myYdKHj42dJXnQA1+d30qgsHPfZ6iemhSUAIMtto7yR+T8JmHmpFK4OTu6UxquBh45FCNkp+4B5tVTGIYn0CtACwWFeHGMN0ASUzRiRqhJHtghc1OFUp6dsNXy/EN7MONo0d+U0zhOQyS6h5rWDCeG3uwgRLCKA/NUbJbdBjVbMmNgnmRrHquX69+W3sVNzGV5hoTtB405EfY+OaZgYsTGZnHwDADvvl3plxlb/pXabPF3X9Hb1uEkl+9J5Z/vZBTWRpZjys8kEZIjzVs0PgRzK82Y/PuMOaMtDPqXjYJmLqyyx0zoEs0fM0zUNSmCGT4Lb6WiCjLMpHskkLXzcL51ujGIpc5WnWheYwBUOHoteRE3kFeRp/LD8dpL4/GUjCcM9mXkK7eA86Q2+s9VcamYEC2CPtOY+N/IiOzn7566a/Y5WoKyHKzvBPC/UUisgZY29hn/5o2CQTrtDv/QFqykKSRBGfHq+IPNz9sZyM9aIwB8L4q4srdg9M6Jj4F0i42praoxvXTLE3XZSg3Q2iD2k4QYb4jylODqD+4XgFrAUm7+WHE5CPBISLUgFEmyqhC4IIr+oHsLS7cCZsCD1RmU2vqeSPUYk7YQ/lHlK4w795TltZE5Usr3UW43HKtuiafAznCNJwQFdL70I2L0aPjmMn/kLkh8NGzI0EKeEm0RM+Qpp9KlU2+AFwOENFfINfn/4GZGMtfaN7vEG9z6Ad9BJR+Oj5b/Bl7wEi7uneF2uLvSBJqmRdnN+6EaBAFu7E1bVHb6633Gyr4gO4ms7esFBRCVpF1unx9iSz6X8f8KDvn+WusZdwqc6sQv5Be1m7fTDNgzMUdzVJI6MT2fgfiCjyQ4qu0tN8hqODrXKCPF3cKu+cbghtB+ZXfC5qC1xPbZCEfY+eWHrBYvsSNTG+1iYLDlgaA/KfKGk8zHLCTnTcxu7liJp7asV7akMYfYEI3T84pO4IUKnhbRasX1MAdTdTlVfhktOgkDYT3nQh8jU1tY+AMeqFcCryEDHpXoKOgMw/oAduKy3hrUzo//1jmsEtSd2tdkeuVBXiGn6kXRUWH9UUjJEB6gUTKOhiZkL3KFZU/HfNytvOYQHkY1zl9fDzpkEkdjPAxr6452SACVjCNtGmmDChn0t9WFFdbYMhReIttGt09YtX3Enrap5ZFwDvpVv2ABJYo5aReVdSlFmgI8MfbR/XvWRKkaR2QP2PsR2W0CoYbuCdF4bXec6Y6p+4IsQiN4Mdvas9mnPTzxP3O9yFYNCx4CpqvxLZPo6InDf3/mtc9FzCyg3BLDJzQE1RB0cE88Q== 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: zTposcWj02qdxUeG3tW4gFkweDYh89wik2tTj1v1O18LmvhXXZavFxMMmjgJkTaRUw9aed1zRLR3Ueu48hpasrPR40HzhuE/1j6DWreImQanqhFAKYFOw8SDZvbkAEctPnJXDGi+SDavuJP8rr3ufTDG3gQZ+TVvrMmsBGQSk2xUsrJlQjY8csnHr+56+2NPBYecI2PVzFVv2RprzARcluoMAt3vPywuDdQRF2xVVWCRhO9CeGEgB9LqYroa++SMXZyOXnHf6w57IH7sKJo9KM1odLe1uaOrHyssBNUdfNXSNgskTfVqSyt7KO0OakqmL5GH1cB1VZCwZs3oDWmLoIE2N+iNV/4KSAR6ii7BcQgyNx3jxhgiP48KeL/Re93RjMUFwUJB9mBp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Q+BtXEgR7dgWUl78TNcXu+Sj519UHSUDJ7h3DO4meFfY+ZjxuVHOt/4c7czekpYPQh9FqlJ+mxelPIJy0TJsz/coxc1xsJQsj/K6OEMiAfxGSF2 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ae158c4-94fe-46ef-abc7-08dd187e9560 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:30.8779 (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: UQZh3n0iHd2oti9m0bS/qgdp5J2Fw0Zjqg5TTB2Q5k/W6ya9cNwi5/U4V1VdlO+l X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4487 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4C6BD1A000D X-Stat-Signature: ky19eebnkruk8z3qdmywo4h4qypwqwmo X-Rspam-User: X-HE-Tag: 1733768593-500904 X-HE-Meta: U2FsdGVkX191DQAlzB+jQxcJZbei3KZ/EDB+HpBz3PusV3p+4QCdIPLyKSvEWrnCDN2EjJPegpo+wMRL7Yaq7tsxZmjnkdWWyf/+cap8+7oGKDsk4ZgYfrDpmc+dwobm4s/V9nmZ3IZOXbPbhIOBdfKQwV01M3v+jyCnZZItoW9XQ4QRmomZ+ojhOIc3pFFnKe9CpS5HrE7ZUm4jnqF/oEPJP+mGc53xvETMgGwV8cJStwhTq1FZic02ufWD9i/cB/guBCm9Qh+DQvqk3g7R6iNLNwATsJvgqw8lkeYQTsWJFBAEkm2ENcr6Ev8fIpMQqej3ZbZAev9IM36gs8x00UsKAGGiz5k+n6tS80JrFf+sKvoZUOAtZA6Sceo8r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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: In commit eacd0e950dc2 ("ARC: [mm] Lazy D-cache flush (non aliasing VIPT)"), arc adds the need to flush dcache to make icache see the code page change. This also requires special handling for clear_user_(high)page(). Introduce cpu_icache_is_aliasing() to make MM code query special clear_user_(high)page() easier. This will be used by the following commit. Suggested-by: Mathieu Desnoyers Signed-off-by: Zi Yan Reviewed-by: Mathieu Desnoyers Acked-by: Vlastimil Babka --- arch/arc/Kconfig | 1 + arch/arc/include/asm/cachetype.h | 8 ++++++++ include/linux/cacheinfo.h | 6 ++++++ 3 files changed, 15 insertions(+) create mode 100644 arch/arc/include/asm/cachetype.h diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig index 5b2488142041..e96935373796 100644 --- a/arch/arc/Kconfig +++ b/arch/arc/Kconfig @@ -6,6 +6,7 @@ config ARC def_bool y select ARC_TIMERS + select ARCH_HAS_CPU_CACHE_ALIASING select ARCH_HAS_CACHE_LINE_SIZE select ARCH_HAS_DEBUG_VM_PGTABLE select ARCH_HAS_DMA_PREP_COHERENT diff --git a/arch/arc/include/asm/cachetype.h b/arch/arc/include/asm/cachetype.h new file mode 100644 index 000000000000..acd3b6cb4bf5 --- /dev/null +++ b/arch/arc/include/asm/cachetype.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_ARC_CACHETYPE_H +#define __ASM_ARC_CACHETYPE_H + +#define cpu_dcache_is_aliasing() false +#define cpu_icache_is_aliasing() true + +#endif diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index 108060612bb8..7ad736538649 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -155,8 +155,14 @@ static inline int get_cpu_cacheinfo_id(int cpu, int level) #ifndef CONFIG_ARCH_HAS_CPU_CACHE_ALIASING #define cpu_dcache_is_aliasing() false +#define cpu_icache_is_aliasing() cpu_dcache_is_aliasing() #else #include + +#ifndef cpu_icache_is_aliasing +#define cpu_icache_is_aliasing() cpu_dcache_is_aliasing() +#endif + #endif #endif /* _LINUX_CACHEINFO_H */ 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/3iwxsn1B30HxWL4NKDrkwZssEvwft3Kw4MTbyEnNJ4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CPA2wn1/LDu2PDtiKPD0riLqB/E7ILcq1yZiOS2pgg682vL1kGhSYLx/pWId666yGSpFgJUHY/Qx7xuaH9ks6tKVxr7u0xvddPbytgHjuMeI/n+NKbOf77EH+NvW+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/o8lbln49164f7l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GWlZNFwVsev2S+f85AUeeuY4Ts549AMzKYMfkpGS2Mp8Wne9t2ya+YzB8wIo2/hgNygxRjhII8wrpBxpgBCRk0rUpAxc844sGaceOF0xyqODhoXbnuy99+D6JRVDH0RTsLYKG3vCJmClm/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; }