From patchwork Wed Jul 24 18:19:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hailong Liu X-Patchwork-Id: 13741243 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 8D96AC3DA63 for ; Wed, 24 Jul 2024 18:19:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDBF06B0088; Wed, 24 Jul 2024 14:19:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D88166B0089; Wed, 24 Jul 2024 14:19:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C017A6B008A; Wed, 24 Jul 2024 14:19:48 -0400 (EDT) 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 A26806B0088 for ; Wed, 24 Jul 2024 14:19:48 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 16529C0B6A for ; Wed, 24 Jul 2024 18:19:48 +0000 (UTC) X-FDA: 82375459656.30.4E1C23B Received: from HK2PR02CU002.outbound.protection.outlook.com (mail-eastasiaazon11010020.outbound.protection.outlook.com [52.101.128.20]) by imf04.hostedemail.com (Postfix) with ESMTP id C689E4000B for ; Wed, 24 Jul 2024 18:19:44 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=oppo.com header.s=selector1 header.b=GMLtglCU; spf=pass (imf04.hostedemail.com: domain of hailong.liu@oppo.com designates 52.101.128.20 as permitted sender) smtp.mailfrom=hailong.liu@oppo.com; dmarc=pass (policy=quarantine) header.from=oppo.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=1721845147; 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=h1hvv6l6sPmJh55CzdkxaTUmd0k2dAxtpiFWX07CLTg=; b=VEXCfEwWGPQuidtvFVDlGzV43wUw06838kw2DDbBHHWJVPcVQQCE7zPllhZnQOpc9zfbec ntb65LQHku1oEldSA3R225pxnZrP9ileUqUkcytLvI/rSMbARFyz5v1O0dpAlbTzKUxLGq Oi4CS3ae6R1PnkgiBqtZGy5stuDiAHU= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=oppo.com header.s=selector1 header.b=GMLtglCU; spf=pass (imf04.hostedemail.com: domain of hailong.liu@oppo.com designates 52.101.128.20 as permitted sender) smtp.mailfrom=hailong.liu@oppo.com; dmarc=pass (policy=quarantine) header.from=oppo.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1721845147; a=rsa-sha256; cv=pass; b=xsLW7naFUOI8JkUOwp+exgLy51L5miEoeq95HH6UrrbF4/u0RE3fb1e9B/CkQz65J4UXvg hqG/c5WcEcVxDNqzqvwP4ifKpt8cjTcDrQYNzuTr06d6w468qTUcORBhvLeB0bynw6/+ik Z+ekl73MQf6r7zqg8zq1KpLID8eAMCw= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TaIlin7A0MXxFYAhy2Mp3Mly1gXM3vF/BX2TuAozZwImBSU0ZuHn+YoqrQo+SbMV0ThCGYtXujY//Kn0x49qQJOgti5S7yw8GB5dQA79uGVhi8CdkM3aXBl1zWpwL8lV2Tqb2uZn10bH+826myeDiw99PytgNaa5956G5fCzPnwjb4ArLUbRl5VcfEKY+unB4dfQos/i8xqDKRZxRjeHNwR6+gU6c4gVLRk8u9wJFQocitrTZ//OPXq7GdveYSnYwpMZqRAnDZBqEjbXQ3VuzfQGNGhHwN5Ps++BBZhpNBkLGhByVCG3VVq5Y7nlpo4eX9llgUzqqHEtE9wjv8b/nQ== 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=h1hvv6l6sPmJh55CzdkxaTUmd0k2dAxtpiFWX07CLTg=; b=K0PiJI0c57jcZhjUlfa6ko0Q7zRr7BAuPdZqDMPSvC30EgAv6GGiopfjTQtFJ79JRLqSdCFs2YQ9FUAHw+Y/MxtkQ0iX7Yj0UCngksX1vot3qP63nsVAMJ5XyZAglgf0jT8Ny2s8ByyopoIr1RlnsAuPXGqDRTLMi4UDQhrdZjKyCDFCn3nkQvsk6PXHRdjnGwcYExrhi2DQ7kPVoiz3jgGNXCDT44r87GdOPxOSsfn2DCu5KX9u/n7zJmSYvf4i80BF4nTUrCvAuwWuPOPlah8s5BjZgXujJicb6vSGgEPFYAMgbGDMzcSNyyGRKV3JgJ3TCTffGcPhhF1dqT874A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 58.252.5.68) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=oppo.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=oppo.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=h1hvv6l6sPmJh55CzdkxaTUmd0k2dAxtpiFWX07CLTg=; b=GMLtglCUsCHEFXj2o5bei+j7uPYli+hcHJLCET62P9ZG7rlJDUJnpYmxbg69v++Uvg16ceITfLOzVPQToqiAMeSj5z0p2+u0D3Gm2DPUSd4Vk0JVUoF+NR6iDxgxlqctG7cUjOGfK7VTBIeXF/PWynobs/e+2I57JAdl6NcodjE= Received: from KL1PR0401CA0026.apcprd04.prod.outlook.com (2603:1096:820:e::13) by SEYPR02MB6460.apcprd02.prod.outlook.com (2603:1096:101:14a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.20; Wed, 24 Jul 2024 18:19:36 +0000 Received: from HK3PEPF0000021F.apcprd03.prod.outlook.com (2603:1096:820:e:cafe::4c) by KL1PR0401CA0026.outlook.office365.com (2603:1096:820:e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.17 via Frontend Transport; Wed, 24 Jul 2024 18:19:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 58.252.5.68) smtp.mailfrom=oppo.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=oppo.com; Received-SPF: Pass (protection.outlook.com: domain of oppo.com designates 58.252.5.68 as permitted sender) receiver=protection.outlook.com; client-ip=58.252.5.68; helo=mail.oppo.com; pr=C Received: from mail.oppo.com (58.252.5.68) by HK3PEPF0000021F.mail.protection.outlook.com (10.167.8.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Wed, 24 Jul 2024 18:19:35 +0000 Received: from PH80250894.adc.com (172.16.40.118) by mailappw31.adc.com (172.16.56.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 25 Jul 2024 02:19:34 +0800 From: To: Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Vlastimil Babka , Michal Hocko CC: Hailong.Liu , Barry Song <21cnbao@gmail.com>, "Tangquan . Zheng" , , Subject: [RFC PATCH v1] mm/vmalloc: fix incorrect __vmap_pages_range_noflush() if vm_area_alloc_pages() from high order fallback to order0 Date: Thu, 25 Jul 2024 02:19:12 +0800 Message-ID: <20240724181916.31776-1-hailong.liu@oppo.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [172.16.40.118] X-ClientProxiedBy: mailappw30.adc.com (172.16.56.197) To mailappw31.adc.com (172.16.56.198) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HK3PEPF0000021F:EE_|SEYPR02MB6460:EE_ X-MS-Office365-Filtering-Correlation-Id: 5ac32c98-091e-4e0c-9d30-08dcac0d2c1b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: mwO9aj0wDnauoAeo09mnb+eftJsQzgsE6z7VZAYEWjAEPLW0JseqK0ppOnwBZRHRMMUZ1PLTmCziiC4W4xi9Ah6u75+G+Roo5VQjh9TUhDuz46Q1v9gc8tYW4B1zBRr9Rp/RKK97hvMm3SC+4wAzk/XndysxBVQTeqLpnWjp3nqgGfMnFBtHKVzzfyubNPI9qLxZhB8lA3TvziyaViHVNrtGj6FBfH0cyAmgZ+JFP5taAurQ0IVTwz6vRDL4hpLQpE8Hy9pK77OaU6LArOVipxUFWVjjDIOq6cEKYRT43TB7cOROqE6EunX6T8UZrzUk1v3S+FLsLT4DUS3F0f2zDMDF1SiuBjK4sohB7UblFbqxr4tBxZpNqvwEySGmaqDSANU5YQyK4IHALF/C/IdRPAwHwMm6VO0OyjcLxVJF+YWUkdslPxoab12JjP0UR+/6OjrNq92PFNTyyfyytpifchIDt8uJBIuefKqpk+EeP0yujEzjp11Sx8BI5fsmP/pMQaXt0jmOzzKSldcxqFHUFciHlOMRz5GlG+cfLk+d/cx4aqDkgifMELLmH5TJRl9ZF80YIifv7wtlA3j6QdE93fyoNmVnTxxHFzmXbDTVxw39Ybhg7WpZLFXOJZZvVSXrkLJYcivjiRw3R2XKunCDuvjYSPqzXA0qnVkSr3Cdb1OOyM8qMHx4boWBYGmdRmjwxpwMca2PHHQholj/bimcYB7d7AynyH9jB6gyRNQ0ElVxMTT6eWnbC5YtI/JlfXqjEdm/AJdAFbcjx37459BRRoxT2abeo8sDO4BYcv0EjAMAkZt4TTWJrUFIcWycFj4ld4KrGQ0w2LoY9YoR8RcSCjqYig763kl74PJHA4qlDo1V7Egm4UvX0x1YuhrjrC/0eOINDLzSuk9jvwiUzT0kDC9g201+FIDnIFxXT7S9/pMrs6b6cnYXe8ZlwYH7wHnyR6ZdDoXFyey9s1utLNPi8DHDdpYQc0Hc3dYyXz8XtSAGaGPuF5KgEm7qk2Vc5Tgyeh+ogtrBFMzBEOiicDHHF1FBdUHfD/VHZbgITmJzpBrTyQ7tzNONO2LiVHqgZRlTZgJFUPnXVzSdXDM0v7+M+rQ8oJD6fR+KaFlTORDmhX8rSORb6YRhRbokw4XuW9/xwVtZSap57RFa2lgrmBe/bQXnu0clQ5LqkGuiJCS4TffnIjnKBbxwLnVHAt6mLtgl2IsGal4z8Cc6hpUmP5bXtNoY6opm6K5CCVHgCXRqqm1uvkVaTzzRei/qISLt0eHWB3r7Pe5fsxuzzi1IfBO4wDWnnEJwgXmaYQ3gh6301X0GYOxOx23oKZduZte74yndGehKjAtWeFEUSsWD1lmXU7a9otSIuIqCWv+92rM1tojbPGFwx/3BlSK0pVUr5QwhOvAFoQWsg1VR8upk9vIyywk4AAz/kdjVEHm7vt8a4cZhC5zDQQIuZ94zM1aFed5v X-Forefront-Antispam-Report: CIP:58.252.5.68;CTRY:CN;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.oppo.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2024 18:19:35.2764 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5ac32c98-091e-4e0c-9d30-08dcac0d2c1b X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f1905eb1-c353-41c5-9516-62b4a54b5ee6;Ip=[58.252.5.68];Helo=[mail.oppo.com] X-MS-Exchange-CrossTenant-AuthSource: HK3PEPF0000021F.apcprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB6460 X-Stat-Signature: 9s75gfpqego9syxssr9h66w5sxgsww3p X-Rspam-User: X-Rspamd-Queue-Id: C689E4000B X-Rspamd-Server: rspam02 X-HE-Tag: 1721845184-779371 X-HE-Meta: U2FsdGVkX18FE6noT2TJN780UvpFx0JyGgngQCAhuq4v3y3c3cTiGzG1v+OBSPjCLCaRvEQp7xHpsunRtr8MzMA/U2KB/y4+hw6/7ZtjF0slcopQC0lTBR8Oc2ffm3EXsP4PTive5ln03SfSvHKpS4T28KXaaVrc6GtdDjD59QL92OLuwymRhwca7g5QSvS8F/rQ46Z6OAc1yUHGrCSoP75X0CFue/Mdsc5QWA/RjdBvHWLdAkyANpI9IlujDmtzWCVYBoFYKTf0E+O6UkoTWU7CTKke3RVqTE0VectnQK83usozKYWRrQRBx6ZSIriWr3eE6NJpgev41njcMdhP/GaDooySK3QXcG65RRhxavJLvKjLaZieFMroxWh4VuhL0v8gIAcRG8y+fyh6ktNVEjzonOz4sHc2tI/F9fsCRpPKPNFXw6YFLN0Sgymn5DqXX2+7WUAnjgRBQQPUL2p5jjuXUSRKfnmxqPcA9vbC26GqQ+s/AyY3SP6msPHz4L8hWkdBz9LcDh9GWK36/aDSGrqYws2zMYyasC9mSZ+G1OTasVi++W7WfnvYMzEG36gwHUyUnvtpJ1cOWq7nXTZC02AAVnI3002+ErJz/eiXDtKuNDwx02fh0u+Fufiqh2xqVM1JEoFNuQQO98aHWbIRApt540wRPCEOH9gHuezGzD24H5XKK2O8UrLaWLoryx1VhhuMDQjCJ3fEuUMiOwjr2iIvOo35T3uQPZJDZN1E0c0EJHLSbh/s1gyXuQBPdUrlqFDItRlvE2co0Voly9rOYg53rNyFklB9ocNtuwo9Rbq1a1vR9gdE2+4QKosnWM9pC0H6fpdXxLo32hte45ActBkAtb/7hUUzhJDNBnSuhnxAnr+B4ltM2A+/6ZVAa7fg4ys07ruULSfJPVFNPj0glZWlFmKcNCsS+khuM+c9ZKUUZxa6SS+ZhMw0aYHLB8qjSqWDecM1G7wo7nDLs1C C2SWqDQL a7fX3vV7PQFP7PkD5ecAxjBp2jyYwRLS0ugO+53F7IODMA6e3UlsLkaXWeNP9nl3jMb+9r1UCbk4SwtK4b0xOyBTwI1WTGK6WNn5XOwyze4lb4fGddhZwNKGGFG7Ptz8smDIy6gjk66UQ6+OnYGjMrtynNNlNLfr7R0ymy7UQA7hkwFe5ISLW1ocS+wRAAhf/bjCVNdpksWH8iPgs1wcatN1cr6nwBIpLunYI/RCJdS3QJh9waRmfgkmHugQEW74tjdUHSsjdx+BY8f+t5TE97TiXRmq6datJowt8IAGkBZMuLhCFwZPFBw3dKhMAstoqUSFHiYffL/pdu6OstkyW+NIlgMJq+o38iMQYUl83BCSwJ6mBD1LbXEfydPaEfUhfykQaZH2pbJkAFQbBod27mvFCJdfu080IHpN1hHB6Kl8v1wIUPw+Q5Dxhv8f/i5mtrzZZAZ7xxOTDHptT2D/MEK2scXD2evsayVw25LS3v7OwS+Q= 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: From: "Hailong.Liu" The scenario where the issue occurs is as follows: CONFIG: vmap_allow_huge = true && 2M is for PMD_SIZE kvmalloc(2M) __vmalloc_node_range(vm_flags=VM_ALLOW_HUGE_VMAP) vm_area_alloc_pages(order=9) --->allocs order9 failed and fallback to order0 and phys_addr is aligned with PMD_SIZE vmap_pages_range vmap_pages_range_noflush __vmap_pages_range_noflush(page_shift = 21) ----> incorrect vmap *huge* here Fix it by introducing VM_AREA_ALLOC_PAGES_FALLBACK in page->private if fallback to 0. Fixes: e9c3cda4d86e ("mm, vmalloc: fix high order __GFP_NOFAIL allocations") CC: Barry Song <21cnbao@gmail.com> Reported-by: Tangquan.Zheng Signed-off-by: Hailong.Liu --- mm/vmalloc.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 03c78fae06f3..b35dfd3eeee3 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -75,6 +75,8 @@ early_param("nohugevmalloc", set_nohugevmalloc); static const bool vmap_allow_huge = false; #endif /* CONFIG_HAVE_ARCH_HUGE_VMALLOC */ +#define VM_AREA_ALLOC_PAGES_FALLBACK 0x1 + bool is_vmalloc_addr(const void *x) { unsigned long addr = (unsigned long)kasan_reset_tag(x); @@ -604,8 +606,13 @@ int __vmap_pages_range_noflush(unsigned long addr, unsigned long end, WARN_ON(page_shift < PAGE_SHIFT); if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMALLOC) || - page_shift == PAGE_SHIFT) - return vmap_small_pages_range_noflush(addr, end, prot, pages); + page_shift == PAGE_SHIFT || + page_private(pages[0]) == VM_AREA_ALLOC_PAGES_FALLBACK) { + int ret = vmap_small_pages_range_noflush(addr, end, prot, pages); + + set_page_private(pages[0], 0); + return ret; + } for (i = 0; i < nr; i += 1U << (page_shift - PAGE_SHIFT)) { int err; @@ -3583,6 +3590,7 @@ vm_area_alloc_pages(gfp_t gfp, int nid, /* fall back to the zero order allocations */ alloc_gfp |= __GFP_NOFAIL; + fallback = true; order = 0; continue; } @@ -3608,6 +3616,8 @@ vm_area_alloc_pages(gfp_t gfp, int nid, cond_resched(); nr_allocated += 1U << order; } + if (nr_allocated && fallback) + set_page_private(pages[0], VM_AREA_ALLOC_PAGES_FALLBACK); return nr_allocated; }