From nobody Mon Mar 20 20:47:51 2023 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 4PgRdN2mHlz40Drn; Mon, 20 Mar 2023 20:47:52 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PgRdN1cyRz3kK4; Mon, 20 Mar 2023 20:47:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679345272; 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=tXFo9jUWEycwrGy1dB8wvguhyg6Dcrvfmo9kuJFLbcM=; b=sSiQtfpunokX+WJDhyzu5fdNpioxWHLzIMKntxwalRnnEgoPgtSAprDj+AjLG7wjtAaMAv Vv9gYkBa64cr5Bt6dQ39AX5NpeYO7NaJ53ifyAWrAFP+8bbiJEpQ163vaPrPILurXrx/jt O5hZr5CiZgMZN2O5DDiy3bRs+CxTs4vqNZ4Vzu9uCU/SS7FF+0/ceYmULwaj29b116oXF8 YuONnRrc8a3dn1SPD5iQEKFedM3mW5hMjUZoZMNc/FzmpsmXBRbdVvEvRu/eG6BzYdkGDD 0XNp1ybwm14qstH15hH/ASrorzhByFkB6OX9dOFA2QfPgwL0CcFMm8JkfPZj1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679345272; 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=tXFo9jUWEycwrGy1dB8wvguhyg6Dcrvfmo9kuJFLbcM=; b=agDDrqOxYJUIMWsherLj/bSv1ru5WF9zrj8idiRDSX9QCOSrTjv6YfD5JAbtdM9oEAuNtf W8EkD93pk/5seCrYOqpDeHj8f6aMxAmJpDalhHZHyxy/gzXyH6SPSZwM5bcf1UGhYCcVLH tbasVjHdpqTbfQPfBYtQqi8hpW+biZLwGS76jVqjNqnUHQN8gy026eo3XspUdVbw6aovHO k6sToritvOjBUYpCY0pkqUwF/qXLHAGLLOQVB81ecjzduUZ9TKtxSIN/nnXVI2Xq0k6YaT K11lS41ZKGEnRuofUmbv8T2baP5/Y8S0X6IUWD9jM6Kk3QL/ZFmWhV5RDneTeg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679345272; a=rsa-sha256; cv=none; b=lKRyEEdtob2F2Kxrc7lrcgLRvLx9wewpO7j5cLrl6byMVQZa2iVAW25lDi9la+2+nSueN/ PUOD3BUGOyBhazz3DXd22QYZ3ShbxJbHfGnEZOE2qZ25E0PbXpOKmsirkjNnFn80jcIQj+ IVhEsVgFPn7jL2RdGj20HJSRI599L2quxk6J3u5ZBP+b0I+INbXw0jDQA8oGzjeO5U8Tgy GO/4VKngQ6RprSokqnUYNLdBNGUTrr8eAhPDexkFFtIV9YocwyvS1TGd5uXa7b4NIFxCOY RghCzWcQ8TvHS8Kpgg2v4O/6vhViztbsWL639mod50/VcQi0ZTGy3Eo/yzjo/g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PgRdN0D60zlJT; Mon, 20 Mar 2023 20:47:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32KKlp3o083343; Mon, 20 Mar 2023 20:47:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32KKlpOO083342; Mon, 20 Mar 2023 20:47:51 GMT (envelope-from git) Date: Mon, 20 Mar 2023 20:47:51 GMT Message-Id: <202303202047.32KKlpOO083342@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Subject: git: 5fbfe9517b4d - main - linuxkpi: Define `seq_has_overflowed()` and `single_open_size()` 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dumbbell X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5fbfe9517b4dab41a95e91b3fd8e73310c9eaa8b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=5fbfe9517b4dab41a95e91b3fd8e73310c9eaa8b commit 5fbfe9517b4dab41a95e91b3fd8e73310c9eaa8b Author: Jean-Sébastien Pédron AuthorDate: 2023-02-20 20:53:36 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2023-03-20 20:47:36 +0000 linuxkpi: Define `seq_has_overflowed()` and `single_open_size()` This required non-trivial changes to `linux_seq_file.c` to manage a new `(struct seq_file)->size` field. This field is read directly by DRM drivers, so we can't alias it to a call to sbuf_len(9). `single_open_size()` also depended on the ability to allocate the sbuf with a specified size instead of relying on `sbuf_new_auto()`. Reviewed by: manu Approved by: manu Differential Revision: https://reviews.freebsd.org/D39056 --- .../linuxkpi/common/include/linux/seq_file.h | 8 +- sys/compat/linuxkpi/common/src/linux_seq_file.c | 89 +++++++++++++++++++--- 2 files changed, 85 insertions(+), 12 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/seq_file.h b/sys/compat/linuxkpi/common/include/linux/seq_file.h index 8fb93646f9a5..d18d3cd906ab 100644 --- a/sys/compat/linuxkpi/common/include/linux/seq_file.h +++ b/sys/compat/linuxkpi/common/include/linux/seq_file.h @@ -54,6 +54,7 @@ static const struct file_operations __name ## _fops = { \ struct seq_file { struct sbuf *buf; + size_t size; const struct seq_operations *op; const struct linux_file *file; void *private; @@ -68,6 +69,9 @@ struct seq_operations { ssize_t seq_read(struct linux_file *, char *, size_t, off_t *); int seq_write(struct seq_file *seq, const void *data, size_t len); +void seq_putc(struct seq_file *m, char c); +void seq_puts(struct seq_file *m, const char *str); +bool seq_has_overflowed(struct seq_file *m); void *__seq_open_private(struct linux_file *, const struct seq_operations *, int); int seq_release_private(struct inode *, struct linux_file *); @@ -77,6 +81,7 @@ int seq_release(struct inode *inode, struct linux_file *file); off_t seq_lseek(struct linux_file *file, off_t offset, int whence); int single_open(struct linux_file *, int (*)(struct seq_file *, void *), void *); +int single_open_size(struct linux_file *, int (*)(struct seq_file *, void *), void *, size_t); int single_release(struct inode *, struct linux_file *); void lkpi_seq_vprintf(struct seq_file *m, const char *fmt, va_list args); @@ -85,9 +90,6 @@ void lkpi_seq_printf(struct seq_file *m, const char *fmt, ...); #define seq_vprintf(...) lkpi_seq_vprintf(__VA_ARGS__) #define seq_printf(...) lkpi_seq_printf(__VA_ARGS__) -#define seq_puts(m, str) sbuf_printf((m)->buf, str) -#define seq_putc(m, str) sbuf_putc((m)->buf, str) - #define file linux_file #endif /* _LINUXKPI_LINUX_SEQ_FILE_H_ */ diff --git a/sys/compat/linuxkpi/common/src/linux_seq_file.c b/sys/compat/linuxkpi/common/src/linux_seq_file.c index d4d8ef059ac4..80b13a3ac28f 100644 --- a/sys/compat/linuxkpi/common/src/linux_seq_file.c +++ b/sys/compat/linuxkpi/common/src/linux_seq_file.c @@ -79,8 +79,33 @@ seq_read(struct linux_file *f, char *ubuf, size_t size, off_t *ppos) int seq_write(struct seq_file *seq, const void *data, size_t len) { + int ret; - return (sbuf_bcpy(seq->buf, data, len)); + ret = sbuf_bcpy(seq->buf, data, len); + if (ret == 0) + seq->size = sbuf_len(seq->buf); + + return (ret); +} + +void +seq_putc(struct seq_file *seq, char c) +{ + int ret; + + ret = sbuf_putc(seq->buf, c); + if (ret == 0) + seq->size = sbuf_len(seq->buf); +} + +void +seq_puts(struct seq_file *seq, const char *str) +{ + int ret; + + ret = sbuf_printf(seq->buf, "%s", str); + if (ret == 0) + seq->size = sbuf_len(seq->buf); } /* @@ -115,21 +140,32 @@ single_stop(struct seq_file *p, void *v) { } -int -seq_open(struct linux_file *f, const struct seq_operations *op) +static int +_seq_open_without_sbuf(struct linux_file *f, const struct seq_operations *op) { struct seq_file *p; if ((p = malloc(sizeof(*p), M_LSEQ, M_NOWAIT|M_ZERO)) == NULL) return (-ENOMEM); - p->buf = sbuf_new_auto(); p->file = f; p->op = op; f->private_data = (void *) p; return (0); } +int +seq_open(struct linux_file *f, const struct seq_operations *op) +{ + int ret; + + ret = _seq_open_without_sbuf(f, op); + if (ret == 0) + ((struct seq_file *)f->private_data)->buf = sbuf_new_auto(); + + return (ret); +} + void * __seq_open_private(struct linux_file *f, const struct seq_operations *op, int size) { @@ -153,8 +189,8 @@ __seq_open_private(struct linux_file *f, const struct seq_operations *op, int si return (private); } -int -single_open(struct linux_file *f, int (*show)(struct seq_file *, void *), void *d) +static int +_single_open_without_sbuf(struct linux_file *f, int (*show)(struct seq_file *, void *), void *d) { struct seq_operations *op; int rc = -ENOMEM; @@ -165,7 +201,7 @@ single_open(struct linux_file *f, int (*show)(struct seq_file *, void *), void * op->next = single_next; op->stop = single_stop; op->show = show; - rc = seq_open(f, op); + rc = _seq_open_without_sbuf(f, op); if (rc) free(op, M_LSEQ); else @@ -174,6 +210,31 @@ single_open(struct linux_file *f, int (*show)(struct seq_file *, void *), void * return (rc); } +int +single_open(struct linux_file *f, int (*show)(struct seq_file *, void *), void *d) +{ + int ret; + + ret = _single_open_without_sbuf(f, show, d); + if (ret == 0) + ((struct seq_file *)f->private_data)->buf = sbuf_new_auto(); + + return (ret); +} + +int +single_open_size(struct linux_file *f, int (*show)(struct seq_file *, void *), void *d, size_t size) +{ + int ret; + + ret = _single_open_without_sbuf(f, show, d); + if (ret == 0) + ((struct seq_file *)f->private_data)->buf = sbuf_new( + NULL, NULL, size, SBUF_AUTOEXTEND); + + return (ret); +} + int seq_release(struct inode *inode __unused, struct linux_file *file) { @@ -219,7 +280,11 @@ single_release(struct vnode *v, struct linux_file *f) void lkpi_seq_vprintf(struct seq_file *m, const char *fmt, va_list args) { - sbuf_vprintf(m->buf, fmt, args); + int ret; + + ret = sbuf_vprintf(m->buf, fmt, args); + if (ret == 0) + m->size = sbuf_len(m->buf); } void @@ -228,6 +293,12 @@ lkpi_seq_printf(struct seq_file *m, const char *fmt, ...) va_list args; va_start(args, fmt); - seq_vprintf(m, fmt, args); + lkpi_seq_vprintf(m, fmt, args); va_end(args); } + +bool +seq_has_overflowed(struct seq_file *m) +{ + return (sbuf_len(m->buf) == -1); +}