From nobody Wed Apr 22 21:08:58 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4g1Bff72mPz6bL6Z for ; Wed, 22 Apr 2026 21:08:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g1Bff5PXjz3ldZ for ; Wed, 22 Apr 2026 21:08:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776892138; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FQHWVJLIESEqIf/FZjEJrfNblHSOmOb5Cki3JgwyrcI=; b=bXsoPGWMGIvxYz+vfaOBxj7o3lll9+BtrCbpg49msBj9pvX1fWAIy0J5EGRd8XgyKwGc6c d361l46ViYMGqWGbSWoAgIRvM2oKi/t3n1CnowIB5kjntpVYyO0Akowjs61pKDVPqZ3FwT zN94jnncXHKhGWYLzkx/upoWP5dhoQJpN3a4DjF5xbHfHhUGzmVcy5kq6uVbwmqUjdF527 1uzm9kBOZ5a1hCD8KfcFDnB3LOyUGHxFd7jewMdYdESrzC+CBqIP9pH1xVcxTNHPS4NvHu EWVr2EaTyZFi50az/YShbvLzBpRi2zCqNRoA2yFDmT1nvfAcV2wyjTTJT/NpCQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776892138; a=rsa-sha256; cv=none; b=dM7E+NAI3z8Bxc1I53MYSk9HppG9w1m2clktQxINJ7PYp5RIsNModuP4h2+XYUFkyfo0Gj ijhkzoJqTYYee1Wr2Px3cAbUD2gw6C1DeJfHgcruCQg/LXYO0cWXelwpun2bijkcOOqFGm /36OTa2lTrxn++w11inuzPXualnLwKXBQ87KCUhgqGO+O6DxkqNWgP9LlKPCrkrymeROoy xJJcXSnZ+MDXqOmnnB7ZV+IVU5LbnZsnHDFIyIJsRMfqkODGSygmHNgNt6M6mO2/a1K1Fq Xvo6H4FE3u30scTqtftrO3TuhtDrwnxRAXjQKjUK7MoJuyrZFzfzONbztCJ4oQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776892138; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FQHWVJLIESEqIf/FZjEJrfNblHSOmOb5Cki3JgwyrcI=; b=cpVpgG+FlAh2zi73c2fZEy1Uhxe46G6ceHNz3geu2PkAZU2jAxVl5t4sILvFLjN4L4YAQl i195+s0liyZGWO3Dmmy1BMn6BVcJ0y12rLcmH7RNTxEjk9wpnY3oMfVoIgmrIL146etN1Z IC6icakopDiEKyXS7CIhkEX/ZZtehnWFphGBoXmn1+0gY9v5/F6XYodtnbB+fUvr+ZoLhw awZgIJ/O+zvaY/aZOpKCrf/y+QybY4Xt4RtD3oPbRE2uNS6UFUFQsm3/amMceK8dLS+OpH 1XxijuO8ruHxYs4+dQsTo7ikwn9rZKFwqDB+bSaXCBOxaWCEjrWlflgydd4wmw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g1Bff4qLNznpQ for ; Wed, 22 Apr 2026 21:08:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2767d by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 22 Apr 2026 21:08:58 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Bjoern A. Zeeb Subject: git: e6f14601d39c - stable/15 - LinuxKPI: add kmalloc_obj[s], kzalloc_obj[s], and kzalloc_flex List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: e6f14601d39c6a6fb41ad725dd4ae2488e4707ce Auto-Submitted: auto-generated Date: Wed, 22 Apr 2026 21:08:58 +0000 Message-Id: <69e938ea.2767d.68d5e87c@gitrepo.freebsd.org> The branch stable/15 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=e6f14601d39c6a6fb41ad725dd4ae2488e4707ce commit e6f14601d39c6a6fb41ad725dd4ae2488e4707ce Author: Bjoern A. Zeeb AuthorDate: 2026-04-14 15:13:18 +0000 Commit: Bjoern A. Zeeb CommitDate: 2026-04-22 20:57:09 +0000 LinuxKPI: add kmalloc_obj[s], kzalloc_obj[s], and kzalloc_flex Drivers in Linux v7.0 seem to have changed to the new allocation macros using a sweep. Add the ones I encountered with wireless drivers so far. They all take an optional argument for a gfp_t, which default_gfp() deals with. The plural version "objs" takes an extra nitems argument in addition to the size. We use size_mul() to possibly detect overflows. The "flex" version uses an extra variable to track the variable sized array allocations and if supported by the compiler will use __builtin_counted_by_ref() to properly track bounds. Sponsored by: The FreeBSD Foundation Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D56395 (cherry picked from commit c72ac6af086962d236f4712761abacac0c62b48e) --- sys/compat/linuxkpi/common/include/linux/slab.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/sys/compat/linuxkpi/common/include/linux/slab.h b/sys/compat/linuxkpi/common/include/linux/slab.h index 0e649e1e3c4a..6c05c77819a5 100644 --- a/sys/compat/linuxkpi/common/include/linux/slab.h +++ b/sys/compat/linuxkpi/common/include/linux/slab.h @@ -4,7 +4,7 @@ * Copyright (c) 2010 Panasas, Inc. * Copyright (c) 2013-2021 Mellanox Technologies, Ltd. * All rights reserved. - * Copyright (c) 2024-2025 The FreeBSD Foundation + * Copyright (c) 2024-2026 The FreeBSD Foundation * * Portions of this software were developed by Björn Zeeb * under sponsorship from the FreeBSD Foundation. @@ -51,6 +51,22 @@ MALLOC_DECLARE(M_KMALLOC); #define kvcalloc(n, size, flags) kvmalloc_array(n, size, (flags) | __GFP_ZERO) #define kzalloc(size, flags) kmalloc(size, (flags) | __GFP_ZERO) #define kzalloc_node(size, flags, node) kmalloc_node(size, (flags) | __GFP_ZERO, node) +#define kzalloc_obj(_p, ...) \ + kzalloc(sizeof(typeof(_p)), default_gfp(__VA_ARGS__)) +#define kzalloc_objs(_p, _n, ...) \ + kzalloc(size_mul((_n), sizeof(typeof(_p))), default_gfp(__VA_ARGS__)) +#define kzalloc_flex(_p, _field, _n, ...) \ +({ \ + const size_t __n = (_n); \ + const size_t __psize = struct_size_t(typeof(_p), _field, __n); \ + typeof(_p) *__p_obj; \ + \ + __p_obj = kzalloc(__psize, default_gfp(__VA_ARGS__)); \ + if (__p_obj != NULL) \ + __set_flex_counter(__p_obj->_field, __n); \ + \ + __p_obj; \ +}) #define kfree_const(ptr) kfree(ptr) #define kfree_async(ptr) kfree(ptr) /* drm-kmod 5.4 compat */ #define vzalloc(size) __vmalloc(size, GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, 0) @@ -143,6 +159,12 @@ kmalloc_node(size_t size, gfp_t flags, int node) return (lkpi___kmalloc_node(size, flags, node)); } +#define kmalloc_obj(_p, ...) \ + kmalloc(sizeof(typeof(_p)), default_gfp(__VA_ARGS__)) + +#define kmalloc_objs(_p, _n, ...) \ + kmalloc(size_mul((_n) * sizeof(typeof(_p))), default_gfp(__VA_ARGS__)) + static inline void * krealloc(void *ptr, size_t size, gfp_t flags) {