From nobody Sun Feb 8 13:09:43 2026 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E2602D47EA for ; Wed, 1 Oct 2025 19:26:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346813; cv=none; b=jnehhXaRn17kCQFWG6sPAnnIM5KdXdzzjAFIBYWXQtfHn1JSOcOJofaXRlYY982eh06fZhSEtMnE5Zfi/UPygMACPbtjpRLhuoiEyidcGs/TywGw49ovuK5gKpx/jcr5u0QqzOGTW/eClk0qQdVAqd/zTHcJJipC50RoQ5hqB/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346813; c=relaxed/simple; bh=997qQQu2kGJpN3V77byc+mN3wx8H8MkzOoZfy80SWDk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YEEwpx/yuUySUceTbZusrtt2skGhPoCa/mWrHAw6yyGVMuyGy/78HNQZAKJ0xXnQrty2wCJUO/4NleOnu9ERVhNvjBgH4xFoE+q4TV/Mc5DYr7X4V3i/6xKquBGjtADvmTiqDkHcA5DOmC9YN9Jbm5lKXO0SOD1zBZq1NcB9iIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JTEzvWte; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JTEzvWte" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-57933d3e498so249590e87.3 for ; Wed, 01 Oct 2025 12:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759346810; x=1759951610; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6fNdEfsbjEkSdVOKy7pPxlOS+w8ubFh5YKBkVpFvsGU=; b=JTEzvWteaM7tBvdRvIFgjyNbPhb+bHtxxNa5i8J64HzpLdKMLHNxMWvM95AsQNJ/3c gCQi4l5QkxPixzTwxZne7Q6JxK3SCxmtUaaqb9JeKmM5bfdq6E+7t7d2DLLzLj+olHsJ DdjLx/5oAMQJ4zA+DWI6D5cyZq6IJBjySYKbURbO1uTbAu24JE2hBk+ZvjUGEa1wDBUD UODGol9BdUb6exOMQsdJD18VYHGhFyGBWTeamTIwYTlPBRXHFVBFcnUWKHQQPfoHKuC7 ppKVbUziKvZ726JiEWEasV0aVyfa0hFsAuAiRZv1BJUW0J2AQcsdvQDCLicunZBnkfYD gL8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759346810; x=1759951610; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6fNdEfsbjEkSdVOKy7pPxlOS+w8ubFh5YKBkVpFvsGU=; b=UEiZlQeSmNnG6LjZy5HuesXJSdkN6HP71aADT0fu9vyFmJkG6DJgYEgCEseYXfWVEG apdd9IaBueWAtJ/DRtc4yZbOzQzwy6NiswFzn5MuUYdf1f5yr0yByXJPIGcqQJ0epgyE 5zaVi0EvSoEcbnghOdIMrxQ0tZ4JBXbHxpRl+9lTibiSn25bb3IUCOI1+RcNvgWtAQi3 X+N72QLZpXavPCuK0DudPNUjMFsGZ9nSTuYsuQNOHwAMccBGSv0PQXtgUgkYCAwY4yW3 mNu/zqr3U4Ij6IBpaKhrfSn03G6P84BM5SgW4IMhQ4OyqCwwgHg6Q7UoC/ZPCYUMsjDa W6sg== X-Forwarded-Encrypted: i=1; AJvYcCU3uSQdiIMSu0sDFfq7RUUmjBG1YBGIqof7ZWwz72Hnp3Wy8E2DmEsqmTE+P1q19BUkdRJ+PpYqHOgRBKA=@vger.kernel.org X-Gm-Message-State: AOJu0YwB2zv2jVIgndwmXCnCuuQEQZSEiynh7as2Ck+iz4f5Vcb3Ae+1 g1WbZnh51XijHxBH1Fe8O1OZjBxYBYV0Du3Ev43vtw6rsZKgBmlAZCBn X-Gm-Gg: ASbGnctuADt3pbYiUg3kYEVJicWZCYGObh5LHgXMGUrV0fRDbVqXUwVVsC+rQMz0bdq KJKALhi2pr/xMMKnukDADl3PHmwj6+Qo39lMshTdJ+xhwsUkRYft3cyWqfdSlhUBHz0DQkrQUcx HDVN6qvyO3kQhkV/fKq6Zi6IT+xURgWZbxwoQ5XaHr4a7J6/Q85axfKA+9845MCt+377sTkIKT/ vpUdEObNFAntpoIB7fYrzOnmUcTDEvJa2WT1ESorapJjmzbgutjQllqlsJNlg6eUXv5xKGc2iTO HOHkjCfFloejAJfZmp7VOnQ6RAsyBK3kB/6OXPo6LLVWZb/xhO+Y9ffVxlfyWk8T/QRvIk8SGJq xDZHlJlZ8D19vnHXOjLMZe0VtdFIISkTvGKJXIqY1 X-Google-Smtp-Source: AGHT+IEfEWBm8M6AzhkYd4fot4+nTsgt3Zq6rjXCLPpDwAaNb3Xiqdqgs47Zz3Hyyexv8rR1mHCSLw== X-Received: by 2002:a05:6512:10c4:b0:577:285f:32bd with SMTP id 2adb3069b0e04-58af9f6739cmr1140787e87.26.1759346810036; Wed, 01 Oct 2025 12:26:50 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-58b0112414fsm136627e87.28.2025.10.01.12.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Oct 2025 12:26:49 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki Subject: [PATCH v3 01/10] lib/test_vmalloc: add no_block_alloc_test case Date: Wed, 1 Oct 2025 21:26:37 +0200 Message-ID: <20251001192647.195204-2-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251001192647.195204-1-urezki@gmail.com> References: <20251001192647.195204-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a new test case "no_block_alloc_test" that verifies non-blocking allocations using __vmalloc() with GFP_ATOMIC and GFP_NOWAIT flags. It is recommended to build kernel with CONFIG_DEBUG_ATOMIC_SLEEP enabled to help catch "sleeping while atomic" issues. This test ensures that memory allocation logic under atomic constraints does not inadvertently sleep. Signed-off-by: Uladzislau Rezki (Sony) --- lib/test_vmalloc.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c index 2815658ccc37..aae5f4910aff 100644 --- a/lib/test_vmalloc.c +++ b/lib/test_vmalloc.c @@ -54,6 +54,7 @@ __param(int, run_test_mask, 7, "\t\tid: 256, name: kvfree_rcu_1_arg_vmalloc_test\n" "\t\tid: 512, name: kvfree_rcu_2_arg_vmalloc_test\n" "\t\tid: 1024, name: vm_map_ram_test\n" + "\t\tid: 2048, name: no_block_alloc_test\n" /* Add a new test case description here. */ ); =20 @@ -283,6 +284,30 @@ static int fix_size_alloc_test(void) return 0; } =20 +static int no_block_alloc_test(void) +{ + void *ptr; + int i; + + for (i =3D 0; i < test_loop_count; i++) { + bool use_atomic =3D !!(get_random_u8() % 2); + gfp_t gfp =3D use_atomic ? GFP_ATOMIC : GFP_NOWAIT; + unsigned long size =3D (nr_pages > 0 ? nr_pages : 1) * PAGE_SIZE; + + preempt_disable(); + ptr =3D __vmalloc(size, gfp); + preempt_enable(); + + if (!ptr) + return -1; + + *((__u8 *)ptr) =3D 0; + vfree(ptr); + } + + return 0; +} + static int pcpu_alloc_test(void) { @@ -411,6 +436,7 @@ static struct test_case_desc test_case_array[] =3D { { "kvfree_rcu_1_arg_vmalloc_test", kvfree_rcu_1_arg_vmalloc_test, }, { "kvfree_rcu_2_arg_vmalloc_test", kvfree_rcu_2_arg_vmalloc_test, }, { "vm_map_ram_test", vm_map_ram_test, }, + { "no_block_alloc_test", no_block_alloc_test, true }, /* Add a new test case here. */ }; =20 --=20 2.47.3 From nobody Sun Feb 8 13:09:43 2026 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBD542D6401 for ; Wed, 1 Oct 2025 19:26:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346814; cv=none; b=GiiE9mAm6HdaASGcA1lBs14Vngn196BdQ1qpW9EYUw2RH+Da+ugu8k5d1UKzBVP9jeH5oNQ4qNjvp8hIVE2+vuhYbNZzLDFKWs5SZoH1kUHbandeVZw25z/X39M8uUUMYSPXtQrkJt0Ymh5SqaUBgguQ4jX6VAMcOl77ofVh+/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346814; c=relaxed/simple; bh=Cid1o0yI6anA0oMjfZ5dvYwhgQOAZ2ZDCkuXoquLJSw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HZNKLqPVjkn+21Qa/tJqbiKEHg7lXtIXpFdd0hj6NT76D3g6KTncPXanntSRYwd0pDWwgsqEGMTkkL3ezTXQvWRSG7OwksGphKOJDUZrqGdG2b91EBImwFeznKtGq5ntBJBsBCPWyWGGX9evUOuD2XaA+Xr70FaxNQzTjMTXWk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QN32oEyS; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QN32oEyS" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-57a604fecb4so262243e87.1 for ; Wed, 01 Oct 2025 12:26:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759346811; x=1759951611; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d4jfcSPGUvol/n8ObJSFwltbXIiILhsqpfoN+DLL7zw=; b=QN32oEySnNbALymZLth7d7dAP/49slpFL0sBEhzXGQA1UAm9nVVqf9h8eA28d6LUgj 9BDqgB8SBLke9N/DhC/N8lAdsEdrtcZ15bXWlstB3f/9Gu7CVkW+RgxjfRUzHKLwCiSw t5kmtWXZc2YiHWxuNG+jqBo3fRZOXBZn7WCjKkhfpU4ZV48mcsPkptYVYKIOD1jWk2ad +ONY7X3QCzSaTxu948V0GQ+DA5eAIRY8Qyizbo7EDbUFalfNKOZeFeAlNWUXZ6mPzBvq xiozYKAef5dbwkh/NxsisrDpERmBpUxS/oTXk5HXXYtwaF4Kd7q9hIzbugVjwHpAklxR KLTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759346811; x=1759951611; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d4jfcSPGUvol/n8ObJSFwltbXIiILhsqpfoN+DLL7zw=; b=wfK3+sSqq01G13sB+pCeV4JBA/s5iL7zDuWgP0Zm5lZe7AzMOYqNceU48mpvfer3Cu 58Rd7tdng29r6/L00Vo2oF84jayufcb4T01rVNFsEY56bkcI3U4gBg/cnA5N2902GXNW lpnzG9oa6dRIjdfVUJcwJcZM21Bu6ntfz9WCn6MRIdoCxqEnwydGGxHEhQT5dHEk0qhl 1C+bJs08UGNIWjSg/3+YmZrAq3qdr1lLB5WyJHaPJI5sdgrJ++Lov4cjkUVQ8sx+YqRM FV8Ml5PPq+n15/y0zswahgkv3d7nupQBJm/Y7HPNwvpLtNnQkuYFMR82bSdp2ceS0HPJ AjtQ== X-Forwarded-Encrypted: i=1; AJvYcCVsulGxfX4U/nUkE49emVqy2VJ3IDeog5ahkeNtLUHkjEvuj3pRbS9CtStsjEd9EvmOBO3aVoa7zLeRZPE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw6pyDI/AHhfpNGYuWbAK4AOEKc2nBpcYRbRV/c7hClntcG6JHt 8CKyhM2/zWCGcWQYgvyZ4uAiVcVcoL37UQeD7m2EP5CC4kewU0P5TkIY X-Gm-Gg: ASbGnctq/dcCMnwOwhIG39/vIKwW+q1vJz3ku4pfQ65CJVq+ED31l+vLC9uafu8sdzT kcm6fsLhzYchjv3ZtbGrTpK/lT8xl0t61CpY5o6HiPRVTQTEueOTqPyiaqoEEjkms7fLeHd8eI5 rA0yPUMWTTWg1QF31CkcCRLZxME7ilzLp+bcODU7YZdBU9ml8bg7jjngiIWmiDVwnZs6sUN4C0N KpZqpKaEgaQ3znL0fQ50Yx8P+YBfrVxa+nvVgI3DVr2frlLXyskyCE/SiGpIDO1US6q3bqFIvcM VLrrECJPxCgMZtCGJQbCkzKK+/h8JdOq9JElhlmYoLVGD1/oawfZ/Hh1otNX/0qh5+7nEHhVPfM rqfdbCqvgKMfP+m1dmv93y9n0CuNZ/05eKMJJa4mv X-Google-Smtp-Source: AGHT+IEf29nqQKPfqYlqzEpEYNiDi956qj5XBnEwQXCvp6W703JnoRPSW6KZ+JL2jB5rOA++8NRQcA== X-Received: by 2002:a05:6512:3b29:b0:577:3ccf:cddf with SMTP id 2adb3069b0e04-58af9f6cd35mr1447231e87.46.1759346810827; Wed, 01 Oct 2025 12:26:50 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-58b0112414fsm136627e87.28.2025.10.01.12.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Oct 2025 12:26:50 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki Subject: [PATCH v3 02/10] lib/test_vmalloc: Remove xfail condition check Date: Wed, 1 Oct 2025 21:26:38 +0200 Message-ID: <20251001192647.195204-3-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251001192647.195204-1-urezki@gmail.com> References: <20251001192647.195204-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A test marked with "xfail =3D true" is expected to fail but that does not mean it is predetermined to fail. Remove "xfail" condition check for tests which pass successfully. Signed-off-by: Uladzislau Rezki (Sony) --- lib/test_vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c index aae5f4910aff..6521c05c7816 100644 --- a/lib/test_vmalloc.c +++ b/lib/test_vmalloc.c @@ -500,7 +500,7 @@ static int test_func(void *private) for (j =3D 0; j < test_repeat_count; j++) { ret =3D test_case_array[index].test_func(); =20 - if (!ret && !test_case_array[index].xfail) + if (!ret) t->data[index].test_passed++; else if (ret && test_case_array[index].xfail) t->data[index].test_xfailed++; --=20 2.47.3 From nobody Sun Feb 8 13:09:43 2026 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0B832D73A6 for ; Wed, 1 Oct 2025 19:26:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346815; cv=none; b=H+EW1NhcK9n9jXP/K13SUE66VHbjluvRvBfwRkyHOwJGPrWfAsq4q4MVI9ouaSWwtPob9rEKATbbPf8Ap1hbm2EBv12cd9ivse+YVjqfTUQsfa7WbePn+5UtPUMtr9QeHmcdYJVT5GsPoV6BCCOkiyiao+wd7WJoiKNmmtPoSnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346815; c=relaxed/simple; bh=5tzWNyU3AXYCEpPLT5aXRk5UxMX97n5L3bxKGpOPArE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L+XSP+PX06ZOLLFeEmQ525d0BCq3liWixn/vKfR+jsOUHJLO1ddZh5apMZHExQ+bEJbvJglxCcteWOUnfyhVaYfnQoaoYvTr+KV6uRxBnLzXGH0vAJVqEagwH7OCYOd3dkE46oKBWBLTk9tguLp8OaG+eMy5CCWsKizpo2qzpPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LPNFXSAl; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LPNFXSAl" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-57a292a3a4bso201746e87.3 for ; Wed, 01 Oct 2025 12:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759346812; x=1759951612; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aTAgJkdvXfIYVJGWt9rTo9DrGAL0rL30tXGrZW/Q/UA=; b=LPNFXSAl7Brk3fKGac2KYCiUkRsgXc1o2LGG5er/oRxTDn96YJTENeTouvvRQjzQqY lnMf7TAzj+H8bl1iFlSU4x0nMPNem8qRBSeBbj+tkLTkwZH0IDAd25LmzM4br3uJltOP JWkd1kwmL5b4c3Q/bmkuqEtdSowWRMxzf6uDaOqGuX/1FadRqfOmNjXmlameHdpeLsCg Ax4e5sq0sBWjMRKDiAGIzVgQa36ZtSnWnIGOglH3agjfyf9RdEfSUWLWKCQ1IzIgckKi orRc/Ifp9sbtSkw07QZkLST+e44bW3WbVfaYIBh1q2qzOOKp9bQK9OFYIsFJ/gHhuty9 6Ogw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759346812; x=1759951612; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aTAgJkdvXfIYVJGWt9rTo9DrGAL0rL30tXGrZW/Q/UA=; b=Y0JQgAuHaKxodajGsRAHQV0n6f2tt9pKPT3qXTAWAhNpchKi8MCCAhEz9mVWNPdvz/ zpm0nKcoJSmmMeDLAjA5LiRsNnfKJuI/ziBm8yQwqOz72/QAZa86QD0cxzP/904c4F05 E6Dj2OFxldmWFklekx2F4bwCVWPiD9Xibj297CRB4yvq4YUParCb9PKL1p+x0uQ14idq nHKWwR3IUQ4qh8MZoIRLK68SGSqJKgT5DT5/nOcqUzxE5kyj7adfNBdffoOsrYu0LHLA ANu4gQs9qG4RFo1xlZBIKEAs+4YweLtjdq2j1yNxRL6rdP0wTWEW6WdL1BSuDLu2Vfbl Y6fQ== X-Forwarded-Encrypted: i=1; AJvYcCV4YafXwqxbqzTC7deHOIp0TcThWl4ibeWp23olY5OZuDmSJBmMk3RgYHskE6u8psU9F92xeF2XrJVPOaw=@vger.kernel.org X-Gm-Message-State: AOJu0YxGbwOf76h226qNWgKs9DdlkZvK/hacfFp1/xeNEAy9Q3MKwvdV +Qd0CKZ5FzwJ6Bic0dFhujZlmW3ai3UTGkYWnrnXkhyPudkhHn0raJjF X-Gm-Gg: ASbGncuJLOs8gXAxA0NWnWp6KyY4UrMTwD0TigMKOSKgLmYw/5wbiTSdOYn5SAhvHXK vaAYC+SiVm19e+Nucf5Gq+/grDOp9yU1vb4WnhqD3XFlToEKjix4H+GjL5JjHe1traLWJyt75Cm ItN8edcTkOaLZmC4SyyFFPLMbE5gW4kNltjb5c+y79QuyuD4hk9lOPKxAiD4+OzOfPpstAiWYcu 5Xa8hZtH7qhQxPGHv042XliEH5Nm5caVeu0rqKvU4716qNrYuj/I7cYvSuRtpeQlHEASpAm+P8S QKFs8EKNq1l/uH/Lfk1jtrQDEsYkhQzY1cnEL9r4HtGjuqbgDU9UR/Jk0enSTdZmHcy2lxYhWN3 xU10by5v2evJulGjclRxiYq4t69CjOQ7zCYc1gG1zT3CteY/4LtA= X-Google-Smtp-Source: AGHT+IF0CvjRQv5Rhg8Uw4MQKskiae3bT7jASaj/mzoAEgMrKa+fqdv3aYo5M9392D4IA+uwz0Xiqw== X-Received: by 2002:a05:6512:110a:b0:57e:65dd:9bcd with SMTP id 2adb3069b0e04-58af9ee5043mr1207622e87.13.1759346811677; Wed, 01 Oct 2025 12:26:51 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-58b0112414fsm136627e87.28.2025.10.01.12.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Oct 2025 12:26:51 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki , Michal Hocko Subject: [PATCH v3 03/10] mm/vmalloc: Support non-blocking GFP flags in alloc_vmap_area() Date: Wed, 1 Oct 2025 21:26:39 +0200 Message-ID: <20251001192647.195204-4-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251001192647.195204-1-urezki@gmail.com> References: <20251001192647.195204-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" alloc_vmap_area() currently assumes that sleeping is allowed during allocation. This is not true for callers which pass non-blocking GFP flags, such as GFP_ATOMIC or GFP_NOWAIT. This patch adds logic to detect whether the given gfp_mask permits blocking. It avoids invoking might_sleep() or falling back to reclaim path if blocking is not allowed. This makes alloc_vmap_area() safer for use in non-sleeping contexts, where previously it could hit unexpected sleeps, trigger warnings. It is a preparation and adjustment step to later allow both GFP_ATOMIC and GFP_NOWAIT allocations in this series. Acked-by: Michal Hocko Reviewed-by: Baoquan He Signed-off-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 798b2ed21e46..d83c01caaabe 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2017,6 +2017,7 @@ static struct vmap_area *alloc_vmap_area(unsigned lon= g size, unsigned long freed; unsigned long addr; unsigned int vn_id; + bool allow_block; int purged =3D 0; int ret; =20 @@ -2028,7 +2029,8 @@ static struct vmap_area *alloc_vmap_area(unsigned lon= g size, =20 /* Only reclaim behaviour flags are relevant. */ gfp_mask =3D gfp_mask & GFP_RECLAIM_MASK; - might_sleep(); + allow_block =3D gfpflags_allow_blocking(gfp_mask); + might_sleep_if(allow_block); =20 /* * If a VA is obtained from a global heap(if it fails here) @@ -2062,7 +2064,8 @@ static struct vmap_area *alloc_vmap_area(unsigned lon= g size, * This is not a fast path. Check if yielding is needed. This * is the only reschedule point in the vmalloc() path. */ - cond_resched(); + if (allow_block) + cond_resched(); } =20 trace_alloc_vmap_area(addr, size, align, vstart, vend, IS_ERR_VALUE(addr)= ); @@ -2071,8 +2074,16 @@ static struct vmap_area *alloc_vmap_area(unsigned lo= ng size, * If an allocation fails, the error value is * returned. Therefore trigger the overflow path. */ - if (IS_ERR_VALUE(addr)) - goto overflow; + if (IS_ERR_VALUE(addr)) { + if (allow_block) + goto overflow; + + /* + * We can not trigger any reclaim logic because + * sleeping is not allowed, thus fail an allocation. + */ + goto out_free_va; + } =20 va->va_start =3D addr; va->va_end =3D addr + size; @@ -2122,6 +2133,7 @@ static struct vmap_area *alloc_vmap_area(unsigned lon= g size, pr_warn("vmalloc_node_range for size %lu failed: Address range restricte= d to %#lx - %#lx\n", size, vstart, vend); =20 +out_free_va: kmem_cache_free(vmap_area_cachep, va); return ERR_PTR(-EBUSY); } --=20 2.47.3 From nobody Sun Feb 8 13:09:43 2026 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8ECCA2D876A for ; Wed, 1 Oct 2025 19:26:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346816; cv=none; b=aKrnaWKSRegp/a917G7Qx+gczV5ruWyhG8isb0jnM274RY33d4SsTU+kX0UUPRMc5U2zY0EINaY7a6DUUOkhKB2Fa1lMKb/Ya0joRLAsG3jDHTkU2jpb5T3l8Ys6bySXxiLoMHB5VJqzglL2as1rQ75D/PElXtSH2YYwX87QHAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346816; c=relaxed/simple; bh=5LOLgDuRoV2shXqOUtSYOTm+9rMW+12+m4ljmK1VYqI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KGRqUHBuSq1pgYpLQUHTLdhVWsnXL7R71j19kUEXoy3H7Kkr6vACqAdV65I1okaEkrIii8kC1rgRxZ2vUtgImbjtJQQfMMyYfBQorkmuf3byowDxCSnhHG9z/7MjgQP1VfUpvaYD0iIZXFAMzW+owQNgDW7qYECK8X2LBzsSOVs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=H31OWF3Q; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H31OWF3Q" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-57ea78e0618so243692e87.0 for ; Wed, 01 Oct 2025 12:26:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759346813; x=1759951613; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FuOmVyVQXsumRDN0WySluCU+eClCoeXEAXwSkpYGp4g=; b=H31OWF3QACtUraPEv/plAmElYGHQDG9MWSoQGPgZ3RFb7Va5w95RCb033TW64aBW6/ DzJKRemsKk2Nkf01XH8laV5v440AnTbO283NeDwjarVD2e8XR+L8TcqWsyB66h5028Pd 4B4V8MiHjtIcOhN+LEqqO8X/QPwH2E2SDOE7nSasAEfDdTITMykNelE6u1y3L8Im5KzC Q9I0wd4VDNaj8UFs9C8jbgGueGyJFxIsjh9VaYYkCoaUdxXBiNxM2cwVhO0tuPP5on91 CTRzBtlAWUCMWuBEAftYL5j4k8HfSFKL6GAkXSG2qIMLfoCzpkMQnyuvQavw7EEm4gOI pQRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759346813; x=1759951613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FuOmVyVQXsumRDN0WySluCU+eClCoeXEAXwSkpYGp4g=; b=Q+E7NDof2znYSAYnX9dwYA/y6DOsKn2wStpfZznVSjDwjW1R4pi2k3yHDUUoVE1/K/ VrbOeHT2vEfcSHNJUMsZRMB3zMBhQvCX+Ry4h2xwc6G3v8g/IrkuJlbHudYjf7/P5P7f BayirKOjNRvGx85LJoMfVJJp+xRx5hzoHnwUEjh6IuK2nd0nWjP4Ky/y4Ut4N7BGsXDv zL6Txk9e4aUrWWiw98kU2YzzsnLooUUJTN6uLJK0dE7l7LTCmSJhyZ/iZ+R8qxohNX8Y y/7M88v62aKuzgwJ+GgMuge4/g//wPPV4tPLDAiulk7iL+DgEJ/X01IJiw488B84HZnM IVVQ== X-Forwarded-Encrypted: i=1; AJvYcCVbzC+l2UzjmqxF2PumeWV6ayqkqmny8XNrow703yJYhtv9U6TlCI9/Vr4mWkHUaVc9ErXkh5flerL0QCU=@vger.kernel.org X-Gm-Message-State: AOJu0YziJWIBItggtVLURIYseRSc8EK4iiqOKuQTKjQy2fm9KhbHyTwG zmc9tefcGD8RtY2De+Ab06y/vz8ZlPRWuDELpDtGIvN3hUVShYRJvpnT X-Gm-Gg: ASbGncu1RnV1k5hN2wc1lFAGHrShnkQ1gQ48fZ/CN6x7EzCDfbtdCaTA0/SzORdgxJi d66OUajxXxyhOCTJPmHmc4t5kPuY7cfAZn2mwS1txh4WIViVNKyuQM2quv1fxvjePJlqsLI0Tgi s7KZvfc/bGSeWJEeAlW3plM71tBlPLs0RiIRUPW4bK4r/e2XJbTonJAV2ZV8Ysw8z6V4TPyb6KC zkJLsWvfpEFrUctgmFWC+Np/EqsmP/8Fedcub+vF24yP5odCk4CTKpvEzjuBuhTRF8ipMCvM4VS F0/1GUOZJOIqpRF1rWCu32oJghIjPy6knEF+Uxb+fFC+6ss8W5uvEPY7OXDXvzYBJPBfpyJXu8K IsuPxL9eDn9ZFl4bKm3g0CVFU5GXFnFpI9pBN0RalviI0AO08X7E= X-Google-Smtp-Source: AGHT+IHZQHFJ0S5f1OcQHCfxhezQQXZPltJgxW4zc1dj/mXykewUGOJa1V03DnNOst08ID094gfxBA== X-Received: by 2002:a05:6512:3e0a:b0:578:ed03:7b70 with SMTP id 2adb3069b0e04-58af9f6afccmr1528057e87.28.1759346812509; Wed, 01 Oct 2025 12:26:52 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-58b0112414fsm136627e87.28.2025.10.01.12.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Oct 2025 12:26:52 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki , Michal Hocko Subject: [PATCH v3 04/10] mm/vmalloc: Defer freeing partly initialized vm_struct Date: Wed, 1 Oct 2025 21:26:40 +0200 Message-ID: <20251001192647.195204-5-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251001192647.195204-1-urezki@gmail.com> References: <20251001192647.195204-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __vmalloc_area_node() may call free_vmap_area() or vfree() on error paths, both of which can sleep. This becomes problematic if the function is invoked from an atomic context, such as when GFP_ATOMIC or GFP_NOWAIT is passed via gfp_mask. To fix this, unify error paths and defer the cleanup of partly initialized vm_struct objects to a workqueue. This ensures that freeing happens in a process context and avoids invalid sleeps in atomic regions. Acked-by: Michal Hocko Reviewed-by: Baoquan He Signed-off-by: Uladzislau Rezki (Sony) --- include/linux/vmalloc.h | 6 +++++- mm/vmalloc.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index eb54b7b3202f..1e43181369f1 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -50,7 +50,11 @@ struct iov_iter; /* in uio.h */ #endif =20 struct vm_struct { - struct vm_struct *next; + union { + struct vm_struct *next; /* Early registration of vm_areas. */ + struct llist_node llnode; /* Asynchronous freeing on error paths. */ + }; + void *addr; unsigned long size; unsigned long flags; diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d83c01caaabe..9e29dd767c41 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3687,6 +3687,35 @@ vm_area_alloc_pages(gfp_t gfp, int nid, return nr_allocated; } =20 +static LLIST_HEAD(pending_vm_area_cleanup); +static void cleanup_vm_area_work(struct work_struct *work) +{ + struct vm_struct *area, *tmp; + struct llist_node *head; + + head =3D llist_del_all(&pending_vm_area_cleanup); + if (!head) + return; + + llist_for_each_entry_safe(area, tmp, head, llnode) { + if (!area->pages) + free_vm_area(area); + else + vfree(area->addr); + } +} + +/* + * Helper for __vmalloc_area_node() to defer cleanup + * of partially initialized vm_struct in error paths. + */ +static DECLARE_WORK(cleanup_vm_area, cleanup_vm_area_work); +static void defer_vm_area_cleanup(struct vm_struct *area) +{ + if (llist_add(&area->llnode, &pending_vm_area_cleanup)) + schedule_work(&cleanup_vm_area); +} + static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, pgprot_t prot, unsigned int page_shift, int node) @@ -3718,8 +3747,7 @@ static void *__vmalloc_area_node(struct vm_struct *ar= ea, gfp_t gfp_mask, warn_alloc(gfp_mask, NULL, "vmalloc error: size %lu, failed to allocated page array size %lu", nr_small_pages * PAGE_SIZE, array_size); - free_vm_area(area); - return NULL; + goto fail; } =20 set_vm_area_page_order(area, page_shift - PAGE_SHIFT); @@ -3796,7 +3824,7 @@ static void *__vmalloc_area_node(struct vm_struct *ar= ea, gfp_t gfp_mask, return area->addr; =20 fail: - vfree(area->addr); + defer_vm_area_cleanup(area); return NULL; } =20 --=20 2.47.3 From nobody Sun Feb 8 13:09:43 2026 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F1F52EACF8 for ; Wed, 1 Oct 2025 19:26:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346817; cv=none; b=VDcCYbpUgJeu+WfipeedzgZiuuZZRpd4xnxDi+wS0AP7gaHC6oq0mfzxXNX5xSscoL1CFkPSJEkUcC/YRFw/j6ZnaKYHtET5tIGGiCU7UuhlbdiOJDaV0ksETzSwXo78+NIkNvUlKbA9c13sgfWpZXuXwAviS7KFX8MHmszDiJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346817; c=relaxed/simple; bh=ZVp9FIATnWymDAEfVzq5zKbM1xcp8hPB8sUKQ+bCiCs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j0cizFT8+ypkmV0TRQqyVle3W7neLe8I8TiiW1wqmN4L9AtA9B3N8Iel7+F6uBmXC+vCLNjwd7zxjbc6A4M782+r1SVcfccYxsDZSb0ec6+Eec6qqIIKLCRCUqNjB4eiZ6bi0zB54pU7HPdrZ/j7R9FilPt7M2i4PEyOEslJXYU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aMYDDm8j; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aMYDDm8j" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-579d7104c37so242541e87.3 for ; Wed, 01 Oct 2025 12:26:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759346813; x=1759951613; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0yCAVXUd+Xggdo34An12Zy3AWPX111PHofILGlMoG8c=; b=aMYDDm8jnCat9++0cksdn4Umvyzopri3Dx0APAZN0O7sM4nQ+ENRpTfB3nMGhOx9Qq /MWMh3YVNZZ5G8YpkVApZYb+ENHoPYAvAMkLvShXM11MYij18k1TTBtrKRzR80yhPh1Y IRvWdp9OeHyB2JnAUkLcRpjOSG8nSytF0RrK6rscDeAxL+YWusAGwRLiSdLbIgo/Ty5c qAtbwAshnR+/WvDuCQr8iqnUYeRG6XWNaf53ygi/Orq+XqLgWFwsmxaZOX/Lrud62Wjp 2tSHhmWXTY5frAYj2U+qFvr2k7R3zSJCsTPhU6gjAsGtP8WqjQZOdkNA+r9u+CD86bfa y7wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759346813; x=1759951613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0yCAVXUd+Xggdo34An12Zy3AWPX111PHofILGlMoG8c=; b=dOZE8E3R3vdSltgOB1YxgnlVUbFAfJ5pF3/FKb077UNyQPfT9G0aDQ0MWLD+hEFup4 pzXRNqh8wgAIoT8pL9zC6Ykw7zsQ/ytUh2VXC7lRr7bLdjZ4z5YgTa69+NJxB4aAs5Ps Ot1vwIs84roaI8FBm0C+sFnenLi7N1lExFe2TKyuUNLlZ6Cbe+hA0Pl6wWATt4JRJ7Gf vQb42/r0rk2hVjC1sf3dQfjfRITIU87vK1gS5ZdozlBVcuN1R/4Pixc2u1R3dkv3Dfod SdrE+U9oY2fZw+k5Z3YvTKNR2iG+E1CG+d+OXGP/xSnJ33AJvLadKshKiL2I+d11nVAI Byzw== X-Forwarded-Encrypted: i=1; AJvYcCU2bOvSDqpqB5tTg0C10gR+VqtPiU850UY9gJ8IWEAB05L0UWJlYpb5y1k35bpZX6cDYT/6GdR9Zxh7RtQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzXo2O6gG2wUdd6fjm1FxVFw5On9ps1JiW+AAO2/ooF5DoMIekN noFyuh0Vu5GoMATLAV/C5Kw7NBU9dc1rs5IfMylYqmMp+W+gy/YnMKMb X-Gm-Gg: ASbGncuICK00bSIrCzxaFn7hGbf7CIgAlk7MpBVJp1oPQ6FucfAtukUjLjo/Rlc6s0D mz47/v6SynSNVfFhO/dGyqPY+y9/5/plFTu4Gdoz83MEnuV35cIfFnQsLyqs7ucQcIn25Hsspxa pQ+ChKRfzi2eeF4acT0W7jPccQ3q1ykmgI6BeF7gOK9Zz/nX/85kZD0H5KlHiffc+E1cJuATTAB vpox7c7cs8QPoJNBLYwg6+WoF0RL/VhMkDOhxn3wuc+zyPUSuN5AdGQqb3yz4MKewE++exS/PIK FSKKEpbsu3Ku5IqDnBFGH/0gWEbhn+6z6m2GYZPNhJFsTdE1w/k/b6QLDZ4n2gVPafKtmTEay+P v1RX5YkoUwtnQgE8sU4sIEkMiByccSD2u4dbu7Niq8iZxHVC7I3g= X-Google-Smtp-Source: AGHT+IF5fzKNeL87En2CtBg9XIbVfY39t145FRGMU6tdsljRKNoG0mSUH5/2UDHarr9y/rtlcz5Xkw== X-Received: by 2002:a05:6512:23a9:b0:57b:8a82:1e27 with SMTP id 2adb3069b0e04-58af9f0d388mr1273724e87.13.1759346813320; Wed, 01 Oct 2025 12:26:53 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-58b0112414fsm136627e87.28.2025.10.01.12.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Oct 2025 12:26:52 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki , Michal Hocko Subject: [PATCH v3 05/10] mm/vmalloc: Handle non-blocking GFP in __vmalloc_area_node() Date: Wed, 1 Oct 2025 21:26:41 +0200 Message-ID: <20251001192647.195204-6-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251001192647.195204-1-urezki@gmail.com> References: <20251001192647.195204-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make __vmalloc_area_node() respect non-blocking GFP masks such as GFP_ATOMIC and GFP_NOWAIT. - Add memalloc_apply_gfp_scope()/memalloc_restore_scope() helpers to apply a proper scope. - Apply memalloc_apply_gfp_scope()/memalloc_restore_scope() around vmap_pages_range() for page table setup. - Set "nofail" to false if a non-blocking mask is used, as they are mutually exclusive. This is particularly important for page table allocations that internally use GFP_PGTABLE_KERNEL, which may sleep unless such scope restrictions are applied. For example: __pte_alloc_kernel() pte_alloc_one_kernel(&init_mm); pagetable_alloc_noprof(GFP_PGTABLE_KERNEL & ~__GFP_HIGHMEM, 0); Note: in most cases, PTE entries are established only up to the level required by current vmap space usage, meaning the page tables are typically fully populated during the mapping process. Acked-by: Michal Hocko Reviewed-by: Baoquan He Signed-off-by: Uladzislau Rezki (Sony) --- include/linux/vmalloc.h | 2 ++ mm/vmalloc.c | 52 +++++++++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 1e43181369f1..e8e94f90d686 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -332,4 +332,6 @@ bool vmalloc_dump_obj(void *object); static inline bool vmalloc_dump_obj(void *object) { return false; } #endif =20 +unsigned int memalloc_apply_gfp_scope(gfp_t gfp_mask); +void memalloc_restore_scope(unsigned int flags); #endif /* _LINUX_VMALLOC_H */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 9e29dd767c41..d8bcd87239b5 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3716,6 +3716,42 @@ static void defer_vm_area_cleanup(struct vm_struct *= area) schedule_work(&cleanup_vm_area); } =20 +/* + * Page tables allocations ignore external GFP. Enforces it by + * the memalloc scope API. It is used by vmalloc internals and + * KASAN shadow population only. + * + * GFP to scope mapping: + * + * non-blocking (no __GFP_DIRECT_RECLAIM) - memalloc_noreclaim_save() + * GFP_NOFS - memalloc_nofs_save() + * GFP_NOIO - memalloc_noio_save() + * + * Returns a flag cookie to pair with restore. + */ +unsigned int +memalloc_apply_gfp_scope(gfp_t gfp_mask) +{ + unsigned int flags =3D 0; + + if (!gfpflags_allow_blocking(gfp_mask)) + flags =3D memalloc_noreclaim_save(); + else if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D __GFP_IO) + flags =3D memalloc_nofs_save(); + else if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D 0) + flags =3D memalloc_noio_save(); + + /* 0 - no scope applied. */ + return flags; +} + +void +memalloc_restore_scope(unsigned int flags) +{ + if (flags) + memalloc_flags_restore(flags); +} + static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, pgprot_t prot, unsigned int page_shift, int node) @@ -3732,6 +3768,10 @@ static void *__vmalloc_area_node(struct vm_struct *a= rea, gfp_t gfp_mask, =20 array_size =3D (unsigned long)nr_small_pages * sizeof(struct page *); =20 + /* __GFP_NOFAIL and "noblock" flags are mutually exclusive. */ + if (!gfpflags_allow_blocking(gfp_mask)) + nofail =3D false; + if (!(gfp_mask & (GFP_DMA | GFP_DMA32))) gfp_mask |=3D __GFP_HIGHMEM; =20 @@ -3797,22 +3837,14 @@ static void *__vmalloc_area_node(struct vm_struct *= area, gfp_t gfp_mask, * page tables allocations ignore external gfp mask, enforce it * by the scope API */ - if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D __GFP_IO) - flags =3D memalloc_nofs_save(); - else if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D 0) - flags =3D memalloc_noio_save(); - + flags =3D memalloc_apply_gfp_scope(gfp_mask); do { ret =3D vmap_pages_range(addr, addr + size, prot, area->pages, page_shift); if (nofail && (ret < 0)) schedule_timeout_uninterruptible(1); } while (nofail && (ret < 0)); - - if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D __GFP_IO) - memalloc_nofs_restore(flags); - else if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D 0) - memalloc_noio_restore(flags); + memalloc_restore_scope(flags); =20 if (ret < 0) { warn_alloc(gfp_mask, NULL, --=20 2.47.3 From nobody Sun Feb 8 13:09:43 2026 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B9B32EDD7E for ; Wed, 1 Oct 2025 19:26:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346817; cv=none; b=eKfb4PeB5fomVP1Dzk3K+PqQLZNDwCNQLYvME8NWVOa7Zi132wrSGsMBzuBjmy+yc5ifXb0o6fzXbBFCAlZ3isISoWJHh5OSFP0aF+rglSXK5QY5nJDFQsRL+5zNK3pOyZCdPmISWPW6LnP9ywhmsEEz/d+4TWiHEHBnj1SFpLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346817; c=relaxed/simple; bh=xgrKQtQTGQJxm4PXSr9W8MvsYHHNgtLsWXzVqBHDSr4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eEv6p/HE3kYZxH6B1gtRsVonHJh/txvv3aIw998L+yFZ4t4+JGCwiE52nVSy8daAiE/1hGBjgPo0o6V7/g48Ioc2gu5cGSB4AAORWVmlgs9R6gILaLX/4PO8jt0iib26MuLdFVAuVSjD5AfWh0n7FeD9hMHgU2I6EOciiviBxJ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=j6WjRsZe; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j6WjRsZe" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5818de29d15so221684e87.2 for ; Wed, 01 Oct 2025 12:26:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759346814; x=1759951614; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CTx3t8206FADCajKY+kyp/2YAJmhuLjY8XEm0uYYaD4=; b=j6WjRsZe76FJu3RAaL/70yRB9pbIdE6lNvWEAD9hgUn5po/UVpiOejT2ORRcmEXx6i fFls7RlAi50GKfIjsMHhn+fsCzqEKqgqoTCI+gEE6hee0RP4qeshv4UUqYJjL3EuWeFN qYLdb+HTiVcQcy0zapZd4KeWFEdSJZDFwmsWj/cpIowlplpohZ2p7Eg3T5mN5xGVFFvD y3zNrND3/j6O/fETkrjAuT3/QPWV936P7ku7EgYCu5yKCRmD21712qprho39nUfS/Sls rUawvl8ze0W15fcYFEqjW4SvTtXYCH63aFvIV3eVHtvG34qBclVtyW+UECDtvR5iTxyr cyfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759346814; x=1759951614; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CTx3t8206FADCajKY+kyp/2YAJmhuLjY8XEm0uYYaD4=; b=O85OlwND+dNyC14yC/Twa7Us+ucZTSZ1UZaliWEEP36J1E/s32U575aWlUD2RNjk3c sA1KokGZShRdaoiiVjT4GrXJrkCVthk1YgClUt+hNJ9qPT/U6ve7la1sobFSYKRLt+Jj AEI46ryHoSbnG0X9TYzS1I9nlj6vv1wHVS1QP3kgPRYTEbdyhcke/jiCYSqwdAiPkMTn 3oeYebJV7M1r5Am3vghlWR6NFmnZwdTKnZus9jWR9zG0wsJW5nrtmhLQ73axQzVYCHP2 IWabtNMKv5ZGSsYqtJRz0GVVvtgK9DbXU76XcGnvq5elV3rz7KT3UftIPdVAC0M52bJ+ gqdg== X-Forwarded-Encrypted: i=1; AJvYcCVcSeEDPlad7ZkiLpez+j2fQvcK5Tigny5N6NyuKS09EwdL5mCsqnWcQ6t4I9CfnTjV+BcpF8+j+5I8+gA=@vger.kernel.org X-Gm-Message-State: AOJu0YyAha5ERS/z3cozD64veZuD2PM8d/5DbdUiErsU4d40r923VTUJ CHJTVT3+lZF9mhuvJNE7cZ8hzIOWtg7nC6YjjZmGBkguU5ddxN4K8a6+ X-Gm-Gg: ASbGncv2U0XB+Q5P7U/ocggBX2OYOBsMUwPtJFBORtpQfppSdXFc81X/gRf7my+w8fT PuE6z1DEtMEKjlGZViMb4JK4OdfvKU7V5ySFpFh0hh+i2S2+tezj8KwJh9mjDNuaeGw5sH2LsJW 1T/qlcO7w6LAcwaPtKW74lJuRsm4KXGLGTdivgzj+d25uuEttYUI5nRrzSOMIhCAi6ZY3bq/riY TIA/JrRpKIx6YUxzThKUFKVEPRS8EtcAq2IUtmw7JU0RA1oROqUNO6s6RxwFOPhaY1j0UKjcOpN iP4xSyxAfBSdCet/OQACjH1zZXNb7tjDkMFXJOAA5S/vvjj2slB0uXil6ogGJ7EbxJeDIdDtOlG 1IWFfPvqPdyoL0aqg+/iAnQ1yo5o4rxJ8EtlXta0u X-Google-Smtp-Source: AGHT+IEdIYEhyfROGcpz5tzh2C/c8xPkZaS+cLjfPY9+92lHTiKC3SF2fw4puKKC6CoPwT8eBnXURA== X-Received: by 2002:a05:6512:3a8e:b0:55f:4423:f52 with SMTP id 2adb3069b0e04-58af9f425cemr1391668e87.37.1759346814169; Wed, 01 Oct 2025 12:26:54 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-58b0112414fsm136627e87.28.2025.10.01.12.26.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Oct 2025 12:26:53 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki , Andrey Ryabinin , Alexander Potapenko Subject: [PATCH v3 06/10] mm/kasan: Support non-blocking GFP in kasan_populate_vmalloc() Date: Wed, 1 Oct 2025 21:26:42 +0200 Message-ID: <20251001192647.195204-7-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251001192647.195204-1-urezki@gmail.com> References: <20251001192647.195204-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A "gfp_mask" is already passed to kasan_populate_vmalloc() as an argument to respect GFPs from callers and KASAN uses it for its internal allocations. But apply_to_page_range() function ignores GFP flags due to a hard-coded mask. Wrap the call with memalloc_apply_gfp_scope()/memalloc_restore_scope() so that non-blocking GFP flags(GFP_ATOMIC, GFP_NOWAIT) are respected. Cc: Andrey Ryabinin Cc: Alexander Potapenko Reviewed-by: Baoquan He Reviewed-by: Andrey Ryabinin Signed-off-by: Uladzislau Rezki (Sony) --- mm/kasan/shadow.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 5d2a876035d6..a30d84bfdd52 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -377,18 +377,10 @@ static int __kasan_populate_vmalloc(unsigned long sta= rt, unsigned long end, gfp_ * page tables allocations ignore external gfp mask, enforce it * by the scope API */ - if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D __GFP_IO) - flags =3D memalloc_nofs_save(); - else if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D 0) - flags =3D memalloc_noio_save(); - + flags =3D memalloc_apply_gfp_scope(gfp_mask); ret =3D apply_to_page_range(&init_mm, start, nr_pages * PAGE_SIZE, kasan_populate_vmalloc_pte, &data); - - if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D __GFP_IO) - memalloc_nofs_restore(flags); - else if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D 0) - memalloc_noio_restore(flags); + memalloc_restore_scope(flags); =20 ___free_pages_bulk(data.pages, nr_pages); if (ret) --=20 2.47.3 From nobody Sun Feb 8 13:09:43 2026 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 048652FDC59 for ; Wed, 1 Oct 2025 19:26:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346818; cv=none; b=rp/nt4xWnIlc5VZ0DXeVbOr4/zVZbaFVNnQ+kLSIGo5uMyo7mOgCAFMRTiqIrCai057YOwfqIGR+YppWEN9t9klhgCnDiEjQXV3/rDXDS1M6BZHUSvglzF5u2GeNAgUIdoMpqUrHn+PzZpIQHYtvD8jyMwj9stM05rlRw8rLQmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346818; c=relaxed/simple; bh=6c2qdsekt/lCMkeMk65Hu+cWiGI0mmLXJB3D5AbXCc4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U14neCg74vwNQY893x6vsgyB6ZtJ6n4TkQYu9jbuk2nQnt15WbBfr9bBuwmqcqxLjk2iXReluVfrfNds7Obo0I2mQysppR5AZdGQgwQL6MnbOwB0Fr/gI0WiS/tS7TSpOCm7fFYkk/GJzaEdGadi2BcOmWYmJ0tufwP4D+nLFQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aThPFWWJ; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aThPFWWJ" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-57da66e0dc9so225508e87.0 for ; Wed, 01 Oct 2025 12:26:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759346815; x=1759951615; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ynvmccn9zBZNQHviUDaoxb4f3kqsprve2CRTYJdnjMs=; b=aThPFWWJ0TtS/rJuTTDvg70HPpGwThNq+hs8BgGxyItCzqqIIyjer/5++9c4hy2y6D 2Q6C1Muk6DsBM7lrB1zgolDQpbf7+WGYcgtXp8xWmJ6tBkxeGXY5jYRib6kc2x1I+u12 o7s+PoXbnPni/Vuq/hw44IERX4Qvgy1ZGdHu1qz0T68VCfz87lxi/CpxMXRErJoPJOcd +0e5gjcOeiFnmzoh2iH1Tq3qq94rmmXSGiDNhWsAgR7SGx1GYAiLoMOpnKPr5UIWjtV7 y4KEV81noh/Tu/qQWSzfmqQYLm3aqy4fBc7BQrCIIHQ029Na+C4jGIe8xPC69qzhQYUq jEVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759346815; x=1759951615; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ynvmccn9zBZNQHviUDaoxb4f3kqsprve2CRTYJdnjMs=; b=HZatfvGqnBiy2CJGYXxc/8LYsIiXGKi6k0CNWRPcw7sW+26OGOueJzsoj5U+J9ECu8 9ZzzAkFD8ZSGFtkVdBks3ktF+qlVFlxUS0TgkcariLjGonZNwTbhtLnLteg1VcF3HKJ6 jMjatL2kzTNh1Bxy4jYTALeVn2pWI98o4DFGb+7m827qfRqjClOchYtKTi3yG5nBbvud RTyf+8KMQBffMoP1bKZBUuTzVbMuNb0e3ShoLIqvGlPqa/XcISYmi2H0wRh3qOyZeu9G r3RCYBTx4NI6NlqJtXoH0TuBHg3O6en0k/eo17lrm0qpAgdtBJoHVtD8s5LppHz8Cfzy eJvw== X-Forwarded-Encrypted: i=1; AJvYcCXimfAF62Ej3ideGD+Vy8vau97NFoHnh+j5hcReWomA9BCk/0RTfEum8GMyaJ99glClMrH6dEEbCV4d/xk=@vger.kernel.org X-Gm-Message-State: AOJu0YwNQnnf5xTpKaAu7iPApeGk4rITudXsx+egyUZDDDf3MO+PyOQk dA5bzqkpRQB6ThQAd6h+NuJA4U7SJ1mn/xtjmnH3AAeto05AJoD4MEPe X-Gm-Gg: ASbGnctEsJ664/MOceVRqd6AtvbERqUX+zTokhF/MU69BvKwnO6cwaWrisZvMDJV/cV h5q80e0u1v/hiwd11bZecosDNvKBsOfj/n/y6cLeaby3apc1nmuIjbNsVb6vuqJ2ks11gZDlDIC OkAkAuYJnltgYh2tSKS0ydUDqtOjMNl7uwFf7S4JaDcGndSMLin6JSCiDJaHEP+cnSuPgoN8LVi NdguYXoxIBlKWsRQVT47hJpkegkDgTG5M6R2ud8ql3N8axJexDDbwf/W0t0XIQD0qwuCh3rwk2y J89n4Nh/SGDAmMUqHGdlFVPwL0hPtjKadegk7vqslUexH/uLZ1TizrP3EsomCIB9YHDjxTr9PDr Yac/ltJYVFPboHhAj++OKbFwlyb+bLlsquiGzbz6v X-Google-Smtp-Source: AGHT+IEdomr7Qvfls97HYRBk5Mx/YGp7v9+/XeOoVOqM7iGX9Gve8C9BG6twnSsknG3MVOR88kGX0g== X-Received: by 2002:a05:6512:31d4:b0:578:9b92:75c7 with SMTP id 2adb3069b0e04-58af9ebced0mr1554547e87.7.1759346815008; Wed, 01 Oct 2025 12:26:55 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-58b0112414fsm136627e87.28.2025.10.01.12.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Oct 2025 12:26:54 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki , Alexander Potapenko , Marco Elver Subject: [PATCH v3 07/10] kmsan: Remove hard-coded GFP_KERNEL flags Date: Wed, 1 Oct 2025 21:26:43 +0200 Message-ID: <20251001192647.195204-8-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251001192647.195204-1-urezki@gmail.com> References: <20251001192647.195204-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" kmsan_vmap_pages_range_noflush() allocates its temp s_pages/o_pages arrays with GFP_KERNEL, which may sleep. This is inconsistent with vmalloc() as it will support non-blocking requests later. Plumb gfp_mask through the kmsan_vmap_pages_range_noflush(), so it can use it internally for its demand. Please note, the subsequent __vmap_pages_range_noflush() still uses GFP_KERNEL and can sleep. If a caller runs under reclaim constraints, sleeping is forbidden, it must establish the appropriate memalloc scope API. Cc: Alexander Potapenko Cc: Marco Elver Signed-off-by: Uladzislau Rezki (Sony) --- include/linux/kmsan.h | 6 ++++-- mm/internal.h | 4 ++-- mm/kmsan/shadow.c | 6 +++--- mm/percpu-vm.c | 2 +- mm/vmalloc.c | 26 +++++++++++++++++--------- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/include/linux/kmsan.h b/include/linux/kmsan.h index f2fd221107bb..7da9fd506b39 100644 --- a/include/linux/kmsan.h +++ b/include/linux/kmsan.h @@ -133,6 +133,7 @@ void kmsan_kfree_large(const void *ptr); * @prot: page protection flags used for vmap. * @pages: array of pages. * @page_shift: page_shift passed to vmap_range_noflush(). + * @gfp_mask: gfp_mask to use internally. * * KMSAN maps shadow and origin pages of @pages into contiguous ranges in * vmalloc metadata address range. Returns 0 on success, callers must check @@ -142,7 +143,8 @@ int __must_check kmsan_vmap_pages_range_noflush(unsigne= d long start, unsigned long end, pgprot_t prot, struct page **pages, - unsigned int page_shift); + unsigned int page_shift, + gfp_t gfp_mask); =20 /** * kmsan_vunmap_kernel_range_noflush() - Notify KMSAN about a vunmap. @@ -347,7 +349,7 @@ static inline void kmsan_kfree_large(const void *ptr) =20 static inline int __must_check kmsan_vmap_pages_range_noflush( unsigned long start, unsigned long end, pgprot_t prot, - struct page **pages, unsigned int page_shift) + struct page **pages, unsigned int page_shift, gfp_t gfp_mask) { return 0; } diff --git a/mm/internal.h b/mm/internal.h index 1561fc2ff5b8..e623c8103358 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1355,7 +1355,7 @@ size_t splice_folio_into_pipe(struct pipe_inode_info = *pipe, #ifdef CONFIG_MMU void __init vmalloc_init(void); int __must_check vmap_pages_range_noflush(unsigned long addr, unsigned lon= g end, - pgprot_t prot, struct page **pages, unsigned int page_shif= t); + pgprot_t prot, struct page **pages, unsigned int page_shift, gfp_t gfp_ma= sk); unsigned int get_vm_area_page_order(struct vm_struct *vm); #else static inline void vmalloc_init(void) @@ -1364,7 +1364,7 @@ static inline void vmalloc_init(void) =20 static inline int __must_check vmap_pages_range_noflush(unsigned long addr, unsigned lon= g end, - pgprot_t prot, struct page **pages, unsigned int page_shif= t) + pgprot_t prot, struct page **pages, unsigned int page_shift, gfp_t gfp_ma= sk) { return -EINVAL; } diff --git a/mm/kmsan/shadow.c b/mm/kmsan/shadow.c index 54f3c3c962f0..3cd733663100 100644 --- a/mm/kmsan/shadow.c +++ b/mm/kmsan/shadow.c @@ -215,7 +215,7 @@ void kmsan_free_page(struct page *page, unsigned int or= der) =20 int kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end, pgprot_t prot, struct page **pages, - unsigned int page_shift) + unsigned int page_shift, gfp_t gfp_mask) { unsigned long shadow_start, origin_start, shadow_end, origin_end; struct page **s_pages, **o_pages; @@ -230,8 +230,8 @@ int kmsan_vmap_pages_range_noflush(unsigned long start,= unsigned long end, return 0; =20 nr =3D (end - start) / PAGE_SIZE; - s_pages =3D kcalloc(nr, sizeof(*s_pages), GFP_KERNEL); - o_pages =3D kcalloc(nr, sizeof(*o_pages), GFP_KERNEL); + s_pages =3D kcalloc(nr, sizeof(*s_pages), gfp_mask); + o_pages =3D kcalloc(nr, sizeof(*o_pages), gfp_mask); if (!s_pages || !o_pages) { err =3D -ENOMEM; goto ret; diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c index cd69caf6aa8d..4f5937090590 100644 --- a/mm/percpu-vm.c +++ b/mm/percpu-vm.c @@ -194,7 +194,7 @@ static int __pcpu_map_pages(unsigned long addr, struct = page **pages, int nr_pages) { return vmap_pages_range_noflush(addr, addr + (nr_pages << PAGE_SHIFT), - PAGE_KERNEL, pages, PAGE_SHIFT); + PAGE_KERNEL, pages, PAGE_SHIFT, GFP_KERNEL); } =20 /** diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d8bcd87239b5..d7e7049e01f8 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -671,16 +671,28 @@ int __vmap_pages_range_noflush(unsigned long addr, un= signed long end, } =20 int vmap_pages_range_noflush(unsigned long addr, unsigned long end, - pgprot_t prot, struct page **pages, unsigned int page_shift) + pgprot_t prot, struct page **pages, unsigned int page_shift, + gfp_t gfp_mask) { int ret =3D kmsan_vmap_pages_range_noflush(addr, end, prot, pages, - page_shift); + page_shift, gfp_mask); =20 if (ret) return ret; return __vmap_pages_range_noflush(addr, end, prot, pages, page_shift); } =20 +static int __vmap_pages_range(unsigned long addr, unsigned long end, + pgprot_t prot, struct page **pages, unsigned int page_shift, + gfp_t gfp_mask) +{ + int err; + + err =3D vmap_pages_range_noflush(addr, end, prot, pages, page_shift, gfp_= mask); + flush_cache_vmap(addr, end); + return err; +} + /** * vmap_pages_range - map pages to a kernel virtual address * @addr: start of the VM area to map @@ -696,11 +708,7 @@ int vmap_pages_range_noflush(unsigned long addr, unsig= ned long end, int vmap_pages_range(unsigned long addr, unsigned long end, pgprot_t prot, struct page **pages, unsigned int page_shift) { - int err; - - err =3D vmap_pages_range_noflush(addr, end, prot, pages, page_shift); - flush_cache_vmap(addr, end); - return err; + return __vmap_pages_range(addr, end, prot, pages, page_shift, GFP_KERNEL); } =20 static int check_sparse_vm_area(struct vm_struct *area, unsigned long star= t, @@ -3839,8 +3847,8 @@ static void *__vmalloc_area_node(struct vm_struct *ar= ea, gfp_t gfp_mask, */ flags =3D memalloc_apply_gfp_scope(gfp_mask); do { - ret =3D vmap_pages_range(addr, addr + size, prot, area->pages, - page_shift); + ret =3D __vmap_pages_range(addr, addr + size, prot, area->pages, + page_shift, nested_gfp); if (nofail && (ret < 0)) schedule_timeout_uninterruptible(1); } while (nofail && (ret < 0)); --=20 2.47.3 From nobody Sun Feb 8 13:09:43 2026 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC1A430215A for ; Wed, 1 Oct 2025 19:26:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346819; cv=none; b=id3IobqOdRloOFFl3xt8JXI93ND1bZxJQiH86xGaqLpSHRMoG6lsiRYGILTn29K+dVzI4Hf7rs8w5Q0cNbbCIEgVhulXy8yCNXuflJLDsuW0BOaxvWXTDpmsOXza7pfSFV0exZPzpIq6pwsOiFfIME+u9UVqZQninDOb616nTPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346819; c=relaxed/simple; bh=IK1bwSNtA4XxkG3lyr951pjs5Cd9+Svig987Fm4zdbY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uKR0Wh9MFaC5dFFp3bxal3OWFGhjWpbfaFUi2/BqjCGXmsJgoePT/ab9tnpUkCW597+AGqorPqdStFx7r426zwPAD+qYmdrwzaP0yCpLXBPNgadwN8FNDqiuxlIqmccgCHFRgUq7kdEeaehbLc63ffwwQqrtQU3Atikx/VDx/O0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mRC0hBIp; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mRC0hBIp" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-57da66e0dc9so225524e87.0 for ; Wed, 01 Oct 2025 12:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759346816; x=1759951616; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xkBi4jfGKtCYgzp1QyKIde+SrLm3hIwzDlMhFP9SOB4=; b=mRC0hBIp+JgcHCGcdl7CAFxyLa+OGUB8JFxxQCwCEp87yHSiqj309stSS3fb26NBwj z8BFEEV/WvB/0iX/dVRar7XOZfkBibUza87BXcQnl20DujWldK8R5O4lwcnnzt3dXEvw D+OrMRHI7t5rjLBxQq1invc2kWwPKnxsDH5z/WOMT2GQPlNTd9/IEW4aX93bYPfwdPyj ozg1qMkI81yPHy/Ki6YkI5hfCxNOfsxnPJ8oQzTarKS4L0TN2WUcSmhYxkJ8rLMUKvRY y5M6ttleSxR1NsUVWn95mlRvf+g6scGEVcVu7w/0VhhfAh6cmpd21+CBmvqw0pPYOACy lYfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759346816; x=1759951616; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xkBi4jfGKtCYgzp1QyKIde+SrLm3hIwzDlMhFP9SOB4=; b=FPOL7AStjSeHOu+8tawQfQ0lwZqSCp07UaYnCvNMYs/tGhzadBkBum0LKbLLt9Dwsn 6Pvvi7D1inKoXmNWss6DTUpmMQfxS89PbTuHYbloBLRyxszwePu8Tv0E88qfjl2YME23 QiuNido5lhDPRw7tUd6uOmxUIfdWH2nbzgxfGlqysZKoqc1WjtcQTn2zNGrUaeWB5N0J ra1SogRCppKsO36V+P6G/rB0NpH19jcpsT5AxAtJrMe+6vf0mJnaIA7Yej0iq5nNpJBd tnZoVt+ntVPSHswQ1x+zHHdWerrYM99uiWaifZaJs8kHhdQYkuPCMXjOWG9H0F1Vc5Mv kSqg== X-Forwarded-Encrypted: i=1; AJvYcCW8Zwz7ZQJ824NB+hWFmJfZVarLeglNdbHWW5aMJMKUJ3tb984CPir4XLtsLFptbAcHNK/8eaDlWBdleQM=@vger.kernel.org X-Gm-Message-State: AOJu0Yxu8AovgFqOEzysXliBberDoJ3rI6Ngrt7l2s77NcQU7KmvT1HO +fH4SyzGa+3pM7fUO6KfX3MDGR7mM+N94g2fSFKMgGNnrzuLMO9rg4Xanj9hAhV4r7A= X-Gm-Gg: ASbGncve6TeN2roi6e75rAfVASXyBeWNgiwaXValyx4Q6cghNAF+/nRy2Q5I7Bdr1Vz 5Pn1OtuiDwVQoyz7WzWSNsrw+vMARaQUOXHZwORBHXLCxlKf8EtKj5HTfJrdjoOxJdseZqt78CE 92kQ0MPtGpuxe33h8vQkIp3+1bX+9v88I8ozds5dY7MrTrN8clldZvCqieGH8AkssJFgN8vya01 lyvbZELulqRXQmLO6JghYAx+8UAxPyoXundjOYoV4SlCLnzt7HjrGZdP80Kt2hFB7b4ZjmWI7F1 /jGtkp8POKZkPsitsZS18r4MJS+LYLG7F5ILXgy9FhX129eoTzFwr4JHxS1lDKkGE2kBDhy7sej dMHjoB4RdrPpcqjatYtniio4lfAtUMsk8SWKJ2+CV X-Google-Smtp-Source: AGHT+IEkQiFaaGHGhvMaMWZ16i+DpN9GfXJ09NHbrvk7y7MEplCQ54CMiAjG/D4d/KqWTkIk76Mo9A== X-Received: by 2002:a05:6512:308b:b0:585:b05f:9459 with SMTP id 2adb3069b0e04-58af9f38cccmr1321362e87.27.1759346815828; Wed, 01 Oct 2025 12:26:55 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-58b0112414fsm136627e87.28.2025.10.01.12.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Oct 2025 12:26:55 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki , Michal Hocko Subject: [PATCH v3 08/10] mm: Skip might_alloc() warnings when PF_MEMALLOC is set Date: Wed, 1 Oct 2025 21:26:44 +0200 Message-ID: <20251001192647.195204-9-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251001192647.195204-1-urezki@gmail.com> References: <20251001192647.195204-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" might_alloc() catches invalid blocking allocations in contexts where sleeping is not allowed. However when PF_MEMALLOC is set, the page allocator already skips reclaim and other blocking paths. In such cases, a blocking gfp_mask does not actually lead to blocking, so triggering might_alloc() splats is misleading. Adjust might_alloc() to skip warnings when the current task has PF_MEMALLOC set, matching the allocator's actual blocking behaviour. Acked-by: Michal Hocko Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Baoquan He --- include/linux/sched/mm.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 0232d983b715..a74582aed747 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -318,6 +318,9 @@ static inline void might_alloc(gfp_t gfp_mask) fs_reclaim_acquire(gfp_mask); fs_reclaim_release(gfp_mask); =20 + if (current->flags & PF_MEMALLOC) + return; + might_sleep_if(gfpflags_allow_blocking(gfp_mask)); } =20 --=20 2.47.3 From nobody Sun Feb 8 13:09:43 2026 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F32E303A02 for ; Wed, 1 Oct 2025 19:26:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346820; cv=none; b=GPcW6b1CN0WXWvpF+OgL+JTTTxy6eNto/qpnsuLncFuLOVFl4IKXU5xVYJCCH6XZtrcWHlJ5Mv01/b7QV/j8Uqc2eaSHG/+TdXoISqOzV4BH6EG2mFcojJ0sdm5DwQ12d9tXaY90d1l03y/wjoWCgdpXbETnP4fDMffh3m/0EmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346820; c=relaxed/simple; bh=Q9aVOYkAKq2gHcgevzm/IrzdwFh0JNa81Fz6ubWQC+8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HiMFKEIEkBvFEYlxGhykuXXyRXlMaHIQ0Jo0AUfU4xuqM3hepu+C3zcl8tLgaPamvtf1rBTYEelytrwP1Qm8YbaVILPsXkVKmIEJ+5PsJz/tpvFiP9YnVIgt0HkSV3y3oCZZjwiLwKBlOErvoUAioOzzrSlpbtSQGyd4OC2hs3o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YOGDEZSR; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YOGDEZSR" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-57a604fecb4so262372e87.1 for ; Wed, 01 Oct 2025 12:26:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759346817; x=1759951617; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IbYRlCl/Dzj0Jt1PXEP3jL/F9CvbCkzzyw4wzC1Iq2o=; b=YOGDEZSRQjqh5pU15EFAjzCDhP/V+pcdk4KtwSl2SfYnLqCY9EC7hMUBkWrE5BBBV3 8wMfujXitOzknSt0jJZWbLATlIAws29crFmyeipAadvSK8LujfbTd4v2aoGvZZwcRREt Tkjob7QyGUVFs12RlGhIjtSBMILjiIbpS7AqQGrMaxx/6nnk+frY2emoXOosChq2xwMQ 3ZlrKQqNg08dWOKf6Lkbspi7n7mq8dDEHpizy5raf05mvMJcAq9tDa1w05CDJ6e0cg5J TcSc9WE0iRJVPK3G7EBkp4Ge+JIL2zcwpb4lGkis+myTWlmUYBbczgnagI3fniHK8DzQ utpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759346817; x=1759951617; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IbYRlCl/Dzj0Jt1PXEP3jL/F9CvbCkzzyw4wzC1Iq2o=; b=rdnklM6Iocj5UXK+5Y724Hn6bIpTdvXHoMFoRedj4v9o4iV5lWcpDUfKlXJb+3pe8p rHA21NIWEsUtsvJ3bmJVSOvie6elBZWnM2GsnHNDDcqBjA+vIjHGRuQk2afCHDo83RCb 4vNGkviVpSwLBaD90dpdj75FJK97qwlr/6AEZLhI8jrXcZ5lo1kCVGpHExum5qHGzhH6 4RaMvS7BcHshXatklhqaMLTIFi3Bag4KdinAgGalHMNi49iikrpqM1kHf+HXYhfGcc8F MEyQBexUGs3V1ERDIt4iRC3MCvoTM7ah1MSAGTW0YdFS8Sd7t5/UIUQjJ9Ups/le8e3M JL+w== X-Forwarded-Encrypted: i=1; AJvYcCWvYtB5sGah5FdHVglgHO8I0YmO02nvoBdSTz+VJxV/x3hGY7Gizo0hWvut96z8lJrLqs+sNYThrKvqr84=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/yf+Z7s6PKabs0wnjjoc30klrGsCjAEFHdmxB0yMBvBx/QbdG As6qwf4VXNYXPA18yrg1d9iHDqx1pIQB4Mfdp3LTaU7auTAKFjIywgwc X-Gm-Gg: ASbGncvjFA11oFJYgl5nkTxn3H9WPNshoscSgaHPq43lSpfuRdEvqNta5tzU9k4ttKA CkFarnpxpXzzQNs8VfPtuaY8paiH+OlgsJ6GbT9hYhBI60sUia34xq6dDpqV9z7/od2OtzvPrZt cblQObo4JAjHs5RjgOwz5xHRxj3lN8Cy4kWfoV6rmjsutpFwWrFDVI5wwRqCEsqclKBLISbQq85 levlC6RHvQkcRe6Hhuzf+YzM1McTZIxwfgFAvoOHXlL9+AUiomjAABnY5ifMs9N6mxxf1Ii3bdO M1mwupnFEE2HhXd6i9M81JXU9L3Q1uj9xBswCDkfZ8RQuPU3naRpLo66B2sTGpFp8YY/zSwVkGF bIi5V/kkagbRVDqWuydxc9E3wiDe3YcIAWlvF+GAK X-Google-Smtp-Source: AGHT+IF9llFN2LXsjgVGkXyRw7BDqyfzeD80j0uo5mXamBd03EZQeOTEdSwaixEgJc8AVhTRjW6k2Q== X-Received: by 2002:a05:6512:3d01:b0:579:e5da:e530 with SMTP id 2adb3069b0e04-58af9efd33amr1535887e87.10.1759346816620; Wed, 01 Oct 2025 12:26:56 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-58b0112414fsm136627e87.28.2025.10.01.12.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Oct 2025 12:26:56 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki , Michal Hocko Subject: [PATCH v3 09/10] mm/vmalloc: Update __vmalloc_node_range() documentation Date: Wed, 1 Oct 2025 21:26:45 +0200 Message-ID: <20251001192647.195204-10-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251001192647.195204-1-urezki@gmail.com> References: <20251001192647.195204-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __vmalloc() function now supports non-blocking flags such as GFP_ATOMIC and GFP_NOWAIT. Update the documentation accordingly. Acked-by: Michal Hocko Signed-off-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d7e7049e01f8..2b45cd4ce119 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3881,19 +3881,20 @@ static void *__vmalloc_area_node(struct vm_struct *= area, gfp_t gfp_mask, * @caller: caller's return address * * Allocate enough pages to cover @size from the page level - * allocator with @gfp_mask flags. Please note that the full set of gfp - * flags are not supported. GFP_KERNEL, GFP_NOFS and GFP_NOIO are all - * supported. - * Zone modifiers are not supported. From the reclaim modifiers - * __GFP_DIRECT_RECLAIM is required (aka GFP_NOWAIT is not supported) - * and only __GFP_NOFAIL is supported (i.e. __GFP_NORETRY and - * __GFP_RETRY_MAYFAIL are not supported). + * allocator with @gfp_mask flags and map them into contiguous + * virtual range with protection @prot. * - * __GFP_NOWARN can be used to suppress failures messages. + * Supported GFP classes: %GFP_KERNEL, %GFP_ATOMIC, %GFP_NOWAIT, + * %GFP_NOFS and %GFP_NOIO. Zone modifiers are not supported. + * Please note %GFP_ATOMIC and %GFP_NOWAIT are supported only + * by __vmalloc(). + + * Retry modifiers: only %__GFP_NOFAIL is supported; %__GFP_NORETRY + * and %__GFP_RETRY_MAYFAIL are not supported. * - * Map them into contiguous kernel virtual space, using a pagetable - * protection of @prot. + * %__GFP_NOWARN can be used to suppress failure messages. * + * Can not be called from interrupt nor NMI contexts. * Return: the address of the area or %NULL on failure */ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align, --=20 2.47.3 From nobody Sun Feb 8 13:09:43 2026 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 727D6303C8D for ; Wed, 1 Oct 2025 19:26:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346821; cv=none; b=NNXOvMEdu6JFB1r9VEbGmyM5amjp0IwRduoQcZ52oPMKQf0h1VsFGQPtlFybZJfA2ZNJdDz/Wh1J7meSRzkfe5KcJVprwRM1nzZnSH6AvUVSQQDKS7f61d/ltg1NYDErqVZtuP36zuke0Xk+ZxTVnkuvLLP0fx4NLFYPVxbz8Zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759346821; c=relaxed/simple; bh=5W64q7JqsQ31eJoMJDFs0Iex3EGFmVJC2o273KNKjFQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UgrgDdQkioQ3aBqfDIlaZio4lji3/a0NrU9ie9w7GJFEyh1vbsMw+Mkztx4miIdEgAUaQYt/vfX6KY2tMNMYv2YAh/ziKV1M+lOWoylzunZCbA2oeavxLzb/VJF0/KGiWBcDb/k9Jp1Ftl5DU7zn6D2uqhQHi2Twj75jZwUIuzw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lFg+pFuI; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lFg+pFuI" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-57e8e67aa3eso1969421e87.1 for ; Wed, 01 Oct 2025 12:26:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759346818; x=1759951618; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eGcXmCAAujJZjKkzb6sJy5VjUrvDSK+t0JgV9AfB/HU=; b=lFg+pFuIMtCRv7IdAWQjOZbVoH0noDbD8Li9DnktpxyPZScg5yraOTVBk96iX3rDFv KUluvM+Oc9NrNpJTkhxKngIHc0XhqEGNYS7roTl9/wSBOgx/yUhe7A65HjC4F75OONaA zmHlKw1c1vclVpdBTkKbFyxQqwWtZYci/trIQpJVBUar+dR4k5KHdyEWL7hCj1v29Bhe L7d8eRX1XpesHsdMNMEzlGnWtKCx2f7X+hKvwSvQQMkfftliIwAmtpmBS5SFx4F/11Z1 jo+BqY+FrQ6Kz5TGz+rNU8InY46VonZWaOnNY6gLYiKrVZTtxixKhkNPS901Cmglrp9J fjeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759346818; x=1759951618; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eGcXmCAAujJZjKkzb6sJy5VjUrvDSK+t0JgV9AfB/HU=; b=KroO05qc8bQxQVTVHilL0Z1mpHjexESDsmdrfc2gYybRuq2M3x3JfsGufcgG3SbQJQ JJQUw9X/4GIA25O0FD0fr/UjIHqRroxl0hdsT2IVHSxe6AuKk+jxgAEpKQUuwDK+srDm 8bJ3eQ5aGRWQhIZep79qxu+A2I6rGD4YOldUmTdO6ZsvfMqrxygap8b/+ttcGskSvkPi CcM6y3eZjEf9MfYaOWvu7IHXEiFzj27T9kDurb7iawBOQhAE7mSrSqDLwZKoKLh20AGj y6UkgexEU7pHLc05l15Um0IclPlWfsDpRePQ54xKzVMjtf3c971Ru5xzhx25qWqnylj/ fOfw== X-Forwarded-Encrypted: i=1; AJvYcCWwObB9EkQqD+CD90ePXbUzzXiBz5E2zgKY1pcpSdYL0B6qLy6M/WcvyRfDYhyFpdxBB3SAS3CsOgEZpzU=@vger.kernel.org X-Gm-Message-State: AOJu0YxlWmIVWeZCpOZscaXZDY8tcmOZ8xsY3tjY6OyOFKmB5emOlZLR ZRDY758FplBRQD71vGXwOItcBWWoa/JOXjoBz6xbfkaN5nrvdsXv7Ki2HfcCACV3XD8= X-Gm-Gg: ASbGnctaeXa8iX2w+3R7p0JdJOQxRrN9fjH6TlDDAeOw6rPWr6sBkc72/1Ds2kFqWIq Dm6SdN73bL3Zx6i98/5WX7CbxmOvoIAh97Sim/K9+4/nCPMOkI6g0lmQNaicmj0k9f33QK7vy68 gxCSIqhSu9ReZ5lueBHeookSeeqGIV7MbgJUtKE5CNsmx+kAbKf7fz47QlJzhDEFPWsG9hEJDeN xr0iluIm3YcIJqatOMFEFgR0EK9o+5r2Z5dbMx2hLbFiPD8d8MurokfFLb3mlPKeHEWml8FJ1xI MGsc1SRhtBEGA/qCugESapATpRByvwg0G+m9/3cs2c6nSAa7PP1qfvUnxN/WAe6UojGMZ3JrKxd iBwsdc5K1aAGsotQyFTCuRehxVYOtXcmeU+de7xnd X-Google-Smtp-Source: AGHT+IFj81R2vtq1WyCNBYlhGONs/CusB8poOp8hUY/5PYbf+QgHwaSgauT7SatCZSoEjPU1zHqd6A== X-Received: by 2002:a05:6512:3da6:b0:585:1a9b:8b9a with SMTP id 2adb3069b0e04-58b00b5eb5cmr248354e87.9.1759346817420; Wed, 01 Oct 2025 12:26:57 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-58b0112414fsm136627e87.28.2025.10.01.12.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Oct 2025 12:26:56 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki Subject: [PATCH v3 10/10] mm: kvmalloc: Add non-blocking support for vmalloc Date: Wed, 1 Oct 2025 21:26:46 +0200 Message-ID: <20251001192647.195204-11-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251001192647.195204-1-urezki@gmail.com> References: <20251001192647.195204-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extend __kvmalloc_node_noprof() to handle non-blocking GFP flags (GFP_NOWAIT and GFP_ATOMIC). Previously such flags were rejected, returning NULL. With this change: - kvmalloc() can fall back to vmalloc() if non-blocking contexts; - for non-blocking allocations the VM_ALLOW_HUGE_VMAP option is disabled, since the huge mapping path still contains might_sleep(); - documentation update to reflect that GFP_NOWAIT and GFP_ATOMIC are now supported. Signed-off-by: Uladzislau Rezki (Sony) Acked-by: Michal Hocko Reviewed-by: Baoquan He --- mm/slub.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 584a5ff1828b..3de0719e24e9 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -7018,7 +7018,7 @@ static gfp_t kmalloc_gfp_adjust(gfp_t flags, size_t s= ize) * Uses kmalloc to get the memory but if the allocation fails then falls b= ack * to the vmalloc allocator. Use kvfree for freeing the memory. * - * GFP_NOWAIT and GFP_ATOMIC are not supported, neither is the __GFP_NORET= RY modifier. + * GFP_NOWAIT and GFP_ATOMIC are supported, the __GFP_NORETRY modifier is = not. * __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmalloc= is * preferable to the vmalloc fallback, due to visible performance drawback= s. * @@ -7027,6 +7027,7 @@ static gfp_t kmalloc_gfp_adjust(gfp_t flags, size_t s= ize) void *__kvmalloc_node_noprof(DECL_BUCKET_PARAMS(size, b), unsigned long al= ign, gfp_t flags, int node) { + bool allow_block; void *ret; =20 /* @@ -7039,16 +7040,22 @@ void *__kvmalloc_node_noprof(DECL_BUCKET_PARAMS(siz= e, b), unsigned long align, if (ret || size <=3D PAGE_SIZE) return ret; =20 - /* non-sleeping allocations are not supported by vmalloc */ - if (!gfpflags_allow_blocking(flags)) - return NULL; - /* Don't even allow crazy sizes */ if (unlikely(size > INT_MAX)) { WARN_ON_ONCE(!(flags & __GFP_NOWARN)); return NULL; } =20 + /* + * For non-blocking the VM_ALLOW_HUGE_VMAP is not used + * because the huge-mapping path in vmalloc contains at + * least one might_sleep() call. + * + * TODO: Revise huge-mapping path to support non-blocking + * flags. + */ + allow_block =3D gfpflags_allow_blocking(flags); + /* * kvmalloc() can always use VM_ALLOW_HUGE_VMAP, * since the callers already cannot assume anything @@ -7056,7 +7063,7 @@ void *__kvmalloc_node_noprof(DECL_BUCKET_PARAMS(size,= b), unsigned long align, * protection games. */ return __vmalloc_node_range_noprof(size, align, VMALLOC_START, VMALLOC_EN= D, - flags, PAGE_KERNEL, VM_ALLOW_HUGE_VMAP, + flags, PAGE_KERNEL, allow_block ? VM_ALLOW_HUGE_VMAP:0, node, __builtin_return_address(0)); } EXPORT_SYMBOL(__kvmalloc_node_noprof); --=20 2.47.3