From nobody Sat Apr 18 01:12: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 4fyDJW3hKgz6ZTfC for ; Sat, 18 Apr 2026 01:12:59 +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 4fyDJV720hz3nhQ for ; Sat, 18 Apr 2026 01:12:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776474779; 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=5vGJP/qt6HDF0hmSpkkKjZjj2YHhT2IBX3/QGeGjggE=; b=kX2BIR67Bho2bBUt12YN0gQ1mhCY6vSlZBImlLPXxBxi01bxEDUJr8ClRSNNBYZb9uCXz9 IO0E8QfWd2+nLYZwJsQP8+Zc5UZL20xa8hqD7ritQd3KSMHY0pyUcAkQN1U7HBT/k/dZba 6Y1wVwh+qvTF9gTCUilfk+l0lZhXW37rt3GMwbgZ6kIvquSeYvWHLehY94W6OTMh+x16wM IXuaLL0s/L/40TdFBW9X77xGjttmYtIxMXM/N/gL8JchqBuZFCVuityGGkuM8rNfqbQ8fB VPjdncA3ojZeIormBdaAzyHyDHrp4R7aegABYY3mL0fHT6PA6y28NSDokcJiKg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776474779; a=rsa-sha256; cv=none; b=LnIK5+7uG7AjnuqIUD+7dvaRcJy388HJ0GT7F0QSyqlO57HFT8nifm8ayyYZN7/uPRn6I7 lFqxel/57Y1XI6z0chMTGmJ3SkxFjGSl7fXZ3vqfvIWw4uLDE1T0awS6zKhWvj+5LUL60I 2n9JrDE9+5vmtJIV0EXGLTHfmfI2E0BWxd0hlg0MCDZoJ1ccqoATRdluc5U8PVHTBySJMZ i5pq20qogo7p8c1va2D06P831GO4axsrH7qX97z7tM2ZEukTgTTjNzl+pFPVjSQMe7SLER D6KZi/QqphYHZcnw9MLSo9EZdh8tsx3Z86WW161s3NHBQ4Psp/27TAY8dQvScA== 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=1776474779; 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=5vGJP/qt6HDF0hmSpkkKjZjj2YHhT2IBX3/QGeGjggE=; b=a37rMM1C/+Bd75v/ONcjaS+LG+MUtzieyqGw/rSFt6XaPy49sE2BJzqfcaMbWhf9UY7gtv MbMyv3wGQvmBbjyAUod2U5DvF00UExkvarsTPPuE3uPyvaFK4nJLyEaF8WiBncRZ5YCZAq YOjjPxwcx+TLZn7gaI61kd9pw+R8On//3Dh0eg20qpNgHoh3UN8our0EqeUk14yUrX9vdx urregm7voxJoa+SokWY8bIkKASBz2/D+7Ypx1cN3V692NPCVnWXpRbOd3EXK/k5eXnLP+/ 5GqMKbb1DRph1MqlRcvsdKyaWQC2MnpKwsEs2GwuieCsugdgggUEyI/h8aH01w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fyDJV6Zclz3Kp for ; Sat, 18 Apr 2026 01:12:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 466ca by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 18 Apr 2026 01:12:58 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Bjoern A. Zeeb Subject: git: c72ac6af0869 - main - 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/main X-Git-Reftype: branch X-Git-Commit: c72ac6af086962d236f4712761abacac0c62b48e Auto-Submitted: auto-generated Date: Sat, 18 Apr 2026 01:12:58 +0000 Message-Id: <69e2da9a.466ca.10abc584@gitrepo.freebsd.org> The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=c72ac6af086962d236f4712761abacac0c62b48e commit c72ac6af086962d236f4712761abacac0c62b48e Author: Bjoern A. Zeeb AuthorDate: 2026-04-14 15:13:18 +0000 Commit: Bjoern A. Zeeb CommitDate: 2026-04-18 01:12:13 +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 MFC after: 3 days Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D56395 --- 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) {