Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp387061lqo; Fri, 10 May 2024 03:02:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVL2zjVPy3RU9XN/xvLXzV3Uqy7e0jPiiw6eF22R+aLRQSbtlo8pMiGY38oZ1OdDo05gvQINZHvlmDGK0ZgAAf9GzuCO2gHkVfA46MvFw== X-Google-Smtp-Source: AGHT+IHivrfTaJaHUve3XcEwtjcB61aJSmMZ2CJFUuNuAD5Vx9b9Uf13cqM4L0hdiaQ9POWjxjrc X-Received: by 2002:a17:906:6944:b0:a55:a895:46ae with SMTP id a640c23a62f3a-a5a2d67db94mr132288266b.63.1715335325922; Fri, 10 May 2024 03:02:05 -0700 (PDT) Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17bfc5fesi185981166b.869.2024.05.10.03.02.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 03:02:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175562-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@oppo.com header.s=selector1 header.b=jkhq5wjO; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-175562-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175562-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oppo.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 45C4D1F215E7 for ; Fri, 10 May 2024 10:02:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0BB87165FB1; Fri, 10 May 2024 10:01:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=oppo.com header.i=@oppo.com header.b="jkhq5wjO" Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2043.outbound.protection.outlook.com [40.107.117.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B577F4AEFA; Fri, 10 May 2024 10:01:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.117.43 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335314; cv=fail; b=a/DiTRMtkEGVVkYgqxQvUMa0s6y+XJfdRPaj1cqMLS3OHuCrk/badRkVIw5NT91wY3llsiWVUxMeMvsbbIrDBb5QvQ5kUxaPxl62ApeReLDM6S4RjWtKiIWiHmpzjG4r2j7y8l7/57juxjKmh4L+8WBgTLmDe4khGxuDZ5AS5rQ= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335314; c=relaxed/simple; bh=JGXVP3NkGWZ8c53BS/ygyeWVONyrdRcIEzpgczXEeg4=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=koaxZfze5cBSpIBhV0viXkvbJQ5bmDtugpm5JqkQkk5oiFS56ou3TUIiqeQlxrNnvVFdJ+4lVNHX5TkHz2Us45ioNFXxvoPujb40zV7rMnalgHYl25qHnp08HWEMuFSyMJQzINoq9QQZ6eaYIHGXncbLV+O4LZ3NANIarjfhYDQ= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oppo.com; spf=pass smtp.mailfrom=oppo.com; dkim=pass (1024-bit key) header.d=oppo.com header.i=@oppo.com header.b=jkhq5wjO; arc=fail smtp.client-ip=40.107.117.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oppo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oppo.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XuTDO2qLskf141dEw6aN0mplcGa/HezeVoWvZsoXKBlEqrEssKfDeBnT4mHSRLLpR13dSQDYSNo5hiKu2RI5nIWCjkptfaU8X7I+qhRX4vPECyopWB2YFTuIkmMN5cCCSJ0TmAaRYHUOF4Pa/zLlOiLZB7LrlLQKoh5gv0uApe6T+mi+6jw210Cz5ncX59LjMhmcvGNPUB5YXOepoFTUh6jlLqPLskVlr85ZfwmDnyjbbDMcu7Cf9iEuJqTSzgmGvZPSUIHOQkXsJ8Cunls80DIFrlube8/BBd34H/q37g4AoGBHx4ESRLJr5StgmzYaXSgmMEyD5ihDNAFWVCUPFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=uKLdzosIdGgv2QIDSek4xu8G6B6eszpULhk2vpR/8V0=; b=Z8+WEyMbCn79JRO4vKTr9J7A0mSB5HKjUzcm0ZDRZciocnHynlGORayS0+bFLT18PzNV+T8qeWXCsN0gdZo0kTCwQgPOxjq0Oa/9IyZ6rbE59PXFeeKuGKGH9jlHMvqPD+vcWm7zZ4Mi9T1P8LF7LbhHyc9QX8rVkNNM2oB+dNxxgwDpDtFaFLIjGVrcLQ7WulMFbhe90Sq2HI8AD6TKESBR+GEB3MtYQ7Tk3DYxcvqcT9FNXtlZq8oTyKMIDdiOfAAQy8EE/nJqVuFhEB2ae5mrEzwx9MWXSrdIg8zOfIhZqCKqf6aLcVk8alcGt5sltFrcRrBkX5MzUijEZkaO5A== 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=uKLdzosIdGgv2QIDSek4xu8G6B6eszpULhk2vpR/8V0=; b=jkhq5wjOc3FA9o0JSljxEXySM2DKNRLDdgd7t0RywNs7kj6aXd/IUq6sdNn2uHdrYfTklQP57KVTNIg2cqvaIwUs/lCq3wZnqny04zHMTIZ3tYHh+acLA9gAE+MA3I+I6klmF609MVy9ZWp0qsh7rBhOeJjvt7w1AYlqQ+dbN2g= Received: from SI2PR06CA0011.apcprd06.prod.outlook.com (2603:1096:4:186::16) by PUZPR02MB6307.apcprd02.prod.outlook.com (2603:1096:301:f9::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.45; Fri, 10 May 2024 10:01:47 +0000 Received: from SG1PEPF000082E8.apcprd02.prod.outlook.com (2603:1096:4:186:cafe::3b) by SI2PR06CA0011.outlook.office365.com (2603:1096:4:186::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.49 via Frontend Transport; Fri, 10 May 2024 10:01:47 +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 SG1PEPF000082E8.mail.protection.outlook.com (10.167.240.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7544.18 via Frontend Transport; Fri, 10 May 2024 10:01:46 +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.27; Fri, 10 May 2024 18:01:46 +0800 From: To: CC: , , , <21cnbao@gmail.com>, , , , , , Hailong.Liu , , Oven Subject: [PATCH v2] mm/vmalloc: fix vmalloc which may return null if called with __GFP_NOFAIL Date: Fri, 10 May 2024 18:01:31 +0800 Message-ID: <20240510100131.1865-1-hailong.liu@oppo.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: mailappw31.adc.com (172.16.56.198) To mailappw31.adc.com (172.16.56.198) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG1PEPF000082E8:EE_|PUZPR02MB6307:EE_ X-MS-Office365-Filtering-Correlation-Id: 23494940-940c-4c52-9147-08dc70d83426 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|82310400017|36860700004|7416005|376005; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?DwffEpv7IPxFQp9+odnMvj11TR7agAqakRvnRVBODm+sP3jNqLNFNmfsWPv3?= =?us-ascii?Q?taWsxU3tSwxUHmtRgKwoMKnrxMqKMQ2FmKmAdMwg+0FT1fsaf8NluNiqVNu9?= =?us-ascii?Q?5aHEK16pRHFMS2zCO7yYG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?Q?NfKZmfHINbvFOcmkUHnn7XhIVzHX9WMdcVHqaLB/YKcq90jwPkjUXrc2miLu?= =?us-ascii?Q?s0EwEVHvYHhUnvjzbbpz3gW0gMY2XcpJpYqPyukb0lPBnr2G3XZKCaF0rQeg?= =?us-ascii?Q?bRRKW27wOoT1c4MjyLz5jyBbkcaBJPae7wejmguGc4bbb5PCNGN67NvywIiH?= =?us-ascii?Q?BL5iPkWFFprUyyLuUXFunfYVfF9WBHpdSxM/gI8C2IeCBI6CrK/XdZbQ05/N?= =?us-ascii?Q?XIhK7cyECvP9gWI/5IQEufXgXvkL3vH3+D2QifevBuI9E+XNVUQ3q62C+nVV?= =?us-ascii?Q?4dEkw7VQq8/3vgjlLUc+U0MQ?= 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:(13230031)(1800799015)(82310400017)(36860700004)(7416005)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2024 10:01:46.9019 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 23494940-940c-4c52-9147-08dc70d83426 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: SG1PEPF000082E8.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PUZPR02MB6307 From: "Hailong.Liu" commit a421ef303008 ("mm: allow !GFP_KERNEL allocations for kvmalloc") includes support for __GFP_NOFAIL, but it presents a conflict with commit dd544141b9eb ("vmalloc: back off when the current task is OOM-killed"). A possible scenario is as follows: process-a __vmalloc_node_range(GFP_KERNEL | __GFP_NOFAIL) __vmalloc_area_node() vm_area_alloc_pages() --> oom-killer send SIGKILL to process-a if (fatal_signal_pending(current)) break; --> return NULL; To fix this, do not check fatal_signal_pending() in vm_area_alloc_pages() if __GFP_NOFAIL set. Fixes: 9376130c390a ("mm/vmalloc: add support for __GFP_NOFAIL") Cc: Acked-by: Michal Hocko Suggested-by: Barry Song <21cnbao@gmail.com> Reported-by: Oven Signed-off-by: Hailong.Liu --- mm/vmalloc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 125427cbdb87..109272b8ee2e 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3492,7 +3492,7 @@ vm_area_alloc_pages(gfp_t gfp, int nid, { unsigned int nr_allocated = 0; gfp_t alloc_gfp = gfp; - bool nofail = false; + bool nofail = gfp & __GFP_NOFAIL; struct page *page; int i; @@ -3549,12 +3549,11 @@ vm_area_alloc_pages(gfp_t gfp, int nid, * and compaction etc. */ alloc_gfp &= ~__GFP_NOFAIL; - nofail = true; } /* High-order pages or fallback path if "bulk" fails. */ while (nr_allocated < nr_pages) { - if (fatal_signal_pending(current)) + if (!nofail && fatal_signal_pending(current)) break; if (nid == NUMA_NO_NODE) --- Changes since RFC v1 [1]: - Remove RFC tag - Add fixes, per Michal - Use nofail instead of gfp & __GFP_NOFAIL, per Barry & Michal - Modify commit log, per Barry [1] https://lore.kernel.org/all/20240508125808.28882-1-hailong.liu@oppo.com/ This issue occurred during OPLUS KASAN TEST. Below is part of the log -> oom-killer sends signal to process [65731.222840] [ T1308] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/apps/uid_10198,task=gs.intelligence,pid=32454,uid=10198 [65731.259685] [T32454] Call trace: [65731.259698] [T32454] dump_backtrace+0xf4/0x118 [65731.259734] [T32454] show_stack+0x18/0x24 [65731.259756] [T32454] dump_stack_lvl+0x60/0x7c [65731.259781] [T32454] dump_stack+0x18/0x38 [65731.259800] [T32454] mrdump_common_die+0x250/0x39c [mrdump] [65731.259936] [T32454] ipanic_die+0x20/0x34 [mrdump] [65731.260019] [T32454] atomic_notifier_call_chain+0xb4/0xfc [65731.260047] [T32454] notify_die+0x114/0x198 [65731.260073] [T32454] die+0xf4/0x5b4 [65731.260098] [T32454] die_kernel_fault+0x80/0x98 [65731.260124] [T32454] __do_kernel_fault+0x160/0x2a8 [65731.260146] [T32454] do_bad_area+0x68/0x148 [65731.260174] [T32454] do_mem_abort+0x151c/0x1b34 [65731.260204] [T32454] el1_abort+0x3c/0x5c [65731.260227] [T32454] el1h_64_sync_handler+0x54/0x90 [65731.260248] [T32454] el1h_64_sync+0x68/0x6c [65731.260269] [T32454] z_erofs_decompress_queue+0x7f0/0x2258 --> be->decompressed_pages = kvcalloc(be->nr_pages, sizeof(struct page *), GFP_KERNEL | __GFP_NOFAIL); kernel panic by NULL pointer dereference. erofs assume kvmalloc with __GFP_NOFAIL never return NULL. [65731.260293] [T32454] z_erofs_runqueue+0xf30/0x104c [65731.260314] [T32454] z_erofs_readahead+0x4f0/0x968 [65731.260339] [T32454] read_pages+0x170/0xadc [65731.260364] [T32454] page_cache_ra_unbounded+0x874/0xf30 [65731.260388] [T32454] page_cache_ra_order+0x24c/0x714 [65731.260411] [T32454] filemap_fault+0xbf0/0x1a74 [65731.260437] [T32454] __do_fault+0xd0/0x33c [65731.260462] [T32454] handle_mm_fault+0xf74/0x3fe0 [65731.260486] [T32454] do_mem_abort+0x54c/0x1b34 [65731.260509] [T32454] el0_da+0x44/0x94 [65731.260531] [T32454] el0t_64_sync_handler+0x98/0xb4 [65731.260553] [T32454] el0t_64_sync+0x198/0x19c -- 2.34.1