From nobody Wed Apr 22 21:08:21 2026 X-Original-To: dev-commits-src-branches@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 4g1Bdx6cpyz6bKpX for ; Wed, 22 Apr 2026 21:08:21 +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 4g1Bdx2lX9z3kfY for ; Wed, 22 Apr 2026 21:08:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776892101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MYlqN2FRyHiCYQo+KKeLlDHaO6kuwO/3blqeRGPg6AI=; b=EOqvT5bV+DFurO6/e0uJlp+ajyh4tsZFuBMjFfJCuvzEiAH9VwIThF3CzwYJQByS27lQbU 7OaO4L6FigaqudL1Q505Jf5c5niArRrKqnVcP8iAiiz1h+a9yt5WKWTGNttu+UBnghhZ7V pQLX4ELhwcrNfwmJFmlKR9lwRTjl5hAIklD+eJhdL3j4zuMLBinmI4up3zLPtb8O1Z7p8w KHzMTX+eVdGL6kfUK4bH4QDo6sAErlQyg1iRuxzWu4PmU+GHQ4D4h9u/rW9DeaB+Sf+HKj 9mq34gGM8F4mYq1l2vm771QlajgBu5n9MjkG45iM5sExXw3HaQxY8w0Kx/Zp4A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776892101; a=rsa-sha256; cv=none; b=U5Cr0gIkbob/+HhugagdI39bFHILPSXN0Td4//gI6TiI3rGauml0Cf3ui5KicolWQEJxsl AchrJcFzYnWHeRagDs91LamsvzVtFkbmb3WgVl3L91Yy5ejyNAOeQFaR7PWu6EA5VKADoJ Egudno9uXkSODkZPKmGJahvNg5OaHqPR8jimbW63Gil817USkBEoFpOjOFyOd+8qIvQfr/ m9k97sputBK5vHjCu8O2A2LcKQ2O899/gZ0VO3PnL12ZuMleaB7cCI1UKmTqknwTe52vyw kkfiFBgdrltR7Fj/mW2Lw9vdkJO9ZeKxA0h8WaKk9+9cGUR6fwXQAbvRBcMo+Q== 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=1776892101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MYlqN2FRyHiCYQo+KKeLlDHaO6kuwO/3blqeRGPg6AI=; b=pfEZiS0pro7pmfwwxDkM8Cwk/SafMaKSxudtgLWGvuMJSvWyrONXI9W2eoToEjmhq10Giu 25h8r5GGYnuRtve1/IudNQS6OzdlCX9yWeT2IBn6Ma3xeAwPMTDyvHMFAUveMp6ifMGPOp ugQ5C66ULGZ9sbFRT1Jv+ll5MuNNbbHniSKBrzlNYbCycEttJVo6dq0RUp1wHcRPu7fnCZ FOWAf4SFcTrT699us3P60U4K3ZAks2w1liLJ1zBmLgTtMBhXnrBpjSEh0G3GoPR1/tglr1 nL+LiXFurq6HJff0qcxUXQWQu+1fzDYKctGg9SFc3JiQFDsyMyHkdDc/7xAxKg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g1Bdx1httznL6 for ; Wed, 22 Apr 2026 21:08:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 26c54 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 22 Apr 2026 21:08:21 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Jean-=?utf-8?Q?S=C3=A9bast?==?utf-8?Q?ien P=C3=A9?=dron From: Bjoern A. Zeeb Subject: git: b9bfb6ca6892 - stable/15 - linuxkpi: Implement List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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: b9bfb6ca6892b24f60aa1c10f1a99473e25d7401 Auto-Submitted: auto-generated Date: Wed, 22 Apr 2026 21:08:21 +0000 Message-Id: <69e938c5.26c54.120d7ad4@gitrepo.freebsd.org> The branch stable/15 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=b9bfb6ca6892b24f60aa1c10f1a99473e25d7401 commit b9bfb6ca6892b24f60aa1c10f1a99473e25d7401 Author: Jean-Sébastien Pédron AuthorDate: 2025-08-11 17:51:59 +0000 Commit: Bjoern A. Zeeb CommitDate: 2026-04-22 20:56:58 +0000 linuxkpi: Implement It is a wrapper above a `char *` to track the overall available space in the buffer as well as the used space. This wrapper does not manage memory allocation. The DRM generic code started to use this in Linux 6.10. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D54488 (cherry picked from commit 710167623d82664ab4276776aed502ab6f91d8ff) --- sys/compat/linuxkpi/common/include/linux/seq_buf.h | 73 ++++++++++++++++++++++ sys/compat/linuxkpi/common/src/linux_seq_buf.c | 64 +++++++++++++++++++ sys/conf/files | 2 + sys/modules/linuxkpi/Makefile | 1 + 4 files changed, 140 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/seq_buf.h b/sys/compat/linuxkpi/common/include/linux/seq_buf.h new file mode 100644 index 000000000000..d6246a40e6f7 --- /dev/null +++ b/sys/compat/linuxkpi/common/include/linux/seq_buf.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2025-2026 The FreeBSD Foundation + * Copyright (c) 2025-2026 Jean-Sébastien Pédron + * + * This software was developed by Jean-Sébastien Pédron under sponsorship + * from the FreeBSD Foundation. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#ifndef _LINUXKPI_LINUX_SEQ_BUF_H_ +#define _LINUXKPI_LINUX_SEQ_BUF_H_ + +#include +#include +#include +#include + +struct seq_buf { + char *buffer; + size_t size; + size_t len; +}; + +#define DECLARE_SEQ_BUF(NAME, SIZE) \ + struct seq_buf NAME = { \ + .buffer = (char[SIZE]) { 0 }, \ + .size = SIZE, \ + } + +static inline void +seq_buf_clear(struct seq_buf *s) +{ + s->len = 0; + if (s->size > 0) + s->buffer[0] = '\0'; +} + +static inline void +seq_buf_set_overflow(struct seq_buf *s) +{ + s->len = s->size + 1; +} + +static inline bool +seq_buf_has_overflowed(struct seq_buf *s) +{ + return (s->len > s->size); +} + +static inline bool +seq_buf_buffer_left(struct seq_buf *s) +{ + if (seq_buf_has_overflowed(s)) + return (0); + + return (s->size - s->len); +} + +#define seq_buf_init(s, buf, size) linuxkpi_seq_buf_init((s), (buf), (size)) +void linuxkpi_seq_buf_init(struct seq_buf *s, char *buf, unsigned int size); + +#define seq_buf_printf(s, f, ...) linuxkpi_seq_buf_printf((s), (f), __VA_ARGS__) +int linuxkpi_seq_buf_printf(struct seq_buf *s, const char *fmt, ...) \ + __printflike(2, 3); + +#define seq_buf_vprintf(s, f, a) linuxkpi_seq_buf_vprintf((s), (f), (a)) +int linuxkpi_seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args); + +#define seq_buf_str(s) linuxkpi_seq_buf_str((s)) +const char * linuxkpi_seq_buf_str(struct seq_buf *s); + +#endif diff --git a/sys/compat/linuxkpi/common/src/linux_seq_buf.c b/sys/compat/linuxkpi/common/src/linux_seq_buf.c new file mode 100644 index 000000000000..112c53044c22 --- /dev/null +++ b/sys/compat/linuxkpi/common/src/linux_seq_buf.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025-2026 The FreeBSD Foundation + * Copyright (c) 2025-2026 Jean-Sébastien Pédron + * + * This software was developed by Jean-Sébastien Pédron under sponsorship + * from the FreeBSD Foundation. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +void +linuxkpi_seq_buf_init(struct seq_buf *s, char *buf, unsigned int size) +{ + s->buffer = buf; + s->size = size; + + seq_buf_clear(s); +} + +int +linuxkpi_seq_buf_printf(struct seq_buf *s, const char *fmt, ...) +{ + int ret; + va_list args; + + va_start(args, fmt); + ret = seq_buf_vprintf(s, fmt, args); + va_end(args); + + return (ret); +} + +int +linuxkpi_seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args) +{ + int ret; + + if (!seq_buf_has_overflowed(s)) { + ret = vsnprintf(s->buffer + s->len, s->size - s->len, fmt, args); + if (s->len + ret < s->size) { + s->len += ret; + return (0); + } + } + + seq_buf_set_overflow(s); + return (-1); +} + +const char * +linuxkpi_seq_buf_str(struct seq_buf *s) +{ + if (s->size == 0) + return (""); + + if (seq_buf_buffer_left(s)) + s->buffer[s->len] = '\0'; + else + s->buffer[s->size - 1] = '\0'; + + return (s->buffer); +} diff --git a/sys/conf/files b/sys/conf/files index 4378abafecee..ddac2f0cea93 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -4687,6 +4687,8 @@ compat/linuxkpi/common/src/linux_rcu.c optional compat_linuxkpi \ compile-with "${LINUXKPI_C} -I$S/contrib/ck/include" compat/linuxkpi/common/src/linux_schedule.c optional compat_linuxkpi \ compile-with "${LINUXKPI_C}" +compat/linuxkpi/common/src/linux_seq_buf.c optional compat_linuxkpi \ + compile-with "${LINUXKPI_C}" compat/linuxkpi/common/src/linux_shmemfs.c optional compat_linuxkpi \ compile-with "${LINUXKPI_C}" compat/linuxkpi/common/src/linux_shrinker.c optional compat_linuxkpi \ diff --git a/sys/modules/linuxkpi/Makefile b/sys/modules/linuxkpi/Makefile index c465c76a7626..77d73f19075a 100644 --- a/sys/modules/linuxkpi/Makefile +++ b/sys/modules/linuxkpi/Makefile @@ -24,6 +24,7 @@ SRCS= linux_compat.c \ linux_radix.c \ linux_rcu.c \ linux_schedule.c \ + linux_seq_buf.c \ linux_seq_file.c \ linux_shmemfs.c \ linux_shrinker.c \