From nobody Thu Oct 2 15:19:17 2025 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 4AE38319861 for ; Mon, 15 Sep 2025 13:40:46 +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=1757943648; cv=none; b=e0Wj/6Y9ifwkgqHW4bpgrHKQFRSfLbB6Euj9KmaRfLWKO+3e+8w2kIm2jmhL6H2LZCRw37zP8O/Hj0Ze8yzUw81cmQRc7QdJigRGDC+s2jManO2a5VRJu2CVXR0O29ULDIlBIQRkXLMtlwkPYUjN/SlzBz//NolpDvZHbLeJhAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943648; c=relaxed/simple; bh=997qQQu2kGJpN3V77byc+mN3wx8H8MkzOoZfy80SWDk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eV8iJmW7mIwm7DyGVWJfuKIFRIOXnv0+s2j8g6AAfam55MTsTNVnh70xM+7/8ZZ8J1A1wQZcQlYMRHFmgqW5YmAZH9kAFXe9tUCcS2JHEk5tF1SynmoARusKVOsHKJMA/nhhihPZ5PkoRrO2r8AZJty8J+kJclqm28zyYZ09NGE= 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=RnAPVPXn; 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="RnAPVPXn" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-5720df4acc5so1487094e87.3 for ; Mon, 15 Sep 2025 06:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757943644; x=1758548444; 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=RnAPVPXnZ/HvyjOSsFEVK+mKh/MFHjxisJjU+ex75uxY6MsdMo8qA2eYw2PWtkfS4M meXIFO9HXpqfOrEviB1C5t+lsAbsJ8FJdkpQl4cXdPjXFdfdALDigSnomRBdsy6fnO5f 7CMaPTgziF9tEuHkX6LG+p3lW7JDJHRRj74tzUe3Id0NCBhW3uB1daMzeC4mG+eKb+0x lRMmjqdPnp5xc1wul1/l/4BAvQ7E/6naootkwG/BkCZy2CEobmz7C7m4612q2jnA5e03 Fsf8zuEtV7E8AXXvdHLPUzas12D/H1b/cAF0WptqCxzbfc9oxKCe14ctTqKM8WAiBP6/ QTCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757943644; x=1758548444; 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=IPspiRmL5/CaG2YGXXMXwnJokCvUmU1qcP9RvfQNrO7QxJlDQdbNgCcGDs2I08lWYY ooIFN22yiOT3NfduFququtK0SKL9tX9YsfupXpCBQHNnJqkA56uTql/S5s5joxjJ7YsC w36Mw8Zm3rdZ5+o6dCtLRtnoikDwZBV0LfgdJbx8ydWABQQ/m6wrmtFMBHyr3WsNE0pu 8rw0JlJWpnt77VeHQPR3Fj5HFDOnzT28HnityKZb7kKia8D3VjuqAJ9bE7woPs2Re2m1 P8zo9x08XMNUnd5aL2kh+e7cUFGQem+EsOoWCgXb3gcc4KTtXGh3bclwDeTwFoXjfNDi WCuw== X-Forwarded-Encrypted: i=1; AJvYcCWhoVyZGLViri0p4eGtVS5hbRmhHCtZzUm4UKCGUebVK72TimKbJQQE2s5/n4kVRNwUvTC8RJWclzd2SwU=@vger.kernel.org X-Gm-Message-State: AOJu0YyKXv5yXzOqR3v3B46dGA+hqt14fgIs0uZ5kkXh4g+MwSbu0blt N1ooMZn7EWyFugLIV8WoGiJebynnJp4eZPwCCCJQXKH5PCNjQRzhSxYv X-Gm-Gg: ASbGncsbtxjw+6E3YyksYvQJAj+3Yu8jtFOmZTupsIBzzcYMj3mZ/RCt7wAEiw9uPCa kLQw4VEqc51svivmCKUboGxA7Gp9aTBGioyQD9xi4XCuzdGDEnollQ5GtHvMDDwDs1V02VWIYq/ kxg1/p3s9eL8C28Drakm/DnSP5tcbAHbtX0DZMchG6mlExJZZWoYZ13AV35BpFLZtxAch7mMWCZ SWvaueQ8+zqg/h+jTMA0O1PcFa3Rhs0wI/6VASZGi6HscT/1KpE0O9BR2HTxGt6CfaKZMhNGkrV pKmv18NjtJHDs5/SAHAiMhnmwOorw5TVvXA9jn3E/mvS/epfQrKkJPMqrCrtqJzF/3F+5IAeN2c 2Lc4HmNPtj9EUuUtkPSf4KFJzcJc= X-Google-Smtp-Source: AGHT+IGfCO5sUXBXkDHpAZfvRpmtA0Ce5XIe1FVG3pHRKDt98SzjVQvDcxRHyiA9Rb3v/QW8ww6Hyw== X-Received: by 2002:a19:6b11:0:b0:560:8b56:5dc4 with SMTP id 2adb3069b0e04-5704aaa0468mr2666530e87.8.1757943644004; Mon, 15 Sep 2025 06:40:44 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-573c8330e54sm1150719e87.63.2025.09.15.06.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 06:40:43 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki Subject: [PATCH v2 01/10] lib/test_vmalloc: add no_block_alloc_test case Date: Mon, 15 Sep 2025 15:40:31 +0200 Message-ID: <20250915134041.151462-2-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250915134041.151462-1-urezki@gmail.com> References: <20250915134041.151462-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 Thu Oct 2 15:19:17 2025 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 E3D7430E823 for ; Mon, 15 Sep 2025 13:40:46 +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=1757943648; cv=none; b=d4X+IJmvHyDgRk3N1h+nIRlc9puuVvORVjJATgoCyLiP0fdPpf+KPwmMPHe61mN0pz3muVhddRvq9sZA8sgfHCEQUMxy0XupJ7pMcQbLBh0UlQYx2thUmtW8nEQsVeH1crROYz2h0kUv4EJioOqmmRlle84xzW/jMU8dqQxTudE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943648; c=relaxed/simple; bh=Cid1o0yI6anA0oMjfZ5dvYwhgQOAZ2ZDCkuXoquLJSw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IQU3Wa4jH3WBEosek6HXtX0Ka/dPU+utcV64997W+OTpPgyUg12hBlUml5rcW76+6voANlA5hjNioCH17G9hdpK0zmO7RVX0lTiaiYX61++0TQ4WfX+QUMo65eYflaccPxpDx9+m03yz1vyIMPwXTLAEjT77ZvSd3fzLwJQZ6G0= 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=On20A5Sz; 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="On20A5Sz" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-55f716e25d9so4335260e87.1 for ; Mon, 15 Sep 2025 06:40:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757943645; x=1758548445; 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=On20A5Sz6Kr3N5KAu+PLbgEqNZq43zhMJUzSLugqxPOspsM5iv4iQQW9ZKF99jVPEC h4scfo5WZh++nLYt4NzbtxYSbAjdvAuqycuyOFwPk2BghlB92ppNdMlz3ZtUzQOtpWAh qjA13zt3b2HCVZPdveIS1GIS1J4NigHA7SLTWl0fjR3QvnY/svNWh+cJXigvuy9G1zKl 8EWzh20alACYgcfnNcZ4ICrkV8d3u1qByZfKqoPx8Q9oOozhxUqix+brC6udLUct5a5Z toapcq0jEnHmzh0syWMruPdX4bu/2sItRy+i/07MkY9x44cTi/Ub1aiVZB2UMTDprIQh hLdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757943645; x=1758548445; 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=U0Kt3oNN3+IJTdGrgNdTMvG3Hd0elEOKdySDSqc2YBgJegPg5nKUo01flP9EcOlcRf J1e/MIW3uOZ7Gv3AqTL9Eh0XTPhYQMFv1FwY+2MG+Pc/7VzNkRT7M46DBjE9CuJmb23K zLA/c3QiNbFbtOly2lpH4S+4eR7vqV6u6pGbKLVHxNrAlv6oZe560gTYACyZyvHQnmpU 8Ri7imJENf5p9SB9tR0A1nqjxFWVUPgWBdwSI3k+hhpL9APQfSLm4snHC7RhN+z44svX R0kPkt3i4b1sE6CK6hBBpe6cIwb9xFGur78SWA/6112E12SxTAg8+GIwVrYV3UjyTuPg M6Sg== X-Forwarded-Encrypted: i=1; AJvYcCWyD4Z2RwjZYCO+67ZNO4guDR1bKWaoSQivQutvHQjGfTvnBXxzBdIeckxBMndkQWmhyg6JUYrAHfPXdiE=@vger.kernel.org X-Gm-Message-State: AOJu0YwObK8BfZUt8DjHOMsmLG9L4WIMwJMX4yLiH9z5XaBOlbapnFqg 8mGwoXEdUlvNLWA/2D6kpRDZ3iXq3WRNb/H6LC1UiwwL/lZxdtSfo6XF X-Gm-Gg: ASbGncv8C5Y8/JEVPbct51LjQuorzTYmEQI/+cylKd/7hHi8znZHXjN8Kb6Qk8O8Xjs fPx1zJ9YxLbqT3V7vgx3wBAYwz4ejWjoZRmrlmrf/n76w4l+GCnXZhw0HmZH71RAfcppRfy8NZK bR4/P3YRGmH0UMhhsdnWQh1PVvVGEntEAByNuw2UvFxhP9TrIKbol1q/SapoRkbw6wTVDFdKWJz WsYf2+aoWMBC4cRYgiNWUicBTJYGdN3gETSU4IAHtpVrmFFziEqIBtu6ok4sq2Ww84r0fh13bsi Br2nK45DZHPgAfTWx7JfH2dEDv3BJ0laCa+/YbGfEbLnTIgW+6YGvq2zj433M0fYSmHZ6oVAySg gLhMw0rg5zJEODGgc X-Google-Smtp-Source: AGHT+IFfFqmM0jy7ylbFqglRpgiY5qZFquoCe9bp4TcomMhze69RBptnZFzQntvLjkxDYXF3stX3XA== X-Received: by 2002:a05:6512:3c8a:b0:55f:64b9:3ab4 with SMTP id 2adb3069b0e04-5704ca47523mr3450667e87.23.1757943644794; Mon, 15 Sep 2025 06:40:44 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-573c8330e54sm1150719e87.63.2025.09.15.06.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 06:40:44 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki Subject: [PATCH v2 02/10] lib/test_vmalloc: Remove xfail condition check Date: Mon, 15 Sep 2025 15:40:32 +0200 Message-ID: <20250915134041.151462-3-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250915134041.151462-1-urezki@gmail.com> References: <20250915134041.151462-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 Thu Oct 2 15:19:17 2025 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 D951A31B804 for ; Mon, 15 Sep 2025 13:40:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943649; cv=none; b=ayN5wRL/9+vxem47WaNAF6l3UubrhsDK6Z0hL+ROPHjQIYHA5vFKU2mbOjmbgwN+3JM68dlH85q6iyHm2UXBz9TbucybkPYymMwvJwNjoauKwb6uAfPT96ZcI+zMtZg27JKZ3i2Y8oI+y7udPaM1KNEV9s8IazG2Fdsrlos1PSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943649; c=relaxed/simple; bh=FBq/DDez1sx7se+2qA7U/NKGp3nbD5QcIkERwmMC/c4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZxwdL4jyM1LlDOEeLnGYVFxGo4E/pVV3qxLweB1S/pmgOQHBZsMLQw+YxHmbtzljyXKSCSivqUwmgw/Izmlx9mkXXkIGkL0O7294lcEQDpUyPDutzB58GdndpDyUpL2eZy1YwA9uSkPUZIuKrlMws3Z1OTD8YGx4AvzQTvSXaKs= 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=dnE6i71U; arc=none smtp.client-ip=209.85.167.54 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="dnE6i71U" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-55f7ab2a84eso4055618e87.1 for ; Mon, 15 Sep 2025 06:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757943646; x=1758548446; 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=OV1e2VNq+22/ypAjT1R5Vw3M7LwIDx8IopA7Om2mhzY=; b=dnE6i71UGQE+vama8PXnPMBbAiZxVI8zmtBBzwWy59J5ep+LQoqZSYWYWc4Ejxf2Eo DdBTqlS5cn4VqF2TJi+EWSjuLTn+bWXDU2datDt8XAmFLu0bUdBtci0xO53q7gPNTp2W OnCiSLObblrOb85DZNJj46/u03eOJ48iyLJpGyH40vHWpig+emrBapKw6Uz4O0g2Xdx4 /kvbtYE74YQ6pnYVWTRaGrY91GCbHIIUrc1eVl4D/9Vz+/95oZSp+wtdfCfn8xM4xK3O e3oKOT7TD7ZaEjJW7Qvt0CFyDCKxLmSLP8tvBj4cZ+nlziPtAcrQAwarCBVTso9zlpW3 6nmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757943646; x=1758548446; 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=OV1e2VNq+22/ypAjT1R5Vw3M7LwIDx8IopA7Om2mhzY=; b=GzLP7RGN8RVYW6DVBkdjHH+4PlFQO5KPJE7hmUaZC3Ep3V8NdoYxTU77FipekY+/Xa 9th2GnmPmSVTgnISAgMDwq50AYG6t9yYIaMD1s1UdyRrG1Uuys3TlP2RH6JFxluyeiPm 2eN7cW8fyPmZW9OcX4zQO7xY6SGgUb7GbUBHjRblWWyCMILkPXKz1njy0BbU1UFWYpGn 5tzFzkm9h1zZtsn8kqss6QmaXcVF4Jya6cqnQjWKuvoFFNePkjYRVgH4lMf4lqj+UcI4 XxEa9yf+tOWbeQZNdBFeRhsZiYOv/t6gHmvre6hP4/WXVpCvAKz00q3C6i1Y7B1ZFbt0 sx2g== X-Forwarded-Encrypted: i=1; AJvYcCWzBD1qiifkiRRlJQ9omACm6xJFaFnzZoWOOHssLq6SfGngnLoIYxsBgx9Zn9YzRkYrUGSpteYjD6tLDDg=@vger.kernel.org X-Gm-Message-State: AOJu0YypuHxRZClCInasqpodJfuGSZP98PDyMymiGw10XOxwZqNsf1Fi 2IoT8tx4YitNR/YeAZARC482D2Ttze4jNpcNQ+mWTxoOPJFy/EDS93f0 X-Gm-Gg: ASbGncu9rKQa5Fphf7roiMj2PXZ+v0J0Zp6NbiMUIgKtELpPMgP4R6yyNX7XoJx2Nw6 eVnKvvdYIYzfZ9XfPWMJYbsbiDm428bAVCtCdp07++z55Cc5vTs1B9oxwbMFArVt5TNwK67B3lO Ox9Et/OGR19bGCMVHvBQQLwoO8GboKiCOjXKFlGMxwYQYsA2kFy42+RVY0Yu06zNmFW40LnkXl6 eT4JCRCWcPADO6tyqs3DCM6CAmmSrVCl61/x5U6iGSdqHEYi9AkHZBj0wP2BTT4Hic481eUzlkg CcMcshKBdEuMKh5De0S6X3KapX+GwvTQzpM1b6BfL5wElF3GhoLgEJlyCMUwVUli/sZBCDDSZlb vBh98eLjOq7nSTGZ1pEZn7ptQw8M= X-Google-Smtp-Source: AGHT+IFMl/8ikQKbN8g7KTI8lfUmWOfTByEM9LJHJSKPa4fW2Bo+fguqUFOHKb+MoWYZ1jAerIJ9wg== X-Received: by 2002:a05:6512:61cf:20b0:560:9993:f14d with SMTP id 2adb3069b0e04-5704a3e6909mr3838025e87.3.1757943645704; Mon, 15 Sep 2025 06:40:45 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-573c8330e54sm1150719e87.63.2025.09.15.06.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 06:40:45 -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 v2 03/10] mm/vmalloc: Support non-blocking GFP flags in alloc_vmap_area() Date: Mon, 15 Sep 2025 15:40:33 +0200 Message-ID: <20250915134041.151462-4-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250915134041.151462-1-urezki@gmail.com> References: <20250915134041.151462-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 Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Baoquan He --- mm/vmalloc.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 5edd536ba9d2..49a0f81930a8 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) @@ -2065,8 +2067,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; @@ -2116,6 +2126,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 Thu Oct 2 15:19:17 2025 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 8B7E531A551 for ; Mon, 15 Sep 2025 13:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943650; cv=none; b=XXGjfjXskvwa6yb9Rmv8chQkqWJ8mZpF+J49sH+JmpzblyskaGhmGTt+kyZ14D3RBLmy8c/7A55nVahrwaxoDPgefrJO7S9sCzhYh31aGEmjN5EDMIC//Bsnv/3oK4HW9Z/a3M3iMjQh1NinXGC6WhNVVz3/7Ett319B9MnY16c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943650; c=relaxed/simple; bh=e6KwawUHwlDsoeQfcPpKLB3WBKhMwuphbIv5QMaRw6E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LVF1dqz2VL9lHDQfuSfLtoFNWybZ5m1l9S3Gj0G3gdR5m4XxLmuvQKmhVNUd6kSDVFea2hK+YTHyQkdodawX17n85iTj8Es9xI+3vETYVogqjnB7ifsgEXveZp/DRQ6MzUtTeVWqb/jSuQtrR+DXo/YQ1OSse9tH7NY9/dOmzgU= 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=NpshFscY; arc=none smtp.client-ip=209.85.167.41 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="NpshFscY" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-55f98e7782bso5135946e87.0 for ; Mon, 15 Sep 2025 06:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757943647; x=1758548447; 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=3k+HMxvoSODNJg+aOvvtyLIc8HnLU1Qgi5sDsLaNJTQ=; b=NpshFscYGtaHviU0tXUkI9jsUViss2iC303a/qDCTp9RahGIqUtdJTzsBcM0FZOHZ5 BJoi8tfxokZ8pMpOmfBIbm3PRGARpY05/age0DBTd03Wp5ZmwIqZhuBIchmmuVhk85lT BsWXD1vEgoudRKSqrX5yxA78uHeYoX2VxV38tI4Juotb5aQpGR1f5vMes7DXWRFMC0gT 6sDX0mfOErr1Jpfyvf0DtRMtiFtGcFVqfVhG2W5oIZi6I50v4e5wMSewGfnFFimbW1JY 07HZ75DxEIAinAMbc4QcFA9vf1PfWbGUqzPKViG/qb1qjPyuR0J+wFjsh4CJ5sz2tEmu 3Hlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757943647; x=1758548447; 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=3k+HMxvoSODNJg+aOvvtyLIc8HnLU1Qgi5sDsLaNJTQ=; b=VI2swb7BJ4iYIc0xHJhRd4n/G9oUQgVoiK5JpoGjVunxWCVcAh431OXEuxTl7xtkVU EenbYNRKRI/u/0LwaJzd4FyxWOJwl+SIGqcB5ESFyGNrC2twqdY2f5so3qxNuneyMdJ+ +yj+he0Hz8U2VAdCILTV8n1yi9uRx+UoHLxl6RT+I54iI+wh37eyvXZA+piC/SeF59kG jvWDo/Y/dvcdS2fAnr6tFB2YxKYvwdwXSWsO337pjYc7O2AS5DE7KHlENuzUp6inQL/C HWoInF6s4ACYSrB1N2iZqY1dOd/9REjmkdztTWxvXj52uf3m7qqixuzFcJPUhjGCPf7p LXrw== X-Forwarded-Encrypted: i=1; AJvYcCX02cqnS++79+7N+5+0ogBI9iv6f3uckFljAAm2Ji3o5+0LpAJYosldFgUEhnVGQCEOr4nx019/hE17OVw=@vger.kernel.org X-Gm-Message-State: AOJu0YwClms+nn40qQo9tLJFaLB0d7TzQmAy9lGdkKBj7iVBuD31UPo0 XudoLetwPJExUfah69W9LpIPTNCnhtvRE6tlrvXONPc1AwiVqW/uAjP9 X-Gm-Gg: ASbGncuNupJoiUch/L5UrsNC+HTaHQ89HyYpfOh5Ymm2Sa7eWHmSEAoqD8nPErAOIeA nqDRe530SOHCd+OOIIjOjI3H7fvbKVhagaL6uSEFmo2gASSqPIAn1eH3ENCdW/+ha56Q3iAOIxQ 9nYDL41onqaURKNHB8bswMI6eKI/v/euYnGc3S7AjyC/yob/r7zU4IDYHfX6TU9TPFDFn0u/fWv x72o99zvua2vGt9GfQD3l8pCdpkopK1pyF0LDHL4oq2OueXZz5Fr/W1Lun+/crI+iCBM0LNVRSv vfZ1wWtPe1TocK84M6r/vn+Bg0MtbP8VB18f4xRU3FmVuAaiQKJyiA23x5OPEhjGelt98gvPWbq L134mtd4hrGnpJfLNCLmnB8gGERk= X-Google-Smtp-Source: AGHT+IERKcOtfpXRTiN0QLo0iio7095LVUAyN+kLUsrBNmWW6XKvJmTj2p0WgeUQPLxrRtNOxCYwTw== X-Received: by 2002:a05:6512:ac8:b0:55f:3ae4:fe57 with SMTP id 2adb3069b0e04-5706133eb11mr3302428e87.20.1757943646550; Mon, 15 Sep 2025 06:40:46 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-573c8330e54sm1150719e87.63.2025.09.15.06.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 06:40:46 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki Subject: [PATCH v2 04/10] mm/vmalloc: Avoid cond_resched() when blocking is not permitted Date: Mon, 15 Sep 2025 15:40:34 +0200 Message-ID: <20250915134041.151462-5-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250915134041.151462-1-urezki@gmail.com> References: <20250915134041.151462-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" vm_area_alloc_pages() contains the only voluntary reschedule points along vmalloc() allocation path. They are needed to ensure forward progress on PREEMPT_NONE kernels under contention for vmap metadata (e.g. alloc_vmap_area()). However, yielding should only be done if the given GFP flags allow blocking. This patch avoids calling cond_resched() when allocation context is non-blocking(GFP_ATOMIC, GFP_NOWAIT). Signed-off-by: Uladzislau Rezki (Sony) Acked-by: Michal Hocko Reviewed-by: Baoquan He --- mm/vmalloc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 49a0f81930a8..b77e8be75f10 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3633,7 +3633,9 @@ vm_area_alloc_pages(gfp_t gfp, int nid, pages + nr_allocated); =20 nr_allocated +=3D nr; - cond_resched(); + + if (gfpflags_allow_blocking(gfp)) + cond_resched(); =20 /* * If zero or pages were obtained partly, @@ -3675,7 +3677,9 @@ vm_area_alloc_pages(gfp_t gfp, int nid, for (i =3D 0; i < (1U << order); i++) pages[nr_allocated + i] =3D page + i; =20 - cond_resched(); + if (gfpflags_allow_blocking(gfp)) + cond_resched(); + nr_allocated +=3D 1U << order; } =20 --=20 2.47.3 From nobody Thu Oct 2 15:19:17 2025 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 A48D131B82B for ; Mon, 15 Sep 2025 13:40:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943651; cv=none; b=cJ7/TPEeWakfKc1xrl0OMb31JHpzgS04Bge0Q07w8Y+1/7i7xSc9QNdy/DaE0tZZto07xwcXlNbsAMaO/KJKgHe2+csQ6PcArQFM2JgCwDXypzRDX76PW8cgQi5TMwXyxbTgXTJxA2/jSW37RNYNHtZj1yh50cFQEse/cdeh8HY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943651; c=relaxed/simple; bh=Q1/mYOo/jb61VwqzwlaOjMqKjlnR76dztMtJqcf/xAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tlAjQdXiyFksI/j8V+goQ9a5NxX6FbtSJsgdGtAhAz5Yql1TEAPG4L9JKjEI5hRAl9WBMRIpcTsEGpUVD1bGDWYwp42QPACf2Nc7Ri2KsggI6iu9BG7V/rCR9BrEalebEactpERDrheKCmI9odSpmK+wtxG1rdsMxMyKek3Yl74= 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=Crq4HnnI; arc=none smtp.client-ip=209.85.167.45 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="Crq4HnnI" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-55f753ec672so4662669e87.2 for ; Mon, 15 Sep 2025 06:40:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757943648; x=1758548448; 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=Jt/2LWtHGT9EgRO0DryBuNasAbNViAyk/FJTAlZaF7w=; b=Crq4HnnIoZ9PL8jx7EkSfAGYiEhLqxPPgzDsfLCmS03QHyZoibw97qKi3Wi8xq+Cn5 wZJPsFNnfBPYlUcYpF05TxrYRlGpWJQSsORc2aZw/YY6hiyIbHjXpcexB9oLOUGgmfXj Y5fAXK1hiBWkoJDjYGab46W1Q7iKsl0VoJC+oQ9MbVzWDRYLUN9WrmLzT4TLYFqXFjNm SNtsjrVyoK6N/RHC09niF3UjebLW7RmFlxVd10kOQLMN+CeGunZHDQZPSI/GD2VZmxkK ywLyuhncT+1tJubANeVZEWWTA40N7DaLIrM86jaYRBdalHFIckJZk1QG8XMKtP2EryYw f4vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757943648; x=1758548448; 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=Jt/2LWtHGT9EgRO0DryBuNasAbNViAyk/FJTAlZaF7w=; b=jyCboTr4SQ7OKSebepu9BXsPd1nI7h1EO+DmUVxtPuAxb3toYI7FFhE4IwsiRPWEfW 5MhTv4bTIv4oZzyxxXHhX/e+/9vE0gmAGxfs4NmPshOKbSu/5fuJdkU7WhG/2s4boIke /72/2sDhRro4ZJzzPdmrJCecDo3wumie9GItkwluGWaKSCewy2OvxJPoYgidCGbD9ZL3 jXlWXs7R2e8lPRuQHUXE4lqk6WZA/Kg3S7BGa+i/MuGqNsek+e3O2DwzFU5aISrZ1lza pcv3fRs4Xt7wlas4SuN48b2WFyimB0NXZGbpr7qaRBkypMLDAbJ3xWUuKR8HysySdkBl gCYQ== X-Forwarded-Encrypted: i=1; AJvYcCVMRQPwK/HgeaF5S8uw0MAP49XZGAgCkZIZ3G+7XlE45NO9alUONM2CsXB50lcgH87hOjDnaFrHMegMaZM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8j5zPdi/tN15/UotN6/M3suu0lVIPaRn829JlJeXVACHaL070 Y+7hRaAFjc9XyhkZwDl4DdyGdOlj7VvVcS7UzF/zZfaAS3CmeMddD8/o X-Gm-Gg: ASbGncts619DSqn4XjmivWVO+dDRWqiZpwQ7RF/PzDKwgstxUzZQZw6Oeepno37cpeO iVmJkyX+Q7+l+pde8+897qZYJhHTXM8Waisc4dUdpWIMDtRg9KYyHgh6VdWJ+luRXU06XwW7MXb +DIOlpsi4txz4sqsebrAVftVLr+wKr684g7Qx/VlV+9p6QozIDe0MODCIGWZWUCbm4EQ3cuc9dj 7IRumsBs0detxM/BE1pHpkJSL8XALvUXSv+TccpUfrrEeQPd6QAkJGp4ceFCSMatbwb1+ABwqSw Ftyf+31zZIGWgWT8MWzurg/nn4I4v+VdrAq5CaakXfE5js5et5w2ZUKbXghVJF830g1/jw3oJqG wio8Bx5+sqZ+qiB3vgfVZK4AbCDA= X-Google-Smtp-Source: AGHT+IFsE9P63lZm6RN6AXK4f+5FSZlBhHgIi0Y9I2WY4Ie/SPWsz/NGfvqkJ+OOyzYdciXpuKcc+g== X-Received: by 2002:a05:6512:2608:b0:570:8bc4:9545 with SMTP id 2adb3069b0e04-5708bc4a015mr3017588e87.4.1757943647381; Mon, 15 Sep 2025 06:40:47 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-573c8330e54sm1150719e87.63.2025.09.15.06.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 06:40:46 -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 v2 05/10] mm/vmalloc: Defer freeing partly initialized vm_struct Date: Mon, 15 Sep 2025 15:40:35 +0200 Message-ID: <20250915134041.151462-6-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250915134041.151462-1-urezki@gmail.com> References: <20250915134041.151462-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 Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Baoquan He --- 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 2759dac6be44..97252078a3dc 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 b77e8be75f10..e61e62872372 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3686,6 +3686,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) @@ -3717,8 +3746,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); @@ -3795,7 +3823,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 Thu Oct 2 15:19:17 2025 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 44C2A31CA68 for ; Mon, 15 Sep 2025 13:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943652; cv=none; b=SLvqybnEdoGUa9rjGlO/9FBF/elOB5Xna65QzCVMSvTBwfi1mJYMwOf+WGED7I3DdZngI8z/6F7eLWgF9k0PfnoALhVtGg13gm54/UF11DpSiRxqljqpz3XYVHcIbTs29LfVCsgpFlBG5A6JoKlS+oP+ucWeRN8nEjNMrITFY7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943652; c=relaxed/simple; bh=hzKRFCzFO3pghIGRyfnPUXUgalcXoKh8Z5rKsazA2mU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=exBQ7uXqt0yhKz4zdgdu6CyJnOw5Yw9QEQDhMi5PKbRaGvKLqpy3nUZOEcALZiAxdg8wMqejQVqckG7NZkCAmq5bgHKTq43aRxX8/IaAjmOHbc0mVq4hf4Br22AfJlSEapyr6kwsmUDGZItM68XLtokeO+1s9mD8L1COmQCeu3E= 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=VlAV7SCG; arc=none smtp.client-ip=209.85.167.54 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="VlAV7SCG" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-571a58b385aso3211823e87.2 for ; Mon, 15 Sep 2025 06:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757943648; x=1758548448; 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=/izOwppE0n2NGxkx7H9WLO0rOAXG+swxzYlRgFxl2qA=; b=VlAV7SCGb1dr3sWo0yI8pb/2/Hgg2/xAKk2ScMhkP1MEu8Rc/Is8+7ooy6PwrE6JOm uzgToBG9EjLXh5qjLmLHpfoU2GbA8Hm7fY/NgI+uafzkBuhGllnoUn0l/Yx0K1s+ZdMa 2YCOwUpqfYWSlX94jM8B8bC9P1bnFRulnAcLOH2EwYyhyR3QGB1H/KZrAyfcqBNTg2WX rb+V6UkinQ9DHv8fnePi43/U39G/YRTd/UK8mnRKNQPw59PZcN1dy9219muX2t3T0HBN Mk01awx52Pjr8HAlT8oR5staiz0mAgxSzXywI+jt5qYwNcGwDvnwKRxfuH4HWOmU1NEC IBQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757943648; x=1758548448; 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=/izOwppE0n2NGxkx7H9WLO0rOAXG+swxzYlRgFxl2qA=; b=I22+4cJ584NanUbRQdrG/ssE5MtVNruG80V91S4vY62wPNpQwynvkMrQS3eKbPtHoM MC2/mY4OKdJ2VF77EMztZgr0Z94lgHSrLkOYhQYIMJRIUTPOeOaEX0GXT6qcmS+XZus0 RU+qbDvhK3nAislfbdKuut+LkpbgN7ijTVTszgsp+gqzxg1aHpSipqk8yLxyLHweibjk V4FYOzzn/1svjed/fRr+IVdrQGz0E54VSQHL8HsAUC0ztlBQK2MtRIoxK1TaDn3p/5Ak 2JZmyhoX0RfUVEvWQnn5B7lqHap6jbW2Mse+ybnmgPk2G/xGXWnjm4Jjet2hvpyAZFOA IF8g== X-Forwarded-Encrypted: i=1; AJvYcCUlyrQVGIjHDE7WGflcc9kmWFPDCH9q/RAGAVy5xXeD3VhdxWNwgcTom0etmGJ+Ib/57kcOV4p5M7Obdog=@vger.kernel.org X-Gm-Message-State: AOJu0YxkeZAgzspgtDf8j76D1x++7rnRCgOc20HbhmcfDew0WIB7u00/ skKRnx6u7LtEiIFg8lnPIuG5Ptde8CfiW9Fyyh6Jnjy2GFoxWPVwDoX9 X-Gm-Gg: ASbGncuwmiG4RKglobC2WG5NtFGKwAgLLGSpvGLPG6eJOg1naFRcY20OuKcLf02jQOT oPcaKJ6kcgI1n329sKh1HRu+dBPk+gdJhc45wyZL0Cxbmx1VPQx53Bh+8jd1AEQZnORZDtHdpSy wcxOJ55noPynwS3SBURe7NtbxUxOvHhZDnBUmUTnhE0VNZPSW+/b5H/TnM7g74OG7pIXpXuXJYR xzQwOAc1DV87qQO8r1le9CkJComtrOhz3CN4Xhzq9hx1kdNTXkAjP+jdnkWkgbi9nN6d3a9qIjk m2bQu/n+c58Bs0L/pi/o032a+JyUOpo1waeCGG1x4+6AKjlrer4k2L3ZXjnazGxMIcFLBIj4J6g W5GhV9VDg6sNsm4MM X-Google-Smtp-Source: AGHT+IENNg57J50ZrYXCeFafqm5XRGYYIfDpp9Jex3+zwIfjPbel+BSgSSthUwdFCiApyxIO38UV3w== X-Received: by 2002:a05:6512:141c:b0:572:7e6e:d31a with SMTP id 2adb3069b0e04-5727e6ed4e0mr2026472e87.26.1757943648235; Mon, 15 Sep 2025 06:40:48 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-573c8330e54sm1150719e87.63.2025.09.15.06.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 06:40:47 -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 v2 06/10] mm/vmalloc: Handle non-blocking GFP in __vmalloc_area_node() Date: Mon, 15 Sep 2025 15:40:36 +0200 Message-ID: <20250915134041.151462-7-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250915134041.151462-1-urezki@gmail.com> References: <20250915134041.151462-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 Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Baoquan He --- 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 97252078a3dc..dcbcbfa842ae 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -326,4 +326,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 e61e62872372..5e01c6ac4aca 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3715,6 +3715,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) @@ -3731,6 +3767,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 @@ -3796,22 +3836,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 Thu Oct 2 15:19:17 2025 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 43A8A31D73A for ; Mon, 15 Sep 2025 13:40:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943653; cv=none; b=bj12h6DeP6SlMkk48AxVm4CqaOPpSxzkLzVw3eYFXxgngsaZQ5ITL3QUF6xFQWTzYH5Dpkv++SEHtbfM+3URZV4KD6uM/5/UTJFhfHpAOgBRJC7Ys+N093C+AanSwPcQyMmYGw8ylUVM+K3tuT7UA2QPIJnvLBlPA0vsgIbBpJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943653; c=relaxed/simple; bh=ttjmvio6QfWzCovg1C7MzOvfsRCArSCL+o0LkD/11Yw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dncy/FQ11B/Av9ptCL4xa2L+W2+rbIbrWAKVKIt5fiTsLuz8TYMFu9r/TD8gXEAzezb9ZVx2cxRdCgZUyZWDN+9+L3pJR28dZF8LvwPS8yVIf8T6gGCFtqWBxpUCOnyFpzryQ46jXwNbTPYEOxvjEAwZDj6xFVs/P8MfWS43TJI= 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=QAo9Kp/s; arc=none smtp.client-ip=209.85.167.49 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="QAo9Kp/s" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-55f720ffe34so4781345e87.1 for ; Mon, 15 Sep 2025 06:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757943649; x=1758548449; 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=7tWr/JqVgOvXu/F9fhJXup17MiB9k9fkyyqujUfoMQs=; b=QAo9Kp/s0X8JE1WvvTFC/Qoj8M/9tj1mFqXdWldX9QyfePfkM/2bXCW99LUyETTF55 xTEnx6KLxgLexahO4GGtUzFL5DewnztFbVpvS3ADuzsQY6fcEIFgoUnM3yFU+htq3q6l AM4VZciOZR3TK1nNm2uXR7Fgrl41ARYRdqseM5oHc+9z5tA33/k+TxAc3IJ8qTtn5RIU 6tPBnEcUCoaGTlfbXKhtKMG6QF0g82mg73IYc0WRxEACAoAbQYKW2uLXECMvIMKpFrMP ZjpSman5aFS/2mKqcyaO0I8sK0IXJTG6ePYCa1gHQd2yNefOR80DsDN+bcYhDNirpwJo LiDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757943649; x=1758548449; 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=7tWr/JqVgOvXu/F9fhJXup17MiB9k9fkyyqujUfoMQs=; b=NTTLSzfSYBEAojI7WLDuEPiGvEL2alQMiFUpKqBw1DjEH7OTf90pVkIdYOaNv3TMRM aiAWptFgVoo1aoyKmO7iWCF3LmStzA6XgsconELhWP2MPyaE9lxm7zMEhMkIKnpFa8NJ S6/JUYndtk6BkNNYrvRfk+TyjGdM/R6Ep4tBoSkgy0nd+t/HLL9oC9SPbp0TieClmo6n jxrbfSyL5lsRfQLBx8jt2QMXVYCOX5/nsbxz/hIAz1QunsgdoH0JXCqP9sVectBVdtIx MVJmpfTjvtgbRU02FamhQnCUMqIN0RrhtM9wlMW4rJDroRaAlJvsGJ00jZ9C9S82VgYh jYbg== X-Forwarded-Encrypted: i=1; AJvYcCXT3A6qOA8IAZ12EIJpWAlhEXTyzPLNatrscT2VsI0yWcrnV0CHuTqnt4xafQvexhqRr8KenScvHAq8c/A=@vger.kernel.org X-Gm-Message-State: AOJu0YyafS9+XvMBJ7rG++9kMZDUeAOk6lU4vuj0dZUfZyE822VrOKWB yWGySWDcdFz3hF53pWQafNV28NNkU8uuR8sypg7mY/5V36lS3TWPzcVQj8A2iw== X-Gm-Gg: ASbGncswjDw2cIyrqy4XlVd+Gi1VdzhoZ6lv1Yg3ELgw6X2ID2Cgmg0WNgjRviCD6JH oVww9Uix0MgbCW9Z3lRFqnTqcJc94U7ac0kFauWW8RM7Ua5p7OOlXGuy3RRNZXvr8rQAP2ougpQ p4nDNXDJGSCzsfW26qOkLJCX9Haupt0S/zv2+YhMZoEb5O2NfReriK+UmEH2Gcy20h8hGIt4lDk 28czFPA2CQiBMJip9jjSpbRbCKXRS4Ti758DteZJQJL6xE82C99mBCd0WWRNcTZb20W5jsn6hgm h5i8SKlgfTziWVfAcH5zI8qaaNQqiYbqeFKgcs2uAgKuIAIhZk3UaK6OYOKEh1N7hLai7LPjtCG HrhYiok7i2wkx5aygoWtOND12Uxk= X-Google-Smtp-Source: AGHT+IGZUiqgRibPAiA5DgB0BOAerZLdpk29rMvBlfQxC3FGQGHcSpvUlZ5Nw+aF8RQ+y3vCwdokTw== X-Received: by 2002:a05:6512:31d6:b0:566:41cb:671d with SMTP id 2adb3069b0e04-57061436fa8mr3784043e87.23.1757943649092; Mon, 15 Sep 2025 06:40:49 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-573c8330e54sm1150719e87.63.2025.09.15.06.40.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 06:40:48 -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 v2 07/10] mm/kasan: Support non-blocking GFP in kasan_populate_vmalloc() Date: Mon, 15 Sep 2025 15:40:37 +0200 Message-ID: <20250915134041.151462-8-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250915134041.151462-1-urezki@gmail.com> References: <20250915134041.151462-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 Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Andrey Ryabinin Reviewed-by: Baoquan He --- 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 11d472a5c4e8..c6643a72d9f6 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 Thu Oct 2 15:19:17 2025 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 167B331D75F for ; Mon, 15 Sep 2025 13:40:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943654; cv=none; b=tcWkfjIqp8TtAy02tbE79sPtxdI+1dhiyDEyuVx/0C1nZxSUxe4jbEtycb1niCsnSPlbE+247Dk3oYYenJBQeA12pobsBnmbyysHwXQAkNattfbhuqGbBo2cMDqiOit3RFRKJwfaI43XRZMU/z28IPcVEFbbR55KNeIjXC2AfVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943654; c=relaxed/simple; bh=R22Tn1GxXynVgGcZZtmj6j+HXED5mHvsvsc3jdyA2XI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kbfufMbO1QSIGKU5qQCLmztwPMRSEPxc2XgOVAK2oD6H3clGCXCmPB5carDd2rE6kGU7N+3BOKvaSab/bi4VHax6s5lyREj89LIzIArxaU29/lGVlm446DlhJFrwKaDJKqSaUOSM3TpVxiFs2GVc5C7P+tYAJ7As0fGlXLJ+/68= 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=RumgNqet; arc=none smtp.client-ip=209.85.167.41 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="RumgNqet" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5608b619cd8so5187127e87.2 for ; Mon, 15 Sep 2025 06:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757943650; x=1758548450; 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=Cxhy1CjTE1SRKEDgpZBn3ZyvPt/a9+eTb0usq/BEmN4=; b=RumgNqetHI7lQll08UXRRRq9ZNz7FeCKHunzN7Z6fBTF3YNAKiPCEfym2hiUWJbYeE cZXhsXqPgJFVPZjs0fg5BFieVgVWl2zpUPPTtdlWZQyQSVJ++jLsEFxzs0wL/5IQdpjR BIZs6q9a311XFTgfIBrZza3p+CDdpf7Ds0jEOVrUOnKlHc72xyMaQXZmC+esGqUzCqjf iF3i1Hc4k01ntRVKhJxvBOmS7agoKRhldWHlbcjWRXqWH88lkN5msQF/cqqM0UX4QBvc Y2aLcjOu/CKPYNZ2A4QdfXl26mnK62W0ihTkyVRkmUuPpCOe2cMHTOhulS6+Ln6AYvCs mL3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757943650; x=1758548450; 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=Cxhy1CjTE1SRKEDgpZBn3ZyvPt/a9+eTb0usq/BEmN4=; b=tpvXMiwY3T54ZRIBA91MXuPDLdHZaKK9bs13kJ7Vbd7nLoG3KqTvrYLcEa2+X69FIf 2pElHix7s4UvydgmEvJME+KZFCucmVOq54yLRHyWumkM6xRJZ6fOFP/gzxY5enUIFqZB Waa/PpFCIstt7u76C9XvmlEnFg53n7QaYNIMkQg3UcrBxCd5HFL673ad/rkCbTxsjpRk 9Lp/CX17x3bQ2GXCXxYzfoAJxoN2R3mnx597/6NJY4AwykblLDg3H3y+BZgdg+gpPd3/ k2Ts3rFrqHu+qJ8N0rG4NxQXXb9UuYgF21EUiJH8V45KXjy2nNDJ6JTOqFEp/M9cwtZx JeaA== X-Forwarded-Encrypted: i=1; AJvYcCUe9UOdS9SZsw1aa4+juEwqUtV9Mf5wzw3Y0tJHceVWC7f8s9r2lTJ89aV1Lw/atm68s1hDrxOIIztyxOE=@vger.kernel.org X-Gm-Message-State: AOJu0YyhmDlEwD2ndcEV2gPTdQl6Sde8eGwEoCpQnHqbQ938qnPbqpRQ 63JI7DVCdC0lsEizps/+qaTAL3GJuPuysbieCfKGPhnausK4xR/HRsmH X-Gm-Gg: ASbGncurppEqcBLOkgVoSxSVE98NiYl8dzjrxUl3UOBVs1TT89O/cN6lL3vx5lv/y6+ zyCGbyEwJo6tdoEU5/TMcEvQwCzAKtGusJl5gGNT4zGyg5pO2kW0/cFGhzSP24NvwL2lCl7yP+P HvqZkNyEMKuqVM4ZbEBHjt6IeZPcll1+vm8ikkTMfnUAIlpGoSHIa9asS4DikcTMjTPWu5SYQu0 2nyaTi4B3qFxkLefcxM0y1lG61QaWde3eDA/jL0FkYMu5JQYt8SFJ/gYv8X+HKaawU+VNkKKuUs V7Ec+vB0pXcOupROHwWt0IYpeKHUPZ8DIFJLPmEQizIe0nitL2UsvMss9b1m6aIm4BJX3ntg1Or WkGTPzLnX1IhvgaHPhLKrxjTL4xQ= X-Google-Smtp-Source: AGHT+IGmRNj1PuGI3ccv6PqCAdUWydP8EuQ817wuW4eDhXwFm+h94+/q66fitzQ60Lp8WCMHShUitw== X-Received: by 2002:ac2:4ca9:0:b0:55f:53fd:e2fe with SMTP id 2adb3069b0e04-5704aa9fff7mr3152235e87.3.1757943649990; Mon, 15 Sep 2025 06:40:49 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-573c8330e54sm1150719e87.63.2025.09.15.06.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 06:40:49 -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 v2 08/10] kmsan: Remove hard-coded GFP_KERNEL flags Date: Mon, 15 Sep 2025 15:40:38 +0200 Message-ID: <20250915134041.151462-9-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250915134041.151462-1-urezki@gmail.com> References: <20250915134041.151462-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 2b1432cc16d5..e4b34e7a3b11 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. @@ -348,7 +350,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 45b725c3dc03..5f3486c1cb83 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1359,7 +1359,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) @@ -1368,7 +1368,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 5e01c6ac4aca..2d4e22dd04f7 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, @@ -3838,8 +3846,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 Thu Oct 2 15:19:17 2025 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 57DDC31AF27 for ; Mon, 15 Sep 2025 13:40:53 +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=1757943655; cv=none; b=KpID3tJXM7kTSU7L9pTHLdgPH5xeWXMJEjjfXLDrg3WrUPkaV34OU8XyjTL638uvmQxcsNdJOHF0qEndS64y8dR1irl2BNSKFg7oqoC0AssklqhFmz8eCMoS730O82ilKC2BWaJAoEq+SJzmfpnNsfCAH7gWBfgt4PrxPW0SULE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943655; c=relaxed/simple; bh=zzmRDyWIbNoIr3Au/5Tj6mx4iv2XRG8hZbeLUABQGtQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WY9n9lIj1s8uQyJ7yZJozFw9SWHAim/OEcVDJ6HP/t1gZNafYFCM9TyMS4zIFoXztyEYZSoEemSybXA1lS5jsG33pKlTnApCsdk2OvKwxSmlDy2Xi461i1TztnDB0fVD0uxAK9DO65GniKWZLY7yjpTavc11V3vSgcspeXPqlVM= 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=UHFxLhMl; 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="UHFxLhMl" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-5720a18b137so1962910e87.2 for ; Mon, 15 Sep 2025 06:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757943651; x=1758548451; 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=oPM/RQw3qfB6SHnbP6cmmYEVv3tF2K8hF5e6CKHShmM=; b=UHFxLhMlvghu94pYV1401VZgySvD87vJydoWoUnSPJLXl/aBPlBAqvw65nJHfmwyv/ Y5vnOj3Ne42+vIVs6Hf04dkmuqVPQmQiS+tCaevAqLF0IxUrr5tqW6N304wg8yGl9pKY pTHny14Uw/Ho9HKfMJ0rR7HN1LqnOzOk8Mce/uosJS2OB7MKhuXM5O9I26tB0dHXzFuL GkUaJdpxkRPy7csRTlKsCbKGoBK7eZHONQkx5oHdl+xAjDuW/BaUoMl8HN5VviIkvYrP RhaJOu87vnk1u3imnrr5BOoH6axuoqjK5LRS3Xjm+oBMiBEyoeAO6EjYzXPtzskO4659 DeVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757943651; x=1758548451; 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=oPM/RQw3qfB6SHnbP6cmmYEVv3tF2K8hF5e6CKHShmM=; b=lL8CpsDdBf3h/bf0WYvBm9OANDrXMReu4kqMgq0eVMI++UQT03kKPHYlNAe4kNjvfs EcVxHuIHQzw2oouqA1rymclNOurNDVVgQnxtzBbtYNNiXBKbB5QK9p6yq7w0pnqjjpvb +tzR64EeeWAQvpD3vXpwD0sD5msVPlaymYkX3LgrFQXBCKuTIbNwEL8JMnzak2CvAhtg +r5DOKSNJ60a7f9o67TusK1wbpZVcmirttSIIaS9iozO2UrFKWTxgkVQ66J1Xt7x0xHd iSQUiQ1DMde1l8kShjWHbdFKdM2VH0N+eJqbaqhwS6NzxgTJib3phr2GJ+6Uh44naawT 6ODg== X-Forwarded-Encrypted: i=1; AJvYcCWZbbOnF6M2v2NhDr4Kf8UEwLYVqDRuhn535TrImCHqOGgHAjqXBu2rFzp2aILUfCcx1cPquR+odo+ybUE=@vger.kernel.org X-Gm-Message-State: AOJu0YwCCeNywlpo7NZCXCZHNpEzCboAGcWd0vf+OQVxXg9W/pM70pxq Sg5VqX2eVFJz3WEpilSForJEvVfHqaeE7aeCxDsGFFT8XWKBQCYDK8Uu X-Gm-Gg: ASbGncscQPKEZly7UvNpZ+0afW56yKcG5wtiTa3DyuHU3ufVAX4gC7rDC0AnZR9ZH10 NCKvI12Jh3MRbeGwaZyiHfgIz/GD23puto5QtBN3JBcWLzhTImyFqcsMsBxWXIhQZ6Pn7hDfj1J YYLkqCPJ/f06vJnkTFiJ4beTR+31L1NXym5anjbPCcXo7v3YteBC4mrAPGCuVu+T0QaS5DA0+2T JhTWbX8WaDyy2YCEsRSBa2vvzGc0HghClcUhJQojctakFrnWS4lcT9EEq+VJqOB5ZpXcpj5TwYq slorQ+PIZzrKWXcOYneKHUMbrMEHi8CAMRb9S+c7J2UODDEZoV34DH86vBxVIi99d1HAnQc33u/ Llk3WQa0fWHF0olFOysBmYuW33gY= X-Google-Smtp-Source: AGHT+IHWeAiSGD+Y8L07HJ5oJgNmCTN7ELdgooFHDZo/26SY4EvrD6cS7mv9RdmLYMUc1s119miMrg== X-Received: by 2002:a05:6512:3c9e:b0:55f:6f1b:24f3 with SMTP id 2adb3069b0e04-57049f1a38bmr3720025e87.15.1757943651044; Mon, 15 Sep 2025 06:40:51 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-573c8330e54sm1150719e87.63.2025.09.15.06.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 06:40:50 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki Subject: [PATCH v2 09/10] mm: Skip might_alloc() warnings when PF_MEMALLOC is set Date: Mon, 15 Sep 2025 15:40:39 +0200 Message-ID: <20250915134041.151462-10-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250915134041.151462-1-urezki@gmail.com> References: <20250915134041.151462-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. Signed-off-by: Uladzislau Rezki (Sony) Acked-by: Michal Hocko --- include/linux/sched/mm.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 2201da0afecc..dc2d3cab32ef 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -318,7 +318,8 @@ static inline void might_alloc(gfp_t gfp_mask) fs_reclaim_acquire(gfp_mask); fs_reclaim_release(gfp_mask); =20 - might_sleep_if(gfpflags_allow_blocking(gfp_mask)); + might_sleep_if(gfpflags_allow_blocking(gfp_mask) && + !(current->flags & PF_MEMALLOC)); } =20 /** --=20 2.47.3 From nobody Thu Oct 2 15:19:17 2025 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 1E387321F4D for ; Mon, 15 Sep 2025 13:40:53 +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=1757943655; cv=none; b=G4gdRuMyJXku9AdyGGb19FFpkMkMLyi09KmxMA6RKncJDM+6qUv6wqYaLkpClqXGfUwpzy8Fwv60VBRoY1fQIeDmEOIWWOngfCEacW9JSzx3hdyhxTYfweJYogaH9LVV3RYBC/1F0cBRAL3acxIVx2DLAOjJAzA28PQA2TEJLec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757943655; c=relaxed/simple; bh=L3ZBiwWYGkSbo6k6JluWr04FWKH+sUKJeig/ryo0U3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZrTV3o7pNC1NP62boQSIWwx4nGxJXSXg+ktXelwoSxtog6MF5IhEEIZl1/zGzNuE0FbkFuwBnQErSHlxkYWcAw6a+NFqe983fuV4444IxASaREzlH4wiPuCLaBg8rISP7jyBn5A4VakNgP6WfAa16MlGUxj1rZKALr+w4Xi5sg8= 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=bIcG8Wf0; 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="bIcG8Wf0" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-5720a18b137so1962929e87.2 for ; Mon, 15 Sep 2025 06:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757943652; x=1758548452; 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=5cGnhxqw7K3FLu3AtNhDK+aUKQwK3uD8HExSuo45tTA=; b=bIcG8Wf0BPBy4+XqF6QmzTrYcz5u/j7J0BSnQgry91juN5sB3unBjhkGSS5T9TWoSR ExRCQAy3k+U7YO7rvP5PumQ0g4doRN4Afok6oN7SacudJFWO7COTRs1jkcR2plmT08py YH2/EjkvvtCyeuteVzxHxeYC+aWsZrX8bK78g0h+2MqxgzSjbo0SXjTEAZxxZGj86sps F0TPY8JSdRSvyRmR958jhhyckPvqMEYwv1eHsUPs/I0AII0pSDo7QUe8Be/DX58vpIX1 2TCPlLvoLmChc9sdF/22jNk8VuSb/tN8Fuq+8bKpnMWbNe4mFueJ4M79w/sn1swBEcZ0 EV1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757943652; x=1758548452; 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=5cGnhxqw7K3FLu3AtNhDK+aUKQwK3uD8HExSuo45tTA=; b=TcAJE/qhO2qpJ49sHi9DDRwxqwR57Iwcf+N32AYLMF8Nk1JRKtsRtQzHWMmopAtVa6 TsWaV7C957ZBEDWRvFkpmzj/9cDaGpK089vaM2JTsJRctNiQ1xA7o9fX0HjcHHvCDZlS jVBQlhfu9QP0qOvfbQQ+MeMUAP+UYTFYEHXebLMUW5G2GM0A6BpVuapg3C7tGOqjDpUv gaoJg15Phas/1P/NyGNw8ShDziQHocAGaXGINCUWXpZJqFStGzvDGDoavCuJqbx9Idfh 5eDYc4Z4/lrdG0R+YYOEaiSQ6PXICoKvGeVD2ZopcCYvaUUAFK5QUqjeo4GK1ZMt4h9j T+Lg== X-Forwarded-Encrypted: i=1; AJvYcCWrvkVI5+0sX4kpirUYOOaUSPfw9uu2BuOv+qW9X57pg1BWGlcvPJcLZnZYoLwJlTlmfCU/gczGIRMKPQg=@vger.kernel.org X-Gm-Message-State: AOJu0YwE5FV4MhQbdwgcS/L9dKtFXjKMj3rDHy8B3L4j+Rrw0LiG3FVs mHNb0TmND/gQJlTZpDJ9+A4zS0TRparA62de5KqsyZ3xBjkxffW0jFpp X-Gm-Gg: ASbGncv/EYEQCpYNpu5kUvy2RwfsvghARaaBouEdufdZ9ObBmA843ekV3pUuS9iMeNF tyFCV0XxCsdhrsJKag1lA7QJN0DGbh/GgWe6MgqNmSPFacqvRpfaHq3FnCUCC6As1B4CeMZ3uPc Xa+2FS2Em2M6sGmuhA5a8wf3YBfz9SDw+6gHcazIZ88Eaokx0xzLpU3r7TujQBsaswNdWyLtnfH XswvcBmFZ2qwneRLyKWe4OtY7/lR87tsIljexcKfCHp4x7SQFj6SGUC1SOhMl4AS0iyFUpsy52U pBrRvHTG1QkAYuSOeNDfvTC5yYY9uXqfUIyPLL2Lgy0yKgsfiOoZ6kxXYQv7K0b1C9hYxWF9MH3 hqj8dEKSQgE8FEU+9XeTmkWRQULk= X-Google-Smtp-Source: AGHT+IHKa7vjk8urMi0MJsQZzlSJv6bCL5W2V3cj7dJf0fQ0uTCa5kr5MJF0Y73xS+PSGi4QMIZRnQ== X-Received: by 2002:a05:6512:661b:b0:55f:4107:ac46 with SMTP id 2adb3069b0e04-5704ad8173cmr2175163e87.25.1757943651896; Mon, 15 Sep 2025 06:40:51 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-573c8330e54sm1150719e87.63.2025.09.15.06.40.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 06:40:51 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: Michal Hocko , Baoquan He , LKML , Uladzislau Rezki Subject: [PATCH v2 10/10] mm/vmalloc: Update __vmalloc_node_range() documentation Date: Mon, 15 Sep 2025 15:40:40 +0200 Message-ID: <20250915134041.151462-11-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250915134041.151462-1-urezki@gmail.com> References: <20250915134041.151462-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. Signed-off-by: Uladzislau Rezki (Sony) Acked-by: Michal Hocko --- mm/vmalloc.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 2d4e22dd04f7..e56d576b46c8 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3880,19 +3880,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