From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796077792; b=5kjMtdtWa5CGvUDBZ9BaaJ2J7dGDr8fZ43AFM1WAXX5G6NiUzu6omRd7w4uLGVKhUnDw UYV2+uKmc0xCCjOug4a7DzyrBgqeE2/HWJJXcFaLBA600KGekoHQgg7Zlp3vojK+tDiIP 7yugLx55U65Tzde1Zz6ze1DO8A+/inCKI84kgyi/4vceRb1qqjs2C4I76KnvuXtUrdWLt GQyZWJ03YegzrvhQm6MGk2UnsnozwgS0UOxiKNnxl7bZJTAk2+5dhoDY/EsXtbo70igg2 s8l7Xo38iJlLO1ZGuwV8KTtWFKKAYM+2PLIGgY9Ohtxua/elZegTzgIY6gcb7OpfqNQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796077792; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=KiQH7ck1PR0OlOe8W3DId2hza9PP2/T4eVDClZHqTHU=; b=NC0pT41KK7zup/qGcUpt/BicAfIlcEHcDlRWfJeeCUppjymMGLeqR4yx44scwAGwV+2K mWi/I3wgG+JDWgO/qZd+KmegD6Bi3bTjQMvLrnGtjTkh1UKQxtgo5vfJTzLPeU9q1BRSI ALBESZsLN+TnN7goTolSJUGbMROR85QukqlzHuB6LlM+hHUl7w0d/OsKHdG5DKxB/vKgE +JhOnfUltYoa/wsu/PZAc455j9lxDuUNDeZWKU+Mx03+AKY9TSDUSJRG0vKx222BGgHs6 zdAmupNelpNj2K8uP6zKEbGUJI6+dPKqxCt7T4EX+KPwgQ3qDMNP/aqbhA9AoBUwqvg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Lwn088bN; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1DEF606A320; Mon, 30 Nov 2026 22:29:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Lwn088bN Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796077792; b=g7ILmfnlYV/I1HokGGSUegoEzRtNAHdOij7zutz1wIikFnshumRfjZ3dlOsNssX02gWT RwmpHyBcMmxsHvEHNDU+F867v33fzWojF8DilrZBS5+FDQ/PVn5EsitA8H/iI9pmrM1PH ozxi1ScflLTWXwv+RC2ygUaFbexaJduQlyeN5IYJyiw+gXuFef6Suq7Eamo+O9zLDREu/ gulAnDWkJ+UkZWWSBbuRvWmZNnEonlO0QsTbMrLKMRmH1MgAP4L7vYItYhDPVpaMDtbx0 Rr2z/Pd/PZgCGcaPPq3e2ZhxM4QNKMjRXEVmD25ZBxx2lxmNCurHWt86yU8vVH6mkoA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796077792; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=KiQH7ck1PR0OlOe8W3DId2hza9PP2/T4eVDClZHqTHU=; b=lHOgZAo5y8dBRp12wy9Qzlm2T4kef1ElaFHUndp6S/KjFCLj7W7rNgIWxFI45yA8qEir fismGT5AvFxeMQpwTurWp4hkv5qgUYtj8dMxyEEqApVtDgFWJDTpMuJZS/2kLeKm0uFui WcCHrPR/u54L+cqye1FdQXNTFY0setkTa4y50FEtpZH2IpGubzO2k3RRL57ytAtlDqaM5 KdUK703fFK0RHDSAC/K1Nw9qCW65pKCa0+yv+amL2+P2+iA5zuSrJzgJKxxRLmPfEPJpY ditpQrz+2lrTSum8q4uYrbpcRN0TFG/FSbxfKpc+eIKvhKyxvv+c5ZdpUZvI+9F8J8g== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 65EAB1F00919; Mon, 30 Nov 2026 22:29:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796077792; bh=KiQH7ck1PR0OlOe8W3DId2hza9PP2/T4eVDClZHqTHU=; h=From:Date:Subject:To:Cc:Reply-To; b=Lwn088bNjCPKm6BW+xjxV9N1njoC0ITSJLWQYt7/1sYDJOlvHW/HdsxTpGa9w6HES rl/KxWdWdnVYSpCES57LoxKbV+2Rv03NLV8hl6Sgt7JeNPaxiSQqOmOd2oxwkAYhSQ QfANVPawD00IEY1sE4Ul5AFUWRlsRMsHXoa02cdUifjvYwV+pD8HUoe5G17rH10jhg kvMOpPlIuNwz87sxQCwpDpufiYdUNdx6TXoWVemYyKCAQdeLVtVsCiyEC1L6jUUCi5 vvD3JFqD5hnIAnIu6r/T8oi8Dz4FGomkWZa/eQmIwsesT4whE8OrWS96bCx0z7hunW 3MtyJCR9XF2aQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id EDC524EA8A; Mon, 30 Nov 2026 22:29:44 +0000 (UTC) From: Arina Kharlamova via B4 Relay Date: Tue, 01 Dec 2026 02:29:42 +0400 Subject: [PATCH v3] slab: fix the kernel-doc of kmalloc_flex() on counter overflow X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261201-slab-doc-v3-1-e4c8ba976456@mbzuai.ac.ae> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/22NQQ7CIBQFr9KwlgYowdaV9zAu6OdjMdoaaIna9 O5C3TTG5SRv5s0koHcYyKGYicfoghv6BNWuINDp/oLUmcREMKE4F5KGm26pGYDyupGgmTSMKZL mD4/WPdfU6fzlMLVXhDH7edG5MA7+tX5Fnnd/spFTThvLpbGAcg/18d6+J+1KDaVGkstRbN1m4 4rkKqU0ahAWoPpxl2X5AMBUd9nxAAAA X-Change-ID: 20261124-slab-doc-1894ca04d006 To: Jonathan Corbet , Shuah Khan , Randy Dunlap , Kees Cook , "Gustavo A. R. Silva" , Vlastimil Babka , Harry Yoo , Hao Li , Christoph Lameter , David Rientjes , Roman Gushchin Cc: workflows@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, linux-mm@kvack.org, Manuel Ebner , Arina Kharlamova X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796077783; l=5017; i=arina.kharlamova@mbzuai.ac.ae; s=20261123; h=from:subject:message-id; bh=Jrgj+eUt+w0IYW6f5GUHLG6XPaXv9nnJ1P3hHErAsJw=; b=wCDwuxwSAa6xehI69FDM0dBmXxJlphq4A/HKopau3faNvvHDX+GBuWAjMFsabOUpWr9R7s1cr KLRYqyhY8gLDKAs1TIPxIf8AIgisPSpoOlYhFPWuYhAuXyCbAMQbGo/ X-Developer-Key: i=arina.kharlamova@mbzuai.ac.ae; a=ed25519; pk=DzQWwMpUtJvSDuzprqvRdbrC72n4Sq8dW6cq3NRt2Mk= X-Endpoint-Received: by B4 Relay for arina.kharlamova@mbzuai.ac.ae/20261123 with auth_id=1625 X-Original-From: Arina Kharlamova Reply-To: arina.kharlamova@mbzuai.ac.ae Content-Transfer-Encoding: 7bit From: Arina Kharlamova Commit fa5c82f4d2bb ("slab.h: disable completely broken overflow handling in flex allocations") removed the counter overflow check from __alloc_flex(), but the kernel-doc and deprecated.rst still say that the allocation fails if COUNT does not fit in the __counted_by() counter. Update them to match the code. While at it, fix the Returns: line of overflows_flex_counter_type(), where true and false are swapped, and mark gfp and GFP_KERNEL in the same paragraph of deprecated.rst, as Manuel Ebner proposed. Fixes: fa5c82f4d2bb ("slab.h: disable completely broken overflow handling in flex allocations") Link: https://lore.kernel.org/all/20260909141255.1367539-2-manuelebnerli@mailbox.org/ Reviewed-by: Manuel Ebner Signed-off-by: Arina Kharlamova --- Found by checks derived from the spec2patch kernel API specifications, with the help of an AI coding assistant (Claude); I reviewed the analysis and the fix. --- Changes in v3: - Mark gfp and GFP_KERNEL in deprecated.rst (Manuel Ebner) - Add Reviewed-by from Manuel Ebner - Link to v2: https://patch.msgid.link/20261129-slab-doc-v2-1-666aeac2fcc3@mbzuai.ac.ae Changes in v2: - Shorten the changelog and the comments (Harry Yoo) - Rebase on slab/for-next - Link to v1: https://patch.msgid.link/20261124-slab-doc-v1-1-9f14dfce47c8@mbzuai.ac.ae --- Documentation/process/deprecated.rst | 9 ++++----- include/linux/overflow.h | 5 +++-- include/linux/slab.h | 10 ++++------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Documentation/process/deprecated.rst b/Documentation/process/deprecated.rst index 22a5e62c92ea..09c6e45210b8 100644 --- a/Documentation/process/deprecated.rst +++ b/Documentation/process/deprecated.rst @@ -404,8 +404,7 @@ become, respectively:: ptr = kmalloc_flex(*ptr, flex_member, count [, gfp] ); __auto_type ptr = kmalloc_obj(struct foo [, gfp] ); -The argument gfp is optional, the default value is GFP_KERNEL. -If `ptr->flex_member` is annotated with __counted_by(), the allocation -will automatically fail if `count` is larger than the maximum -representable value that can be stored in the counter member associated -with `flex_member`. +The argument `gfp` is optional, the default value is `GFP_KERNEL`. +If `ptr->flex_member` is annotated with __counted_by(), the caller must +make sure that `count` fits in the counter member associated with +`flex_member`. diff --git a/include/linux/overflow.h b/include/linux/overflow.h index d0f04436343e..2eb5490c2f2c 100644 --- a/include/linux/overflow.h +++ b/include/linux/overflow.h @@ -566,8 +566,9 @@ static __always_inline size_t __must_check size_sub(size_t minuend, size_t subtr * @FAM: Member name of the FAM within @TYPE. * @COUNT: Value to check against the __counted_by annotated @FAM's counter. * - * Returns: true if @COUNT can be represented in the @FAM's counter. When - * @FAM is not annotated with __counted_by(), always returns true. + * Returns: true if @COUNT cannot be represented in the @FAM's counter. + * When @FAM is not annotated with __counted_by(), @COUNT is checked + * against size_t. */ #define overflows_flex_counter_type(TYPE, FAM, COUNT) \ (overflows_type(COUNT, typeof_flex_counter(((TYPE *)NULL)->FAM))) diff --git a/include/linux/slab.h b/include/linux/slab.h index ad645967a3ee..5d67144c5a81 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -1092,9 +1092,8 @@ void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node); * @COUNT: how many @FAM elements to allocate space for. * * Returns: Newly allocated pointer to @TYPE with @COUNT-many trailing - * @FAM elements, or NULL on failure or if @COUNT cannot be represented - * by the member of @TYPE that counts the @FAM elements (annotated via - * __counted_by()). + * @FAM elements, or NULL on failure. @COUNT is not checked against the + * type of the __counted_by() counter of @FAM. */ #define __alloc_flex(KMALLOC, GFP, TYPE, FAM, COUNT) \ ({ \ @@ -1137,9 +1136,8 @@ void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node); * @...: optional GFP flags for the allocation (GFP_KERNEL when not specified). * * Returns: newly allocated pointer to @VAR_OR_TYPE on success, NULL on - * failure. If @FAM has been annotated with __counted_by(), the allocation - * will immediately fail if @COUNT is larger than what the type of the - * struct's counter variable can represent. + * failure. If @FAM has been annotated with __counted_by(), the caller + * must make sure that @COUNT fits in the struct's counter variable. */ #define kmalloc_flex(VAR_OR_TYPE, FAM, COUNT, ...) \ __alloc_flex(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), FAM, COUNT) --- base-commit: 0b0985aeb9979c5fa5c3b872cecdf97ed4ed2b3e change-id: 20261124-slab-doc-1894ca04d006 Best regards, -- Arina Kharlamova