From patchwork Thu Jul 25 03:53:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hailong Liu X-Patchwork-Id: 13741536 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 91514C3DA5D for ; Thu, 25 Jul 2024 03:53:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CED446B0082; Wed, 24 Jul 2024 23:53:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C99A76B0083; Wed, 24 Jul 2024 23:53:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B132F6B0085; Wed, 24 Jul 2024 23:53:52 -0400 (EDT) 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 91E906B0082 for ; Wed, 24 Jul 2024 23:53:52 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C62F5140DA3 for ; Thu, 25 Jul 2024 03:53:51 +0000 (UTC) X-FDA: 82376906262.01.CC35BD8 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2078.outbound.protection.outlook.com [40.107.215.78]) by imf28.hostedemail.com (Postfix) with ESMTP id 40D94C0006 for ; Thu, 25 Jul 2024 03:53:47 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=oppo.com header.s=selector1 header.b=wSiUlbpE; spf=pass (imf28.hostedemail.com: domain of hailong.liu@oppo.com designates 40.107.215.78 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=1721879604; a=rsa-sha256; cv=pass; b=tN0ldS51Cy3YH/9eq0RCylj/4Vb+pYdXTgZEdB6X3jokG5aSggIlJQiXGcxcHXuh1RROOG VFyf1f+fxVY3wNvvJ2xN7XlUbEiSqhwp5fVNXImIO15noeMh0w1qBajC71NHymMlUR6EqV V/fafxMMBdps104L7/OIE/lcwZDG2nU= ARC-Authentication-Results: i=2; imf28.hostedemail.com; dkim=pass header.d=oppo.com header.s=selector1 header.b=wSiUlbpE; spf=pass (imf28.hostedemail.com: domain of hailong.liu@oppo.com designates 40.107.215.78 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=1721879604; 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=tmnIhMzJ44mVfaOUTSFbb1BP8k4pmqbGQeixeOFAlHE=; b=eOpS7QL51LImLf0w/CL9qjhj9vWXiPfb7XkgobsgHt7e6bP085cbzQEdr7iAH6DqXcWANo FCx4QivsAG6VWpAXKGAZm/JxekmYXLrvoGlY1CnDBouu/pW6MHWJ7lNXCbRP2V1TcB8ZXt pwmUIExzxxfpz7oKjbgXFgDXbFxgd/o= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RxbW38cibKc06RAVvM60ifKPyAff78tECCNtr4tdABsru8PwpHh1mTDiXfh1qDB8J/gIYX+ZIa1pe0YpLSDs+vu1nf4hCH4TTUr9KRjjXj79dL4PLNV+8gSPHbam24KJo/QjPbk2VAPTS2RDOIlsjJAbwcNXQV++5tl40TsPaR+pJ6LklA9O6ex9rGS8g3LtDETTWaGcTo9Q+48tqfNQxyUr8VTbJej3q3E3aDRlTnZp+iMqoP7+RsJj9AU27obC3Wvf7Vam54/dB+xeHE/B/prFCGcLz4mH5Ymo9dNaRwAB+MYcEtczRUf+qAgrGGcA1TV2mqM7pMBSTEl2dvIRuQ== 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=tmnIhMzJ44mVfaOUTSFbb1BP8k4pmqbGQeixeOFAlHE=; b=ovLmrsW4QcjhuG0fMedlvZHVLFhQXQZgx+gMjT8MkC8xLxtO6vFgvLiUUuluaDmu2wfZLuFgYZPBrCJvbEyxCxCOrvtefdAS7YAGrPRaSrG8G1DZkhN2qOCtVfO9pN/HIZumjS92KnR9MTQCZ6cQJixtuRe/ImZZM0B9OIhtR+pAQV6nRV/+8ykg1RDtMTP3dMECrLq7ITuHnBiwlL7ddIXtZn52a0mNkn5qUe7L8nTG2zcdiABLGzJ3q5X0VwmqTKPzUEAeUUBAgcQmFFHATW7/gHTF+1M+GzKJSXpJhDc5phyoqXLyQ/yG7sbDWEZCh1Fk6sST6rziJtZVTl6R/Q== 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=tmnIhMzJ44mVfaOUTSFbb1BP8k4pmqbGQeixeOFAlHE=; b=wSiUlbpESf1Uta+T68LKHx/u1Ln9N5ySEBN2IfAwxS+uh155CLITiSw4G6x0rPVmZGu7B0zaZvwQNckX9yRUs0/+HfxLQmkYbEW+t55XiPgwaue4Uf37anqDpi09kq9sBneiKXS9VlVaYzckiLRH5R8AGLynT1plmG2aYx/+OWc= Received: from KL1PR01CA0008.apcprd01.prod.exchangelabs.com (2603:1096:820::20) by SEYPR02MB7175.apcprd02.prod.outlook.com (2603:1096:101:1a8::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.20; Thu, 25 Jul 2024 03:53:39 +0000 Received: from HK2PEPF00006FB3.apcprd02.prod.outlook.com (2603:1096:820:0:cafe::29) by KL1PR01CA0008.outlook.office365.com (2603:1096:820::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.28 via Frontend Transport; Thu, 25 Jul 2024 03:53:39 +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 HK2PEPF00006FB3.mail.protection.outlook.com (10.167.8.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Thu, 25 Jul 2024 03:53:38 +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 11:53:37 +0800 From: To: Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Vlastimil Babka , Michal Hocko CC: Hailong.Liu , Barry Song <21cnbao@gmail.com>, Baoquan He , Matthew Wilcox , "Tangquan . Zheng" , , Subject: [RFC PATCH v2] mm/vmalloc: fix incorrect __vmap_pages_range_noflush() if vm_area_alloc_pages() from high order fallback to order0 Date: Thu, 25 Jul 2024 11:53:15 +0800 Message-ID: <20240725035318.471-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: HK2PEPF00006FB3:EE_|SEYPR02MB7175:EE_ X-MS-Office365-Filtering-Correlation-Id: 1bfd25cc-4ff3-4112-8253-08dcac5d5dfc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|7416014|376014; X-Microsoft-Antispam-Message-Info: VhfRYumsqorIgQkA9CrDCJoodQWJ+BTlN3Hkq1IbksvuMaUfAENQZObq3WGhK1SScUYxBLexu5kkKFCTIJ1P2Qs8vDedGARg3Bxn12TNpDkWNS0S0Sqd7avZJmxYW7Frh9RIsvz5fTAU2kGxShZ4iIZQ5lhHELhy6n9TrmacF2k4Mvgf4zsuCLtA6MJ0olEZYluK/wRGu0vcLINjs48NlxYZAOoOdkXP2513gl/im7mv2C9rIrY1AAzXwvGvr9Vig5MLvQyY/K0DmU+ZQI/s8gcKg16MNmazRC+IFIPg1Z3Yz+1nES3OgZAIMg8/tTOTbS8rwG9HVRMmNMRYhKhapBGfNUwRdM4KYZ5CC1vE/pbmqTYaTP9ODsJ2AUpbAxC/qLghOojOy44x+JIbRsynhVbqcnTQ1pq93ZDJO0xBiKBvbKSiUWWDdCFMkwbykacJQ7AJ1ubjFk63d55LKB3mwGuSMLDbueF1txo7FzqtvzghazqJnjonqp8rALZiwXaFj8VIUWYseD6s7DCSYschJfyHGwR/ezvCK60/wmFd7/UTLhcg5ww1i1ojl8RrQhoaRn7P2v1Xs2yVQm74JV8K153Jg2IWApPayRm90LLd0+ROy/5b8ErW9tod3hBzRhG6AH+hmczQLdbg0l7C4CzCzcChwJrR0x+TRtzvjTy6w3OqdjpLNDJEcldx0qde9wKcC38xI25shXKUYLKAyr6pctNRKeb8BGYHPDuamEGbnqyhSy5b9VYz05bghK7irB7FeDMPI9b+rIuQgJUE5cYpJgmRhvIte3cXr2WLkcrBtiP6Ujw9AbunrkZAyzivi+0X8EHddf2QIddRIMhlIJxVlakc3xthFQdyaMcHFqeGbTWC3wph4/N4000/a68EyyBQa16neMEm6jK5Dt/u4hSfY4kXg0EbviJEKztKbYCfbNMtXM3lvzSJLVQB9+9ZzHMlD9sDYl3ZAzrieyPuOtQUHtBg7LdHzlJwfYYNzvRQ+m7d6RXq82ysVRKI89/U6bA+qBhqcGqRhdrC2GMdLg86H2pIiR3rWAjD6tSQk7Mf0oflpYJG0hb+LYdG/QqkkrUvcGsfRmdCkIvqeJEECxlrLHUQQKL9c4NYCLQjeYmGc7cRtlr0WyTXV4ZA020eLShE196AU+aGFL+cNFRQpsqwMz9AAFEFokTaepIvK6/ZHvbKZoWTSghXlNbHPbkvckC2eGVeS/Zy1O+daMd/leo60s9iA1BQa15eSZtPeQI38wC/iWwnRrxdyHE/bwrSAbHqoqFWi0cnqPkU0n/loE/PLvqmn+pa1vuEhCLn4FFOsY/apbZYLvgg5ovYbJAs35aSN0hCmu/pN4dfdReP9cF0F0p9mahmbk48T7LHI6QRcOCTvkXBmmObPSwma4bxpwlh2SGZwEKl7dFUvi+zZw3wHQ== 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)(36860700013)(1800799024)(82310400026)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2024 03:53:38.6814 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1bfd25cc-4ff3-4112-8253-08dcac5d5dfc 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: HK2PEPF00006FB3.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7175 X-Stat-Signature: eqbo8awt7zw9gz1akif743u7fpr7eus7 X-Rspamd-Queue-Id: 40D94C0006 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1721879627-919940 X-HE-Meta: U2FsdGVkX1/dhKJCHmATcMg3DyI0gZW+4haPu/hu5jIqEMygm5CHTAHPeYwd7qjf+mVr7gtdfORtxk4taO5XNEofEp0a99TO3t+Gh3O1mVo7WYf8vyt3aSfnBI/O4DXk/nEhf9pVkCPoh5CRbvmf4mQi3Vuh5jHoVgE+Bcc8ejl/fLLTdR+Lhh8UElzODRVr+iy03IFmfiiuW8eP9gbRjfR3iqMr6IDqdK/TA/7rHM45dyHbgscRpKN7ALHTS4NrMiePzmucuWctZyrQ+mWm8X8seJmgvS8TFRXjGddFiGMFJgiqxqEubj8EuRHO2YkyujO/10Nn0PI+LAzLkxUStPe3Gg6/dnCwWohCgzwoGA+vh0Y/jpALyEL5cHCBNl61VL62QXY5IhLb4BfBEhaYM2MWaMiV1Kq2jgyswupEB60qcZmqrTe6OjhMhNgb+C9SheFXqnsZt+EvkKymrgle/Zu++M/ST2UPBWPRYL3+yCGiLgW0EKBRYUOQ+747wb9Tb3f14eQM/PdXws6xVwxDBCekMnomq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000, 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, __GFP_NOFAIL|GFP_XXX) __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 In fact, as long as page_shift is not equal to PAGE_SHIFT, there might be issues with the __vmap_pages_range_noflush(). The patch also remove VM_ALLOW_HUGE_VMAP in kvmalloc_node(), There are several reasons for this: - This increases memory footprint because ALIGNMENT. - This increases the likelihood of kvmalloc allocation failures. - Without this it fixes the origin issue of kvmalloc with __GFP_NOFAIL may return NULL. Besides if drivers want to vmap huge, user vmalloc_huge instead. Fix it by disabling fallback and remove VM_ALLOW_HUGE_VMAP in kvmalloc_node(). Fixes: e9c3cda4d86e ("mm, vmalloc: fix high order __GFP_NOFAIL allocations") CC: Barry Song <21cnbao@gmail.com> CC: Baoquan He CC: Matthew Wilcox Reported-by: Tangquan.Zheng Signed-off-by: Hailong.Liu --- mm/util.c | 2 +- mm/vmalloc.c | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) -- After 1) I check the code and I can't find a resonable band-aid to fix this. so the v2 patch works but ugly. Glad to hear a better solution :) [1] https://lore.kernel.org/lkml/20240724182827.nlgdckimtg2gwns5@oppo.com/ 2.34.1 diff --git a/mm/util.c b/mm/util.c index 669397235787..b23133b738cf 100644 --- a/mm/util.c +++ b/mm/util.c @@ -657,7 +657,7 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node) * protection games. */ return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, - flags, PAGE_KERNEL, VM_ALLOW_HUGE_VMAP, + flags, PAGE_KERNEL, 0, node, __builtin_return_address(0)); } EXPORT_SYMBOL(kvmalloc_node); diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 03c78fae06f3..1914768f473e 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3577,15 +3577,6 @@ vm_area_alloc_pages(gfp_t gfp, int nid, page = alloc_pages(alloc_gfp, order); else page = alloc_pages_node(nid, alloc_gfp, order); - if (unlikely(!page)) { - if (!nofail) - break; - - /* fall back to the zero order allocations */ - alloc_gfp |= __GFP_NOFAIL; - order = 0; - continue; - } /* * Higher order allocations must be able to be treated as