From owner-dev-commits-src-branches@freebsd.org Mon Aug 9 08:23:24 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 089BF65096D; Mon, 9 Aug 2021 08:23:24 +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 4Gjpxl6hRCz3j0R; Mon, 9 Aug 2021 08:23:23 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 CE36A24DA9; Mon, 9 Aug 2021 08:23:23 +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 1798NNm7048452; Mon, 9 Aug 2021 08:23:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1798NNf2048451; Mon, 9 Aug 2021 08:23:23 GMT (envelope-from git) Date: Mon, 9 Aug 2021 08:23:23 GMT Message-Id: <202108090823.1798NNf2048451@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Toomas Soome Subject: git: e6847536a89a - stable/13 - loader: cstyle cleanup of libsa/lseek.c MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tsoome X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e6847536a89a7f35a0372bb46cee6f939ed78919 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Aug 2021 08:23:24 -0000 The branch stable/13 has been updated by tsoome: URL: https://cgit.FreeBSD.org/src/commit/?id=e6847536a89a7f35a0372bb46cee6f939ed78919 commit e6847536a89a7f35a0372bb46cee6f939ed78919 Author: Toomas Soome AuthorDate: 2021-08-01 07:07:32 +0000 Commit: Toomas Soome CommitDate: 2021-08-08 13:17:13 +0000 loader: cstyle cleanup of libsa/lseek.c Clean up lseek.c, no functional changes intended. This is pre-patch for open file list rewrite. MFC after: 1 week (cherry-picked from commit bbb539b83ceced2d355893ead5987193737833fd) --- stand/libsa/lseek.c | 137 ++++++++++++++++++++++++++-------------------------- 1 file changed, 69 insertions(+), 68 deletions(-) diff --git a/stand/libsa/lseek.c b/stand/libsa/lseek.c index df2591acd76d..1a39eb31421b 100644 --- a/stand/libsa/lseek.c +++ b/stand/libsa/lseek.c @@ -32,30 +32,30 @@ * SUCH DAMAGE. * * @(#)lseek.c 8.1 (Berkeley) 6/11/93 - * + * * * Copyright (c) 1989, 1990, 1991 Carnegie Mellon University * All Rights Reserved. * * Author: Alessandro Forin - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. */ @@ -68,74 +68,75 @@ __FBSDID("$FreeBSD$"); off_t lseek(int fd, off_t offset, int where) { - off_t bufpos, filepos, target; - struct open_file *f = &files[fd]; + off_t bufpos, filepos, target; + struct open_file *f = &files[fd]; - if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) { - errno = EBADF; - return (-1); - } - - if (f->f_flags & F_RAW) { - /* - * On RAW devices, update internal offset. - */ - switch (where) { - case SEEK_SET: - f->f_offset = offset; - break; - case SEEK_CUR: - f->f_offset += offset; - break; - default: - errno = EOFFSET; - return (-1); + if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) { + errno = EBADF; + return (-1); } - return (f->f_offset); - } - /* - * If there is some unconsumed data in the readahead buffer and it - * contains the desired offset, simply adjust the buffer offset and - * length. We don't bother with SEEK_END here, since the code to - * handle it would fail in the same cases where the non-readahead - * code fails (namely, for streams which cannot seek backward and whose - * size isn't known in advance). - */ - if (f->f_ralen != 0 && where != SEEK_END) { - if ((filepos = (f->f_ops->fo_seek)(f, (off_t)0, SEEK_CUR)) == -1) - return (-1); - bufpos = filepos - f->f_ralen; - switch (where) { - case SEEK_SET: - target = offset; - break; - case SEEK_CUR: - target = bufpos + offset; - break; - default: - errno = EINVAL; - return (-1); + if (f->f_flags & F_RAW) { + /* + * On RAW devices, update internal offset. + */ + switch (where) { + case SEEK_SET: + f->f_offset = offset; + break; + case SEEK_CUR: + f->f_offset += offset; + break; + default: + errno = EOFFSET; + return (-1); + } + return (f->f_offset); } - if (bufpos <= target && target < filepos) { - f->f_raoffset += target - bufpos; - f->f_ralen -= target - bufpos; - return (target); + + /* + * If there is some unconsumed data in the readahead buffer and it + * contains the desired offset, simply adjust the buffer offset and + * length. We don't bother with SEEK_END here, since the code to + * handle it would fail in the same cases where the non-readahead + * code fails (namely, for streams which cannot seek backward and whose + * size isn't known in advance). + */ + if (f->f_ralen != 0 && where != SEEK_END) { + filepos = (f->f_ops->fo_seek)(f, 0, SEEK_CUR); + if (filepos == -1) + return (-1); + bufpos = filepos - f->f_ralen; + switch (where) { + case SEEK_SET: + target = offset; + break; + case SEEK_CUR: + target = bufpos + offset; + break; + default: + errno = EINVAL; + return (-1); + } + if (bufpos <= target && target < filepos) { + f->f_raoffset += target - bufpos; + f->f_ralen -= target - bufpos; + return (target); + } } - } - /* - * If this is a relative seek, we need to correct the offset for - * bytes that we have already read but the caller doesn't know - * about. - */ - if (where == SEEK_CUR) - offset -= f->f_ralen; + /* + * If this is a relative seek, we need to correct the offset for + * bytes that we have already read but the caller doesn't know + * about. + */ + if (where == SEEK_CUR) + offset -= f->f_ralen; - /* - * Invalidate the readahead buffer. - */ - f->f_ralen = 0; + /* + * Invalidate the readahead buffer. + */ + f->f_ralen = 0; - return (f->f_ops->fo_seek)(f, offset, where); + return (f->f_ops->fo_seek)(f, offset, where); } From owner-dev-commits-src-branches@freebsd.org Mon Aug 9 08:25:56 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 07A0F650E0B; Mon, 9 Aug 2021 08:25:56 +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 4Gjq0g6n95z3hxw; Mon, 9 Aug 2021 08:25:55 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 CCE0A24DAA; Mon, 9 Aug 2021 08:25:55 +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 1798PtZD048737; Mon, 9 Aug 2021 08:25:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1798PtEC048736; Mon, 9 Aug 2021 08:25:55 GMT (envelope-from git) Date: Mon, 9 Aug 2021 08:25:55 GMT Message-Id: <202108090825.1798PtEC048736@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Toomas Soome Subject: git: e6639057146d - stable/13 - loader: tftp client should use server address from rootip MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tsoome X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e6639057146de16e4883512a900dd9a53705f477 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Aug 2021 08:25:56 -0000 The branch stable/13 has been updated by tsoome: URL: https://cgit.FreeBSD.org/src/commit/?id=e6639057146de16e4883512a900dd9a53705f477 commit e6639057146de16e4883512a900dd9a53705f477 Author: Toomas Soome AuthorDate: 2021-08-02 12:27:38 +0000 Commit: Toomas Soome CommitDate: 2021-08-08 13:21:07 +0000 loader: tftp client should use server address from rootip servip is set from bootp bp_siaddr (if present) and rootip is set immediately from servip in tha sane bootp code. However, the common/dev_net.c does only set rootip (based on url processing etc). Therefore, we should also use rootip in tftp reader. Fixes hung tftp based boot when bp_siaddr is not provided. MFC after: 1 week (cherry-picked from commit 1b1bb6f178802a4522824e0268634a99cdbda098) --- stand/libsa/tftp.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/stand/libsa/tftp.c b/stand/libsa/tftp.c index 3892f2aad86a..22e03ab58da1 100644 --- a/stand/libsa/tftp.c +++ b/stand/libsa/tftp.c @@ -38,7 +38,7 @@ __FBSDID("$FreeBSD$"); * Simple TFTP implementation for libsa. * Assumes: * - socket descriptor (int) at open_file->f_devdata - * - server host IP in global servip + * - server host IP in global rootip * Restrictions: * - read only * - lseek only with SEEK_SET or SEEK_CUR @@ -83,8 +83,6 @@ struct fs_ops tftp_fsops = { .fo_readdir = null_readdir }; -extern struct in_addr servip; - static int tftpport = 2000; static int is_open = 0; @@ -460,7 +458,7 @@ tftp_open(const char *path, struct open_file *f) return (EINVAL); } - io->destip = servip; + io->destip = rootip; tftpfile->off = 0; pathsize = (strlen(rootpath) + 1 + strlen(path) + 1) * sizeof(char); tftpfile->path = malloc(pathsize); From owner-dev-commits-src-branches@freebsd.org Mon Aug 9 18:39:47 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 036FF659617; Mon, 9 Aug 2021 18:39:47 +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 4Gk4cy6MsJz3H41; Mon, 9 Aug 2021 18:39:46 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B583F51D1; Mon, 9 Aug 2021 18:39:46 +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 179Idkxl069145; Mon, 9 Aug 2021 18:39:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 179IdkJB069144; Mon, 9 Aug 2021 18:39:46 GMT (envelope-from git) Date: Mon, 9 Aug 2021 18:39:46 GMT Message-Id: <202108091839.179IdkJB069144@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 6f2898503a92 - stable/13 - pf: bound DIOCGETSTATES memory use MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 6f2898503a927a44104e4ceae8ff9c765abf7ece Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Aug 2021 18:39:47 -0000 The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=6f2898503a927a44104e4ceae8ff9c765abf7ece commit 6f2898503a927a44104e4ceae8ff9c765abf7ece Author: Kristof Provost AuthorDate: 2021-08-02 07:46:33 +0000 Commit: Kristof Provost CommitDate: 2021-08-09 15:56:26 +0000 pf: bound DIOCGETSTATES memory use Similar to what we did earlier for DIOCGETSTATESV2 we only allocate enough memory for a handful of states and copy those out, bit by bit, rather than allocating memory for all states in one go. MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 600745f1e2260e7ed3c2e6183b24388ff38c916c) --- sys/netpfil/pf/pf_ioctl.c | 51 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 5fd711d1c574..39931540d03d 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -2840,7 +2840,9 @@ DIOCCHANGERULE_error: struct pfioc_states *ps = (struct pfioc_states *)addr; struct pf_kstate *s; struct pfsync_state *pstore, *p; - int i, nr; + int i, nr; + size_t slice_count = 16, count; + void *out; if (ps->ps_len <= 0) { nr = uma_zone_get_cur(V_pf_state_z); @@ -2848,34 +2850,59 @@ DIOCCHANGERULE_error: break; } - p = pstore = malloc(ps->ps_len, M_TEMP, M_WAITOK | M_ZERO); + out = ps->ps_states; + pstore = mallocarray(slice_count, + sizeof(struct pfsync_state), M_TEMP, M_WAITOK | M_ZERO); nr = 0; for (i = 0; i <= pf_hashmask; i++) { struct pf_idhash *ih = &V_pf_idhash[i]; +DIOCGETSTATES_retry: + p = pstore; + + if (LIST_EMPTY(&ih->states)) + continue; + PF_HASHROW_LOCK(ih); + count = 0; + LIST_FOREACH(s, &ih->states, entry) { + if (s->timeout == PFTM_UNLINKED) + continue; + count++; + } + + if (count > slice_count) { + PF_HASHROW_UNLOCK(ih); + free(pstore, M_TEMP); + slice_count = count * 2; + pstore = mallocarray(slice_count, + sizeof(struct pfsync_state), M_TEMP, + M_WAITOK | M_ZERO); + goto DIOCGETSTATES_retry; + } + + if ((nr+count) * sizeof(*p) > ps->ps_len) { + PF_HASHROW_UNLOCK(ih); + goto DIOCGETSTATES_full; + } + LIST_FOREACH(s, &ih->states, entry) { if (s->timeout == PFTM_UNLINKED) continue; - if ((nr+1) * sizeof(*p) > ps->ps_len) { - PF_HASHROW_UNLOCK(ih); - goto DIOCGETSTATES_full; - } pfsync_state_export(p, s); p++; nr++; } PF_HASHROW_UNLOCK(ih); + error = copyout(pstore, out, + sizeof(struct pfsync_state) * count); + if (error) + break; + out = ps->ps_states + nr; } DIOCGETSTATES_full: - error = copyout(pstore, ps->ps_states, - sizeof(struct pfsync_state) * nr); - if (error) { - free(pstore, M_TEMP); - break; - } ps->ps_len = sizeof(struct pfsync_state) * nr; free(pstore, M_TEMP); From owner-dev-commits-src-branches@freebsd.org Mon Aug 9 18:39:48 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B975C6591D3; Mon, 9 Aug 2021 18:39:48 +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 4Gk4d04wWqz3HCh; Mon, 9 Aug 2021 18:39:48 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 90A9351D2; Mon, 9 Aug 2021 18:39:48 +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 179IdmMs069249; Mon, 9 Aug 2021 18:39:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 179IdmaQ069248; Mon, 9 Aug 2021 18:39:48 GMT (envelope-from git) Date: Mon, 9 Aug 2021 18:39:48 GMT Message-Id: <202108091839.179IdmaQ069248@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 42cb78bdd49c - stable/12 - pf: bound DIOCGETSTATES memory use MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 42cb78bdd49cd9a3e834c1ba3a00c7413917c812 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Aug 2021 18:39:48 -0000 The branch stable/12 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=42cb78bdd49cd9a3e834c1ba3a00c7413917c812 commit 42cb78bdd49cd9a3e834c1ba3a00c7413917c812 Author: Kristof Provost AuthorDate: 2021-08-02 07:46:33 +0000 Commit: Kristof Provost CommitDate: 2021-08-09 15:57:23 +0000 pf: bound DIOCGETSTATES memory use Similar to what we did earlier for DIOCGETSTATESV2 we only allocate enough memory for a handful of states and copy those out, bit by bit, rather than allocating memory for all states in one go. MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 600745f1e2260e7ed3c2e6183b24388ff38c916c) --- sys/netpfil/pf/pf_ioctl.c | 51 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 8a6286b5c21a..ea323709f6cd 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -2852,7 +2852,9 @@ DIOCCHANGERULE_error: struct pfioc_states *ps = (struct pfioc_states *)addr; struct pf_kstate *s; struct pfsync_state *pstore, *p; - int i, nr; + int i, nr; + size_t slice_count = 16, count; + void *out; if (ps->ps_len <= 0) { nr = uma_zone_get_cur(V_pf_state_z); @@ -2860,35 +2862,60 @@ DIOCCHANGERULE_error: break; } - p = pstore = malloc(ps->ps_len, M_TEMP, M_WAITOK | M_ZERO); + out = ps->ps_states; + pstore = mallocarray(slice_count, + sizeof(struct pfsync_state), M_TEMP, M_WAITOK | M_ZERO); nr = 0; for (i = 0; i <= pf_hashmask; i++) { struct pf_idhash *ih = &V_pf_idhash[i]; +DIOCGETSTATES_retry: + p = pstore; + + if (LIST_EMPTY(&ih->states)) + continue; + PF_HASHROW_LOCK(ih); + count = 0; + LIST_FOREACH(s, &ih->states, entry) { + if (s->timeout == PFTM_UNLINKED) + continue; + count++; + } + + if (count > slice_count) { + PF_HASHROW_UNLOCK(ih); + free(pstore, M_TEMP); + slice_count = count * 2; + pstore = mallocarray(slice_count, + sizeof(struct pfsync_state), M_TEMP, + M_WAITOK | M_ZERO); + goto DIOCGETSTATES_retry; + } + + if ((nr+count) * sizeof(*p) > ps->ps_len) { + PF_HASHROW_UNLOCK(ih); + goto DIOCGETSTATES_full; + } + LIST_FOREACH(s, &ih->states, entry) { if (s->timeout == PFTM_UNLINKED) continue; - if ((nr+1) * sizeof(*p) > ps->ps_len) { - PF_HASHROW_UNLOCK(ih); - goto DIOCGETSTATES_full; - } pfsync_state_export(p, s); p++; nr++; } PF_HASHROW_UNLOCK(ih); + error = copyout(pstore, out, + sizeof(struct pfsync_state) * count); + if (error) + break; + out = ps->ps_states + nr; } DIOCGETSTATES_full: - error = copyout(pstore, ps->ps_states, - sizeof(struct pfsync_state) * nr); - if (error) { - free(pstore, M_TEMP); - break; - } ps->ps_len = sizeof(struct pfsync_state) * nr; free(pstore, M_TEMP); From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 00:49:26 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8803A6715ED; Wed, 11 Aug 2021 00:49:26 +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 4Gkrn23Mprz3LBN; Wed, 11 Aug 2021 00:49:26 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 5BA31259EE; Wed, 11 Aug 2021 00:49:26 +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 17B0nQ7Y086560; Wed, 11 Aug 2021 00:49:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17B0nQOx086559; Wed, 11 Aug 2021 00:49:26 GMT (envelope-from git) Date: Wed, 11 Aug 2021 00:49:26 GMT Message-Id: <202108110049.17B0nQOx086559@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 50c21bf33905 - stable/13 - Do not expose to scheduler caches of single CPU. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 50c21bf3390556920ba8d73c50292776ce58bdaf Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 00:49:26 -0000 The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=50c21bf3390556920ba8d73c50292776ce58bdaf commit 50c21bf3390556920ba8d73c50292776ce58bdaf Author: Alexander Motin AuthorDate: 2021-07-28 20:15:43 +0000 Commit: Alexander Motin CommitDate: 2021-08-11 00:49:22 +0000 Do not expose to scheduler caches of single CPU. Before this change my dual-Xeon(R) Gold 6242R always reported 3 levels or topology (root, package/L3 and core/L2). But with SMT disabled core/L2 matches thread, so additional topology level only causes more traversal work. With this change SMT case is reported same as before, while non-SMT is reported with only 2 much more simple levels. MFC after: 2 weeks (cherry picked from commit 5a49f1914178c5275105f2ab0d23a98118cd585f) --- sys/x86/x86/mp_x86.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sys/x86/x86/mp_x86.c b/sys/x86/x86/mp_x86.c index 2dcdf923c467..f1c1e45e79b8 100644 --- a/sys/x86/x86/mp_x86.c +++ b/sys/x86/x86/mp_x86.c @@ -828,6 +828,12 @@ x86topo_add_sched_group(struct topo_node *root, struct cpu_group *cg_root) node = topo_next_nonchild_node(root, node); } + /* + * We are not interested in nodes including only one CPU each. + */ + if (nchildren == root->cpu_count) + return; + cg_root->cg_child = smp_topo_alloc(nchildren); cg_root->cg_children = nchildren; From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 00:49:58 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 70734671A46; Wed, 11 Aug 2021 00:49: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Gkrnf2mgMz3LLp; Wed, 11 Aug 2021 00:49:58 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 4730C25A88; Wed, 11 Aug 2021 00:49:58 +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 17B0nwMw086705; Wed, 11 Aug 2021 00:49:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17B0nwIv086704; Wed, 11 Aug 2021 00:49:58 GMT (envelope-from git) Date: Wed, 11 Aug 2021 00:49:58 GMT Message-Id: <202108110049.17B0nwIv086704@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 70a137b75e14 - stable/12 - Do not expose to scheduler caches of single CPU. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 70a137b75e149611c101cb57e0322e370f669094 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 00:49:58 -0000 The branch stable/12 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=70a137b75e149611c101cb57e0322e370f669094 commit 70a137b75e149611c101cb57e0322e370f669094 Author: Alexander Motin AuthorDate: 2021-07-28 20:15:43 +0000 Commit: Alexander Motin CommitDate: 2021-08-11 00:49:48 +0000 Do not expose to scheduler caches of single CPU. Before this change my dual-Xeon(R) Gold 6242R always reported 3 levels or topology (root, package/L3 and core/L2). But with SMT disabled core/L2 matches thread, so additional topology level only causes more traversal work. With this change SMT case is reported same as before, while non-SMT is reported with only 2 much more simple levels. MFC after: 2 weeks (cherry picked from commit 5a49f1914178c5275105f2ab0d23a98118cd585f) --- sys/x86/x86/mp_x86.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sys/x86/x86/mp_x86.c b/sys/x86/x86/mp_x86.c index 984edb43dd22..73565360007b 100644 --- a/sys/x86/x86/mp_x86.c +++ b/sys/x86/x86/mp_x86.c @@ -817,6 +817,12 @@ x86topo_add_sched_group(struct topo_node *root, struct cpu_group *cg_root) node = topo_next_nonchild_node(root, node); } + /* + * We are not interested in nodes including only one CPU each. + */ + if (nchildren == root->cpu_count) + return; + cg_root->cg_child = smp_topo_alloc(nchildren); cg_root->cg_children = nchildren; From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 01:13:43 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 16804672280; Wed, 11 Aug 2021 01:13:43 +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 4GksK300hTz3Mtm; Wed, 11 Aug 2021 01:13:43 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 D19D926113; Wed, 11 Aug 2021 01:13:42 +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 17B1Dgbm026808; Wed, 11 Aug 2021 01:13:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17B1DgvZ026807; Wed, 11 Aug 2021 01:13:42 GMT (envelope-from git) Date: Wed, 11 Aug 2021 01:13:42 GMT Message-Id: <202108110113.17B1DgvZ026807@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: ec95c1303332 - stable/13 - pf: Initialize arrays before copying out to userland MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: ec95c1303332ea3f157a61d696be8a1d3ec5d3b7 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 01:13:43 -0000 The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ec95c1303332ea3f157a61d696be8a1d3ec5d3b7 commit ec95c1303332ea3f157a61d696be8a1d3ec5d3b7 Author: Mark Johnston AuthorDate: 2021-07-28 14:16:25 +0000 Commit: Mark Johnston CommitDate: 2021-08-11 01:11:02 +0000 pf: Initialize arrays before copying out to userland A number of pf ioctls populate an array of structures and copy it out. They have the following structures: - caller specifies the size of its output buffer - ioctl handler allocates a kernel buffer of the same size - ioctl handler populates the buffer, possibly leaving some items initialized if the caller provided more space than needed - ioctl handler copies the entire buffer out to userland Thus, if more space was provided than is required, we end up copying out uninitialized kernel memory. Simply zero the buffer at allocation time to prevent this. Reported by: KMSAN Reviewed by: kp Sponsored by: The FreeBSD Foundation (cherry picked from commit 2b82c57e399700f5134c47d86d45ef2f2bd465e2) --- sys/netpfil/pf/pf_ioctl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 39931540d03d..6d2403bf213d 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -3811,7 +3811,7 @@ DIOCCHANGEADDR_error: totlen = io->pfrio_size * sizeof(struct pfr_table); pfrts = mallocarray(io->pfrio_size, sizeof(struct pfr_table), - M_TEMP, M_NOWAIT); + M_TEMP, M_NOWAIT | M_ZERO); if (pfrts == NULL) { error = ENOMEM; PF_RULES_RUNLOCK(); @@ -3849,7 +3849,7 @@ DIOCCHANGEADDR_error: totlen = io->pfrio_size * sizeof(struct pfr_tstats); pfrtstats = mallocarray(io->pfrio_size, - sizeof(struct pfr_tstats), M_TEMP, M_NOWAIT); + sizeof(struct pfr_tstats), M_TEMP, M_NOWAIT | M_ZERO); if (pfrtstats == NULL) { error = ENOMEM; PF_RULES_RUNLOCK(); @@ -4081,7 +4081,7 @@ DIOCCHANGEADDR_error: } totlen = io->pfrio_size * sizeof(struct pfr_addr); pfras = mallocarray(io->pfrio_size, sizeof(struct pfr_addr), - M_TEMP, M_WAITOK); + M_TEMP, M_WAITOK | M_ZERO); PF_RULES_RLOCK(); error = pfr_get_addrs(&io->pfrio_table, pfras, &io->pfrio_size, io->pfrio_flags | PFR_FLAG_USERIOCTL); @@ -4109,7 +4109,7 @@ DIOCCHANGEADDR_error: } totlen = io->pfrio_size * sizeof(struct pfr_astats); pfrastats = mallocarray(io->pfrio_size, - sizeof(struct pfr_astats), M_TEMP, M_WAITOK); + sizeof(struct pfr_astats), M_TEMP, M_WAITOK | M_ZERO); PF_RULES_RLOCK(); error = pfr_get_astats(&io->pfrio_table, pfrastats, &io->pfrio_size, io->pfrio_flags | PFR_FLAG_USERIOCTL); @@ -4613,7 +4613,7 @@ DIOCCHANGEADDR_error: bufsiz = io->pfiio_size * sizeof(struct pfi_kif); ifstore = mallocarray(io->pfiio_size, sizeof(struct pfi_kif), - M_TEMP, M_WAITOK); + M_TEMP, M_WAITOK | M_ZERO); PF_RULES_RLOCK(); pfi_get_ifaces(io->pfiio_name, ifstore, &io->pfiio_size); From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 01:13:44 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3A1E1672025; Wed, 11 Aug 2021 01:13:44 +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 4GksK40x6wz3N4X; Wed, 11 Aug 2021 01:13:44 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 03A7C260B4; Wed, 11 Aug 2021 01:13:44 +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 17B1DhR3026832; Wed, 11 Aug 2021 01:13:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17B1DhLl026831; Wed, 11 Aug 2021 01:13:43 GMT (envelope-from git) Date: Wed, 11 Aug 2021 01:13:43 GMT Message-Id: <202108110113.17B1DhLl026831@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 76aa36ab4853 - stable/13 - pf: Validate user string nul-termination before copying MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 76aa36ab4853eac6e6f5d2617323872a62b80b46 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 01:13:44 -0000 The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=76aa36ab4853eac6e6f5d2617323872a62b80b46 commit 76aa36ab4853eac6e6f5d2617323872a62b80b46 Author: Mark Johnston AuthorDate: 2021-07-28 14:16:42 +0000 Commit: Mark Johnston CommitDate: 2021-08-11 01:11:41 +0000 pf: Validate user string nul-termination before copying Some pf ioctl handlers use strlcpy() to copy strings when converting from user structures to their in-kernel representations. strlcpy() ensures that the destination will be nul-terminated, but it assumes that the source is nul-terminated. In particular, it returns the full length of the source string, so if the source is not nul-terminated, strlcpy() will keep scanning until it finds a nul byte, and it may encounter an unmapped page first. Add a helper to validate user strings before copying. There are also places where we look up a ruleset using a user-provided anchor string. In some ioctl handlers we were already nul-terminating the string, avoiding the same problem, but in other places we were not. Fix those by nul-terminating as well. Aside from being consistent, anchors have a maximum length of MAXPATHLEN - 1 so calling strnlen() might not be so desirable. Reported by: syzbot+35a1549b4663e9483dd1@syzkaller.appspotmail.com Reviewed by: kp Sponsored by: The FreeBSD Foundation (cherry picked from commit 64432ad2a2c4b10d3d3411a8ca018e2a35cec97e) --- sys/netpfil/pf/pf_ioctl.c | 123 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 92 insertions(+), 31 deletions(-) diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 6d2403bf213d..edc786d804da 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -283,6 +283,20 @@ extern u_long pf_ioctl_maxcount; goto target; \ } while (0) +/* + * Copy a user-provided string, returning an error if truncation would occur. + * Avoid scanning past "sz" bytes in the source string since there's no + * guarantee that it's nul-terminated. + */ +static int +pf_user_strcpy(char *dst, const char *src, size_t sz) +{ + if (strnlen(src, sz) == sz) + return (EINVAL); + (void)strlcpy(dst, src, sz); + return (0); +} + static void pfattach_vnet(void) { @@ -1522,14 +1536,17 @@ pf_kpooladdr_to_pooladdr(const struct pf_kpooladdr *kpool, strlcpy(pool->ifname, kpool->ifname, sizeof(pool->ifname)); } -static void +static int pf_pooladdr_to_kpooladdr(const struct pf_pooladdr *pool, struct pf_kpooladdr *kpool) { + int ret; bzero(kpool, sizeof(*kpool)); bcopy(&pool->addr, &kpool->addr, sizeof(kpool->addr)); - strlcpy(kpool->ifname, pool->ifname, sizeof(kpool->ifname)); + ret = pf_user_strcpy(kpool->ifname, pool->ifname, + sizeof(kpool->ifname)); + return (ret); } static void @@ -1694,15 +1711,30 @@ pf_rule_to_krule(const struct pf_rule *rule, struct pf_krule *krule) bcopy(&rule->src, &krule->src, sizeof(rule->src)); bcopy(&rule->dst, &krule->dst, sizeof(rule->dst)); - strlcpy(krule->label[0], rule->label, sizeof(rule->label)); - strlcpy(krule->ifname, rule->ifname, sizeof(rule->ifname)); - strlcpy(krule->qname, rule->qname, sizeof(rule->qname)); - strlcpy(krule->pqname, rule->pqname, sizeof(rule->pqname)); - strlcpy(krule->tagname, rule->tagname, sizeof(rule->tagname)); - strlcpy(krule->match_tagname, rule->match_tagname, + ret = pf_user_strcpy(krule->label[0], rule->label, sizeof(rule->label)); + if (ret != 0) + return (ret); + ret = pf_user_strcpy(krule->ifname, rule->ifname, sizeof(rule->ifname)); + if (ret != 0) + return (ret); + ret = pf_user_strcpy(krule->qname, rule->qname, sizeof(rule->qname)); + if (ret != 0) + return (ret); + ret = pf_user_strcpy(krule->pqname, rule->pqname, sizeof(rule->pqname)); + if (ret != 0) + return (ret); + ret = pf_user_strcpy(krule->tagname, rule->tagname, + sizeof(rule->tagname)); + if (ret != 0) + return (ret); + ret = pf_user_strcpy(krule->match_tagname, rule->match_tagname, sizeof(rule->match_tagname)); - strlcpy(krule->overload_tblname, rule->overload_tblname, + if (ret != 0) + return (ret); + ret = pf_user_strcpy(krule->overload_tblname, rule->overload_tblname, sizeof(rule->overload_tblname)); + if (ret != 0) + return (ret); ret = pf_pool_to_kpool(&rule->rpool, &krule->rpool); if (ret != 0) @@ -1916,6 +1948,8 @@ static int pf_state_kill_to_kstate_kill(const struct pfioc_state_kill *psk, struct pf_kstate_kill *kill) { + int ret; + bzero(kill, sizeof(*kill)); bcopy(&psk->psk_pfcmp, &kill->psk_pfcmp, sizeof(kill->psk_pfcmp)); @@ -1923,8 +1957,14 @@ pf_state_kill_to_kstate_kill(const struct pfioc_state_kill *psk, kill->psk_proto = psk->psk_proto; bcopy(&psk->psk_src, &kill->psk_src, sizeof(kill->psk_src)); bcopy(&psk->psk_dst, &kill->psk_dst, sizeof(kill->psk_dst)); - strlcpy(kill->psk_ifname, psk->psk_ifname, sizeof(kill->psk_ifname)); - strlcpy(kill->psk_label, psk->psk_label, sizeof(kill->psk_label)); + ret = pf_user_strcpy(kill->psk_ifname, psk->psk_ifname, + sizeof(kill->psk_ifname)); + if (ret != 0) + return (ret); + ret = pf_user_strcpy(kill->psk_label, psk->psk_label, + sizeof(kill->psk_label)); + if (ret != 0) + return (ret); return (0); } @@ -2340,8 +2380,9 @@ DIOCADDRULENV_error: struct pf_krule *tail; int rs_num; - PF_RULES_WLOCK(); pr->anchor[sizeof(pr->anchor) - 1] = 0; + + PF_RULES_WLOCK(); ruleset = pf_find_kruleset(pr->anchor); if (ruleset == NULL) { PF_RULES_WUNLOCK(); @@ -2371,8 +2412,9 @@ DIOCADDRULENV_error: struct pf_krule *rule; int rs_num; - PF_RULES_WLOCK(); pr->anchor[sizeof(pr->anchor) - 1] = 0; + + PF_RULES_WLOCK(); ruleset = pf_find_kruleset(pr->anchor); if (ruleset == NULL) { PF_RULES_WUNLOCK(); @@ -2561,6 +2603,8 @@ DIOCGETRULENV_error: u_int32_t nr = 0; int rs_num; + pcr->anchor[sizeof(pcr->anchor) - 1] = 0; + if (pcr->action < PF_CHANGE_ADD_HEAD || pcr->action > PF_CHANGE_GET_TICKET) { error = EINVAL; @@ -3028,7 +3072,7 @@ DIOCGETSTATESV2_full: break; } PF_RULES_WLOCK(); - strlcpy(V_pf_status.ifname, pi->ifname, IFNAMSIZ); + error = pf_user_strcpy(V_pf_status.ifname, pi->ifname, IFNAMSIZ); PF_RULES_WUNLOCK(); break; } @@ -3194,19 +3238,23 @@ DIOCGETSTATESV2_full: struct pf_ifspeed_v1 ps; struct ifnet *ifp; - if (psp->ifname[0] != 0) { - /* Can we completely trust user-land? */ - strlcpy(ps.ifname, psp->ifname, IFNAMSIZ); - ifp = ifunit(ps.ifname); - if (ifp != NULL) { - psp->baudrate32 = - (u_int32_t)uqmin(ifp->if_baudrate, UINT_MAX); - if (cmd == DIOCGIFSPEEDV1) - psp->baudrate = ifp->if_baudrate; - } else - error = EINVAL; - } else + if (psp->ifname[0] == '\0') { + error = EINVAL; + break; + } + + error = pf_user_strcpy(ps.ifname, psp->ifname, IFNAMSIZ); + if (error != 0) + break; + ifp = ifunit(ps.ifname); + if (ifp != NULL) { + psp->baudrate32 = + (u_int32_t)uqmin(ifp->if_baudrate, UINT_MAX); + if (cmd == DIOCGIFSPEEDV1) + psp->baudrate = ifp->if_baudrate; + } else { error = EINVAL; + } break; } @@ -3433,7 +3481,9 @@ DIOCGETSTATESV2_full: break; } pa = malloc(sizeof(*pa), M_PFRULE, M_WAITOK); - pf_pooladdr_to_kpooladdr(&pp->addr, pa); + error = pf_pooladdr_to_kpooladdr(&pp->addr, pa); + if (error != 0) + break; if (pa->ifname[0]) kif = pf_kkif_create(M_WAITOK); PF_RULES_WLOCK(); @@ -3469,8 +3519,10 @@ DIOCGETSTATESV2_full: struct pf_kpool *pool; struct pf_kpooladdr *pa; - PF_RULES_RLOCK(); + pp->anchor[sizeof(pp->anchor) - 1] = 0; pp->nr = 0; + + PF_RULES_RLOCK(); pool = pf_get_kpool(pp->anchor, pp->ticket, pp->r_action, pp->r_num, 0, 1, 0); if (pool == NULL) { @@ -3490,6 +3542,8 @@ DIOCGETSTATESV2_full: struct pf_kpooladdr *pa; u_int32_t nr = 0; + pp->anchor[sizeof(pp->anchor) - 1] = 0; + PF_RULES_RLOCK(); pool = pf_get_kpool(pp->anchor, pp->ticket, pp->r_action, pp->r_num, 0, 1, 1); @@ -3521,6 +3575,8 @@ DIOCGETSTATESV2_full: struct pf_kruleset *ruleset; struct pfi_kkif *kif = NULL; + pca->anchor[sizeof(pca->anchor) - 1] = 0; + if (pca->action < PF_CHANGE_ADD_HEAD || pca->action > PF_CHANGE_REMOVE) { error = EINVAL; @@ -3652,8 +3708,9 @@ DIOCCHANGEADDR_error: struct pf_kruleset *ruleset; struct pf_kanchor *anchor; - PF_RULES_RLOCK(); pr->path[sizeof(pr->path) - 1] = 0; + + PF_RULES_RLOCK(); if ((ruleset = pf_find_kruleset(pr->path)) == NULL) { PF_RULES_RUNLOCK(); error = ENOENT; @@ -3680,8 +3737,9 @@ DIOCCHANGEADDR_error: struct pf_kanchor *anchor; u_int32_t nr = 0; - PF_RULES_RLOCK(); pr->path[sizeof(pr->path) - 1] = 0; + + PF_RULES_RLOCK(); if ((ruleset = pf_find_kruleset(pr->path)) == NULL) { PF_RULES_RUNLOCK(); error = ENOENT; @@ -4262,6 +4320,7 @@ DIOCCHANGEADDR_error: } PF_RULES_WLOCK(); for (i = 0, ioe = ioes; i < io->size; i++, ioe++) { + ioe->anchor[sizeof(ioe->anchor) - 1] = '\0'; switch (ioe->rs_num) { #ifdef ALTQ case PF_RULESET_ALTQ: @@ -4335,6 +4394,7 @@ DIOCCHANGEADDR_error: } PF_RULES_WLOCK(); for (i = 0, ioe = ioes; i < io->size; i++, ioe++) { + ioe->anchor[sizeof(ioe->anchor) - 1] = '\0'; switch (ioe->rs_num) { #ifdef ALTQ case PF_RULESET_ALTQ: @@ -4411,6 +4471,7 @@ DIOCCHANGEADDR_error: PF_RULES_WLOCK(); /* First makes sure everything will succeed. */ for (i = 0, ioe = ioes; i < io->size; i++, ioe++) { + ioe->anchor[sizeof(ioe->anchor) - 1] = 0; switch (ioe->rs_num) { #ifdef ALTQ case PF_RULESET_ALTQ: @@ -4477,7 +4538,7 @@ DIOCCHANGEADDR_error: struct pfr_table table; bzero(&table, sizeof(table)); - strlcpy(table.pfrt_anchor, ioe->anchor, + (void)strlcpy(table.pfrt_anchor, ioe->anchor, sizeof(table.pfrt_anchor)); if ((error = pfr_ina_commit(&table, ioe->ticket, NULL, NULL, 0))) { From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 01:57:55 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DE18B67328B; Wed, 11 Aug 2021 01:57:55 +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 4GktJ35ZXHz3R9R; Wed, 11 Aug 2021 01:57:55 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 9D2F226A81; Wed, 11 Aug 2021 01:57:55 +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 17B1vtEp079991; Wed, 11 Aug 2021 01:57:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17B1vtEL079990; Wed, 11 Aug 2021 01:57:55 GMT (envelope-from git) Date: Wed, 11 Aug 2021 01:57:55 GMT Message-Id: <202108110157.17B1vtEL079990@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kevin Bowling Subject: git: f45271340836 - stable/13 - socket: Implement SO_RERROR MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f45271340836769d53320d6dbcf63226bb4e39e3 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 01:57:55 -0000 The branch stable/13 has been updated by kbowling (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=f45271340836769d53320d6dbcf63226bb4e39e3 commit f45271340836769d53320d6dbcf63226bb4e39e3 Author: Roy Marples AuthorDate: 2021-07-28 15:46:59 +0000 Commit: Kevin Bowling CommitDate: 2021-08-11 01:54:00 +0000 socket: Implement SO_RERROR SO_RERROR indicates that receive buffer overflows should be handled as errors. Historically receive buffer overflows have been ignored and programs could not tell if they missed messages or messages had been truncated because of overflows. Since programs historically do not expect to get receive overflow errors, this behavior is not the default. This is really really important for programs that use route(4) to keep in sync with the system. If we loose a message then we need to reload the full system state, otherwise the behaviour from that point is undefined and can lead to chasing bogus bug reports. Reviewed by: philip (network), kbowling (transport), gbe (manpages) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D26652 (cherry picked from commit 7045b1603bdf054145dd958a4acc17b410fb62a0) --- lib/libc/sys/getsockopt.2 | 10 +++++++- sbin/route/route.c | 13 +++++++++- sys/kern/uipc_sockbuf.c | 24 +++++++++++++++++ sys/kern/uipc_socket.c | 30 ++++++++++++++++------ sys/kern/uipc_usrreq.c | 2 +- sys/net/raw_usrreq.c | 11 ++++---- .../bluetooth/socket/ng_btsocket_hci_raw.c | 1 + sys/netgraph/ng_socket.c | 2 +- sys/netinet/ip_divert.c | 2 +- sys/netinet/ip_mroute.c | 2 +- sys/netinet/raw_ip.c | 3 +-- sys/netinet/udp_usrreq.c | 2 +- sys/netinet6/icmp6.c | 6 ++--- sys/netinet6/ip6_input.c | 1 + sys/netinet6/ip6_mroute.c | 3 ++- sys/netinet6/raw_ip6.c | 2 ++ sys/netinet6/send.c | 2 +- sys/netinet6/udp6_usrreq.c | 2 +- sys/netipsec/keysock.c | 10 ++++---- sys/sys/socket.h | 1 + sys/sys/socketvar.h | 6 ++++- 21 files changed, 100 insertions(+), 35 deletions(-) diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2 index 1e4ed6827170..3ff971a0e5db 100644 --- a/lib/libc/sys/getsockopt.2 +++ b/lib/libc/sys/getsockopt.2 @@ -28,7 +28,7 @@ .\" @(#)getsockopt.2 8.4 (Berkeley) 5/2/95 .\" $FreeBSD$ .\" -.Dd June 3, 2020 +.Dd February 8, 2021 .Dt GETSOCKOPT 2 .Os .Sh NAME @@ -177,6 +177,7 @@ for the socket .It Dv SO_PROTOCOL Ta "get the protocol number for the socket (get only)" .It Dv SO_PROTOTYPE Ta "SunOS alias for the Linux SO_PROTOCOL (get only)" .It Dv SO_ERROR Ta "get and clear error on the socket (get only)" +.It Dv SO_RERROR Ta "enables receive error reporting" .It Dv SO_SETFIB Ta "set the associated FIB (routing table) for the socket (set only)" .El .Pp @@ -514,6 +515,13 @@ returns any pending error on the socket and clears the error status. It may be used to check for asynchronous errors on connected datagram sockets or for other asynchronous errors. +.Dv SO_RERROR +indicates that receive buffer overflows should be handled as errors. +Historically receive buffer overflows have been ignored and programs +could not tell if they missed messages or messages had been truncated +because of overflows. +Since programs historically do not expect to get receive overflow errors, +this behavior is not the default. .Pp .Dv SO_LABEL returns the MAC label of the socket. diff --git a/sbin/route/route.c b/sbin/route/route.c index 51a0c68746a6..b16fb6d17a08 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1444,9 +1444,20 @@ monitor(int argc, char *argv[]) interfaces(); exit(0); } + +#ifdef SO_RERROR + n = 1; + if (setsockopt(s, SOL_SOCKET, SO_RERROR, &n, sizeof(n)) == -1) + warn("SO_RERROR"); +#endif + for (;;) { time_t now; - n = read(s, msg, 2048); + n = read(s, msg, sizeof(msg)); + if (n == -1) { + warn("read"); + continue; + } now = time(NULL); (void)printf("\ngot message of size %d on %s", n, ctime(&now)); print_rtmsg((struct rt_msghdr *)(void *)msg, n); diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c index 2c0e10ee1dc2..b2202fe15192 100644 --- a/sys/kern/uipc_sockbuf.c +++ b/sys/kern/uipc_sockbuf.c @@ -436,6 +436,30 @@ socantrcvmore(struct socket *so) mtx_assert(SOCKBUF_MTX(&so->so_rcv), MA_NOTOWNED); } +void +soroverflow_locked(struct socket *so) +{ + + SOCKBUF_LOCK_ASSERT(&so->so_rcv); + + if (so->so_options & SO_RERROR) { + so->so_rerror = ENOBUFS; + sorwakeup_locked(so); + } else + SOCKBUF_UNLOCK(&so->so_rcv); + + mtx_assert(SOCKBUF_MTX(&so->so_rcv), MA_NOTOWNED); +} + +void +soroverflow(struct socket *so) +{ + + SOCKBUF_LOCK(&so->so_rcv); + soroverflow_locked(so); + mtx_assert(SOCKBUF_MTX(&so->so_rcv), MA_NOTOWNED); +} + /* * Wait for data to arrive at/drain from a socket buffer. */ diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 9f8ad921933b..9f4e2fc64e98 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1948,12 +1948,19 @@ restart: KASSERT(m != NULL || !sbavail(&so->so_rcv), ("receive: m == %p sbavail == %u", m, sbavail(&so->so_rcv))); - if (so->so_error) { + if (so->so_error || so->so_rerror) { if (m != NULL) goto dontblock; - error = so->so_error; - if ((flags & MSG_PEEK) == 0) - so->so_error = 0; + if (so->so_error) + error = so->so_error; + else + error = so->so_rerror; + if ((flags & MSG_PEEK) == 0) { + if (so->so_error) + so->so_error = 0; + else + so->so_rerror = 0; + } SOCKBUF_UNLOCK(&so->so_rcv); goto release; } @@ -2297,7 +2304,7 @@ dontblock: while (flags & MSG_WAITALL && m == NULL && uio->uio_resid > 0 && !sosendallatonce(so) && nextrecord == NULL) { SOCKBUF_LOCK_ASSERT(&so->so_rcv); - if (so->so_error || + if (so->so_error || so->so_rerror || so->so_rcv.sb_state & SBS_CANTRCVMORE) break; /* @@ -3038,6 +3045,7 @@ sosetopt(struct socket *so, struct sockopt *sopt) case SO_NOSIGPIPE: case SO_NO_DDP: case SO_NO_OFFLOAD: + case SO_RERROR: error = sooptcopyin(sopt, &optval, sizeof optval, sizeof optval); if (error) @@ -3259,6 +3267,7 @@ sogetopt(struct socket *so, struct sockopt *sopt) case SO_NOSIGPIPE: case SO_NO_DDP: case SO_NO_OFFLOAD: + case SO_RERROR: optval = so->so_options & sopt->sopt_name; integer: error = sooptcopyout(sopt, &optval, sizeof optval); @@ -3278,8 +3287,13 @@ integer: case SO_ERROR: SOCK_LOCK(so); - optval = so->so_error; - so->so_error = 0; + if (so->so_error) { + optval = so->so_error; + so->so_error = 0; + } else { + optval = so->so_rerror; + so->so_rerror = 0; + } SOCK_UNLOCK(so); goto integer; @@ -3832,7 +3846,7 @@ filt_soread(struct knote *kn, long hint) kn->kn_flags |= EV_EOF; kn->kn_fflags = so->so_error; return (1); - } else if (so->so_error) /* temporary udp error */ + } else if (so->so_error || so->so_rerror) return (1); if (kn->kn_sfflags & NOTE_LOWAT) { diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index a01171424320..3d7daac42001 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1059,7 +1059,7 @@ uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, m = NULL; control = NULL; } else { - SOCKBUF_UNLOCK(&so2->so_rcv); + soroverflow_locked(so2); error = ENOBUFS; } if (nam != NULL) diff --git a/sys/net/raw_usrreq.c b/sys/net/raw_usrreq.c index f43de7dae9ca..5d4e223e5a0a 100644 --- a/sys/net/raw_usrreq.c +++ b/sys/net/raw_usrreq.c @@ -100,10 +100,10 @@ raw_input_ext(struct mbuf *m0, struct sockproto *proto, struct sockaddr *src, n = m_copym(m, 0, M_COPYALL, M_NOWAIT); if (n) { if (sbappendaddr(&last->so_rcv, src, - n, (struct mbuf *)0) == 0) - /* should notify about lost packet */ + n, (struct mbuf *)0) == 0) { + soroverflow(last); m_freem(n); - else + } else sorwakeup(last); } } @@ -111,9 +111,10 @@ raw_input_ext(struct mbuf *m0, struct sockproto *proto, struct sockaddr *src, } if (last) { if (sbappendaddr(&last->so_rcv, src, - m, (struct mbuf *)0) == 0) + m, (struct mbuf *)0) == 0) { + soroverflow(last); m_freem(m); - else + } else sorwakeup(last); } else m_freem(m); diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c b/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c index 5f6b98d03359..c82515f82631 100644 --- a/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c +++ b/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c @@ -539,6 +539,7 @@ ng_btsocket_hci_raw_data_input(struct mbuf *nam) NG_FREE_M(m); NG_FREE_M(ctl); + soroverflow(pcb->so); } } next: diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c index 1c67099a4dc4..05f37579aba1 100644 --- a/sys/netgraph/ng_socket.c +++ b/sys/netgraph/ng_socket.c @@ -993,7 +993,7 @@ ngs_rcvmsg(node_p node, item_p item, hook_p lasthook) /* Send it up to the socket. */ if (sbappendaddr_locked(&so->so_rcv, (struct sockaddr *)&addr, m, NULL) == 0) { - SOCKBUF_UNLOCK(&so->so_rcv); + soroverflow_locked(so); TRAP_ERROR; m_freem(m); return (ENOBUFS); diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 77a4bfcd08ac..4141386a6a2d 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -295,7 +295,7 @@ divert_packet(struct mbuf *m, bool incoming) if (sbappendaddr_locked(&sa->so_rcv, (struct sockaddr *)&divsrc, m, (struct mbuf *)0) == 0) { - SOCKBUF_UNLOCK(&sa->so_rcv); + soroverflow_locked(sa); sa = NULL; /* force mbuf reclaim below */ } else sorwakeup_locked(sa); diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index b66fe8df0793..6aeea44f631c 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -1199,7 +1199,7 @@ socket_send(struct socket *s, struct mbuf *mm, struct sockaddr_in *src) sorwakeup_locked(s); return 0; } - SOCKBUF_UNLOCK(&s->so_rcv); + soroverflow_locked(s); } m_freem(mm); return -1; diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 996440227145..afbdc14e47c4 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -263,11 +263,10 @@ rip_append(struct inpcb *last, struct ip *ip, struct mbuf *n, SOCKBUF_LOCK(&so->so_rcv); if (sbappendaddr_locked(&so->so_rcv, (struct sockaddr *)ripsrc, n, opts) == 0) { - /* should notify about lost packet */ + soroverflow_locked(so); m_freem(n); if (opts) m_freem(opts); - SOCKBUF_UNLOCK(&so->so_rcv); } else sorwakeup_locked(so); } else diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 5c9dbd36a1d6..ed79ddce5109 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -379,7 +379,7 @@ udp_append(struct inpcb *inp, struct ip *ip, struct mbuf *n, int off, so = inp->inp_socket; SOCKBUF_LOCK(&so->so_rcv); if (sbappendaddr_locked(&so->so_rcv, append_sa, n, opts) == 0) { - SOCKBUF_UNLOCK(&so->so_rcv); + soroverflow(so); m_freem(n); if (opts) m_freem(opts); diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index e17f82a54951..6b8f0f7be5bb 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1974,13 +1974,11 @@ icmp6_rip6_input(struct mbuf **mp, int off) &last->inp_socket->so_rcv, (struct sockaddr *)&fromsa, n, opts) == 0) { - /* should notify about lost packet */ + soroverflow_locked(last->inp_socket); m_freem(n); if (opts) { m_freem(opts); } - SOCKBUF_UNLOCK( - &last->inp_socket->so_rcv); } else sorwakeup_locked(last->inp_socket); opts = NULL; @@ -2020,7 +2018,7 @@ icmp6_rip6_input(struct mbuf **mp, int off) m_freem(m); if (opts) m_freem(opts); - SOCKBUF_UNLOCK(&last->inp_socket->so_rcv); + soroverflow_locked(last->inp_socket); } else sorwakeup_locked(last->inp_socket); INP_RUNLOCK(last); diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 9ea578f88417..30ad9a53006a 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1575,6 +1575,7 @@ ip6_notify_pmtu(struct inpcb *inp, struct sockaddr_in6 *dst, u_int32_t mtu) so = inp->inp_socket; if (sbappendaddr(&so->so_rcv, (struct sockaddr *)dst, NULL, m_mtu) == 0) { + soroverflow(so); m_freem(m_mtu); /* XXX: should count statistics */ } else diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index d2277e41110c..503c83490940 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1038,7 +1038,8 @@ socket_send(struct socket *s, struct mbuf *mm, struct sockaddr_in6 *src) mm, (struct mbuf *)0) != 0) { sorwakeup(s); return (0); - } + } else + soroverflow(s); } m_freem(mm); return (-1); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index a369abb04bfc..3e3df65a0e12 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -214,6 +214,7 @@ rip6_input(struct mbuf **mp, int *offp, int proto) if (sbappendaddr(&last->inp_socket->so_rcv, (struct sockaddr *)&fromsa, n, opts) == 0) { + soroverflow(last->inp_socket); m_freem(n); if (opts) m_freem(opts); @@ -325,6 +326,7 @@ skip_2: m_adj(m, *offp); if (sbappendaddr(&last->inp_socket->so_rcv, (struct sockaddr *)&fromsa, m, opts) == 0) { + soroverflow(last->inp_socket); m_freem(m); if (opts) m_freem(opts); diff --git a/sys/netinet6/send.c b/sys/netinet6/send.c index 0a2b3c65aab4..a69afd7b5ed6 100644 --- a/sys/netinet6/send.c +++ b/sys/netinet6/send.c @@ -309,7 +309,7 @@ send_input(struct mbuf *m, struct ifnet *ifp, int direction, int msglen __unused SOCKBUF_LOCK(&V_send_so->so_rcv); if (sbappendaddr_locked(&V_send_so->so_rcv, (struct sockaddr *)&sendsrc, m, NULL) == 0) { - SOCKBUF_UNLOCK(&V_send_so->so_rcv); + soroverflow_locked(V_send_so); /* XXX stats. */ m_freem(m); } else { diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c index 7c573d095d77..816e3bdd2850 100644 --- a/sys/netinet6/udp6_usrreq.c +++ b/sys/netinet6/udp6_usrreq.c @@ -197,7 +197,7 @@ udp6_append(struct inpcb *inp, struct mbuf *n, int off, SOCKBUF_LOCK(&so->so_rcv); if (sbappendaddr_locked(&so->so_rcv, (struct sockaddr *)&fromsa[0], n, opts) == 0) { - SOCKBUF_UNLOCK(&so->so_rcv); + soroverflow_locked(so); m_freem(n); if (opts) m_freem(opts); diff --git a/sys/netipsec/keysock.c b/sys/netipsec/keysock.c index 317eb53289cf..aa893b131a57 100644 --- a/sys/netipsec/keysock.c +++ b/sys/netipsec/keysock.c @@ -141,7 +141,6 @@ end: static int key_sendup0(struct rawcb *rp, struct mbuf *m, int promisc) { - int error; if (promisc) { struct sadb_msg *pmsg; @@ -165,11 +164,12 @@ key_sendup0(struct rawcb *rp, struct mbuf *m, int promisc) m, NULL)) { PFKEYSTAT_INC(in_nomem); m_freem(m); - error = ENOBUFS; - } else - error = 0; + soroverflow(rp->rcb_socket); + return ENOBUFS; + } + sorwakeup(rp->rcb_socket); - return error; + return 0; } /* so can be NULL if target != KEY_SENDUP_ONE */ diff --git a/sys/sys/socket.h b/sys/sys/socket.h index d9256fd7544a..2cb76f9c6d63 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -147,6 +147,7 @@ typedef __uintptr_t uintptr_t; #define SO_NO_OFFLOAD 0x00004000 /* socket cannot be offloaded */ #define SO_NO_DDP 0x00008000 /* disable direct data placement */ #define SO_REUSEPORT_LB 0x00010000 /* reuse with load balancing */ +#define SO_RERROR 0x00020000 /* keep track of receive errors */ /* * Additional options, not kept in so_options. diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index dbd9804a980d..47033fdabbfa 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -100,6 +100,7 @@ struct socket { struct protosw *so_proto; /* (a) protocol handle */ short so_timeo; /* (g) connection timeout */ u_short so_error; /* (f) error affecting connection */ + u_short so_rerror; /* (f) error affecting connection */ struct sigio *so_sigio; /* [sg] information for async I/O or out of band data (SIGURG) */ struct ucred *so_cred; /* (a) user credentials */ @@ -266,7 +267,8 @@ struct socket { /* can we read something from so? */ #define soreadabledata(so) \ - (sbavail(&(so)->so_rcv) >= (so)->so_rcv.sb_lowat || (so)->so_error) + (sbavail(&(so)->so_rcv) >= (so)->so_rcv.sb_lowat || \ + (so)->so_error || (so)->so_rerror) #define soreadable(so) \ (soreadabledata(so) || ((so)->so_rcv.sb_state & SBS_CANTRCVMORE)) @@ -480,6 +482,8 @@ void socantrcvmore(struct socket *so); void socantrcvmore_locked(struct socket *so); void socantsendmore(struct socket *so); void socantsendmore_locked(struct socket *so); +void soroverflow(struct socket *so); +void soroverflow_locked(struct socket *so); /* * Accept filter functions (duh). From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 01:57:56 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E0B5567328E; Wed, 11 Aug 2021 01:57:56 +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 4GktJ460Q2z3R7N; Wed, 11 Aug 2021 01:57:56 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B5354266CF; Wed, 11 Aug 2021 01:57:56 +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 17B1vuSL080015; Wed, 11 Aug 2021 01:57:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17B1vuNo080014; Wed, 11 Aug 2021 01:57:56 GMT (envelope-from git) Date: Wed, 11 Aug 2021 01:57:56 GMT Message-Id: <202108110157.17B1vuNo080014@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kevin Bowling Subject: git: 2141aab35b70 - stable/13 - udp: Fix soroverflow SOCKBUF unlocking MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2141aab35b70b0bf29d6ff9bd39d0cf7e2bd7e11 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 01:57:57 -0000 The branch stable/13 has been updated by kbowling (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=2141aab35b70b0bf29d6ff9bd39d0cf7e2bd7e11 commit 2141aab35b70b0bf29d6ff9bd39d0cf7e2bd7e11 Author: Konstantin Kukushkin AuthorDate: 2021-08-01 14:41:38 +0000 Commit: Kevin Bowling CommitDate: 2021-08-11 01:54:18 +0000 udp: Fix soroverflow SOCKBUF unlocking We hold the SOCKBUF_LOCK so use soroverflow_locked here. This bug may manifest as a non-killable process stuck in [*so_rcv]. Approved by: scottl Reviewed by: Roy Marples Fixes: 7045b1603bdf MFC after: 10 days Differential Revision: https://reviews.freebsd.org/D31374 (cherry picked from commit a61c24ddb7d677337d6184ffcee34a6e902d72d7) --- sys/netinet/udp_usrreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index ed79ddce5109..76ed063391eb 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -379,7 +379,7 @@ udp_append(struct inpcb *inp, struct ip *ip, struct mbuf *n, int off, so = inp->inp_socket; SOCKBUF_LOCK(&so->so_rcv); if (sbappendaddr_locked(&so->so_rcv, append_sa, n, opts) == 0) { - soroverflow(so); + soroverflow_locked(so); m_freem(n); if (opts) m_freem(opts); From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 02:34:25 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B543867335F; Wed, 11 Aug 2021 02:34:25 +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 4Gkv694jQGz3j4V; Wed, 11 Aug 2021 02:34:25 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 85F1D27205; Wed, 11 Aug 2021 02:34:25 +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 17B2YPBu033171; Wed, 11 Aug 2021 02:34:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17B2YPHT033170; Wed, 11 Aug 2021 02:34:25 GMT (envelope-from git) Date: Wed, 11 Aug 2021 02:34:25 GMT Message-Id: <202108110234.17B2YPHT033170@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kevin Bowling Subject: git: 664077e69e8f - stable/12 - socket: Implement SO_RERROR MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 664077e69e8f300cd0218e3c700ee235df12fcff Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 02:34:25 -0000 The branch stable/12 has been updated by kbowling (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=664077e69e8f300cd0218e3c700ee235df12fcff commit 664077e69e8f300cd0218e3c700ee235df12fcff Author: Roy Marples AuthorDate: 2021-07-28 15:46:59 +0000 Commit: Kevin Bowling CommitDate: 2021-08-11 01:59:36 +0000 socket: Implement SO_RERROR SO_RERROR indicates that receive buffer overflows should be handled as errors. Historically receive buffer overflows have been ignored and programs could not tell if they missed messages or messages had been truncated because of overflows. Since programs historically do not expect to get receive overflow errors, this behavior is not the default. This is really really important for programs that use route(4) to keep in sync with the system. If we loose a message then we need to reload the full system state, otherwise the behaviour from that point is undefined and can lead to chasing bogus bug reports. Reviewed by: philip (network), kbowling (transport), gbe (manpages) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D26652 (cherry picked from commit 7045b1603bdf054145dd958a4acc17b410fb62a0) --- lib/libc/sys/getsockopt.2 | 10 +++++++- sbin/route/route.c | 13 +++++++++- sys/kern/uipc_sockbuf.c | 24 +++++++++++++++++ sys/kern/uipc_socket.c | 30 ++++++++++++++++------ sys/kern/uipc_usrreq.c | 2 +- sys/net/raw_usrreq.c | 11 ++++---- .../bluetooth/socket/ng_btsocket_hci_raw.c | 1 + sys/netgraph/ng_socket.c | 2 +- sys/netinet/ip_divert.c | 2 +- sys/netinet/ip_mroute.c | 2 +- sys/netinet/raw_ip.c | 3 +-- sys/netinet/udp_usrreq.c | 2 +- sys/netinet6/icmp6.c | 6 ++--- sys/netinet6/ip6_input.c | 1 + sys/netinet6/ip6_mroute.c | 3 ++- sys/netinet6/raw_ip6.c | 2 ++ sys/netinet6/send.c | 2 +- sys/netinet6/udp6_usrreq.c | 2 +- sys/netipsec/keysock.c | 10 ++++---- sys/sys/socket.h | 1 + sys/sys/socketvar.h | 6 ++++- 21 files changed, 100 insertions(+), 35 deletions(-) diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2 index dcd39e07efb8..b27f663f01bd 100644 --- a/lib/libc/sys/getsockopt.2 +++ b/lib/libc/sys/getsockopt.2 @@ -28,7 +28,7 @@ .\" @(#)getsockopt.2 8.4 (Berkeley) 5/2/95 .\" $FreeBSD$ .\" -.Dd June 03, 2020 +.Dd February 8, 2021 .Dt GETSOCKOPT 2 .Os .Sh NAME @@ -177,6 +177,7 @@ for the socket .It Dv SO_PROTOCOL Ta "get the protocol number for the socket (get only)" .It Dv SO_PROTOTYPE Ta "SunOS alias for the Linux SO_PROTOCOL (get only)" .It Dv SO_ERROR Ta "get and clear error on the socket (get only)" +.It Dv SO_RERROR Ta "enables receive error reporting" .It Dv SO_SETFIB Ta "set the associated FIB (routing table) for the socket (set only)" .El .Pp @@ -513,6 +514,13 @@ returns any pending error on the socket and clears the error status. It may be used to check for asynchronous errors on connected datagram sockets or for other asynchronous errors. +.Dv SO_RERROR +indicates that receive buffer overflows should be handled as errors. +Historically receive buffer overflows have been ignored and programs +could not tell if they missed messages or messages had been truncated +because of overflows. +Since programs historically do not expect to get receive overflow errors, +this behavior is not the default. .Pp .Dv SO_LABEL returns the MAC label of the socket. diff --git a/sbin/route/route.c b/sbin/route/route.c index 9c9e4b304848..14d1fe274ad3 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1485,9 +1485,20 @@ monitor(int argc, char *argv[]) interfaces(); exit(0); } + +#ifdef SO_RERROR + n = 1; + if (setsockopt(s, SOL_SOCKET, SO_RERROR, &n, sizeof(n)) == -1) + warn("SO_RERROR"); +#endif + for (;;) { time_t now; - n = read(s, msg, 2048); + n = read(s, msg, sizeof(msg)); + if (n == -1) { + warn("read"); + continue; + } now = time(NULL); (void)printf("\ngot message of size %d on %s", n, ctime(&now)); print_rtmsg((struct rt_msghdr *)(void *)msg, n); diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c index 598fc05f2fcf..92b6d728fcd8 100644 --- a/sys/kern/uipc_sockbuf.c +++ b/sys/kern/uipc_sockbuf.c @@ -254,6 +254,30 @@ socantrcvmore(struct socket *so) mtx_assert(SOCKBUF_MTX(&so->so_rcv), MA_NOTOWNED); } +void +soroverflow_locked(struct socket *so) +{ + + SOCKBUF_LOCK_ASSERT(&so->so_rcv); + + if (so->so_options & SO_RERROR) { + so->so_rerror = ENOBUFS; + sorwakeup_locked(so); + } else + SOCKBUF_UNLOCK(&so->so_rcv); + + mtx_assert(SOCKBUF_MTX(&so->so_rcv), MA_NOTOWNED); +} + +void +soroverflow(struct socket *so) +{ + + SOCKBUF_LOCK(&so->so_rcv); + soroverflow_locked(so); + mtx_assert(SOCKBUF_MTX(&so->so_rcv), MA_NOTOWNED); +} + /* * Wait for data to arrive at/drain from a socket buffer. */ diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index dd028c660d2b..620d81246062 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1771,12 +1771,19 @@ restart: KASSERT(m != NULL || !sbavail(&so->so_rcv), ("receive: m == %p sbavail == %u", m, sbavail(&so->so_rcv))); - if (so->so_error) { + if (so->so_error || so->so_rerror) { if (m != NULL) goto dontblock; - error = so->so_error; - if ((flags & MSG_PEEK) == 0) - so->so_error = 0; + if (so->so_error) + error = so->so_error; + else + error = so->so_rerror; + if ((flags & MSG_PEEK) == 0) { + if (so->so_error) + so->so_error = 0; + else + so->so_rerror = 0; + } SOCKBUF_UNLOCK(&so->so_rcv); goto release; } @@ -2084,7 +2091,7 @@ dontblock: while (flags & MSG_WAITALL && m == NULL && uio->uio_resid > 0 && !sosendallatonce(so) && nextrecord == NULL) { SOCKBUF_LOCK_ASSERT(&so->so_rcv); - if (so->so_error || + if (so->so_error || so->so_rerror || so->so_rcv.sb_state & SBS_CANTRCVMORE) break; /* @@ -2805,6 +2812,7 @@ sosetopt(struct socket *so, struct sockopt *sopt) case SO_NOSIGPIPE: case SO_NO_DDP: case SO_NO_OFFLOAD: + case SO_RERROR: error = sooptcopyin(sopt, &optval, sizeof optval, sizeof optval); if (error) @@ -3026,6 +3034,7 @@ sogetopt(struct socket *so, struct sockopt *sopt) case SO_NOSIGPIPE: case SO_NO_DDP: case SO_NO_OFFLOAD: + case SO_RERROR: optval = so->so_options & sopt->sopt_name; integer: error = sooptcopyout(sopt, &optval, sizeof optval); @@ -3045,8 +3054,13 @@ integer: case SO_ERROR: SOCK_LOCK(so); - optval = so->so_error; - so->so_error = 0; + if (so->so_error) { + optval = so->so_error; + so->so_error = 0; + } else { + optval = so->so_rerror; + so->so_rerror = 0; + } SOCK_UNLOCK(so); goto integer; @@ -3595,7 +3609,7 @@ filt_soread(struct knote *kn, long hint) kn->kn_flags |= EV_EOF; kn->kn_fflags = so->so_error; return (1); - } else if (so->so_error) /* temporary udp error */ + } else if (so->so_error || so->so_rerror) return (1); if (kn->kn_sfflags & NOTE_LOWAT) { diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 25f27837d6d5..329e4346c425 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1047,7 +1047,7 @@ uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, m = NULL; control = NULL; } else { - SOCKBUF_UNLOCK(&so2->so_rcv); + soroverflow_locked(so2); error = ENOBUFS; } if (nam != NULL) diff --git a/sys/net/raw_usrreq.c b/sys/net/raw_usrreq.c index f43de7dae9ca..5d4e223e5a0a 100644 --- a/sys/net/raw_usrreq.c +++ b/sys/net/raw_usrreq.c @@ -100,10 +100,10 @@ raw_input_ext(struct mbuf *m0, struct sockproto *proto, struct sockaddr *src, n = m_copym(m, 0, M_COPYALL, M_NOWAIT); if (n) { if (sbappendaddr(&last->so_rcv, src, - n, (struct mbuf *)0) == 0) - /* should notify about lost packet */ + n, (struct mbuf *)0) == 0) { + soroverflow(last); m_freem(n); - else + } else sorwakeup(last); } } @@ -111,9 +111,10 @@ raw_input_ext(struct mbuf *m0, struct sockproto *proto, struct sockaddr *src, } if (last) { if (sbappendaddr(&last->so_rcv, src, - m, (struct mbuf *)0) == 0) + m, (struct mbuf *)0) == 0) { + soroverflow(last); m_freem(m); - else + } else sorwakeup(last); } else m_freem(m); diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c b/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c index 9523d88af633..a78905705fd0 100644 --- a/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c +++ b/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c @@ -539,6 +539,7 @@ ng_btsocket_hci_raw_data_input(struct mbuf *nam) NG_FREE_M(m); NG_FREE_M(ctl); + soroverflow(pcb->so); } } next: diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c index 08ee76300ae8..a10993a8fab6 100644 --- a/sys/netgraph/ng_socket.c +++ b/sys/netgraph/ng_socket.c @@ -974,7 +974,7 @@ ngs_rcvmsg(node_p node, item_p item, hook_p lasthook) /* Send it up to the socket. */ if (sbappendaddr_locked(&so->so_rcv, (struct sockaddr *)&addr, m, NULL) == 0) { - SOCKBUF_UNLOCK(&so->so_rcv); + soroverflow_locked(so); TRAP_ERROR; m_freem(m); return (ENOBUFS); diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 81e70177e641..54cd0f509b51 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -287,7 +287,7 @@ divert_packet(struct mbuf *m, int incoming) if (sbappendaddr_locked(&sa->so_rcv, (struct sockaddr *)&divsrc, m, (struct mbuf *)0) == 0) { - SOCKBUF_UNLOCK(&sa->so_rcv); + soroverflow_locked(sa); sa = NULL; /* force mbuf reclaim below */ } else sorwakeup_locked(sa); diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index d024cdb16772..60b18cdbd35c 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -1195,7 +1195,7 @@ socket_send(struct socket *s, struct mbuf *mm, struct sockaddr_in *src) sorwakeup_locked(s); return 0; } - SOCKBUF_UNLOCK(&s->so_rcv); + soroverflow_locked(s); } m_freem(mm); return -1; diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index f15a3bca3a90..84dd4d7a764c 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -261,11 +261,10 @@ rip_append(struct inpcb *last, struct ip *ip, struct mbuf *n, SOCKBUF_LOCK(&so->so_rcv); if (sbappendaddr_locked(&so->so_rcv, (struct sockaddr *)ripsrc, n, opts) == 0) { - /* should notify about lost packet */ + soroverflow_locked(so); m_freem(n); if (opts) m_freem(opts); - SOCKBUF_UNLOCK(&so->so_rcv); } else sorwakeup_locked(so); } else diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index c271392c225d..2a5e8fdd25c2 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -376,7 +376,7 @@ udp_append(struct inpcb *inp, struct ip *ip, struct mbuf *n, int off, so = inp->inp_socket; SOCKBUF_LOCK(&so->so_rcv); if (sbappendaddr_locked(&so->so_rcv, append_sa, n, opts) == 0) { - SOCKBUF_UNLOCK(&so->so_rcv); + soroverflow(so); m_freem(n); if (opts) m_freem(opts); diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 75e7ef7c2039..923f5dd63ddc 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1976,13 +1976,11 @@ icmp6_rip6_input(struct mbuf **mp, int off) &last->inp_socket->so_rcv, (struct sockaddr *)&fromsa, n, opts) == 0) { - /* should notify about lost packet */ + soroverflow_locked(last->inp_socket); m_freem(n); if (opts) { m_freem(opts); } - SOCKBUF_UNLOCK( - &last->inp_socket->so_rcv); } else sorwakeup_locked(last->inp_socket); opts = NULL; @@ -2023,7 +2021,7 @@ icmp6_rip6_input(struct mbuf **mp, int off) m_freem(m); if (opts) m_freem(opts); - SOCKBUF_UNLOCK(&last->inp_socket->so_rcv); + soroverflow_locked(last->inp_socket); } else sorwakeup_locked(last->inp_socket); INP_RUNLOCK(last); diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 74d275f7e66e..9ef4620565a1 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1579,6 +1579,7 @@ ip6_notify_pmtu(struct inpcb *inp, struct sockaddr_in6 *dst, u_int32_t mtu) so = inp->inp_socket; if (sbappendaddr(&so->so_rcv, (struct sockaddr *)dst, NULL, m_mtu) == 0) { + soroverflow(so); m_freem(m_mtu); /* XXX: should count statistics */ } else diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index 82ca908d4553..bce491d7fa5b 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1039,7 +1039,8 @@ socket_send(struct socket *s, struct mbuf *mm, struct sockaddr_in6 *src) mm, (struct mbuf *)0) != 0) { sorwakeup(s); return (0); - } + } else + soroverflow(s); } m_freem(mm); return (-1); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 304ee4a8899b..47e106f02651 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -212,6 +212,7 @@ rip6_input(struct mbuf **mp, int *offp, int proto) if (sbappendaddr(&last->inp_socket->so_rcv, (struct sockaddr *)&fromsa, n, opts) == 0) { + soroverflow(last->inp_socket); m_freem(n); if (opts) m_freem(opts); @@ -324,6 +325,7 @@ skip_2: m_adj(m, *offp); if (sbappendaddr(&last->inp_socket->so_rcv, (struct sockaddr *)&fromsa, m, opts) == 0) { + soroverflow(last->inp_socket); m_freem(m); if (opts) m_freem(opts); diff --git a/sys/netinet6/send.c b/sys/netinet6/send.c index bc9880c82267..8458ef367cba 100644 --- a/sys/netinet6/send.c +++ b/sys/netinet6/send.c @@ -291,7 +291,7 @@ send_input(struct mbuf *m, struct ifnet *ifp, int direction, int msglen __unused SOCKBUF_LOCK(&V_send_so->so_rcv); if (sbappendaddr_locked(&V_send_so->so_rcv, (struct sockaddr *)&sendsrc, m, NULL) == 0) { - SOCKBUF_UNLOCK(&V_send_so->so_rcv); + soroverflow_locked(V_send_so); /* XXX stats. */ m_freem(m); } else { diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c index 98588e48c511..02d4359dc92f 100644 --- a/sys/netinet6/udp6_usrreq.c +++ b/sys/netinet6/udp6_usrreq.c @@ -191,7 +191,7 @@ udp6_append(struct inpcb *inp, struct mbuf *n, int off, SOCKBUF_LOCK(&so->so_rcv); if (sbappendaddr_locked(&so->so_rcv, (struct sockaddr *)&fromsa[0], n, opts) == 0) { - SOCKBUF_UNLOCK(&so->so_rcv); + soroverflow_locked(so); m_freem(n); if (opts) m_freem(opts); diff --git a/sys/netipsec/keysock.c b/sys/netipsec/keysock.c index a216f085c1bc..84a65967eea2 100644 --- a/sys/netipsec/keysock.c +++ b/sys/netipsec/keysock.c @@ -141,7 +141,6 @@ end: static int key_sendup0(struct rawcb *rp, struct mbuf *m, int promisc) { - int error; if (promisc) { struct sadb_msg *pmsg; @@ -165,11 +164,12 @@ key_sendup0(struct rawcb *rp, struct mbuf *m, int promisc) m, NULL)) { PFKEYSTAT_INC(in_nomem); m_freem(m); - error = ENOBUFS; - } else - error = 0; + soroverflow(rp->rcb_socket); + return ENOBUFS; + } + sorwakeup(rp->rcb_socket); - return error; + return 0; } /* so can be NULL if target != KEY_SENDUP_ONE */ diff --git a/sys/sys/socket.h b/sys/sys/socket.h index eaad9b1bacdb..17a5099424f4 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -147,6 +147,7 @@ typedef __uintptr_t uintptr_t; #define SO_NO_OFFLOAD 0x00004000 /* socket cannot be offloaded */ #define SO_NO_DDP 0x00008000 /* disable direct data placement */ #define SO_REUSEPORT_LB 0x00010000 /* reuse with load balancing */ +#define SO_RERROR 0x00020000 /* keep track of receive errors */ /* * Additional options, not kept in so_options. diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 99d8839f8beb..99d2d554143e 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -99,6 +99,7 @@ struct socket { struct protosw *so_proto; /* (a) protocol handle */ short so_timeo; /* (g) connection timeout */ u_short so_error; /* (f) error affecting connection */ + u_short so_rerror; /* (f) error affecting connection */ struct sigio *so_sigio; /* [sg] information for async I/O or out of band data (SIGURG) */ struct ucred *so_cred; /* (a) user credentials */ @@ -258,7 +259,8 @@ struct socket { /* can we read something from so? */ #define soreadabledata(so) \ - (sbavail(&(so)->so_rcv) >= (so)->so_rcv.sb_lowat || (so)->so_error) + (sbavail(&(so)->so_rcv) >= (so)->so_rcv.sb_lowat || \ + (so)->so_error || (so)->so_rerror) #define soreadable(so) \ (soreadabledata(so) || ((so)->so_rcv.sb_state & SBS_CANTRCVMORE)) @@ -471,6 +473,8 @@ void socantrcvmore(struct socket *so); void socantrcvmore_locked(struct socket *so); void socantsendmore(struct socket *so); void socantsendmore_locked(struct socket *so); +void soroverflow(struct socket *so); +void soroverflow_locked(struct socket *so); /* * Accept filter functions (duh). From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 02:34:26 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CD1C8673722; Wed, 11 Aug 2021 02:34:26 +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 4Gkv6B5N3Nz3j4X; Wed, 11 Aug 2021 02:34:26 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 A07A227301; Wed, 11 Aug 2021 02:34:26 +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 17B2YQ4N033195; Wed, 11 Aug 2021 02:34:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17B2YQBm033194; Wed, 11 Aug 2021 02:34:26 GMT (envelope-from git) Date: Wed, 11 Aug 2021 02:34:26 GMT Message-Id: <202108110234.17B2YQBm033194@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kevin Bowling Subject: git: ae51594c9794 - stable/12 - udp: Fix soroverflow SOCKBUF unlocking MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: ae51594c9794275073c955ad4c6fa7ad9fcc1614 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 02:34:27 -0000 The branch stable/12 has been updated by kbowling (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=ae51594c9794275073c955ad4c6fa7ad9fcc1614 commit ae51594c9794275073c955ad4c6fa7ad9fcc1614 Author: Konstantin Kukushkin AuthorDate: 2021-08-01 14:41:38 +0000 Commit: Kevin Bowling CommitDate: 2021-08-11 02:00:09 +0000 udp: Fix soroverflow SOCKBUF unlocking We hold the SOCKBUF_LOCK so use soroverflow_locked here. This bug may manifest as a non-killable process stuck in [*so_rcv]. Approved by: scottl Reviewed by: Roy Marples Fixes: 7045b1603bdf MFC after: 10 days Differential Revision: https://reviews.freebsd.org/D31374 (cherry picked from commit a61c24ddb7d677337d6184ffcee34a6e902d72d7) --- sys/netinet/udp_usrreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 2a5e8fdd25c2..f57a9059a7db 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -376,7 +376,7 @@ udp_append(struct inpcb *inp, struct ip *ip, struct mbuf *n, int off, so = inp->inp_socket; SOCKBUF_LOCK(&so->so_rcv); if (sbappendaddr_locked(&so->so_rcv, append_sa, n, opts) == 0) { - soroverflow(so); + soroverflow_locked(so); m_freem(n); if (opts) m_freem(opts); From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 13:25:14 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C9F4F653647; Wed, 11 Aug 2021 13:25:14 +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 4Gl9Y65Klkz3ClJ; Wed, 11 Aug 2021 13:25:14 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 9ADD37DE8; Wed, 11 Aug 2021 13:25:14 +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 17BDPEAq004778; Wed, 11 Aug 2021 13:25:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BDPEsV004777; Wed, 11 Aug 2021 13:25:14 GMT (envelope-from git) Date: Wed, 11 Aug 2021 13:25:14 GMT Message-Id: <202108111325.17BDPEsV004777@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 8abcdb1f59cc - stable/12 - pf: hide struct pf_kstatus behind ifdef _KERNEL MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 8abcdb1f59ccdb75df84112427eb2a7ba7e69bb7 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 13:25:14 -0000 The branch stable/12 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=8abcdb1f59ccdb75df84112427eb2a7ba7e69bb7 commit 8abcdb1f59ccdb75df84112427eb2a7ba7e69bb7 Author: Mateusz Guzik AuthorDate: 2021-07-23 17:34:43 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 12:14:22 +0000 pf: hide struct pf_kstatus behind ifdef _KERNEL Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit d9cc6ea270ea52e860e3cc730876ee4324081586) --- sys/net/pfvar.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 52fd015ba54e..eda2e9fb71c0 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1146,6 +1146,7 @@ enum pf_syncookies_mode { PF_SYNCOOKIES_MODE_MAX = PF_SYNCOOKIES_ALWAYS }; +#ifdef _KERNEL struct pf_kstatus { counter_u64_t counters[PFRES_MAX]; /* reason for passing/dropping */ counter_u64_t lcounters[LCNT_MAX]; /* limit counters */ @@ -1163,6 +1164,7 @@ struct pf_kstatus { enum pf_syncookies_mode syncookies_mode; bool syncookies_active; }; +#endif struct pf_divert { union { From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 13:25:15 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D46B0653DDF; Wed, 11 Aug 2021 13:25:15 +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 4Gl9Y75j2Gz3CQm; Wed, 11 Aug 2021 13:25:15 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 AB2867B4C; Wed, 11 Aug 2021 13:25:15 +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 17BDPFBp004802; Wed, 11 Aug 2021 13:25:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BDPFfF004801; Wed, 11 Aug 2021 13:25:15 GMT (envelope-from git) Date: Wed, 11 Aug 2021 13:25:15 GMT Message-Id: <202108111325.17BDPFfF004801@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 919cf790d4da - stable/12 - pf: consistently malloc rules with M_ZERO MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 919cf790d4da75f82cae2c3dfc28a5d0f8e3d115 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 13:25:15 -0000 The branch stable/12 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=919cf790d4da75f82cae2c3dfc28a5d0f8e3d115 commit 919cf790d4da75f82cae2c3dfc28a5d0f8e3d115 Author: Mateusz Guzik AuthorDate: 2021-07-23 15:01:29 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 12:14:32 +0000 pf: consistently malloc rules with M_ZERO Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 49a7d47235434a300cc57b205e493988fdebf79c) --- sys/netpfil/pf/pf_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index ea323709f6cd..bb71f44cad97 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -2330,7 +2330,7 @@ DIOCADDRULENV_error: struct pfioc_rule *pr = (struct pfioc_rule *)addr; struct pf_krule *rule; - rule = malloc(sizeof(*rule), M_PFRULE, M_WAITOK); + rule = malloc(sizeof(*rule), M_PFRULE, M_WAITOK | M_ZERO); error = pf_rule_to_krule(&pr->rule, rule); if (error != 0) { free(rule, M_PFRULE); @@ -2583,7 +2583,7 @@ DIOCGETRULENV_error: } if (pcr->action != PF_CHANGE_REMOVE) { - newrule = malloc(sizeof(*newrule), M_PFRULE, M_WAITOK); + newrule = malloc(sizeof(*newrule), M_PFRULE, M_WAITOK | M_ZERO); error = pf_rule_to_krule(&pcr->rule, newrule); if (error != 0) { free(newrule, M_PFRULE); From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 13:25:17 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2615B653DE1; Wed, 11 Aug 2021 13:25:17 +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 4Gl9Y905Ggz3Cnb; Wed, 11 Aug 2021 13:25:16 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 CFDD17D7C; Wed, 11 Aug 2021 13:25:16 +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 17BDPGaY004826; Wed, 11 Aug 2021 13:25:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BDPGI2004825; Wed, 11 Aug 2021 13:25:16 GMT (envelope-from git) Date: Wed, 11 Aug 2021 13:25:16 GMT Message-Id: <202108111325.17BDPGI2004825@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: abfc083a0859 - stable/12 - pf: drop redundant 'else' in pf_normalize_* MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: abfc083a085902f296cf8c56731e9fcf9af99adc Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 13:25:17 -0000 The branch stable/12 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=abfc083a085902f296cf8c56731e9fcf9af99adc commit abfc083a085902f296cf8c56731e9fcf9af99adc Author: Mateusz Guzik AuthorDate: 2021-07-24 05:17:27 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 12:15:11 +0000 pf: drop redundant 'else' in pf_normalize_* Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 6f1fb6561236fa933835a9a67bd442053fb509e9) --- sys/netpfil/pf/pf_norm.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/sys/netpfil/pf/pf_norm.c b/sys/netpfil/pf/pf_norm.c index ea49fb230021..8ffa690ac36f 100644 --- a/sys/netpfil/pf/pf_norm.c +++ b/sys/netpfil/pf/pf_norm.c @@ -1061,10 +1061,9 @@ pf_normalize_ip(struct mbuf **m0, int dir, struct pfi_kkif *kif, u_short *reason if (r == NULL || r->action == PF_NOSCRUB) return (PF_PASS); - else { - counter_u64_add(r->packets[dir == PF_OUT], 1); - counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); - } + + counter_u64_add(r->packets[dir == PF_OUT], 1); + counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); /* Check for illegal packets */ if (hlen < (int)sizeof(struct ip)) { @@ -1204,10 +1203,9 @@ pf_normalize_ip6(struct mbuf **m0, int dir, struct pfi_kkif *kif, if (r == NULL || r->action == PF_NOSCRUB) return (PF_PASS); - else { - counter_u64_add(r->packets[dir == PF_OUT], 1); - counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); - } + + counter_u64_add(r->packets[dir == PF_OUT], 1); + counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); /* Check for illegal packets */ if (sizeof(struct ip6_hdr) + IPV6_MAXPACKET < m->m_pkthdr.len) @@ -1390,10 +1388,9 @@ pf_normalize_tcp(int dir, struct pfi_kkif *kif, struct mbuf *m, int ipoff, if (rm == NULL || rm->action == PF_NOSCRUB) return (PF_PASS); - else { - counter_u64_add(r->packets[dir == PF_OUT], 1); - counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); - } + + counter_u64_add(r->packets[dir == PF_OUT], 1); + counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); if (rm->rule_flag & PFRULE_REASSEMBLE_TCP) pd->flags |= PFDESC_TCP_NORM; From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 13:25:18 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 67C9865386D; Wed, 11 Aug 2021 13:25:18 +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 4Gl9YB1Hymz3Chr; Wed, 11 Aug 2021 13:25:18 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 0B9E77EF4; Wed, 11 Aug 2021 13:25:18 +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 17BDPH16004850; Wed, 11 Aug 2021 13:25:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BDPHnL004849; Wed, 11 Aug 2021 13:25:17 GMT (envelope-from git) Date: Wed, 11 Aug 2021 13:25:17 GMT Message-Id: <202108111325.17BDPHnL004849@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 5bc73c369dba - stable/12 - pf: add hybrid 32- an 64- bit counters MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 5bc73c369dbae8759f5735ca5a1f940127cec2db Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 13:25:18 -0000 The branch stable/12 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=5bc73c369dbae8759f5735ca5a1f940127cec2db commit 5bc73c369dbae8759f5735ca5a1f940127cec2db Author: Mateusz Guzik AuthorDate: 2021-07-22 20:47:24 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 12:20:09 +0000 pf: add hybrid 32- an 64- bit counters Numerous counters got migrated from straight uint64_t to the counter(9) API. Unfortunately the implementation comes with a significiant performance hit on some platforms and cannot be easily fixed. Work around the problem by implementing a pf-specific variant. Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit defdcdd5648dc1ea789bc54bb45108fcab546a6b) --- sys/net/pfvar.h | 218 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sys/netpfil/pf/pf.c | 28 ++++++- 2 files changed, 245 insertions(+), 1 deletion(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index eda2e9fb71c0..fd0b36c72a42 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -43,9 +43,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -64,6 +66,222 @@ #ifdef _KERNEL +#if defined(__arm__) +#define PF_WANT_32_TO_64_COUNTER +#endif + +/* + * A hybrid of 32-bit and 64-bit counters which can be used on platforms where + * counter(9) is very expensive. + * + * As 32-bit counters are expected to overflow, a periodic job sums them up to + * a saved 64-bit state. Fetching the value still walks all CPUs to get the most + * current snapshot. + */ +#ifdef PF_WANT_32_TO_64_COUNTER +struct pf_counter_u64_pcpu { + u_int32_t current; + u_int32_t snapshot; +}; + +struct pf_counter_u64 { + struct pf_counter_u64_pcpu *pfcu64_pcpu; + u_int64_t pfcu64_value; + seq_t pfcu64_seqc; +}; + +static inline int +pf_counter_u64_init(struct pf_counter_u64 *pfcu64, int flags) +{ + + pfcu64->pfcu64_value = 0; + pfcu64->pfcu64_seqc = 0; + pfcu64->pfcu64_pcpu = uma_zalloc_pcpu(pcpu_zone_64, flags | M_ZERO); + if (__predict_false(pfcu64->pfcu64_pcpu == NULL)) + return (ENOMEM); + return (0); +} + +static inline void +pf_counter_u64_deinit(struct pf_counter_u64 *pfcu64) +{ + + uma_zfree_pcpu(pcpu_zone_64, pfcu64->pfcu64_pcpu); +} + +static inline void +pf_counter_u64_critical_enter(void) +{ + + critical_enter(); +} + +static inline void +pf_counter_u64_critical_exit(void) +{ + + critical_exit(); +} + +static inline void +pf_counter_u64_add_protected(struct pf_counter_u64 *pfcu64, uint32_t n) +{ + struct pf_counter_u64_pcpu *pcpu; + u_int32_t val; + + MPASS(curthread->td_critnest > 0); + pcpu = zpcpu_get(pfcu64->pfcu64_pcpu); + val = atomic_load_int(&pcpu->current); + atomic_store_int(&pcpu->current, val + n); +} + +static inline void +pf_counter_u64_add(struct pf_counter_u64 *pfcu64, uint32_t n) +{ + + critical_enter(); + pf_counter_u64_add_protected(pfcu64, n); + critical_exit(); +} + +static inline u_int64_t +pf_counter_u64_periodic(struct pf_counter_u64 *pfcu64) +{ + struct pf_counter_u64_pcpu *pcpu; + u_int64_t sum; + u_int32_t val; + int cpu; + + MPASS(curthread->td_critnest > 0); + seq_write_begin(&pfcu64->pfcu64_seqc); + sum = pfcu64->pfcu64_value; + CPU_FOREACH(cpu) { + pcpu = zpcpu_get_cpu(pfcu64->pfcu64_pcpu, cpu); + val = atomic_load_int(&pcpu->current); + sum += (uint32_t)(val - pcpu->snapshot); + pcpu->snapshot = val; + } + pfcu64->pfcu64_value = sum; + seq_write_end(&pfcu64->pfcu64_seqc); + return (sum); +} + +static inline u_int64_t +pf_counter_u64_fetch(struct pf_counter_u64 *pfcu64) +{ + struct pf_counter_u64_pcpu *pcpu; + u_int64_t sum; + seq_t seqc; + int cpu; + + for (;;) { + seqc = seq_load(&pfcu64->pfcu64_seqc); + sum = 0; + CPU_FOREACH(cpu) { + pcpu = zpcpu_get_cpu(pfcu64->pfcu64_pcpu, cpu); + sum += (uint32_t)(atomic_load_int(&pcpu->current) -pcpu->snapshot); + } + sum += pfcu64->pfcu64_value; + if (seq_consistent(&pfcu64->pfcu64_seqc, seqc)) + break; + } + return (sum); +} + +static inline void +pf_counter_u64_zero_protected(struct pf_counter_u64 *pfcu64) +{ + struct pf_counter_u64_pcpu *pcpu; + int cpu; + + MPASS(curthread->td_critnest > 0); + seq_write_begin(&pfcu64->pfcu64_seqc); + CPU_FOREACH(cpu) { + pcpu = zpcpu_get_cpu(pfcu64->pfcu64_pcpu, cpu); + pcpu->snapshot = atomic_load_int(&pcpu->current); + } + pfcu64->pfcu64_value = 0; + seq_write_end(&pfcu64->pfcu64_seqc); +} + +static inline void +pf_counter_u64_zero(struct pf_counter_u64 *pfcu64) +{ + + critical_enter(); + pf_counter_u64_zero_protected(pfcu64); + critical_exit(); +} +#else +struct pf_counter_u64 { + counter_u64_t counter; +}; + +static inline int +pf_counter_u64_init(struct pf_counter_u64 *pfcu64, int flags) +{ + + pfcu64->counter = counter_u64_alloc(flags); + if (__predict_false(pfcu64->counter == NULL)) + return (ENOMEM); + return (0); +} + +static inline void +pf_counter_u64_deinit(struct pf_counter_u64 *pfcu64) +{ + + counter_u64_free(pfcu64->counter); +} + +static inline void +pf_counter_u64_critical_enter(void) +{ + +} + +static inline void +pf_counter_u64_critical_exit(void) +{ + +} + +static inline void +pf_counter_u64_add_protected(struct pf_counter_u64 *pfcu64, uint32_t n) +{ + + counter_u64_add(pfcu64->counter, n); +} + +static inline void +pf_counter_u64_add(struct pf_counter_u64 *pfcu64, uint32_t n) +{ + + pf_counter_u64_add_protected(pfcu64, n); +} + +static inline u_int64_t +pf_counter_u64_fetch(struct pf_counter_u64 *pfcu64) +{ + + return (counter_u64_fetch(pfcu64->counter)); +} + +static inline void +pf_counter_u64_zero_protected(struct pf_counter_u64 *pfcu64) +{ + + counter_u64_zero(pfcu64->counter); +} + +static inline void +pf_counter_u64_zero(struct pf_counter_u64 *pfcu64) +{ + + pf_counter_u64_zero_protected(pfcu64); +} +#endif + SYSCTL_DECL(_net_pf); MALLOC_DECLARE(M_PFHASH); diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index a7b429120c9e..5edafe4b5e7a 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -155,6 +155,11 @@ VNET_DECLARE(int, pf_vnet_active); VNET_DEFINE_STATIC(uint32_t, pf_purge_idx); #define V_pf_purge_idx VNET(pf_purge_idx) +#ifdef PF_WANT_32_TO_64_COUNTER +VNET_DEFINE_STATIC(uint32_t, pf_counter_periodic_iter); +#define V_pf_counter_periodic_iter VNET(pf_counter_periodic_iter) +#endif + /* * Queue for pf_intr() sends. */ @@ -1505,6 +1510,25 @@ pf_intr(void *v) CURVNET_RESTORE(); } +#define pf_purge_thread_period (hz / 10) + +#ifdef PF_WANT_32_TO_64_COUNTER +static void +pf_counter_u64_periodic_main(void) +{ + PF_RULES_RLOCK_TRACKER; + + V_pf_counter_periodic_iter++; + + PF_RULES_RLOCK(); + pf_counter_u64_critical_enter(); + pf_counter_u64_critical_exit(); + PF_RULES_RUNLOCK(); +} +#else +#define pf_counter_u64_periodic_main() do { } while (0) +#endif + void pf_purge_thread(void *unused __unused) { @@ -1512,7 +1536,7 @@ pf_purge_thread(void *unused __unused) sx_xlock(&pf_end_lock); while (pf_end_threads == 0) { - sx_sleep(pf_purge_thread, &pf_end_lock, 0, "pftm", hz / 10); + sx_sleep(pf_purge_thread, &pf_end_lock, 0, "pftm", pf_purge_thread_period); VNET_LIST_RLOCK(); VNET_FOREACH(vnet_iter) { @@ -1525,6 +1549,8 @@ pf_purge_thread(void *unused __unused) continue; } + pf_counter_u64_periodic_main(); + /* * Process 1/interval fraction of the state * table every run. From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 13:25:20 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7AD036538EB; Wed, 11 Aug 2021 13:25:20 +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 4Gl9YD2SB1z3Cpg; Wed, 11 Aug 2021 13:25:20 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 39A4210137; Wed, 11 Aug 2021 13:25:20 +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 17BDPK24004905; Wed, 11 Aug 2021 13:25:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BDPKxP004904; Wed, 11 Aug 2021 13:25:20 GMT (envelope-from git) Date: Wed, 11 Aug 2021 13:25:20 GMT Message-Id: <202108111325.17BDPKxP004904@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 72b14da466bb - stable/12 - pf: switch kif counters to pf_counter_u64 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 72b14da466bbb9eebf2400930abefce8de47261d Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 13:25:20 -0000 The branch stable/12 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=72b14da466bbb9eebf2400930abefce8de47261d commit 72b14da466bbb9eebf2400930abefce8de47261d Author: Mateusz Guzik AuthorDate: 2021-07-23 10:29:46 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 12:21:48 +0000 pf: switch kif counters to pf_counter_u64 Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit d40d4b3ed788b05697541b9ae94b1960ff2cf6f6) --- sys/net/pfvar.h | 17 +++++++++++-- sys/netpfil/pf/pf.c | 51 +++++++++++++++++++++++++++++++++++--- sys/netpfil/pf/pf_if.c | 62 +++++++++++++++++++++++++++++++++++------------ sys/netpfil/pf/pf_ioctl.c | 17 +++++++++++++ 4 files changed, 126 insertions(+), 21 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 7c1e92d39470..e8cf8b1e6019 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1255,14 +1255,17 @@ struct pfi_kkif { } _pfik_glue; #define pfik_tree _pfik_glue._pfik_tree #define pfik_list _pfik_glue._pfik_list - counter_u64_t pfik_packets[2][2][2]; - counter_u64_t pfik_bytes[2][2][2]; + struct pf_counter_u64 pfik_packets[2][2][2]; + struct pf_counter_u64 pfik_bytes[2][2][2]; u_int32_t pfik_tzero; u_int pfik_flags; struct ifnet *pfik_ifp; struct ifg_group *pfik_group; u_int pfik_rulerefs; TAILQ_HEAD(, pfi_dynaddr) pfik_dynaddrs; +#ifdef PF_WANT_32_TO_64_COUNTER + LIST_ENTRY(pfi_kkif) pfik_allkiflist; +#endif }; #endif @@ -1848,6 +1851,16 @@ VNET_DECLARE(struct pf_altqqueue *, pf_altq_ifs_inactive); VNET_DECLARE(struct pf_krulequeue, pf_unlinked_rules); #define V_pf_unlinked_rules VNET(pf_unlinked_rules) +#ifdef PF_WANT_32_TO_64_COUNTER +LIST_HEAD(allkiflist_head, pfi_kkif); +VNET_DECLARE(struct allkiflist_head, pf_allkiflist); +#define V_pf_allkiflist VNET(pf_allkiflist) +VNET_DECLARE(size_t, pf_allkifcount); +#define V_pf_allkifcount VNET(pf_allkifcount) +VNET_DECLARE(struct pfi_kkif *, pf_kifmarker); +#define V_pf_kifmarker VNET(pf_kifmarker) +#endif + void pf_initialize(void); void pf_mtag_initialize(void); void pf_mtag_cleanup(void); diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 1ba95754bd32..3dcea7e59bd0 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1528,6 +1528,48 @@ pf_status_counter_u64_periodic(void) } } +static void +pf_kif_counter_u64_periodic(void) +{ + struct pfi_kkif *kif; + size_t r, run; + + PF_RULES_RASSERT(); + + if (__predict_false(V_pf_allkifcount == 0)) { + return; + } + + if ((V_pf_counter_periodic_iter % (pf_purge_thread_period * 10 * 300)) != 0) { + return; + } + + run = V_pf_allkifcount / 10; + if (run < 5) + run = 5; + + for (r = 0; r < run; r++) { + kif = LIST_NEXT(V_pf_kifmarker, pfik_allkiflist); + if (kif == NULL) { + LIST_REMOVE(V_pf_kifmarker, pfik_allkiflist); + LIST_INSERT_HEAD(&V_pf_allkiflist, V_pf_kifmarker, pfik_allkiflist); + break; + } + + LIST_REMOVE(V_pf_kifmarker, pfik_allkiflist); + LIST_INSERT_AFTER(kif, V_pf_kifmarker, pfik_allkiflist); + + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + for (int k = 0; k < 2; k++) { + pf_counter_u64_periodic(&kif->pfik_packets[i][j][k]); + pf_counter_u64_periodic(&kif->pfik_bytes[i][j][k]); + } + } + } + } +} + static void pf_counter_u64_periodic_main(void) { @@ -1538,6 +1580,7 @@ pf_counter_u64_periodic_main(void) PF_RULES_RLOCK(); pf_counter_u64_critical_enter(); pf_status_counter_u64_periodic(); + pf_kif_counter_u64_periodic(); pf_counter_u64_critical_exit(); PF_RULES_RUNLOCK(); } @@ -6468,9 +6511,9 @@ done: (s == NULL)); } - counter_u64_add(kif->pfik_bytes[0][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_add(&kif->pfik_bytes[0][dir == PF_OUT][action != PF_PASS], pd.tot_len); - counter_u64_add(kif->pfik_packets[0][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_add(&kif->pfik_packets[0][dir == PF_OUT][action != PF_PASS], 1); if (action == PF_PASS || r->action == PF_DROP) { @@ -6876,9 +6919,9 @@ done: &pd, (s == NULL)); } - counter_u64_add(kif->pfik_bytes[1][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_add(&kif->pfik_bytes[1][dir == PF_OUT][action != PF_PASS], pd.tot_len); - counter_u64_add(kif->pfik_packets[1][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_add(&kif->pfik_packets[1][dir == PF_OUT][action != PF_PASS], 1); if (action == PF_PASS || r->action == PF_DROP) { diff --git a/sys/netpfil/pf/pf_if.c b/sys/netpfil/pf/pf_if.c index 9c10be3b3b77..ff2038138068 100644 --- a/sys/netpfil/pf/pf_if.c +++ b/sys/netpfil/pf/pf_if.c @@ -69,6 +69,12 @@ VNET_DEFINE_STATIC(int, pfi_buffer_max); #define V_pfi_buffer_cnt VNET(pfi_buffer_cnt) #define V_pfi_buffer_max VNET(pfi_buffer_max) +#ifdef PF_WANT_32_TO_64_COUNTER +VNET_DEFINE(struct allkiflist_head, pf_allkiflist); +VNET_DEFINE(size_t, pf_allkifcount); +VNET_DEFINE(struct pfi_kkif *, pf_kifmarker); +#endif + eventhandler_tag pfi_attach_cookie; eventhandler_tag pfi_detach_cookie; eventhandler_tag pfi_attach_group_cookie; @@ -198,6 +204,9 @@ struct pfi_kkif* pf_kkif_create(int flags) { struct pfi_kkif *kif; +#ifdef PF_WANT_32_TO_64_COUNTER + bool wowned; +#endif kif = malloc(sizeof(*kif), PFI_MTYPE, flags | M_ZERO); if (! kif) @@ -206,13 +215,12 @@ pf_kkif_create(int flags) for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { - kif->pfik_packets[i][j][k] = - counter_u64_alloc(flags); - kif->pfik_bytes[i][j][k] = - counter_u64_alloc(flags); + if (pf_counter_u64_init(&kif->pfik_packets[i][j][k], flags) != 0) { + pf_kkif_free(kif); + return (NULL); + } - if (! kif->pfik_packets[i][j][k] || - ! kif->pfik_bytes[i][j][k]) { + if (pf_counter_u64_init(&kif->pfik_bytes[i][j][k], flags) != 0) { pf_kkif_free(kif); return (NULL); } @@ -220,20 +228,44 @@ pf_kkif_create(int flags) } } +#ifdef PF_WANT_32_TO_64_COUNTER + wowned = PF_RULES_WOWNED(); + if (!wowned) + PF_RULES_WLOCK(); + LIST_INSERT_HEAD(&V_pf_allkiflist, kif, pfik_allkiflist); + V_pf_allkifcount++; + if (!wowned) + PF_RULES_WUNLOCK(); +#endif + return (kif); } void pf_kkif_free(struct pfi_kkif *kif) { +#ifdef PF_WANT_32_TO_64_COUNTER + bool wowned; +#endif + if (! kif) return; +#ifdef PF_WANT_32_TO_64_COUNTER + wowned = PF_RULES_WOWNED(); + if (!wowned) + PF_RULES_WLOCK(); + LIST_REMOVE(kif, pfik_allkiflist); + V_pf_allkifcount--; + if (!wowned) + PF_RULES_WUNLOCK(); +#endif + for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { - counter_u64_free(kif->pfik_packets[i][j][k]); - counter_u64_free(kif->pfik_bytes[i][j][k]); + pf_counter_u64_deinit(&kif->pfik_packets[i][j][k]); + pf_counter_u64_deinit(&kif->pfik_bytes[i][j][k]); } } } @@ -248,8 +280,8 @@ pf_kkif_zero(struct pfi_kkif *kif) for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { - counter_u64_zero(kif->pfik_packets[i][j][k]); - counter_u64_zero(kif->pfik_bytes[i][j][k]); + pf_counter_u64_zero(&kif->pfik_packets[i][j][k]); + pf_counter_u64_zero(&kif->pfik_bytes[i][j][k]); } } } @@ -791,15 +823,15 @@ pfi_update_status(const char *name, struct pf_status *pfs) for (j = 0; j < 2; j++) for (k = 0; k < 2; k++) { pfs->pcounters[i][j][k] += - counter_u64_fetch(p->pfik_packets[i][j][k]); + pf_counter_u64_fetch(&p->pfik_packets[i][j][k]); pfs->bcounters[i][j] += - counter_u64_fetch(p->pfik_bytes[i][j][k]); + pf_counter_u64_fetch(&p->pfik_bytes[i][j][k]); } } } static void -pf_kkif_to_kif(const struct pfi_kkif *kkif, struct pfi_kif *kif) +pf_kkif_to_kif(struct pfi_kkif *kkif, struct pfi_kif *kif) { bzero(kif, sizeof(*kif)); @@ -808,9 +840,9 @@ pf_kkif_to_kif(const struct pfi_kkif *kkif, struct pfi_kif *kif) for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { kif->pfik_packets[i][j][k] = - counter_u64_fetch(kkif->pfik_packets[i][j][k]); + pf_counter_u64_fetch(&kkif->pfik_packets[i][j][k]); kif->pfik_bytes[i][j][k] = - counter_u64_fetch(kkif->pfik_bytes[i][j][k]); + pf_counter_u64_fetch(&kkif->pfik_bytes[i][j][k]); } } } diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 1b2c329fdb2c..e02fff4f88f6 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -319,6 +319,13 @@ pfattach_vnet(void) V_pf_default_rule.states_tot = counter_u64_alloc(M_WAITOK); V_pf_default_rule.src_nodes = counter_u64_alloc(M_WAITOK); +#ifdef PF_WANT_32_TO_64_COUNTER + V_pf_kifmarker = malloc(sizeof(*V_pf_kifmarker), PFI_MTYPE, M_WAITOK | M_ZERO); + PF_RULES_WLOCK(); + LIST_INSERT_HEAD(&V_pf_allkiflist, V_pf_kifmarker, pfik_allkiflist); + PF_RULES_WUNLOCK(); +#endif + /* initialize default timeouts */ my_timeout[PFTM_TCP_FIRST_PACKET] = PFTM_TCP_FIRST_PACKET_VAL; my_timeout[PFTM_TCP_OPENING] = PFTM_TCP_OPENING_VAL; @@ -5601,6 +5608,16 @@ pf_unload_vnet(void) #endif uma_zdestroy(V_pf_tag_z); +#ifdef PF_WANT_32_TO_64_COUNTER + PF_RULES_WLOCK(); + LIST_REMOVE(V_pf_kifmarker, pfik_allkiflist); + PF_RULES_WUNLOCK(); + free(V_pf_kifmarker, PFI_MTYPE); + + MPASS(LIST_EMPTY(&V_pf_allkiflist)); + MPASS(V_pf_allkifcount == 0); +#endif + /* Free counters last as we updated them during shutdown. */ counter_u64_free(V_pf_default_rule.evaluations); for (int i = 0; i < 2; i++) { From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 13:25:19 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 55FDA6536EB; Wed, 11 Aug 2021 13:25:19 +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 4Gl9YC1gbXz3ClZ; Wed, 11 Aug 2021 13:25:19 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 152B37EF5; Wed, 11 Aug 2021 13:25:19 +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 17BDPINU004881; Wed, 11 Aug 2021 13:25:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BDPIGS004880; Wed, 11 Aug 2021 13:25:18 GMT (envelope-from git) Date: Wed, 11 Aug 2021 13:25:18 GMT Message-Id: <202108111325.17BDPIGS004880@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: f45535b6c79d - stable/12 - pf: switch pf_status.fcounters to pf_counter_u64 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: f45535b6c79d359625fb2d9cff5e46de5bd59861 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 13:25:19 -0000 The branch stable/12 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=f45535b6c79d359625fb2d9cff5e46de5bd59861 commit f45535b6c79d359625fb2d9cff5e46de5bd59861 Author: Mateusz Guzik AuthorDate: 2021-07-24 05:33:52 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 12:21:04 +0000 pf: switch pf_status.fcounters to pf_counter_u64 Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit fc4c42ce0b5ce87901b327e25f55b4e3ab4c6cf5) --- sys/net/pfvar.h | 2 +- sys/netpfil/pf/pf.c | 26 +++++++++++++++++++++----- sys/netpfil/pf/pf_ioctl.c | 8 ++++---- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index fd0b36c72a42..7c1e92d39470 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1368,7 +1368,7 @@ enum pf_syncookies_mode { struct pf_kstatus { counter_u64_t counters[PFRES_MAX]; /* reason for passing/dropping */ counter_u64_t lcounters[LCNT_MAX]; /* limit counters */ - counter_u64_t fcounters[FCNT_MAX]; /* state operation counters */ + struct pf_counter_u64 fcounters[FCNT_MAX]; /* state operation counters */ counter_u64_t scounters[SCNT_MAX]; /* src_node operation counters */ uint32_t states; uint32_t src_nodes; diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 5edafe4b5e7a..1ba95754bd32 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1311,7 +1311,7 @@ pf_state_insert(struct pfi_kkif *kif, struct pfi_kkif *orig_kif, /* One for keys, one for ID hash. */ refcount_init(&s->refs, 2); - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_INSERT], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_INSERT], 1); if (V_pfsync_insert_state_ptr != NULL) V_pfsync_insert_state_ptr(s); @@ -1328,7 +1328,7 @@ pf_find_state_byid(uint64_t id, uint32_t creatorid) struct pf_idhash *ih; struct pf_kstate *s; - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); ih = &V_pf_idhash[(be64toh(id) % (pf_hashmask + 1))]; @@ -1355,7 +1355,7 @@ pf_find_state(struct pfi_kkif *kif, struct pf_state_key_cmp *key, u_int dir) struct pf_kstate *s; int idx; - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); kh = &V_pf_keyhash[pf_hashkey((struct pf_state_key *)key)]; @@ -1399,7 +1399,7 @@ pf_find_state_all(struct pf_state_key_cmp *key, u_int dir, int *more) struct pf_kstate *s, *ret = NULL; int idx, inout = 0; - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); kh = &V_pf_keyhash[pf_hashkey((struct pf_state_key *)key)]; @@ -1513,6 +1513,21 @@ pf_intr(void *v) #define pf_purge_thread_period (hz / 10) #ifdef PF_WANT_32_TO_64_COUNTER +static void +pf_status_counter_u64_periodic(void) +{ + + PF_RULES_RASSERT(); + + if ((V_pf_counter_periodic_iter % (pf_purge_thread_period * 10 * 60)) != 0) { + return; + } + + for (int i = 0; i < FCNT_MAX; i++) { + pf_counter_u64_periodic(&V_pf_status.fcounters[i]); + } +} + static void pf_counter_u64_periodic_main(void) { @@ -1522,6 +1537,7 @@ pf_counter_u64_periodic_main(void) PF_RULES_RLOCK(); pf_counter_u64_critical_enter(); + pf_status_counter_u64_periodic(); pf_counter_u64_critical_exit(); PF_RULES_RUNLOCK(); } @@ -1779,7 +1795,7 @@ pf_free_state(struct pf_kstate *cur) pf_normalize_tcp_cleanup(cur); uma_zfree(V_pf_state_z, cur); - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_REMOVALS], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_REMOVALS], 1); } /* diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index bb71f44cad97..1b2c329fdb2c 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -354,7 +354,7 @@ pfattach_vnet(void) for (int i = 0; i < LCNT_MAX; i++) V_pf_status.lcounters[i] = counter_u64_alloc(M_WAITOK); for (int i = 0; i < FCNT_MAX; i++) - V_pf_status.fcounters[i] = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&V_pf_status.fcounters[i], M_WAITOK); for (int i = 0; i < SCNT_MAX; i++) V_pf_status.scounters[i] = counter_u64_alloc(M_WAITOK); @@ -3019,7 +3019,7 @@ DIOCGETSTATESV2_full: counter_u64_fetch(V_pf_status.lcounters[i]); for (int i = 0; i < FCNT_MAX; i++) s->fcounters[i] = - counter_u64_fetch(V_pf_status.fcounters[i]); + pf_counter_u64_fetch(&V_pf_status.fcounters[i]); for (int i = 0; i < SCNT_MAX; i++) s->scounters[i] = counter_u64_fetch(V_pf_status.scounters[i]); @@ -3051,7 +3051,7 @@ DIOCGETSTATESV2_full: for (int i = 0; i < PFRES_MAX; i++) counter_u64_zero(V_pf_status.counters[i]); for (int i = 0; i < FCNT_MAX; i++) - counter_u64_zero(V_pf_status.fcounters[i]); + pf_counter_u64_zero(&V_pf_status.fcounters[i]); for (int i = 0; i < SCNT_MAX; i++) counter_u64_zero(V_pf_status.scounters[i]); for (int i = 0; i < LCNT_MAX; i++) @@ -5616,7 +5616,7 @@ pf_unload_vnet(void) for (int i = 0; i < LCNT_MAX; i++) counter_u64_free(V_pf_status.lcounters[i]); for (int i = 0; i < FCNT_MAX; i++) - counter_u64_free(V_pf_status.fcounters[i]); + pf_counter_u64_deinit(&V_pf_status.fcounters[i]); for (int i = 0; i < SCNT_MAX; i++) counter_u64_free(V_pf_status.scounters[i]); } From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 13:25:21 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id AA74265387D; Wed, 11 Aug 2021 13:25: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Gl9YF3bmlz3CP6; Wed, 11 Aug 2021 13:25:21 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 5E5207DE9; Wed, 11 Aug 2021 13:25:21 +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 17BDPL30004929; Wed, 11 Aug 2021 13:25:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BDPLNt004928; Wed, 11 Aug 2021 13:25:21 GMT (envelope-from git) Date: Wed, 11 Aug 2021 13:25:21 GMT Message-Id: <202108111325.17BDPLNt004928@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 463aa33ff662 - stable/12 - pf: switch rule counters to pf_counter_u64 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 463aa33ff66280385dcc34d51233b14f33a69403 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 13:25:22 -0000 The branch stable/12 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=463aa33ff66280385dcc34d51233b14f33a69403 commit 463aa33ff66280385dcc34d51233b14f33a69403 Author: Mateusz Guzik AuthorDate: 2021-07-22 14:45:14 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 12:22:27 +0000 pf: switch rule counters to pf_counter_u64 Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 02cf67ccf6538b14677672640e405f7f94044dc3) --- sys/net/pfvar.h | 19 ++++++- sys/netpfil/pf/pf.c | 80 +++++++++++++++++++++------ sys/netpfil/pf/pf_ioctl.c | 137 +++++++++++++++++++++++++++++++--------------- sys/netpfil/pf/pf_lb.c | 2 +- sys/netpfil/pf/pf_norm.c | 18 +++--- sys/netpfil/pf/pf_nv.c | 8 +-- sys/netpfil/pf/pf_nv.h | 2 +- 7 files changed, 185 insertions(+), 81 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index e8cf8b1e6019..624456149162 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -583,9 +583,9 @@ struct pf_krule { TAILQ_ENTRY(pf_krule) entries; struct pf_kpool rpool; - counter_u64_t evaluations; - counter_u64_t packets[2]; - counter_u64_t bytes[2]; + struct pf_counter_u64 evaluations; + struct pf_counter_u64 packets[2]; + struct pf_counter_u64 bytes[2]; struct pfi_kkif *kif; struct pf_kanchor *anchor; @@ -659,6 +659,11 @@ struct pf_krule { struct pf_addr addr; u_int16_t port; } divert; + +#ifdef PF_WANT_32_TO_64_COUNTER + LIST_ENTRY(pf_krule) allrulelist; + bool allrulelinked; +#endif }; struct pf_ksrc_node { @@ -1859,6 +1864,14 @@ VNET_DECLARE(size_t, pf_allkifcount); #define V_pf_allkifcount VNET(pf_allkifcount) VNET_DECLARE(struct pfi_kkif *, pf_kifmarker); #define V_pf_kifmarker VNET(pf_kifmarker) + +LIST_HEAD(allrulelist_head, pf_krule); +VNET_DECLARE(struct allrulelist_head, pf_allrulelist); +#define V_pf_allrulelist VNET(pf_allrulelist) +VNET_DECLARE(size_t, pf_allrulecount); +#define V_pf_allrulecount VNET(pf_allrulecount) +VNET_DECLARE(struct pf_krule *, pf_rulemarker); +#define V_pf_rulemarker VNET(pf_rulemarker) #endif void pf_initialize(void); diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 3dcea7e59bd0..0c485189ec16 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -158,6 +158,10 @@ VNET_DEFINE_STATIC(uint32_t, pf_purge_idx); #ifdef PF_WANT_32_TO_64_COUNTER VNET_DEFINE_STATIC(uint32_t, pf_counter_periodic_iter); #define V_pf_counter_periodic_iter VNET(pf_counter_periodic_iter) + +VNET_DEFINE(struct allrulelist_head, pf_allrulelist); +VNET_DEFINE(size_t, pf_allrulecount); +VNET_DEFINE(struct pf_krule *, pf_rulemarker); #endif /* @@ -1570,6 +1574,45 @@ pf_kif_counter_u64_periodic(void) } } +static void +pf_rule_counter_u64_periodic(void) +{ + struct pf_krule *rule; + size_t r, run; + + PF_RULES_RASSERT(); + + if (__predict_false(V_pf_allrulecount == 0)) { + return; + } + + if ((V_pf_counter_periodic_iter % (pf_purge_thread_period * 10 * 300)) != 0) { + return; + } + + run = V_pf_allrulecount / 10; + if (run < 5) + run = 5; + + for (r = 0; r < run; r++) { + rule = LIST_NEXT(V_pf_rulemarker, allrulelist); + if (rule == NULL) { + LIST_REMOVE(V_pf_rulemarker, allrulelist); + LIST_INSERT_HEAD(&V_pf_allrulelist, V_pf_rulemarker, allrulelist); + break; + } + + LIST_REMOVE(V_pf_rulemarker, allrulelist); + LIST_INSERT_AFTER(rule, V_pf_rulemarker, allrulelist); + + pf_counter_u64_periodic(&rule->evaluations); + for (int i = 0; i < 2; i++) { + pf_counter_u64_periodic(&rule->packets[i]); + pf_counter_u64_periodic(&rule->bytes[i]); + } + } +} + static void pf_counter_u64_periodic_main(void) { @@ -1581,6 +1624,7 @@ pf_counter_u64_periodic_main(void) pf_counter_u64_critical_enter(); pf_status_counter_u64_periodic(); pf_kif_counter_u64_periodic(); + pf_rule_counter_u64_periodic(); pf_counter_u64_critical_exit(); PF_RULES_RUNLOCK(); } @@ -3643,7 +3687,7 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, int direction, } while (r != NULL) { - counter_u64_add(r->evaluations, 1); + pf_counter_u64_add(&r->evaluations, 1); if (pfi_kkif_match(r->kif, kif) == r->ifnot) r = r->skip[PF_SKIP_IFP].ptr; else if (r->direction && r->direction != direction) @@ -3712,8 +3756,8 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, int direction, rtableid = r->rtableid; if (r->anchor == NULL) { if (r->action == PF_MATCH) { - counter_u64_add(r->packets[direction == PF_OUT], 1); - counter_u64_add(r->bytes[direction == PF_OUT], pd->tot_len); + pf_counter_u64_add(&r->packets[direction == PF_OUT], 1); + pf_counter_u64_add(&r->bytes[direction == PF_OUT], pd->tot_len); pf_rule_to_actions(r, &pd->act); if (r->log) PFLOG_PACKET(kif, m, af, @@ -4085,7 +4129,7 @@ pf_test_fragment(struct pf_krule **rm, int direction, struct pfi_kkif *kif, r = TAILQ_FIRST(pf_main_ruleset.rules[PF_RULESET_FILTER].active.ptr); while (r != NULL) { - counter_u64_add(r->evaluations, 1); + pf_counter_u64_add(&r->evaluations, 1); if (pfi_kkif_match(r->kif, kif) == r->ifnot) r = r->skip[PF_SKIP_IFP].ptr; else if (r->direction && r->direction != direction) @@ -4126,8 +4170,8 @@ pf_test_fragment(struct pf_krule **rm, int direction, struct pfi_kkif *kif, else { if (r->anchor == NULL) { if (r->action == PF_MATCH) { - counter_u64_add(r->packets[direction == PF_OUT], 1); - counter_u64_add(r->bytes[direction == PF_OUT], pd->tot_len); + pf_counter_u64_add(&r->packets[direction == PF_OUT], 1); + pf_counter_u64_add(&r->bytes[direction == PF_OUT], pd->tot_len); pf_rule_to_actions(r, &pd->act); if (r->log) PFLOG_PACKET(kif, m, af, @@ -6518,17 +6562,17 @@ done: if (action == PF_PASS || r->action == PF_DROP) { dirndx = (dir == PF_OUT); - counter_u64_add(r->packets[dirndx], 1); - counter_u64_add(r->bytes[dirndx], pd.tot_len); + pf_counter_u64_add(&r->packets[dirndx], 1); + pf_counter_u64_add(&r->bytes[dirndx], pd.tot_len); if (a != NULL) { - counter_u64_add(a->packets[dirndx], 1); - counter_u64_add(a->bytes[dirndx], pd.tot_len); + pf_counter_u64_add(&a->packets[dirndx], 1); + pf_counter_u64_add(&a->bytes[dirndx], pd.tot_len); } if (s != NULL) { if (s->nat_rule.ptr != NULL) { - counter_u64_add(s->nat_rule.ptr->packets[dirndx], + pf_counter_u64_add(&s->nat_rule.ptr->packets[dirndx], 1); - counter_u64_add(s->nat_rule.ptr->bytes[dirndx], + pf_counter_u64_add(&s->nat_rule.ptr->bytes[dirndx], pd.tot_len); } if (s->src_node != NULL) { @@ -6926,17 +6970,17 @@ done: if (action == PF_PASS || r->action == PF_DROP) { dirndx = (dir == PF_OUT); - counter_u64_add(r->packets[dirndx], 1); - counter_u64_add(r->bytes[dirndx], pd.tot_len); + pf_counter_u64_add(&r->packets[dirndx], 1); + pf_counter_u64_add(&r->bytes[dirndx], pd.tot_len); if (a != NULL) { - counter_u64_add(a->packets[dirndx], 1); - counter_u64_add(a->bytes[dirndx], pd.tot_len); + pf_counter_u64_add(&a->packets[dirndx], 1); + pf_counter_u64_add(&a->bytes[dirndx], pd.tot_len); } if (s != NULL) { if (s->nat_rule.ptr != NULL) { - counter_u64_add(s->nat_rule.ptr->packets[dirndx], + pf_counter_u64_add(&s->nat_rule.ptr->packets[dirndx], 1); - counter_u64_add(s->nat_rule.ptr->bytes[dirndx], + pf_counter_u64_add(&s->nat_rule.ptr->bytes[dirndx], pd.tot_len); } if (s->src_node != NULL) { diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index e02fff4f88f6..81b50c237252 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -310,10 +310,10 @@ pfattach_vnet(void) V_pf_default_rule.nr = -1; V_pf_default_rule.rtableid = -1; - V_pf_default_rule.evaluations = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&V_pf_default_rule.evaluations, M_WAITOK); for (int i = 0; i < 2; i++) { - V_pf_default_rule.packets[i] = counter_u64_alloc(M_WAITOK); - V_pf_default_rule.bytes[i] = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&V_pf_default_rule.packets[i], M_WAITOK); + pf_counter_u64_init(&V_pf_default_rule.bytes[i], M_WAITOK); } V_pf_default_rule.states_cur = counter_u64_alloc(M_WAITOK); V_pf_default_rule.states_tot = counter_u64_alloc(M_WAITOK); @@ -321,8 +321,12 @@ pfattach_vnet(void) #ifdef PF_WANT_32_TO_64_COUNTER V_pf_kifmarker = malloc(sizeof(*V_pf_kifmarker), PFI_MTYPE, M_WAITOK | M_ZERO); + V_pf_rulemarker = malloc(sizeof(*V_pf_rulemarker), M_PFRULE, M_WAITOK | M_ZERO); PF_RULES_WLOCK(); LIST_INSERT_HEAD(&V_pf_allkiflist, V_pf_kifmarker, pfik_allkiflist); + LIST_INSERT_HEAD(&V_pf_allrulelist, &V_pf_default_rule, allrulelist); + V_pf_allrulecount++; + LIST_INSERT_HEAD(&V_pf_allrulelist, V_pf_rulemarker, allrulelist); PF_RULES_WUNLOCK(); #endif @@ -1116,16 +1120,16 @@ pf_commit_rules(u_int32_t ticket, int rs_num, char *anchor) while ((tail != NULL) && ! pf_krule_compare(tail, rule)) tail = TAILQ_NEXT(tail, entries); if (tail != NULL) { - counter_u64_add(rule->evaluations, - counter_u64_fetch(tail->evaluations)); - counter_u64_add(rule->packets[0], - counter_u64_fetch(tail->packets[0])); - counter_u64_add(rule->packets[1], - counter_u64_fetch(tail->packets[1])); - counter_u64_add(rule->bytes[0], - counter_u64_fetch(tail->bytes[0])); - counter_u64_add(rule->bytes[1], - counter_u64_fetch(tail->bytes[1])); + pf_counter_u64_add(&rule->evaluations, + pf_counter_u64_fetch(&tail->evaluations)); + pf_counter_u64_add(&rule->packets[0], + pf_counter_u64_fetch(&tail->packets[0])); + pf_counter_u64_add(&rule->packets[1], + pf_counter_u64_fetch(&tail->packets[1])); + pf_counter_u64_add(&rule->bytes[0], + pf_counter_u64_fetch(&tail->bytes[0])); + pf_counter_u64_add(&rule->bytes[1], + pf_counter_u64_fetch(&tail->bytes[1])); } } } @@ -1506,13 +1510,29 @@ pf_altq_get_nth_active(u_int32_t n) void pf_krule_free(struct pf_krule *rule) { +#ifdef PF_WANT_32_TO_64_COUNTER + bool wowned; +#endif + if (rule == NULL) return; - counter_u64_free(rule->evaluations); +#ifdef PF_WANT_32_TO_64_COUNTER + if (rule->allrulelinked) { + wowned = PF_RULES_WOWNED(); + if (!wowned) + PF_RULES_WLOCK(); + LIST_REMOVE(rule, allrulelist); + V_pf_allrulecount--; + if (!wowned) + PF_RULES_WUNLOCK(); + } +#endif + + pf_counter_u64_deinit(&rule->evaluations); for (int i = 0; i < 2; i++) { - counter_u64_free(rule->packets[i]); - counter_u64_free(rule->bytes[i]); + pf_counter_u64_deinit(&rule->packets[i]); + pf_counter_u64_deinit(&rule->bytes[i]); } counter_u64_free(rule->states_cur); counter_u64_free(rule->states_tot); @@ -1574,7 +1594,7 @@ pf_pool_to_kpool(const struct pf_pool *pool, struct pf_kpool *kpool) } static void -pf_krule_to_rule(const struct pf_krule *krule, struct pf_rule *rule) +pf_krule_to_rule(struct pf_krule *krule, struct pf_rule *rule) { bzero(rule, sizeof(*rule)); @@ -1601,10 +1621,10 @@ pf_krule_to_rule(const struct pf_krule *krule, struct pf_rule *rule) pf_kpool_to_pool(&krule->rpool, &rule->rpool); - rule->evaluations = counter_u64_fetch(krule->evaluations); + rule->evaluations = pf_counter_u64_fetch(&krule->evaluations); for (int i = 0; i < 2; i++) { - rule->packets[i] = counter_u64_fetch(krule->packets[i]); - rule->bytes[i] = counter_u64_fetch(krule->bytes[i]); + rule->packets[i] = pf_counter_u64_fetch(&krule->packets[i]); + rule->bytes[i] = pf_counter_u64_fetch(&krule->bytes[i]); } /* kif, anchor, overload_tbl are not copied over. */ @@ -1958,10 +1978,10 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket, if (rule->ifname[0]) kif = pf_kkif_create(M_WAITOK); - rule->evaluations = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&rule->evaluations, M_WAITOK); for (int i = 0; i < 2; i++) { - rule->packets[i] = counter_u64_alloc(M_WAITOK); - rule->bytes[i] = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&rule->packets[i], M_WAITOK); + pf_counter_u64_init(&rule->bytes[i], M_WAITOK); } rule->states_cur = counter_u64_alloc(M_WAITOK); rule->states_tot = counter_u64_alloc(M_WAITOK); @@ -1971,6 +1991,12 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket, TAILQ_INIT(&rule->rpool.list); PF_RULES_WLOCK(); +#ifdef PF_WANT_32_TO_64_COUNTER + LIST_INSERT_HEAD(&V_pf_allrulelist, rule, allrulelist); + MPASS(!rule->allrulelinked); + rule->allrulelinked = true; + V_pf_allrulecount++; +#endif ruleset = pf_find_kruleset(anchor); if (ruleset == NULL) ERROUT(EINVAL); @@ -2074,10 +2100,10 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket, } rule->rpool.cur = TAILQ_FIRST(&rule->rpool.list); - counter_u64_zero(rule->evaluations); + pf_counter_u64_zero(&rule->evaluations); for (int i = 0; i < 2; i++) { - counter_u64_zero(rule->packets[i]); - counter_u64_zero(rule->bytes[i]); + pf_counter_u64_zero(&rule->packets[i]); + pf_counter_u64_zero(&rule->bytes[i]); } TAILQ_INSERT_TAIL(ruleset->rules[rs_num].inactive.ptr, rule, entries); @@ -2428,10 +2454,10 @@ DIOCADDRULENV_error: pf_addr_copyout(&pr->rule.dst.addr); if (pr->action == PF_GET_CLR_CNTR) { - counter_u64_zero(rule->evaluations); + pf_counter_u64_zero(&rule->evaluations); for (int i = 0; i < 2; i++) { - counter_u64_zero(rule->packets[i]); - counter_u64_zero(rule->bytes[i]); + pf_counter_u64_zero(&rule->packets[i]); + pf_counter_u64_zero(&rule->bytes[i]); } counter_u64_zero(rule->states_tot); } @@ -2550,10 +2576,10 @@ DIOCADDRULENV_error: } if (clear_counter) { - counter_u64_zero(rule->evaluations); + pf_counter_u64_zero(&rule->evaluations); for (int i = 0; i < 2; i++) { - counter_u64_zero(rule->packets[i]); - counter_u64_zero(rule->bytes[i]); + pf_counter_u64_zero(&rule->packets[i]); + pf_counter_u64_zero(&rule->bytes[i]); } counter_u64_zero(rule->states_tot); } @@ -2599,12 +2625,10 @@ DIOCGETRULENV_error: if (newrule->ifname[0]) kif = pf_kkif_create(M_WAITOK); - newrule->evaluations = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&newrule->evaluations, M_WAITOK); for (int i = 0; i < 2; i++) { - newrule->packets[i] = - counter_u64_alloc(M_WAITOK); - newrule->bytes[i] = - counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&newrule->packets[i], M_WAITOK); + pf_counter_u64_init(&newrule->bytes[i], M_WAITOK); } newrule->states_cur = counter_u64_alloc(M_WAITOK); newrule->states_tot = counter_u64_alloc(M_WAITOK); @@ -2617,6 +2641,14 @@ DIOCGETRULENV_error: #define ERROUT(x) { error = (x); goto DIOCCHANGERULE_error; } PF_RULES_WLOCK(); +#ifdef PF_WANT_32_TO_64_COUNTER + if (newrule != NULL) { + LIST_INSERT_HEAD(&V_pf_allrulelist, newrule, allrulelist); + newrule->allrulelinked = true; + V_pf_allrulecount++; + } +#endif + if (!(pcr->action == PF_CHANGE_REMOVE || pcr->action == PF_CHANGE_GET_TICKET) && pcr->pool_ticket != V_ticket_pabuf) @@ -3198,10 +3230,10 @@ DIOCGETSTATESV2_full: PF_RULES_WLOCK(); TAILQ_FOREACH(rule, ruleset->rules[PF_RULESET_FILTER].active.ptr, entries) { - counter_u64_zero(rule->evaluations); + pf_counter_u64_zero(&rule->evaluations); for (int i = 0; i < 2; i++) { - counter_u64_zero(rule->packets[i]); - counter_u64_zero(rule->bytes[i]); + pf_counter_u64_zero(&rule->packets[i]); + pf_counter_u64_zero(&rule->bytes[i]); } } PF_RULES_WUNLOCK(); @@ -5611,18 +5643,33 @@ pf_unload_vnet(void) #ifdef PF_WANT_32_TO_64_COUNTER PF_RULES_WLOCK(); LIST_REMOVE(V_pf_kifmarker, pfik_allkiflist); - PF_RULES_WUNLOCK(); - free(V_pf_kifmarker, PFI_MTYPE); MPASS(LIST_EMPTY(&V_pf_allkiflist)); MPASS(V_pf_allkifcount == 0); + + LIST_REMOVE(&V_pf_default_rule, allrulelist); + V_pf_allrulecount--; + LIST_REMOVE(V_pf_rulemarker, allrulelist); + + /* + * There are known pf rule leaks when running the test suite. + */ +#ifdef notyet + MPASS(LIST_EMPTY(&V_pf_allrulelist)); + MPASS(V_pf_allrulecount == 0); +#endif + + PF_RULES_WUNLOCK(); + + free(V_pf_kifmarker, PFI_MTYPE); + free(V_pf_rulemarker, M_PFRULE); #endif /* Free counters last as we updated them during shutdown. */ - counter_u64_free(V_pf_default_rule.evaluations); + pf_counter_u64_deinit(&V_pf_default_rule.evaluations); for (int i = 0; i < 2; i++) { - counter_u64_free(V_pf_default_rule.packets[i]); - counter_u64_free(V_pf_default_rule.bytes[i]); + pf_counter_u64_deinit(&V_pf_default_rule.packets[i]); + pf_counter_u64_deinit(&V_pf_default_rule.bytes[i]); } counter_u64_free(V_pf_default_rule.states_cur); counter_u64_free(V_pf_default_rule.states_tot); diff --git a/sys/netpfil/pf/pf_lb.c b/sys/netpfil/pf/pf_lb.c index b7079c47308a..24ff907cdc61 100644 --- a/sys/netpfil/pf/pf_lb.c +++ b/sys/netpfil/pf/pf_lb.c @@ -149,7 +149,7 @@ pf_match_translation(struct pf_pdesc *pd, struct mbuf *m, int off, dst = &r->dst; } - counter_u64_add(r->evaluations, 1); + pf_counter_u64_add(&r->evaluations, 1); if (pfi_kkif_match(r->kif, kif) == r->ifnot) r = r->skip[PF_SKIP_IFP].ptr; else if (r->direction && r->direction != direction) diff --git a/sys/netpfil/pf/pf_norm.c b/sys/netpfil/pf/pf_norm.c index 8ffa690ac36f..19d3a268e4f8 100644 --- a/sys/netpfil/pf/pf_norm.c +++ b/sys/netpfil/pf/pf_norm.c @@ -1035,7 +1035,7 @@ pf_normalize_ip(struct mbuf **m0, int dir, struct pfi_kkif *kif, u_short *reason r = TAILQ_FIRST(pf_main_ruleset.rules[PF_RULESET_SCRUB].active.ptr); while (r != NULL) { - counter_u64_add(r->evaluations, 1); + pf_counter_u64_add(&r->evaluations, 1); if (pfi_kkif_match(r->kif, kif) == r->ifnot) r = r->skip[PF_SKIP_IFP].ptr; else if (r->direction && r->direction != dir) @@ -1062,8 +1062,8 @@ pf_normalize_ip(struct mbuf **m0, int dir, struct pfi_kkif *kif, u_short *reason if (r == NULL || r->action == PF_NOSCRUB) return (PF_PASS); - counter_u64_add(r->packets[dir == PF_OUT], 1); - counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_add(&r->packets[dir == PF_OUT], 1); + pf_counter_u64_add(&r->bytes[dir == PF_OUT], pd->tot_len); /* Check for illegal packets */ if (hlen < (int)sizeof(struct ip)) { @@ -1178,7 +1178,7 @@ pf_normalize_ip6(struct mbuf **m0, int dir, struct pfi_kkif *kif, r = TAILQ_FIRST(pf_main_ruleset.rules[PF_RULESET_SCRUB].active.ptr); while (r != NULL) { - counter_u64_add(r->evaluations, 1); + pf_counter_u64_add(&r->evaluations, 1); if (pfi_kkif_match(r->kif, kif) == r->ifnot) r = r->skip[PF_SKIP_IFP].ptr; else if (r->direction && r->direction != dir) @@ -1204,8 +1204,8 @@ pf_normalize_ip6(struct mbuf **m0, int dir, struct pfi_kkif *kif, if (r == NULL || r->action == PF_NOSCRUB) return (PF_PASS); - counter_u64_add(r->packets[dir == PF_OUT], 1); - counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_add(&r->packets[dir == PF_OUT], 1); + pf_counter_u64_add(&r->bytes[dir == PF_OUT], pd->tot_len); /* Check for illegal packets */ if (sizeof(struct ip6_hdr) + IPV6_MAXPACKET < m->m_pkthdr.len) @@ -1355,7 +1355,7 @@ pf_normalize_tcp(int dir, struct pfi_kkif *kif, struct mbuf *m, int ipoff, r = TAILQ_FIRST(pf_main_ruleset.rules[PF_RULESET_SCRUB].active.ptr); while (r != NULL) { - counter_u64_add(r->evaluations, 1); + pf_counter_u64_add(&r->evaluations, 1); if (pfi_kkif_match(r->kif, kif) == r->ifnot) r = r->skip[PF_SKIP_IFP].ptr; else if (r->direction && r->direction != dir) @@ -1389,8 +1389,8 @@ pf_normalize_tcp(int dir, struct pfi_kkif *kif, struct mbuf *m, int ipoff, if (rm == NULL || rm->action == PF_NOSCRUB) return (PF_PASS); - counter_u64_add(r->packets[dir == PF_OUT], 1); - counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_add(&r->packets[dir == PF_OUT], 1); + pf_counter_u64_add(&r->bytes[dir == PF_OUT], pd->tot_len); if (rm->rule_flag & PFRULE_REASSEMBLE_TCP) pd->flags |= PFDESC_TCP_NORM; diff --git a/sys/netpfil/pf/pf_nv.c b/sys/netpfil/pf/pf_nv.c index c0a17cd876ae..d1eca90e0ee5 100644 --- a/sys/netpfil/pf/pf_nv.c +++ b/sys/netpfil/pf/pf_nv.c @@ -655,7 +655,7 @@ error: } nvlist_t * -pf_krule_to_nvrule(const struct pf_krule *rule) +pf_krule_to_nvrule(struct pf_krule *rule) { nvlist_t *nvl, *tmp; @@ -698,12 +698,12 @@ pf_krule_to_nvrule(const struct pf_krule *rule) nvlist_destroy(tmp); nvlist_add_number(nvl, "evaluations", - counter_u64_fetch(rule->evaluations)); + pf_counter_u64_fetch(&rule->evaluations)); for (int i = 0; i < 2; i++) { nvlist_append_number_array(nvl, "packets", - counter_u64_fetch(rule->packets[i])); + pf_counter_u64_fetch(&rule->packets[i])); nvlist_append_number_array(nvl, "bytes", - counter_u64_fetch(rule->bytes[i])); + pf_counter_u64_fetch(&rule->bytes[i])); } nvlist_add_number(nvl, "os_fingerprint", rule->os_fingerprint); diff --git a/sys/netpfil/pf/pf_nv.h b/sys/netpfil/pf/pf_nv.h index 2abb5a2401e2..f1cdc52aad6b 100644 --- a/sys/netpfil/pf/pf_nv.h +++ b/sys/netpfil/pf/pf_nv.h @@ -78,7 +78,7 @@ int pf_nvstring(const nvlist_t *, const char *, char *, size_t); int pf_check_rule_addr(const struct pf_rule_addr *); -nvlist_t *pf_krule_to_nvrule(const struct pf_krule *); +nvlist_t *pf_krule_to_nvrule(struct pf_krule *); int pf_nvrule_to_krule(const nvlist_t *, struct pf_krule *); int pf_nvstate_kill_to_kstate_kill(const nvlist_t *, struct pf_kstate_kill *); From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 13:25:22 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EB626653666; Wed, 11 Aug 2021 13:25:22 +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 4Gl9YG451Sz3CjB; Wed, 11 Aug 2021 13:25:22 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 72D6310138; Wed, 11 Aug 2021 13:25:22 +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 17BDPMaJ004953; Wed, 11 Aug 2021 13:25:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BDPMqY004952; Wed, 11 Aug 2021 13:25:22 GMT (envelope-from git) Date: Wed, 11 Aug 2021 13:25:22 GMT Message-Id: <202108111325.17BDPMqY004952@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 2522a90dcd41 - stable/12 - pf: batch critical section for several counters MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 2522a90dcd41c9c8326525fa23876bb2acc7d51a Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 13:25:23 -0000 The branch stable/12 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=2522a90dcd41c9c8326525fa23876bb2acc7d51a commit 2522a90dcd41c9c8326525fa23876bb2acc7d51a Author: Mateusz Guzik AuthorDate: 2021-07-24 07:47:40 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 12:23:20 +0000 pf: batch critical section for several counters Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 87c010e6e364e96e2c1546b3c2bbcbef1dcd422f) --- sys/netpfil/pf/pf.c | 48 +++++++++++++++++++++++++++-------------------- sys/netpfil/pf/pf_ioctl.c | 12 +++++++----- sys/netpfil/pf/pf_norm.c | 18 ++++++++++++------ 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 0c485189ec16..f1b1890f50c5 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -3756,8 +3756,10 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, int direction, rtableid = r->rtableid; if (r->anchor == NULL) { if (r->action == PF_MATCH) { - pf_counter_u64_add(&r->packets[direction == PF_OUT], 1); - pf_counter_u64_add(&r->bytes[direction == PF_OUT], pd->tot_len); + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&r->packets[direction == PF_OUT], 1); + pf_counter_u64_add_protected(&r->bytes[direction == PF_OUT], pd->tot_len); + pf_counter_u64_critical_exit(); pf_rule_to_actions(r, &pd->act); if (r->log) PFLOG_PACKET(kif, m, af, @@ -4170,8 +4172,10 @@ pf_test_fragment(struct pf_krule **rm, int direction, struct pfi_kkif *kif, else { if (r->anchor == NULL) { if (r->action == PF_MATCH) { - pf_counter_u64_add(&r->packets[direction == PF_OUT], 1); - pf_counter_u64_add(&r->bytes[direction == PF_OUT], pd->tot_len); + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&r->packets[direction == PF_OUT], 1); + pf_counter_u64_add_protected(&r->bytes[direction == PF_OUT], pd->tot_len); + pf_counter_u64_critical_exit(); pf_rule_to_actions(r, &pd->act); if (r->log) PFLOG_PACKET(kif, m, af, @@ -6555,24 +6559,25 @@ done: (s == NULL)); } - pf_counter_u64_add(&kif->pfik_bytes[0][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&kif->pfik_bytes[0][dir == PF_OUT][action != PF_PASS], pd.tot_len); - pf_counter_u64_add(&kif->pfik_packets[0][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_add_protected(&kif->pfik_packets[0][dir == PF_OUT][action != PF_PASS], 1); if (action == PF_PASS || r->action == PF_DROP) { dirndx = (dir == PF_OUT); - pf_counter_u64_add(&r->packets[dirndx], 1); - pf_counter_u64_add(&r->bytes[dirndx], pd.tot_len); + pf_counter_u64_add_protected(&r->packets[dirndx], 1); + pf_counter_u64_add_protected(&r->bytes[dirndx], pd.tot_len); if (a != NULL) { - pf_counter_u64_add(&a->packets[dirndx], 1); - pf_counter_u64_add(&a->bytes[dirndx], pd.tot_len); + pf_counter_u64_add_protected(&a->packets[dirndx], 1); + pf_counter_u64_add_protected(&a->bytes[dirndx], pd.tot_len); } if (s != NULL) { if (s->nat_rule.ptr != NULL) { - pf_counter_u64_add(&s->nat_rule.ptr->packets[dirndx], + pf_counter_u64_add_protected(&s->nat_rule.ptr->packets[dirndx], 1); - pf_counter_u64_add(&s->nat_rule.ptr->bytes[dirndx], + pf_counter_u64_add_protected(&s->nat_rule.ptr->bytes[dirndx], pd.tot_len); } if (s->src_node != NULL) { @@ -6610,6 +6615,7 @@ done: pd.af, pd.tot_len, dir == PF_OUT, r->action == PF_PASS, tr->dst.neg); } + pf_counter_u64_critical_exit(); switch (action) { case PF_SYNPROXY_DROP: @@ -6963,24 +6969,25 @@ done: &pd, (s == NULL)); } - pf_counter_u64_add(&kif->pfik_bytes[1][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&kif->pfik_bytes[1][dir == PF_OUT][action != PF_PASS], pd.tot_len); - pf_counter_u64_add(&kif->pfik_packets[1][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_add_protected(&kif->pfik_packets[1][dir == PF_OUT][action != PF_PASS], 1); if (action == PF_PASS || r->action == PF_DROP) { dirndx = (dir == PF_OUT); - pf_counter_u64_add(&r->packets[dirndx], 1); - pf_counter_u64_add(&r->bytes[dirndx], pd.tot_len); + pf_counter_u64_add_protected(&r->packets[dirndx], 1); + pf_counter_u64_add_protected(&r->bytes[dirndx], pd.tot_len); if (a != NULL) { - pf_counter_u64_add(&a->packets[dirndx], 1); - pf_counter_u64_add(&a->bytes[dirndx], pd.tot_len); + pf_counter_u64_add_protected(&a->packets[dirndx], 1); + pf_counter_u64_add_protected(&a->bytes[dirndx], pd.tot_len); } if (s != NULL) { if (s->nat_rule.ptr != NULL) { - pf_counter_u64_add(&s->nat_rule.ptr->packets[dirndx], + pf_counter_u64_add_protected(&s->nat_rule.ptr->packets[dirndx], 1); - pf_counter_u64_add(&s->nat_rule.ptr->bytes[dirndx], + pf_counter_u64_add_protected(&s->nat_rule.ptr->bytes[dirndx], pd.tot_len); } if (s->src_node != NULL) { @@ -7016,6 +7023,7 @@ done: pd.af, pd.tot_len, dir == PF_OUT, r->action == PF_PASS, tr->dst.neg); } + pf_counter_u64_critical_exit(); switch (action) { case PF_SYNPROXY_DROP: diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 81b50c237252..4f1786b36a30 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -1120,16 +1120,18 @@ pf_commit_rules(u_int32_t ticket, int rs_num, char *anchor) while ((tail != NULL) && ! pf_krule_compare(tail, rule)) tail = TAILQ_NEXT(tail, entries); if (tail != NULL) { - pf_counter_u64_add(&rule->evaluations, + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&rule->evaluations, pf_counter_u64_fetch(&tail->evaluations)); - pf_counter_u64_add(&rule->packets[0], + pf_counter_u64_add_protected(&rule->packets[0], pf_counter_u64_fetch(&tail->packets[0])); - pf_counter_u64_add(&rule->packets[1], + pf_counter_u64_add_protected(&rule->packets[1], pf_counter_u64_fetch(&tail->packets[1])); - pf_counter_u64_add(&rule->bytes[0], + pf_counter_u64_add_protected(&rule->bytes[0], pf_counter_u64_fetch(&tail->bytes[0])); - pf_counter_u64_add(&rule->bytes[1], + pf_counter_u64_add_protected(&rule->bytes[1], pf_counter_u64_fetch(&tail->bytes[1])); + pf_counter_u64_critical_exit(); } } } diff --git a/sys/netpfil/pf/pf_norm.c b/sys/netpfil/pf/pf_norm.c index 19d3a268e4f8..40e4b1bae2f9 100644 --- a/sys/netpfil/pf/pf_norm.c +++ b/sys/netpfil/pf/pf_norm.c @@ -1062,8 +1062,10 @@ pf_normalize_ip(struct mbuf **m0, int dir, struct pfi_kkif *kif, u_short *reason if (r == NULL || r->action == PF_NOSCRUB) return (PF_PASS); - pf_counter_u64_add(&r->packets[dir == PF_OUT], 1); - pf_counter_u64_add(&r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&r->packets[dir == PF_OUT], 1); + pf_counter_u64_add_protected(&r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_critical_exit(); /* Check for illegal packets */ if (hlen < (int)sizeof(struct ip)) { @@ -1204,8 +1206,10 @@ pf_normalize_ip6(struct mbuf **m0, int dir, struct pfi_kkif *kif, if (r == NULL || r->action == PF_NOSCRUB) return (PF_PASS); - pf_counter_u64_add(&r->packets[dir == PF_OUT], 1); - pf_counter_u64_add(&r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&r->packets[dir == PF_OUT], 1); + pf_counter_u64_add_protected(&r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_critical_exit(); /* Check for illegal packets */ if (sizeof(struct ip6_hdr) + IPV6_MAXPACKET < m->m_pkthdr.len) @@ -1389,8 +1393,10 @@ pf_normalize_tcp(int dir, struct pfi_kkif *kif, struct mbuf *m, int ipoff, if (rm == NULL || rm->action == PF_NOSCRUB) return (PF_PASS); - pf_counter_u64_add(&r->packets[dir == PF_OUT], 1); - pf_counter_u64_add(&r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&r->packets[dir == PF_OUT], 1); + pf_counter_u64_add_protected(&r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_critical_exit(); if (rm->rule_flag & PFRULE_REASSEMBLE_TCP) pd->flags |= PFDESC_TCP_NORM; From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 15:22:40 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 65EC76556DD; Wed, 11 Aug 2021 15:22:40 +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 4GlD8c2Ld5z3LDm; Wed, 11 Aug 2021 15:22:40 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 38A4211569; Wed, 11 Aug 2021 15:22:40 +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 17BFMeZC064219; Wed, 11 Aug 2021 15:22:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BFMeBl064218; Wed, 11 Aug 2021 15:22:40 GMT (envelope-from git) Date: Wed, 11 Aug 2021 15:22:40 GMT Message-Id: <202108111522.17BFMeBl064218@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 53551e9976b9 - stable/13 - pf: hide struct pf_kstatus behind ifdef _KERNEL MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 53551e9976b9bfcff71ca820aefc22d7a668214e Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 15:22:40 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=53551e9976b9bfcff71ca820aefc22d7a668214e commit 53551e9976b9bfcff71ca820aefc22d7a668214e Author: Mateusz Guzik AuthorDate: 2021-07-23 17:34:43 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 13:37:51 +0000 pf: hide struct pf_kstatus behind ifdef _KERNEL Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit d9cc6ea270ea52e860e3cc730876ee4324081586) --- sys/net/pfvar.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index e037947a5375..55ecbecf657a 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1146,6 +1146,7 @@ enum pf_syncookies_mode { PF_SYNCOOKIES_MODE_MAX = PF_SYNCOOKIES_ALWAYS }; +#ifdef _KERNEL struct pf_kstatus { counter_u64_t counters[PFRES_MAX]; /* reason for passing/dropping */ counter_u64_t lcounters[LCNT_MAX]; /* limit counters */ @@ -1163,6 +1164,7 @@ struct pf_kstatus { enum pf_syncookies_mode syncookies_mode; bool syncookies_active; }; +#endif struct pf_divert { union { From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 15:22:42 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A56B16556EF; Wed, 11 Aug 2021 15:22:42 +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 4GlD8f4JDnz3Lcp; Wed, 11 Aug 2021 15:22:42 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 7CE2111D3D; Wed, 11 Aug 2021 15:22:42 +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 17BFMge9064267; Wed, 11 Aug 2021 15:22:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BFMggV064266; Wed, 11 Aug 2021 15:22:42 GMT (envelope-from git) Date: Wed, 11 Aug 2021 15:22:42 GMT Message-Id: <202108111522.17BFMggV064266@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 5640fea1e373 - stable/13 - pf: drop redundant 'else' in pf_normalize_* MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5640fea1e37323133cc8447e050ec44012389883 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 15:22:42 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=5640fea1e37323133cc8447e050ec44012389883 commit 5640fea1e37323133cc8447e050ec44012389883 Author: Mateusz Guzik AuthorDate: 2021-07-24 05:17:27 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 13:37:53 +0000 pf: drop redundant 'else' in pf_normalize_* Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 6f1fb6561236fa933835a9a67bd442053fb509e9) --- sys/netpfil/pf/pf_norm.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/sys/netpfil/pf/pf_norm.c b/sys/netpfil/pf/pf_norm.c index 561181eb1b56..3df4e06f15b6 100644 --- a/sys/netpfil/pf/pf_norm.c +++ b/sys/netpfil/pf/pf_norm.c @@ -1065,10 +1065,9 @@ pf_normalize_ip(struct mbuf **m0, int dir, struct pfi_kkif *kif, u_short *reason if (r == NULL || r->action == PF_NOSCRUB) return (PF_PASS); - else { - counter_u64_add(r->packets[dir == PF_OUT], 1); - counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); - } + + counter_u64_add(r->packets[dir == PF_OUT], 1); + counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); /* Check for illegal packets */ if (hlen < (int)sizeof(struct ip)) { @@ -1207,10 +1206,9 @@ pf_normalize_ip6(struct mbuf **m0, int dir, struct pfi_kkif *kif, if (r == NULL || r->action == PF_NOSCRUB) return (PF_PASS); - else { - counter_u64_add(r->packets[dir == PF_OUT], 1); - counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); - } + + counter_u64_add(r->packets[dir == PF_OUT], 1); + counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); /* Check for illegal packets */ if (sizeof(struct ip6_hdr) + IPV6_MAXPACKET < m->m_pkthdr.len) @@ -1369,10 +1367,9 @@ pf_normalize_tcp(int dir, struct pfi_kkif *kif, struct mbuf *m, int ipoff, if (rm == NULL || rm->action == PF_NOSCRUB) return (PF_PASS); - else { - counter_u64_add(r->packets[dir == PF_OUT], 1); - counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); - } + + counter_u64_add(r->packets[dir == PF_OUT], 1); + counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); if (rm->rule_flag & PFRULE_REASSEMBLE_TCP) pd->flags |= PFDESC_TCP_NORM; From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 15:22:44 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 215B8656065; Wed, 11 Aug 2021 15:22:44 +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 4GlD8g5ddZz3LMg; Wed, 11 Aug 2021 15:22:43 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 A1DEC11A5F; Wed, 11 Aug 2021 15:22:43 +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 17BFMhl3064298; Wed, 11 Aug 2021 15:22:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BFMhuj064297; Wed, 11 Aug 2021 15:22:43 GMT (envelope-from git) Date: Wed, 11 Aug 2021 15:22:43 GMT Message-Id: <202108111522.17BFMhuj064297@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: fff80a6992f1 - stable/13 - pf: add hybrid 32- an 64- bit counters MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: fff80a6992f1ba13f2261b066d70a3a97d8837e4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 15:22:44 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=fff80a6992f1ba13f2261b066d70a3a97d8837e4 commit fff80a6992f1ba13f2261b066d70a3a97d8837e4 Author: Mateusz Guzik AuthorDate: 2021-07-22 20:47:24 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 13:37:53 +0000 pf: add hybrid 32- an 64- bit counters Numerous counters got migrated from straight uint64_t to the counter(9) API. Unfortunately the implementation comes with a significiant performance hit on some platforms and cannot be easily fixed. Work around the problem by implementing a pf-specific variant. Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit defdcdd5648dc1ea789bc54bb45108fcab546a6b) --- sys/net/pfvar.h | 218 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sys/netpfil/pf/pf.c | 28 ++++++- 2 files changed, 245 insertions(+), 1 deletion(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 55ecbecf657a..e381279a113f 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -43,9 +43,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -64,6 +66,222 @@ #ifdef _KERNEL +#if defined(__arm__) +#define PF_WANT_32_TO_64_COUNTER +#endif + +/* + * A hybrid of 32-bit and 64-bit counters which can be used on platforms where + * counter(9) is very expensive. + * + * As 32-bit counters are expected to overflow, a periodic job sums them up to + * a saved 64-bit state. Fetching the value still walks all CPUs to get the most + * current snapshot. + */ +#ifdef PF_WANT_32_TO_64_COUNTER +struct pf_counter_u64_pcpu { + u_int32_t current; + u_int32_t snapshot; +}; + +struct pf_counter_u64 { + struct pf_counter_u64_pcpu *pfcu64_pcpu; + u_int64_t pfcu64_value; + seqc_t pfcu64_seqc; +}; + +static inline int +pf_counter_u64_init(struct pf_counter_u64 *pfcu64, int flags) +{ + + pfcu64->pfcu64_value = 0; + pfcu64->pfcu64_seqc = 0; + pfcu64->pfcu64_pcpu = uma_zalloc_pcpu(pcpu_zone_8, flags | M_ZERO); + if (__predict_false(pfcu64->pfcu64_pcpu == NULL)) + return (ENOMEM); + return (0); +} + +static inline void +pf_counter_u64_deinit(struct pf_counter_u64 *pfcu64) +{ + + uma_zfree_pcpu(pcpu_zone_8, pfcu64->pfcu64_pcpu); +} + +static inline void +pf_counter_u64_critical_enter(void) +{ + + critical_enter(); +} + +static inline void +pf_counter_u64_critical_exit(void) +{ + + critical_exit(); +} + +static inline void +pf_counter_u64_add_protected(struct pf_counter_u64 *pfcu64, uint32_t n) +{ + struct pf_counter_u64_pcpu *pcpu; + u_int32_t val; + + MPASS(curthread->td_critnest > 0); + pcpu = zpcpu_get(pfcu64->pfcu64_pcpu); + val = atomic_load_int(&pcpu->current); + atomic_store_int(&pcpu->current, val + n); +} + +static inline void +pf_counter_u64_add(struct pf_counter_u64 *pfcu64, uint32_t n) +{ + + critical_enter(); + pf_counter_u64_add_protected(pfcu64, n); + critical_exit(); +} + +static inline u_int64_t +pf_counter_u64_periodic(struct pf_counter_u64 *pfcu64) +{ + struct pf_counter_u64_pcpu *pcpu; + u_int64_t sum; + u_int32_t val; + int cpu; + + MPASS(curthread->td_critnest > 0); + seqc_write_begin(&pfcu64->pfcu64_seqc); + sum = pfcu64->pfcu64_value; + CPU_FOREACH(cpu) { + pcpu = zpcpu_get_cpu(pfcu64->pfcu64_pcpu, cpu); + val = atomic_load_int(&pcpu->current); + sum += (uint32_t)(val - pcpu->snapshot); + pcpu->snapshot = val; + } + pfcu64->pfcu64_value = sum; + seqc_write_end(&pfcu64->pfcu64_seqc); + return (sum); +} + +static inline u_int64_t +pf_counter_u64_fetch(struct pf_counter_u64 *pfcu64) +{ + struct pf_counter_u64_pcpu *pcpu; + u_int64_t sum; + seqc_t seqc; + int cpu; + + for (;;) { + seqc = seqc_read(&pfcu64->pfcu64_seqc); + sum = 0; + CPU_FOREACH(cpu) { + pcpu = zpcpu_get_cpu(pfcu64->pfcu64_pcpu, cpu); + sum += (uint32_t)(atomic_load_int(&pcpu->current) -pcpu->snapshot); + } + sum += pfcu64->pfcu64_value; + if (seqc_consistent(&pfcu64->pfcu64_seqc, seqc)) + break; + } + return (sum); +} + +static inline void +pf_counter_u64_zero_protected(struct pf_counter_u64 *pfcu64) +{ + struct pf_counter_u64_pcpu *pcpu; + int cpu; + + MPASS(curthread->td_critnest > 0); + seqc_write_begin(&pfcu64->pfcu64_seqc); + CPU_FOREACH(cpu) { + pcpu = zpcpu_get_cpu(pfcu64->pfcu64_pcpu, cpu); + pcpu->snapshot = atomic_load_int(&pcpu->current); + } + pfcu64->pfcu64_value = 0; + seqc_write_end(&pfcu64->pfcu64_seqc); +} + +static inline void +pf_counter_u64_zero(struct pf_counter_u64 *pfcu64) +{ + + critical_enter(); + pf_counter_u64_zero_protected(pfcu64); + critical_exit(); +} +#else +struct pf_counter_u64 { + counter_u64_t counter; +}; + +static inline int +pf_counter_u64_init(struct pf_counter_u64 *pfcu64, int flags) +{ + + pfcu64->counter = counter_u64_alloc(flags); + if (__predict_false(pfcu64->counter == NULL)) + return (ENOMEM); + return (0); +} + +static inline void +pf_counter_u64_deinit(struct pf_counter_u64 *pfcu64) +{ + + counter_u64_free(pfcu64->counter); +} + +static inline void +pf_counter_u64_critical_enter(void) +{ + +} + +static inline void +pf_counter_u64_critical_exit(void) +{ + +} + +static inline void +pf_counter_u64_add_protected(struct pf_counter_u64 *pfcu64, uint32_t n) +{ + + counter_u64_add(pfcu64->counter, n); +} + +static inline void +pf_counter_u64_add(struct pf_counter_u64 *pfcu64, uint32_t n) +{ + + pf_counter_u64_add_protected(pfcu64, n); +} + +static inline u_int64_t +pf_counter_u64_fetch(struct pf_counter_u64 *pfcu64) +{ + + return (counter_u64_fetch(pfcu64->counter)); +} + +static inline void +pf_counter_u64_zero_protected(struct pf_counter_u64 *pfcu64) +{ + + counter_u64_zero(pfcu64->counter); +} + +static inline void +pf_counter_u64_zero(struct pf_counter_u64 *pfcu64) +{ + + pf_counter_u64_zero_protected(pfcu64); +} +#endif + SYSCTL_DECL(_net_pf); MALLOC_DECLARE(M_PFHASH); diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 0db9eaed1ac4..b74491bb88d0 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -154,6 +154,11 @@ VNET_DECLARE(int, pf_vnet_active); VNET_DEFINE_STATIC(uint32_t, pf_purge_idx); #define V_pf_purge_idx VNET(pf_purge_idx) +#ifdef PF_WANT_32_TO_64_COUNTER +VNET_DEFINE_STATIC(uint32_t, pf_counter_periodic_iter); +#define V_pf_counter_periodic_iter VNET(pf_counter_periodic_iter) +#endif + /* * Queue for pf_intr() sends. */ @@ -1509,6 +1514,25 @@ pf_intr(void *v) CURVNET_RESTORE(); } +#define pf_purge_thread_period (hz / 10) + +#ifdef PF_WANT_32_TO_64_COUNTER +static void +pf_counter_u64_periodic_main(void) +{ + PF_RULES_RLOCK_TRACKER; + + V_pf_counter_periodic_iter++; + + PF_RULES_RLOCK(); + pf_counter_u64_critical_enter(); + pf_counter_u64_critical_exit(); + PF_RULES_RUNLOCK(); +} +#else +#define pf_counter_u64_periodic_main() do { } while (0) +#endif + void pf_purge_thread(void *unused __unused) { @@ -1516,7 +1540,7 @@ pf_purge_thread(void *unused __unused) sx_xlock(&pf_end_lock); while (pf_end_threads == 0) { - sx_sleep(pf_purge_thread, &pf_end_lock, 0, "pftm", hz / 10); + sx_sleep(pf_purge_thread, &pf_end_lock, 0, "pftm", pf_purge_thread_period); VNET_LIST_RLOCK(); VNET_FOREACH(vnet_iter) { @@ -1528,6 +1552,8 @@ pf_purge_thread(void *unused __unused) continue; } + pf_counter_u64_periodic_main(); + /* * Process 1/interval fraction of the state * table every run. From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 15:22:41 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9D62C655870; Wed, 11 Aug 2021 15:22:41 +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 4GlD8d3NX5z3LBV; Wed, 11 Aug 2021 15:22:41 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 547DA11A5E; Wed, 11 Aug 2021 15:22:41 +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 17BFMfFP064243; Wed, 11 Aug 2021 15:22:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BFMfr3064242; Wed, 11 Aug 2021 15:22:41 GMT (envelope-from git) Date: Wed, 11 Aug 2021 15:22:41 GMT Message-Id: <202108111522.17BFMfr3064242@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 67ed59f6a826 - stable/13 - pf: consistently malloc rules with M_ZERO MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 67ed59f6a8261e6cbb82554c72e59ae81afb0b36 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 15:22:41 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=67ed59f6a8261e6cbb82554c72e59ae81afb0b36 commit 67ed59f6a8261e6cbb82554c72e59ae81afb0b36 Author: Mateusz Guzik AuthorDate: 2021-07-23 15:01:29 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 13:37:52 +0000 pf: consistently malloc rules with M_ZERO Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 49a7d47235434a300cc57b205e493988fdebf79c) --- sys/netpfil/pf/pf_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index edc786d804da..d3d0ede278fd 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -2359,7 +2359,7 @@ DIOCADDRULENV_error: struct pfioc_rule *pr = (struct pfioc_rule *)addr; struct pf_krule *rule; - rule = malloc(sizeof(*rule), M_PFRULE, M_WAITOK); + rule = malloc(sizeof(*rule), M_PFRULE, M_WAITOK | M_ZERO); error = pf_rule_to_krule(&pr->rule, rule); if (error != 0) { free(rule, M_PFRULE); @@ -2616,7 +2616,7 @@ DIOCGETRULENV_error: } if (pcr->action != PF_CHANGE_REMOVE) { - newrule = malloc(sizeof(*newrule), M_PFRULE, M_WAITOK); + newrule = malloc(sizeof(*newrule), M_PFRULE, M_WAITOK | M_ZERO); error = pf_rule_to_krule(&pcr->rule, newrule); if (error != 0) { free(newrule, M_PFRULE); From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 15:22:45 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 07F7C655D8B; Wed, 11 Aug 2021 15:22:45 +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 4GlD8h6DXLz3LdG; Wed, 11 Aug 2021 15:22:44 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 BDA4011BE0; Wed, 11 Aug 2021 15:22:44 +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 17BFMipx064322; Wed, 11 Aug 2021 15:22:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BFMiUH064321; Wed, 11 Aug 2021 15:22:44 GMT (envelope-from git) Date: Wed, 11 Aug 2021 15:22:44 GMT Message-Id: <202108111522.17BFMiUH064321@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: b45b050a69ee - stable/13 - pf: switch pf_status.fcounters to pf_counter_u64 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b45b050a69ee7c9bd1c1b6c546e0d0a9714688e1 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 15:22:45 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=b45b050a69ee7c9bd1c1b6c546e0d0a9714688e1 commit b45b050a69ee7c9bd1c1b6c546e0d0a9714688e1 Author: Mateusz Guzik AuthorDate: 2021-07-24 05:33:52 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 13:37:54 +0000 pf: switch pf_status.fcounters to pf_counter_u64 Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit fc4c42ce0b5ce87901b327e25f55b4e3ab4c6cf5) --- sys/net/pfvar.h | 2 +- sys/netpfil/pf/pf.c | 26 +++++++++++++++++++++----- sys/netpfil/pf/pf_ioctl.c | 8 ++++---- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index e381279a113f..bf70a8a5d016 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1368,7 +1368,7 @@ enum pf_syncookies_mode { struct pf_kstatus { counter_u64_t counters[PFRES_MAX]; /* reason for passing/dropping */ counter_u64_t lcounters[LCNT_MAX]; /* limit counters */ - counter_u64_t fcounters[FCNT_MAX]; /* state operation counters */ + struct pf_counter_u64 fcounters[FCNT_MAX]; /* state operation counters */ counter_u64_t scounters[SCNT_MAX]; /* src_node operation counters */ uint32_t states; uint32_t src_nodes; diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index b74491bb88d0..5d043bdbd0e4 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1311,7 +1311,7 @@ pf_state_insert(struct pfi_kkif *kif, struct pfi_kkif *orig_kif, /* One for keys, one for ID hash. */ refcount_init(&s->refs, 2); - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_INSERT], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_INSERT], 1); if (V_pfsync_insert_state_ptr != NULL) V_pfsync_insert_state_ptr(s); @@ -1328,7 +1328,7 @@ pf_find_state_byid(uint64_t id, uint32_t creatorid) struct pf_idhash *ih; struct pf_kstate *s; - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); ih = &V_pf_idhash[(be64toh(id) % (pf_hashmask + 1))]; @@ -1355,7 +1355,7 @@ pf_find_state(struct pfi_kkif *kif, struct pf_state_key_cmp *key, u_int dir) struct pf_kstate *s; int idx; - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); kh = &V_pf_keyhash[pf_hashkey((struct pf_state_key *)key)]; @@ -1399,7 +1399,7 @@ pf_find_state_all(struct pf_state_key_cmp *key, u_int dir, int *more) struct pf_kstate *s, *ret = NULL; int idx, inout = 0; - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); kh = &V_pf_keyhash[pf_hashkey((struct pf_state_key *)key)]; @@ -1517,6 +1517,21 @@ pf_intr(void *v) #define pf_purge_thread_period (hz / 10) #ifdef PF_WANT_32_TO_64_COUNTER +static void +pf_status_counter_u64_periodic(void) +{ + + PF_RULES_RASSERT(); + + if ((V_pf_counter_periodic_iter % (pf_purge_thread_period * 10 * 60)) != 0) { + return; + } + + for (int i = 0; i < FCNT_MAX; i++) { + pf_counter_u64_periodic(&V_pf_status.fcounters[i]); + } +} + static void pf_counter_u64_periodic_main(void) { @@ -1526,6 +1541,7 @@ pf_counter_u64_periodic_main(void) PF_RULES_RLOCK(); pf_counter_u64_critical_enter(); + pf_status_counter_u64_periodic(); pf_counter_u64_critical_exit(); PF_RULES_RUNLOCK(); } @@ -1781,7 +1797,7 @@ pf_free_state(struct pf_kstate *cur) pf_normalize_tcp_cleanup(cur); uma_zfree(V_pf_state_z, cur); - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_REMOVALS], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_REMOVALS], 1); } /* diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index d3d0ede278fd..2cce147035ae 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -368,7 +368,7 @@ pfattach_vnet(void) for (int i = 0; i < LCNT_MAX; i++) V_pf_status.lcounters[i] = counter_u64_alloc(M_WAITOK); for (int i = 0; i < FCNT_MAX; i++) - V_pf_status.fcounters[i] = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&V_pf_status.fcounters[i], M_WAITOK); for (int i = 0; i < SCNT_MAX; i++) V_pf_status.scounters[i] = counter_u64_alloc(M_WAITOK); @@ -3050,7 +3050,7 @@ DIOCGETSTATESV2_full: counter_u64_fetch(V_pf_status.lcounters[i]); for (int i = 0; i < FCNT_MAX; i++) s->fcounters[i] = - counter_u64_fetch(V_pf_status.fcounters[i]); + pf_counter_u64_fetch(&V_pf_status.fcounters[i]); for (int i = 0; i < SCNT_MAX; i++) s->scounters[i] = counter_u64_fetch(V_pf_status.scounters[i]); @@ -3082,7 +3082,7 @@ DIOCGETSTATESV2_full: for (int i = 0; i < PFRES_MAX; i++) counter_u64_zero(V_pf_status.counters[i]); for (int i = 0; i < FCNT_MAX; i++) - counter_u64_zero(V_pf_status.fcounters[i]); + pf_counter_u64_zero(&V_pf_status.fcounters[i]); for (int i = 0; i < SCNT_MAX; i++) counter_u64_zero(V_pf_status.scounters[i]); for (int i = 0; i < LCNT_MAX; i++) @@ -5618,7 +5618,7 @@ pf_unload_vnet(void) for (int i = 0; i < LCNT_MAX; i++) counter_u64_free(V_pf_status.lcounters[i]); for (int i = 0; i < FCNT_MAX; i++) - counter_u64_free(V_pf_status.fcounters[i]); + pf_counter_u64_deinit(&V_pf_status.fcounters[i]); for (int i = 0; i < SCNT_MAX; i++) counter_u64_free(V_pf_status.scounters[i]); } From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 15:22:47 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 88D4265618A; Wed, 11 Aug 2021 15:22:47 +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 4GlD8l2GwQz3LQf; Wed, 11 Aug 2021 15:22:47 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 00B77119F6; Wed, 11 Aug 2021 15:22:47 +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 17BFMkuP064370; Wed, 11 Aug 2021 15:22:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BFMkbl064369; Wed, 11 Aug 2021 15:22:46 GMT (envelope-from git) Date: Wed, 11 Aug 2021 15:22:46 GMT Message-Id: <202108111522.17BFMkbl064369@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: c9731a3f464f - stable/13 - pf: switch rule counters to pf_counter_u64 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c9731a3f464fd49efbd39c44e262dd069034894e Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 15:22:47 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=c9731a3f464fd49efbd39c44e262dd069034894e commit c9731a3f464fd49efbd39c44e262dd069034894e Author: Mateusz Guzik AuthorDate: 2021-07-22 14:45:14 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 13:37:55 +0000 pf: switch rule counters to pf_counter_u64 Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 02cf67ccf6538b14677672640e405f7f94044dc3) --- sys/net/pfvar.h | 19 ++++++- sys/netpfil/pf/pf.c | 80 +++++++++++++++++++++------ sys/netpfil/pf/pf_ioctl.c | 137 +++++++++++++++++++++++++++++++--------------- sys/netpfil/pf/pf_lb.c | 2 +- sys/netpfil/pf/pf_norm.c | 18 +++--- sys/netpfil/pf/pf_nv.c | 8 +-- sys/netpfil/pf/pf_nv.h | 2 +- 7 files changed, 185 insertions(+), 81 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 7afc8b895b80..76e3834372e3 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -583,9 +583,9 @@ struct pf_krule { TAILQ_ENTRY(pf_krule) entries; struct pf_kpool rpool; - counter_u64_t evaluations; - counter_u64_t packets[2]; - counter_u64_t bytes[2]; + struct pf_counter_u64 evaluations; + struct pf_counter_u64 packets[2]; + struct pf_counter_u64 bytes[2]; struct pfi_kkif *kif; struct pf_kanchor *anchor; @@ -659,6 +659,11 @@ struct pf_krule { struct pf_addr addr; u_int16_t port; } divert; + +#ifdef PF_WANT_32_TO_64_COUNTER + LIST_ENTRY(pf_krule) allrulelist; + bool allrulelinked; +#endif }; struct pf_ksrc_node { @@ -1858,6 +1863,14 @@ VNET_DECLARE(size_t, pf_allkifcount); #define V_pf_allkifcount VNET(pf_allkifcount) VNET_DECLARE(struct pfi_kkif *, pf_kifmarker); #define V_pf_kifmarker VNET(pf_kifmarker) + +LIST_HEAD(allrulelist_head, pf_krule); +VNET_DECLARE(struct allrulelist_head, pf_allrulelist); +#define V_pf_allrulelist VNET(pf_allrulelist) +VNET_DECLARE(size_t, pf_allrulecount); +#define V_pf_allrulecount VNET(pf_allrulecount) +VNET_DECLARE(struct pf_krule *, pf_rulemarker); +#define V_pf_rulemarker VNET(pf_rulemarker) #endif void pf_initialize(void); diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index f3d82549edff..6e154b620a80 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -157,6 +157,10 @@ VNET_DEFINE_STATIC(uint32_t, pf_purge_idx); #ifdef PF_WANT_32_TO_64_COUNTER VNET_DEFINE_STATIC(uint32_t, pf_counter_periodic_iter); #define V_pf_counter_periodic_iter VNET(pf_counter_periodic_iter) + +VNET_DEFINE(struct allrulelist_head, pf_allrulelist); +VNET_DEFINE(size_t, pf_allrulecount); +VNET_DEFINE(struct pf_krule *, pf_rulemarker); #endif /* @@ -1574,6 +1578,45 @@ pf_kif_counter_u64_periodic(void) } } +static void +pf_rule_counter_u64_periodic(void) +{ + struct pf_krule *rule; + size_t r, run; + + PF_RULES_RASSERT(); + + if (__predict_false(V_pf_allrulecount == 0)) { + return; + } + + if ((V_pf_counter_periodic_iter % (pf_purge_thread_period * 10 * 300)) != 0) { + return; + } + + run = V_pf_allrulecount / 10; + if (run < 5) + run = 5; + + for (r = 0; r < run; r++) { + rule = LIST_NEXT(V_pf_rulemarker, allrulelist); + if (rule == NULL) { + LIST_REMOVE(V_pf_rulemarker, allrulelist); + LIST_INSERT_HEAD(&V_pf_allrulelist, V_pf_rulemarker, allrulelist); + break; + } + + LIST_REMOVE(V_pf_rulemarker, allrulelist); + LIST_INSERT_AFTER(rule, V_pf_rulemarker, allrulelist); + + pf_counter_u64_periodic(&rule->evaluations); + for (int i = 0; i < 2; i++) { + pf_counter_u64_periodic(&rule->packets[i]); + pf_counter_u64_periodic(&rule->bytes[i]); + } + } +} + static void pf_counter_u64_periodic_main(void) { @@ -1585,6 +1628,7 @@ pf_counter_u64_periodic_main(void) pf_counter_u64_critical_enter(); pf_status_counter_u64_periodic(); pf_kif_counter_u64_periodic(); + pf_rule_counter_u64_periodic(); pf_counter_u64_critical_exit(); PF_RULES_RUNLOCK(); } @@ -3642,7 +3686,7 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, int direction, } while (r != NULL) { - counter_u64_add(r->evaluations, 1); + pf_counter_u64_add(&r->evaluations, 1); if (pfi_kkif_match(r->kif, kif) == r->ifnot) r = r->skip[PF_SKIP_IFP].ptr; else if (r->direction && r->direction != direction) @@ -3711,8 +3755,8 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, int direction, rtableid = r->rtableid; if (r->anchor == NULL) { if (r->action == PF_MATCH) { - counter_u64_add(r->packets[direction == PF_OUT], 1); - counter_u64_add(r->bytes[direction == PF_OUT], pd->tot_len); + pf_counter_u64_add(&r->packets[direction == PF_OUT], 1); + pf_counter_u64_add(&r->bytes[direction == PF_OUT], pd->tot_len); pf_rule_to_actions(r, &pd->act); if (r->log) PFLOG_PACKET(kif, m, af, @@ -4084,7 +4128,7 @@ pf_test_fragment(struct pf_krule **rm, int direction, struct pfi_kkif *kif, r = TAILQ_FIRST(pf_main_ruleset.rules[PF_RULESET_FILTER].active.ptr); while (r != NULL) { - counter_u64_add(r->evaluations, 1); + pf_counter_u64_add(&r->evaluations, 1); if (pfi_kkif_match(r->kif, kif) == r->ifnot) r = r->skip[PF_SKIP_IFP].ptr; else if (r->direction && r->direction != direction) @@ -4125,8 +4169,8 @@ pf_test_fragment(struct pf_krule **rm, int direction, struct pfi_kkif *kif, else { if (r->anchor == NULL) { if (r->action == PF_MATCH) { - counter_u64_add(r->packets[direction == PF_OUT], 1); - counter_u64_add(r->bytes[direction == PF_OUT], pd->tot_len); + pf_counter_u64_add(&r->packets[direction == PF_OUT], 1); + pf_counter_u64_add(&r->bytes[direction == PF_OUT], pd->tot_len); pf_rule_to_actions(r, &pd->act); if (r->log) PFLOG_PACKET(kif, m, af, @@ -6431,17 +6475,17 @@ done: if (action == PF_PASS || r->action == PF_DROP) { dirndx = (dir == PF_OUT); - counter_u64_add(r->packets[dirndx], 1); - counter_u64_add(r->bytes[dirndx], pd.tot_len); + pf_counter_u64_add(&r->packets[dirndx], 1); + pf_counter_u64_add(&r->bytes[dirndx], pd.tot_len); if (a != NULL) { - counter_u64_add(a->packets[dirndx], 1); - counter_u64_add(a->bytes[dirndx], pd.tot_len); + pf_counter_u64_add(&a->packets[dirndx], 1); + pf_counter_u64_add(&a->bytes[dirndx], pd.tot_len); } if (s != NULL) { if (s->nat_rule.ptr != NULL) { - counter_u64_add(s->nat_rule.ptr->packets[dirndx], + pf_counter_u64_add(&s->nat_rule.ptr->packets[dirndx], 1); - counter_u64_add(s->nat_rule.ptr->bytes[dirndx], + pf_counter_u64_add(&s->nat_rule.ptr->bytes[dirndx], pd.tot_len); } if (s->src_node != NULL) { @@ -6836,17 +6880,17 @@ done: if (action == PF_PASS || r->action == PF_DROP) { dirndx = (dir == PF_OUT); - counter_u64_add(r->packets[dirndx], 1); - counter_u64_add(r->bytes[dirndx], pd.tot_len); + pf_counter_u64_add(&r->packets[dirndx], 1); + pf_counter_u64_add(&r->bytes[dirndx], pd.tot_len); if (a != NULL) { - counter_u64_add(a->packets[dirndx], 1); - counter_u64_add(a->bytes[dirndx], pd.tot_len); + pf_counter_u64_add(&a->packets[dirndx], 1); + pf_counter_u64_add(&a->bytes[dirndx], pd.tot_len); } if (s != NULL) { if (s->nat_rule.ptr != NULL) { - counter_u64_add(s->nat_rule.ptr->packets[dirndx], + pf_counter_u64_add(&s->nat_rule.ptr->packets[dirndx], 1); - counter_u64_add(s->nat_rule.ptr->bytes[dirndx], + pf_counter_u64_add(&s->nat_rule.ptr->bytes[dirndx], pd.tot_len); } if (s->src_node != NULL) { diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index a0d877263235..7fece0facde6 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -324,10 +324,10 @@ pfattach_vnet(void) V_pf_default_rule.nr = -1; V_pf_default_rule.rtableid = -1; - V_pf_default_rule.evaluations = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&V_pf_default_rule.evaluations, M_WAITOK); for (int i = 0; i < 2; i++) { - V_pf_default_rule.packets[i] = counter_u64_alloc(M_WAITOK); - V_pf_default_rule.bytes[i] = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&V_pf_default_rule.packets[i], M_WAITOK); + pf_counter_u64_init(&V_pf_default_rule.bytes[i], M_WAITOK); } V_pf_default_rule.states_cur = counter_u64_alloc(M_WAITOK); V_pf_default_rule.states_tot = counter_u64_alloc(M_WAITOK); @@ -335,8 +335,12 @@ pfattach_vnet(void) #ifdef PF_WANT_32_TO_64_COUNTER V_pf_kifmarker = malloc(sizeof(*V_pf_kifmarker), PFI_MTYPE, M_WAITOK | M_ZERO); + V_pf_rulemarker = malloc(sizeof(*V_pf_rulemarker), M_PFRULE, M_WAITOK | M_ZERO); PF_RULES_WLOCK(); LIST_INSERT_HEAD(&V_pf_allkiflist, V_pf_kifmarker, pfik_allkiflist); + LIST_INSERT_HEAD(&V_pf_allrulelist, &V_pf_default_rule, allrulelist); + V_pf_allrulecount++; + LIST_INSERT_HEAD(&V_pf_allrulelist, V_pf_rulemarker, allrulelist); PF_RULES_WUNLOCK(); #endif @@ -1130,16 +1134,16 @@ pf_commit_rules(u_int32_t ticket, int rs_num, char *anchor) while ((tail != NULL) && ! pf_krule_compare(tail, rule)) tail = TAILQ_NEXT(tail, entries); if (tail != NULL) { - counter_u64_add(rule->evaluations, - counter_u64_fetch(tail->evaluations)); - counter_u64_add(rule->packets[0], - counter_u64_fetch(tail->packets[0])); - counter_u64_add(rule->packets[1], - counter_u64_fetch(tail->packets[1])); - counter_u64_add(rule->bytes[0], - counter_u64_fetch(tail->bytes[0])); - counter_u64_add(rule->bytes[1], - counter_u64_fetch(tail->bytes[1])); + pf_counter_u64_add(&rule->evaluations, + pf_counter_u64_fetch(&tail->evaluations)); + pf_counter_u64_add(&rule->packets[0], + pf_counter_u64_fetch(&tail->packets[0])); + pf_counter_u64_add(&rule->packets[1], + pf_counter_u64_fetch(&tail->packets[1])); + pf_counter_u64_add(&rule->bytes[0], + pf_counter_u64_fetch(&tail->bytes[0])); + pf_counter_u64_add(&rule->bytes[1], + pf_counter_u64_fetch(&tail->bytes[1])); } } } @@ -1519,13 +1523,29 @@ pf_altq_get_nth_active(u_int32_t n) void pf_krule_free(struct pf_krule *rule) { +#ifdef PF_WANT_32_TO_64_COUNTER + bool wowned; +#endif + if (rule == NULL) return; - counter_u64_free(rule->evaluations); +#ifdef PF_WANT_32_TO_64_COUNTER + if (rule->allrulelinked) { + wowned = PF_RULES_WOWNED(); + if (!wowned) + PF_RULES_WLOCK(); + LIST_REMOVE(rule, allrulelist); + V_pf_allrulecount--; + if (!wowned) + PF_RULES_WUNLOCK(); + } +#endif + + pf_counter_u64_deinit(&rule->evaluations); for (int i = 0; i < 2; i++) { - counter_u64_free(rule->packets[i]); - counter_u64_free(rule->bytes[i]); + pf_counter_u64_deinit(&rule->packets[i]); + pf_counter_u64_deinit(&rule->bytes[i]); } counter_u64_free(rule->states_cur); counter_u64_free(rule->states_tot); @@ -1590,7 +1610,7 @@ pf_pool_to_kpool(const struct pf_pool *pool, struct pf_kpool *kpool) } static void -pf_krule_to_rule(const struct pf_krule *krule, struct pf_rule *rule) +pf_krule_to_rule(struct pf_krule *krule, struct pf_rule *rule) { bzero(rule, sizeof(*rule)); @@ -1617,10 +1637,10 @@ pf_krule_to_rule(const struct pf_krule *krule, struct pf_rule *rule) pf_kpool_to_pool(&krule->rpool, &rule->rpool); - rule->evaluations = counter_u64_fetch(krule->evaluations); + rule->evaluations = pf_counter_u64_fetch(&krule->evaluations); for (int i = 0; i < 2; i++) { - rule->packets[i] = counter_u64_fetch(krule->packets[i]); - rule->bytes[i] = counter_u64_fetch(krule->bytes[i]); + rule->packets[i] = pf_counter_u64_fetch(&krule->packets[i]); + rule->bytes[i] = pf_counter_u64_fetch(&krule->bytes[i]); } /* kif, anchor, overload_tbl are not copied over. */ @@ -1997,10 +2017,10 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket, if (rule->ifname[0]) kif = pf_kkif_create(M_WAITOK); - rule->evaluations = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&rule->evaluations, M_WAITOK); for (int i = 0; i < 2; i++) { - rule->packets[i] = counter_u64_alloc(M_WAITOK); - rule->bytes[i] = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&rule->packets[i], M_WAITOK); + pf_counter_u64_init(&rule->bytes[i], M_WAITOK); } rule->states_cur = counter_u64_alloc(M_WAITOK); rule->states_tot = counter_u64_alloc(M_WAITOK); @@ -2010,6 +2030,12 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket, TAILQ_INIT(&rule->rpool.list); PF_RULES_WLOCK(); +#ifdef PF_WANT_32_TO_64_COUNTER + LIST_INSERT_HEAD(&V_pf_allrulelist, rule, allrulelist); + MPASS(!rule->allrulelinked); + rule->allrulelinked = true; + V_pf_allrulecount++; +#endif ruleset = pf_find_kruleset(anchor); if (ruleset == NULL) ERROUT(EINVAL); @@ -2113,10 +2139,10 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket, } rule->rpool.cur = TAILQ_FIRST(&rule->rpool.list); - counter_u64_zero(rule->evaluations); + pf_counter_u64_zero(&rule->evaluations); for (int i = 0; i < 2; i++) { - counter_u64_zero(rule->packets[i]); - counter_u64_zero(rule->bytes[i]); + pf_counter_u64_zero(&rule->packets[i]); + pf_counter_u64_zero(&rule->bytes[i]); } TAILQ_INSERT_TAIL(ruleset->rules[rs_num].inactive.ptr, rule, entries); @@ -2459,10 +2485,10 @@ DIOCADDRULENV_error: pf_addr_copyout(&pr->rule.dst.addr); if (pr->action == PF_GET_CLR_CNTR) { - counter_u64_zero(rule->evaluations); + pf_counter_u64_zero(&rule->evaluations); for (int i = 0; i < 2; i++) { - counter_u64_zero(rule->packets[i]); - counter_u64_zero(rule->bytes[i]); + pf_counter_u64_zero(&rule->packets[i]); + pf_counter_u64_zero(&rule->bytes[i]); } counter_u64_zero(rule->states_tot); } @@ -2581,10 +2607,10 @@ DIOCADDRULENV_error: } if (clear_counter) { - counter_u64_zero(rule->evaluations); + pf_counter_u64_zero(&rule->evaluations); for (int i = 0; i < 2; i++) { - counter_u64_zero(rule->packets[i]); - counter_u64_zero(rule->bytes[i]); + pf_counter_u64_zero(&rule->packets[i]); + pf_counter_u64_zero(&rule->bytes[i]); } counter_u64_zero(rule->states_tot); } @@ -2632,12 +2658,10 @@ DIOCGETRULENV_error: if (newrule->ifname[0]) kif = pf_kkif_create(M_WAITOK); - newrule->evaluations = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&newrule->evaluations, M_WAITOK); for (int i = 0; i < 2; i++) { - newrule->packets[i] = - counter_u64_alloc(M_WAITOK); - newrule->bytes[i] = - counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&newrule->packets[i], M_WAITOK); + pf_counter_u64_init(&newrule->bytes[i], M_WAITOK); } newrule->states_cur = counter_u64_alloc(M_WAITOK); newrule->states_tot = counter_u64_alloc(M_WAITOK); @@ -2649,6 +2673,14 @@ DIOCGETRULENV_error: #define ERROUT(x) { error = (x); goto DIOCCHANGERULE_error; } PF_RULES_WLOCK(); +#ifdef PF_WANT_32_TO_64_COUNTER + if (newrule != NULL) { + LIST_INSERT_HEAD(&V_pf_allrulelist, newrule, allrulelist); + newrule->allrulelinked = true; + V_pf_allrulecount++; + } +#endif + if (!(pcr->action == PF_CHANGE_REMOVE || pcr->action == PF_CHANGE_GET_TICKET) && pcr->pool_ticket != V_ticket_pabuf) @@ -3229,10 +3261,10 @@ DIOCGETSTATESV2_full: PF_RULES_WLOCK(); TAILQ_FOREACH(rule, ruleset->rules[PF_RULESET_FILTER].active.ptr, entries) { - counter_u64_zero(rule->evaluations); + pf_counter_u64_zero(&rule->evaluations); for (int i = 0; i < 2; i++) { - counter_u64_zero(rule->packets[i]); - counter_u64_zero(rule->bytes[i]); + pf_counter_u64_zero(&rule->packets[i]); + pf_counter_u64_zero(&rule->bytes[i]); } } PF_RULES_WUNLOCK(); @@ -5613,18 +5645,33 @@ pf_unload_vnet(void) #ifdef PF_WANT_32_TO_64_COUNTER PF_RULES_WLOCK(); LIST_REMOVE(V_pf_kifmarker, pfik_allkiflist); - PF_RULES_WUNLOCK(); - free(V_pf_kifmarker, PFI_MTYPE); MPASS(LIST_EMPTY(&V_pf_allkiflist)); MPASS(V_pf_allkifcount == 0); + + LIST_REMOVE(&V_pf_default_rule, allrulelist); + V_pf_allrulecount--; + LIST_REMOVE(V_pf_rulemarker, allrulelist); + + /* + * There are known pf rule leaks when running the test suite. + */ +#ifdef notyet + MPASS(LIST_EMPTY(&V_pf_allrulelist)); + MPASS(V_pf_allrulecount == 0); +#endif + + PF_RULES_WUNLOCK(); + + free(V_pf_kifmarker, PFI_MTYPE); + free(V_pf_rulemarker, M_PFRULE); #endif /* Free counters last as we updated them during shutdown. */ - counter_u64_free(V_pf_default_rule.evaluations); + pf_counter_u64_deinit(&V_pf_default_rule.evaluations); for (int i = 0; i < 2; i++) { - counter_u64_free(V_pf_default_rule.packets[i]); - counter_u64_free(V_pf_default_rule.bytes[i]); + pf_counter_u64_deinit(&V_pf_default_rule.packets[i]); + pf_counter_u64_deinit(&V_pf_default_rule.bytes[i]); } counter_u64_free(V_pf_default_rule.states_cur); counter_u64_free(V_pf_default_rule.states_tot); diff --git a/sys/netpfil/pf/pf_lb.c b/sys/netpfil/pf/pf_lb.c index 000ee69d9ae9..3da27c7df26d 100644 --- a/sys/netpfil/pf/pf_lb.c +++ b/sys/netpfil/pf/pf_lb.c @@ -149,7 +149,7 @@ pf_match_translation(struct pf_pdesc *pd, struct mbuf *m, int off, dst = &r->dst; } - counter_u64_add(r->evaluations, 1); + pf_counter_u64_add(&r->evaluations, 1); if (pfi_kkif_match(r->kif, kif) == r->ifnot) r = r->skip[PF_SKIP_IFP].ptr; else if (r->direction && r->direction != direction) diff --git a/sys/netpfil/pf/pf_norm.c b/sys/netpfil/pf/pf_norm.c index 3df4e06f15b6..388e2bca77b6 100644 --- a/sys/netpfil/pf/pf_norm.c +++ b/sys/netpfil/pf/pf_norm.c @@ -1039,7 +1039,7 @@ pf_normalize_ip(struct mbuf **m0, int dir, struct pfi_kkif *kif, u_short *reason r = TAILQ_FIRST(pf_main_ruleset.rules[PF_RULESET_SCRUB].active.ptr); while (r != NULL) { - counter_u64_add(r->evaluations, 1); + pf_counter_u64_add(&r->evaluations, 1); if (pfi_kkif_match(r->kif, kif) == r->ifnot) r = r->skip[PF_SKIP_IFP].ptr; else if (r->direction && r->direction != dir) @@ -1066,8 +1066,8 @@ pf_normalize_ip(struct mbuf **m0, int dir, struct pfi_kkif *kif, u_short *reason if (r == NULL || r->action == PF_NOSCRUB) return (PF_PASS); - counter_u64_add(r->packets[dir == PF_OUT], 1); - counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_add(&r->packets[dir == PF_OUT], 1); + pf_counter_u64_add(&r->bytes[dir == PF_OUT], pd->tot_len); /* Check for illegal packets */ if (hlen < (int)sizeof(struct ip)) { @@ -1181,7 +1181,7 @@ pf_normalize_ip6(struct mbuf **m0, int dir, struct pfi_kkif *kif, r = TAILQ_FIRST(pf_main_ruleset.rules[PF_RULESET_SCRUB].active.ptr); while (r != NULL) { - counter_u64_add(r->evaluations, 1); + pf_counter_u64_add(&r->evaluations, 1); if (pfi_kkif_match(r->kif, kif) == r->ifnot) r = r->skip[PF_SKIP_IFP].ptr; else if (r->direction && r->direction != dir) @@ -1207,8 +1207,8 @@ pf_normalize_ip6(struct mbuf **m0, int dir, struct pfi_kkif *kif, if (r == NULL || r->action == PF_NOSCRUB) return (PF_PASS); - counter_u64_add(r->packets[dir == PF_OUT], 1); - counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_add(&r->packets[dir == PF_OUT], 1); + pf_counter_u64_add(&r->bytes[dir == PF_OUT], pd->tot_len); /* Check for illegal packets */ if (sizeof(struct ip6_hdr) + IPV6_MAXPACKET < m->m_pkthdr.len) @@ -1334,7 +1334,7 @@ pf_normalize_tcp(int dir, struct pfi_kkif *kif, struct mbuf *m, int ipoff, r = TAILQ_FIRST(pf_main_ruleset.rules[PF_RULESET_SCRUB].active.ptr); while (r != NULL) { - counter_u64_add(r->evaluations, 1); + pf_counter_u64_add(&r->evaluations, 1); if (pfi_kkif_match(r->kif, kif) == r->ifnot) r = r->skip[PF_SKIP_IFP].ptr; else if (r->direction && r->direction != dir) @@ -1368,8 +1368,8 @@ pf_normalize_tcp(int dir, struct pfi_kkif *kif, struct mbuf *m, int ipoff, if (rm == NULL || rm->action == PF_NOSCRUB) return (PF_PASS); - counter_u64_add(r->packets[dir == PF_OUT], 1); - counter_u64_add(r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_add(&r->packets[dir == PF_OUT], 1); + pf_counter_u64_add(&r->bytes[dir == PF_OUT], pd->tot_len); if (rm->rule_flag & PFRULE_REASSEMBLE_TCP) pd->flags |= PFDESC_TCP_NORM; diff --git a/sys/netpfil/pf/pf_nv.c b/sys/netpfil/pf/pf_nv.c index c0a17cd876ae..d1eca90e0ee5 100644 --- a/sys/netpfil/pf/pf_nv.c +++ b/sys/netpfil/pf/pf_nv.c @@ -655,7 +655,7 @@ error: } nvlist_t * -pf_krule_to_nvrule(const struct pf_krule *rule) +pf_krule_to_nvrule(struct pf_krule *rule) { nvlist_t *nvl, *tmp; @@ -698,12 +698,12 @@ pf_krule_to_nvrule(const struct pf_krule *rule) nvlist_destroy(tmp); nvlist_add_number(nvl, "evaluations", - counter_u64_fetch(rule->evaluations)); + pf_counter_u64_fetch(&rule->evaluations)); for (int i = 0; i < 2; i++) { nvlist_append_number_array(nvl, "packets", - counter_u64_fetch(rule->packets[i])); + pf_counter_u64_fetch(&rule->packets[i])); nvlist_append_number_array(nvl, "bytes", - counter_u64_fetch(rule->bytes[i])); + pf_counter_u64_fetch(&rule->bytes[i])); } nvlist_add_number(nvl, "os_fingerprint", rule->os_fingerprint); diff --git a/sys/netpfil/pf/pf_nv.h b/sys/netpfil/pf/pf_nv.h index 2abb5a2401e2..f1cdc52aad6b 100644 --- a/sys/netpfil/pf/pf_nv.h +++ b/sys/netpfil/pf/pf_nv.h @@ -78,7 +78,7 @@ int pf_nvstring(const nvlist_t *, const char *, char *, size_t); int pf_check_rule_addr(const struct pf_rule_addr *); -nvlist_t *pf_krule_to_nvrule(const struct pf_krule *); +nvlist_t *pf_krule_to_nvrule(struct pf_krule *); int pf_nvrule_to_krule(const nvlist_t *, struct pf_krule *); int pf_nvstate_kill_to_kstate_kill(const nvlist_t *, struct pf_kstate_kill *); From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 15:22:48 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5130C65618B; Wed, 11 Aug 2021 15:22:48 +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 4GlD8m1Tgvz3LV8; Wed, 11 Aug 2021 15:22:48 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 13A9A118FF; Wed, 11 Aug 2021 15:22:48 +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 17BFMms3064394; Wed, 11 Aug 2021 15:22:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BFMlbY064393; Wed, 11 Aug 2021 15:22:47 GMT (envelope-from git) Date: Wed, 11 Aug 2021 15:22:47 GMT Message-Id: <202108111522.17BFMlbY064393@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: bf60d2826768 - stable/13 - pf: batch critical section for several counters MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: bf60d2826768ca4ab125ba770b14b04d303dea2f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 15:22:48 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=bf60d2826768ca4ab125ba770b14b04d303dea2f commit bf60d2826768ca4ab125ba770b14b04d303dea2f Author: Mateusz Guzik AuthorDate: 2021-07-24 07:47:40 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 13:37:56 +0000 pf: batch critical section for several counters Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 87c010e6e364e96e2c1546b3c2bbcbef1dcd422f) --- sys/netpfil/pf/pf.c | 48 +++++++++++++++++++++++++++-------------------- sys/netpfil/pf/pf_ioctl.c | 12 +++++++----- sys/netpfil/pf/pf_norm.c | 18 ++++++++++++------ 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 6e154b620a80..633346eee21c 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -3755,8 +3755,10 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, int direction, rtableid = r->rtableid; if (r->anchor == NULL) { if (r->action == PF_MATCH) { - pf_counter_u64_add(&r->packets[direction == PF_OUT], 1); - pf_counter_u64_add(&r->bytes[direction == PF_OUT], pd->tot_len); + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&r->packets[direction == PF_OUT], 1); + pf_counter_u64_add_protected(&r->bytes[direction == PF_OUT], pd->tot_len); + pf_counter_u64_critical_exit(); pf_rule_to_actions(r, &pd->act); if (r->log) PFLOG_PACKET(kif, m, af, @@ -4169,8 +4171,10 @@ pf_test_fragment(struct pf_krule **rm, int direction, struct pfi_kkif *kif, else { if (r->anchor == NULL) { if (r->action == PF_MATCH) { - pf_counter_u64_add(&r->packets[direction == PF_OUT], 1); - pf_counter_u64_add(&r->bytes[direction == PF_OUT], pd->tot_len); + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&r->packets[direction == PF_OUT], 1); + pf_counter_u64_add_protected(&r->bytes[direction == PF_OUT], pd->tot_len); + pf_counter_u64_critical_exit(); pf_rule_to_actions(r, &pd->act); if (r->log) PFLOG_PACKET(kif, m, af, @@ -6468,24 +6472,25 @@ done: (s == NULL)); } - pf_counter_u64_add(&kif->pfik_bytes[0][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&kif->pfik_bytes[0][dir == PF_OUT][action != PF_PASS], pd.tot_len); - pf_counter_u64_add(&kif->pfik_packets[0][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_add_protected(&kif->pfik_packets[0][dir == PF_OUT][action != PF_PASS], 1); if (action == PF_PASS || r->action == PF_DROP) { dirndx = (dir == PF_OUT); - pf_counter_u64_add(&r->packets[dirndx], 1); - pf_counter_u64_add(&r->bytes[dirndx], pd.tot_len); + pf_counter_u64_add_protected(&r->packets[dirndx], 1); + pf_counter_u64_add_protected(&r->bytes[dirndx], pd.tot_len); if (a != NULL) { - pf_counter_u64_add(&a->packets[dirndx], 1); - pf_counter_u64_add(&a->bytes[dirndx], pd.tot_len); + pf_counter_u64_add_protected(&a->packets[dirndx], 1); + pf_counter_u64_add_protected(&a->bytes[dirndx], pd.tot_len); } if (s != NULL) { if (s->nat_rule.ptr != NULL) { - pf_counter_u64_add(&s->nat_rule.ptr->packets[dirndx], + pf_counter_u64_add_protected(&s->nat_rule.ptr->packets[dirndx], 1); - pf_counter_u64_add(&s->nat_rule.ptr->bytes[dirndx], + pf_counter_u64_add_protected(&s->nat_rule.ptr->bytes[dirndx], pd.tot_len); } if (s->src_node != NULL) { @@ -6523,6 +6528,7 @@ done: pd.af, pd.tot_len, dir == PF_OUT, r->action == PF_PASS, tr->dst.neg); } + pf_counter_u64_critical_exit(); switch (action) { case PF_SYNPROXY_DROP: @@ -6873,24 +6879,25 @@ done: &pd, (s == NULL)); } - pf_counter_u64_add(&kif->pfik_bytes[1][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&kif->pfik_bytes[1][dir == PF_OUT][action != PF_PASS], pd.tot_len); - pf_counter_u64_add(&kif->pfik_packets[1][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_add_protected(&kif->pfik_packets[1][dir == PF_OUT][action != PF_PASS], 1); if (action == PF_PASS || r->action == PF_DROP) { dirndx = (dir == PF_OUT); - pf_counter_u64_add(&r->packets[dirndx], 1); - pf_counter_u64_add(&r->bytes[dirndx], pd.tot_len); + pf_counter_u64_add_protected(&r->packets[dirndx], 1); + pf_counter_u64_add_protected(&r->bytes[dirndx], pd.tot_len); if (a != NULL) { - pf_counter_u64_add(&a->packets[dirndx], 1); - pf_counter_u64_add(&a->bytes[dirndx], pd.tot_len); + pf_counter_u64_add_protected(&a->packets[dirndx], 1); + pf_counter_u64_add_protected(&a->bytes[dirndx], pd.tot_len); } if (s != NULL) { if (s->nat_rule.ptr != NULL) { - pf_counter_u64_add(&s->nat_rule.ptr->packets[dirndx], + pf_counter_u64_add_protected(&s->nat_rule.ptr->packets[dirndx], 1); - pf_counter_u64_add(&s->nat_rule.ptr->bytes[dirndx], + pf_counter_u64_add_protected(&s->nat_rule.ptr->bytes[dirndx], pd.tot_len); } if (s->src_node != NULL) { @@ -6926,6 +6933,7 @@ done: pd.af, pd.tot_len, dir == PF_OUT, r->action == PF_PASS, tr->dst.neg); } + pf_counter_u64_critical_exit(); switch (action) { case PF_SYNPROXY_DROP: diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 7fece0facde6..ebb30604ebf1 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -1134,16 +1134,18 @@ pf_commit_rules(u_int32_t ticket, int rs_num, char *anchor) while ((tail != NULL) && ! pf_krule_compare(tail, rule)) tail = TAILQ_NEXT(tail, entries); if (tail != NULL) { - pf_counter_u64_add(&rule->evaluations, + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&rule->evaluations, pf_counter_u64_fetch(&tail->evaluations)); - pf_counter_u64_add(&rule->packets[0], + pf_counter_u64_add_protected(&rule->packets[0], pf_counter_u64_fetch(&tail->packets[0])); - pf_counter_u64_add(&rule->packets[1], + pf_counter_u64_add_protected(&rule->packets[1], pf_counter_u64_fetch(&tail->packets[1])); - pf_counter_u64_add(&rule->bytes[0], + pf_counter_u64_add_protected(&rule->bytes[0], pf_counter_u64_fetch(&tail->bytes[0])); - pf_counter_u64_add(&rule->bytes[1], + pf_counter_u64_add_protected(&rule->bytes[1], pf_counter_u64_fetch(&tail->bytes[1])); + pf_counter_u64_critical_exit(); } } } diff --git a/sys/netpfil/pf/pf_norm.c b/sys/netpfil/pf/pf_norm.c index 388e2bca77b6..e9674d21ec5a 100644 --- a/sys/netpfil/pf/pf_norm.c +++ b/sys/netpfil/pf/pf_norm.c @@ -1066,8 +1066,10 @@ pf_normalize_ip(struct mbuf **m0, int dir, struct pfi_kkif *kif, u_short *reason if (r == NULL || r->action == PF_NOSCRUB) return (PF_PASS); - pf_counter_u64_add(&r->packets[dir == PF_OUT], 1); - pf_counter_u64_add(&r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&r->packets[dir == PF_OUT], 1); + pf_counter_u64_add_protected(&r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_critical_exit(); /* Check for illegal packets */ if (hlen < (int)sizeof(struct ip)) { @@ -1207,8 +1209,10 @@ pf_normalize_ip6(struct mbuf **m0, int dir, struct pfi_kkif *kif, if (r == NULL || r->action == PF_NOSCRUB) return (PF_PASS); - pf_counter_u64_add(&r->packets[dir == PF_OUT], 1); - pf_counter_u64_add(&r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&r->packets[dir == PF_OUT], 1); + pf_counter_u64_add_protected(&r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_critical_exit(); /* Check for illegal packets */ if (sizeof(struct ip6_hdr) + IPV6_MAXPACKET < m->m_pkthdr.len) @@ -1368,8 +1372,10 @@ pf_normalize_tcp(int dir, struct pfi_kkif *kif, struct mbuf *m, int ipoff, if (rm == NULL || rm->action == PF_NOSCRUB) return (PF_PASS); - pf_counter_u64_add(&r->packets[dir == PF_OUT], 1); - pf_counter_u64_add(&r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_critical_enter(); + pf_counter_u64_add_protected(&r->packets[dir == PF_OUT], 1); + pf_counter_u64_add_protected(&r->bytes[dir == PF_OUT], pd->tot_len); + pf_counter_u64_critical_exit(); if (rm->rule_flag & PFRULE_REASSEMBLE_TCP) pd->flags |= PFDESC_TCP_NORM; From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 15:22:46 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 437A5655E99; Wed, 11 Aug 2021 15:22:46 +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 4GlD8k0jMtz3LMl; Wed, 11 Aug 2021 15:22:46 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 E674B11D3E; Wed, 11 Aug 2021 15:22:45 +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 17BFMjfG064346; Wed, 11 Aug 2021 15:22:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BFMj75064345; Wed, 11 Aug 2021 15:22:45 GMT (envelope-from git) Date: Wed, 11 Aug 2021 15:22:45 GMT Message-Id: <202108111522.17BFMj75064345@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 79f0e6469aad - stable/13 - pf: switch kif counters to pf_counter_u64 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 79f0e6469aad525400e8be0deb16b4d964e7a6c1 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 15:22:46 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=79f0e6469aad525400e8be0deb16b4d964e7a6c1 commit 79f0e6469aad525400e8be0deb16b4d964e7a6c1 Author: Mateusz Guzik AuthorDate: 2021-07-23 10:29:46 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 13:37:55 +0000 pf: switch kif counters to pf_counter_u64 Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit d40d4b3ed788b05697541b9ae94b1960ff2cf6f6) --- sys/net/pfvar.h | 17 +++++++++++-- sys/netpfil/pf/pf.c | 51 +++++++++++++++++++++++++++++++++++--- sys/netpfil/pf/pf_if.c | 62 +++++++++++++++++++++++++++++++++++------------ sys/netpfil/pf/pf_ioctl.c | 17 +++++++++++++ 4 files changed, 126 insertions(+), 21 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index bf70a8a5d016..7afc8b895b80 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1255,14 +1255,17 @@ struct pfi_kkif { } _pfik_glue; #define pfik_tree _pfik_glue._pfik_tree #define pfik_list _pfik_glue._pfik_list - counter_u64_t pfik_packets[2][2][2]; - counter_u64_t pfik_bytes[2][2][2]; + struct pf_counter_u64 pfik_packets[2][2][2]; + struct pf_counter_u64 pfik_bytes[2][2][2]; u_int32_t pfik_tzero; u_int pfik_flags; struct ifnet *pfik_ifp; struct ifg_group *pfik_group; u_int pfik_rulerefs; TAILQ_HEAD(, pfi_dynaddr) pfik_dynaddrs; +#ifdef PF_WANT_32_TO_64_COUNTER + LIST_ENTRY(pfi_kkif) pfik_allkiflist; +#endif }; #endif @@ -1847,6 +1850,16 @@ VNET_DECLARE(struct pf_altqqueue *, pf_altq_ifs_inactive); VNET_DECLARE(struct pf_krulequeue, pf_unlinked_rules); #define V_pf_unlinked_rules VNET(pf_unlinked_rules) +#ifdef PF_WANT_32_TO_64_COUNTER +LIST_HEAD(allkiflist_head, pfi_kkif); +VNET_DECLARE(struct allkiflist_head, pf_allkiflist); +#define V_pf_allkiflist VNET(pf_allkiflist) +VNET_DECLARE(size_t, pf_allkifcount); +#define V_pf_allkifcount VNET(pf_allkifcount) +VNET_DECLARE(struct pfi_kkif *, pf_kifmarker); +#define V_pf_kifmarker VNET(pf_kifmarker) +#endif + void pf_initialize(void); void pf_mtag_initialize(void); void pf_mtag_cleanup(void); diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 5d043bdbd0e4..f3d82549edff 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1532,6 +1532,48 @@ pf_status_counter_u64_periodic(void) } } +static void +pf_kif_counter_u64_periodic(void) +{ + struct pfi_kkif *kif; + size_t r, run; + + PF_RULES_RASSERT(); + + if (__predict_false(V_pf_allkifcount == 0)) { + return; + } + + if ((V_pf_counter_periodic_iter % (pf_purge_thread_period * 10 * 300)) != 0) { + return; + } + + run = V_pf_allkifcount / 10; + if (run < 5) + run = 5; + + for (r = 0; r < run; r++) { + kif = LIST_NEXT(V_pf_kifmarker, pfik_allkiflist); + if (kif == NULL) { + LIST_REMOVE(V_pf_kifmarker, pfik_allkiflist); + LIST_INSERT_HEAD(&V_pf_allkiflist, V_pf_kifmarker, pfik_allkiflist); + break; + } + + LIST_REMOVE(V_pf_kifmarker, pfik_allkiflist); + LIST_INSERT_AFTER(kif, V_pf_kifmarker, pfik_allkiflist); + + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + for (int k = 0; k < 2; k++) { + pf_counter_u64_periodic(&kif->pfik_packets[i][j][k]); + pf_counter_u64_periodic(&kif->pfik_bytes[i][j][k]); + } + } + } + } +} + static void pf_counter_u64_periodic_main(void) { @@ -1542,6 +1584,7 @@ pf_counter_u64_periodic_main(void) PF_RULES_RLOCK(); pf_counter_u64_critical_enter(); pf_status_counter_u64_periodic(); + pf_kif_counter_u64_periodic(); pf_counter_u64_critical_exit(); PF_RULES_RUNLOCK(); } @@ -6381,9 +6424,9 @@ done: (s == NULL)); } - counter_u64_add(kif->pfik_bytes[0][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_add(&kif->pfik_bytes[0][dir == PF_OUT][action != PF_PASS], pd.tot_len); - counter_u64_add(kif->pfik_packets[0][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_add(&kif->pfik_packets[0][dir == PF_OUT][action != PF_PASS], 1); if (action == PF_PASS || r->action == PF_DROP) { @@ -6786,9 +6829,9 @@ done: &pd, (s == NULL)); } - counter_u64_add(kif->pfik_bytes[1][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_add(&kif->pfik_bytes[1][dir == PF_OUT][action != PF_PASS], pd.tot_len); - counter_u64_add(kif->pfik_packets[1][dir == PF_OUT][action != PF_PASS], + pf_counter_u64_add(&kif->pfik_packets[1][dir == PF_OUT][action != PF_PASS], 1); if (action == PF_PASS || r->action == PF_DROP) { diff --git a/sys/netpfil/pf/pf_if.c b/sys/netpfil/pf/pf_if.c index 3c9b53daa28c..dcbbce08ed6c 100644 --- a/sys/netpfil/pf/pf_if.c +++ b/sys/netpfil/pf/pf_if.c @@ -69,6 +69,12 @@ VNET_DEFINE_STATIC(int, pfi_buffer_max); #define V_pfi_buffer_cnt VNET(pfi_buffer_cnt) #define V_pfi_buffer_max VNET(pfi_buffer_max) +#ifdef PF_WANT_32_TO_64_COUNTER +VNET_DEFINE(struct allkiflist_head, pf_allkiflist); +VNET_DEFINE(size_t, pf_allkifcount); +VNET_DEFINE(struct pfi_kkif *, pf_kifmarker); +#endif + eventhandler_tag pfi_attach_cookie; eventhandler_tag pfi_detach_cookie; eventhandler_tag pfi_attach_group_cookie; @@ -222,6 +228,9 @@ struct pfi_kkif* pf_kkif_create(int flags) { struct pfi_kkif *kif; +#ifdef PF_WANT_32_TO_64_COUNTER + bool wowned; +#endif kif = malloc(sizeof(*kif), PFI_MTYPE, flags | M_ZERO); if (! kif) @@ -230,13 +239,12 @@ pf_kkif_create(int flags) for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { - kif->pfik_packets[i][j][k] = - counter_u64_alloc(flags); - kif->pfik_bytes[i][j][k] = - counter_u64_alloc(flags); + if (pf_counter_u64_init(&kif->pfik_packets[i][j][k], flags) != 0) { + pf_kkif_free(kif); + return (NULL); + } - if (! kif->pfik_packets[i][j][k] || - ! kif->pfik_bytes[i][j][k]) { + if (pf_counter_u64_init(&kif->pfik_bytes[i][j][k], flags) != 0) { pf_kkif_free(kif); return (NULL); } @@ -244,20 +252,44 @@ pf_kkif_create(int flags) } } +#ifdef PF_WANT_32_TO_64_COUNTER + wowned = PF_RULES_WOWNED(); + if (!wowned) + PF_RULES_WLOCK(); + LIST_INSERT_HEAD(&V_pf_allkiflist, kif, pfik_allkiflist); + V_pf_allkifcount++; + if (!wowned) + PF_RULES_WUNLOCK(); +#endif + return (kif); } void pf_kkif_free(struct pfi_kkif *kif) { +#ifdef PF_WANT_32_TO_64_COUNTER + bool wowned; +#endif + if (! kif) return; +#ifdef PF_WANT_32_TO_64_COUNTER + wowned = PF_RULES_WOWNED(); + if (!wowned) + PF_RULES_WLOCK(); + LIST_REMOVE(kif, pfik_allkiflist); + V_pf_allkifcount--; + if (!wowned) + PF_RULES_WUNLOCK(); +#endif + for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { - counter_u64_free(kif->pfik_packets[i][j][k]); - counter_u64_free(kif->pfik_bytes[i][j][k]); + pf_counter_u64_deinit(&kif->pfik_packets[i][j][k]); + pf_counter_u64_deinit(&kif->pfik_bytes[i][j][k]); } } } @@ -272,8 +304,8 @@ pf_kkif_zero(struct pfi_kkif *kif) for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { - counter_u64_zero(kif->pfik_packets[i][j][k]); - counter_u64_zero(kif->pfik_bytes[i][j][k]); + pf_counter_u64_zero(&kif->pfik_packets[i][j][k]); + pf_counter_u64_zero(&kif->pfik_bytes[i][j][k]); } } } @@ -805,15 +837,15 @@ pfi_update_status(const char *name, struct pf_status *pfs) for (j = 0; j < 2; j++) for (k = 0; k < 2; k++) { pfs->pcounters[i][j][k] += - counter_u64_fetch(p->pfik_packets[i][j][k]); + pf_counter_u64_fetch(&p->pfik_packets[i][j][k]); pfs->bcounters[i][j] += - counter_u64_fetch(p->pfik_bytes[i][j][k]); + pf_counter_u64_fetch(&p->pfik_bytes[i][j][k]); } } } static void -pf_kkif_to_kif(const struct pfi_kkif *kkif, struct pfi_kif *kif) +pf_kkif_to_kif(struct pfi_kkif *kkif, struct pfi_kif *kif) { bzero(kif, sizeof(*kif)); @@ -822,9 +854,9 @@ pf_kkif_to_kif(const struct pfi_kkif *kkif, struct pfi_kif *kif) for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { kif->pfik_packets[i][j][k] = - counter_u64_fetch(kkif->pfik_packets[i][j][k]); + pf_counter_u64_fetch(&kkif->pfik_packets[i][j][k]); kif->pfik_bytes[i][j][k] = - counter_u64_fetch(kkif->pfik_bytes[i][j][k]); + pf_counter_u64_fetch(&kkif->pfik_bytes[i][j][k]); } } } diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 2cce147035ae..a0d877263235 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -333,6 +333,13 @@ pfattach_vnet(void) V_pf_default_rule.states_tot = counter_u64_alloc(M_WAITOK); V_pf_default_rule.src_nodes = counter_u64_alloc(M_WAITOK); +#ifdef PF_WANT_32_TO_64_COUNTER + V_pf_kifmarker = malloc(sizeof(*V_pf_kifmarker), PFI_MTYPE, M_WAITOK | M_ZERO); + PF_RULES_WLOCK(); + LIST_INSERT_HEAD(&V_pf_allkiflist, V_pf_kifmarker, pfik_allkiflist); + PF_RULES_WUNLOCK(); +#endif + /* initialize default timeouts */ my_timeout[PFTM_TCP_FIRST_PACKET] = PFTM_TCP_FIRST_PACKET_VAL; my_timeout[PFTM_TCP_OPENING] = PFTM_TCP_OPENING_VAL; @@ -5603,6 +5610,16 @@ pf_unload_vnet(void) #endif uma_zdestroy(V_pf_tag_z); +#ifdef PF_WANT_32_TO_64_COUNTER + PF_RULES_WLOCK(); + LIST_REMOVE(V_pf_kifmarker, pfik_allkiflist); + PF_RULES_WUNLOCK(); + free(V_pf_kifmarker, PFI_MTYPE); + + MPASS(LIST_EMPTY(&V_pf_allkiflist)); + MPASS(V_pf_allkifcount == 0); +#endif + /* Free counters last as we updated them during shutdown. */ counter_u64_free(V_pf_default_rule.evaluations); for (int i = 0; i < 2; i++) { From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 17:24:38 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B2E7C657C5B; Wed, 11 Aug 2021 17:24:38 +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 4GlGsL4jpPz3jj8; Wed, 11 Aug 2021 17:24:38 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 89E231316E; Wed, 11 Aug 2021 17:24:38 +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 17BHOcus026087; Wed, 11 Aug 2021 17:24:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BHOcaL026086; Wed, 11 Aug 2021 17:24:38 GMT (envelope-from git) Date: Wed, 11 Aug 2021 17:24:38 GMT Message-Id: <202108111724.17BHOcaL026086@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 2e50ba70742b - stable/13 - hwpmc: disable uncore class on Sandy Bridge and newer MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2e50ba70742bac34f144832ceb5f6816fcc06be2 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 17:24:38 -0000 The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=2e50ba70742bac34f144832ceb5f6816fcc06be2 commit 2e50ba70742bac34f144832ceb5f6816fcc06be2 Author: Mitchell Horne AuthorDate: 2021-08-04 17:31:36 +0000 Commit: Mitchell Horne CommitDate: 2021-08-11 16:49:44 +0000 hwpmc: disable uncore class on Sandy Bridge and newer It was written for Nehalem and Westmere, with minor but incomplete updates for Sandy Bridge in 78d763a29b15. The uncore architecture changed significantly with this generation, bringing new layouts and locations for some MSRs. Misprogramming these MSRs in ucp_start_pmc() may panic the system, and this is trivially reproducible via pmcstat(8) on at least Broadwell and Haswell. Disable the class on these CPUs until it can be updated more completely and leave a TODO comment detailing some of the work required. Note that the nclasses value for Broadwell was already incorrect and doesn't need changing. The result is that any uncore events listed by pmcstat -L will no longer be allocatable, but this is already the case for newer generations of Intel CPUs. PR: 253687 Reported by: Zhenlei Huang Reviewed by: kib MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D31389 (cherry picked from commit 4f35e8cba232d9256ab1399b8adfb761988e5eff) --- sys/dev/hwpmc/hwpmc_intel.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_intel.c b/sys/dev/hwpmc/hwpmc_intel.c index aec037b64938..02b8fd9431d1 100644 --- a/sys/dev/hwpmc/hwpmc_intel.c +++ b/sys/dev/hwpmc/hwpmc_intel.c @@ -149,7 +149,7 @@ pmc_intel_initialize(void) break; case 0x2A: /* Per Intel document 253669-039US 05/2011. */ cputype = PMC_CPU_INTEL_SANDYBRIDGE; - nclasses = 5; + nclasses = 3; break; case 0x2D: /* Per Intel document 253669-044US 08/2012. */ cputype = PMC_CPU_INTEL_SANDYBRIDGE_XEON; @@ -195,7 +195,7 @@ pmc_intel_initialize(void) case 0x3C: /* Per Intel document 325462-045US 01/2013. */ case 0x45: /* Per Intel document 325462-045US 09/2014. */ cputype = PMC_CPU_INTEL_HASWELL; - nclasses = 5; + nclasses = 3; break; case 0x37: case 0x4A: @@ -275,10 +275,27 @@ pmc_intel_initialize(void) * Intel Corei7 and Westmere processors. */ case PMC_CPU_INTEL_COREI7: - case PMC_CPU_INTEL_HASWELL: - case PMC_CPU_INTEL_SANDYBRIDGE: case PMC_CPU_INTEL_WESTMERE: +#ifdef notyet + /* + * TODO: re-enable uncore class on these processors. + * + * The uncore unit was reworked beginning with Sandy Bridge, including + * the MSRs required to program it. In particular, we need to: + * - Parse the MSR_UNC_CBO_CONFIG MSR for number of C-box units in the + * system + * - Support reading and writing to ARB and C-box units, depending on + * the requested event + * - Create some kind of mapping between C-box <--> CPU + * + * Also TODO: support other later changes to these interfaces, to + * enable the uncore class on generations newer than Broadwell. + * Skylake+ appears to use newer addresses for the uncore MSRs. + */ + case PMC_CPU_INTEL_HASWELL: case PMC_CPU_INTEL_BROADWELL: + case PMC_CPU_INTEL_SANDYBRIDGE: +#endif error = pmc_uncore_initialize(pmc_mdep, ncpus); break; default: @@ -329,11 +346,13 @@ pmc_intel_finalize(struct pmc_mdep *md) * Uncore. */ switch (md->pmd_cputype) { - case PMC_CPU_INTEL_BROADWELL: case PMC_CPU_INTEL_COREI7: + case PMC_CPU_INTEL_WESTMERE: +#ifdef notyet case PMC_CPU_INTEL_HASWELL: + case PMC_CPU_INTEL_BROADWELL: case PMC_CPU_INTEL_SANDYBRIDGE: - case PMC_CPU_INTEL_WESTMERE: +#endif pmc_uncore_finalize(md); break; default: From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 17:24:39 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D7E3C657C64; Wed, 11 Aug 2021 17:24:39 +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 4GlGsM5hQmz3jmW; Wed, 11 Aug 2021 17:24:39 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 AD01E13692; Wed, 11 Aug 2021 17:24:39 +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 17BHOdBl026111; Wed, 11 Aug 2021 17:24:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BHOd4G026110; Wed, 11 Aug 2021 17:24:39 GMT (envelope-from git) Date: Wed, 11 Aug 2021 17:24:39 GMT Message-Id: <202108111724.17BHOd4G026110@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 19cbaf34a3e4 - stable/13 - mk: format some option lists MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 19cbaf34a3e47475f72f2ba3783d9281ca57996f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 17:24:39 -0000 The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=19cbaf34a3e47475f72f2ba3783d9281ca57996f commit 19cbaf34a3e47475f72f2ba3783d9281ca57996f Author: Mitchell Horne AuthorDate: 2021-08-04 18:17:34 +0000 Commit: Mitchell Horne CommitDate: 2021-08-11 16:53:16 +0000 mk: format some option lists Alphabetize and give each option its own line, ahead of making another change to these lists. This makes future diffs easier to read. Reviewed by: imp, emaste MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D31399 (cherry picked from commit bcd2f41f7d222a942fe0a268614b46d3ec3af4c0) --- Makefile.inc1 | 48 ++++++++++++++++++++++++--------- Makefile.libcompat | 8 ++++-- targets/pseudo/bootstrap-tools/Makefile | 23 +++++++++++----- 3 files changed, 59 insertions(+), 20 deletions(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index 8b417eaaac05..a03b79a5b02c 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -727,12 +727,23 @@ BSARGS= DESTDIR= \ BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \ BWPHASE=${.TARGET:C,^_,,} \ SSP_CFLAGS= \ - MK_HTML=no NO_LINT=yes MK_MAN=no MK_MAN_UTILS=yes \ - -DNO_PIC MK_PROFILE=no -DNO_SHARED \ - -DNO_CPU_CFLAGS MK_WERROR=no MK_CTF=no \ - MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \ - MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no \ - MK_INCLUDES=yes + -DNO_CPU_CFLAGS \ + -DNO_LINT \ + -DNO_PIC \ + -DNO_SHARED \ + MK_CTF=no \ + MK_CLANG_EXTRAS=no \ + MK_CLANG_FORMAT=no \ + MK_CLANG_FULL=no \ + MK_HTML=no \ + MK_LLDB=no \ + MK_MAN=no \ + MK_PROFILE=no \ + MK_RETPOLINE=no \ + MK_TESTS=no \ + MK_WERROR=no \ + MK_INCLUDES=yes \ + MK_MAN_UTILS=yes BMAKE= \ ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \ @@ -749,10 +760,16 @@ TMAKE= \ BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \ BWPHASE=${.TARGET:C,^_,,} \ SSP_CFLAGS= \ + -DNO_CPU_CFLAGS \ -DNO_LINT \ - -DNO_CPU_CFLAGS MK_WERROR=no MK_CTF=no \ - MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \ - MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no + MK_CTF=no \ + MK_CLANG_EXTRAS=no \ + MK_CLANG_FORMAT=no \ + MK_CLANG_FULL=no \ + MK_LLDB=no \ + MK_RETPOLINE=no \ + MK_TESTS=no \ + MK_WERROR=no # cross-tools stage # TOOLS_PREFIX set in BMAKE @@ -776,9 +793,16 @@ KTMAKE= \ MAKEOBJDIRPREFIX= \ BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \ SSP_CFLAGS= \ - MK_HTML=no -DNO_LINT MK_MAN=no \ - -DNO_PIC MK_PROFILE=no -DNO_SHARED \ - -DNO_CPU_CFLAGS MK_RETPOLINE=no MK_WERROR=no MK_CTF=no + -DNO_CPU_CFLAGS \ + -DNO_LINT \ + -DNO_PIC \ + -DNO_SHARED \ + MK_CTF=no \ + MK_HTML=no \ + MK_MAN=no \ + MK_PROFILE=no \ + MK_RETPOLINE=no \ + MK_WERROR=no # world stage WMAKEENV= ${CROSSENV} \ diff --git a/Makefile.libcompat b/Makefile.libcompat index 779bcb163cf7..7238c6faf898 100644 --- a/Makefile.libcompat +++ b/Makefile.libcompat @@ -103,8 +103,12 @@ build${libcompat}: .PHONY OBJTOP=${LIBCOMPAT_OBJTOP} \ OBJROOT='$${OBJTOP}/' \ MAKEOBJDIRPREFIX= \ - DIRPRFX=${_dir}/ -DNO_LINT -DNO_CPU_CFLAGS \ - MK_CTF=no MK_RETPOLINE=no MK_WERROR=no \ + DIRPRFX=${_dir}/ \ + -DNO_LINT \ + -DNO_CPU_CFLAGS \ + MK_CTF=no \ + MK_RETPOLINE=no \ + MK_WERROR=no \ ${_t} .endfor .endfor diff --git a/targets/pseudo/bootstrap-tools/Makefile b/targets/pseudo/bootstrap-tools/Makefile index 0023f763af83..1a7f2bd15ad0 100644 --- a/targets/pseudo/bootstrap-tools/Makefile +++ b/targets/pseudo/bootstrap-tools/Makefile @@ -40,12 +40,23 @@ BSARGS= DESTDIR= \ BOOTSTRAPPING=${OSRELDATE} \ BWPHASE=${.TARGET} \ SSP_CFLAGS= \ - MK_HTML=no NO_LINT=yes MK_MAN=no \ - -DNO_PIC MK_PROFILE=no -DNO_SHARED \ - -DNO_CPU_CFLAGS MK_WERROR=no MK_CTF=no \ - MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \ - MK_LLDB=no MK_TESTS=no \ - MK_INCLUDES=yes + -DNO_CPU_CFLAGS \ + -DNO_LINT \ + -DNO_PIC \ + -DNO_SHARED \ + MK_CTF=no \ + MK_CLANG_EXTRAS=no \ + MK_CLANG_FORMAT=no \ + MK_CLANG_FULL=no \ + MK_HTML=no \ + MK_LLDB=no \ + MK_MAN=no \ + MK_PROFILE=no \ + MK_RETPOLINE=no \ + MK_TESTS=no \ + MK_WERROR=no \ + MK_INCLUDES=yes \ + MK_MAN_UTILS=yes # We will handle building the toolchain and cross-compiler. BSARGS+= MK_CROSS_COMPILER=no MK_CLANG=no From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 17:24:41 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 56B61657D0E; Wed, 11 Aug 2021 17:24:41 +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 4GlGsP027Pz3jmh; Wed, 11 Aug 2021 17:24:40 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 D103C13359; Wed, 11 Aug 2021 17:24:40 +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 17BHOeFs026137; Wed, 11 Aug 2021 17:24:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BHOeUF026136; Wed, 11 Aug 2021 17:24:40 GMT (envelope-from git) Date: Wed, 11 Aug 2021 17:24:40 GMT Message-Id: <202108111724.17BHOeUF026136@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 952226eedb0b - stable/13 - Prefer MK_SSP=no to SSP_CFLAGS= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 952226eedb0be32b2c952fb2ae12f76a62131c00 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 17:24:41 -0000 The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=952226eedb0be32b2c952fb2ae12f76a62131c00 commit 952226eedb0be32b2c952fb2ae12f76a62131c00 Author: Mitchell Horne AuthorDate: 2021-08-04 18:20:50 +0000 Commit: Mitchell Horne CommitDate: 2021-08-11 16:56:28 +0000 Prefer MK_SSP=no to SSP_CFLAGS= It is more idiomatic. CFLAGS is only augmented with $SSP_CFLAGS when $MK_SSP != "no". Reviewed by: imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D31401 (cherry picked from commit 61ed578ee66648eff206ee5622b66727bfb52e78) --- Makefile.inc1 | 8 ++++---- Makefile.libcompat | 3 ++- lib/csu/Makefile.inc | 3 +-- lib/libclang_rt/Makefile.inc | 2 +- stand/defs.mk | 2 -- targets/pseudo/bootstrap-tools/Makefile | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index a03b79a5b02c..cc854fbebbb1 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -726,7 +726,6 @@ BSARGS= DESTDIR= \ MAKEOBJDIRPREFIX= \ BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \ BWPHASE=${.TARGET:C,^_,,} \ - SSP_CFLAGS= \ -DNO_CPU_CFLAGS \ -DNO_LINT \ -DNO_PIC \ @@ -740,6 +739,7 @@ BSARGS= DESTDIR= \ MK_MAN=no \ MK_PROFILE=no \ MK_RETPOLINE=no \ + MK_SSP=no \ MK_TESTS=no \ MK_WERROR=no \ MK_INCLUDES=yes \ @@ -759,7 +759,6 @@ TMAKE= \ DESTDIR= \ BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \ BWPHASE=${.TARGET:C,^_,,} \ - SSP_CFLAGS= \ -DNO_CPU_CFLAGS \ -DNO_LINT \ MK_CTF=no \ @@ -768,6 +767,7 @@ TMAKE= \ MK_CLANG_FULL=no \ MK_LLDB=no \ MK_RETPOLINE=no \ + MK_SSP=no \ MK_TESTS=no \ MK_WERROR=no @@ -792,7 +792,6 @@ KTMAKE= \ OBJROOT='$${OBJTOP}/' \ MAKEOBJDIRPREFIX= \ BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \ - SSP_CFLAGS= \ -DNO_CPU_CFLAGS \ -DNO_LINT \ -DNO_PIC \ @@ -801,6 +800,7 @@ KTMAKE= \ MK_HTML=no \ MK_MAN=no \ MK_PROFILE=no \ + MK_SSP=no \ MK_RETPOLINE=no \ MK_WERROR=no @@ -2780,7 +2780,6 @@ NXBMAKEARGS+= \ -DNO_SHARED \ -DNO_CPU_CFLAGS \ -DNO_PIC \ - SSP_CFLAGS= \ MK_CASPER=no \ MK_CLANG_EXTRAS=no \ MK_CLANG_FORMAT=no \ @@ -2797,6 +2796,7 @@ NXBMAKEARGS+= \ MK_RETPOLINE=no \ MK_SENDMAIL=no \ MK_SVNLITE=no \ + MK_SSP=no \ MK_TESTS=no \ MK_WERROR=no \ MK_ZFS=no diff --git a/Makefile.libcompat b/Makefile.libcompat index 7238c6faf898..3691050b9f69 100644 --- a/Makefile.libcompat +++ b/Makefile.libcompat @@ -99,7 +99,7 @@ build${libcompat}: .PHONY ${_+_}cd ${.CURDIR}/${_dir}; \ WORLDTMP=${WORLDTMP} \ MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \ - ${MAKE} SSP_CFLAGS= DESTDIR= \ + ${MAKE} DESTDIR= \ OBJTOP=${LIBCOMPAT_OBJTOP} \ OBJROOT='$${OBJTOP}/' \ MAKEOBJDIRPREFIX= \ @@ -108,6 +108,7 @@ build${libcompat}: .PHONY -DNO_CPU_CFLAGS \ MK_CTF=no \ MK_RETPOLINE=no \ + MK_SSP=no \ MK_WERROR=no \ ${_t} .endfor diff --git a/lib/csu/Makefile.inc b/lib/csu/Makefile.inc index 5681ef65117a..d39722847b4e 100644 --- a/lib/csu/Makefile.inc +++ b/lib/csu/Makefile.inc @@ -1,10 +1,9 @@ # $FreeBSD$ -SSP_CFLAGS= - NO_WMISSING_VARIABLE_DECLARATIONS= .include +MK_SSP= no .if !defined(BUILDING_TESTS) diff --git a/lib/libclang_rt/Makefile.inc b/lib/libclang_rt/Makefile.inc index 946d3f4c77a7..95fa32ba1f66 100644 --- a/lib/libclang_rt/Makefile.inc +++ b/lib/libclang_rt/Makefile.inc @@ -12,10 +12,10 @@ SHLIBDIR= ${LIBDIR} NO_PIC= MK_PROFILE= no +MK_SSP= no WARNS?= 0 -SSP_CFLAGS= CFLAGS+= -DNDEBUG CFLAGS+= -DHAVE_RPC_XDR_H=0 CFLAGS+= -DSANITIZER_SUPPORTS_WEAK_HOOKS=0 diff --git a/stand/defs.mk b/stand/defs.mk index d50c89879613..901c30666835 100644 --- a/stand/defs.mk +++ b/stand/defs.mk @@ -129,8 +129,6 @@ LD_FLAGS+= -m elf_i386_fbsd AFLAGS+= --32 .endif -SSP_CFLAGS= - # Add in the no float / no SIMD stuff and announce we're freestanding # aarch64 and riscv don't have -msoft-float, but all others do. CFLAGS+= -ffreestanding ${CFLAGS_NO_SIMD} diff --git a/targets/pseudo/bootstrap-tools/Makefile b/targets/pseudo/bootstrap-tools/Makefile index 1a7f2bd15ad0..3ac47053a388 100644 --- a/targets/pseudo/bootstrap-tools/Makefile +++ b/targets/pseudo/bootstrap-tools/Makefile @@ -39,7 +39,6 @@ BSARGS= DESTDIR= \ MAKEOBJDIRPREFIX= \ BOOTSTRAPPING=${OSRELDATE} \ BWPHASE=${.TARGET} \ - SSP_CFLAGS= \ -DNO_CPU_CFLAGS \ -DNO_LINT \ -DNO_PIC \ @@ -53,6 +52,7 @@ BSARGS= DESTDIR= \ MK_MAN=no \ MK_PROFILE=no \ MK_RETPOLINE=no \ + MK_SSP=no \ MK_TESTS=no \ MK_WERROR=no \ MK_INCLUDES=yes \ From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 17:25:11 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 32A76657ECC; Wed, 11 Aug 2021 17:25:11 +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 4GlGsz0wHCz3jsZ; Wed, 11 Aug 2021 17:25:11 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 0825C1335A; Wed, 11 Aug 2021 17:25:11 +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 17BHPA3k026341; Wed, 11 Aug 2021 17:25:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BHPAL9026340; Wed, 11 Aug 2021 17:25:10 GMT (envelope-from git) Date: Wed, 11 Aug 2021 17:25:10 GMT Message-Id: <202108111725.17BHPAL9026340@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 88ef00584bc7 - stable/12 - hwpmc: disable uncore class on Sandy Bridge and newer MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 88ef00584bc7f9f9e19546bc3ef8682d5c4d6cb6 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 17:25:11 -0000 The branch stable/12 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=88ef00584bc7f9f9e19546bc3ef8682d5c4d6cb6 commit 88ef00584bc7f9f9e19546bc3ef8682d5c4d6cb6 Author: Mitchell Horne AuthorDate: 2021-08-04 17:31:36 +0000 Commit: Mitchell Horne CommitDate: 2021-08-11 17:07:59 +0000 hwpmc: disable uncore class on Sandy Bridge and newer It was written for Nehalem and Westmere, with minor but incomplete updates for Sandy Bridge in 78d763a29b15. The uncore architecture changed significantly with this generation, bringing new layouts and locations for some MSRs. Misprogramming these MSRs in ucp_start_pmc() may panic the system, and this is trivially reproducible via pmcstat(8) on at least Broadwell and Haswell. Disable the class on these CPUs until it can be updated more completely and leave a TODO comment detailing some of the work required. Note that the nclasses value for Broadwell was already incorrect and doesn't need changing. The result is that any uncore events listed by pmcstat -L will no longer be allocatable, but this is already the case for newer generations of Intel CPUs. PR: 253687 Reported by: Zhenlei Huang Reviewed by: kib MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D31389 (cherry picked from commit 4f35e8cba232d9256ab1399b8adfb761988e5eff) --- sys/dev/hwpmc/hwpmc_intel.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_intel.c b/sys/dev/hwpmc/hwpmc_intel.c index aec037b64938..02b8fd9431d1 100644 --- a/sys/dev/hwpmc/hwpmc_intel.c +++ b/sys/dev/hwpmc/hwpmc_intel.c @@ -149,7 +149,7 @@ pmc_intel_initialize(void) break; case 0x2A: /* Per Intel document 253669-039US 05/2011. */ cputype = PMC_CPU_INTEL_SANDYBRIDGE; - nclasses = 5; + nclasses = 3; break; case 0x2D: /* Per Intel document 253669-044US 08/2012. */ cputype = PMC_CPU_INTEL_SANDYBRIDGE_XEON; @@ -195,7 +195,7 @@ pmc_intel_initialize(void) case 0x3C: /* Per Intel document 325462-045US 01/2013. */ case 0x45: /* Per Intel document 325462-045US 09/2014. */ cputype = PMC_CPU_INTEL_HASWELL; - nclasses = 5; + nclasses = 3; break; case 0x37: case 0x4A: @@ -275,10 +275,27 @@ pmc_intel_initialize(void) * Intel Corei7 and Westmere processors. */ case PMC_CPU_INTEL_COREI7: - case PMC_CPU_INTEL_HASWELL: - case PMC_CPU_INTEL_SANDYBRIDGE: case PMC_CPU_INTEL_WESTMERE: +#ifdef notyet + /* + * TODO: re-enable uncore class on these processors. + * + * The uncore unit was reworked beginning with Sandy Bridge, including + * the MSRs required to program it. In particular, we need to: + * - Parse the MSR_UNC_CBO_CONFIG MSR for number of C-box units in the + * system + * - Support reading and writing to ARB and C-box units, depending on + * the requested event + * - Create some kind of mapping between C-box <--> CPU + * + * Also TODO: support other later changes to these interfaces, to + * enable the uncore class on generations newer than Broadwell. + * Skylake+ appears to use newer addresses for the uncore MSRs. + */ + case PMC_CPU_INTEL_HASWELL: case PMC_CPU_INTEL_BROADWELL: + case PMC_CPU_INTEL_SANDYBRIDGE: +#endif error = pmc_uncore_initialize(pmc_mdep, ncpus); break; default: @@ -329,11 +346,13 @@ pmc_intel_finalize(struct pmc_mdep *md) * Uncore. */ switch (md->pmd_cputype) { - case PMC_CPU_INTEL_BROADWELL: case PMC_CPU_INTEL_COREI7: + case PMC_CPU_INTEL_WESTMERE: +#ifdef notyet case PMC_CPU_INTEL_HASWELL: + case PMC_CPU_INTEL_BROADWELL: case PMC_CPU_INTEL_SANDYBRIDGE: - case PMC_CPU_INTEL_WESTMERE: +#endif pmc_uncore_finalize(md); break; default: From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 17:25:12 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 67949658099; Wed, 11 Aug 2021 17:25:12 +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 4GlGt023d0z3jqK; Wed, 11 Aug 2021 17:25:12 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 2D6981335B; Wed, 11 Aug 2021 17:25:12 +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 17BHPCvA026369; Wed, 11 Aug 2021 17:25:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BHPC2v026368; Wed, 11 Aug 2021 17:25:12 GMT (envelope-from git) Date: Wed, 11 Aug 2021 17:25:12 GMT Message-Id: <202108111725.17BHPC2v026368@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: db26d3ca59a9 - stable/12 - mk: format some option lists MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: db26d3ca59a90185d73d3345398d3e3efcea6862 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 17:25:12 -0000 The branch stable/12 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=db26d3ca59a90185d73d3345398d3e3efcea6862 commit db26d3ca59a90185d73d3345398d3e3efcea6862 Author: Mitchell Horne AuthorDate: 2021-08-04 18:17:34 +0000 Commit: Mitchell Horne CommitDate: 2021-08-11 17:15:50 +0000 mk: format some option lists Alphabetize and give each option its own line, ahead of making another change to these lists. This makes future diffs easier to read. Reviewed by: imp, emaste MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D31399 (cherry picked from commit bcd2f41f7d222a942fe0a268614b46d3ec3af4c0) --- Makefile.inc1 | 45 +++++++++++++++++++++++++-------- Makefile.libcompat | 8 ++++-- targets/pseudo/bootstrap-tools/Makefile | 19 ++++++++++---- 3 files changed, 54 insertions(+), 18 deletions(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index be0d0d2a2334..d7e05df9ae24 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -656,11 +656,21 @@ BSARGS= DESTDIR= \ BOOTSTRAPPING=${OSRELDATE} \ BWPHASE=${.TARGET:C,^_,,} \ SSP_CFLAGS= \ - MK_HTML=no NO_LINT=yes MK_MAN=no \ - -DNO_PIC MK_PROFILE=no -DNO_SHARED \ - -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \ - MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \ - MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no \ + -DNO_CPU_CFLAGS \ + -DNO_LINT \ + -DNO_PIC \ + -DNO_SHARED \ + MK_CTF=no \ + MK_CLANG_EXTRAS=no \ + MK_CLANG_FORMAT=no \ + MK_CLANG_FULL=no \ + MK_HTML=no \ + MK_LLDB=no \ + MK_MAN=no \ + MK_PROFILE=no \ + MK_RETPOLINE=no \ + MK_TESTS=no \ + MK_WARNS=no \ MK_INCLUDES=yes BMAKE= \ @@ -678,10 +688,16 @@ TMAKE= \ BOOTSTRAPPING=${OSRELDATE} \ BWPHASE=${.TARGET:C,^_,,} \ SSP_CFLAGS= \ + -DNO_CPU_CFLAGS \ -DNO_LINT \ - -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \ - MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \ - MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no + MK_CTF=no \ + MK_CLANG_EXTRAS=no \ + MK_CLANG_FORMAT=no \ + MK_CLANG_FULL=no \ + MK_LLDB=no \ + MK_RETPOLINE=no \ + MK_TESTS=no \ + MK_WARNS=no # cross-tools stage # TOOLS_PREFIX set in BMAKE @@ -703,9 +719,16 @@ KTMAKE= \ MAKEOBJDIRPREFIX= \ BOOTSTRAPPING=${OSRELDATE} \ SSP_CFLAGS= \ - MK_HTML=no -DNO_LINT MK_MAN=no \ - -DNO_PIC MK_PROFILE=no -DNO_SHARED \ - -DNO_CPU_CFLAGS MK_RETPOLINE=no MK_WARNS=no MK_CTF=no + -DNO_CPU_CFLAGS \ + -DNO_LINT \ + -DNO_PIC \ + -DNO_SHARED \ + MK_CTF=no \ + MK_HTML=no \ + MK_MAN=no \ + MK_PROFILE=no \ + MK_RETPOLINE=no \ + MK_WARNS=no # world stage WMAKEENV= ${CROSSENV} \ diff --git a/Makefile.libcompat b/Makefile.libcompat index a2a6bb607fdc..4e5a8dd8ae73 100644 --- a/Makefile.libcompat +++ b/Makefile.libcompat @@ -201,8 +201,12 @@ build${libcompat}: .PHONY OBJTOP=${LIBCOMPAT_OBJTOP} \ OBJROOT='$${OBJTOP}/' \ MAKEOBJDIRPREFIX= \ - DIRPRFX=${_dir}/ -DNO_LINT -DNO_CPU_CFLAGS \ - MK_CTF=no MK_RETPOLINE=no MK_WARNS=no \ + DIRPRFX=${_dir}/ \ + -DNO_LINT \ + -DNO_CPU_CFLAGS \ + MK_CTF=no \ + MK_RETPOLINE=no \ + MK_WARNS=no \ ${_t} .endfor .endfor diff --git a/targets/pseudo/bootstrap-tools/Makefile b/targets/pseudo/bootstrap-tools/Makefile index d860a50836b1..7ab8032157c3 100644 --- a/targets/pseudo/bootstrap-tools/Makefile +++ b/targets/pseudo/bootstrap-tools/Makefile @@ -40,11 +40,20 @@ BSARGS= DESTDIR= \ BOOTSTRAPPING=${OSRELDATE} \ BWPHASE=${.TARGET} \ SSP_CFLAGS= \ - MK_HTML=no NO_LINT=yes MK_MAN=no \ - -DNO_PIC MK_PROFILE=no -DNO_SHARED \ - -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \ - MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \ - MK_LLDB=no MK_TESTS=no \ + -DNO_CPU_CFLAGS \ + -DNO_LINT \ + -DNO_PIC \ + -DNO_SHARED \ + MK_CTF=no \ + MK_CLANG_EXTRAS=no \ + MK_CLANG_FORMAT=no \ + MK_CLANG_FULL=no \ + MK_HTML=no \ + MK_LLDB=no \ + MK_MAN=no \ + MK_PROFILE=no \ + MK_TESTS=no \ + MK_WARNS=no \ MK_INCLUDES=yes # We will handle building the toolchain and cross-compiler. From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 17:25:13 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DB8CE657D33; Wed, 11 Aug 2021 17:25:13 +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 4GlGt14H2Tz3jnS; Wed, 11 Aug 2021 17:25:13 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 58D761365D; Wed, 11 Aug 2021 17:25:13 +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 17BHPDC6026398; Wed, 11 Aug 2021 17:25:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BHPDgT026397; Wed, 11 Aug 2021 17:25:13 GMT (envelope-from git) Date: Wed, 11 Aug 2021 17:25:13 GMT Message-Id: <202108111725.17BHPDgT026397@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 62bee146aa42 - stable/12 - Prefer MK_SSP=no to SSP_CFLAGS= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 62bee146aa42276264008df1d2190ca94eef26cd Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 17:25:14 -0000 The branch stable/12 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=62bee146aa42276264008df1d2190ca94eef26cd commit 62bee146aa42276264008df1d2190ca94eef26cd Author: Mitchell Horne AuthorDate: 2021-08-04 18:20:50 +0000 Commit: Mitchell Horne CommitDate: 2021-08-11 17:20:01 +0000 Prefer MK_SSP=no to SSP_CFLAGS= It is more idiomatic. CFLAGS is only augmented with $SSP_CFLAGS when $MK_SSP != "no". Reviewed by: imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D31401 (cherry picked from commit 61ed578ee66648eff206ee5622b66727bfb52e78) --- Makefile.inc1 | 8 ++++---- Makefile.libcompat | 3 ++- lib/csu/Makefile.inc | 3 +-- lib/libclang_rt/Makefile.inc | 2 +- stand/defs.mk | 2 -- targets/pseudo/bootstrap-tools/Makefile | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index d7e05df9ae24..08574880be97 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -655,7 +655,6 @@ BSARGS= DESTDIR= \ MAKEOBJDIRPREFIX= \ BOOTSTRAPPING=${OSRELDATE} \ BWPHASE=${.TARGET:C,^_,,} \ - SSP_CFLAGS= \ -DNO_CPU_CFLAGS \ -DNO_LINT \ -DNO_PIC \ @@ -669,6 +668,7 @@ BSARGS= DESTDIR= \ MK_MAN=no \ MK_PROFILE=no \ MK_RETPOLINE=no \ + MK_SSP=no \ MK_TESTS=no \ MK_WARNS=no \ MK_INCLUDES=yes @@ -687,7 +687,6 @@ TMAKE= \ DESTDIR= \ BOOTSTRAPPING=${OSRELDATE} \ BWPHASE=${.TARGET:C,^_,,} \ - SSP_CFLAGS= \ -DNO_CPU_CFLAGS \ -DNO_LINT \ MK_CTF=no \ @@ -696,6 +695,7 @@ TMAKE= \ MK_CLANG_FULL=no \ MK_LLDB=no \ MK_RETPOLINE=no \ + MK_SSP=no \ MK_TESTS=no \ MK_WARNS=no @@ -718,7 +718,6 @@ KTMAKE= \ OBJROOT='$${OBJTOP}/' \ MAKEOBJDIRPREFIX= \ BOOTSTRAPPING=${OSRELDATE} \ - SSP_CFLAGS= \ -DNO_CPU_CFLAGS \ -DNO_LINT \ -DNO_PIC \ @@ -727,6 +726,7 @@ KTMAKE= \ MK_HTML=no \ MK_MAN=no \ MK_PROFILE=no \ + MK_SSP=no \ MK_RETPOLINE=no \ MK_WARNS=no @@ -2499,7 +2499,6 @@ NXBMAKEARGS+= \ -DNO_SHARED \ -DNO_CPU_CFLAGS \ -DNO_PIC \ - SSP_CFLAGS= \ MK_CLANG_EXTRAS=no \ MK_CLANG_FORMAT=no \ MK_CLANG_FULL=no \ @@ -2516,6 +2515,7 @@ NXBMAKEARGS+= \ MK_RETPOLINE=no \ MK_SENDMAIL=no \ MK_SVNLITE=no \ + MK_SSP=no \ MK_TESTS=no \ MK_WARNS=no \ MK_ZFS=no diff --git a/Makefile.libcompat b/Makefile.libcompat index 4e5a8dd8ae73..89509a266af0 100644 --- a/Makefile.libcompat +++ b/Makefile.libcompat @@ -197,7 +197,7 @@ build${libcompat}: .PHONY ${_+_}cd ${.CURDIR}/${_dir}; \ WORLDTMP=${WORLDTMP} \ MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \ - ${MAKE} SSP_CFLAGS= DESTDIR= \ + ${MAKE} DESTDIR= \ OBJTOP=${LIBCOMPAT_OBJTOP} \ OBJROOT='$${OBJTOP}/' \ MAKEOBJDIRPREFIX= \ @@ -206,6 +206,7 @@ build${libcompat}: .PHONY -DNO_CPU_CFLAGS \ MK_CTF=no \ MK_RETPOLINE=no \ + MK_SSP=no \ MK_WARNS=no \ ${_t} .endfor diff --git a/lib/csu/Makefile.inc b/lib/csu/Makefile.inc index 93bf9672db04..5aa2132fe8c4 100644 --- a/lib/csu/Makefile.inc +++ b/lib/csu/Makefile.inc @@ -1,12 +1,11 @@ # $FreeBSD$ -SSP_CFLAGS= - SED_FIX_NOTE = -i "" -e '/\.note\.tag/s/progbits/note/' NO_WMISSING_VARIABLE_DECLARATIONS= .include +MK_SSP= no .if ${MK_BSD_CRTBEGIN} != "no" && !defined(BUILDING_TESTS) diff --git a/lib/libclang_rt/Makefile.inc b/lib/libclang_rt/Makefile.inc index f2f25843dda3..07b66015acb1 100644 --- a/lib/libclang_rt/Makefile.inc +++ b/lib/libclang_rt/Makefile.inc @@ -20,10 +20,10 @@ SHLIBDIR= ${LIBDIR} NO_PIC= MK_PROFILE= no +MK_SSP= no WARNS?= 0 -SSP_CFLAGS= CFLAGS+= -DNDEBUG CFLAGS+= -DHAVE_RPC_XDR_H=0 CFLAGS+= -DSANITIZER_SUPPORTS_WEAK_HOOKS=0 diff --git a/stand/defs.mk b/stand/defs.mk index 3f440d9017f8..c81be884f3ae 100644 --- a/stand/defs.mk +++ b/stand/defs.mk @@ -120,8 +120,6 @@ LD_FLAGS+= -m elf_i386_fbsd AFLAGS+= --32 .endif -SSP_CFLAGS= - # Add in the no float / no SIMD stuff and announce we're freestanding # aarch64 and riscv don't have -msoft-float, but all others do. riscv # currently has no /boot/loader, but may soon. diff --git a/targets/pseudo/bootstrap-tools/Makefile b/targets/pseudo/bootstrap-tools/Makefile index 7ab8032157c3..1a973dc7fc18 100644 --- a/targets/pseudo/bootstrap-tools/Makefile +++ b/targets/pseudo/bootstrap-tools/Makefile @@ -39,7 +39,6 @@ BSARGS= DESTDIR= \ MAKEOBJDIRPREFIX= \ BOOTSTRAPPING=${OSRELDATE} \ BWPHASE=${.TARGET} \ - SSP_CFLAGS= \ -DNO_CPU_CFLAGS \ -DNO_LINT \ -DNO_PIC \ @@ -52,6 +51,7 @@ BSARGS= DESTDIR= \ MK_LLDB=no \ MK_MAN=no \ MK_PROFILE=no \ + MK_SSP=no \ MK_TESTS=no \ MK_WARNS=no \ MK_INCLUDES=yes From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 21:14:02 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 58BC065BE0F; Wed, 11 Aug 2021 21:14:02 +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 4GlMy226mDz4Xh6; Wed, 11 Aug 2021 21:14:02 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 30C191688D; Wed, 11 Aug 2021 21:14:02 +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 17BLE2QI033655; Wed, 11 Aug 2021 21:14:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BLE25k033654; Wed, 11 Aug 2021 21:14:02 GMT (envelope-from git) Date: Wed, 11 Aug 2021 21:14:02 GMT Message-Id: <202108112114.17BLE25k033654@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 3e4aeeb95df2 - stable/13 - m_dup: Handle unmapped mbufs as an input mbuf. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3e4aeeb95df217fdd9ec21e5a86ec61d1b2abc59 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 21:14:02 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=3e4aeeb95df217fdd9ec21e5a86ec61d1b2abc59 commit 3e4aeeb95df217fdd9ec21e5a86ec61d1b2abc59 Author: John Baldwin AuthorDate: 2021-07-26 21:03:28 +0000 Commit: John Baldwin CommitDate: 2021-08-11 19:18:46 +0000 m_dup: Handle unmapped mbufs as an input mbuf. Use m_copydata() instead of a direct bcopy() when copying data out of a source mbuf into a newly-allocated mbuf. PR: 256610 Reported by: Niels Bakker Reviewed by: markj MFC after: 2 weeks (cherry picked from commit be79f30d6c3e353856d4f82227b270abc26be702) --- sys/kern/uipc_mbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index f7852bc7dd7f..f525c25d1431 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -719,7 +719,7 @@ m_dup(const struct mbuf *m, int how) while (n->m_len < nsize && m != NULL) { int chunk = min(nsize - n->m_len, m->m_len - moff); - bcopy(m->m_data + moff, n->m_data + n->m_len, chunk); + m_copydata(m, moff, chunk, n->m_data + n->m_len); moff += chunk; n->m_len += chunk; remain -= chunk; From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 22:14:12 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 954C665D405; Wed, 11 Aug 2021 22:14:12 +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 4GlPHS3mHBz4fDS; Wed, 11 Aug 2021 22:14:12 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 64C7817502; Wed, 11 Aug 2021 22:14:12 +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 17BMEC77013780; Wed, 11 Aug 2021 22:14:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BMECJR013777; Wed, 11 Aug 2021 22:14:12 GMT (envelope-from git) Date: Wed, 11 Aug 2021 22:14:12 GMT Message-Id: <202108112214.17BMECJR013777@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 525024fc9cbf - stable/13 - Refactor configuration management in bhyve. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 525024fc9cbfcafe9470cdaf1d4aedec62b6fa6d Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 22:14:12 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=525024fc9cbfcafe9470cdaf1d4aedec62b6fa6d commit 525024fc9cbfcafe9470cdaf1d4aedec62b6fa6d Author: John Baldwin AuthorDate: 2019-06-26 20:30:41 +0000 Commit: John Baldwin CommitDate: 2021-08-11 22:11:39 +0000 Refactor configuration management in bhyve. Replace the existing ad-hoc configuration via various global variables with a small database of key-value pairs. The database supports heirarchical keys using a MIB-like syntax to name the path to a given key. Values are always stored as strings. The API used to manage configuation values does include wrappers to handling boolean values. Other values use non-string types require parsing by consumers. The configuration values are stored in a tree using nvlists. Leaf nodes hold string values. Configuration values are permitted to reference other configuration values using '%(name)'. This permits constructing template configurations. All existing command line arguments now set configuration values. For devices, the "-s" option parses its option argument to generate a list of key-value pairs for the given device. A new '-o' command line option permits setting an individual configuration variable. The key name is always given as a full path of dot-separated components. A new '-k' command line option parses a simple configuration file. This configuration file holds a flat list of 'key=value' lines where the 'key' is the full path of a configuration variable. Lines starting with a '#' are comments. In general, bhyve starts by parsing command line options in sequence and applying those settings to configuration values. Once this is complete, bhyve then begins initializing its state based on the configuration values. This means that subsequent configuration options or files may override or supplement previously given settings. A special 'config.dump' configuration value can be set to true to help debug configuration issues. When this value is set, bhyve will print out the configuration variables as a flat list of 'key=value' lines. Most command line argments map to a single configuration variable, e.g. '-w' sets the 'x86.strictmsr' value to false. A few command line arguments have less obvious effects: - Multiple '-p' options append their values (as a comma-seperated list) to "vcpu.N.cpuset" values (where N is a decimal vcpu number). - For '-s' options, a pci... node is created. The first argument to '-s' (the device type) is used as the value of a "device" variable. Additional comma-separated arguments are then parsed into 'key=value' pairs and used to set additional variables under the device node. A PCI device emulation driver can provide its own hook to override the parsing of the additonal '-s' arguments after the device type. After the configuration phase as completed, the init_pci hook then walks the "pci..." nodes. It uses the "device" value to find the device model to use. The device model's init routine is passed a reference to its nvlist node in the configuration tree which it can query for specific variables. The result is that a lot of the string parsing is removed from the device models and centralized. In addition, adding a new variable just requires teaching the model to look for the new variable. - For '-l' options, a similar model is used where the string is parsed into values that are later read during initialization. One key note here is that the serial ports use the commonly used lowercase names from existing documentation and examples (e.g. "lpc.com1") instead of the uppercase names previously used internally in bhyve. Reviewed by: grehan MFC after: 3 months Differential Revision: https://reviews.freebsd.org/D26035 (cherry picked from commit 621b5090487de9fed1b503769702a9a2a27cc7bb) --- usr.sbin/bhyve/Makefile | 5 +- usr.sbin/bhyve/bhyve.8 | 47 ++- usr.sbin/bhyve/bhyve_config.5 | 560 ++++++++++++++++++++++++++++++++++++ usr.sbin/bhyve/bhyverun.c | 485 ++++++++++++++++++++----------- usr.sbin/bhyve/bhyverun.h | 7 +- usr.sbin/bhyve/block_if.c | 98 ++++--- usr.sbin/bhyve/block_if.h | 4 +- usr.sbin/bhyve/config.c | 431 +++++++++++++++++++++++++++ usr.sbin/bhyve/config.h | 119 ++++++++ usr.sbin/bhyve/gdb.c | 12 + usr.sbin/bhyve/hda_codec.c | 6 +- usr.sbin/bhyve/inout.c | 6 +- usr.sbin/bhyve/inout.h | 3 +- usr.sbin/bhyve/mevent.c | 2 - usr.sbin/bhyve/mevent_test.c | 2 - usr.sbin/bhyve/net_backends.c | 106 +++---- usr.sbin/bhyve/net_backends.h | 3 +- usr.sbin/bhyve/net_utils.c | 5 +- usr.sbin/bhyve/net_utils.h | 2 +- usr.sbin/bhyve/pci_ahci.c | 283 ++++++++++-------- usr.sbin/bhyve/pci_e82545.c | 65 +---- usr.sbin/bhyve/pci_emul.c | 147 +++++++--- usr.sbin/bhyve/pci_emul.h | 7 +- usr.sbin/bhyve/pci_fbuf.c | 194 +++++++------ usr.sbin/bhyve/pci_hda.c | 95 ++---- usr.sbin/bhyve/pci_hda.h | 2 +- usr.sbin/bhyve/pci_hostbridge.c | 32 ++- usr.sbin/bhyve/pci_lpc.c | 60 ++-- usr.sbin/bhyve/pci_nvme.c | 164 +++++------ usr.sbin/bhyve/pci_passthru.c | 47 ++- usr.sbin/bhyve/pci_uart.c | 19 +- usr.sbin/bhyve/pci_virtio_9p.c | 80 +++--- usr.sbin/bhyve/pci_virtio_block.c | 15 +- usr.sbin/bhyve/pci_virtio_console.c | 131 +++++++-- usr.sbin/bhyve/pci_virtio_net.c | 97 +++---- usr.sbin/bhyve/pci_virtio_rnd.c | 2 +- usr.sbin/bhyve/pci_virtio_scsi.c | 49 ++-- usr.sbin/bhyve/pci_xhci.c | 220 +++++++++----- usr.sbin/bhyve/pctestdev.c | 9 - usr.sbin/bhyve/pctestdev.h | 1 - usr.sbin/bhyve/rtc.c | 9 +- usr.sbin/bhyve/rtc.h | 2 +- usr.sbin/bhyve/smbiostbl.c | 5 + usr.sbin/bhyve/uart_emul.c | 12 +- usr.sbin/bhyve/uart_emul.h | 2 +- usr.sbin/bhyve/usb_emul.c | 2 +- usr.sbin/bhyve/usb_emul.h | 5 +- usr.sbin/bhyve/usb_mouse.c | 5 +- 48 files changed, 2593 insertions(+), 1071 deletions(-) diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile index a4fc3deea77e..e35d528ab605 100644 --- a/usr.sbin/bhyve/Makefile +++ b/usr.sbin/bhyve/Makefile @@ -10,7 +10,7 @@ CFLAGS+=-I${SRCTOP}/sys PROG= bhyve PACKAGE= bhyve -MAN= bhyve.8 +MAN= bhyve.8 bhyve_config.5 BHYVE_SYSDIR?=${SRCTOP} @@ -22,6 +22,7 @@ SRCS= \ bhyverun.c \ block_if.c \ bootrom.c \ + config.c \ console.c \ ctl_util.c \ ctl_scsi_all.c \ @@ -83,7 +84,7 @@ CFLAGS.kernemu_dev.c+= -I${SRCTOP}/sys/amd64 .PATH: ${BHYVE_SYSDIR}/sys/amd64/vmm SRCS+= vmm_instruction_emul.c -LIBADD= vmmapi md pthread z util sbuf cam 9p +LIBADD= vmmapi md nv pthread z util sbuf cam 9p .if ${MK_CASPER} != "no" LIBADD+= casper diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8 index 115727a136a7..04e22302d9d7 100644 --- a/usr.sbin/bhyve/bhyve.8 +++ b/usr.sbin/bhyve/bhyve.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 18, 2021 +.Dd March 18, 2021 .Dt BHYVE 8 .Os .Sh NAME @@ -46,6 +46,7 @@ .Oc .Sm on .Op Fl G Ar port +.Op Fl k Ar file .Oo Fl l .Sm off .Cm help | Ar lpcdev Op Cm \&, Ar conf @@ -59,6 +60,7 @@ .Oc .Sm on .Oc +.Op Fl o Ar var Ns Cm = Ns Ar value .Op Fl p Ar vcpu Ns Cm \&: Ns Ar hostcpu .Op Fl r Ar file .Oo Fl s @@ -149,6 +151,17 @@ Print help message and exit. .It Fl H Yield the virtual CPU thread when a HLT instruction is detected. If this option is not specified, virtual CPUs will use 100% of a host CPU. +.It Fl k Ar file +Set configuration variables from a simple, key-value config file. +Each line of the config file is expected to consist of a config variable +name, an equals sign +.Pq Sq = , +and a value. +No spaces are permitted between the variable name, equals sign, or +value. +Blank lines and lines starting with +.Sq # +are ignored. .It Fl l Op Ar help|lpcdev Ns Op , Ns Ar conf Allow devices behind the LPC PCI-ISA bridge to be configured. The only supported devices are the TTY-class devices @@ -174,6 +187,11 @@ If no suffix is given, the value is assumed to be in megabytes. .Pp .Ar memsize defaults to 256M. +.It Fl o Ar var Ns Cm = Ns Ar value +Set the configuration variable +.Ar var +to +.Ar value . .It Fl p Ar vcpu:hostcpu Pin guest's virtual CPU .Em vcpu @@ -594,6 +612,32 @@ Alphanumeric name of the guest. This should be the same as that created by .Xr bhyveload 8 . .El +.Sh CONFIGURATION VARIABLES +.Nm +uses an internal tree of configuration variables to describe global and +per-device settings. +When +.Nm +starts, +it parses command line options (including config files) in the order given +on the command line. +Each command line option sets one or more configuration variables. +For example, +the +.Fl s +option creates a new tree node for a PCI device and sets one or more variables +under that node including the device model and device model-specific variables. +Variables may be set multiple times during this parsing stage with the final +value overriding previous values. +.Pp +Once all of the command line options have been processed, +the configuration values are frozen. +.Nm +then uses the value of configuration values to initialize device models +and global settings. +.Pp +More details on configuration variables can be found in +.Xr bhyve_config 5 . .Sh DEBUG SERVER The current debug server provides limited support for debuggers. .Ss Registers @@ -717,6 +761,7 @@ bhyve -c 2 -m 4G -w -H \\ .Xr ng_socket 4 , .Xr nmdm 4 , .Xr vmm 4 , +.Xr bhyve_config 5 , .Xr ethers 5 , .Xr bhyvectl 8 , .Xr bhyveload 8 diff --git a/usr.sbin/bhyve/bhyve_config.5 b/usr.sbin/bhyve/bhyve_config.5 new file mode 100644 index 000000000000..4e200a779d50 --- /dev/null +++ b/usr.sbin/bhyve/bhyve_config.5 @@ -0,0 +1,560 @@ +.\" SPDX-License-Identifier: BSD-2-Clause +.\" +.\" Copyright (c) 2021 John H. Baldwin +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd March 18, 2021 +.Dt BHYVE_CONFIG 5 +.Os +.Sh NAME +.Nm bhyve_config +.Nd "bhyve configuration variables" +.Sh DESCRIPTION +.Xr bhyve 8 +uses a hierarchical tree of configuration variables to describe global and +per-device settings. +Internal nodes in this tree do not have a value, +only leaf nodes have values. +This manual describes the configuration variables understood by +.Xr bhyve 8 . +If additional variables are defined, +.Xr bhyve 8 +will ignore them and will not emit errors for unknown variables. +However, these additional variables can be referenced by other +variables as described below. +.Sh VARIABLE VALUES +Configuration variable values are stored as strings. +A configuration variable value may refer to one or more other +configuration values by name. +Instances of the pattern +.Sq % Ns Pq Ar var +are replaced by the value of the configuration variable +.Va var . +To avoid unwanted expansion, +.Sq % +characters can be escaped by a leading +.Sq % . +For example, +if a configuration variable +.Va disk +uses the value +.Pa /dev/zvol/bhyve/%(name) , +then the final value of the +.Va disk +variable will be set to the path of a ZFS volume whose name matches +the name of the virtual machine on the pool +.Pa bhyve . +.Pp +Some configuration variables may be interpreted as a boolean value. +For those variables the following case-insensitive values may be used to +indicate true: +.Pp +.Bl -bullet -offset indent -compact +.It +true +.It +on +.It +yes +.It +1 +.El +.Pp +The following values may be used to indicate false: +.Pp +.Bl -bullet -offset indent -compact +.It +false +.It +off +.It +no +.It +0 +.El +.Pp +Some configuration variables may be interperted as an integer. +For those variables, +any syntax supported by +.Xr strtol 3 +may be used. +.Sh GLOBAL SETTINGS +.Ss Architecture Neutral Settings +.Bl -column "memory.guest_in_core" "integer" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va name Ta string Ta Ta +The name of the VM. +.It Va cpus Ta integer Ta 1 Ta +The total number of virtual CPUs. +.It Va cores Ta integer Ta 1 Ta +The number of virtual cores in each virtual socket. +.It Va threads Ta integer Ta 1 Ta +The number of virtual CPUs in each virtual core. +.It Va sockets Ta integer Ta 1 Ta +The number of virtual sockets. +.It Va memory.guest_in_core Ta bool Ta false Ta +Include guest memory in core file. +.It Va memory.size Ta string Ta 256M Ta +Guest physical memory size in bytes. +The value must be formatted as described in +.Xr expand_number 3 . +.It Va memory.wired Ta bool Ta false Ta +Wire guest memory. +.It Va acpi_tables Ta bool Ta false Ta +Generate ACPI tables. +.It Va destroy_on_poweroff Ta bool Ta false Ta +Destroy the VM on guest-initiated power-off. +.It Va gdb.port Ta integer Ta 0 Ta +TCP port number for the debug server. +If this is set to a non-zero value, a debug server +will listen for connections on this port. +.It Va gdb.wait Ta bool Ta false Ta +If the debug server is enabled, wait for a debugger to connect +before starting the guest. +.It Va rtc.use_localtime Ta bool Ta true Ta +The real time clock uses the local time of the host. +If this is set to false, the real time clock uses UTC. +.It Va uuid Ta string Ta Ta +The universally unique identifier (UUID) to use in the guest's +System Management BIOS System Information structure. +If an explicit value is not set, a valid UUID is generated from +the host's hostname and the VM name. +.It Va virtio_msix Ta bool Ta true Ta +Use MSI-X interrupts for PCI VirtIO devices. +If set to false, MSI interrupts are used instead. +.It Va config.dump Ta bool Ta false Ta +If this value is set to true, +then +.Xr bhyve 8 +will write all of its configuration variables to stdout and exit +after it has finished parsing command line options. +.El +.Ss x86-Specific Settings +.Bl -column "x86.vmexit_on_pause" "integer" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va x86.mptable Ta bool Ta true Ta +Generate an MPTable. +.It Va x86.x2apic Ta bool Ta false Ta +Configure guest's local APICs in x2APIC mode. +.It Va x86.strictio Ta bool Ta false Ta +Exit if a guest accesses an I/O port that is not emulated. +By default, writes are ignored and reads return all bits set. +.It Va x86.strictmsr Ta bool Ta true Ta +Inject a general protection fault if a guest accesses a Model Specific +Register (MSR) that is not emulated. +If this is false, writes are ignored and reads return zero. +.It Va x86.vmexit_on_hlt Ta bool Ta false Ta +Force a VM exit when a guest CPU executes the +.Dv HLT +instruction. +This allows idle guest CPUs to yield the host CPU. +.It Va x86.vmexit_on_pause Ta bool Ta false Ta +Force a VM exit when a guest CPU executes the +.Dv PAUSE +instruction. +.El +.Sh DEVICE SETTINGS +Device settings are stored under a device node. +The device node's name is set by the parent bus of the device. +.Ss PCI Device Settings +PCI devices are described by a device node named +.Dq pci Ns Ar bus . Ns Ar slot . Ns Ar function +where each of +.Ar bus , +.Ar slot , +and +.Ar function +are formatted as decimal values with no padding. +All PCI device nodes must contain a configuration variable named +.Dq device +which specifies the device model to use. +The following PCI device models are supported: +.Bl -tag -indent +.It Li hostbridge +Provide a simple PCI-Host bridge device. +This is usually configured at pci0:0:0 and is required by most guest +operating systems. +.It Li ahci +AHCI storage controller. +.It Li e1000 +Intel e82545 network interface. +.It Li fbuf +VGA framebuffer device attached to VNC server. +.It Li lpc +LPC PCI-ISA bridge with COM1-COM4 16550 serial ports, +a boot ROM, +and an optional debug/test device. +This device must be configured on bus 0. +.It Li hda +High Definition audio controller. +.It Li nvme +NVM Express (NVMe) controller. +.It Li passthru +PCI pass-through device. +.It Li uart +PCI 16550 serial device. +.It Li virtio-9p +VirtIO 9p (VirtFS) interface. +.It Li virtio-blk +VirtIO block storage interface. +.It Li virtio-console +VirtIO console interface. +.It Li virtio-net +VirtIO network interface. +.It Li virtio-rnd +VirtIO RNG interface. +.It Li virtio-scsi +VirtIO SCSI interface. +.It Li xhci +Extensible Host Controller Interface (XHCI) USB controller. +.El +.Ss USB Device Settings +USB controller devices contain zero or more child USB devices +attached to slots. +Each USB device stores its settings in a node named +.Dq slot. Ns Va N +under the controller's device node. +.Va N +is the number of the slot to which the USB device is attached. +Note that USB slot numbers begin at 1. +All USB device nodes must contain a configuration variable named +.Dq device +which specifies the device model to use. +The following USB device models are supported: +.Bl -tag -indent +.It Li tablet +A USB tablet device which provides precise cursor synchronization +when using VNC. +.El +.Ss Block Device Settings +Block devices use the following settings to configure their backing store. +These settings are stored in the configuration node of the respective device. +.Bl -column "sectorsize" "logical[/physical]" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It path Ta string Ta Ta +The path of the file or disk device to use as the backing store. +.It nocache Ta bool Ta false Ta +Disable caching on the backing file by opening the backing file with +.Dv O_DIRECT . +.It nodelete Ta bool Ta false Ta +Disable emulation of guest trim requests via +.Dv DIOCGDELETE +requests. +.It sync Ta bool Ta false Ta +Write changes to the backing file with synchronous writes. +.It direct Ta bool Ta false Ta +An alias for +.Va sync . +.It ro Ta bool Ta false Ta +Disable writes to the backing file. +.It sectorsize Ta Va logical Ns Op / Ns Va physical Ta Ta +Specify the logical and physical sector size of the emulated disk. +If the physical size is not specified, +it is equal to the logical size. +.El +.Ss Network Backend Settings +Network devices use the following settings to configure their backend. +The backend is responsible for passing packets between the device model +and a desired destination. +Configuring a backend requires setting the +.Va backend +variable to one of the following values: +.Bl -tag +.It tap Ns Va N +Use the named +.Xr tap 4 +interface as the backend. +.It vmnet Ns Va N +Use the named +.Xr vmnet 4 +interface as the backend. +.It netgraph +Use a +.Xr netgraph 4 +socket hook as the backend. +This backend uses the following additional variables: +.Bl -column "peerhook" "Format" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va path Ta string Ta Ta +The name of the +.Xr netgraph 4 +destination node. +.It Va peerhook Ta string Ta Ta +The name of the destination hook. +.It Va socket Ta string Ta Ta +The name of the created +.Xr ng_socket 4 +node. +.It Va hook Ta string Ta vmlink Ta +The name of the source hook on the created +.Xr ng_socket 4 +node. +.El +.It netmap: Ns Va interface +Use +.Xr netmap 4 +on a network interface as the backend. +.It vale Ns Va bridge : Ns Va port +Use a port on a +.Xr vale 4 +bridge as the backend. +.El +.Ss UART Device Settings +.Bl -column "Name" "Format" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va path Ta path Ta Ta +Backend device for the serial port. +Either the pathname of a character device or +.Dq stdio +to use standard input and output of the +.Xr bhyve 8 +process. +.El +.Ss Host Bridge Settings +.Bl -column "vendor" "integer" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va vendor Ta integer Ta 0x1275 Ta +PCI vendor ID. +.It Va device Ta integer Ta 0x1275 Ta +PCI device ID. +.El +.Ss AHCI Controller Settings +AHCI controller devices contain zero or more ports each of which +provides a storage device. +Each port stores its settings in a node named +.Dq port. Ns Va N +under the controller's device node. +The +.Va N +values are formatted as successive decimal values starting with 0. +In addition to the block device settings described above, each +port supports the following settings: +.Bl -column "model" "integer" "generated" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va type Ta string Ta Ta +The type of storage device to emulate. +Must be set to either +.Dq cd +or +.Dq hd . +.It Va nmrr Ta integer Ta 0 Ta +Nominal Media Rotation Rate, also known as RPM. +A value 1 of indicates a device with no rate such as a Solid State Disk. +.It Va ser Ta string Ta generated Ta +Serial number of up to twenty characters. +A default serial number is generated using a hash of the backing +store's pathname. +.It Va rev Ta string Ta 001 Ta +Revision number of up to eight characters. +.It Va model Ta string Ta Ta +Model number of up to forty characters. +Separate default model strings are used for +.Dq cd +and +.Dq hd +device types. +.El +.Ss e1000 Settings +In addition to the network backend settings, +Intel e82545 network interfaces support the following variables: +.Bl -column "Name" "MAC address" "generated" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va mac Ta MAC address Ta generated Ta +MAC address. +If an explicit address is not provided, +a MAC address is generated from a hash of the device's PCI address. +.El +.Ss Frame Buffer Settings +.Bl -column "password" "[IP:]port" "127.0.0.1:5900" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va wait Ta bool Ta false Ta +Wait for a remote connection before starting the VM. +.It Va rfb Ta Oo Ar IP Ns : Oc Ns Ar port Ta 127.0.0.1:5900 Ta +TCP address to listen on for remote connections. +The IP address must be given as a numeric address. +IPv6 addresses must be enclosed in square brackets and +support scoped identifiers as described in +.Xr getaddrinfo 3 . +A bare port number may be given in which case the IPv4 +localhost address is used. +.It Va vga Ta string Ta io Ta +VGA configuration. +More details are provided in +.Xr bhyve 8 . +.It Va w Ta integer Ta 1024 Ta +Frame buffer width in pixels. +.It Va h Ta integer Ta 768 Ta +Frame buffer height in pixels. +.It Va password Ta string Ta Ta +Password to use for VNC authentication. +This type of authentication is known to be cryptographically weak and is not +intended for use on untrusted networks. +.El +.Ss High Definition Audio Settings +.Bl -column "Name" "Format" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va play Ta path Ta Ta +Host playback device, +typically +.Pa /dev/dsp0 . +.It Va rec Ta path Ta Ta +Host recording device, +typically +.Pa /dev/dsp0 . +.El +.Ss LPC Device Settings +The LPC bridge stores its configuration under a top-level +.Va lpc +node rather than under the PCI LPC device's node. +The following nodes are available under +.Va lpc : +.Bl -column "pc-testdev" "Format" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va bootrom Ta path Ta Ta +Path to a boot ROM. +The contents of this file are copied into the guest's +memory ending just before the 4GB physical address. +If a boot ROM is present, a firmware interface device is +also enabled for use by the boot ROM. +.It Va com1 Ta node Ta Ta +Settings for the COM1 serial port device. +.It Va com2 Ta node Ta Ta +Settings for the COM2 serial port device. +.It Va com3 Ta node Ta Ta +Settings for the COM3 serial port device. +.It Va com4 Ta node Ta Ta +Settings for the COM4 serial port device. +.It Va pc-testdev Ta bool Ta false Ta +Enable the PC debug/test device. +.El +.Ss NVMe Controller Settings +Each NVMe controller supports a single storage device. +The device can be backed either by a memory disk described by the +.Va ram +variable, or a block device using the the block device settings described above. +In addition, each controller supports the following settings: +.Bl -column "ioslots" "Format" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va maxq Ta integer Ta 16 Ta +Maximum number of I/O submission and completion queue pairs. +.It Va qsz Ta integer Ta 2058 Ta +Number of elements in each I/O queue. +.It Va ioslots Ta integer Ta 8 Ta +Maximum number of concurrent I/O requests. +.It Va sectsz Ta integer Ta Ta +Sector size. +Can be one of 512, 4096, or 8192. +Devices backed by a memory disk use 4096 as the default. +Devices backed by a block device use the block device's sector size +as the default. +.It Va ser Ta string Ta Ta +Serial number of up to twenty characters. +A default serial number is generated using a hash of the device's PCI address. +.It Va eui64 Ta integer Ta Ta +IEEE Extended Unique Identifier. +If an EUI is not provided, a default is generated using a checksum of the +device's PCI address. +.It Va dsm Ta string Ta auto Ta +Whether or not to advertise DataSet Management support. +One of +.Dq auto , +.Dq enable , +or +.Dq disable . +The +.Dq auto +setting only advertises support if the backing store supports +resource freeing, for example via TRIM. +.It Va ram Ta integer Ta Ta +If set, allocate a memory disk as the backing store. +The value of this variable is the size of the memory disk in megabytes. +.El +.Ss PCI Passthrough Settings +.Bl -column "Name" "integer" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va bus Ta integer Ta Ta +Host PCI bus address of device to pass through. +.It Va slot Ta integer Ta Ta +Host PCI slot address of device to pass through. +.It Va func Ta integer Ta Ta +Host PCI function address of device to pass through. +.El +.Ss VirtIO 9p Settings +Each VirtIO 9p device exposes a single filesystem from a host path. +.Bl -column "sharename" "Format" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va sharename Ta string Ta Ta +The share name exposed to the guest. +.It Va path Ta path Ta Ta +The path of a directory on the host to export to the guest. +.It Va ro Ta bool Ta false Ta +If true, the guest filesystem is read-only. +.El +.Ss VirtIO Console Device Settings +Each VirtIO Console device contains one or more console ports. +Each port stores its settings in a node named +.Dq port. Ns Va N +under the controller's device node. +The +.Va N +values are formatted as successive decimal values starting with 0. +Each port supports the following settings: +.Bl -column "Name" "Format" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va name Ta string Ta Ta +The name of the port exposed to the guest. +.It Va path Ta path Ta Ta +The path of a UNIX domain socket providing the host connection for the port. +.El +.Ss VirtIO Network Interface Settings +In addition to the network backend settings, +VirtIO network interfaces support the following variables: +.Bl -column "Name" "MAC address" "generated" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va mac Ta MAC address Ta generated Ta +MAC address. +If an explicit address is not provided, +a MAC address is generated from a hash of the device's PCI address. +.It Va mtu Ta integer Ta 1500 Ta +The largest supported MTU advertised to the guest. +.El +.Ss VirtIO SCSI Settings +.Bl -column "Name" "integer" "Default" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va dev Ta path Ta Ta +The path of a CAM target layer (CTL) device to export: +.Pa /dev/cam/ctl Ns Oo Ar pp . Ns Ar vp Oc . +.It Va iid Ta integer Ta 0 Ta +Initiator ID to use when sending requests to the CTL port. +.El +.Sh SEE ALSO +.Xr expand_number 3 , +.Xr getaddrinfo 3 , +.Xr strtol 3 , +.Xr netgraph 4 , +.Xr netmap 4 , +.Xr ng_socket 4 , +.Xr tap 4 , +.Xr vale 4 , +.Xr vmnet 4 , +.Xr bhyve 8 diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index aafab4af8d8c..a3e6ef3c4724 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -87,6 +87,7 @@ __FBSDID("$FreeBSD$"); #include "acpi.h" #include "atkbdc.h" #include "bootrom.h" +#include "config.h" #include "inout.h" #include "debug.h" #include "fwctl.h" @@ -183,26 +184,11 @@ static const char * const vmx_exit_reason_desc[] = { typedef int (*vmexit_handler_t)(struct vmctx *, struct vm_exit *, int *vcpu); extern int vmexit_task_switch(struct vmctx *, struct vm_exit *, int *vcpu); -const char *vmname; - int guest_ncpus; uint16_t cores, maxcpus, sockets, threads; -char *guest_uuid_str; - int raw_stdio = 0; -static int gdb_port = 0; -static int guest_vmexit_on_hlt, guest_vmexit_on_pause; -static int virtio_msix = 1; -static int x2apic_mode = 0; /* default is xAPIC */ -static int destroy_on_poweroff = 0; - -static int strictio; -static int strictmsr = 1; - -static int acpi; - static char *progname; static const int BSP = 0; @@ -238,8 +224,8 @@ usage(int code) fprintf(stderr, "Usage: %s [-aehuwxACDHPSWY]\n" " %*s [-c [[cpus=]numcpus][,sockets=n][,cores=n][,threads=n]]\n" - " %*s [-l ]\n" - " %*s [-m mem] [-p vcpu:hostcpu] [-s ] [-U uuid] \n" + " %*s [-k ] [-l ] [-m mem] [-o =]\n" + " %*s [-p vcpu:hostcpu] [-s ] [-U uuid] []\n" " -a: local apic is in xAPIC mode (deprecated)\n" " -A: create ACPI tables\n" " -c: number of cpus and/or topology specification\n" @@ -248,13 +234,15 @@ usage(int code) " -e: exit on unhandled I/O access\n" " -h: help\n" " -H: vmexit from the guest on hlt\n" + " -k: key=value flat config file\n" " -l: LPC device configuration\n" " -m: memory size in MB\n" + " -o: set config 'var' to 'value'\n" + " -p: pin 'vcpu' to 'hostcpu'\n" + " -P: vmexit from the guest on pause\n" #ifdef BHYVE_SNAPSHOT " -r: path to checkpoint file\n" #endif - " -p: pin 'vcpu' to 'hostcpu'\n" - " -P: vmexit from the guest on pause\n" " -s: PCI slot config\n" " -S: guest memory cannot be swapped\n" " -u: RTC keeps UTC time\n" @@ -271,11 +259,8 @@ usage(int code) /* * XXX This parser is known to have the following issues: - * 1. It accepts null key=value tokens ",,". - * 2. It accepts whitespace after = and before value. - * 3. Values out of range of INT are silently wrapped. - * 4. It doesn't check non-final values. - * 5. The apparently bogus limits of UINT16_MAX are for future expansion. + * 1. It accepts null key=value tokens ",," as setting "cpus" to an + * empty string. * * The acceptance of a null specification ('-c ""') is by design to match the * manual page syntax specification, this results in a topology of 1 vCPU. @@ -283,83 +268,122 @@ usage(int code) static int topology_parse(const char *opt) { - uint64_t ncpus; - int c, chk, n, s, t, tmp; char *cp, *str; - bool ns, scts; - c = 1, n = 1, s = 1, t = 1; - ns = false, scts = false; + if (*opt == '\0') { + set_config_value("sockets", "1"); + set_config_value("cores", "1"); + set_config_value("threads", "1"); + set_config_value("cpus", "1"); + return (0); + } + str = strdup(opt); if (str == NULL) - goto out; + errx(4, "Failed to allocate memory"); while ((cp = strsep(&str, ",")) != NULL) { - if (sscanf(cp, "%i%n", &tmp, &chk) == 1) { - n = tmp; - ns = true; - } else if (sscanf(cp, "cpus=%i%n", &tmp, &chk) == 1) { - n = tmp; - ns = true; - } else if (sscanf(cp, "sockets=%i%n", &tmp, &chk) == 1) { - s = tmp; - scts = true; - } else if (sscanf(cp, "cores=%i%n", &tmp, &chk) == 1) { - c = tmp; - scts = true; - } else if (sscanf(cp, "threads=%i%n", &tmp, &chk) == 1) { - t = tmp; - scts = true; + if (strncmp(cp, "cpus=", strlen("cpus=")) == 0) + set_config_value("cpus", cp + strlen("cpus=")); + else if (strncmp(cp, "sockets=", strlen("sockets=")) == 0) + set_config_value("sockets", cp + strlen("sockets=")); + else if (strncmp(cp, "cores=", strlen("cores=")) == 0) + set_config_value("cores", cp + strlen("cores=")); + else if (strncmp(cp, "threads=", strlen("threads=")) == 0) + set_config_value("threads", cp + strlen("threads=")); #ifdef notyet /* Do not expose this until vmm.ko implements it */ - } else if (sscanf(cp, "maxcpus=%i%n", &tmp, &chk) == 1) { - m = tmp; + else if (strncmp(cp, "maxcpus=", strlen("maxcpus=")) == 0) + set_config_value("maxcpus", cp + strlen("maxcpus=")); #endif - /* Skip the empty argument case from -c "" */ - } else if (cp[0] == '\0') - continue; - else - goto out; - /* Any trailing garbage causes an error */ - if (cp[chk] != '\0') + else if (strchr(cp, '=') != NULL) goto out; + else + set_config_value("cpus", cp); } free(str); - str = NULL; - - /* - * Range check 1 <= n <= UINT16_MAX all values - */ *** 4875 LINES SKIPPED *** From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 22:14:13 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A6FF265D408; Wed, 11 Aug 2021 22:14:13 +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 4GlPHT49J7z4f9n; Wed, 11 Aug 2021 22:14:13 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 7682F16FE5; Wed, 11 Aug 2021 22:14:13 +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 17BMED02013805; Wed, 11 Aug 2021 22:14:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BMEDNx013804; Wed, 11 Aug 2021 22:14:13 GMT (envelope-from git) Date: Wed, 11 Aug 2021 22:14:13 GMT Message-Id: <202108112214.17BMEDNx013804@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: f08d1570fa76 - stable/13 - bhyve hostbridge: Rename "device" property to "devid". MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f08d1570fa760e98d82ec209a948a42dc49ab0da Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 22:14:13 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=f08d1570fa760e98d82ec209a948a42dc49ab0da commit f08d1570fa760e98d82ec209a948a42dc49ab0da Author: John Baldwin AuthorDate: 2021-03-24 16:29:15 +0000 Commit: John Baldwin CommitDate: 2021-08-11 22:12:23 +0000 bhyve hostbridge: Rename "device" property to "devid". "device" is already used as the generic PCI-level name of the device model to use (e.g. "hostbridge"). The result was that parsing "hostbridge" as an integer failed and the host bridge used a device ID of 0. The EFI ROM asserts that the device ID of the hostbridge is not 0, so booting with the current EFI ROM was failing during the ROM boot. Fixes: 621b5090487de9fed1b503769702a9a2a27cc7bb (cherry picked from commit 9f40a3be3d5dbddf782c3d1eeaadcd022a4dad01) --- usr.sbin/bhyve/bhyve_config.5 | 4 ++-- usr.sbin/bhyve/pci_hostbridge.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/usr.sbin/bhyve/bhyve_config.5 b/usr.sbin/bhyve/bhyve_config.5 index 4e200a779d50..d65040513cb0 100644 --- a/usr.sbin/bhyve/bhyve_config.5 +++ b/usr.sbin/bhyve/bhyve_config.5 @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 18, 2021 +.Dd March 24, 2021 .Dt BHYVE_CONFIG 5 .Os .Sh NAME @@ -335,7 +335,7 @@ process. .It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description .It Va vendor Ta integer Ta 0x1275 Ta PCI vendor ID. -.It Va device Ta integer Ta 0x1275 Ta +.It Va devid Ta integer Ta 0x1275 Ta PCI device ID. .El .Ss AHCI Controller Settings diff --git a/usr.sbin/bhyve/pci_hostbridge.c b/usr.sbin/bhyve/pci_hostbridge.c index 7099474eaf92..9fce225bb1d6 100644 --- a/usr.sbin/bhyve/pci_hostbridge.c +++ b/usr.sbin/bhyve/pci_hostbridge.c @@ -48,7 +48,7 @@ pci_hostbridge_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) value = get_config_value_node(nvl, "vendor"); if (value != NULL) vendor = strtol(value, NULL, 0); - value = get_config_value_node(nvl, "device"); + value = get_config_value_node(nvl, "devid"); if (value != NULL) device = strtol(value, NULL, 0); @@ -69,7 +69,7 @@ pci_amd_hostbridge_legacy_config(nvlist_t *nvl, const char *opts) { set_config_value_node(nvl, "vendor", "0x1022"); /* AMD */ - set_config_value_node(nvl, "device", "0x7432"); /* made up */ + set_config_value_node(nvl, "devid", "0x7432"); /* made up */ return (0); } From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 22:14:14 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EB8C165D40B; Wed, 11 Aug 2021 22:14:14 +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 4GlPHV60BDz4f7c; Wed, 11 Aug 2021 22:14:14 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 A6A7D172C5; Wed, 11 Aug 2021 22:14:14 +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 17BMEEe1013829; Wed, 11 Aug 2021 22:14:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BMEEiQ013828; Wed, 11 Aug 2021 22:14:14 GMT (envelope-from git) Date: Wed, 11 Aug 2021 22:14:14 GMT Message-Id: <202108112214.17BMEEiQ013828@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 2b2d263d0b7a - stable/13 - bhyve: Enable virtio-scsi legacy config parsing. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2b2d263d0b7aa338af7171d308228ad9cb3acc70 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 22:14:15 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=2b2d263d0b7aa338af7171d308228ad9cb3acc70 commit 2b2d263d0b7aa338af7171d308228ad9cb3acc70 Author: John Baldwin AuthorDate: 2021-03-29 17:25:45 +0000 Commit: John Baldwin CommitDate: 2021-08-11 22:12:32 +0000 bhyve: Enable virtio-scsi legacy config parsing. The previous commit added the handler to parse the command line options for virtio-scsi devices but forgot to set the correct function pointer to point to the handler. Reported by: vangyzen Reviewed by: vangyzen Fixes: 621b5090487de9fed1b503769702a9a2a27cc7bb Differential Revision: https://reviews.freebsd.org/D29438 (cherry picked from commit 4d5460a720c59a4404eb1df1b768d2f16b2f341a) --- usr.sbin/bhyve/pci_virtio_scsi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/usr.sbin/bhyve/pci_virtio_scsi.c b/usr.sbin/bhyve/pci_virtio_scsi.c index bd688d0325ef..8314b4afce38 100644 --- a/usr.sbin/bhyve/pci_virtio_scsi.c +++ b/usr.sbin/bhyve/pci_virtio_scsi.c @@ -739,6 +739,7 @@ pci_vtscsi_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) struct pci_devemu pci_de_vscsi = { .pe_emu = "virtio-scsi", .pe_init = pci_vtscsi_init, + .pe_legacy_config = pci_vtscsi_legacy_config, .pe_barwrite = vi_pci_write, .pe_barread = vi_pci_read }; From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 22:14:16 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5B3DA65CEF7; Wed, 11 Aug 2021 22:14:16 +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 4GlPHX0NJ2z4f9w; Wed, 11 Aug 2021 22:14:15 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 BEB7A17333; Wed, 11 Aug 2021 22:14:15 +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 17BMEFIr013853; Wed, 11 Aug 2021 22:14:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BMEFWI013852; Wed, 11 Aug 2021 22:14:15 GMT (envelope-from git) Date: Wed, 11 Aug 2021 22:14:15 GMT Message-Id: <202108112214.17BMEFWI013852@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 30519e53dbad - stable/13 - Fix typo in xhci nvlist node name, and also increment device counter. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 30519e53dbad93a4d316a1b7d779dde26806a4d6 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 22:14:16 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=30519e53dbad93a4d316a1b7d779dde26806a4d6 commit 30519e53dbad93a4d316a1b7d779dde26806a4d6 Author: Peter Grehan AuthorDate: 2021-04-03 04:32:54 +0000 Commit: John Baldwin CommitDate: 2021-08-11 22:12:38 +0000 Fix typo in xhci nvlist node name, and also increment device counter. This allows the xhci tablet device to be recognized and a PCI device instantiated. Reviewed by: jhb Fixes: 621b5090487d Refactor configuration management in bhyve. MFC after: 3 months. (cherry picked from commit ab899f8937c1c7c79197baf7192b727ddc9cfe54) --- usr.sbin/bhyve/pci_xhci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/pci_xhci.c b/usr.sbin/bhyve/pci_xhci.c index dd6dfc39d014..b71d66337048 100644 --- a/usr.sbin/bhyve/pci_xhci.c +++ b/usr.sbin/bhyve/pci_xhci.c @@ -2720,7 +2720,7 @@ pci_xhci_parse_devices(struct pci_xhci_softc *sc, nvlist_t *nvl) ndevices = 0; - slots_nvl = find_relative_config_node(nvl, "slots"); + slots_nvl = find_relative_config_node(nvl, "slot"); if (slots_nvl == NULL) goto portsfinal; @@ -2806,6 +2806,7 @@ pci_xhci_parse_devices(struct pci_xhci_softc *sc, nvlist_t *nvl) dev->dev_sc = devsc; XHCI_SLOTDEV_PTR(sc, slot) = dev; + ndevices++; } portsfinal: From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 22:14:17 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4658865D07D; Wed, 11 Aug 2021 22:14:17 +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 4GlPHY0Q0dz4f5W; Wed, 11 Aug 2021 22:14:17 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 E038B17503; Wed, 11 Aug 2021 22:14:16 +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 17BMEGbH013877; Wed, 11 Aug 2021 22:14:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BMEG8u013876; Wed, 11 Aug 2021 22:14:16 GMT (envelope-from git) Date: Wed, 11 Aug 2021 22:14:16 GMT Message-Id: <202108112214.17BMEG8u013876@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 001f3d25518c - stable/13 - bhyve: fix regression in legacy virtio-9p config parsing MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 001f3d25518c9179136629abf5ab42cab58c9347 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 22:14:17 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=001f3d25518c9179136629abf5ab42cab58c9347 commit 001f3d25518c9179136629abf5ab42cab58c9347 Author: Roman Bogorodskiy AuthorDate: 2021-04-08 14:44:58 +0000 Commit: John Baldwin CommitDate: 2021-08-11 22:12:42 +0000 bhyve: fix regression in legacy virtio-9p config parsing Commit 621b5090487de9fed1b503769702a9a2a27cc7bb introduced a regression in legacy virtio-9p config parsing by not initializing *sharename to NULL. As a result, "sharename != NULL" check in the first iteration fails and bhyve exits with "virtio-9p: more than one share name given". Fix by adding NULL back. Approved by: grehan (cherry picked from commit f2ecc0d1b7d569b4b2c930c7450390c04778ee8a) --- usr.sbin/bhyve/pci_virtio_9p.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/pci_virtio_9p.c b/usr.sbin/bhyve/pci_virtio_9p.c index 10023158f8bd..6c6dc483b7ba 100644 --- a/usr.sbin/bhyve/pci_virtio_9p.c +++ b/usr.sbin/bhyve/pci_virtio_9p.c @@ -232,7 +232,7 @@ pci_vt9p_notify(void *vsc, struct vqueue_info *vq) static int pci_vt9p_legacy_config(nvlist_t *nvl, const char *opts) { - char *sharename, *tofree, *token, *tokens; + char *sharename = NULL, *tofree, *token, *tokens; if (opts == NULL) return (0); From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 22:14:18 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 643C465D587; Wed, 11 Aug 2021 22:14:18 +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 4GlPHZ1V5cz4f3h; Wed, 11 Aug 2021 22:14:18 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 14736172C6; Wed, 11 Aug 2021 22:14:18 +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 17BMEHVs013901; Wed, 11 Aug 2021 22:14:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BMEH7j013900; Wed, 11 Aug 2021 22:14:17 GMT (envelope-from git) Date: Wed, 11 Aug 2021 22:14:17 GMT Message-Id: <202108112214.17BMEH7j013900@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 77e736186d8f - stable/13 - bhyve: Move the gdb_active check to gdb_cpu_suspend(). MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 77e736186d8f13246f886164c3e934a34f00af87 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 22:14:18 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=77e736186d8f13246f886164c3e934a34f00af87 commit 77e736186d8f13246f886164c3e934a34f00af87 Author: John Baldwin AuthorDate: 2021-04-12 18:43:34 +0000 Commit: John Baldwin CommitDate: 2021-08-11 22:12:47 +0000 bhyve: Move the gdb_active check to gdb_cpu_suspend(). The check needs to be in the public routine (gdb_cpu_suspend()), not in the internal routine called from various places (_gdb_cpu_suspend()). All the other callers of _gdb_cpu_suspend() already check gdb_active, and this breaks the use of snapshots when the debug server is not enabled since gdb_cpu_suspend() tries to lock an uninitialized mutex. Reported by: Darius Mihai, Elena Mihailescu Reviewed by: elenamihailescu22_gmail.com Fixes: 621b5090487de9fed1b503769702a9a2a27cc7bb Differential Revision: https://reviews.freebsd.org/D29538 (cherry picked from commit eacc27affeff17beb3791793ba54458444df7135) --- usr.sbin/bhyve/gdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr.sbin/bhyve/gdb.c b/usr.sbin/bhyve/gdb.c index 3bff62418840..219d192b7c9a 100644 --- a/usr.sbin/bhyve/gdb.c +++ b/usr.sbin/bhyve/gdb.c @@ -731,8 +731,6 @@ static void _gdb_cpu_suspend(int vcpu, bool report_stop) { - if (!gdb_active) - return; debug("$vCPU %d suspending\n", vcpu); CPU_SET(vcpu, &vcpus_waiting); if (report_stop && CPU_CMP(&vcpus_waiting, &vcpus_suspended) == 0) @@ -807,6 +805,8 @@ void gdb_cpu_suspend(int vcpu) { + if (!gdb_active) + return; pthread_mutex_lock(&gdb_lock); _gdb_cpu_suspend(vcpu, true); gdb_cpu_resume(vcpu); From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 22:14:19 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B679665D41A; Wed, 11 Aug 2021 22:14:19 +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 4GlPHb2nhXz4ds7; Wed, 11 Aug 2021 22:14:19 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 33C4217498; Wed, 11 Aug 2021 22:14:19 +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 17BMEJ2e013931; Wed, 11 Aug 2021 22:14:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BMEJ9L013930; Wed, 11 Aug 2021 22:14:19 GMT (envelope-from git) Date: Wed, 11 Aug 2021 22:14:19 GMT Message-Id: <202108112214.17BMEJ9L013930@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 81c33f22216b - stable/13 - bhyve: Be explicit that setting config.dump will not start a VM. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 81c33f22216b8dd2bd4bffc7dcdd52d4c5d9a5ff Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 22:14:19 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=81c33f22216b8dd2bd4bffc7dcdd52d4c5d9a5ff commit 81c33f22216b8dd2bd4bffc7dcdd52d4c5d9a5ff Author: John Baldwin AuthorDate: 2021-04-20 20:33:28 +0000 Commit: John Baldwin CommitDate: 2021-08-11 22:12:57 +0000 bhyve: Be explicit that setting config.dump will not start a VM. Suggested by: rpokala Reviewed by: bcr (manpages) Differential Revision: https://reviews.freebsd.org/D29738 (cherry picked from commit e15bf05e0abcf4435a09edb8ff8d7e38d1508bb2) --- usr.sbin/bhyve/bhyve_config.5 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/usr.sbin/bhyve/bhyve_config.5 b/usr.sbin/bhyve/bhyve_config.5 index d65040513cb0..1a77b1bbacb4 100644 --- a/usr.sbin/bhyve/bhyve_config.5 +++ b/usr.sbin/bhyve/bhyve_config.5 @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 24, 2021 +.Dd April 20, 2021 .Dt BHYVE_CONFIG 5 .Os .Sh NAME @@ -143,11 +143,13 @@ the host's hostname and the VM name. Use MSI-X interrupts for PCI VirtIO devices. If set to false, MSI interrupts are used instead. .It Va config.dump Ta bool Ta false Ta -If this value is set to true, +If this value is set to true after +.Xr bhyve 8 +has finished parsing command line options, then .Xr bhyve 8 -will write all of its configuration variables to stdout and exit -after it has finished parsing command line options. +will write all of its configuration variables to stdout and exit. +No VM will be started. .El .Ss x86-Specific Settings .Bl -column "x86.vmexit_on_pause" "integer" "Default" From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 22:14:20 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 95CE765CF7D; Wed, 11 Aug 2021 22:14:20 +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 4GlPHc3bJSz4f85; Wed, 11 Aug 2021 22:14:20 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 53F22172C7; Wed, 11 Aug 2021 22:14:20 +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 17BMEK7H013955; Wed, 11 Aug 2021 22:14:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BMEKmk013954; Wed, 11 Aug 2021 22:14:20 GMT (envelope-from git) Date: Wed, 11 Aug 2021 22:14:20 GMT Message-Id: <202108112214.17BMEKmk013954@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: b1a2ffd650c0 - stable/13 - bhyve: Gracefully handle virtio-scsi with no conf MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b1a2ffd650c0b85d7df97d61869d7e598b81f477 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 22:14:20 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=b1a2ffd650c0b85d7df97d61869d7e598b81f477 commit b1a2ffd650c0b85d7df97d61869d7e598b81f477 Author: Ryan Moeller AuthorDate: 2021-04-22 16:06:08 +0000 Commit: John Baldwin CommitDate: 2021-08-11 22:13:00 +0000 bhyve: Gracefully handle virtio-scsi with no conf Fixes segfault with the command `bhyve -s 0,virtio-scsi`, which is used by some third party software to probe bhyve for virtio-scsi support. Reviewed by: jhb MFC after: 1 day Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D29926 (cherry picked from commit 89c3c32647a5099b297af2958e5a939eff0c0ce0) --- usr.sbin/bhyve/pci_virtio_scsi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/usr.sbin/bhyve/pci_virtio_scsi.c b/usr.sbin/bhyve/pci_virtio_scsi.c index 8314b4afce38..33cf67bef12c 100644 --- a/usr.sbin/bhyve/pci_virtio_scsi.c +++ b/usr.sbin/bhyve/pci_virtio_scsi.c @@ -670,6 +670,9 @@ pci_vtscsi_legacy_config(nvlist_t *nvl, const char *opts) { char *cp, *devname; + if (opts == NULL) + return (0); + cp = strchr(opts, ','); if (cp == NULL) { set_config_value_node(nvl, "dev", opts); From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 22:14:22 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2C24465D51D; Wed, 11 Aug 2021 22:14:22 +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 4GlPHd4DWkz4f1Q; Wed, 11 Aug 2021 22:14:21 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 77FEB16FE6; Wed, 11 Aug 2021 22:14:21 +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 17BMELZc013979; Wed, 11 Aug 2021 22:14:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BMELZB013978; Wed, 11 Aug 2021 22:14:21 GMT (envelope-from git) Date: Wed, 11 Aug 2021 22:14:21 GMT Message-Id: <202108112214.17BMELZB013978@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 704d90845ce2 - stable/13 - bhyve: Fix cli regression with NVMe ram MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 704d90845ce2364b75a97aa69bc687d2cd9e236d Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 22:14:22 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=704d90845ce2364b75a97aa69bc687d2cd9e236d commit 704d90845ce2364b75a97aa69bc687d2cd9e236d Author: Chuck Tuffli AuthorDate: 2021-06-15 13:59:02 +0000 Commit: John Baldwin CommitDate: 2021-08-11 22:13:04 +0000 bhyve: Fix cli regression with NVMe ram The configuration management refactoring inadvertently removed support for a RAM-backed NVMe Namespace (i.e. -s X,nvme,ram=16384). This adds it back. Reported by: andy@omniosce.org Reviewed by: jhb, andy@omniosce.org Fixes: 621b5090487d MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30717 (cherry picked from commit 3a4ab18377c86c4588d79c4ca91fe8f4530dc90c) --- usr.sbin/bhyve/pci_nvme.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/pci_nvme.c b/usr.sbin/bhyve/pci_nvme.c index adf49e1ff61f..9b3fece43fde 100644 --- a/usr.sbin/bhyve/pci_nvme.c +++ b/usr.sbin/bhyve/pci_nvme.c @@ -2800,11 +2800,32 @@ done: return (error); } +static int +pci_nvme_legacy_config(nvlist_t *nvl, const char *opts) +{ + char *cp, *ram; + + if (opts == NULL) + return (0); + + if (strncmp(opts, "ram=", 4) == 0) { + cp = strchr(opts, ','); + if (cp == NULL) { + set_config_value_node(nvl, "ram", opts + 4); + return (0); + } + ram = strndup(opts + 4, cp - opts - 4); + set_config_value_node(nvl, "ram", ram); + free(ram); + return (pci_parse_legacy_config(nvl, cp + 1)); + } else + return (blockif_legacy_config(nvl, opts)); +} struct pci_devemu pci_de_nvme = { .pe_emu = "nvme", .pe_init = pci_nvme_init, - .pe_legacy_config = blockif_legacy_config, + .pe_legacy_config = pci_nvme_legacy_config, .pe_barwrite = pci_nvme_write, .pe_barread = pci_nvme_read }; From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 06:45:24 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 24A9E665168; Thu, 12 Aug 2021 06:45:24 +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 4GlcdJ0FPXz3pRZ; Thu, 12 Aug 2021 06:45:24 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 E4EAB1E1E4; Thu, 12 Aug 2021 06:45:23 +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 17C6jNQZ090445; Thu, 12 Aug 2021 06:45:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17C6jNT6090444; Thu, 12 Aug 2021 06:45:23 GMT (envelope-from git) Date: Thu, 12 Aug 2021 06:45:23 GMT Message-Id: <202108120645.17C6jNT6090444@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ka Ho Ng Subject: git: ddf1b5ac761e - stable/13 - bhyve: virtio shares definitions between sys/dev/virtio MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: khng X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: ddf1b5ac761edc6f7c9e3e0788ef4a36b50c5e6a Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 06:45:24 -0000 The branch stable/13 has been updated by khng: URL: https://cgit.FreeBSD.org/src/commit/?id=ddf1b5ac761edc6f7c9e3e0788ef4a36b50c5e6a commit ddf1b5ac761edc6f7c9e3e0788ef4a36b50c5e6a Author: Ka Ho Ng AuthorDate: 2021-08-12 06:44:52 +0000 Commit: Ka Ho Ng CommitDate: 2021-08-12 06:44:52 +0000 bhyve: virtio shares definitions between sys/dev/virtio Definitions inside usr.sbin/bhyve/virtio.h are thrown away. Definitions in sys/dev/virtio are used instead. This reduces code duplication. Sponsored by: The FreeBSD Foundation Reviewed by: grehan Approved by: philip (mentor) Differential Revision: https://reviews.freebsd.org/D29084 (cherry picked from commit 54ac6f721efccdba5a09aa9f38be0a1c4ef6cf14) --- sys/dev/virtio/virtio.h | 4 + sys/dev/virtio/virtio_endian.h | 3 + usr.sbin/bhyve/pci_virtio_9p.c | 2 +- usr.sbin/bhyve/pci_virtio_block.c | 2 +- usr.sbin/bhyve/pci_virtio_console.c | 2 +- usr.sbin/bhyve/pci_virtio_net.c | 2 +- usr.sbin/bhyve/pci_virtio_rnd.c | 2 +- usr.sbin/bhyve/pci_virtio_scsi.c | 2 +- usr.sbin/bhyve/virtio.c | 147 +++++++++++++++++------------------ usr.sbin/bhyve/virtio.h | 150 ++++++------------------------------ 10 files changed, 105 insertions(+), 211 deletions(-) diff --git a/sys/dev/virtio/virtio.h b/sys/dev/virtio/virtio.h index b22327351b43..8d32d5a8742f 100644 --- a/sys/dev/virtio/virtio.h +++ b/sys/dev/virtio/virtio.h @@ -35,6 +35,8 @@ #include #include +#ifdef _KERNEL + struct sbuf; struct vq_alloc_info; @@ -187,4 +189,6 @@ virtio_simple_probe(device_t dev, const struct virtio_pnp_match *match) return (BUS_PROBE_DEFAULT); } +#endif /* _KERNEL */ + #endif /* _VIRTIO_H_ */ diff --git a/sys/dev/virtio/virtio_endian.h b/sys/dev/virtio/virtio_endian.h index d0de299c7227..19d7fcc12079 100644 --- a/sys/dev/virtio/virtio_endian.h +++ b/sys/dev/virtio/virtio_endian.h @@ -32,6 +32,9 @@ #define _VIRTIO_ENDIAN_H_ #include +#ifndef _KERNEL +#include +#endif /* _KERNEL */ /* * VirtIO V1 (modern) uses little endian, while legacy VirtIO uses the guest's diff --git a/usr.sbin/bhyve/pci_virtio_9p.c b/usr.sbin/bhyve/pci_virtio_9p.c index 6c6dc483b7ba..830e13878a71 100644 --- a/usr.sbin/bhyve/pci_virtio_9p.c +++ b/usr.sbin/bhyve/pci_virtio_9p.c @@ -340,7 +340,7 @@ pci_vt9p_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_9P); pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR); pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_STORAGE); - pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_9P); + pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_ID_9P); pci_set_cfgdata16(pi, PCIR_SUBVEND_0, VIRTIO_VENDOR); if (vi_intr_init(&sc->vsc_vs, 1, fbsdrun_virtio_msix())) diff --git a/usr.sbin/bhyve/pci_virtio_block.c b/usr.sbin/bhyve/pci_virtio_block.c index 3735e0cd3124..0dc58e49594b 100644 --- a/usr.sbin/bhyve/pci_virtio_block.c +++ b/usr.sbin/bhyve/pci_virtio_block.c @@ -531,7 +531,7 @@ pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_BLOCK); pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR); pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_STORAGE); - pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_BLOCK); + pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_ID_BLOCK); pci_set_cfgdata16(pi, PCIR_SUBVEND_0, VIRTIO_VENDOR); if (vi_intr_init(&sc->vbsc_vs, 1, fbsdrun_virtio_msix())) { diff --git a/usr.sbin/bhyve/pci_virtio_console.c b/usr.sbin/bhyve/pci_virtio_console.c index 670287cb3b79..88d6c37f582e 100644 --- a/usr.sbin/bhyve/pci_virtio_console.c +++ b/usr.sbin/bhyve/pci_virtio_console.c @@ -712,7 +712,7 @@ pci_vtcon_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_CONSOLE); pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR); pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_SIMPLECOMM); - pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_CONSOLE); + pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_ID_CONSOLE); pci_set_cfgdata16(pi, PCIR_SUBVEND_0, VIRTIO_VENDOR); if (vi_intr_init(&sc->vsc_vs, 1, fbsdrun_virtio_msix())) diff --git a/usr.sbin/bhyve/pci_virtio_net.c b/usr.sbin/bhyve/pci_virtio_net.c index 409cf9b49654..0ea470a71b56 100644 --- a/usr.sbin/bhyve/pci_virtio_net.c +++ b/usr.sbin/bhyve/pci_virtio_net.c @@ -636,7 +636,7 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_NET); pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR); pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_NETWORK); - pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_NET); + pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_ID_NETWORK); pci_set_cfgdata16(pi, PCIR_SUBVEND_0, VIRTIO_VENDOR); /* Link is always up. */ diff --git a/usr.sbin/bhyve/pci_virtio_rnd.c b/usr.sbin/bhyve/pci_virtio_rnd.c index e30328ffd2a7..d51301b32534 100644 --- a/usr.sbin/bhyve/pci_virtio_rnd.c +++ b/usr.sbin/bhyve/pci_virtio_rnd.c @@ -190,7 +190,7 @@ pci_vtrnd_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_RANDOM); pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR); pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_CRYPTO); - pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_ENTROPY); + pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_ID_ENTROPY); pci_set_cfgdata16(pi, PCIR_SUBVEND_0, VIRTIO_VENDOR); if (vi_intr_init(&sc->vrsc_vs, 1, fbsdrun_virtio_msix())) diff --git a/usr.sbin/bhyve/pci_virtio_scsi.c b/usr.sbin/bhyve/pci_virtio_scsi.c index 33cf67bef12c..e17c3002bc54 100644 --- a/usr.sbin/bhyve/pci_virtio_scsi.c +++ b/usr.sbin/bhyve/pci_virtio_scsi.c @@ -728,7 +728,7 @@ pci_vtscsi_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_SCSI); pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR); pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_STORAGE); - pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_SCSI); + pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_ID_SCSI); pci_set_cfgdata16(pi, PCIR_SUBVEND_0, VIRTIO_VENDOR); if (vi_intr_init(&sc->vss_vs, 1, fbsdrun_virtio_msix())) diff --git a/usr.sbin/bhyve/virtio.c b/usr.sbin/bhyve/virtio.c index f3deb72b081c..078a74b759df 100644 --- a/usr.sbin/bhyve/virtio.c +++ b/usr.sbin/bhyve/virtio.c @@ -36,6 +36,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include @@ -127,10 +129,10 @@ vi_set_io_bar(struct virtio_softc *vs, int barnum) size_t size; /* - * ??? should we use CFG0 if MSI-X is disabled? + * ??? should we use VIRTIO_PCI_CONFIG_OFF(0) if MSI-X is disabled? * Existing code did not... */ - size = VTCFG_R_CFG1 + vs->vs_vc->vc_cfgsize; + size = VIRTIO_PCI_CONFIG_OFF(1) + vs->vs_vc->vc_cfgsize; pci_emul_alloc_bar(vs->vs_pi, barnum, PCIBAR_IO, size); } @@ -182,12 +184,12 @@ vi_vq_init(struct virtio_softc *vs, uint32_t pfn) vq = &vs->vs_queues[vs->vs_curq]; vq->vq_pfn = pfn; phys = (uint64_t)pfn << VRING_PFN; - size = vring_size(vq->vq_qsize); + size = vring_size_aligned(vq->vq_qsize); base = paddr_guest2host(vs->vs_pi->pi_vmctx, phys, size); /* First page(s) are descriptors... */ - vq->vq_desc = (struct virtio_desc *)base; - base += vq->vq_qsize * sizeof(struct virtio_desc); + vq->vq_desc = (struct vring_desc *)base; + base += vq->vq_qsize * sizeof(struct vring_desc); /* ... immediately followed by "avail" ring (entirely uint16_t's) */ vq->vq_avail = (struct vring_avail *)base; @@ -211,15 +213,15 @@ vi_vq_init(struct virtio_softc *vs, uint32_t pfn) * descriptor. */ static inline void -_vq_record(int i, volatile struct virtio_desc *vd, struct vmctx *ctx, +_vq_record(int i, volatile struct vring_desc *vd, struct vmctx *ctx, struct iovec *iov, int n_iov, uint16_t *flags) { if (i >= n_iov) return; - iov[i].iov_base = paddr_guest2host(ctx, vd->vd_addr, vd->vd_len); - iov[i].iov_len = vd->vd_len; + iov[i].iov_base = paddr_guest2host(ctx, vd->addr, vd->len); + iov[i].iov_len = vd->len; if (flags != NULL) - flags[i] = vd->vd_flags; + flags[i] = vd->flags; } #define VQ_MAX_DESCRIPTORS 512 /* see below */ @@ -236,7 +238,7 @@ _vq_record(int i, volatile struct virtio_desc *vd, struct vmctx *ctx, * i.e., we do not count the indirect descriptors, only the "real" * ones. * - * Basically, this vets the vd_flags and vd_next field of each + * Basically, this vets the "flags" and "next" field of each * descriptor and tells you how many are involved. Since some may * be indirect, this also needs the vmctx (in the pci_devinst * at vs->vs_pi) so that it can find indirect descriptors. @@ -253,7 +255,7 @@ _vq_record(int i, volatile struct virtio_desc *vd, struct vmctx *ctx, * * If you want to verify the WRITE flag on each descriptor, pass a * non-NULL "flags" pointer to an array of "uint16_t" of the same size - * as n_iov and we'll copy each vd_flags field after unwinding any + * as n_iov and we'll copy each "flags" field after unwinding any * indirects. * * If some descriptor(s) are invalid, this prints a diagnostic message @@ -269,7 +271,7 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, int i; u_int ndesc, n_indir; u_int idx, next; - volatile struct virtio_desc *vdir, *vindir, *vp; + volatile struct vring_desc *vdir, *vindir, *vp; struct vmctx *ctx; struct virtio_softc *vs; const char *name; @@ -279,11 +281,11 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, /* * Note: it's the responsibility of the guest not to - * update vq->vq_avail->va_idx until all of the descriptors + * update vq->vq_avail->idx until all of the descriptors * the guest has written are valid (including all their - * vd_next fields and vd_flags). + * "next" fields and "flags"). * - * Compute (va_idx - last_avail) in integers mod 2**16. This is + * Compute (vq_avail->idx - last_avail) in integers mod 2**16. This is * the number of descriptors the device has made available * since the last time we updated vq->vq_last_avail. * @@ -291,7 +293,7 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, * then trim off excess bits. */ idx = vq->vq_last_avail; - ndesc = (uint16_t)((u_int)vq->vq_avail->va_idx - idx); + ndesc = (uint16_t)((u_int)vq->vq_avail->idx - idx); if (ndesc == 0) return (0); if (ndesc > vq->vq_qsize) { @@ -311,9 +313,9 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, * index, but we just abort if the count gets excessive. */ ctx = vs->vs_pi->pi_vmctx; - *pidx = next = vq->vq_avail->va_ring[idx & (vq->vq_qsize - 1)]; + *pidx = next = vq->vq_avail->ring[idx & (vq->vq_qsize - 1)]; vq->vq_last_avail++; - for (i = 0; i < VQ_MAX_DESCRIPTORS; next = vdir->vd_next) { + for (i = 0; i < VQ_MAX_DESCRIPTORS; next = vdir->next) { if (next >= vq->vq_qsize) { EPRINTLN( "%s: descriptor index %u out of range, " @@ -322,7 +324,7 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, return (-1); } vdir = &vq->vq_desc[next]; - if ((vdir->vd_flags & VRING_DESC_F_INDIRECT) == 0) { + if ((vdir->flags & VRING_DESC_F_INDIRECT) == 0) { _vq_record(i, vdir, ctx, iov, n_iov, flags); i++; } else if ((vs->vs_vc->vc_hv_caps & @@ -333,16 +335,16 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, name); return (-1); } else { - n_indir = vdir->vd_len / 16; - if ((vdir->vd_len & 0xf) || n_indir == 0) { + n_indir = vdir->len / 16; + if ((vdir->len & 0xf) || n_indir == 0) { EPRINTLN( "%s: invalid indir len 0x%x, " "driver confused?", - name, (u_int)vdir->vd_len); + name, (u_int)vdir->len); return (-1); } vindir = paddr_guest2host(ctx, - vdir->vd_addr, vdir->vd_len); + vdir->addr, vdir->len); /* * Indirects start at the 0th, then follow * their own embedded "next"s until those run @@ -353,7 +355,7 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, next = 0; for (;;) { vp = &vindir[next]; - if (vp->vd_flags & VRING_DESC_F_INDIRECT) { + if (vp->flags & VRING_DESC_F_INDIRECT) { EPRINTLN( "%s: indirect desc has INDIR flag," " driver confused?", @@ -363,9 +365,9 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, _vq_record(i, vp, ctx, iov, n_iov, flags); if (++i > VQ_MAX_DESCRIPTORS) goto loopy; - if ((vp->vd_flags & VRING_DESC_F_NEXT) == 0) + if ((vp->flags & VRING_DESC_F_NEXT) == 0) break; - next = vp->vd_next; + next = vp->next; if (next >= n_indir) { EPRINTLN( "%s: invalid next %u > %u, " @@ -375,7 +377,7 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, } } } - if ((vdir->vd_flags & VRING_DESC_F_NEXT) == 0) + if ((vdir->flags & VRING_DESC_F_NEXT) == 0) return (i); } loopy: @@ -402,7 +404,7 @@ void vq_relchain_prepare(struct vqueue_info *vq, uint16_t idx, uint32_t iolen) { volatile struct vring_used *vuh; - volatile struct virtio_used *vue; + volatile struct vring_used_elem *vue; uint16_t mask; /* @@ -410,16 +412,13 @@ vq_relchain_prepare(struct vqueue_info *vq, uint16_t idx, uint32_t iolen) * - mask is N-1 where N is a power of 2 so computes x % N * - vuh points to the "used" data shared with guest * - vue points to the "used" ring entry we want to update - * - * (I apologize for the two fields named vu_idx; the - * virtio spec calls the one that vue points to, "id"...) */ mask = vq->vq_qsize - 1; vuh = vq->vq_used; - vue = &vuh->vu_ring[vq->vq_next_used++ & mask]; - vue->vu_idx = idx; - vue->vu_tlen = iolen; + vue = &vuh->ring[vq->vq_next_used++ & mask]; + vue->id = idx; + vue->len = iolen; } void @@ -431,7 +430,7 @@ vq_relchain_publish(struct vqueue_info *vq) * (and even on x86 to act as a compiler barrier). */ atomic_thread_fence_rel(); - vq->vq_used->vu_idx = vq->vq_next_used; + vq->vq_used->idx = vq->vq_next_used; } /* @@ -481,12 +480,12 @@ vq_endchains(struct vqueue_info *vq, int used_all_avail) */ vs = vq->vq_vs; old_idx = vq->vq_save_used; - vq->vq_save_used = new_idx = vq->vq_used->vu_idx; + vq->vq_save_used = new_idx = vq->vq_used->idx; /* - * Use full memory barrier between vu_idx store from preceding + * Use full memory barrier between "idx" store from preceding * vq_relchain() call and the loads from VQ_USED_EVENT_IDX() or - * va_flags below. + * "flags" field below. */ atomic_thread_fence_seq_cst(); if (used_all_avail && @@ -502,7 +501,7 @@ vq_endchains(struct vqueue_info *vq, int used_all_avail) (uint16_t)(new_idx - old_idx); } else { intr = new_idx != old_idx && - !(vq->vq_avail->va_flags & VRING_AVAIL_F_NO_INTERRUPT); + !(vq->vq_avail->flags & VRING_AVAIL_F_NO_INTERRUPT); } if (intr) vq_interrupt(vs, vq); @@ -515,16 +514,16 @@ static struct config_reg { uint8_t cr_ro; /* true => reg is read only */ const char *cr_name; /* name of reg */ } config_regs[] = { - { VTCFG_R_HOSTCAP, 4, 1, "HOSTCAP" }, - { VTCFG_R_GUESTCAP, 4, 0, "GUESTCAP" }, - { VTCFG_R_PFN, 4, 0, "PFN" }, - { VTCFG_R_QNUM, 2, 1, "QNUM" }, - { VTCFG_R_QSEL, 2, 0, "QSEL" }, - { VTCFG_R_QNOTIFY, 2, 0, "QNOTIFY" }, - { VTCFG_R_STATUS, 1, 0, "STATUS" }, - { VTCFG_R_ISR, 1, 0, "ISR" }, - { VTCFG_R_CFGVEC, 2, 0, "CFGVEC" }, - { VTCFG_R_QVEC, 2, 0, "QVEC" }, + { VIRTIO_PCI_HOST_FEATURES, 4, 1, "HOST_FEATURES" }, + { VIRTIO_PCI_GUEST_FEATURES, 4, 0, "GUEST_FEATURES" }, + { VIRTIO_PCI_QUEUE_PFN, 4, 0, "QUEUE_PFN" }, + { VIRTIO_PCI_QUEUE_NUM, 2, 1, "QUEUE_NUM" }, + { VIRTIO_PCI_QUEUE_SEL, 2, 0, "QUEUE_SEL" }, + { VIRTIO_PCI_QUEUE_NOTIFY, 2, 0, "QUEUE_NOTIFY" }, + { VIRTIO_PCI_STATUS, 1, 0, "STATUS" }, + { VIRTIO_PCI_ISR, 1, 0, "ISR" }, + { VIRTIO_MSI_CONFIG_VECTOR, 2, 0, "CONFIG_VECTOR" }, + { VIRTIO_MSI_QUEUE_VECTOR, 2, 0, "QUEUE_VECTOR" }, }; static inline struct config_reg * @@ -586,10 +585,7 @@ vi_pci_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, if (size != 1 && size != 2 && size != 4) goto bad; - if (pci_msix_enabled(pi)) - virtio_config_size = VTCFG_R_CFG1; - else - virtio_config_size = VTCFG_R_CFG0; + virtio_config_size = VIRTIO_PCI_CONFIG_OFF(pci_msix_enabled(pi)); if (offset >= virtio_config_size) { /* @@ -623,39 +619,39 @@ bad: } switch (offset) { - case VTCFG_R_HOSTCAP: + case VIRTIO_PCI_HOST_FEATURES: value = vc->vc_hv_caps; break; - case VTCFG_R_GUESTCAP: + case VIRTIO_PCI_GUEST_FEATURES: value = vs->vs_negotiated_caps; break; - case VTCFG_R_PFN: + case VIRTIO_PCI_QUEUE_PFN: if (vs->vs_curq < vc->vc_nvq) value = vs->vs_queues[vs->vs_curq].vq_pfn; break; - case VTCFG_R_QNUM: + case VIRTIO_PCI_QUEUE_NUM: value = vs->vs_curq < vc->vc_nvq ? vs->vs_queues[vs->vs_curq].vq_qsize : 0; break; - case VTCFG_R_QSEL: + case VIRTIO_PCI_QUEUE_SEL: value = vs->vs_curq; break; - case VTCFG_R_QNOTIFY: + case VIRTIO_PCI_QUEUE_NOTIFY: value = 0; /* XXX */ break; - case VTCFG_R_STATUS: + case VIRTIO_PCI_STATUS: value = vs->vs_status; break; - case VTCFG_R_ISR: + case VIRTIO_PCI_ISR: value = vs->vs_isr; vs->vs_isr = 0; /* a read clears this flag */ if (value) pci_lintr_deassert(pi); break; - case VTCFG_R_CFGVEC: + case VIRTIO_MSI_CONFIG_VECTOR: value = vs->vs_msix_cfg_idx; break; - case VTCFG_R_QVEC: + case VIRTIO_MSI_QUEUE_VECTOR: value = vs->vs_curq < vc->vc_nvq ? vs->vs_queues[vs->vs_curq].vq_msix_idx : VIRTIO_MSI_NO_VECTOR; @@ -706,10 +702,7 @@ vi_pci_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, if (size != 1 && size != 2 && size != 4) goto bad; - if (pci_msix_enabled(pi)) - virtio_config_size = VTCFG_R_CFG1; - else - virtio_config_size = VTCFG_R_CFG0; + virtio_config_size = VIRTIO_PCI_CONFIG_OFF(pci_msix_enabled(pi)); if (offset >= virtio_config_size) { /* @@ -747,18 +740,18 @@ bad: } switch (offset) { - case VTCFG_R_GUESTCAP: + case VIRTIO_PCI_GUEST_FEATURES: vs->vs_negotiated_caps = value & vc->vc_hv_caps; if (vc->vc_apply_features) (*vc->vc_apply_features)(DEV_SOFTC(vs), vs->vs_negotiated_caps); break; - case VTCFG_R_PFN: + case VIRTIO_PCI_QUEUE_PFN: if (vs->vs_curq >= vc->vc_nvq) goto bad_qindex; vi_vq_init(vs, value); break; - case VTCFG_R_QSEL: + case VIRTIO_PCI_QUEUE_SEL: /* * Note that the guest is allowed to select an * invalid queue; we just need to return a QNUM @@ -766,7 +759,7 @@ bad: */ vs->vs_curq = value; break; - case VTCFG_R_QNOTIFY: + case VIRTIO_PCI_QUEUE_NOTIFY: if (value >= vc->vc_nvq) { EPRINTLN("%s: queue %d notify out of range", name, (int)value); @@ -782,15 +775,15 @@ bad: "%s: qnotify queue %d: missing vq/vc notify", name, (int)value); break; - case VTCFG_R_STATUS: + case VIRTIO_PCI_STATUS: vs->vs_status = value; if (value == 0) (*vc->vc_reset)(DEV_SOFTC(vs)); break; - case VTCFG_R_CFGVEC: + case VIRTIO_MSI_CONFIG_VECTOR: vs->vs_msix_cfg_idx = value; break; - case VTCFG_R_QVEC: + case VIRTIO_MSI_QUEUE_VECTOR: if (vs->vs_curq >= vc->vc_nvq) goto bad_qindex; vq = &vs->vs_queues[vs->vs_curq]; @@ -896,7 +889,7 @@ vi_pci_snapshot_queues(struct virtio_softc *vs, struct vm_snapshot_meta *meta) SNAPSHOT_VAR_OR_LEAVE(vq->vq_pfn, meta, ret, done); - addr_size = vq->vq_qsize * sizeof(struct virtio_desc); + addr_size = vq->vq_qsize * sizeof(struct vring_desc); SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(vq->vq_desc, addr_size, false, meta, ret, done); @@ -908,8 +901,8 @@ vi_pci_snapshot_queues(struct virtio_softc *vs, struct vm_snapshot_meta *meta) SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(vq->vq_used, addr_size, false, meta, ret, done); - SNAPSHOT_BUF_OR_LEAVE(vq->vq_desc, vring_size(vq->vq_qsize), - meta, ret, done); + SNAPSHOT_BUF_OR_LEAVE(vq->vq_desc, + vring_size_aligned(vq->vq_qsize), meta, ret, done); } done: diff --git a/usr.sbin/bhyve/virtio.h b/usr.sbin/bhyve/virtio.h index b055f0c35941..c5730f71000e 100644 --- a/usr.sbin/bhyve/virtio.h +++ b/usr.sbin/bhyve/virtio.h @@ -28,11 +28,15 @@ * $FreeBSD$ */ -#ifndef _VIRTIO_H_ -#define _VIRTIO_H_ +#ifndef _BHYVE_VIRTIO_H_ +#define _BHYVE_VIRTIO_H_ #include +#include +#include +#include + /* * These are derived from several virtio specifications. * @@ -125,39 +129,6 @@ */ #define VRING_ALIGN 4096 -#define VRING_DESC_F_NEXT (1 << 0) -#define VRING_DESC_F_WRITE (1 << 1) -#define VRING_DESC_F_INDIRECT (1 << 2) - -struct virtio_desc { /* AKA vring_desc */ - uint64_t vd_addr; /* guest physical address */ - uint32_t vd_len; /* length of scatter/gather seg */ - uint16_t vd_flags; /* VRING_F_DESC_* */ - uint16_t vd_next; /* next desc if F_NEXT */ -} __packed; - -struct virtio_used { /* AKA vring_used_elem */ - uint32_t vu_idx; /* head of used descriptor chain */ - uint32_t vu_tlen; /* length written-to */ -} __packed; - -#define VRING_AVAIL_F_NO_INTERRUPT 1 - -struct vring_avail { - uint16_t va_flags; /* VRING_AVAIL_F_* */ - uint16_t va_idx; /* counts to 65535, then cycles */ - uint16_t va_ring[]; /* size N, reported in QNUM value */ -/* uint16_t va_used_event; -- after N ring entries */ -} __packed; - -#define VRING_USED_F_NO_NOTIFY 1 -struct vring_used { - uint16_t vu_flags; /* VRING_USED_F_* */ - uint16_t vu_idx; /* counts to 65535, then cycles */ - struct virtio_used vu_ring[]; /* size N */ -/* uint16_t vu_avail_event; -- after N ring entries */ -} __packed; - /* * The address of any given virtual queue is determined by a single * Page Frame Number register. The guest writes the PFN into the @@ -190,23 +161,6 @@ struct vring_used { */ #define VRING_PFN 12 -/* - * Virtio device types - * - * XXX Should really be merged with defines - */ -#define VIRTIO_TYPE_NET 1 -#define VIRTIO_TYPE_BLOCK 2 -#define VIRTIO_TYPE_CONSOLE 3 -#define VIRTIO_TYPE_ENTROPY 4 -#define VIRTIO_TYPE_BALLOON 5 -#define VIRTIO_TYPE_IOMEMORY 6 -#define VIRTIO_TYPE_RPMSG 7 -#define VIRTIO_TYPE_SCSI 8 -#define VIRTIO_TYPE_9P 9 - -/* experimental IDs start at 65535 and work down */ - /* * PCI vendor/device IDs */ @@ -218,71 +172,11 @@ struct vring_used { #define VIRTIO_DEV_SCSI 0x1008 #define VIRTIO_DEV_9P 0x1009 -/* - * PCI config space constants. - * - * If MSI-X is enabled, the ISR register is generally not used, - * and the configuration vector and queue vector appear at offsets - * 20 and 22 with the remaining configuration registers at 24. - * If MSI-X is not enabled, those two registers disappear and - * the remaining configuration registers start at offset 20. - */ -#define VTCFG_R_HOSTCAP 0 -#define VTCFG_R_GUESTCAP 4 -#define VTCFG_R_PFN 8 -#define VTCFG_R_QNUM 12 -#define VTCFG_R_QSEL 14 -#define VTCFG_R_QNOTIFY 16 -#define VTCFG_R_STATUS 18 -#define VTCFG_R_ISR 19 -#define VTCFG_R_CFGVEC 20 -#define VTCFG_R_QVEC 22 -#define VTCFG_R_CFG0 20 /* No MSI-X */ -#define VTCFG_R_CFG1 24 /* With MSI-X */ -#define VTCFG_R_MSIX 20 - -/* - * Bits in VTCFG_R_STATUS. Guests need not actually set any of these, - * but a guest writing 0 to this register means "please reset". - */ -#define VTCFG_STATUS_ACK 0x01 /* guest OS has acknowledged dev */ -#define VTCFG_STATUS_DRIVER 0x02 /* guest OS driver is loaded */ -#define VTCFG_STATUS_DRIVER_OK 0x04 /* guest OS driver ready */ -#define VTCFG_STATUS_FAILED 0x80 /* guest has given up on this dev */ - -/* - * Bits in VTCFG_R_ISR. These apply only if not using MSI-X. - * - * (We don't [yet?] ever use CONF_CHANGED.) - */ -#define VTCFG_ISR_QUEUES 0x01 /* re-scan queues */ -#define VTCFG_ISR_CONF_CHANGED 0x80 /* configuration changed */ - -#define VIRTIO_MSI_NO_VECTOR 0xFFFF - -/* - * Feature flags. - * Note: bits 0 through 23 are reserved to each device type. - */ -#define VIRTIO_F_NOTIFY_ON_EMPTY (1 << 24) -#define VIRTIO_RING_F_INDIRECT_DESC (1 << 28) -#define VIRTIO_RING_F_EVENT_IDX (1 << 29) - /* From section 2.3, "Virtqueue Configuration", of the virtio specification */ -static inline size_t -vring_size(u_int qsz) +static inline int +vring_size_aligned(u_int qsz) { - size_t size; - - /* constant 3 below = va_flags, va_idx, va_used_event */ - size = sizeof(struct virtio_desc) * qsz + sizeof(uint16_t) * (3 + qsz); - size = roundup2(size, VRING_ALIGN); - - /* constant 3 below = vu_flags, vu_idx, vu_avail_event */ - size += sizeof(uint16_t) * 3 + sizeof(struct virtio_used) * qsz; - size = roundup2(size, VRING_ALIGN); - - return (size); + return (roundup2(vring_size(qsz, VRING_ALIGN), VRING_ALIGN)); } struct vmctx; @@ -397,23 +291,23 @@ struct vqueue_info { uint16_t vq_num; /* we're the num'th queue in the softc */ uint16_t vq_flags; /* flags (see above) */ - uint16_t vq_last_avail; /* a recent value of vq_avail->va_idx */ + uint16_t vq_last_avail; /* a recent value of vq_avail->idx */ uint16_t vq_next_used; /* index of the next used slot to be filled */ - uint16_t vq_save_used; /* saved vq_used->vu_idx; see vq_endchains */ + uint16_t vq_save_used; /* saved vq_used->idx; see vq_endchains */ uint16_t vq_msix_idx; /* MSI-X index, or VIRTIO_MSI_NO_VECTOR */ uint32_t vq_pfn; /* PFN of virt queue (not shifted!) */ - volatile struct virtio_desc *vq_desc; /* descriptor array */ + volatile struct vring_desc *vq_desc; /* descriptor array */ volatile struct vring_avail *vq_avail; /* the "avail" ring */ volatile struct vring_used *vq_used; /* the "used" ring */ }; /* as noted above, these are sort of backwards, name-wise */ #define VQ_AVAIL_EVENT_IDX(vq) \ - (*(volatile uint16_t *)&(vq)->vq_used->vu_ring[(vq)->vq_qsize]) + (*(volatile uint16_t *)&(vq)->vq_used->ring[(vq)->vq_qsize]) #define VQ_USED_EVENT_IDX(vq) \ - ((vq)->vq_avail->va_ring[(vq)->vq_qsize]) + ((vq)->vq_avail->ring[(vq)->vq_qsize]) /* * Is this ring ready for I/O? @@ -434,7 +328,7 @@ vq_has_descs(struct vqueue_info *vq) { return (vq_ring_ready(vq) && vq->vq_last_avail != - vq->vq_avail->va_idx); + vq->vq_avail->idx); } /* @@ -449,7 +343,7 @@ vq_interrupt(struct virtio_softc *vs, struct vqueue_info *vq) pci_generate_msix(vs->vs_pi, vq->vq_msix_idx); else { VS_LOCK(vs); - vs->vs_isr |= VTCFG_ISR_QUEUES; + vs->vs_isr |= VIRTIO_PCI_ISR_INTR; pci_generate_msi(vs->vs_pi, 0); pci_lintr_assert(vs->vs_pi); VS_UNLOCK(vs); @@ -460,11 +354,11 @@ static inline void vq_kick_enable(struct vqueue_info *vq) { - vq->vq_used->vu_flags &= ~VRING_USED_F_NO_NOTIFY; + vq->vq_used->flags &= ~VRING_USED_F_NO_NOTIFY; /* - * Full memory barrier to make sure the store to vu_flags - * happens before the load from va_idx, which results from - * a subsequent call to vq_has_descs(). + * Full memory barrier to make sure the store to vq_used->flags + * happens before the load from vq_avail->idx, which results from a + * subsequent call to vq_has_descs(). */ atomic_thread_fence_seq_cst(); } @@ -473,7 +367,7 @@ static inline void vq_kick_disable(struct vqueue_info *vq) { - vq->vq_used->vu_flags |= VRING_USED_F_NO_NOTIFY; + vq->vq_used->flags |= VRING_USED_F_NO_NOTIFY; } struct iovec; @@ -502,4 +396,4 @@ int vi_pci_snapshot(struct vm_snapshot_meta *meta); int vi_pci_pause(struct vmctx *ctx, struct pci_devinst *pi); int vi_pci_resume(struct vmctx *ctx, struct pci_devinst *pi); #endif -#endif /* _VIRTIO_H_ */ +#endif /* _BHYVE_VIRTIO_H_ */ From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 06:45:25 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3A704664EA8; Thu, 12 Aug 2021 06:45:25 +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 4GlcdK0qXGz3pfl; Thu, 12 Aug 2021 06:45:25 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 00DF71E228; Thu, 12 Aug 2021 06:45:25 +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 17C6jOLQ090476; Thu, 12 Aug 2021 06:45:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17C6jOO7090475; Thu, 12 Aug 2021 06:45:24 GMT (envelope-from git) Date: Thu, 12 Aug 2021 06:45:24 GMT Message-Id: <202108120645.17C6jOO7090475@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ka Ho Ng Subject: git: 3fc8a816d9a3 - stable/13 - bhyve: change vq_getchain to return iovecs in both directions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: khng X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3fc8a816d9a34462b473b1db3ccdd073efa91cd0 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 06:45:25 -0000 The branch stable/13 has been updated by khng: URL: https://cgit.FreeBSD.org/src/commit/?id=3fc8a816d9a34462b473b1db3ccdd073efa91cd0 commit 3fc8a816d9a34462b473b1db3ccdd073efa91cd0 Author: Ka Ho Ng AuthorDate: 2021-03-30 08:43:24 +0000 Commit: Ka Ho Ng CommitDate: 2021-08-12 06:45:01 +0000 bhyve: change vq_getchain to return iovecs in both directions The old prototype requires callers to inspect flags of each descriptors to get the starting position of host-writable iovecs. vq_getchain() is changed to return a virtio request with the number of host-readable iovecs and host-writable iovecs instead. Callers can avoid boilerplate code of getting the start offset of host-writable iovecs. Sponsored by: The FreeBSD Foundation Reviewed by: afedorov Approved by: philip (mentor) Differential Revision: https://reviews.freebsd.org/D29433 (cherry picked from commit b013912772ec9e135b52aaec5f70bc92a191ebdb) --- usr.sbin/bhyve/pci_virtio_9p.c | 22 +++++++--------------- usr.sbin/bhyve/pci_virtio_block.c | 25 +++++++++++++------------ usr.sbin/bhyve/pci_virtio_console.c | 20 ++++++++++---------- usr.sbin/bhyve/pci_virtio_net.c | 12 +++++++----- usr.sbin/bhyve/pci_virtio_rnd.c | 6 +++--- usr.sbin/bhyve/pci_virtio_scsi.c | 34 +++++++++++++--------------------- usr.sbin/bhyve/virtio.c | 36 +++++++++++++++++++++--------------- usr.sbin/bhyve/virtio.h | 16 ++++++++++++++-- 8 files changed, 88 insertions(+), 83 deletions(-) diff --git a/usr.sbin/bhyve/pci_virtio_9p.c b/usr.sbin/bhyve/pci_virtio_9p.c index 830e13878a71..f96d53858225 100644 --- a/usr.sbin/bhyve/pci_virtio_9p.c +++ b/usr.sbin/bhyve/pci_virtio_9p.c @@ -197,32 +197,24 @@ pci_vt9p_notify(void *vsc, struct vqueue_info *vq) struct iovec iov[VT9P_MAX_IOV]; struct pci_vt9p_softc *sc; struct pci_vt9p_request *preq; - uint16_t idx, n, i; - uint16_t flags[VT9P_MAX_IOV]; + struct vi_req req; + uint16_t n; sc = vsc; while (vq_has_descs(vq)) { - n = vq_getchain(vq, &idx, iov, VT9P_MAX_IOV, flags); + n = vq_getchain(vq, iov, VT9P_MAX_IOV, &req); preq = calloc(1, sizeof(struct pci_vt9p_request)); preq->vsr_sc = sc; - preq->vsr_idx = idx; + preq->vsr_idx = req.idx; preq->vsr_iov = iov; preq->vsr_niov = n; - preq->vsr_respidx = 0; - - /* Count readable descriptors */ - for (i = 0; i < n; i++) { - if (flags[i] & VRING_DESC_F_WRITE) - break; - - preq->vsr_respidx++; - } + preq->vsr_respidx = req.readable; for (int i = 0; i < n; i++) { DPRINTF(("vt9p: vt9p_notify(): desc%d base=%p, " - "len=%zu, flags=0x%04x\r\n", i, iov[i].iov_base, - iov[i].iov_len, flags[i])); + "len=%zu\r\n", i, iov[i].iov_base, + iov[i].iov_len)); } l9p_connection_recv(sc->vsc_conn, iov, preq->vsr_respidx, preq); diff --git a/usr.sbin/bhyve/pci_virtio_block.c b/usr.sbin/bhyve/pci_virtio_block.c index 0dc58e49594b..8a172c54eda7 100644 --- a/usr.sbin/bhyve/pci_virtio_block.c +++ b/usr.sbin/bhyve/pci_virtio_block.c @@ -308,11 +308,11 @@ pci_vtblk_proc(struct pci_vtblk_softc *sc, struct vqueue_info *vq) int err; ssize_t iolen; int writeop, type; + struct vi_req req; struct iovec iov[BLOCKIF_IOV_MAX + 2]; - uint16_t idx, flags[BLOCKIF_IOV_MAX + 2]; struct virtio_blk_discard_write_zeroes *discard; - n = vq_getchain(vq, &idx, iov, BLOCKIF_IOV_MAX + 2, flags); + n = vq_getchain(vq, iov, BLOCKIF_IOV_MAX + 2, &req); /* * The first descriptor will be the read-only fixed header, @@ -324,16 +324,16 @@ pci_vtblk_proc(struct pci_vtblk_softc *sc, struct vqueue_info *vq) */ assert(n >= 2 && n <= BLOCKIF_IOV_MAX + 2); - io = &sc->vbsc_ios[idx]; - assert((flags[0] & VRING_DESC_F_WRITE) == 0); + io = &sc->vbsc_ios[req.idx]; + assert(req.readable != 0); assert(iov[0].iov_len == sizeof(struct virtio_blk_hdr)); vbh = (struct virtio_blk_hdr *)iov[0].iov_base; memcpy(&io->io_req.br_iov, &iov[1], sizeof(struct iovec) * (n - 2)); io->io_req.br_iovcnt = n - 2; io->io_req.br_offset = vbh->vbh_sector * VTBLK_BSIZE; io->io_status = (uint8_t *)iov[--n].iov_base; + assert(req.writable != 0); assert(iov[n].iov_len == 1); - assert(flags[n] & VRING_DESC_F_WRITE); /* * XXX @@ -342,16 +342,17 @@ pci_vtblk_proc(struct pci_vtblk_softc *sc, struct vqueue_info *vq) */ type = vbh->vbh_type & ~VBH_FLAG_BARRIER; writeop = (type == VBH_OP_WRITE || type == VBH_OP_DISCARD); + /* + * - Write op implies read-only descriptor + * - Read/ident op implies write-only descriptor + * + * By taking away either the read-only fixed header or the write-only + * status iovec, the following condition should hold true. + */ + assert(n == (writeop ? req.readable : req.writable)); iolen = 0; for (i = 1; i < n; i++) { - /* - * - write op implies read-only descriptor, - * - read/ident op implies write-only descriptor, - * therefore test the inverse of the descriptor bit - * to the op. - */ - assert(((flags[i] & VRING_DESC_F_WRITE) == 0) == writeop); iolen += iov[i].iov_len; } io->io_req.br_resid = iolen; diff --git a/usr.sbin/bhyve/pci_virtio_console.c b/usr.sbin/bhyve/pci_virtio_console.c index 88d6c37f582e..6832a3f92774 100644 --- a/usr.sbin/bhyve/pci_virtio_console.c +++ b/usr.sbin/bhyve/pci_virtio_console.c @@ -415,10 +415,10 @@ pci_vtcon_sock_rx(int fd __unused, enum ev_type t __unused, void *arg) struct pci_vtcon_port *port; struct pci_vtcon_sock *sock = (struct pci_vtcon_sock *)arg; struct vqueue_info *vq; + struct vi_req req; struct iovec iov; static char dummybuf[2048]; int len, n; - uint16_t idx; port = sock->vss_port; vq = pci_vtcon_port_to_vq(port, true); @@ -441,7 +441,7 @@ pci_vtcon_sock_rx(int fd __unused, enum ev_type t __unused, void *arg) } do { - n = vq_getchain(vq, &idx, &iov, 1, NULL); + n = vq_getchain(vq, &iov, 1, &req); len = readv(sock->vss_conn_fd, &iov, n); if (len == 0 || (len < 0 && errno == EWOULDBLOCK)) { @@ -453,7 +453,7 @@ pci_vtcon_sock_rx(int fd __unused, enum ev_type t __unused, void *arg) return; } - vq_relchain(vq, idx, len); + vq_relchain(vq, req.idx, len); } while (vq_has_descs(vq)); vq_endchains(vq, 1); @@ -572,8 +572,8 @@ pci_vtcon_control_send(struct pci_vtcon_softc *sc, struct pci_vtcon_control *ctrl, const void *payload, size_t len) { struct vqueue_info *vq; + struct vi_req req; struct iovec iov; - uint16_t idx; int n; vq = pci_vtcon_port_to_vq(&sc->vsc_control_port, true); @@ -581,7 +581,7 @@ pci_vtcon_control_send(struct pci_vtcon_softc *sc, if (!vq_has_descs(vq)) return; - n = vq_getchain(vq, &idx, &iov, 1, NULL); + n = vq_getchain(vq, &iov, 1, &req); assert(n == 1); @@ -590,7 +590,7 @@ pci_vtcon_control_send(struct pci_vtcon_softc *sc, memcpy(iov.iov_base + sizeof(struct pci_vtcon_control), payload, len); - vq_relchain(vq, idx, sizeof(struct pci_vtcon_control) + len); + vq_relchain(vq, req.idx, sizeof(struct pci_vtcon_control) + len); vq_endchains(vq, 1); } @@ -601,14 +601,14 @@ pci_vtcon_notify_tx(void *vsc, struct vqueue_info *vq) struct pci_vtcon_softc *sc; struct pci_vtcon_port *port; struct iovec iov[1]; - uint16_t idx, n; - uint16_t flags[8]; + struct vi_req req; + uint16_t n; sc = vsc; port = pci_vtcon_vq_to_port(sc, vq); while (vq_has_descs(vq)) { - n = vq_getchain(vq, &idx, iov, 1, flags); + n = vq_getchain(vq, iov, 1, &req); assert(n >= 1); if (port != NULL) port->vsp_cb(port, port->vsp_arg, iov, 1); @@ -616,7 +616,7 @@ pci_vtcon_notify_tx(void *vsc, struct vqueue_info *vq) /* * Release this chain and handle more */ - vq_relchain(vq, idx, 0); + vq_relchain(vq, req.idx, 0); } vq_endchains(vq, 1); /* Generate interrupt if appropriate. */ } diff --git a/usr.sbin/bhyve/pci_virtio_net.c b/usr.sbin/bhyve/pci_virtio_net.c index 0ea470a71b56..d253b081d13a 100644 --- a/usr.sbin/bhyve/pci_virtio_net.c +++ b/usr.sbin/bhyve/pci_virtio_net.c @@ -248,6 +248,7 @@ pci_vtnet_rx(struct pci_vtnet_softc *sc) struct virtio_mrg_rxbuf_info info[VTNET_MAXSEGS]; struct iovec iov[VTNET_MAXSEGS + 1]; struct vqueue_info *vq; + struct vi_req req; vq = &sc->vsc_queues[VTNET_RXQ]; @@ -288,8 +289,9 @@ pci_vtnet_rx(struct pci_vtnet_softc *sc) riov = iov; n_chains = 0; do { - int n = vq_getchain(vq, &info[n_chains].idx, riov, - VTNET_MAXSEGS - riov_len, NULL); + int n = vq_getchain(vq, riov, VTNET_MAXSEGS - riov_len, + &req); + info[n_chains].idx = req.idx; if (n == 0) { /* @@ -435,7 +437,7 @@ pci_vtnet_proctx(struct pci_vtnet_softc *sc, struct vqueue_info *vq) { struct iovec iov[VTNET_MAXSEGS + 1]; struct iovec *siov = iov; - uint16_t idx; + struct vi_req req; ssize_t len; int n; @@ -443,7 +445,7 @@ pci_vtnet_proctx(struct pci_vtnet_softc *sc, struct vqueue_info *vq) * Obtain chain of descriptors. The first descriptor also * contains the virtio-net header. */ - n = vq_getchain(vq, &idx, iov, VTNET_MAXSEGS, NULL); + n = vq_getchain(vq, iov, VTNET_MAXSEGS, &req); assert(n >= 1 && n <= VTNET_MAXSEGS); if (sc->vhdrlen != sc->be_vhdrlen) { @@ -473,7 +475,7 @@ pci_vtnet_proctx(struct pci_vtnet_softc *sc, struct vqueue_info *vq) * Return the processed chain to the guest, reporting * the number of bytes that we read. */ - vq_relchain(vq, idx, len); + vq_relchain(vq, req.idx, len); } /* Called on TX kick. */ diff --git a/usr.sbin/bhyve/pci_virtio_rnd.c b/usr.sbin/bhyve/pci_virtio_rnd.c index d51301b32534..1d2d6144f949 100644 --- a/usr.sbin/bhyve/pci_virtio_rnd.c +++ b/usr.sbin/bhyve/pci_virtio_rnd.c @@ -113,8 +113,8 @@ pci_vtrnd_notify(void *vsc, struct vqueue_info *vq) { struct iovec iov; struct pci_vtrnd_softc *sc; + struct vi_req req; int len; - uint16_t idx; sc = vsc; @@ -124,7 +124,7 @@ pci_vtrnd_notify(void *vsc, struct vqueue_info *vq) } while (vq_has_descs(vq)) { - vq_getchain(vq, &idx, &iov, 1, NULL); + vq_getchain(vq, &iov, 1, &req); len = read(sc->vrsc_fd, iov.iov_base, iov.iov_len); @@ -136,7 +136,7 @@ pci_vtrnd_notify(void *vsc, struct vqueue_info *vq) /* * Release this chain and handle more */ - vq_relchain(vq, idx, len); + vq_relchain(vq, req.idx, len); } vq_endchains(vq, 1); /* Generate interrupt if appropriate. */ } diff --git a/usr.sbin/bhyve/pci_virtio_scsi.c b/usr.sbin/bhyve/pci_virtio_scsi.c index e17c3002bc54..e8124b9b3441 100644 --- a/usr.sbin/bhyve/pci_virtio_scsi.c +++ b/usr.sbin/bhyve/pci_virtio_scsi.c @@ -558,7 +558,8 @@ pci_vtscsi_controlq_notify(void *vsc, struct vqueue_info *vq) { struct pci_vtscsi_softc *sc; struct iovec iov[VTSCSI_MAXSEG]; - uint16_t idx, n; + struct vi_req req; + uint16_t n; void *buf = NULL; size_t bufsize; int iolen; @@ -566,7 +567,7 @@ pci_vtscsi_controlq_notify(void *vsc, struct vqueue_info *vq) sc = vsc; while (vq_has_descs(vq)) { - n = vq_getchain(vq, &idx, iov, VTSCSI_MAXSEG, NULL); + n = vq_getchain(vq, iov, VTSCSI_MAXSEG, &req); bufsize = iov_to_buf(iov, n, &buf); iolen = pci_vtscsi_control_handle(sc, buf, bufsize); buf_to_iov(buf + bufsize - iolen, iolen, iov, n, @@ -575,7 +576,7 @@ pci_vtscsi_controlq_notify(void *vsc, struct vqueue_info *vq) /* * Release this chain and handle more */ - vq_relchain(vq, idx, iolen); + vq_relchain(vq, req.idx, iolen); } vq_endchains(vq, 1); /* Generate interrupt if appropriate. */ free(buf); @@ -595,33 +596,23 @@ pci_vtscsi_requestq_notify(void *vsc, struct vqueue_info *vq) struct pci_vtscsi_queue *q; struct pci_vtscsi_request *req; struct iovec iov[VTSCSI_MAXSEG]; - uint16_t flags[VTSCSI_MAXSEG]; - uint16_t idx, n, i; - int readable; + struct vi_req vireq; + uint16_t n; sc = vsc; q = &sc->vss_queues[vq->vq_num - 2]; while (vq_has_descs(vq)) { - readable = 0; - n = vq_getchain(vq, &idx, iov, VTSCSI_MAXSEG, flags); - - /* Count readable descriptors */ - for (i = 0; i < n; i++) { - if (flags[i] & VRING_DESC_F_WRITE) - break; - - readable++; - } + n = vq_getchain(vq, iov, VTSCSI_MAXSEG, &vireq); req = calloc(1, sizeof(struct pci_vtscsi_request)); - req->vsr_idx = idx; + req->vsr_idx = vireq.idx; req->vsr_queue = q; - req->vsr_niov_in = readable; - req->vsr_niov_out = n - readable; + req->vsr_niov_in = vireq.readable; + req->vsr_niov_out = vireq.writable; memcpy(req->vsr_iov_in, iov, req->vsr_niov_in * sizeof(struct iovec)); - memcpy(req->vsr_iov_out, iov + readable, + memcpy(req->vsr_iov_out, iov + vireq.readable, req->vsr_niov_out * sizeof(struct iovec)); pthread_mutex_lock(&q->vsq_mtx); @@ -629,7 +620,8 @@ pci_vtscsi_requestq_notify(void *vsc, struct vqueue_info *vq) pthread_cond_signal(&q->vsq_cv); pthread_mutex_unlock(&q->vsq_mtx); - DPRINTF(("virtio-scsi: request enqueued", idx)); + DPRINTF(("virtio-scsi: request enqueued", + vireq.idx)); } } diff --git a/usr.sbin/bhyve/virtio.c b/usr.sbin/bhyve/virtio.c index 078a74b759df..7f0485cbb826 100644 --- a/usr.sbin/bhyve/virtio.c +++ b/usr.sbin/bhyve/virtio.c @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -213,15 +214,18 @@ vi_vq_init(struct virtio_softc *vs, uint32_t pfn) * descriptor. */ static inline void -_vq_record(int i, volatile struct vring_desc *vd, struct vmctx *ctx, - struct iovec *iov, int n_iov, uint16_t *flags) { +_vq_record(int i, volatile struct vring_desc *vd, + struct vmctx *ctx, struct iovec *iov, int n_iov, + struct vi_req *reqp) { if (i >= n_iov) return; iov[i].iov_base = paddr_guest2host(ctx, vd->addr, vd->len); iov[i].iov_len = vd->len; - if (flags != NULL) - flags[i] = vd->flags; + if ((vd->flags & VRING_DESC_F_WRITE) == 0) + reqp->readable++; + else + reqp->writable++; } #define VQ_MAX_DESCRIPTORS 512 /* see below */ @@ -253,11 +257,6 @@ _vq_record(int i, volatile struct vring_desc *vd, struct vmctx *ctx, * a larger iov array if needed, or supply a zero length to find * out how much space is needed). * - * If you want to verify the WRITE flag on each descriptor, pass a - * non-NULL "flags" pointer to an array of "uint16_t" of the same size - * as n_iov and we'll copy each "flags" field after unwinding any - * indirects. - * * If some descriptor(s) are invalid, this prints a diagnostic message * and returns -1. If no descriptors are ready now it simply returns 0. * @@ -265,12 +264,13 @@ _vq_record(int i, volatile struct vring_desc *vd, struct vmctx *ctx, * that vq_has_descs() does one). */ int -vq_getchain(struct vqueue_info *vq, uint16_t *pidx, - struct iovec *iov, int n_iov, uint16_t *flags) +vq_getchain(struct vqueue_info *vq, struct iovec *iov, int niov, + struct vi_req *reqp) { int i; u_int ndesc, n_indir; u_int idx, next; + struct vi_req req; volatile struct vring_desc *vdir, *vindir, *vp; struct vmctx *ctx; struct virtio_softc *vs; @@ -278,6 +278,7 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, vs = vq->vq_vs; name = vs->vs_vc->vc_name; + memset(&req, 0, sizeof(req)); /* * Note: it's the responsibility of the guest not to @@ -313,7 +314,7 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, * index, but we just abort if the count gets excessive. */ ctx = vs->vs_pi->pi_vmctx; - *pidx = next = vq->vq_avail->ring[idx & (vq->vq_qsize - 1)]; + req.idx = next = vq->vq_avail->ring[idx & (vq->vq_qsize - 1)]; vq->vq_last_avail++; for (i = 0; i < VQ_MAX_DESCRIPTORS; next = vdir->next) { if (next >= vq->vq_qsize) { @@ -325,7 +326,7 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, } vdir = &vq->vq_desc[next]; if ((vdir->flags & VRING_DESC_F_INDIRECT) == 0) { - _vq_record(i, vdir, ctx, iov, n_iov, flags); + _vq_record(i, vdir, ctx, iov, niov, &req); i++; } else if ((vs->vs_vc->vc_hv_caps & VIRTIO_RING_F_INDIRECT_DESC) == 0) { @@ -362,7 +363,7 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, name); return (-1); } - _vq_record(i, vp, ctx, iov, n_iov, flags); + _vq_record(i, vp, ctx, iov, niov, &req); if (++i > VQ_MAX_DESCRIPTORS) goto loopy; if ((vp->flags & VRING_DESC_F_NEXT) == 0) @@ -378,13 +379,18 @@ vq_getchain(struct vqueue_info *vq, uint16_t *pidx, } } if ((vdir->flags & VRING_DESC_F_NEXT) == 0) - return (i); + goto done; } + loopy: EPRINTLN( "%s: descriptor loop? count > %d - driver confused?", name, i); return (-1); + +done: + *reqp = req; + return (i); } /* diff --git a/usr.sbin/bhyve/virtio.h b/usr.sbin/bhyve/virtio.h index c5730f71000e..e03fd5f710d1 100644 --- a/usr.sbin/bhyve/virtio.h +++ b/usr.sbin/bhyve/virtio.h @@ -371,6 +371,18 @@ vq_kick_disable(struct vqueue_info *vq) } struct iovec; + +/* + * Request description returned by vq_getchain. + * + * Writable iovecs start at iov[req.readable]. + */ +struct vi_req { + int readable; /* num of readable iovecs */ + int writable; /* num of writable iovecs */ + unsigned int idx; /* ring index */ +}; + void vi_softc_linkup(struct virtio_softc *vs, struct virtio_consts *vc, void *dev_softc, struct pci_devinst *pi, struct vqueue_info *queues); @@ -378,8 +390,8 @@ int vi_intr_init(struct virtio_softc *vs, int barnum, int use_msix); void vi_reset_dev(struct virtio_softc *); void vi_set_io_bar(struct virtio_softc *, int); -int vq_getchain(struct vqueue_info *vq, uint16_t *pidx, - struct iovec *iov, int n_iov, uint16_t *flags); +int vq_getchain(struct vqueue_info *vq, struct iovec *iov, int niov, + struct vi_req *reqp); void vq_retchains(struct vqueue_info *vq, uint16_t n_chains); void vq_relchain_prepare(struct vqueue_info *vq, uint16_t idx, uint32_t iolen); From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 12:26:08 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EAFE566AD9D; Thu, 12 Aug 2021 12:26:08 +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 4GlmBS5ZMVz4hWd; Thu, 12 Aug 2021 12:26:08 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 A305E22CA1; Thu, 12 Aug 2021 12:26:08 +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 17CCQ8IF044114; Thu, 12 Aug 2021 12:26:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CCQ8Cd044113; Thu, 12 Aug 2021 12:26:08 GMT (envelope-from git) Date: Thu, 12 Aug 2021 12:26:08 GMT Message-Id: <202108121226.17CCQ8Cd044113@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Gordon Bergling Subject: git: b844fc25c844 - stable/13 - nanobsd: Correct a typo in a comment MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: gbe X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b844fc25c844cac3e86a26e81426a357f0f9a42c Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 12:26:09 -0000 The branch stable/13 has been updated by gbe (doc committer): URL: https://cgit.FreeBSD.org/src/commit/?id=b844fc25c844cac3e86a26e81426a357f0f9a42c commit b844fc25c844cac3e86a26e81426a357f0f9a42c Author: Gordon Bergling AuthorDate: 2021-08-09 11:45:10 +0000 Commit: Gordon Bergling CommitDate: 2021-08-12 12:25:50 +0000 nanobsd: Correct a typo in a comment - s/partion/partition/ (cherry picked from commit 8b9f6d62f75a367459997e5bb27d86d0302aedd2) --- tools/tools/nanobsd/embedded/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tools/nanobsd/embedded/common b/tools/tools/nanobsd/embedded/common index 7186aa5ba4b5..f3be05ae857a 100644 --- a/tools/tools/nanobsd/embedded/common +++ b/tools/tools/nanobsd/embedded/common @@ -574,7 +574,7 @@ eval std_${NANO_ARCH} # Slice 4: FreeBSD partition (empty) # on first boot, we resize slice 3 & 4 to be 1/2 of what's # left over on the SD card after slice 1 and 2 are taken -# off the top. We also resize the 'a' partion on first boot +# off the top. We also resize the 'a' partition on first boot # to the size of the partition for the ping/pong upgrade. # This feature needs support in the rc.d bootup script. # From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 12:28:22 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9299366B113; Thu, 12 Aug 2021 12:28:22 +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 4GlmF23VGHz4hqr; Thu, 12 Aug 2021 12:28:22 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 60D4B22968; Thu, 12 Aug 2021 12:28:22 +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 17CCSM0j044483; Thu, 12 Aug 2021 12:28:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CCSMn9044482; Thu, 12 Aug 2021 12:28:22 GMT (envelope-from git) Date: Thu, 12 Aug 2021 12:28:22 GMT Message-Id: <202108121228.17CCSMn9044482@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Gordon Bergling Subject: git: 844e8b71f2fe - stable/12 - nanobsd: Correct a typo in a comment MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: gbe X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 844e8b71f2fe96d98d1aae7c1d63a0c7c431749e Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 12:28:22 -0000 The branch stable/12 has been updated by gbe (doc committer): URL: https://cgit.FreeBSD.org/src/commit/?id=844e8b71f2fe96d98d1aae7c1d63a0c7c431749e commit 844e8b71f2fe96d98d1aae7c1d63a0c7c431749e Author: Gordon Bergling AuthorDate: 2021-08-09 11:45:10 +0000 Commit: Gordon Bergling CommitDate: 2021-08-12 12:28:06 +0000 nanobsd: Correct a typo in a comment - s/partion/partition/ (cherry picked from commit 8b9f6d62f75a367459997e5bb27d86d0302aedd2) --- tools/tools/nanobsd/embedded/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tools/nanobsd/embedded/common b/tools/tools/nanobsd/embedded/common index 47a13f4cd43e..a944ba0b5119 100644 --- a/tools/tools/nanobsd/embedded/common +++ b/tools/tools/nanobsd/embedded/common @@ -588,7 +588,7 @@ eval std_${NANO_ARCH} # Slice 4: FreeBSD partition (empty) # on first boot, we resize slice 3 & 4 to be 1/2 of what's # left over on the SD card after slice 1 and 2 are taken -# off the top. We also resize the 'a' partion on first boot +# off the top. We also resize the 'a' partition on first boot # to the size of the partition for the ping/pong upgrade. # This feature needs support in the rc.d bootup script. # From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 12:39:24 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9777066B13B; Thu, 12 Aug 2021 12:39:24 +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 4GlmTm3cZqz4jCW; Thu, 12 Aug 2021 12:39:24 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 6044422D2A; Thu, 12 Aug 2021 12:39:24 +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 17CCdO1c058888; Thu, 12 Aug 2021 12:39:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CCdOo1058887; Thu, 12 Aug 2021 12:39:24 GMT (envelope-from git) Date: Thu, 12 Aug 2021 12:39:24 GMT Message-Id: <202108121239.17CCdOo1058887@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: a9c0baa1d063 - stable/13 - fork.2: Add a simple use pattern MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a9c0baa1d063b219e9ff71076bfb05231e58acf4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 12:39:24 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a9c0baa1d063b219e9ff71076bfb05231e58acf4 commit a9c0baa1d063b219e9ff71076bfb05231e58acf4 Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2021-04-17 21:10:48 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-12 12:37:54 +0000 fork.2: Add a simple use pattern (cherry picked from commit c4207d867c201a726aa3157e09262f72166c89c4) --- lib/libc/sys/fork.2 | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/libc/sys/fork.2 b/lib/libc/sys/fork.2 index 3e55530827c5..d43ade6a483e 100644 --- a/lib/libc/sys/fork.2 +++ b/lib/libc/sys/fork.2 @@ -28,7 +28,7 @@ .\" @(#)fork.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd December 1, 2017 +.Dd April 17, 2021 .Dt FORK 2 .Os .Sh NAME @@ -99,6 +99,42 @@ to the parent process, no child process is created, and the global variable .Va errno is set to indicate the error. +.Sh EXAMPLES +The following example shows a common pattern of how +.Fn fork +is used in practice. +.Bd -literal -offset indent +#include +#include +#include +#include + +int +main(void) +{ + pid_t pid; + + switch (pid = fork()) { + case -1: + err(1, "Failed to fork"); + case 0: + printf("Hello from child process!\en"); + exit(0); + default: + break; + } + + printf("Hello from parent process (child's PID: %d)!\en", pid); + + return (0); +} +.Ed +.Pp +The output of such a program is along the lines of: +.Bd -literal -offset indent +Hello from parent (child's PID: 27804)! +Hello from child process! +.Ed .Sh ERRORS The .Fn fork From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 12:39:25 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A5DF666AC64; Thu, 12 Aug 2021 12:39:25 +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 4GlmTn41CMz4j5j; Thu, 12 Aug 2021 12:39:25 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 6FD7A22CC0; Thu, 12 Aug 2021 12:39:25 +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 17CCdPbH058914; Thu, 12 Aug 2021 12:39:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CCdPUD058913; Thu, 12 Aug 2021 12:39:25 GMT (envelope-from git) Date: Thu, 12 Aug 2021 12:39:25 GMT Message-Id: <202108121239.17CCdPUD058913@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 3248a03c1a13 - stable/13 - fork.2: Fix a typo in an example MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3248a03c1a135bf8633d34be19902b54583a331f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 12:39:25 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=3248a03c1a135bf8633d34be19902b54583a331f commit 3248a03c1a135bf8633d34be19902b54583a331f Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2021-04-20 08:24:21 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-12 12:37:54 +0000 fork.2: Fix a typo in an example (cherry picked from commit ca904beafd925719af998a86cd67a9c787f44255) --- lib/libc/sys/fork.2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libc/sys/fork.2 b/lib/libc/sys/fork.2 index d43ade6a483e..9ea0a6afb96f 100644 --- a/lib/libc/sys/fork.2 +++ b/lib/libc/sys/fork.2 @@ -28,7 +28,7 @@ .\" @(#)fork.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd April 17, 2021 +.Dd April 20, 2021 .Dt FORK 2 .Os .Sh NAME @@ -132,7 +132,7 @@ main(void) .Pp The output of such a program is along the lines of: .Bd -literal -offset indent -Hello from parent (child's PID: 27804)! +Hello from parent process (child's PID: 27804)! Hello from child process! .Ed .Sh ERRORS From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 12:39:26 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CAB0966B300; Thu, 12 Aug 2021 12:39:26 +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 4GlmTp58Kmz4hvs; Thu, 12 Aug 2021 12:39:26 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 94E4B230F4; Thu, 12 Aug 2021 12:39:26 +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 17CCdQCK058946; Thu, 12 Aug 2021 12:39:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CCdQtN058945; Thu, 12 Aug 2021 12:39:26 GMT (envelope-from git) Date: Thu, 12 Aug 2021 12:39:26 GMT Message-Id: <202108121239.17CCdQtN058945@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 8c51479a6e90 - stable/13 - Style MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 8c51479a6e903855c4b4073b6827eb7694f824f4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 12:39:26 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=8c51479a6e903855c4b4073b6827eb7694f824f4 commit 8c51479a6e903855c4b4073b6827eb7694f824f4 Author: Konstantin Belousov AuthorDate: 2021-08-02 21:05:11 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-12 12:37:54 +0000 Style (cherry picked from commit 2d319ebe5c08f3454c4e76564b88fb921f008185) --- lib/libc/include/compat.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libc/include/compat.h b/lib/libc/include/compat.h index 72823366c33a..ccb92c0fd930 100644 --- a/lib/libc/include/compat.h +++ b/lib/libc/include/compat.h @@ -37,7 +37,7 @@ #ifndef __LIBC_COMPAT_H__ #define __LIBC_COMPAT_H__ -#define __sym_compat(sym,impl,verid) \ +#define __sym_compat(sym, impl, verid) \ .symver impl, sym@verid #ifndef NO_COMPAT7 @@ -74,7 +74,7 @@ __sym_compat(kevent, freebsd11_kevent, FBSD_1.0); #define __weak_reference(sym,alias) \ .weak alias;.equ alias,sym -__weak_reference(__sys_fcntl,__fcntl_compat) +__weak_reference(__sys_fcntl, __fcntl_compat) #undef __weak_reference From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 12:39:27 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DBB9E66AF33; Thu, 12 Aug 2021 12:39:27 +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 4GlmTq5ngLz4jFc; Thu, 12 Aug 2021 12:39:27 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 AEC4F22F97; Thu, 12 Aug 2021 12:39:27 +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 17CCdRNQ058971; Thu, 12 Aug 2021 12:39:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CCdRU7058970; Thu, 12 Aug 2021 12:39:27 GMT (envelope-from git) Date: Thu, 12 Aug 2021 12:39:27 GMT Message-Id: <202108121239.17CCdRU7058970@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 1c54a109d71e - stable/13 - Add _Fork() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1c54a109d71ee768929e96fecbda27e44a173aa7 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 12:39:28 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=1c54a109d71ee768929e96fecbda27e44a173aa7 commit 1c54a109d71ee768929e96fecbda27e44a173aa7 Author: Konstantin Belousov AuthorDate: 2021-08-02 09:50:32 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-12 12:37:54 +0000 Add _Fork() (cherry picked from commit 49ad342cc10cba14b3a40ba26cf8bb2150e2925a) --- include/unistd.h | 1 + lib/libc/sys/Makefile.inc | 1 + lib/libc/sys/Symbol.map | 4 +++ lib/libc/sys/_Fork.c | 45 +++++++++++++++++++++++++++ lib/libc/sys/fork.2 | 78 ++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 125 insertions(+), 4 deletions(-) diff --git a/include/unistd.h b/include/unistd.h index 9fa9bebbc4c0..5f358ad72d9a 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -586,6 +586,7 @@ int undelete(const char *); int unwhiteout(const char *); void *valloc(size_t); /* obsoleted by malloc() */ int funlinkat(int, const char *, int, int); +pid_t _Fork(void); #ifndef _OPTRESET_DECLARED #define _OPTRESET_DECLARED diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 82d16fb81b6b..d0fd7bda74f5 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -49,6 +49,7 @@ SRCS+= closefrom.c SRCS+= pipe.c SRCS+= shm_open.c SRCS+= vadvise.c +SRCS+= _Fork.c SRCS+= compat-stub.c diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map index 0044c06fd639..80bb2c236191 100644 --- a/lib/libc/sys/Symbol.map +++ b/lib/libc/sys/Symbol.map @@ -417,6 +417,10 @@ FBSD_1.6 { shm_rename; }; +FBSD_1.7 { + _Fork; +}; + FBSDprivate_1.0 { ___acl_aclcheck_fd; __sys___acl_aclcheck_fd; diff --git a/lib/libc/sys/_Fork.c b/lib/libc/sys/_Fork.c new file mode 100644 index 000000000000..a7aaf82429bb --- /dev/null +++ b/lib/libc/sys/_Fork.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 The FreeBSD Foundation. + * All rights reserved. + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include "libc_private.h" + +#pragma weak _Fork +pid_t +_Fork(void) +{ + return (__sys_fork()); +} diff --git a/lib/libc/sys/fork.2 b/lib/libc/sys/fork.2 index 9ea0a6afb96f..bf934d166b03 100644 --- a/lib/libc/sys/fork.2 +++ b/lib/libc/sys/fork.2 @@ -28,7 +28,7 @@ .\" @(#)fork.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd April 20, 2021 +.Dd August 2, 2021 .Dt FORK 2 .Os .Sh NAME @@ -40,10 +40,12 @@ .In unistd.h .Ft pid_t .Fn fork void +.Ft pid_t +.Fn _Fork void .Sh DESCRIPTION The .Fn fork -system call causes creation of a new process. +function causes creation of a new process. The new process (child process) is an exact copy of the calling process (parent process) except for the following: .Bl -bullet -offset indent @@ -77,6 +79,15 @@ are set to 0; see All interval timers are cleared; see .Xr setitimer 2 . .It +The robust mutexes list (see +.Xr pthread_mutexattr_setrobust 3 ) +is cleared for the child. +.It +The atfork handlers established with the +.Xr pthread_atfork 3 +function are called as appropriate before fork in the parent process, +and after the child is created, in parent and child. +.It The child process has only one thread, corresponding to the calling thread in the parent process. If the process has more than one thread, @@ -87,11 +98,58 @@ and therefore only async-signal-safe functions are guaranteed to work in the child process until a call to .Xr execve 2 or a similar function. +The +.Fx +implementation of +.Fn fork +provides a usable +.Xr malloc 3 , +and +.Xr rtld 1 +services in the child process. .El +.Pp +The +.Fn fork +function is not async-signal safe and creates a cancellation point +in the parent process. +It cannot be safely used from signal handlers, and the atfork handlers +established by +.Xr pthread_atfork 3 +do not need to be async-signal safe either. +.Pp +The +.Fn _Fork +function creates a new process, similarly to +.Fn fork , +but it is async-signal safe. +.Fn _Fork +does not call atfork handlers, and does not create a cancellation point. +It can be used safely from signal handlers, but then no userspace +services ( +.Xr malloc 3 +or +.Xr rtld 1 ) +are available in the child if forked from multi-threaded parent. +In particular, if using dynamic linking, all dynamic symbols used by the +child after +.Fn _Fork +must be pre-resolved. +Note: resolving can be done globally by specifying the +.Ev LD_BIND_NOW +environment variable to the dynamic linker, or per-binary by passing the +.Fl z Ar now +option to the static linker +.Xr ld 1 , +or by using each symbol before the +.Fn _Fork +call to force the binding. .Sh RETURN VALUES Upon successful completion, .Fn fork -returns a value +and +.Fn _Fork +return a value of 0 to the child process and returns the process ID of the child process to the parent process. Otherwise, a value of -1 is returned @@ -176,9 +234,21 @@ There is insufficient swap space for the new process. .Xr setrlimit 2 , .Xr sigaction 2 , .Xr vfork 2 , -.Xr wait 2 +.Xr wait 2 , +.Xr pthread_atfork 3 .Sh HISTORY The .Fn fork function appeared in .At v1 . +.Pp +The +.Fn _Fork +function was defined by Austin Group together with the removal +of a requirement that the +.Fn fork +implementation must be async-signal safe. +The +.Fn _Fork +function appeared in +.Fx 14.0 . From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 12:39:29 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 274F566B151; Thu, 12 Aug 2021 12:39:29 +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 4GlmTs04hcz4jH0; Thu, 12 Aug 2021 12:39:29 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 DB58822F98; Thu, 12 Aug 2021 12:39:28 +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 17CCdSTQ058995; Thu, 12 Aug 2021 12:39:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CCdSi4058994; Thu, 12 Aug 2021 12:39:28 GMT (envelope-from git) Date: Thu, 12 Aug 2021 12:39:28 GMT Message-Id: <202108121239.17CCdSi4058994@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: f59374b69a95 - stable/13 - fork.2: correct minor typo in manpage. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f59374b69a95452aafc22a9b2881fd6ff23208ee Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 12:39:29 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=f59374b69a95452aafc22a9b2881fd6ff23208ee commit f59374b69a95452aafc22a9b2881fd6ff23208ee Author: Ceri Davies AuthorDate: 2021-08-05 18:36:33 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-12 12:37:54 +0000 fork.2: correct minor typo in manpage. (cherry picked from commit 383dbdb2ebffabf8c0efadd8928f8ef3e45ab9e5) --- lib/libc/sys/fork.2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libc/sys/fork.2 b/lib/libc/sys/fork.2 index bf934d166b03..d841b0bc38e1 100644 --- a/lib/libc/sys/fork.2 +++ b/lib/libc/sys/fork.2 @@ -150,7 +150,7 @@ Upon successful completion, and .Fn _Fork return a value -of 0 to the child process and returns the process ID of the child +of 0 to the child process and return the process ID of the child process to the parent process. Otherwise, a value of -1 is returned to the parent process, no child process is created, and the global From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 12:39:30 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A450F66AF39; Thu, 12 Aug 2021 12:39:30 +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 4GlmTt1HwDz4j5x; Thu, 12 Aug 2021 12:39:30 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 027D622F79; Thu, 12 Aug 2021 12:39:30 +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 17CCdTPg059021; Thu, 12 Aug 2021 12:39:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CCdTqm059020; Thu, 12 Aug 2021 12:39:29 GMT (envelope-from git) Date: Thu, 12 Aug 2021 12:39:29 GMT Message-Id: <202108121239.17CCdTqm059020@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 5d7b612949c1 - stable/13 - fork(2): comment about doubtful use of stdio and exit(3) in example MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5d7b612949c1c7f8a284d69e6db48a6c65cd16d3 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 12:39:30 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=5d7b612949c1c7f8a284d69e6db48a6c65cd16d3 commit 5d7b612949c1c7f8a284d69e6db48a6c65cd16d3 Author: Konstantin Belousov AuthorDate: 2021-08-05 16:03:03 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-12 12:37:54 +0000 fork(2): comment about doubtful use of stdio and exit(3) in example (cherry picked from commit 2a51e8823a60180feb534176bc41d5d10e2a01b1) --- lib/libc/sys/fork.2 | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/libc/sys/fork.2 b/lib/libc/sys/fork.2 index d841b0bc38e1..dbde8f5275aa 100644 --- a/lib/libc/sys/fork.2 +++ b/lib/libc/sys/fork.2 @@ -28,7 +28,7 @@ .\" @(#)fork.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd August 2, 2021 +.Dd August 5, 2021 .Dt FORK 2 .Os .Sh NAME @@ -172,11 +172,28 @@ main(void) { pid_t pid; + /* + * If child is expected to use stdio(3), state of + * the reused io streams must be synchronized between + * parent and child, to avoid double output and other + * possible issues. + */ + fflush(stdout); + switch (pid = fork()) { case -1: err(1, "Failed to fork"); case 0: printf("Hello from child process!\en"); + + /* + * Since we wrote into stdout, child needs to use + * exit(3) and not _exit(2). This causes handlers + * registered with atexit(3) to be called twice, + * once in parent, and once in the child. If such + * behavior is undesirable, consider + * terminating child with _exit(2) or _Exit(3). + */ exit(0); default: break; From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 12:39:31 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 88A2C66B161; Thu, 12 Aug 2021 12:39:31 +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 4GlmTv2DCLz4jCx; Thu, 12 Aug 2021 12:39:31 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 24EF422F99; Thu, 12 Aug 2021 12:39:31 +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 17CCdV52059047; Thu, 12 Aug 2021 12:39:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CCdVGN059046; Thu, 12 Aug 2021 12:39:31 GMT (envelope-from git) Date: Thu, 12 Aug 2021 12:39:31 GMT Message-Id: <202108121239.17CCdVGN059046@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: c4bb20a5ec87 - stable/13 - _Exit(3): document implementation MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c4bb20a5ec876fb44e152c5773b7104e4c753dec Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 12:39:31 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=c4bb20a5ec876fb44e152c5773b7104e4c753dec commit c4bb20a5ec876fb44e152c5773b7104e4c753dec Author: Konstantin Belousov AuthorDate: 2021-08-05 16:04:44 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-12 12:37:54 +0000 _Exit(3): document implementation (cherry picked from commit ee62fb2e1e14eab35d4e4e92535bcac9fc91eeb8) --- lib/libc/stdlib/exit.3 | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/libc/stdlib/exit.3 b/lib/libc/stdlib/exit.3 index 9c2b79b72956..ff7a67ffcb85 100644 --- a/lib/libc/stdlib/exit.3 +++ b/lib/libc/stdlib/exit.3 @@ -32,7 +32,7 @@ .\" @(#)exit.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd March 22, 2020 +.Dd August 5, 2021 .Dt EXIT 3 .Os .Sh NAME @@ -58,17 +58,17 @@ Before termination, performs the following functions in the order listed: .Bl -enum -offset indent .It -Call the functions registered with the +Call all functions registered with the +.Xr __cxa_atexit 3 +function +(which are typically destructors from the loaded dynamic objects), +and the functions registered with the .Xr atexit 3 function, in the reverse order of their registration. .It Flush all open output streams. .It Close all open streams. -.It -Unlink all files created with the -.Xr tmpfile 3 -function. .El .Pp The @@ -76,6 +76,14 @@ The function terminates without calling the functions registered with the .Xr atexit 3 function, and may or may not perform the other actions listed. +The +.Fx +implementation of the +.Fn _Exit +function does not call destructors registered with +.Xr __cxa_atexit 3, +does not flush buffers, and does not close streams. +.Pp Both functions make the low-order eight bits of the .Fa status argument available to a parent process which has called a From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 12:39:32 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A5C5C66AF3B; Thu, 12 Aug 2021 12:39:32 +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 4GlmTw3bTQz4j4C; Thu, 12 Aug 2021 12:39:32 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 4DE1F22F7A; Thu, 12 Aug 2021 12:39:32 +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 17CCdWR8059074; Thu, 12 Aug 2021 12:39:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CCdW4W059073; Thu, 12 Aug 2021 12:39:32 GMT (envelope-from git) Date: Thu, 12 Aug 2021 12:39:32 GMT Message-Id: <202108121239.17CCdW4W059073@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: c7b5abde5389 - stable/13 - Add vn_lktype_write() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c7b5abde53899c381ed6773b61e1ad940a44792f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 12:39:32 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=c7b5abde53899c381ed6773b61e1ad940a44792f commit c7b5abde53899c381ed6773b61e1ad940a44792f Author: Konstantin Belousov AuthorDate: 2021-08-04 02:34:48 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-12 12:37:54 +0000 Add vn_lktype_write() (cherry picked from commit 0ef5eee9d94162ac3cefa0bd8aedf1bfa6f87192) --- sys/cam/ctl/ctl_backend_block.c | 20 +++++--------------- sys/kern/vfs_syscalls.c | 10 ++-------- sys/kern/vfs_vnops.c | 34 ++++++++++++++-------------------- sys/sys/vnode.h | 1 + sys/vm/vm_pageout.c | 6 ++---- 5 files changed, 24 insertions(+), 47 deletions(-) diff --git a/sys/cam/ctl/ctl_backend_block.c b/sys/cam/ctl/ctl_backend_block.c index 4ffaf0912915..83ea6b43dac3 100644 --- a/sys/cam/ctl/ctl_backend_block.c +++ b/sys/cam/ctl/ctl_backend_block.c @@ -588,7 +588,7 @@ ctl_be_block_flush_file(struct ctl_be_block_lun *be_lun, { union ctl_io *io = beio->io; struct mount *mountpoint; - int error, lock_flags; + int error; DPRINTF("entered\n"); @@ -597,12 +597,8 @@ ctl_be_block_flush_file(struct ctl_be_block_lun *be_lun, (void) vn_start_write(be_lun->vn, &mountpoint, V_WAIT); - if (MNT_SHARED_WRITES(mountpoint) || - ((mountpoint == NULL) && MNT_SHARED_WRITES(be_lun->vn->v_mount))) - lock_flags = LK_SHARED; - else - lock_flags = LK_EXCLUSIVE; - vn_lock(be_lun->vn, lock_flags | LK_RETRY); + vn_lock(be_lun->vn, vn_lktype_write(mountpoint, be_lun->vn) | + LK_RETRY); error = VOP_FSYNC(be_lun->vn, beio->io_arg ? MNT_NOWAIT : MNT_WAIT, curthread); VOP_UNLOCK(be_lun->vn); @@ -722,16 +718,10 @@ ctl_be_block_dispatch_file(struct ctl_be_block_lun *be_lun, } } else { struct mount *mountpoint; - int lock_flags; (void)vn_start_write(be_lun->vn, &mountpoint, V_WAIT); - - if (MNT_SHARED_WRITES(mountpoint) || ((mountpoint == NULL) - && MNT_SHARED_WRITES(be_lun->vn->v_mount))) - lock_flags = LK_SHARED; - else - lock_flags = LK_EXCLUSIVE; - vn_lock(be_lun->vn, lock_flags | LK_RETRY); + vn_lock(be_lun->vn, vn_lktype_write(mountpoint, + be_lun->vn) | LK_RETRY); /* * UFS pays attention to IO_DIRECT for writes. The write diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 7f2f3480a5af..80bcc0cb4d41 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -3505,7 +3505,7 @@ kern_fsync(struct thread *td, int fd, bool fullsync) struct vnode *vp; struct mount *mp; struct file *fp; - int error, lock_flags; + int error; AUDIT_ARG_FD(fd); error = getvnode(td, fd, &cap_fsync_rights, &fp); @@ -3520,13 +3520,7 @@ retry: error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error != 0) goto drop; - if (MNT_SHARED_WRITES(mp) || - ((mp == NULL) && MNT_SHARED_WRITES(vp->v_mount))) { - lock_flags = LK_SHARED; - } else { - lock_flags = LK_EXCLUSIVE; - } - vn_lock(vp, lock_flags | LK_RETRY); + vn_lock(vp, vn_lktype_write(mp, vp) | LK_RETRY); AUDIT_ARG_VNODE1(vp); if (vp->v_object != NULL) { VM_OBJECT_WLOCK(vp->v_object); diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index fc5118e8aa24..b7e53add5a35 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -653,11 +653,7 @@ vn_rdwr(enum uio_rw rw, struct vnode *vp, void *base, int len, off_t offset, (error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) goto out; - if (MNT_SHARED_WRITES(mp) || - ((mp == NULL) && MNT_SHARED_WRITES(vp->v_mount))) - lock_flags = LK_SHARED; - else - lock_flags = LK_EXCLUSIVE; + lock_flags = vn_lktype_write(mp, vp); } else lock_flags = LK_SHARED; vn_lock(vp, lock_flags | LK_RETRY); @@ -1106,7 +1102,7 @@ vn_write(struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct vnode *vp; struct mount *mp; off_t orig_offset; - int error, ioflag, lock_flags; + int error, ioflag; int advice; bool need_finished_write; @@ -1147,14 +1143,7 @@ vn_write(struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, advice = get_advice(fp, uio); - if (MNT_SHARED_WRITES(mp) || - (mp == NULL && MNT_SHARED_WRITES(vp->v_mount))) { - lock_flags = LK_SHARED; - } else { - lock_flags = LK_EXCLUSIVE; - } - - vn_lock(vp, lock_flags | LK_RETRY); + vn_lock(vp, vn_lktype_write(mp, vp) | LK_RETRY); switch (advice) { case POSIX_FADV_NORMAL: case POSIX_FADV_SEQUENTIAL: @@ -3060,7 +3049,7 @@ vn_write_outvp(struct vnode *outvp, char *dat, off_t outoff, off_t xfer, { struct mount *mp; off_t dataoff, holeoff, xfer2; - int error, lckf; + int error; /* * Loop around doing writes of blksize until write has been completed. @@ -3099,11 +3088,7 @@ vn_write_outvp(struct vnode *outvp, char *dat, off_t outoff, off_t xfer, VOP_UNLOCK(outvp); } } else { - if (MNT_SHARED_WRITES(mp)) - lckf = LK_SHARED; - else - lckf = LK_EXCLUSIVE; - error = vn_lock(outvp, lckf); + error = vn_lock(outvp, vn_lktype_write(mp, outvp)); if (error == 0) { error = vn_rdwr(UIO_WRITE, outvp, dat, xfer2, outoff, UIO_SYSSPACE, IO_NODELOCKED, @@ -3532,3 +3517,12 @@ vn_lock_pair(struct vnode *vp1, bool vp1_locked, struct vnode *vp2, if (vp2 != NULL) ASSERT_VOP_ELOCKED(vp2, "vp2 ret"); } + +int +vn_lktype_write(struct mount *mp, struct vnode *vp) +{ + if (MNT_SHARED_WRITES(mp) || + (mp == NULL && MNT_SHARED_WRITES(vp->v_mount))) + return (LK_SHARED); + return (LK_EXCLUSIVE); +} diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 8b14aac36df0..8336fd859781 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -1087,6 +1087,7 @@ int vn_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, void vn_fsid(struct vnode *vp, struct vattr *va); int vn_dir_check_exec(struct vnode *vp, struct componentname *cnp); +int vn_lktype_write(struct mount *mp, struct vnode *vp); #define VOP_UNLOCK_FLAGS(vp, flags) ({ \ struct vnode *_vp = (vp); \ diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c index 216e76359631..9a0b295569e2 100644 --- a/sys/vm/vm_pageout.c +++ b/sys/vm/vm_pageout.c @@ -606,7 +606,7 @@ vm_pageout_clean(vm_page_t m, int *numpagedout) struct mount *mp; vm_object_t object; vm_pindex_t pindex; - int error, lockmode; + int error; object = m->object; VM_OBJECT_ASSERT_WLOCKED(object); @@ -640,9 +640,7 @@ vm_pageout_clean(vm_page_t m, int *numpagedout) vm_object_reference_locked(object); pindex = m->pindex; VM_OBJECT_WUNLOCK(object); - lockmode = MNT_SHARED_WRITES(vp->v_mount) ? - LK_SHARED : LK_EXCLUSIVE; - if (vget(vp, lockmode | LK_TIMELOCK)) { + if (vget(vp, vn_lktype_write(NULL, vp) | LK_TIMELOCK) != 0) { vp = NULL; error = EDEADLK; goto unlock_mp; From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 13:49:51 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A56D166C1FC; Thu, 12 Aug 2021 13:49:51 +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 4Glp333mZ4z4nMQ; Thu, 12 Aug 2021 13:49:51 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 6943E23BD5; Thu, 12 Aug 2021 13:49:51 +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 17CDnp7f052496; Thu, 12 Aug 2021 13:49:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CDnp0n052495; Thu, 12 Aug 2021 13:49:51 GMT (envelope-from git) Date: Thu, 12 Aug 2021 13:49:51 GMT Message-Id: <202108121349.17CDnp0n052495@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: b8adacf39a5a - stable/13 - amd64: Set GS.base before calling init_secondary() on APs MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b8adacf39a5a968dabb36390bc51388553fb6ca9 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 13:49:51 -0000 The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b8adacf39a5a968dabb36390bc51388553fb6ca9 commit b8adacf39a5a968dabb36390bc51388553fb6ca9 Author: Mark Johnston AuthorDate: 2021-07-29 14:22:37 +0000 Commit: Mark Johnston CommitDate: 2021-08-12 13:43:21 +0000 amd64: Set GS.base before calling init_secondary() on APs KMSAN instrumentation requires thread-local storage to track initialization state for function parameters and return values. This buffer is accessed as part of each function prologue. It is provided by the KMSAN runtime, which looks up a pointer in the current thread's structure. When KMSAN is configured, init_secondary() is instrumented, but this means that GS.base must be initialized first, otherwise the runtime cannot safely access curthread. Work around this by loading GS.base before calling init_secondary(), so that the runtime can at least check curthread == NULL and return a pointer to some dummy storage. Note that init_secondary() still must reload GS.base after calling lgdt(), which loads a selector into %gs, which in turn clears the base register. Reviewed by: kib Sponsored by: The FreeBSD Foundation (cherry picked from commit 4b136ef259cefedc9b6404afc09138aeb8acbd91) --- sys/amd64/amd64/mp_machdep.c | 8 ++++---- sys/amd64/amd64/mpboot.S | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c index 74f1af919b66..41c082ff40e9 100644 --- a/sys/amd64/amd64/mp_machdep.c +++ b/sys/amd64/amd64/mp_machdep.c @@ -103,6 +103,7 @@ char *doublefault_stack; char *mce_stack; char *nmi_stack; char *dbg_stack; +void *bootpcpu; extern u_int mptramp_la57; @@ -273,10 +274,8 @@ init_secondary(void) /* Update microcode before doing anything else. */ ucode_load_ap(cpu); - /* Get per-cpu data and save */ - pc = &__pcpu[cpu]; - - /* prime data page for it to use */ + /* Initialize the PCPU area. */ + pc = bootpcpu; pcpu_init(pc, cpu, sizeof(struct pcpu)); dpcpu_init(dpcpu, cpu); pc->pc_apic_id = cpu_apic_ids[cpu]; @@ -495,6 +494,7 @@ native_start_all_aps(void) dpcpu = (void *)kmem_malloc_domainset(DOMAINSET_PREF(domain), DPCPU_SIZE, M_WAITOK | M_ZERO); + bootpcpu = &__pcpu[cpu]; bootSTK = (char *)bootstacks[cpu] + kstack_pages * PAGE_SIZE - 8; bootAP = cpu; diff --git a/sys/amd64/amd64/mpboot.S b/sys/amd64/amd64/mpboot.S index e525102b5d3d..afdcffa573a4 100644 --- a/sys/amd64/amd64/mpboot.S +++ b/sys/amd64/amd64/mpboot.S @@ -270,4 +270,21 @@ entry_64: 2: movq KPML5phys, %rax 3: movq %rax, %cr3 movq bootSTK, %rsp + + /* + * Initialize the segment register used for the PCPU area. The PCPU + * area will be initialized by init_secondary(), but it should be + * accessible before that to support sanitizer instrumentation which + * accesses per-CPU variables. + * + * Note that GS.base is loaded again in init_secondary(). This is not + * redundant: lgdt() loads a selector into %gs and this has the side + * effect of clearing GS.base. + */ + movl $MSR_GSBASE, %ecx + movq bootpcpu, %rax + movq %rax, %rdx + shrq $32, %rdx + wrmsr + jmp init_secondary From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 13:49:52 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C56D366C81C; Thu, 12 Aug 2021 13:49: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 4Glp344ry0z4n8f; Thu, 12 Aug 2021 13:49:52 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 8BB2223B7D; Thu, 12 Aug 2021 13:49: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 17CDnqIm052520; Thu, 12 Aug 2021 13:49:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CDnq8U052519; Thu, 12 Aug 2021 13:49:52 GMT (envelope-from git) Date: Thu, 12 Aug 2021 13:49:52 GMT Message-Id: <202108121349.17CDnq8U052519@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 7f39284c271b - stable/13 - amd64: Set MSR_KGSBASE to 0 during AP startup MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 7f39284c271b6c5801b6af9a9f0e46805528b244 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 13:49:52 -0000 The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7f39284c271b6c5801b6af9a9f0e46805528b244 commit 7f39284c271b6c5801b6af9a9f0e46805528b244 Author: Mark Johnston AuthorDate: 2021-07-29 14:14:05 +0000 Commit: Mark Johnston CommitDate: 2021-08-12 13:43:31 +0000 amd64: Set MSR_KGSBASE to 0 during AP startup There is no reason to initialize it to anything else, and this matches initialization of the BSP. No functional change intended. Reviewed by: kib Sponsored by: The FreeBSD Foundation (cherry picked from commit e1537450838134daaf584d1f17e661673b2c4c76) --- sys/amd64/amd64/mp_machdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c index 41c082ff40e9..d1064262891f 100644 --- a/sys/amd64/amd64/mp_machdep.c +++ b/sys/amd64/amd64/mp_machdep.c @@ -337,8 +337,8 @@ init_secondary(void) lgdt(&ap_gdt); /* does magic intra-segment return */ wrmsr(MSR_FSBASE, 0); /* User value */ - wrmsr(MSR_GSBASE, (u_int64_t)pc); - wrmsr(MSR_KGSBASE, (u_int64_t)pc); /* XXX User value while we're in the kernel */ + wrmsr(MSR_GSBASE, (uint64_t)pc); + wrmsr(MSR_KGSBASE, 0); /* User value */ fix_cpuid(); lidt(&r_idt); From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 13:49:54 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5323B66C247; Thu, 12 Aug 2021 13:49:54 +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 4Glp360lMwz4n8j; Thu, 12 Aug 2021 13:49:54 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B053423B7E; Thu, 12 Aug 2021 13:49:53 +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 17CDnr6C052546; Thu, 12 Aug 2021 13:49:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CDnrFO052545; Thu, 12 Aug 2021 13:49:53 GMT (envelope-from git) Date: Thu, 12 Aug 2021 13:49:53 GMT Message-Id: <202108121349.17CDnrFO052545@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: f53932dfc411 - stable/13 - link_elf_obj: Invoke fini callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f53932dfc411fbab6f8d8fbca8727a97cc5b92a9 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 13:49:54 -0000 The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f53932dfc411fbab6f8d8fbca8727a97cc5b92a9 commit f53932dfc411fbab6f8d8fbca8727a97cc5b92a9 Author: Mark Johnston AuthorDate: 2021-07-29 13:46:25 +0000 Commit: Mark Johnston CommitDate: 2021-08-12 13:43:41 +0000 link_elf_obj: Invoke fini callbacks This is required for KASAN: when a module is unloaded, poisoned regions (e.g., pad areas between global variables) are left as such, so if they are reused as KLDs are loaded, false positives can arise. Reported by: pho, Jenkins Reviewed by: kib Sponsored by: The FreeBSD Foundation (cherry picked from commit 9e575fadf491152fb3445d4837d49a9cb87dd6e2) --- sys/kern/kern_linker.c | 2 ++ sys/kern/link_elf_obj.c | 32 +++++++++++++++++++++++++++++--- sys/sys/linker.h | 6 ++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c index dbbf240a2f56..cb5d587bfbbc 100644 --- a/sys/kern/kern_linker.c +++ b/sys/kern/kern_linker.c @@ -613,6 +613,8 @@ linker_make_file(const char *pathname, linker_class_t lc) return (NULL); lf->ctors_addr = 0; lf->ctors_size = 0; + lf->dtors_addr = 0; + lf->dtors_size = 0; lf->refs = 1; lf->userrefs = 0; lf->flags = 0; diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c index 65b997b513e3..91852939e5e8 100644 --- a/sys/kern/link_elf_obj.c +++ b/sys/kern/link_elf_obj.c @@ -544,6 +544,17 @@ link_elf_link_preload(linker_class_t cls, const char *filename, lf->ctors_addr = ef->progtab[pb].addr; lf->ctors_size = shdr[i].sh_size; } + } else if ((ef->progtab[pb].name != NULL && + strcmp(ef->progtab[pb].name, ".dtors") == 0) || + shdr[i].sh_type == SHT_FINI_ARRAY) { + if (lf->dtors_addr != 0) { + printf( + "%s: multiple dtor sections in %s\n", + __func__, filename); + } else { + lf->dtors_addr = ef->progtab[pb].addr; + lf->dtors_size = shdr[i].sh_size; + } } /* Update all symbol values with the offset. */ @@ -612,7 +623,7 @@ out: } static void -link_elf_invoke_ctors(caddr_t addr, size_t size) +link_elf_invoke_cbs(caddr_t addr, size_t size) { void (**ctor)(void); size_t i, cnt; @@ -653,7 +664,7 @@ link_elf_link_preload_finish(linker_file_t lf) /* Apply protections now that relocation processing is complete. */ link_elf_protect(ef); - link_elf_invoke_ctors(lf->ctors_addr, lf->ctors_size); + link_elf_invoke_cbs(lf->ctors_addr, lf->ctors_size); return (0); } @@ -1012,6 +1023,19 @@ link_elf_load_file(linker_class_t cls, const char *filename, lf->ctors_size = shdr[i].sh_size; } + } else if (!strcmp(ef->progtab[pb].name, + ".dtors") || + shdr[i].sh_type == SHT_FINI_ARRAY) { + if (lf->dtors_addr != 0) { + printf( + "%s: multiple dtor sections in %s\n", + __func__, filename); + } else { + lf->dtors_addr = + (caddr_t)mapbase; + lf->dtors_size = + shdr[i].sh_size; + } } } else if (shdr[i].sh_type == SHT_PROGBITS) ef->progtab[pb].name = "<>"; @@ -1196,7 +1220,7 @@ link_elf_load_file(linker_class_t cls, const char *filename, #endif link_elf_protect(ef); - link_elf_invoke_ctors(lf->ctors_addr, lf->ctors_size); + link_elf_invoke_cbs(lf->ctors_addr, lf->ctors_size); *result = lf; out: @@ -1216,6 +1240,8 @@ link_elf_unload_file(linker_file_t file) elf_file_t ef = (elf_file_t) file; u_int i; + link_elf_invoke_cbs(file->dtors_addr, file->dtors_size); + /* Notify MD code that a module is being unloaded. */ elf_cpu_unload_file(file); diff --git a/sys/sys/linker.h b/sys/sys/linker.h index 6423a3989a02..35c8449382cf 100644 --- a/sys/sys/linker.h +++ b/sys/sys/linker.h @@ -82,8 +82,10 @@ struct linker_file { int id; /* unique id */ caddr_t address; /* load address */ size_t size; /* size of file */ - caddr_t ctors_addr; /* address of .ctors */ - size_t ctors_size; /* size of .ctors */ + caddr_t ctors_addr; /* address of .ctors/.init_array */ + size_t ctors_size; /* size of .ctors/.init_array */ + caddr_t dtors_addr; /* address of .dtors/.fini_array */ + size_t dtors_size; /* size of .dtors/.fini_array */ int ndeps; /* number of dependencies */ linker_file_t* deps; /* list of dependencies */ STAILQ_HEAD(, common_symbol) common; /* list of common symbols */ From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 17:02:29 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1DF5966F801; Thu, 12 Aug 2021 17:02:29 +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 4GltKK0Pgsz3JN2; Thu, 12 Aug 2021 17:02:29 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 DFE4526B05; Thu, 12 Aug 2021 17:02:28 +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 17CH2SUE017741; Thu, 12 Aug 2021 17:02:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CH2SxC017740; Thu, 12 Aug 2021 17:02:28 GMT (envelope-from git) Date: Thu, 12 Aug 2021 17:02:28 GMT Message-Id: <202108121702.17CH2SxC017740@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 909459c2eda4 - stable/13 - bhyve: Register new kevents synchronously. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 909459c2eda4a6bc45e1fe5ff3da992e9614392b Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 17:02:29 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=909459c2eda4a6bc45e1fe5ff3da992e9614392b commit 909459c2eda4a6bc45e1fe5ff3da992e9614392b Author: John Baldwin AuthorDate: 2021-06-12 00:58:54 +0000 Commit: John Baldwin CommitDate: 2021-08-12 15:56:13 +0000 bhyve: Register new kevents synchronously. Change mevent_add*() to synchronously add the new kevent. This permits reporting event registration failures to the caller and avoids failing the registration of other, unrelated events queued up in the same batch. Reviewed by: grehan, markj MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D30502 (cherry picked from commit e8424e2947dd8a0e1d3f08295432941b5c5aafb9) --- usr.sbin/bhyve/mevent.c | 96 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 33 deletions(-) diff --git a/usr.sbin/bhyve/mevent.c b/usr.sbin/bhyve/mevent.c index 2e9059837011..a394b7c5d69f 100644 --- a/usr.sbin/bhyve/mevent.c +++ b/usr.sbin/bhyve/mevent.c @@ -64,8 +64,10 @@ __FBSDID("$FreeBSD$"); #define MEVENT_MAX 64 static pthread_t mevent_tid; +static pthread_once_t mevent_once = PTHREAD_ONCE_INIT; static int mevent_timid = 43; static int mevent_pipefd[2]; +static int mfd; static pthread_mutex_t mevent_lmutex = PTHREAD_MUTEX_INITIALIZER; struct mevent { @@ -124,6 +126,26 @@ mevent_notify(void) } } +static void +mevent_init(void) +{ +#ifndef WITHOUT_CAPSICUM + cap_rights_t rights; +#endif + + mfd = kqueue(); + assert(mfd > 0); + +#ifndef WITHOUT_CAPSICUM + cap_rights_init(&rights, CAP_KQUEUE); + if (caph_rights_limit(mfd, &rights) == -1) + errx(EX_OSERR, "Unable to apply rights for sandbox"); +#endif + + LIST_INIT(&change_head); + LIST_INIT(&global_head); +} + static int mevent_kq_filter(struct mevent *mevp) { @@ -159,8 +181,24 @@ mevent_kq_fflags(struct mevent *mevp) return (0); } +static void +mevent_populate(struct mevent *mevp, struct kevent *kev) +{ + if (mevp->me_type == EVF_TIMER) { + kev->ident = mevp->me_timid; + kev->data = mevp->me_msecs; + } else { + kev->ident = mevp->me_fd; + kev->data = 0; + } + kev->filter = mevent_kq_filter(mevp); + kev->flags = mevent_kq_flags(mevp); + kev->fflags = mevent_kq_fflags(mevp); + kev->udata = mevp; +} + static int -mevent_build(int mfd, struct kevent *kev) +mevent_build(struct kevent *kev) { struct mevent *mevp, *tmpp; int i; @@ -177,17 +215,8 @@ mevent_build(int mfd, struct kevent *kev) */ close(mevp->me_fd); } else { - if (mevp->me_type == EVF_TIMER) { - kev[i].ident = mevp->me_timid; - kev[i].data = mevp->me_msecs; - } else { - kev[i].ident = mevp->me_fd; - kev[i].data = 0; - } - kev[i].filter = mevent_kq_filter(mevp); - kev[i].flags = mevent_kq_flags(mevp); - kev[i].fflags = mevent_kq_fflags(mevp); - kev[i].udata = mevp; + assert((mevp->me_state & EV_ADD) == 0); + mevent_populate(mevp, &kev[i]); i++; } @@ -197,12 +226,6 @@ mevent_build(int mfd, struct kevent *kev) if (mevp->me_state & EV_DELETE) { free(mevp); } else { - /* - * We need to add the event only once, so we can - * reset the EV_ADD bit after it has been propagated - * to the kevent() arguments the first time. - */ - mevp->me_state &= ~EV_ADD; LIST_INSERT_HEAD(&global_head, mevp, me_list); } @@ -234,7 +257,9 @@ mevent_add_state(int tfd, enum ev_type type, void (*func)(int, enum ev_type, void *), void *param, int state) { + struct kevent kev; struct mevent *lp, *mevp; + int ret; if (tfd < 0 || func == NULL) { return (NULL); @@ -242,6 +267,8 @@ mevent_add_state(int tfd, enum ev_type type, mevp = NULL; + pthread_once(&mevent_once, mevent_init); + mevent_qlock(); /* @@ -262,7 +289,7 @@ mevent_add_state(int tfd, enum ev_type type, } /* - * Allocate an entry, populate it, and add it to the change list. + * Allocate an entry and populate it. */ mevp = calloc(1, sizeof(struct mevent)); if (mevp == NULL) { @@ -277,11 +304,22 @@ mevent_add_state(int tfd, enum ev_type type, mevp->me_type = type; mevp->me_func = func; mevp->me_param = param; - - LIST_INSERT_HEAD(&change_head, mevp, me_list); - mevp->me_cq = 1; mevp->me_state = state; - mevent_notify(); + + /* + * Try to add the event. If this fails, report the failure to + * the caller. + */ + mevent_populate(mevp, &kev); + ret = kevent(mfd, &kev, 1, NULL, 0, NULL); + if (ret == -1) { + free(mevp); + mevp = NULL; + goto exit; + } + + mevp->me_state &= ~EV_ADD; + LIST_INSERT_HEAD(&global_head, mevp, me_list); exit: mevent_qunlock(); @@ -415,7 +453,6 @@ mevent_dispatch(void) struct kevent changelist[MEVENT_MAX]; struct kevent eventlist[MEVENT_MAX]; struct mevent *pipev; - int mfd; int numev; int ret; #ifndef WITHOUT_CAPSICUM @@ -425,14 +462,7 @@ mevent_dispatch(void) mevent_tid = pthread_self(); mevent_set_name(); - mfd = kqueue(); - assert(mfd > 0); - -#ifndef WITHOUT_CAPSICUM - cap_rights_init(&rights, CAP_KQUEUE); - if (caph_rights_limit(mfd, &rights) == -1) - errx(EX_OSERR, "Unable to apply rights for sandbox"); -#endif + pthread_once(&mevent_once, mevent_init); /* * Open the pipe that will be used for other threads to force @@ -466,7 +496,7 @@ mevent_dispatch(void) * to eliminate the extra syscall. Currently better for * debug. */ - numev = mevent_build(mfd, changelist); + numev = mevent_build(changelist); if (numev) { ret = kevent(mfd, changelist, numev, NULL, 0, NULL); if (ret == -1) { From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 17:02:30 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 53F8566F1E4; Thu, 12 Aug 2021 17:02:30 +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 4GltKL16Y9z3JN7; Thu, 12 Aug 2021 17:02:30 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 0AA3626B81; Thu, 12 Aug 2021 17:02:30 +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 17CH2TQ3017772; Thu, 12 Aug 2021 17:02:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CH2TVH017771; Thu, 12 Aug 2021 17:02:29 GMT (envelope-from git) Date: Thu, 12 Aug 2021 17:02:29 GMT Message-Id: <202108121702.17CH2TVH017771@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: d7e2c1479ccf - stable/13 - bhyve: Add support for EVFILT_VNODE mevents. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: d7e2c1479ccf5bbbe7d80c203e05300353d24e52 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 17:02:30 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=d7e2c1479ccf5bbbe7d80c203e05300353d24e52 commit d7e2c1479ccf5bbbe7d80c203e05300353d24e52 Author: John Baldwin AuthorDate: 2021-06-12 00:59:13 +0000 Commit: John Baldwin CommitDate: 2021-08-12 15:56:18 +0000 bhyve: Add support for EVFILT_VNODE mevents. This allows registering an event to watch for changes to a file's attributes. This is a bit imperfect as it would be nice to have a way to determine if an fd can use EVFILT_VNODE successfully. mevent's current structure does not permit that and a failure to register a single kevent impacts several other kevents. Reviewed by: grehan, markj MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D30503 (cherry picked from commit 67d60dcce62c08250dceedaf761cb48bc74c75a4) --- usr.sbin/bhyve/mevent.c | 33 ++++++++++++++++++++++++++++----- usr.sbin/bhyve/mevent.h | 9 ++++++++- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/usr.sbin/bhyve/mevent.c b/usr.sbin/bhyve/mevent.c index a394b7c5d69f..0c5351cd31a9 100644 --- a/usr.sbin/bhyve/mevent.c +++ b/usr.sbin/bhyve/mevent.c @@ -80,6 +80,7 @@ struct mevent { int me_cq; int me_state; /* Desired kevent flags. */ int me_closefd; + int me_fflags; LIST_ENTRY(mevent) me_list; }; @@ -165,6 +166,9 @@ mevent_kq_filter(struct mevent *mevp) if (mevp->me_type == EVF_SIGNAL) retval = EVFILT_SIGNAL; + if (mevp->me_type == EVF_VNODE) + retval = EVFILT_VNODE; + return (retval); } @@ -177,8 +181,18 @@ mevent_kq_flags(struct mevent *mevp) static int mevent_kq_fflags(struct mevent *mevp) { - /* XXX nothing yet, perhaps EV_EOF for reads ? */ - return (0); + int retval; + + retval = 0; + + switch (mevp->me_type) { + case EVF_VNODE: + if ((mevp->me_fflags & EVFF_ATTRIB) != 0) + retval |= NOTE_ATTRIB; + break; + } + + return (retval); } static void @@ -255,7 +269,7 @@ mevent_handle(struct kevent *kev, int numev) static struct mevent * mevent_add_state(int tfd, enum ev_type type, void (*func)(int, enum ev_type, void *), void *param, - int state) + int state, int fflags) { struct kevent kev; struct mevent *lp, *mevp; @@ -305,6 +319,7 @@ mevent_add_state(int tfd, enum ev_type type, mevp->me_func = func; mevp->me_param = param; mevp->me_state = state; + mevp->me_fflags = fflags; /* * Try to add the event. If this fails, report the failure to @@ -332,7 +347,15 @@ mevent_add(int tfd, enum ev_type type, void (*func)(int, enum ev_type, void *), void *param) { - return (mevent_add_state(tfd, type, func, param, EV_ADD)); + return (mevent_add_state(tfd, type, func, param, EV_ADD, 0)); +} + +struct mevent * +mevent_add_flags(int tfd, enum ev_type type, int fflags, + void (*func)(int, enum ev_type, void *), void *param) +{ + + return (mevent_add_state(tfd, type, func, param, EV_ADD, fflags)); } struct mevent * @@ -340,7 +363,7 @@ mevent_add_disabled(int tfd, enum ev_type type, void (*func)(int, enum ev_type, void *), void *param) { - return (mevent_add_state(tfd, type, func, param, EV_ADD | EV_DISABLE)); + return (mevent_add_state(tfd, type, func, param, EV_ADD | EV_DISABLE, 0)); } static int diff --git a/usr.sbin/bhyve/mevent.h b/usr.sbin/bhyve/mevent.h index 503ec415a3b5..a26293867a09 100644 --- a/usr.sbin/bhyve/mevent.h +++ b/usr.sbin/bhyve/mevent.h @@ -35,14 +35,21 @@ enum ev_type { EVF_READ, EVF_WRITE, EVF_TIMER, - EVF_SIGNAL + EVF_SIGNAL, + EVF_VNODE, }; +/* Filter flags for EVF_VNODE */ +#define EVFF_ATTRIB 0x0001 + struct mevent; struct mevent *mevent_add(int fd, enum ev_type type, void (*func)(int, enum ev_type, void *), void *param); +struct mevent *mevent_add_flags(int fd, enum ev_type type, int fflags, + void (*func)(int, enum ev_type, void *), + void *param); struct mevent *mevent_add_disabled(int fd, enum ev_type type, void (*func)(int, enum ev_type, void *), void *param); From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 17:02:32 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6CB8D66F805; Thu, 12 Aug 2021 17:02:32 +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 4GltKN2HSBz3JQh; Thu, 12 Aug 2021 17:02:32 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 358A226AD0; Thu, 12 Aug 2021 17:02:32 +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 17CH2WMF018542; Thu, 12 Aug 2021 17:02:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CH2WWN018541; Thu, 12 Aug 2021 17:02:32 GMT (envelope-from git) Date: Thu, 12 Aug 2021 17:02:32 GMT Message-Id: <202108121702.17CH2WWN018541@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: e8b442c74c90 - stable/13 - bhyve: Split out a lower-level helper for VirtIO interrupts. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e8b442c74c903dfd020a83ebba7d1b3c2c281aba Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 17:02:32 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=e8b442c74c903dfd020a83ebba7d1b3c2c281aba commit e8b442c74c903dfd020a83ebba7d1b3c2c281aba Author: John Baldwin AuthorDate: 2021-06-12 00:59:35 +0000 Commit: John Baldwin CommitDate: 2021-08-12 17:01:25 +0000 bhyve: Split out a lower-level helper for VirtIO interrupts. This allows device models to assert VirtIO interrupts for reasons other than publishing changes to a VirtIO ring such as configuration changes. Reviewed by: grehan, markj MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D30505 (cherry picked from commit c06676bee3d228ac18c5ed3604304e932eb84c1e) --- usr.sbin/bhyve/virtio.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/usr.sbin/bhyve/virtio.h b/usr.sbin/bhyve/virtio.h index e03fd5f710d1..5b2cf6fe2cc8 100644 --- a/usr.sbin/bhyve/virtio.h +++ b/usr.sbin/bhyve/virtio.h @@ -332,24 +332,35 @@ vq_has_descs(struct vqueue_info *vq) } /* - * Deliver an interrupt to guest on the given virtual queue - * (if possible, or a generic MSI interrupt if not using MSI-X). + * Deliver an interrupt to the guest for a specific MSI-X queue or + * event. */ static inline void -vq_interrupt(struct virtio_softc *vs, struct vqueue_info *vq) +vi_interrupt(struct virtio_softc *vs, uint8_t isr, uint16_t msix_idx) { if (pci_msix_enabled(vs->vs_pi)) - pci_generate_msix(vs->vs_pi, vq->vq_msix_idx); + pci_generate_msix(vs->vs_pi, msix_idx); else { VS_LOCK(vs); - vs->vs_isr |= VIRTIO_PCI_ISR_INTR; + vs->vs_isr |= isr; pci_generate_msi(vs->vs_pi, 0); pci_lintr_assert(vs->vs_pi); VS_UNLOCK(vs); } } +/* + * Deliver an interrupt to the guest on the given virtual queue (if + * possible, or a generic MSI interrupt if not using MSI-X). + */ +static inline void +vq_interrupt(struct virtio_softc *vs, struct vqueue_info *vq) +{ + + vi_interrupt(vs, VIRTIO_PCI_ISR_INTR, vq->vq_msix_idx); +} + static inline void vq_kick_enable(struct vqueue_info *vq) { From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 17:02:31 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B522366F1E6; Thu, 12 Aug 2021 17:02:31 +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 4GltKM1zmhz3JQb; Thu, 12 Aug 2021 17:02:31 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 1C8CE26ACF; Thu, 12 Aug 2021 17:02:31 +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 17CH2V0w018339; Thu, 12 Aug 2021 17:02:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CH2Urj018332; Thu, 12 Aug 2021 17:02:30 GMT (envelope-from git) Date: Thu, 12 Aug 2021 17:02:30 GMT Message-Id: <202108121702.17CH2Urj018332@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 0f01337e3af4 - stable/13 - bhyve: Add support for handling disk resize events to block_if. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 0f01337e3af4c013f3ef81401a56d420fa4de997 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 17:02:31 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=0f01337e3af4c013f3ef81401a56d420fa4de997 commit 0f01337e3af4c013f3ef81401a56d420fa4de997 Author: John Baldwin AuthorDate: 2021-06-12 00:59:25 +0000 Commit: John Baldwin CommitDate: 2021-08-12 15:56:23 +0000 bhyve: Add support for handling disk resize events to block_if. Allow clients of blockif to register a resize callback handler. When a callback is registered, register an EVFILT_VNODE kevent watching the backing store for a change in the file's attributes. If the size has changed when the kevent fires, invoke the clients' callback. Currently resize detection is limited to backing stores that support EVFILT_VNODE kevents such as regular files. Reviewed by: grehan, markj MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D30504 (cherry picked from commit 8794846a91c5429c612ba939c61ebf8f1ff1a628) --- usr.sbin/bhyve/block_if.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++- usr.sbin/bhyve/block_if.h | 5 ++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/block_if.c b/usr.sbin/bhyve/block_if.c index ae09bc71d622..98c0f9f5f38b 100644 --- a/usr.sbin/bhyve/block_if.c +++ b/usr.sbin/bhyve/block_if.c @@ -115,6 +115,9 @@ struct blockif_ctxt { pthread_cond_t bc_cond; pthread_cond_t bc_paused_cond; pthread_cond_t bc_work_done_cond; + blockif_resize_cb *bc_resize_cb; + void *bc_resize_cb_arg; + struct mevent *bc_resize_event; /* Request elements and free/pending/busy queues */ TAILQ_HEAD(, blockif_elem) bc_freeq; @@ -532,7 +535,7 @@ blockif_open(nvlist_t *nvl, const char *ident) #ifndef WITHOUT_CAPSICUM cap_rights_init(&rights, CAP_FSYNC, CAP_IOCTL, CAP_READ, CAP_SEEK, - CAP_WRITE); + CAP_WRITE, CAP_FSTAT, CAP_EVENT); if (ro) cap_rights_clear(&rights, CAP_FSYNC, CAP_WRITE); @@ -643,6 +646,62 @@ err: return (NULL); } +static void +blockif_resized(int fd, enum ev_type type, void *arg) +{ + struct blockif_ctxt *bc; + struct stat sb; + + if (fstat(fd, &sb) != 0) + return; + + bc = arg; + pthread_mutex_lock(&bc->bc_mtx); + if (sb.st_size != bc->bc_size) { + bc->bc_size = sb.st_size; + bc->bc_resize_cb(bc, bc->bc_resize_cb_arg, bc->bc_size); + } + pthread_mutex_unlock(&bc->bc_mtx); +} + +int +blockif_register_resize_callback(struct blockif_ctxt *bc, blockif_resize_cb *cb, + void *cb_arg) +{ + struct stat sb; + int err; + + if (cb == NULL) + return (EINVAL); + + pthread_mutex_lock(&bc->bc_mtx); + if (bc->bc_resize_cb != NULL) { + err = EBUSY; + goto out; + } + + assert(bc->bc_closing == 0); + + if (fstat(bc->bc_fd, &sb) != 0) { + err = errno; + goto out; + } + + bc->bc_resize_event = mevent_add_flags(bc->bc_fd, EVF_VNODE, + EVFF_ATTRIB, blockif_resized, bc); + if (bc->bc_resize_event == NULL) { + err = ENXIO; + goto out; + } + + bc->bc_resize_cb = cb; + bc->bc_resize_cb_arg = cb_arg; +out: + pthread_mutex_unlock(&bc->bc_mtx); + + return (err); +} + static int blockif_request(struct blockif_ctxt *bc, struct blockif_req *breq, enum blockop op) @@ -796,6 +855,8 @@ blockif_close(struct blockif_ctxt *bc) */ pthread_mutex_lock(&bc->bc_mtx); bc->bc_closing = 1; + if (bc->bc_resize_event != NULL) + mevent_disable(bc->bc_resize_event); pthread_mutex_unlock(&bc->bc_mtx); pthread_cond_broadcast(&bc->bc_cond); for (i = 0; i < BLOCKIF_NUMTHR; i++) diff --git a/usr.sbin/bhyve/block_if.h b/usr.sbin/bhyve/block_if.h index 87ae4d169969..0407ff43cf94 100644 --- a/usr.sbin/bhyve/block_if.h +++ b/usr.sbin/bhyve/block_if.h @@ -63,8 +63,13 @@ struct blockif_req { }; struct blockif_ctxt; + +typedef void blockif_resize_cb(struct blockif_ctxt *, void *, size_t); + int blockif_legacy_config(nvlist_t *nvl, const char *opts); struct blockif_ctxt *blockif_open(nvlist_t *nvl, const char *ident); +int blockif_register_resize_callback(struct blockif_ctxt *bc, + blockif_resize_cb *cb, void *cb_arg); off_t blockif_size(struct blockif_ctxt *bc); void blockif_chs(struct blockif_ctxt *bc, uint16_t *c, uint8_t *h, uint8_t *s); From owner-dev-commits-src-branches@freebsd.org Thu Aug 12 17:02:33 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A850966F886; Thu, 12 Aug 2021 17:02:33 +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 4GltKP3zlqz3JNf; Thu, 12 Aug 2021 17:02:33 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 5F75D2692A; Thu, 12 Aug 2021 17:02:33 +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 17CH2XIL018566; Thu, 12 Aug 2021 17:02:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CH2Xmr018565; Thu, 12 Aug 2021 17:02:33 GMT (envelope-from git) Date: Thu, 12 Aug 2021 17:02:33 GMT Message-Id: <202108121702.17CH2Xmr018565@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 86139cc75a55 - stable/13 - bhyve vtblk: Inform guests of disk resize events. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 86139cc75a5506bde6a4b180c024294e470d5cb6 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2021 17:02:33 -0000 The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=86139cc75a5506bde6a4b180c024294e470d5cb6 commit 86139cc75a5506bde6a4b180c024294e470d5cb6 Author: John Baldwin AuthorDate: 2021-06-12 00:59:46 +0000 Commit: John Baldwin CommitDate: 2021-08-12 17:01:34 +0000 bhyve vtblk: Inform guests of disk resize events. Register a resize callback with the blockif interface. When the callback fires, update the size of the disk and notify the guest via a configuration change interrupt. Reviewed by: grehan, markj MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D30506 (cherry picked from commit 2349cda44fea17c089b026e743ec8f03199019eb) --- usr.sbin/bhyve/pci_virtio_block.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/pci_virtio_block.c b/usr.sbin/bhyve/pci_virtio_block.c index 8a172c54eda7..3718b2d7eff0 100644 --- a/usr.sbin/bhyve/pci_virtio_block.c +++ b/usr.sbin/bhyve/pci_virtio_block.c @@ -3,7 +3,7 @@ * * Copyright (c) 2011 NetApp, Inc. * All rights reserved. - * Copyright 2020 Joyent, Inc. + * Copyright 2020-2021 Joyent, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -436,6 +436,18 @@ pci_vtblk_notify(void *vsc, struct vqueue_info *vq) pci_vtblk_proc(sc, vq); } +static void +pci_vtblk_resized(struct blockif_ctxt *bctxt, void *arg, size_t new_size) +{ + struct pci_vtblk_softc *sc; + + sc = arg; + + sc->vbsc_cfg.vbc_capacity = new_size / VTBLK_BSIZE; /* 512-byte units */ + vi_interrupt(&sc->vbsc_vs, VIRTIO_PCI_ISR_CONFIG, + sc->vbsc_vs.vs_msix_cfg_idx); +} + static int pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) { @@ -541,6 +553,7 @@ pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) return (1); } vi_set_io_bar(&sc->vbsc_vs, 0); + blockif_register_resize_callback(sc->bc, pci_vtblk_resized, sc); return (0); } From owner-dev-commits-src-branches@freebsd.org Fri Aug 13 01:18:41 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 048E367578A; Fri, 13 Aug 2021 01:18:41 +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 4Gm5Kr6R7Vz4Z3V; Fri, 13 Aug 2021 01:18:40 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B63612CFB1; Fri, 13 Aug 2021 01:18:40 +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 17D1IeP7071220; Fri, 13 Aug 2021 01:18:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17D1IeOP071219; Fri, 13 Aug 2021 01:18:40 GMT (envelope-from git) Date: Fri, 13 Aug 2021 01:18:40 GMT Message-Id: <202108130118.17D1IeOP071219@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: b41b86b65f10 - stable/13 - ipmi(4): Add more watchdog error checks. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b41b86b65f10ccaa8cce8cc11a030ad464b654c0 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 01:18:41 -0000 The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=b41b86b65f10ccaa8cce8cc11a030ad464b654c0 commit b41b86b65f10ccaa8cce8cc11a030ad464b654c0 Author: Alexander Motin AuthorDate: 2021-07-30 03:39:04 +0000 Commit: Alexander Motin CommitDate: 2021-08-13 01:18:31 +0000 ipmi(4): Add more watchdog error checks. Add request submission status checks before checking req->ir_compcode, otherwise it may be zero just because of initialization. Add checks for req->ir_compcode errors in ipmi_reset_watchdog() and ipmi_set_watchdog(). In first case explicitly check for 0x80, which means timer was not previously set, that I found happening after BMC cold reset. This change makes watchdog timer to recover instead of permanently ignoring reset errors after BMC reset or upgraded. MFC after: 2 weeks Sponsored by: iXsystems, Inc. (cherry picked from commit 9d3b47abbba74830661e90206cc0f692b159c432) --- sys/dev/ipmi/ipmi.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/sys/dev/ipmi/ipmi.c b/sys/dev/ipmi/ipmi.c index 25077500d835..cd2a289b25cb 100644 --- a/sys/dev/ipmi/ipmi.c +++ b/sys/dev/ipmi/ipmi.c @@ -638,8 +638,15 @@ ipmi_reset_watchdog(struct ipmi_softc *sc) IPMI_ALLOC_DRIVER_REQUEST(req, IPMI_ADDR(IPMI_APP_REQUEST, 0), IPMI_RESET_WDOG, 0, 0); error = ipmi_submit_driver_request(sc, req, 0); - if (error) + if (error) { device_printf(sc->ipmi_dev, "Failed to reset watchdog\n"); + } else if (req->ir_compcode == 0x80) { + error = ENOENT; + } else if (req->ir_compcode != 0) { + device_printf(sc->ipmi_dev, "Watchdog reset returned 0x%x\n", + req->ir_compcode); + error = EINVAL; + } return (error); } @@ -671,8 +678,13 @@ ipmi_set_watchdog(struct ipmi_softc *sc, unsigned int sec) req->ir_request[5] = 0; } error = ipmi_submit_driver_request(sc, req, 0); - if (error) + if (error) { device_printf(sc->ipmi_dev, "Failed to set watchdog\n"); + } else if (req->ir_compcode != 0) { + device_printf(sc->ipmi_dev, "Watchdog set returned 0x%x\n", + req->ir_compcode); + error = EINVAL; + } return (error); } @@ -886,9 +898,9 @@ ipmi_startup(void *arg) IPMI_GET_CHANNEL_INFO, 1, 0); req->ir_request[0] = i; - ipmi_submit_driver_request(sc, req, 0); + error = ipmi_submit_driver_request(sc, req, 0); - if (req->ir_compcode != 0) + if (error != 0 || req->ir_compcode != 0) break; } device_printf(dev, "Number of channels %d\n", i); @@ -901,9 +913,9 @@ ipmi_startup(void *arg) IPMI_INIT_DRIVER_REQUEST(req, IPMI_ADDR(IPMI_APP_REQUEST, 0), IPMI_GET_WDOG, 0, 0); - ipmi_submit_driver_request(sc, req, 0); + error = ipmi_submit_driver_request(sc, req, 0); - if (req->ir_compcode == 0x00) { + if (error == 0 && req->ir_compcode == 0x00) { device_printf(dev, "Attached watchdog\n"); /* register the watchdog event handler */ sc->ipmi_watchdog_tag = EVENTHANDLER_REGISTER( From owner-dev-commits-src-branches@freebsd.org Fri Aug 13 01:19:22 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 12AF1675942; Fri, 13 Aug 2021 01:19:22 +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 4Gm5Ld6ng3z4Yyg; Fri, 13 Aug 2021 01:19:21 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 D1D2E2CE63; Fri, 13 Aug 2021 01:19:21 +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 17D1JLfB071401; Fri, 13 Aug 2021 01:19:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17D1JLSl071400; Fri, 13 Aug 2021 01:19:21 GMT (envelope-from git) Date: Fri, 13 Aug 2021 01:19:21 GMT Message-Id: <202108130119.17D1JLSl071400@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 8e6bcb7f56f1 - stable/12 - ipmi(4): Add more watchdog error checks. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 8e6bcb7f56f12ca2d237b4684223ebb5c5d9092c Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 01:19:22 -0000 The branch stable/12 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=8e6bcb7f56f12ca2d237b4684223ebb5c5d9092c commit 8e6bcb7f56f12ca2d237b4684223ebb5c5d9092c Author: Alexander Motin AuthorDate: 2021-07-30 03:39:04 +0000 Commit: Alexander Motin CommitDate: 2021-08-13 01:19:13 +0000 ipmi(4): Add more watchdog error checks. Add request submission status checks before checking req->ir_compcode, otherwise it may be zero just because of initialization. Add checks for req->ir_compcode errors in ipmi_reset_watchdog() and ipmi_set_watchdog(). In first case explicitly check for 0x80, which means timer was not previously set, that I found happening after BMC cold reset. This change makes watchdog timer to recover instead of permanently ignoring reset errors after BMC reset or upgraded. MFC after: 2 weeks Sponsored by: iXsystems, Inc. (cherry picked from commit 9d3b47abbba74830661e90206cc0f692b159c432) --- sys/dev/ipmi/ipmi.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/sys/dev/ipmi/ipmi.c b/sys/dev/ipmi/ipmi.c index edbe1741e0f7..d48a7d10c289 100644 --- a/sys/dev/ipmi/ipmi.c +++ b/sys/dev/ipmi/ipmi.c @@ -635,8 +635,15 @@ ipmi_reset_watchdog(struct ipmi_softc *sc) IPMI_ALLOC_DRIVER_REQUEST(req, IPMI_ADDR(IPMI_APP_REQUEST, 0), IPMI_RESET_WDOG, 0, 0); error = ipmi_submit_driver_request(sc, req, 0); - if (error) + if (error) { device_printf(sc->ipmi_dev, "Failed to reset watchdog\n"); + } else if (req->ir_compcode == 0x80) { + error = ENOENT; + } else if (req->ir_compcode != 0) { + device_printf(sc->ipmi_dev, "Watchdog reset returned 0x%x\n", + req->ir_compcode); + error = EINVAL; + } return (error); } @@ -668,8 +675,13 @@ ipmi_set_watchdog(struct ipmi_softc *sc, unsigned int sec) req->ir_request[5] = 0; } error = ipmi_submit_driver_request(sc, req, 0); - if (error) + if (error) { device_printf(sc->ipmi_dev, "Failed to set watchdog\n"); + } else if (req->ir_compcode != 0) { + device_printf(sc->ipmi_dev, "Watchdog set returned 0x%x\n", + req->ir_compcode); + error = EINVAL; + } return (error); } @@ -883,9 +895,9 @@ ipmi_startup(void *arg) IPMI_GET_CHANNEL_INFO, 1, 0); req->ir_request[0] = i; - ipmi_submit_driver_request(sc, req, 0); + error = ipmi_submit_driver_request(sc, req, 0); - if (req->ir_compcode != 0) + if (error != 0 || req->ir_compcode != 0) break; } device_printf(dev, "Number of channels %d\n", i); @@ -898,9 +910,9 @@ ipmi_startup(void *arg) IPMI_INIT_DRIVER_REQUEST(req, IPMI_ADDR(IPMI_APP_REQUEST, 0), IPMI_GET_WDOG, 0, 0); - ipmi_submit_driver_request(sc, req, 0); + error = ipmi_submit_driver_request(sc, req, 0); - if (req->ir_compcode == 0x00) { + if (error == 0 && req->ir_compcode == 0x00) { device_printf(dev, "Attached watchdog\n"); /* register the watchdog event handler */ sc->ipmi_watchdog_tag = EVENTHANDLER_REGISTER( From owner-dev-commits-src-branches@freebsd.org Fri Aug 13 01:48:32 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2C27F675B3D; Fri, 13 Aug 2021 01:48:32 +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 4Gm60J0Rgkz4bJ7; Fri, 13 Aug 2021 01:48:32 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 E84AC2D6C1; Fri, 13 Aug 2021 01:48:31 +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 17D1mV6M012249; Fri, 13 Aug 2021 01:48:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17D1mV4Z012248; Fri, 13 Aug 2021 01:48:31 GMT (envelope-from git) Date: Fri, 13 Aug 2021 01:48:31 GMT Message-Id: <202108130148.17D1mV4Z012248@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 7eb023696a7d - stable/13 - coretemp(4): Switch to smp_rendezvous_cpus(). MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 7eb023696a7db1d66a811756b81e0cc7d617cc23 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 01:48:32 -0000 The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=7eb023696a7db1d66a811756b81e0cc7d617cc23 commit 7eb023696a7db1d66a811756b81e0cc7d617cc23 Author: Alexander Motin AuthorDate: 2021-07-30 03:16:22 +0000 Commit: Alexander Motin CommitDate: 2021-08-13 01:48:17 +0000 coretemp(4): Switch to smp_rendezvous_cpus(). Use of smp_rendezvous_cpus() instead of sched_bind() allows to not block indefinitely if target CPU is running some thread with higher priority, while all we need is single rdmsr/wrmsr instruction call. I guess it should also be much cheaper than full thread migration. MFC after: 2 weeks Sponsored by: iXsystems, Inc. (cherry picked from commit 74f80bc1af2ffd56ec290f610c80e46f768731a0) --- sys/dev/coretemp/coretemp.c | 59 ++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/sys/dev/coretemp/coretemp.c b/sys/dev/coretemp/coretemp.c index 884ed6309f0e..53a2434254f6 100644 --- a/sys/dev/coretemp/coretemp.c +++ b/sys/dev/coretemp/coretemp.c @@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$"); #include #include #include /* for curthread */ -#include +#include #include #include @@ -310,14 +310,32 @@ coretemp_detach(device_t dev) return (0); } +struct coretemp_args { + u_int msr; + uint64_t val; +}; + +static void +coretemp_rdmsr(void *arg) +{ + struct coretemp_args *args = arg; + + args->val = rdmsr(args->msr); +} + +static void +coretemp_wrmsr(void *arg) +{ + struct coretemp_args *args = arg; + + wrmsr(args->msr, args->val); +} + static uint64_t coretemp_get_thermal_msr(int cpu) { - uint64_t msr; - - thread_lock(curthread); - sched_bind(curthread, cpu); - thread_unlock(curthread); + struct coretemp_args args; + cpuset_t cpus; /* * The digital temperature reading is located at bit 16 @@ -329,27 +347,24 @@ coretemp_get_thermal_msr(int cpu) * The temperature is computed by subtracting the temperature * reading by Tj(max). */ - msr = rdmsr(MSR_THERM_STATUS); - - thread_lock(curthread); - sched_unbind(curthread); - thread_unlock(curthread); - - return (msr); + args.msr = MSR_THERM_STATUS; + CPU_SETOF(cpu, &cpus); + smp_rendezvous_cpus(cpus, smp_no_rendezvous_barrier, coretemp_rdmsr, + smp_no_rendezvous_barrier, &args); + return (args.val); } static void coretemp_clear_thermal_msr(int cpu) { - thread_lock(curthread); - sched_bind(curthread, cpu); - thread_unlock(curthread); - - wrmsr(MSR_THERM_STATUS, 0); - - thread_lock(curthread); - sched_unbind(curthread); - thread_unlock(curthread); + struct coretemp_args args; + cpuset_t cpus; + + args.msr = MSR_THERM_STATUS; + args.val = 0; + CPU_SETOF(cpu, &cpus); + smp_rendezvous_cpus(cpus, smp_no_rendezvous_barrier, coretemp_wrmsr, + smp_no_rendezvous_barrier, &args); } static int From owner-dev-commits-src-branches@freebsd.org Fri Aug 13 01:56:03 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 78683675EC1; Fri, 13 Aug 2021 01:56:03 +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 4Gm68z2psMz4bb4; Fri, 13 Aug 2021 01:56:03 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 3A8002D9D3; Fri, 13 Aug 2021 01:56:03 +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 17D1u333025218; Fri, 13 Aug 2021 01:56:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17D1u3tj025217; Fri, 13 Aug 2021 01:56:03 GMT (envelope-from git) Date: Fri, 13 Aug 2021 01:56:03 GMT Message-Id: <202108130156.17D1u3tj025217@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 6004eaaf0fc4 - stable/12 - coretemp(4): Switch to smp_rendezvous_cpus(). MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 6004eaaf0fc4f0e7af1cfec335f78e372937d4c4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 01:56:03 -0000 The branch stable/12 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=6004eaaf0fc4f0e7af1cfec335f78e372937d4c4 commit 6004eaaf0fc4f0e7af1cfec335f78e372937d4c4 Author: Alexander Motin AuthorDate: 2021-07-30 03:16:22 +0000 Commit: Alexander Motin CommitDate: 2021-08-13 01:55:55 +0000 coretemp(4): Switch to smp_rendezvous_cpus(). Use of smp_rendezvous_cpus() instead of sched_bind() allows to not block indefinitely if target CPU is running some thread with higher priority, while all we need is single rdmsr/wrmsr instruction call. I guess it should also be much cheaper than full thread migration. MFC after: 2 weeks Sponsored by: iXsystems, Inc. (cherry picked from commit 74f80bc1af2ffd56ec290f610c80e46f768731a0) --- sys/dev/coretemp/coretemp.c | 59 ++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/sys/dev/coretemp/coretemp.c b/sys/dev/coretemp/coretemp.c index 8b9fc3b82350..b4f3fb7700f5 100644 --- a/sys/dev/coretemp/coretemp.c +++ b/sys/dev/coretemp/coretemp.c @@ -43,7 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include #include /* for curthread */ -#include +#include #include #include @@ -308,14 +308,32 @@ coretemp_detach(device_t dev) return (0); } +struct coretemp_args { + u_int msr; + uint64_t val; +}; + +static void +coretemp_rdmsr(void *arg) +{ + struct coretemp_args *args = arg; + + args->val = rdmsr(args->msr); +} + +static void +coretemp_wrmsr(void *arg) +{ + struct coretemp_args *args = arg; + + wrmsr(args->msr, args->val); +} + static uint64_t coretemp_get_thermal_msr(int cpu) { - uint64_t msr; - - thread_lock(curthread); - sched_bind(curthread, cpu); - thread_unlock(curthread); + struct coretemp_args args; + cpuset_t cpus; /* * The digital temperature reading is located at bit 16 @@ -327,27 +345,24 @@ coretemp_get_thermal_msr(int cpu) * The temperature is computed by subtracting the temperature * reading by Tj(max). */ - msr = rdmsr(MSR_THERM_STATUS); - - thread_lock(curthread); - sched_unbind(curthread); - thread_unlock(curthread); - - return (msr); + args.msr = MSR_THERM_STATUS; + CPU_SETOF(cpu, &cpus); + smp_rendezvous_cpus(cpus, smp_no_rendezvous_barrier, coretemp_rdmsr, + smp_no_rendezvous_barrier, &args); + return (args.val); } static void coretemp_clear_thermal_msr(int cpu) { - thread_lock(curthread); - sched_bind(curthread, cpu); - thread_unlock(curthread); - - wrmsr(MSR_THERM_STATUS, 0); - - thread_lock(curthread); - sched_unbind(curthread); - thread_unlock(curthread); + struct coretemp_args args; + cpuset_t cpus; + + args.msr = MSR_THERM_STATUS; + args.val = 0; + CPU_SETOF(cpu, &cpus); + smp_rendezvous_cpus(cpus, smp_no_rendezvous_barrier, coretemp_wrmsr, + smp_no_rendezvous_barrier, &args); } static int From owner-dev-commits-src-branches@freebsd.org Fri Aug 13 07:32:25 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 37E6965185D; Fri, 13 Aug 2021 07:32:25 +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 4GmFd50y0lz3C4R; Fri, 13 Aug 2021 07:32:25 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 097A92311; Fri, 13 Aug 2021 07:32:25 +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 17D7WOSI079105; Fri, 13 Aug 2021 07:32:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17D7WObD079104; Fri, 13 Aug 2021 07:32:24 GMT (envelope-from git) Date: Fri, 13 Aug 2021 07:32:24 GMT Message-Id: <202108130732.17D7WObD079104@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Andrey V. Elsukov" Subject: git: 40ec2323e689 - stable/13 - Fix panic in IPv6 multicast code. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ae X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 40ec2323e689e2b9bcede8e2f217b689e64f621f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 07:32:25 -0000 The branch stable/13 has been updated by ae: URL: https://cgit.FreeBSD.org/src/commit/?id=40ec2323e689e2b9bcede8e2f217b689e64f621f commit 40ec2323e689e2b9bcede8e2f217b689e64f621f Author: Andrey V. Elsukov AuthorDate: 2021-08-05 08:51:46 +0000 Commit: Andrey V. Elsukov CommitDate: 2021-08-13 07:31:11 +0000 Fix panic in IPv6 multicast code. Add check that ifp supports IPv6 multicasts in in6_getmulti. This fixes panic when user application tries to join into multicast group on an interface that doesn't support IPv6 multicasts, like IFT_PFLOG interfaces. PR: 257302 Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D31420 (cherry picked from commit d477a7feed177d0ad5c12bc6e2cce804d427ed38) --- sys/netinet6/in6_mcast.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sys/netinet6/in6_mcast.c b/sys/netinet6/in6_mcast.c index 0744a1178fc7..7326befc6d01 100644 --- a/sys/netinet6/in6_mcast.c +++ b/sys/netinet6/in6_mcast.c @@ -374,9 +374,18 @@ in6_getmulti(struct ifnet *ifp, const struct in6_addr *group, IN6_MULTI_LIST_LOCK(); IF_ADDR_WLOCK(ifp); NET_EPOCH_ENTER(et); - inm = in6m_lookup_locked(ifp, group); + /* + * Does ifp support IPv6 multicasts? + */ + if (ifp->if_afdata[AF_INET6] == NULL) + error = ENODEV; + else + inm = in6m_lookup_locked(ifp, group); NET_EPOCH_EXIT(et); + if (error != 0) + goto out_locked; + if (inm != NULL) { /* * If we already joined this group, just bump the From owner-dev-commits-src-branches@freebsd.org Fri Aug 13 07:39:01 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3DAA76521F7; Fri, 13 Aug 2021 07:39:01 +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 4GmFmj0lL0z3Cgj; Fri, 13 Aug 2021 07:39:01 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 024FE22A5; Fri, 13 Aug 2021 07:39:01 +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 17D7d0F1079827; Fri, 13 Aug 2021 07:39:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17D7d0BH079826; Fri, 13 Aug 2021 07:39:00 GMT (envelope-from git) Date: Fri, 13 Aug 2021 07:39:00 GMT Message-Id: <202108130739.17D7d0BH079826@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Andrey V. Elsukov" Subject: git: 6144be57c0ab - stable/12 - Fix panic in IPv6 multicast code. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ae X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 6144be57c0ab08ddeb1a729f698f0997fe142b96 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 07:39:01 -0000 The branch stable/12 has been updated by ae: URL: https://cgit.FreeBSD.org/src/commit/?id=6144be57c0ab08ddeb1a729f698f0997fe142b96 commit 6144be57c0ab08ddeb1a729f698f0997fe142b96 Author: Andrey V. Elsukov AuthorDate: 2021-08-05 08:51:46 +0000 Commit: Andrey V. Elsukov CommitDate: 2021-08-13 07:37:39 +0000 Fix panic in IPv6 multicast code. Add check that ifp supports IPv6 multicasts in in6_getmulti. This fixes panic when user application tries to join into multicast group on an interface that doesn't support IPv6 multicasts, like IFT_PFLOG interfaces. PR: 257302 Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D31420 (cherry picked from commit d477a7feed177d0ad5c12bc6e2cce804d427ed38) --- sys/netinet6/in6_mcast.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sys/netinet6/in6_mcast.c b/sys/netinet6/in6_mcast.c index bd202e76c6b6..46ed091a193e 100644 --- a/sys/netinet6/in6_mcast.c +++ b/sys/netinet6/in6_mcast.c @@ -372,9 +372,18 @@ in6_getmulti(struct ifnet *ifp, const struct in6_addr *group, IN6_MULTI_LIST_LOCK(); IF_ADDR_WLOCK(ifp); NET_EPOCH_ENTER_ET(et); - inm = in6m_lookup_locked(ifp, group); + /* + * Does ifp support IPv6 multicasts? + */ + if (ifp->if_afdata[AF_INET6] == NULL) + error = ENODEV; + else + inm = in6m_lookup_locked(ifp, group); NET_EPOCH_EXIT_ET(et); + if (error != 0) + goto out_locked; + if (inm != NULL) { /* * If we already joined this group, just bump the From owner-dev-commits-src-branches@freebsd.org Fri Aug 13 09:35:10 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A791A653959; Fri, 13 Aug 2021 09:35:10 +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 4GmJLk4JQ0z3LcB; Fri, 13 Aug 2021 09:35:10 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 77DB63CA7; Fri, 13 Aug 2021 09:35:10 +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 17D9ZAEu039065; Fri, 13 Aug 2021 09:35:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17D9ZAt3039064; Fri, 13 Aug 2021 09:35:10 GMT (envelope-from git) Date: Fri, 13 Aug 2021 09:35:10 GMT Message-Id: <202108130935.17D9ZAt3039064@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 95b63f103bfd - stable/13 - netipsec/keydb.h: fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 95b63f103bfd29505678f095c263278e45f09592 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 09:35:10 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=95b63f103bfd29505678f095c263278e45f09592 commit 95b63f103bfd29505678f095c263278e45f09592 Author: Konstantin Belousov AuthorDate: 2021-07-31 01:41:13 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-13 09:34:42 +0000 netipsec/keydb.h: fix typo (cherry picked from commit fd4751b3892973f3d329f6fb516da6b01be6f71f) --- sys/netipsec/keydb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/netipsec/keydb.h b/sys/netipsec/keydb.h index e3c1417a2f9a..69c1cb29db34 100644 --- a/sys/netipsec/keydb.h +++ b/sys/netipsec/keydb.h @@ -55,7 +55,7 @@ union sockaddr_union { }; #endif /* _SOCKADDR_UNION_DEFINED */ -/* Security Assocciation Index */ +/* Security Association Index */ /* NOTE: Ensure to be same address family */ struct secasindex { union sockaddr_union src; /* source address for SA */ From owner-dev-commits-src-branches@freebsd.org Fri Aug 13 09:35:11 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BE764653A32; Fri, 13 Aug 2021 09:35:11 +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 4GmJLl4gRjz3M2W; Fri, 13 Aug 2021 09:35:11 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 843103CA8; Fri, 13 Aug 2021 09:35:11 +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 17D9ZBkx039089; Fri, 13 Aug 2021 09:35:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17D9ZBkI039088; Fri, 13 Aug 2021 09:35:11 GMT (envelope-from git) Date: Fri, 13 Aug 2021 09:35:11 GMT Message-Id: <202108130935.17D9ZBkI039088@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 3a8f4c41fb17 - stable/13 - netipsec/key.c: Use ANSI C definition for key_random() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3a8f4c41fb1751e83af7ef45d1f2f1e3969669ac Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 09:35:11 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=3a8f4c41fb1751e83af7ef45d1f2f1e3969669ac commit 3a8f4c41fb1751e83af7ef45d1f2f1e3969669ac Author: Konstantin Belousov AuthorDate: 2021-08-03 01:24:31 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-13 09:34:42 +0000 netipsec/key.c: Use ANSI C definition for key_random() (cherry picked from commit 8b000bf5bcddea30e66e0b4e1158e2d7b328b262) --- sys/netipsec/key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c index 86dc9ea41024..71eaac7f8fa3 100644 --- a/sys/netipsec/key.c +++ b/sys/netipsec/key.c @@ -4739,7 +4739,7 @@ key_timehandler(void *arg) } u_long -key_random() +key_random(void) { u_long value; From owner-dev-commits-src-branches@freebsd.org Fri Aug 13 09:35:13 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0281265400B; Fri, 13 Aug 2021 09:35:13 +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 4GmJLm6Ckcz3M0C; Fri, 13 Aug 2021 09:35:12 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 AAF9437DE; Fri, 13 Aug 2021 09:35:12 +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 17D9ZC2f039113; Fri, 13 Aug 2021 09:35:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17D9ZCO5039112; Fri, 13 Aug 2021 09:35:12 GMT (envelope-from git) Date: Fri, 13 Aug 2021 09:35:12 GMT Message-Id: <202108130935.17D9ZCO5039112@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 0896bbff7ff3 - stable/13 - ip(4): Mention IP_IPSEC_POLICY ip-level socket option MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 0896bbff7ff3799688574a0393791277d770cc6c Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 09:35:13 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=0896bbff7ff3799688574a0393791277d770cc6c commit 0896bbff7ff3799688574a0393791277d770cc6c Author: Konstantin Belousov AuthorDate: 2021-08-09 11:07:18 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-13 09:34:42 +0000 ip(4): Mention IP_IPSEC_POLICY ip-level socket option (cherry picked from commit 4a5a67fe679d6b29957bf87dbf2e7c08ff97bb30) --- share/man/man4/ip.4 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/share/man/man4/ip.4 b/share/man/man4/ip.4 index c53cd3d5aeda..24b06846e66f 100644 --- a/share/man/man4/ip.4 +++ b/share/man/man4/ip.4 @@ -28,7 +28,7 @@ .\" @(#)ip.4 8.2 (Berkeley) 11/30/93 .\" $FreeBSD$ .\" -.Dd May 24, 2020 +.Dd August 9, 2021 .Dt IP 4 .Os .Sh NAME @@ -109,6 +109,15 @@ int ttl = 60; /* max = 255 */ setsockopt(s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)); .Ed .Pp +.Dv IP_IPSEC_POLICY +controls IPSec policy for sockets. +For example, +.Bd -literal +const char *policy = "in ipsec ah/transport//require"; +char *buf = ipsec_set_policy(policy, strlen(policy)); +setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY, buf, ipsec_get_policylen(buf)); +.Ed +.Pp .Dv IP_MINTTL may be used to set the minimum acceptable TTL a packet must have when received on a socket. From owner-dev-commits-src-branches@freebsd.org Fri Aug 13 09:35:14 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 065A1653A37; Fri, 13 Aug 2021 09:35:14 +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 4GmJLn6ZlHz3LnJ; Fri, 13 Aug 2021 09:35:13 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 CAA0E3C32; Fri, 13 Aug 2021 09:35:13 +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 17D9ZDgO039139; Fri, 13 Aug 2021 09:35:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17D9ZD20039138; Fri, 13 Aug 2021 09:35:13 GMT (envelope-from git) Date: Fri, 13 Aug 2021 09:35:13 GMT Message-Id: <202108130935.17D9ZD20039138@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: c24e3f5d44b7 - stable/13 - ipsec_set_policy(3): fix sentence MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c24e3f5d44b7a88690913655de20cb4e26b01af6 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 09:35:14 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=c24e3f5d44b7a88690913655de20cb4e26b01af6 commit c24e3f5d44b7a88690913655de20cb4e26b01af6 Author: Konstantin Belousov AuthorDate: 2021-08-09 10:37:41 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-13 09:34:42 +0000 ipsec_set_policy(3): fix sentence (cherry picked from commit ba3896e16913fd6f9f227d84038171f1fdf5496b) --- lib/libipsec/ipsec_set_policy.3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libipsec/ipsec_set_policy.3 b/lib/libipsec/ipsec_set_policy.3 index 1e24b63e6c04..25ef8cbe32cf 100644 --- a/lib/libipsec/ipsec_set_policy.3 +++ b/lib/libipsec/ipsec_set_policy.3 @@ -71,7 +71,7 @@ library function. .Pp The .Fn ipsec_get_policylen -function will returns the of the buffer which is needed when passing +function returns the length of the buffer which is needed when passing the specification structure to the .Xr setsockopt 2 system call. From owner-dev-commits-src-branches@freebsd.org Fri Aug 13 20:36:10 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 81D6465EDED; Fri, 13 Aug 2021 20:36:10 +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 4Gmb1Q37kjz4k7r; Fri, 13 Aug 2021 20:36:10 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 5474A1493A; Fri, 13 Aug 2021 20:36:10 +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 17DKaA07021213; Fri, 13 Aug 2021 20:36:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17DKaAsr021212; Fri, 13 Aug 2021 20:36:10 GMT (envelope-from git) Date: Fri, 13 Aug 2021 20:36:10 GMT Message-Id: <202108132036.17DKaAsr021212@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kirk McKusick Subject: git: 654e91791ba3 - stable/13 - Clean up orphaned indirdep dependency structures after disk failure. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 654e91791ba3230bf26954d3ac1af6848702e4e6 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 20:36:10 -0000 The branch stable/13 has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=654e91791ba3230bf26954d3ac1af6848702e4e6 commit 654e91791ba3230bf26954d3ac1af6848702e4e6 Author: Kirk McKusick AuthorDate: 2021-07-29 23:11:58 +0000 Commit: Kirk McKusick CommitDate: 2021-08-13 17:37:26 +0000 Clean up orphaned indirdep dependency structures after disk failure. (cherry picked from commit 412b5e40a721430adba1b4abae210641f733f976) (cherry picked from commit a91716efeb684c50289c0e1136f5432f880dc873) --- sys/ufs/ffs/ffs_softdep.c | 54 +++++++++++++++++++++++++++++++++++++++++------ sys/ufs/ffs/softdep.h | 4 +--- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index 446fc69a6a32..c53ba7c70d2f 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -1233,9 +1233,7 @@ workitem_free(item, type) ump->um_fs->fs_fsmnt, TYPENAME(item->wk_type))); atomic_subtract_long(&dep_current[item->wk_type], 1); ump->softdep_curdeps[item->wk_type] -= 1; -#ifdef INVARIANTS LIST_REMOVE(item, wk_all); -#endif free(item, DtoM(type)); } @@ -1262,9 +1260,7 @@ workitem_alloc(item, type, mp) ump->softdep_curdeps[type] += 1; ump->softdep_deps++; ump->softdep_accdeps++; -#ifdef INVARIANTS LIST_INSERT_HEAD(&ump->softdep_alldeps[type], item, wk_all); -#endif FREE_LOCK(ump); } @@ -1293,6 +1289,8 @@ workitem_reassign(item, newtype) dep_total[newtype]++; FREE_GBLLOCK(&lk); item->wk_type = newtype; + LIST_REMOVE(item, wk_all); + LIST_INSERT_HEAD(&ump->softdep_alldeps[newtype], item, wk_all); } /* @@ -2710,10 +2708,8 @@ softdep_mount(devvp, mp, fs, cred) ump->indir_hash_size = i - 1; for (i = 0; i <= ump->indir_hash_size; i++) TAILQ_INIT(&ump->indir_hashtbl[i]); -#ifdef INVARIANTS for (i = 0; i <= D_LAST; i++) LIST_INIT(&ump->softdep_alldeps[i]); -#endif ACQUIRE_GBLLOCK(&lk); TAILQ_INSERT_TAIL(&softdepmounts, sdp, sd_next); FREE_GBLLOCK(&lk); @@ -14765,9 +14761,12 @@ softdep_check_suspend(struct mount *mp, int secondary_writes, int secondary_accwrites) { + struct buf *bp; struct bufobj *bo; struct ufsmount *ump; struct inodedep *inodedep; + struct indirdep *indirdep; + struct worklist *wk, *nextwk; int error, unlinked; bo = &devvp->v_bufobj; @@ -14843,9 +14842,52 @@ softdep_check_suspend(struct mount *mp, } } + /* + * XXX Check for orphaned indirdep dependency structures. + * + * During forcible unmount after a disk failure there is a + * bug that causes one or more indirdep dependency structures + * to fail to be deallocated. We check for them here and clean + * them up so that the unmount can succeed. + */ + if ((ump->um_flags & UM_FSFAIL_CLEANUP) != 0 && ump->softdep_deps > 0 && + ump->softdep_deps == ump->softdep_curdeps[D_INDIRDEP]) { + LIST_FOREACH_SAFE(wk, &ump->softdep_alldeps[D_INDIRDEP], + wk_all, nextwk) { + indirdep = WK_INDIRDEP(wk); + if ((indirdep->ir_state & (GOINGAWAY | DEPCOMPLETE)) != + (GOINGAWAY | DEPCOMPLETE) || + !TAILQ_EMPTY(&indirdep->ir_trunc) || + !LIST_EMPTY(&indirdep->ir_completehd) || + !LIST_EMPTY(&indirdep->ir_writehd) || + !LIST_EMPTY(&indirdep->ir_donehd) || + !LIST_EMPTY(&indirdep->ir_deplisthd) || + indirdep->ir_saveddata != NULL || + indirdep->ir_savebp == NULL) { + printf("%s: skipping orphaned indirdep %p\n", + __FUNCTION__, indirdep); + continue; + } + printf("%s: freeing orphaned indirdep %p\n", + __FUNCTION__, indirdep); + bp = indirdep->ir_savebp; + indirdep->ir_savebp = NULL; + free_indirdep(indirdep); + FREE_LOCK(ump); + brelse(bp); + while (!TRY_ACQUIRE_LOCK(ump)) { + BO_UNLOCK(bo); + ACQUIRE_LOCK(ump); + FREE_LOCK(ump); + BO_LOCK(bo); + } + } + } + /* * Reasons for needing more work before suspend: * - Dirty buffers on devvp. + * - Dependency structures still exist * - Softdep activity occurred after start of vnode sync loop * - Secondary writes occurred after start of vnode sync loop */ diff --git a/sys/ufs/ffs/softdep.h b/sys/ufs/ffs/softdep.h index 3493aadafc98..41728be3ec0f 100644 --- a/sys/ufs/ffs/softdep.h +++ b/sys/ufs/ffs/softdep.h @@ -213,10 +213,10 @@ struct worklist { struct mount *wk_mp; /* Mount we live in */ unsigned int wk_type:8, /* type of request */ wk_state:24; /* state flags */ + LIST_ENTRY(worklist) wk_all; /* list of deps of this type */ #ifdef INVARIANTS const char *wk_func; /* func where added / removed */ int wk_line; /* line where added / removed */ - LIST_ENTRY(worklist) wk_all; /* list of deps of this type */ #endif }; #define WK_DATA(wk) ((void *)(wk)) @@ -1075,9 +1075,7 @@ struct mount_softdeps { TAILQ_ENTRY(mount_softdeps) sd_next; /* List of softdep filesystem */ struct ufsmount *sd_ump; /* our ufsmount structure */ u_long sd_curdeps[D_LAST + 1]; /* count of current deps */ -#ifdef INVARIANTS struct workhead sd_alldeps[D_LAST + 1];/* Lists of all deps */ -#endif }; /* * Flags for communicating with the syncer thread. From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 01:13:20 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 87B90663591; Sat, 14 Aug 2021 01:13:20 +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 4Gmj9D3JCZz3Ksn; Sat, 14 Aug 2021 01:13:20 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 3B4C518914; Sat, 14 Aug 2021 01:13:20 +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 17E1DKLj094834; Sat, 14 Aug 2021 01:13:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17E1DKgO094833; Sat, 14 Aug 2021 01:13:20 GMT (envelope-from git) Date: Sat, 14 Aug 2021 01:13:20 GMT Message-Id: <202108140113.17E1DKgO094833@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 9c15ec46bfb6 - stable/13 - ncurses: Apply a tputs() fix from patch 20210403 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9c15ec46bfb6558c42a668afeef1a4418dcd970d Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 01:13:20 -0000 The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=9c15ec46bfb6558c42a668afeef1a4418dcd970d commit 9c15ec46bfb6558c42a668afeef1a4418dcd970d Author: Mark Johnston AuthorDate: 2021-08-11 16:54:29 +0000 Commit: Mark Johnston CommitDate: 2021-08-14 01:13:16 +0000 ncurses: Apply a tputs() fix from patch 20210403 From the (substantially larger) upstream commit: + call delay_output_sp to handle BSD-style padding when tputs_sp is called, whether directly or internally, to ensure that the SCREEN pointer is passed correctly (reports by Henric Jungheim, Juraj Lutter). This fixes bison segfaults observed when colourized output is enabled. Thanks to jrtc27@ for identifying the upstream fix. PR: 256731 MFC after: 3 days (cherry picked from commit b2da1032397e3339fbeebcd57b1f179e1d8a2e19) --- contrib/ncurses/ncurses/tinfo/lib_tputs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/ncurses/ncurses/tinfo/lib_tputs.c b/contrib/ncurses/ncurses/tinfo/lib_tputs.c index bfde26efd980..7da8803905e4 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_tputs.c +++ b/contrib/ncurses/ncurses/tinfo/lib_tputs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 2018-2020,2021 Thomas E. Dickey * * Copyright 1998-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -52,7 +52,7 @@ #include /* ospeed */ #include -MODULE_ID("$Id: lib_tputs.c,v 1.103 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_tputs.c,v 1.107 2021/04/03 18:45:53 tom Exp $") NCURSES_EXPORT_VAR(char) PC = 0; /* used by termcap library */ NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */ @@ -419,7 +419,7 @@ NCURSES_SP_NAME(tputs) (NCURSES_SP_DCLx */ if (trailpad > 0 && (always_delay || normal_delay)) - delay_output(trailpad / 10); + NCURSES_SP_NAME(delay_output) (NCURSES_SP_ARGx trailpad / 10); #endif /* BSD_TPUTS */ SetOutCh(my_outch); From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 06:28:52 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6EE24665B6D; Sat, 14 Aug 2021 06:28: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 4Gmr9J26t0z4qSx; Sat, 14 Aug 2021 06:28:52 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 312231D6F2; Sat, 14 Aug 2021 06:28: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 17E6SqZb007982; Sat, 14 Aug 2021 06:28:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17E6SqZ7007981; Sat, 14 Aug 2021 06:28:52 GMT (envelope-from git) Date: Sat, 14 Aug 2021 06:28:52 GMT Message-Id: <202108140628.17E6SqZ7007981@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Gordon Bergling Subject: git: 375a52cc3cfe - stable/13 - mkimg(1): Correct a typo in the usage output MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: gbe X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 375a52cc3cfee15a66dbe857b8381112b129af98 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 06:28:52 -0000 The branch stable/13 has been updated by gbe (doc committer): URL: https://cgit.FreeBSD.org/src/commit/?id=375a52cc3cfee15a66dbe857b8381112b129af98 commit 375a52cc3cfee15a66dbe857b8381112b129af98 Author: Gordon Bergling AuthorDate: 2021-08-09 11:53:30 +0000 Commit: Gordon Bergling CommitDate: 2021-08-14 06:28:00 +0000 mkimg(1): Correct a typo in the usage output - s/partion/partition/ (cherry picked from commit 6bddade6114abacacb30ef2c28781f1af331c106) --- usr.bin/mkimg/mkimg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.bin/mkimg/mkimg.c b/usr.bin/mkimg/mkimg.c index e5e6c036575b..71af45b5815d 100644 --- a/usr.bin/mkimg/mkimg.c +++ b/usr.bin/mkimg/mkimg.c @@ -151,7 +151,7 @@ usage(const char *why) fprintf(stderr, "\t--schemes\t- list partition schemes\n"); fprintf(stderr, "\t--version\t- show version information\n"); fputc('\n', stderr); - fprintf(stderr, "\t-a \t- mark num'th partion as active\n"); + fprintf(stderr, "\t-a \t- mark num'th partition as active\n"); fprintf(stderr, "\t-b \t- file containing boot code\n"); fprintf(stderr, "\t-c \t- minimum capacity (in bytes) of the disk\n"); fprintf(stderr, "\t-C \t- maximum capacity (in bytes) of the disk\n"); From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 06:29:22 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 14775666AC4; Sat, 14 Aug 2021 06:29:22 +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 4Gmr9t04Lhz4qJC; Sat, 14 Aug 2021 06:29:22 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 DED651CF57; Sat, 14 Aug 2021 06:29:21 +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 17E6TL1Q008127; Sat, 14 Aug 2021 06:29:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17E6TLai008126; Sat, 14 Aug 2021 06:29:21 GMT (envelope-from git) Date: Sat, 14 Aug 2021 06:29:21 GMT Message-Id: <202108140629.17E6TLai008126@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Gordon Bergling Subject: git: 53b0a143509c - stable/12 - mkimg(1): Correct a typo in the usage output MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: gbe X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 53b0a143509cfaa88a3fe621063966158367f498 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 06:29:22 -0000 The branch stable/12 has been updated by gbe (doc committer): URL: https://cgit.FreeBSD.org/src/commit/?id=53b0a143509cfaa88a3fe621063966158367f498 commit 53b0a143509cfaa88a3fe621063966158367f498 Author: Gordon Bergling AuthorDate: 2021-08-09 11:53:30 +0000 Commit: Gordon Bergling CommitDate: 2021-08-14 06:29:07 +0000 mkimg(1): Correct a typo in the usage output - s/partion/partition/ (cherry picked from commit 6bddade6114abacacb30ef2c28781f1af331c106) --- usr.bin/mkimg/mkimg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.bin/mkimg/mkimg.c b/usr.bin/mkimg/mkimg.c index c5a85aa7c33d..8967e538df42 100644 --- a/usr.bin/mkimg/mkimg.c +++ b/usr.bin/mkimg/mkimg.c @@ -151,7 +151,7 @@ usage(const char *why) fprintf(stderr, "\t--schemes\t- list partition schemes\n"); fprintf(stderr, "\t--version\t- show version information\n"); fputc('\n', stderr); - fprintf(stderr, "\t-a \t- mark num'th partion as active\n"); + fprintf(stderr, "\t-a \t- mark num'th partition as active\n"); fprintf(stderr, "\t-b \t- file containing boot code\n"); fprintf(stderr, "\t-c \t- minimum capacity (in bytes) of the disk\n"); fprintf(stderr, "\t-C \t- maximum capacity (in bytes) of the disk\n"); From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:20 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3C7B0669ED9; Sat, 14 Aug 2021 10:22:20 +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 4GmxLh0wKtz3LVw; Sat, 14 Aug 2021 10:22:20 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 08040204F3; Sat, 14 Aug 2021 10:22:20 +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 17EAMJ4h029610; Sat, 14 Aug 2021 10:22:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMJDp029609; Sat, 14 Aug 2021 10:22:19 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:19 GMT Message-Id: <202108141022.17EAMJDp029609@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 88156d89fbc5 - stable/13 - simplify journal_mount: move the out label after success block MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 88156d89fbc5f0fd43aeb58eafbf16aec833c77d Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:20 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=88156d89fbc5f0fd43aeb58eafbf16aec833c77d commit 88156d89fbc5f0fd43aeb58eafbf16aec833c77d Author: Konstantin Belousov AuthorDate: 2021-03-04 18:55:33 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:58 +0000 simplify journal_mount: move the out label after success block (cherry picked from commit 25aac48d2ce322355e7890a1de0f045a15d1cc09) --- sys/ufs/ffs/ffs_softdep.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index c53ba7c70d2f..e03f88029340 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -3013,26 +3013,26 @@ journal_mount(mp, fs, cred) jblocks->jb_low = jblocks->jb_free / 3; /* Reserve 33%. */ jblocks->jb_min = jblocks->jb_free / 10; /* Suspend at 10%. */ ump->softdep_jblocks = jblocks; -out: - if (error == 0) { - MNT_ILOCK(mp); - mp->mnt_flag |= MNT_SUJ; - mp->mnt_flag &= ~MNT_SOFTDEP; - MNT_IUNLOCK(mp); - /* - * Only validate the journal contents if the - * filesystem is clean, otherwise we write the logs - * but they'll never be used. If the filesystem was - * still dirty when we mounted it the journal is - * invalid and a new journal can only be valid if it - * starts from a clean mount. - */ - if (fs->fs_clean) { - DIP_SET(ip, i_modrev, fs->fs_mtime); - ip->i_flags |= IN_MODIFIED; - ffs_update(vp, 1); - } + + MNT_ILOCK(mp); + mp->mnt_flag |= MNT_SUJ; + mp->mnt_flag &= ~MNT_SOFTDEP; + MNT_IUNLOCK(mp); + + /* + * Only validate the journal contents if the + * filesystem is clean, otherwise we write the logs + * but they'll never be used. If the filesystem was + * still dirty when we mounted it the journal is + * invalid and a new journal can only be valid if it + * starts from a clean mount. + */ + if (fs->fs_clean) { + DIP_SET(ip, i_modrev, fs->fs_mtime); + ip->i_flags |= IN_MODIFIED; + ffs_update(vp, 1); } +out: vput(vp); return (error); } From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:21 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 79E1E66A11C; Sat, 14 Aug 2021 10:22: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GmxLj2c1dz3LSw; Sat, 14 Aug 2021 10:22:21 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 3633A20652; Sat, 14 Aug 2021 10:22:21 +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 17EAML8G029634; Sat, 14 Aug 2021 10:22:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMLel029633; Sat, 14 Aug 2021 10:22:21 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:21 GMT Message-Id: <202108141022.17EAMLel029633@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: cac4051570d9 - stable/13 - Add FFSV_FORCEINODEDEP flag for ffs_vgetf() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: cac4051570d9feb18a05084f327b86b53114acac Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:21 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=cac4051570d9feb18a05084f327b86b53114acac commit cac4051570d9feb18a05084f327b86b53114acac Author: Konstantin Belousov AuthorDate: 2021-03-03 17:40:56 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:58 +0000 Add FFSV_FORCEINODEDEP flag for ffs_vgetf() (cherry picked from commit fd97fa64638d810b415af7afcc86634c9709ad12) --- sys/ufs/ffs/ffs_extern.h | 1 + sys/ufs/ffs/ffs_softdep.c | 13 +++++++------ sys/ufs/ffs/ffs_vfsops.c | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/sys/ufs/ffs/ffs_extern.h b/sys/ufs/ffs/ffs_extern.h index 0365cb76601e..c0ceeee09e89 100644 --- a/sys/ufs/ffs/ffs_extern.h +++ b/sys/ufs/ffs/ffs_extern.h @@ -127,6 +127,7 @@ int ffs_breadz(struct ufsmount *, struct vnode *, daddr_t, daddr_t, int, #define FFSV_FORCEINSMQ 0x0001 #define FFSV_REPLACE 0x0002 #define FFSV_REPLACE_DOOMED 0x0004 +#define FFSV_FORCEINODEDEP 0x0008 /* * Flags to ffs_reload diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index e03f88029340..37db84f06fd0 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -1470,7 +1470,7 @@ get_parent_vp(struct vnode *vp, struct mount *mp, ino_t inum, struct buf *bp, ASSERT_VOP_ELOCKED(vp, "child vnode must be locked"); for (bplocked = true, pvp = NULL;;) { error = ffs_vgetf(mp, inum, LK_EXCLUSIVE | LK_NOWAIT, &pvp, - FFSV_FORCEINSMQ); + FFSV_FORCEINSMQ | FFSV_FORCEINODEDEP); if (error == 0) { /* * Since we could have unlocked vp, the inode @@ -1511,7 +1511,7 @@ get_parent_vp(struct vnode *vp, struct mount *mp, ino_t inum, struct buf *bp, VOP_UNLOCK(vp); error = ffs_vgetf(mp, inum, LK_EXCLUSIVE, &pvp, - FFSV_FORCEINSMQ); + FFSV_FORCEINSMQ | FFSV_FORCEINODEDEP); if (error != 0) { MPASS(error != ERELOOKUP); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); @@ -8413,7 +8413,7 @@ handle_complete_freeblocks(freeblks, flags) */ if (spare && freeblks->fb_len != 0) { if (ffs_vgetf(freeblks->fb_list.wk_mp, freeblks->fb_inum, - flags, &vp, FFSV_FORCEINSMQ) != 0) + flags, &vp, FFSV_FORCEINSMQ | FFSV_FORCEINODEDEP) != 0) return (EBUSY); ip = VTOI(vp); if (ip->i_mode == 0) { @@ -10203,7 +10203,8 @@ handle_workitem_remove(dirrem, flags) mp = dirrem->dm_list.wk_mp; ump = VFSTOUFS(mp); flags |= LK_EXCLUSIVE; - if (ffs_vgetf(mp, oldinum, flags, &vp, FFSV_FORCEINSMQ) != 0) + if (ffs_vgetf(mp, oldinum, flags, &vp, FFSV_FORCEINSMQ | + FFSV_FORCEINODEDEP) != 0) return (EBUSY); ip = VTOI(vp); MPASS(ip->i_mode != 0); @@ -14295,7 +14296,7 @@ clear_remove(mp) if (error != 0) goto finish_write; error = ffs_vgetf(mp, ino, LK_EXCLUSIVE, &vp, - FFSV_FORCEINSMQ); + FFSV_FORCEINSMQ | FFSV_FORCEINODEDEP); vfs_unbusy(mp); if (error != 0) { softdep_error("clear_remove: vget", error); @@ -14375,7 +14376,7 @@ clear_inodedeps(mp) return; } if ((error = ffs_vgetf(mp, ino, LK_EXCLUSIVE, &vp, - FFSV_FORCEINSMQ)) != 0) { + FFSV_FORCEINSMQ | FFSV_FORCEINODEDEP)) != 0) { softdep_error("clear_inodedeps: vget", error); vfs_unbusy(mp); vn_finished_write(mp); diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index c8073874a85f..0e8a13b87eec 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -2073,7 +2073,8 @@ ffs_vgetf(mp, ino, flags, vpp, ffs_flags) *vpp = NULL; return (error); } - if (DOINGSOFTDEP(vp)) + if (DOINGSOFTDEP(vp) && (!fs->fs_ronly || + (ffs_flags & FFSV_FORCEINODEDEP) != 0)) softdep_load_inodeblock(ip); else ip->i_effnlink = ip->i_nlink; From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:22 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A2CA5669E41; Sat, 14 Aug 2021 10:22:22 +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 4GmxLk3GTxz3LQy; Sat, 14 Aug 2021 10:22:22 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 57C7E205D9; Sat, 14 Aug 2021 10:22:22 +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 17EAMMGN029658; Sat, 14 Aug 2021 10:22:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMMSe029657; Sat, 14 Aug 2021 10:22:22 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:22 GMT Message-Id: <202108141022.17EAMMSe029657@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 8475c8db9962 - stable/13 - ffs_extern.h: Add comments for ffs_vgetf() flags MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 8475c8db9962fc0facb5b6e14d293010b55fb9b2 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:22 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=8475c8db9962fc0facb5b6e14d293010b55fb9b2 commit 8475c8db9962fc0facb5b6e14d293010b55fb9b2 Author: Konstantin Belousov AuthorDate: 2021-03-11 07:02:16 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:58 +0000 ffs_extern.h: Add comments for ffs_vgetf() flags (cherry picked from commit a285d3edacf602e555a918119d787d94f342fe90) --- sys/ufs/ffs/ffs_extern.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/ufs/ffs/ffs_extern.h b/sys/ufs/ffs/ffs_extern.h index c0ceeee09e89..2ea828861b42 100644 --- a/sys/ufs/ffs/ffs_extern.h +++ b/sys/ufs/ffs/ffs_extern.h @@ -124,10 +124,12 @@ int ffs_breadz(struct ufsmount *, struct vnode *, daddr_t, daddr_t, int, /* * Flags to ffs_vgetf */ -#define FFSV_FORCEINSMQ 0x0001 -#define FFSV_REPLACE 0x0002 -#define FFSV_REPLACE_DOOMED 0x0004 -#define FFSV_FORCEINODEDEP 0x0008 +#define FFSV_FORCEINSMQ 0x0001 /* Force insertion into mount list */ +#define FFSV_REPLACE 0x0002 /* Replace existing vnode */ +#define FFSV_REPLACE_DOOMED 0x0004 /* Replace existing vnode if it is + doomed */ +#define FFSV_FORCEINODEDEP 0x0008 /* Force allocation of inodedep, ignore + MNT_SOFTDEP */ /* * Flags to ffs_reload From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:23 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BF73666A180; Sat, 14 Aug 2021 10:22:23 +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 4GmxLl4m1Nz3LbH; Sat, 14 Aug 2021 10:22:23 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 827C620374; Sat, 14 Aug 2021 10:22:23 +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 17EAMNrx029682; Sat, 14 Aug 2021 10:22:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMNGP029681; Sat, 14 Aug 2021 10:22:23 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:23 GMT Message-Id: <202108141022.17EAMNGP029681@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 12eeb8eed34f - stable/13 - ffs softdep: clear ump->um_softdep on softdep_unmount() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 12eeb8eed34fbd8321ee0c525305c8cb13978f63 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:23 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=12eeb8eed34fbd8321ee0c525305c8cb13978f63 commit 12eeb8eed34fbd8321ee0c525305c8cb13978f63 Author: Konstantin Belousov AuthorDate: 2021-03-03 17:42:24 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:58 +0000 ffs softdep: clear ump->um_softdep on softdep_unmount() (cherry picked from commit 81cdb19e04e57a934e8a5dd76e5c7e0afcba1acb) --- sys/ufs/ffs/ffs_softdep.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index 37db84f06fd0..4f69dc853e4b 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -2773,13 +2773,11 @@ softdep_unmount(mp) struct mount *mp; { struct ufsmount *ump; -#ifdef INVARIANTS - int i; -#endif + struct mount_softdeps *ums; - KASSERT(MOUNTEDSOFTDEP(mp) != 0, - ("softdep_unmount called on non-softdep filesystem")); ump = VFSTOUFS(mp); + KASSERT(ump->um_softdep != NULL, + ("softdep_unmount called on non-softdep filesystem")); MNT_ILOCK(mp); mp->mnt_flag &= ~MNT_SOFTDEP; if (MOUNTEDSUJ(mp) == 0) { @@ -2802,30 +2800,37 @@ softdep_unmount(mp) KASSERT((ump->softdep_flags & FLUSH_EXIT) == 0, ("Thread shutdown failed")); } + /* - * Free up our resources. + * We are no longer have softdep structure attached to ump. */ + ums = ump->um_softdep; ACQUIRE_GBLLOCK(&lk); - TAILQ_REMOVE(&softdepmounts, ump->um_softdep, sd_next); + TAILQ_REMOVE(&softdepmounts, ums, sd_next); FREE_GBLLOCK(&lk); - rw_destroy(LOCK_PTR(ump)); - hashdestroy(ump->pagedep_hashtbl, M_PAGEDEP, ump->pagedep_hash_size); - hashdestroy(ump->inodedep_hashtbl, M_INODEDEP, ump->inodedep_hash_size); - hashdestroy(ump->newblk_hashtbl, M_NEWBLK, ump->newblk_hash_size); - hashdestroy(ump->bmsafemap_hashtbl, M_BMSAFEMAP, - ump->bmsafemap_hash_size); - free(ump->indir_hashtbl, M_FREEWORK); + ump->um_softdep = NULL; + + /* + * Free up our resources. + */ + rw_destroy(&ums->sd_fslock); + hashdestroy(ums->sd_pdhash, M_PAGEDEP, ums->sd_pdhashsize); + hashdestroy(ums->sd_idhash, M_INODEDEP, ums->sd_idhashsize); + hashdestroy(ums->sd_newblkhash, M_NEWBLK, ums->sd_newblkhashsize); + hashdestroy(ums->sd_bmhash, M_BMSAFEMAP, ums->sd_bmhashsize); + free(ums->sd_indirhash, M_FREEWORK); #ifdef INVARIANTS - for (i = 0; i <= D_LAST; i++) { - KASSERT(ump->softdep_curdeps[i] == 0, + for (int i = 0; i <= D_LAST; i++) { + KASSERT(ums->sd_curdeps[i] == 0, ("Unmount %s: Dep type %s != 0 (%ld)", ump->um_fs->fs_fsmnt, - TYPENAME(i), ump->softdep_curdeps[i])); - KASSERT(LIST_EMPTY(&ump->softdep_alldeps[i]), - ("Unmount %s: Dep type %s not empty (%p)", ump->um_fs->fs_fsmnt, - TYPENAME(i), LIST_FIRST(&ump->softdep_alldeps[i]))); + TYPENAME(i), ums->sd_curdeps[i])); + KASSERT(LIST_EMPTY(&ums->sd_alldeps[i]), + ("Unmount %s: Dep type %s not empty (%p)", + ump->um_fs->fs_fsmnt, + TYPENAME(i), LIST_FIRST(&ums->sd_alldeps[i]))); } #endif - free(ump->um_softdep, M_MOUNTDATA); + free(ums, M_MOUNTDATA); } static struct jblocks * From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:25 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1F35B66A11D; Sat, 14 Aug 2021 10:22:25 +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 4GmxLm5cP4z3LTB; Sat, 14 Aug 2021 10:22:24 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 9BA9A20568; Sat, 14 Aug 2021 10:22:24 +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 17EAMOOb029706; Sat, 14 Aug 2021 10:22:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMOuM029705; Sat, 14 Aug 2021 10:22:24 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:24 GMT Message-Id: <202108141022.17EAMOuM029705@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 41a1ede01c1c - stable/13 - Rework MOUNTED/DOING SOFTDEP/SUJ macros MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 41a1ede01c1ca519c7b1ca5c8b209cfd8bd4acec Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:25 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=41a1ede01c1ca519c7b1ca5c8b209cfd8bd4acec commit 41a1ede01c1ca519c7b1ca5c8b209cfd8bd4acec Author: Konstantin Belousov AuthorDate: 2021-03-03 17:43:17 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:58 +0000 Rework MOUNTED/DOING SOFTDEP/SUJ macros (cherry picked from commit 7f682bdcabdaf95ded6a69994344ddbc84fd36db) --- sys/ufs/ffs/ffs_softdep.c | 1 - sys/ufs/ufs/inode.h | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index 4f69dc853e4b..a110f8b58701 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -3021,7 +3021,6 @@ journal_mount(mp, fs, cred) MNT_ILOCK(mp); mp->mnt_flag |= MNT_SUJ; - mp->mnt_flag &= ~MNT_SOFTDEP; MNT_IUNLOCK(mp); /* diff --git a/sys/ufs/ufs/inode.h b/sys/ufs/ufs/inode.h index 4515dcbed401..2ff619b4eac0 100644 --- a/sys/ufs/ufs/inode.h +++ b/sys/ufs/ufs/inode.h @@ -261,11 +261,11 @@ struct indir { #define ITOV(ip) ((ip)->i_vnode) /* Determine if soft dependencies are being done */ -#define DOINGSOFTDEP(vp) \ - (((vp)->v_mount->mnt_flag & (MNT_SOFTDEP | MNT_SUJ)) != 0) -#define MOUNTEDSOFTDEP(mp) (((mp)->mnt_flag & (MNT_SOFTDEP | MNT_SUJ)) != 0) -#define DOINGSUJ(vp) (((vp)->v_mount->mnt_flag & MNT_SUJ) != 0) -#define MOUNTEDSUJ(mp) (((mp)->mnt_flag & MNT_SUJ) != 0) +#define MOUNTEDSOFTDEP(mp) (((mp)->mnt_flag & MNT_SOFTDEP) != 0) +#define DOINGSOFTDEP(vp) MOUNTEDSOFTDEP((vp)->v_mount) +#define MOUNTEDSUJ(mp) (((mp)->mnt_flag & (MNT_SOFTDEP | MNT_SUJ)) == \ + (MNT_SOFTDEP | MNT_SUJ)) +#define DOINGSUJ(vp) MOUNTEDSUJ((vp)->v_mount) /* This overlays the fid structure (see mount.h). */ struct ufid { From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:26 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 54F1D669E47; Sat, 14 Aug 2021 10:22:26 +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 4GmxLn6Ln2z3LWL; Sat, 14 Aug 2021 10:22:25 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 BFFB620654; Sat, 14 Aug 2021 10:22:25 +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 17EAMPKg029737; Sat, 14 Aug 2021 10:22:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMPlZ029736; Sat, 14 Aug 2021 10:22:25 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:25 GMT Message-Id: <202108141022.17EAMPlZ029736@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: a71498a29844 - stable/13 - ffs: clear MNT_SOFTDEP earlier when remounting rw to ro MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a71498a29844e2cf055bdb7b1daad12ffe0c1fc0 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:26 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a71498a29844e2cf055bdb7b1daad12ffe0c1fc0 commit a71498a29844e2cf055bdb7b1daad12ffe0c1fc0 Author: Konstantin Belousov AuthorDate: 2021-02-28 18:55:35 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:58 +0000 ffs: clear MNT_SOFTDEP earlier when remounting rw to ro (cherry picked from commit 7c7a6681fab2c0453085d30424f479c0f766904d) --- sys/ufs/ffs/ffs_softdep.c | 21 ++++++++++++--------- sys/ufs/ffs/ffs_vfsops.c | 28 +++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index a110f8b58701..3fd5476df17d 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -1791,10 +1791,10 @@ softdep_process_worklist(mp, full) long starttime; KASSERT(mp != NULL, ("softdep_process_worklist: NULL mp")); - if (MOUNTEDSOFTDEP(mp) == 0) + ump = VFSTOUFS(mp); + if (ump->um_softdep == NULL) return (0); matchcnt = 0; - ump = VFSTOUFS(mp); ACQUIRE_LOCK(ump); starttime = time_second; softdep_process_journal(mp, NULL, full ? MNT_WAIT : 0); @@ -2133,6 +2133,8 @@ softdep_waitidle(struct mount *mp, int flags __unused) int error, i; ump = VFSTOUFS(mp); + KASSERT(ump->um_softdep != NULL, + ("softdep_waitidle called on non-softdep filesystem")); devvp = ump->um_devvp; td = curthread; error = 0; @@ -2170,14 +2172,15 @@ softdep_flushfiles(oldmnt, flags, td) int flags; struct thread *td; { -#ifdef QUOTA struct ufsmount *ump; +#ifdef QUOTA int i; #endif int error, early, depcount, loopcnt, retry_flush_count, retry; int morework; - KASSERT(MOUNTEDSOFTDEP(oldmnt) != 0, + ump = VFSTOUFS(oldmnt); + KASSERT(ump->um_softdep != NULL, ("softdep_flushfiles called on non-softdep filesystem")); loopcnt = 10; retry_flush_count = 3; @@ -2221,7 +2224,6 @@ retry_flush: MNT_ILOCK(oldmnt); morework = oldmnt->mnt_nvnodelistsize > 0; #ifdef QUOTA - ump = VFSTOUFS(oldmnt); UFS_LOCK(ump); for (i = 0; i < MAXQUOTAS; i++) { if (ump->um_quotas[i] != NULLVP) @@ -2780,7 +2782,7 @@ softdep_unmount(mp) ("softdep_unmount called on non-softdep filesystem")); MNT_ILOCK(mp); mp->mnt_flag &= ~MNT_SOFTDEP; - if (MOUNTEDSUJ(mp) == 0) { + if ((mp->mnt_flag & MNT_SUJ) == 0) { MNT_IUNLOCK(mp); } else { mp->mnt_flag &= ~MNT_SUJ; @@ -3730,12 +3732,12 @@ softdep_process_journal(mp, needwk, flags) int off; int devbsize; - if (MOUNTEDSUJ(mp) == 0) + ump = VFSTOUFS(mp); + if (ump->um_softdep == NULL || ump->um_softdep->sd_jblocks == NULL) return; shouldflush = softdep_flushcache; bio = NULL; jseg = NULL; - ump = VFSTOUFS(mp); LOCK_OWNED(ump); fs = ump->um_fs; jblocks = ump->softdep_jblocks; @@ -14227,7 +14229,8 @@ check_clear_deps(mp) * causes deferred work to be done sooner. */ ump = VFSTOUFS(mp); - suj_susp = MOUNTEDSUJ(mp) && ump->softdep_jblocks->jb_suspended; + suj_susp = ump->um_softdep->sd_jblocks != NULL && + ump->softdep_jblocks->jb_suspended; if (req_clear_remove || req_clear_inodedeps || suj_susp) { FREE_LOCK(ump); softdep_send_speedup(ump, 0, BIO_SPEEDUP_TRIM | BIO_SPEEDUP_WRITE); diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index 0e8a13b87eec..28b8175a42dd 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -380,6 +380,7 @@ ffs_mount(struct mount *mp) accmode_t accmode; struct nameidata ndp; char *fspec; + bool mounted_softdep; td = curthread; if (vfs_filteropt(mp->mnt_optnew, ffs_opts)) @@ -491,6 +492,16 @@ ffs_mount(struct mount *mp) error = vfs_write_suspend_umnt(mp); if (error != 0) return (error); + + fs->fs_ronly = 1; + if (MOUNTEDSOFTDEP(mp)) { + MNT_ILOCK(mp); + mp->mnt_flag &= ~MNT_SOFTDEP; + MNT_IUNLOCK(mp); + mounted_softdep = true; + } else + mounted_softdep = false; + /* * Check for and optionally get rid of files open * for writing. @@ -498,15 +509,22 @@ ffs_mount(struct mount *mp) flags = WRITECLOSE; if (mp->mnt_flag & MNT_FORCE) flags |= FORCECLOSE; - if (MOUNTEDSOFTDEP(mp)) { + if (mounted_softdep) { error = softdep_flushfiles(mp, flags, td); } else { error = ffs_flushfiles(mp, flags, td); } if (error) { + fs->fs_ronly = 0; + if (mounted_softdep) { + MNT_ILOCK(mp); + mp->mnt_flag |= MNT_SOFTDEP; + MNT_IUNLOCK(mp); + } vfs_write_resume(mp, 0); return (error); } + if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) { printf("WARNING: %s Update error: blocks %jd " @@ -521,10 +539,15 @@ ffs_mount(struct mount *mp) if ((error = ffs_sbupdate(ump, MNT_WAIT, 0)) != 0) { fs->fs_ronly = 0; fs->fs_clean = 0; + if (mounted_softdep) { + MNT_ILOCK(mp); + mp->mnt_flag |= MNT_SOFTDEP; + MNT_IUNLOCK(mp); + } vfs_write_resume(mp, 0); return (error); } - if (MOUNTEDSOFTDEP(mp)) + if (mounted_softdep) softdep_unmount(mp); g_topology_lock(); /* @@ -532,7 +555,6 @@ ffs_mount(struct mount *mp) */ g_access(ump->um_cp, 0, -1, -1); g_topology_unlock(); - fs->fs_ronly = 1; MNT_ILOCK(mp); mp->mnt_flag |= MNT_RDONLY; MNT_IUNLOCK(mp); From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:28 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 635E566A194; Sat, 14 Aug 2021 10:22:28 +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 4GmxLr1YlMz3LWb; Sat, 14 Aug 2021 10:22:28 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 1A02320656; Sat, 14 Aug 2021 10:22:28 +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 17EAMRYA029785; Sat, 14 Aug 2021 10:22:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMRX6029784; Sat, 14 Aug 2021 10:22:27 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:27 GMT Message-Id: <202108141022.17EAMRX6029784@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: f59d0c7c58f1 - stable/13 - softdep_unmount: handle spurious wakeups MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f59d0c7c58f1b0ee32675be915dfc9eac7d0044d Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:28 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=f59d0c7c58f1b0ee32675be915dfc9eac7d0044d commit f59d0c7c58f1b0ee32675be915dfc9eac7d0044d Author: Konstantin Belousov AuthorDate: 2021-02-28 22:46:21 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:58 +0000 softdep_unmount: handle spurious wakeups (cherry picked from commit d7e5e374167fe98e998b80691824750f44bb050d) --- sys/ufs/ffs/ffs_softdep.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index fbb5c0cbc727..c904336af2e4 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -2802,10 +2802,13 @@ softdep_unmount(mp) ACQUIRE_LOCK(ump); ump->softdep_flags |= FLUSH_EXIT; wakeup(&ump->softdep_flushtd); - msleep(&ump->softdep_flags, LOCK_PTR(ump), PVM | PDROP, - "sdwait", 0); + while ((ump->softdep_flags & FLUSH_EXIT) != 0) { + msleep(&ump->softdep_flags, LOCK_PTR(ump), PVM, + "sdwait", 0); + } KASSERT((ump->softdep_flags & FLUSH_EXIT) == 0, ("Thread shutdown failed")); + FREE_LOCK(ump); } /* From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:29 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9B7E9669E53; Sat, 14 Aug 2021 10:22:29 +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 4GmxLs2wCKz3Lql; Sat, 14 Aug 2021 10:22:29 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 36253206CD; Sat, 14 Aug 2021 10:22:29 +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 17EAMTAQ029809; Sat, 14 Aug 2021 10:22:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMTOq029808; Sat, 14 Aug 2021 10:22:29 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:29 GMT Message-Id: <202108141022.17EAMTOq029808@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 1b957df8f8f2 - stable/13 - ffs_mount: when remounting ro->rw and sbupdate failed, cleanup softdeps MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1b957df8f8f2a24fdbc95690d9c1f615194bcc64 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:29 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=1b957df8f8f2a24fdbc95690d9c1f615194bcc64 commit 1b957df8f8f2a24fdbc95690d9c1f615194bcc64 Author: Konstantin Belousov AuthorDate: 2021-03-03 18:02:13 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:58 +0000 ffs_mount: when remounting ro->rw and sbupdate failed, cleanup softdeps (cherry picked from commit f776c54cee81b4297b59ffe87a0f154e3924ee7f) --- sys/ufs/ffs/ffs_vfsops.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index 28b8175a42dd..d321e98e8347 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -645,6 +645,8 @@ ffs_mount(struct mount *mp) fs->fs_clean = 0; if ((error = ffs_sbupdate(ump, MNT_WAIT, 0)) != 0) { fs->fs_ronly = 1; + if ((fs->fs_flags & FS_DOSOFTDEP) != 0) + softdep_unmount(mp); MNT_ILOCK(mp); mp->mnt_flag |= saved_mnt_flag; MNT_IUNLOCK(mp); From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:27 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5F511669E4C; Sat, 14 Aug 2021 10:22:27 +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 4GmxLq10qVz3LnJ; Sat, 14 Aug 2021 10:22:27 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 E1CD0206CC; Sat, 14 Aug 2021 10:22:26 +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 17EAMQ4e029761; Sat, 14 Aug 2021 10:22:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMQZj029760; Sat, 14 Aug 2021 10:22:26 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:26 GMT Message-Id: <202108141022.17EAMQZj029760@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: a326a8f616e9 - stable/13 - softdep_flush(): do not access ump after we acked FLUSH_EXIT and unlocked SU lock MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a326a8f616e9fc0b7ec4024e555261485fc1b1e1 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:27 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a326a8f616e9fc0b7ec4024e555261485fc1b1e1 commit a326a8f616e9fc0b7ec4024e555261485fc1b1e1 Author: Konstantin Belousov AuthorDate: 2021-02-28 22:45:04 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:58 +0000 softdep_flush(): do not access ump after we acked FLUSH_EXIT and unlocked SU lock (cherry picked from commit fabbc3d879cce5c37df25707107a0fcb64267346) --- sys/ufs/ffs/ffs_softdep.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index 3fd5476df17d..fbb5c0cbc727 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -1568,6 +1568,7 @@ softdep_flush(addr) struct mount *mp; struct thread *td; struct ufsmount *ump; + int cleanups; td = curthread; td->td_pflags |= TDP_NORUNNINGBUF; @@ -1602,10 +1603,14 @@ softdep_flush(addr) continue; } ump->softdep_flags &= ~FLUSH_EXIT; + cleanups = ump->um_softdep->sd_cleanups; FREE_LOCK(ump); wakeup(&ump->softdep_flags); - if (print_threads) - printf("Stop thread %s: searchfailed %d, did cleanups %d\n", td->td_name, searchfailed, ump->um_softdep->sd_cleanups); + if (print_threads) { + printf("Stop thread %s: searchfailed %d, " + "did cleanups %d\n", + td->td_name, searchfailed, cleanups); + } atomic_subtract_int(&stat_flush_threads, 1); kthread_exit(); panic("kthread_exit failed\n"); From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:32 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B761466A0A9; Sat, 14 Aug 2021 10:22:32 +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 4GmxLv6XwJz3Lt5; Sat, 14 Aug 2021 10:22:31 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 7E2372056C; Sat, 14 Aug 2021 10:22:31 +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 17EAMVb7029865; Sat, 14 Aug 2021 10:22:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMVlm029864; Sat, 14 Aug 2021 10:22:31 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:31 GMT Message-Id: <202108141022.17EAMVlm029864@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 22d33453e141 - stable/13 - FFS: assign fully initialized struct mount_softdeps to um_softdep MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 22d33453e14119e898cbf4de3aee93533451e2ae Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:32 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=22d33453e14119e898cbf4de3aee93533451e2ae commit 22d33453e14119e898cbf4de3aee93533451e2ae Author: Konstantin Belousov AuthorDate: 2021-03-03 22:02:30 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:59 +0000 FFS: assign fully initialized struct mount_softdeps to um_softdep (cherry picked from commit 7a8d4b4da69af966bff4892acb2fd101a95a4848) --- sys/ufs/ffs/ffs_softdep.c | 68 ++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index c904336af2e4..54f7d0d559fc 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -2678,48 +2678,50 @@ softdep_mount(devvp, mp, fs, cred) u_int cyl, i; int error; + ump = VFSTOUFS(mp); + sdp = malloc(sizeof(struct mount_softdeps), M_MOUNTDATA, M_WAITOK | M_ZERO); - MNT_ILOCK(mp); - mp->mnt_flag = (mp->mnt_flag & ~MNT_ASYNC) | MNT_SOFTDEP; - if ((mp->mnt_kern_flag & MNTK_SOFTDEP) == 0) { - mp->mnt_kern_flag = (mp->mnt_kern_flag & ~MNTK_ASYNC) | - MNTK_SOFTDEP | MNTK_NOASYNC; - } - ump = VFSTOUFS(mp); - ump->um_softdep = sdp; - MNT_IUNLOCK(mp); - rw_init(LOCK_PTR(ump), "per-fs softdep"); + rw_init(&sdp->sd_fslock, "SUrw"); sdp->sd_ump = ump; - LIST_INIT(&ump->softdep_workitem_pending); - LIST_INIT(&ump->softdep_journal_pending); - TAILQ_INIT(&ump->softdep_unlinked); - LIST_INIT(&ump->softdep_dirtycg); - ump->softdep_worklist_tail = NULL; - ump->softdep_on_worklist = 0; - ump->softdep_deps = 0; - LIST_INIT(&ump->softdep_mkdirlisthd); - ump->pagedep_hashtbl = hashinit(desiredvnodes / 5, M_PAGEDEP, - &ump->pagedep_hash_size); - ump->pagedep_nextclean = 0; - ump->inodedep_hashtbl = hashinit(desiredvnodes, M_INODEDEP, - &ump->inodedep_hash_size); - ump->inodedep_nextclean = 0; - ump->newblk_hashtbl = hashinit(max_softdeps / 2, M_NEWBLK, - &ump->newblk_hash_size); - ump->bmsafemap_hashtbl = hashinit(1024, M_BMSAFEMAP, - &ump->bmsafemap_hash_size); + LIST_INIT(&sdp->sd_workitem_pending); + LIST_INIT(&sdp->sd_journal_pending); + TAILQ_INIT(&sdp->sd_unlinked); + LIST_INIT(&sdp->sd_dirtycg); + sdp->sd_worklist_tail = NULL; + sdp->sd_on_worklist = 0; + sdp->sd_deps = 0; + LIST_INIT(&sdp->sd_mkdirlisthd); + sdp->sd_pdhash = hashinit(desiredvnodes / 5, M_PAGEDEP, + &sdp->sd_pdhashsize); + sdp->sd_pdnextclean = 0; + sdp->sd_idhash = hashinit(desiredvnodes, M_INODEDEP, + &sdp->sd_idhashsize); + sdp->sd_idnextclean = 0; + sdp->sd_newblkhash = hashinit(max_softdeps / 2, M_NEWBLK, + &sdp->sd_newblkhashsize); + sdp->sd_bmhash = hashinit(1024, M_BMSAFEMAP, &sdp->sd_bmhashsize); i = 1 << (ffs(desiredvnodes / 10) - 1); - ump->indir_hashtbl = malloc(i * sizeof(struct indir_hashhead), + sdp->sd_indirhash = malloc(i * sizeof(struct indir_hashhead), M_FREEWORK, M_WAITOK); - ump->indir_hash_size = i - 1; - for (i = 0; i <= ump->indir_hash_size; i++) - TAILQ_INIT(&ump->indir_hashtbl[i]); + sdp->sd_indirhashsize = i - 1; + for (i = 0; i <= sdp->sd_indirhashsize; i++) + TAILQ_INIT(&sdp->sd_indirhash[i]); for (i = 0; i <= D_LAST; i++) - LIST_INIT(&ump->softdep_alldeps[i]); + LIST_INIT(&sdp->sd_alldeps[i]); ACQUIRE_GBLLOCK(&lk); TAILQ_INSERT_TAIL(&softdepmounts, sdp, sd_next); FREE_GBLLOCK(&lk); + + ump->um_softdep = sdp; + MNT_ILOCK(mp); + mp->mnt_flag = (mp->mnt_flag & ~MNT_ASYNC) | MNT_SOFTDEP; + if ((mp->mnt_kern_flag & MNTK_SOFTDEP) == 0) { + mp->mnt_kern_flag = (mp->mnt_kern_flag & ~MNTK_ASYNC) | + MNTK_SOFTDEP | MNTK_NOASYNC; + } + MNT_IUNLOCK(mp); + if ((fs->fs_flags & FS_SUJ) && (error = journal_mount(mp, fs, cred)) != 0) { printf("Failed to start journal: %d\n", error); From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:30 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BE23466A0A7; Sat, 14 Aug 2021 10:22:30 +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 4GmxLt3yHlz3LZ4; Sat, 14 Aug 2021 10:22:30 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 5847C20658; Sat, 14 Aug 2021 10:22:30 +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 17EAMUPX029833; Sat, 14 Aug 2021 10:22:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMUDW029832; Sat, 14 Aug 2021 10:22:30 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:30 GMT Message-Id: <202108141022.17EAMUDW029832@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: f14006ee899f - stable/13 - Assert that um_softdep is NULL on free(ump), i.e. softdep_unmount() was called MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f14006ee899f3bc44056d98f4fc915b8976c2302 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:31 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=f14006ee899f3bc44056d98f4fc915b8976c2302 commit f14006ee899f3bc44056d98f4fc915b8976c2302 Author: Konstantin Belousov AuthorDate: 2021-03-03 19:40:34 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:58 +0000 Assert that um_softdep is NULL on free(ump), i.e. softdep_unmount() was called (cherry picked from commit 2af934cc15bd8e7daa2daeb806321d0daddf3b7a) --- sys/ufs/ffs/ffs_vfsops.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index d321e98e8347..85c7929550fb 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -1355,6 +1355,7 @@ out: free(mp->mnt_gjprovider, M_UFSMNT); mp->mnt_gjprovider = NULL; } + MPASS(ump->um_softdep == NULL); free(ump, M_UFSMNT); mp->mnt_data = NULL; } @@ -1537,6 +1538,7 @@ ffs_unmount(mp, mntflags) UFS_UNLOCK(ump); if (MOUNTEDSOFTDEP(mp)) softdep_unmount(mp); + MPASS(ump->um_softdep == NULL); if (fs->fs_ronly == 0 || ump->um_fsckpid > 0) { fs->fs_clean = fs->fs_flags & (FS_UNCLEAN|FS_NEEDSFSCK) ? 0 : 1; error = ffs_sbupdate(ump, MNT_WAIT, 0); From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:34 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C3EDB66A21D; Sat, 14 Aug 2021 10:22:34 +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 4GmxLy1hy1z3Lny; Sat, 14 Aug 2021 10:22:33 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 C28E4208EB; Sat, 14 Aug 2021 10:22:33 +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 17EAMXR9029913; Sat, 14 Aug 2021 10:22:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMXrX029912; Sat, 14 Aug 2021 10:22:33 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:33 GMT Message-Id: <202108141022.17EAMXrX029912@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: a14a142c6e32 - stable/13 - vlrureclaim: only skip vnode with resident pages if it own the pages MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a14a142c6e32926b2d751356fb1f5ea4f3ddfa0c Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:35 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a14a142c6e32926b2d751356fb1f5ea4f3ddfa0c commit a14a142c6e32926b2d751356fb1f5ea4f3ddfa0c Author: Konstantin Belousov AuthorDate: 2021-03-06 21:09:16 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:59 +0000 vlrureclaim: only skip vnode with resident pages if it own the pages (cherry picked from commit 44691b33cc99d0e17262368b6e0f64e531994a23) --- sys/kern/vfs_subr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index bd4413edcb40..d67936447216 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1169,7 +1169,7 @@ restart: VI_LOCK(vp); if (vp->v_usecount > 0 || (!reclaim_nc_src && !LIST_EMPTY(&vp->v_cache_src)) || - (vp->v_object != NULL && + (vp->v_object != NULL && vp->v_object->handle == vp && vp->v_object->resident_page_count > trigger)) { VOP_UNLOCK(vp); vdropl(vp); From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:33 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2EC0566A12D; Sat, 14 Aug 2021 10:22:33 +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 4GmxLw6Kpcz3LWq; Sat, 14 Aug 2021 10:22:32 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 A0E71206D0; Sat, 14 Aug 2021 10:22:32 +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 17EAMWMs029889; Sat, 14 Aug 2021 10:22:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMWsQ029888; Sat, 14 Aug 2021 10:22:32 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:32 GMT Message-Id: <202108141022.17EAMWsQ029888@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 494aba874922 - stable/13 - softdep_unmount: assert that no dandling dependencies are left MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 494aba874922e7a0367548e264306f89a268c407 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:33 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=494aba874922e7a0367548e264306f89a268c407 commit 494aba874922e7a0367548e264306f89a268c407 Author: Konstantin Belousov AuthorDate: 2021-03-06 09:52:10 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:59 +0000 softdep_unmount: assert that no dandling dependencies are left (cherry picked from commit 0b3948e73b749b0fefc3f9d4fc61f356542bb9b9) --- sys/ufs/ffs/ffs_softdep.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index 54f7d0d559fc..27d1cc8b0537 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -2822,6 +2822,13 @@ softdep_unmount(mp) FREE_GBLLOCK(&lk); ump->um_softdep = NULL; + KASSERT(ums->sd_on_journal == 0, + ("ump %p ums %p on_journal %d", ump, ums, ums->sd_on_journal)); + KASSERT(ums->sd_on_worklist == 0, + ("ump %p ums %p on_worklist %d", ump, ums, ums->sd_on_worklist)); + KASSERT(ums->sd_deps == 0, + ("ump %p ums %p deps %d", ump, ums, ums->sd_deps)); + /* * Free up our resources. */ From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 10:22:35 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6565E669E64; Sat, 14 Aug 2021 10:22:35 +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 4GmxLz1K3mz3LX0; Sat, 14 Aug 2021 10:22:35 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 EDF332056E; Sat, 14 Aug 2021 10:22:34 +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 17EAMYqx029937; Sat, 14 Aug 2021 10:22:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EAMY67029936; Sat, 14 Aug 2021 10:22:34 GMT (envelope-from git) Date: Sat, 14 Aug 2021 10:22:34 GMT Message-Id: <202108141022.17EAMY67029936@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 94cb19f46114 - stable/13 - null_vput_pair(): release use reference on dvp earlier MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 94cb19f46114950586fc363b518550c171849291 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 10:22:35 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=94cb19f46114950586fc363b518550c171849291 commit 94cb19f46114950586fc363b518550c171849291 Author: Konstantin Belousov AuthorDate: 2021-03-07 21:08:38 +0000 Commit: Konstantin Belousov CommitDate: 2021-08-14 10:21:59 +0000 null_vput_pair(): release use reference on dvp earlier (cherry picked from commit 16dea8341024b8ee8be619c27d4e63bd81bd9b6c) --- sys/fs/nullfs/null_vnops.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/sys/fs/nullfs/null_vnops.c b/sys/fs/nullfs/null_vnops.c index 6a6df55a0bef..e3a320a22bfa 100644 --- a/sys/fs/nullfs/null_vnops.c +++ b/sys/fs/nullfs/null_vnops.c @@ -1084,33 +1084,50 @@ null_vput_pair(struct vop_vput_pair_args *ap) vpp = ap->a_vpp; vp = NULL; lvp = NULL; - if (vpp != NULL) { + mp = NULL; + if (vpp != NULL) vp = *vpp; - if (vp != NULL) { + if (vp != NULL) { + lvp = NULLVPTOLOWERVP(vp); + vref(lvp); + if (!ap->a_unlock_vp) { vhold(vp); + vhold(lvp); mp = vp->v_mount; - lvp = NULLVPTOLOWERVP(vp); - if (ap->a_unlock_vp) - vref(lvp); + vfs_ref(mp); } } - res = VOP_VPUT_PAIR(ldvp, &lvp, ap->a_unlock_vp); + res = VOP_VPUT_PAIR(ldvp, lvp != NULL ? &lvp : NULL, true); + if (vp != NULL && ap->a_unlock_vp) + vrele(vp); + vrele(dvp); - /* lvp might have been unlocked and vp reclaimed */ - if (vp != NULL) { - if (!ap->a_unlock_vp && vp->v_vnlock != lvp->v_vnlock) { + if (vp == NULL || ap->a_unlock_vp) + return (res); + + /* lvp has been unlocked and vp might be reclaimed */ + VOP_LOCK(vp, LK_EXCLUSIVE | LK_RETRY); + if (vp->v_data == NULL && vfs_busy(mp, MBF_NOWAIT) == 0) { + vput(vp); + vget(lvp, LK_EXCLUSIVE | LK_RETRY); + if (VN_IS_DOOMED(lvp)) { + vput(lvp); + vget(vp, LK_EXCLUSIVE | LK_RETRY); + } else { error = null_nodeget(mp, lvp, &vp1); if (error == 0) { - vput(vp); *vpp = vp1; + } else { + vget(vp, LK_EXCLUSIVE | LK_RETRY); } } - if (ap->a_unlock_vp) - vrele(vp); - vdrop(vp); + vfs_unbusy(mp); } - vrele(dvp); + vdrop(lvp); + vdrop(vp); + vfs_rel(mp); + return (res); } From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 12:57:27 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6225666C8CE; Sat, 14 Aug 2021 12:57:27 +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 4Gn0ng1xPrz3lsV; Sat, 14 Aug 2021 12:57:27 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 2AB09224CD; Sat, 14 Aug 2021 12:57:27 +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 17ECvRnK030846; Sat, 14 Aug 2021 12:57:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17ECvRie030845; Sat, 14 Aug 2021 12:57:27 GMT (envelope-from git) Date: Sat, 14 Aug 2021 12:57:27 GMT Message-Id: <202108141257.17ECvRie030845@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: ed698ef1e152 - stable/13 - Apply upstream lld fix for compressed input sections on BE targets MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: ed698ef1e1523b3bd25405f5dc82bbeb44f79805 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 12:57:27 -0000 The branch stable/13 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=ed698ef1e1523b3bd25405f5dc82bbeb44f79805 commit ed698ef1e1523b3bd25405f5dc82bbeb44f79805 Author: Dimitry Andric AuthorDate: 2021-08-07 11:14:11 +0000 Commit: Dimitry Andric CommitDate: 2021-08-14 12:52:55 +0000 Apply upstream lld fix for compressed input sections on BE targets Merge commit c6ebc651b6fa from llvm git (by Simon Atanasyan): [LLD] Support compressed input sections on big-endian targets This patch enables compressed input sections on big-endian targets by checking the target endianness and selecting an appropriate `Chdr` structure. Fixes PR51369 Differential Revision: https://reviews.llvm.org/D107635 Reported by: emaste (cherry picked from commit d69d07569ee2404705ff4c4abb45dc0b884eeb35) Follow-up to d69d07569ee2 by bumping lld local version This makes it easier to detect that lld's support for compressed input sections on BE targets is fixed. (cherry picked from commit cd38d9cf26db9264f709c52469f0f4e9684d62bb) --- contrib/llvm-project/lld/ELF/InputSection.cpp | 47 ++++++++++++--------------- contrib/llvm-project/lld/ELF/InputSection.h | 1 + lib/clang/include/VCSVersion.inc | 2 +- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/contrib/llvm-project/lld/ELF/InputSection.cpp b/contrib/llvm-project/lld/ELF/InputSection.cpp index 6f16fc7abc48..f9cad7f975a7 100644 --- a/contrib/llvm-project/lld/ELF/InputSection.cpp +++ b/contrib/llvm-project/lld/ELF/InputSection.cpp @@ -88,7 +88,22 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags, if (!zlib::isAvailable()) error(toString(file) + ": contains a compressed section, " + "but zlib is not available"); - parseCompressedHeader(); + switch (config->ekind) { + case ELF32LEKind: + parseCompressedHeader(); + break; + case ELF32BEKind: + parseCompressedHeader(); + break; + case ELF64LEKind: + parseCompressedHeader(); + break; + case ELF64BEKind: + parseCompressedHeader(); + break; + default: + llvm_unreachable("unknown ELFT"); + } } } @@ -210,10 +225,7 @@ OutputSection *SectionBase::getOutputSection() { // When a section is compressed, `rawData` consists with a header followed // by zlib-compressed data. This function parses a header to initialize // `uncompressedSize` member and remove the header from `rawData`. -void InputSectionBase::parseCompressedHeader() { - using Chdr64 = typename ELF64LE::Chdr; - using Chdr32 = typename ELF32LE::Chdr; - +template void InputSectionBase::parseCompressedHeader() { // Old-style header if (name.startswith(".zdebug")) { if (!toStringRef(rawData).startswith("ZLIB")) { @@ -239,32 +251,13 @@ void InputSectionBase::parseCompressedHeader() { assert(flags & SHF_COMPRESSED); flags &= ~(uint64_t)SHF_COMPRESSED; - // New-style 64-bit header - if (config->is64) { - if (rawData.size() < sizeof(Chdr64)) { - error(toString(this) + ": corrupted compressed section"); - return; - } - - auto *hdr = reinterpret_cast(rawData.data()); - if (hdr->ch_type != ELFCOMPRESS_ZLIB) { - error(toString(this) + ": unsupported compression type"); - return; - } - - uncompressedSize = hdr->ch_size; - alignment = std::max(hdr->ch_addralign, 1); - rawData = rawData.slice(sizeof(*hdr)); - return; - } - - // New-style 32-bit header - if (rawData.size() < sizeof(Chdr32)) { + // New-style header + if (rawData.size() < sizeof(typename ELFT::Chdr)) { error(toString(this) + ": corrupted compressed section"); return; } - auto *hdr = reinterpret_cast(rawData.data()); + auto *hdr = reinterpret_cast(rawData.data()); if (hdr->ch_type != ELFCOMPRESS_ZLIB) { error(toString(this) + ": unsupported compression type"); return; diff --git a/contrib/llvm-project/lld/ELF/InputSection.h b/contrib/llvm-project/lld/ELF/InputSection.h index 5b91c1c90bd2..c914d0b42155 100644 --- a/contrib/llvm-project/lld/ELF/InputSection.h +++ b/contrib/llvm-project/lld/ELF/InputSection.h @@ -238,6 +238,7 @@ public: } protected: + template void parseCompressedHeader(); void uncompress() const; diff --git a/lib/clang/include/VCSVersion.inc b/lib/clang/include/VCSVersion.inc index cb7736e7d7de..8c1798de59ee 100644 --- a/lib/clang/include/VCSVersion.inc +++ b/lib/clang/include/VCSVersion.inc @@ -7,7 +7,7 @@ #define CLANG_REPOSITORY "git@github.com:llvm/llvm-project.git" // - -#define LLD_REVISION "llvmorg-12.0.1-0-gfed41342a82f-1400001" +#define LLD_REVISION "llvmorg-12.0.1-0-gfed41342a82f-1400002" #define LLD_REPOSITORY "FreeBSD" #define LLDB_REVISION "llvmorg-12.0.1-0-gfed41342a82f" From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 13:03:52 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9383966CF8C; Sat, 14 Aug 2021 13:03: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 4Gn0x43hyqz3mbV; Sat, 14 Aug 2021 13:03:52 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 673CA224F6; Sat, 14 Aug 2021 13:03: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 17ED3qKY045374; Sat, 14 Aug 2021 13:03:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17ED3qUK045373; Sat, 14 Aug 2021 13:03:52 GMT (envelope-from git) Date: Sat, 14 Aug 2021 13:03:52 GMT Message-Id: <202108141303.17ED3qUK045373@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: 6b364a92fd79 - stable/13 - Add ElfW() macro for compatibility with Linux MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 6b364a92fd790717fe7ea589df62dc1a653137dc Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 13:03:52 -0000 The branch stable/13 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=6b364a92fd790717fe7ea589df62dc1a653137dc commit 6b364a92fd790717fe7ea589df62dc1a653137dc Author: Dimitry Andric AuthorDate: 2021-08-05 18:57:22 +0000 Commit: Dimitry Andric CommitDate: 2021-08-14 12:57:58 +0000 Add ElfW() macro for compatibility with Linux Some Linux software using ELF headers assumes the existence of an ElfW(type) macro, which concatenates 'Elf', the default ELF word size, and the given type. This is identical to our __ElfN(x) macro in . Add the macro for compatibility, with a comment that we prefer the __ElfN() macro for FreeBSD. Reviewed by: emaste, kib Differential Revision: https://reviews.freebsd.org/D31427 MFC after: 1 week (cherry picked from commit 34e7e4b6a059eee5e4e3e34de5b9d5f0d6e589f9) --- sys/sys/elf_generic.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sys/sys/elf_generic.h b/sys/sys/elf_generic.h index 301ee52cf7a1..dcd44fe93b14 100644 --- a/sys/sys/elf_generic.h +++ b/sys/sys/elf_generic.h @@ -57,6 +57,9 @@ #define __ELFN(x) __CONCAT(__CONCAT(__CONCAT(ELF,__ELF_WORD_SIZE),_),x) #define __ElfType(x) typedef __ElfN(x) __CONCAT(Elf_,x) +/* Define ElfW for compatibility with Linux, prefer __ElfN() in FreeBSD code */ +#define ElfW(x) __ElfN(x) + __ElfType(Addr); __ElfType(Half); __ElfType(Off); From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 13:04:36 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id ED91166CF1E; Sat, 14 Aug 2021 13:04:36 +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 4Gn0xw6Qljz3mW9; Sat, 14 Aug 2021 13:04:36 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 C4CB622C87; Sat, 14 Aug 2021 13:04:36 +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 17ED4ani045537; Sat, 14 Aug 2021 13:04:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17ED4ad8045536; Sat, 14 Aug 2021 13:04:36 GMT (envelope-from git) Date: Sat, 14 Aug 2021 13:04:36 GMT Message-Id: <202108141304.17ED4ad8045536@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: b58a13b94c99 - stable/12 - Add ElfW() macro for compatibility with Linux MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: b58a13b94c99a5c505bc24ca705111585d1b6759 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 13:04:37 -0000 The branch stable/12 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=b58a13b94c99a5c505bc24ca705111585d1b6759 commit b58a13b94c99a5c505bc24ca705111585d1b6759 Author: Dimitry Andric AuthorDate: 2021-08-05 18:57:22 +0000 Commit: Dimitry Andric CommitDate: 2021-08-14 13:00:28 +0000 Add ElfW() macro for compatibility with Linux Some Linux software using ELF headers assumes the existence of an ElfW(type) macro, which concatenates 'Elf', the default ELF word size, and the given type. This is identical to our __ElfN(x) macro in . Add the macro for compatibility, with a comment that we prefer the __ElfN() macro for FreeBSD. Reviewed by: emaste, kib Differential Revision: https://reviews.freebsd.org/D31427 MFC after: 1 week (cherry picked from commit 34e7e4b6a059eee5e4e3e34de5b9d5f0d6e589f9) --- sys/sys/elf_generic.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sys/sys/elf_generic.h b/sys/sys/elf_generic.h index 301ee52cf7a1..dcd44fe93b14 100644 --- a/sys/sys/elf_generic.h +++ b/sys/sys/elf_generic.h @@ -57,6 +57,9 @@ #define __ELFN(x) __CONCAT(__CONCAT(__CONCAT(ELF,__ELF_WORD_SIZE),_),x) #define __ElfType(x) typedef __ElfN(x) __CONCAT(Elf_,x) +/* Define ElfW for compatibility with Linux, prefer __ElfN() in FreeBSD code */ +#define ElfW(x) __ElfN(x) + __ElfType(Addr); __ElfType(Half); __ElfType(Off); From owner-dev-commits-src-branches@freebsd.org Sat Aug 14 13:04:56 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 63F2B66D062; Sat, 14 Aug 2021 13:04:56 +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 4Gn0yJ2Shqz3ml8; Sat, 14 Aug 2021 13:04:56 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 3CB04225D3; Sat, 14 Aug 2021 13:04:56 +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 17ED4ucF045670; Sat, 14 Aug 2021 13:04:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17ED4uAD045669; Sat, 14 Aug 2021 13:04:56 GMT (envelope-from git) Date: Sat, 14 Aug 2021 13:04:56 GMT Message-Id: <202108141304.17ED4uAD045669@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: 2b53701772f0 - stable/11 - Add ElfW() macro for compatibility with Linux MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/11 X-Git-Reftype: branch X-Git-Commit: 2b53701772f00a0bfa1783f5e82a9a497f335f2a Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 13:04:56 -0000 The branch stable/11 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=2b53701772f00a0bfa1783f5e82a9a497f335f2a commit 2b53701772f00a0bfa1783f5e82a9a497f335f2a Author: Dimitry Andric AuthorDate: 2021-08-05 18:57:22 +0000 Commit: Dimitry Andric CommitDate: 2021-08-14 13:03:26 +0000 Add ElfW() macro for compatibility with Linux Some Linux software using ELF headers assumes the existence of an ElfW(type) macro, which concatenates 'Elf', the default ELF word size, and the given type. This is identical to our __ElfN(x) macro in . Add the macro for compatibility, with a comment that we prefer the __ElfN() macro for FreeBSD. Reviewed by: emaste, kib Differential Revision: https://reviews.freebsd.org/D31427 MFC after: 1 week (cherry picked from commit 34e7e4b6a059eee5e4e3e34de5b9d5f0d6e589f9) --- sys/sys/elf_generic.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sys/sys/elf_generic.h b/sys/sys/elf_generic.h index 5ff5242efcb2..34f4f47e064d 100644 --- a/sys/sys/elf_generic.h +++ b/sys/sys/elf_generic.h @@ -55,6 +55,9 @@ #define __ELFN(x) __CONCAT(__CONCAT(__CONCAT(ELF,__ELF_WORD_SIZE),_),x) #define __ElfType(x) typedef __ElfN(x) __CONCAT(Elf_,x) +/* Define ElfW for compatibility with Linux, prefer __ElfN() in FreeBSD code */ +#define ElfW(x) __ElfN(x) + __ElfType(Addr); __ElfType(Half); __ElfType(Off); From owner-dev-commits-src-branches@freebsd.org Sun Aug 15 05:56:21 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 64D8B65A82A; Sun, 15 Aug 2021 05:56: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GnRPJ70HPz4c6T; Sun, 15 Aug 2021 05:56:20 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 D8FFB10EBB; Sun, 15 Aug 2021 05:56:20 +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 17F5uK9B090790; Sun, 15 Aug 2021 05:56:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17F5uKqj090789; Sun, 15 Aug 2021 05:56:20 GMT (envelope-from git) Date: Sun, 15 Aug 2021 05:56:20 GMT Message-Id: <202108150556.17F5uKqj090789@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Gordon Bergling Subject: git: 64085efb677f - stable/13 - hms(4): Fix a typo in sysctl description MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: gbe X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 64085efb677fbfcf76235a1a9dcb497819e2b72f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2021 05:56:21 -0000 The branch stable/13 has been updated by gbe (doc committer): URL: https://cgit.FreeBSD.org/src/commit/?id=64085efb677fbfcf76235a1a9dcb497819e2b72f commit 64085efb677fbfcf76235a1a9dcb497819e2b72f Author: Gordon Bergling AuthorDate: 2021-08-12 13:37:47 +0000 Commit: Gordon Bergling CommitDate: 2021-08-15 05:56:02 +0000 hms(4): Fix a typo in sysctl description - s/threshhold/threshold/ (cherry picked from commit 4b4850aefe3ff9d9c29c7ed8bd8907bbd6142e86) --- sys/dev/hid/hms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/dev/hid/hms.c b/sys/dev/hid/hms.c index 94267b3fcd52..014354c3acc3 100644 --- a/sys/dev/hid/hms.c +++ b/sys/dev/hid/hms.c @@ -271,7 +271,7 @@ hms_attach(device_t dev) SYSCTL_ADD_U32(device_get_sysctl_ctx(dev), SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "drift_thresh", CTLFLAG_RW, &sc->drift_thresh, 0, - "drift detection threshhold"); + "drift detection threshold"); } #endif From owner-dev-commits-src-branches@freebsd.org Sun Aug 15 09:12:02 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4351D65D5BE; Sun, 15 Aug 2021 09:12:02 +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 4GnWl617x8z4mRw; Sun, 15 Aug 2021 09:12:02 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 0FE24139B9; Sun, 15 Aug 2021 09:12:02 +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 17F9C24H058552; Sun, 15 Aug 2021 09:12:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17F9C1Ye058492; Sun, 15 Aug 2021 09:12:01 GMT (envelope-from git) Date: Sun, 15 Aug 2021 09:12:01 GMT Message-Id: <202108150912.17F9C1Ye058492@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Peter Grehan Subject: git: d7388d33b4dd - stable/13 - MFC 517904de5cca: igc(4): Introduce new driver for the Intel I225 Ethernet controller. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: grehan X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: d7388d33b4ddffb8900b511ae767875916dd5126 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2021 09:12:02 -0000 The branch stable/13 has been updated by grehan: URL: https://cgit.FreeBSD.org/src/commit/?id=d7388d33b4ddffb8900b511ae767875916dd5126 commit d7388d33b4ddffb8900b511ae767875916dd5126 Author: Peter Grehan AuthorDate: 2021-07-12 04:50:15 +0000 Commit: Peter Grehan CommitDate: 2021-08-15 10:33:54 +0000 MFC 517904de5cca: igc(4): Introduce new driver for the Intel I225 Ethernet controller. This controller supports 2.5G/1G/100MB/10MB speeds, and allows tx/rx checksum offload, TSO, LRO, and multi-queue operation. The driver was derived from code contributed by Intel, and modified by Netgate to fit into the iflib framework. Thanks to Mike Karels for testing and feedback on the driver. Reviewed by: bcr (manpages), kbowling, scottl, erj Relnotes: yes Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D30668 (cherry picked from commit 517904de5ccac643589c71ac0d2751797f89e4f9) --- share/man/man4/Makefile | 2 + share/man/man4/igc.4 | 167 +++ sys/amd64/conf/GENERIC | 1 + sys/amd64/conf/NOTES | 2 + sys/conf/files | 8 + sys/dev/igc/if_igc.c | 2984 +++++++++++++++++++++++++++++++++++++++++++++ sys/dev/igc/if_igc.h | 430 +++++++ sys/dev/igc/igc_api.c | 735 +++++++++++ sys/dev/igc/igc_api.h | 58 + sys/dev/igc/igc_base.c | 188 +++ sys/dev/igc/igc_base.h | 131 ++ sys/dev/igc/igc_defines.h | 1347 ++++++++++++++++++++ sys/dev/igc/igc_hw.h | 548 +++++++++ sys/dev/igc/igc_i225.c | 1232 +++++++++++++++++++ sys/dev/igc/igc_i225.h | 112 ++ sys/dev/igc/igc_mac.c | 1050 ++++++++++++++++ sys/dev/igc/igc_mac.h | 48 + sys/dev/igc/igc_nvm.c | 721 +++++++++++ sys/dev/igc/igc_nvm.h | 32 + sys/dev/igc/igc_osdep.h | 133 ++ sys/dev/igc/igc_phy.c | 1109 +++++++++++++++++ sys/dev/igc/igc_phy.h | 134 ++ sys/dev/igc/igc_regs.h | 424 +++++++ sys/dev/igc/igc_txrx.c | 580 +++++++++ sys/i386/conf/GENERIC | 1 + sys/i386/conf/NOTES | 2 + sys/modules/Makefile | 2 + sys/modules/igc/Makefile | 11 + 28 files changed, 12192 insertions(+) diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile index 1e5df4bb2eec..c912abccae6e 100644 --- a/share/man/man4/Makefile +++ b/share/man/man4/Makefile @@ -225,6 +225,7 @@ MAN= aac.4 \ iicmux.4 \ iicsmb.4 \ iir.4 \ + ${_igc.4} \ ${_imcsmb.4} \ inet.4 \ inet6.4 \ @@ -820,6 +821,7 @@ _if_nfe.4= if_nfe.4 _if_urtw.4= if_urtw.4 _if_vmx.4= if_vmx.4 _if_wpi.4= if_wpi.4 +_igc.4= igc.4 _imcsmb.4= imcsmb.4 _ipmi.4= ipmi.4 _io.4= io.4 diff --git a/share/man/man4/igc.4 b/share/man/man4/igc.4 new file mode 100644 index 000000000000..bb79fbe5a8fa --- /dev/null +++ b/share/man/man4/igc.4 @@ -0,0 +1,167 @@ +.\"- +.\" Copyright 2021 Intel Corp +.\" Copyright 2021 Rubicon Communications, LLC (Netgate) +.\" SPDX-License-Identifier: BSD-3-Clause +.\" +.\" $FreeBSD$ +.\" +.Dd May 10, 2021 +.Dt IGC +.Os +.Sh NAME +.Nm igc +.Nd "Intel Ethernet Controller I225 driver" +.Sh SYNOPSIS +To compile this driver into the kernel, +place the following lines in your +kernel configuration file: +.Bd -ragged -offset indent +.Cd "device iflib" +.Cd "device igc" +.Ed +.Pp +Alternatively, to load the driver as a +module at boot time, place the following line in +.Xr loader.conf 5 : +.Bd -literal -offset indent +if_igc_load="YES" +.Ed +.Sh DESCRIPTION +The +.Nm +driver provides support for any PCI Express adapter or LOM (LAN +On Motherboard) based on the Intel I225 Multi Gigabit Controller. +The driver supports Transmit/Receive checksum offload, Jumbo Frames, +MSI/MSI-X, TSO, and RSS. +.Pp +Support for Jumbo Frames is provided via the interface MTU setting. +Selecting an MTU larger than 1500 bytes with the +.Xr ifconfig 8 +utility +configures the adapter to receive and transmit Jumbo Frames. +The maximum MTU size for Jumbo Frames is 9216 bytes. +.Pp +This driver version supports VLAN hardware insertion / extraction, and +VLAN checksum offload. +For information on enabling VLANs, see +.Xr ifconfig 8 . +The +.Nm +driver supports the following media types: +.Bl -tag -width ".Cm 10baseT/UTP" +.It Cm autoselect +Enables auto-negotiation for speed and duplex. +.It Cm 10baseT/UTP +Sets 10Mbps operation. +Use the +.Cm mediaopt +option to select +.Cm half-duplex +mode. +.It Cm 100baseTX +Sets 100Mbps operation. +Use the +.Cm mediaopt +option to select +.Cm half-duplex +mode. +.It Cm 1000baseT +Sets 1000Mbps operation. +Only +.Cm full-duplex +mode is supported at this speed. +.It Cm 2500baseT +Sets 2500Mbps operation. +Only +.Cm full-duplex +mode is supported at this speed. +.El +.Pp +.Sh HARDWARE +The +.Nm +driver supports the following models: +.Pp +.Bl -bullet -compact +.It +I225-LM +.It +I225-V +.It +I225-IT +.It +I225-K +.El +.Sh LOADER TUNABLES +Tunables can be set at the +.Xr loader 8 +prompt before booting the kernel or stored in +.Xr loader.conf 5 . +.Bl -tag -width indent +.It Va hw.igc.igc_disable_crc_stripping +Disable or enable hardware stripping of CRC field. +This is mostly useful on BMC/IPMI shared interfaces where stripping the +CRC causes remote access over IPMI to fail. +Default 0 (enabled). +.It Va hw.igc.rx_int_delay +This value delays the generation of receive interrupts in units +of 1.024 microseconds. +The default value is 0, since adapters may hang with this feature being +enabled. +.It Va hw.igc.rx_abs_int_delay +If hw.igc.rx_int_delay is non-zero, this tunable limits the +maximum delay in which a receive interrupt is generated. +.It Va hw.igc.tx_int_delay +This value delays the generation of transmit interrupts in units +of 1.024 microseconds. +The default value is 64. +.It Va hw.igc.tx_abs_int_delay +If hw.igc.tx_int_delay is non-zero, this tunable limits the +maximum delay in which a transmit interrupt is generated. +.It Va hw.igc.sbp +Show bad packets when in promiscuous mode. +Default is false. +.It Va hw.igc.rx_process_limit +Maximum number of received packets to process at a time. +Default is 100. +A value of -1 means unlimited. +.It Va hw.igc.eee_setting +Disable or enable Energy Efficient Ethernet. +Default 1 (disabled). +.It Va hw.igc.max_interrupt_rate +Maximum device interrupts per second. +The default is 8000. +.El +.Sh DIAGNOSTICS +.Bl -diag +.It "igc%d: Hardware Initialization Failed" +A fatal initialization error has occurred. +.It "igc%d: Unable to allocate bus resource: memory" +A fatal initialization error has occurred. +.It "igc%d: Invalid MAC address" +The MAC address programmed into the EEPROM is either empty or a multicast/broadcast +address. +.El +.Sh SEE ALSO +.Xr altq 4 , +.Xr arp 4 , +.Xr iflib 4 , +.Xr netintro 4 , +.Xr ng_ether 4 , +.Xr vlan 4 , +.Xr ifconfig 8 +.Sh HISTORY +The +.Nm +device driver first appeared in +.Fx 14.0 . +.Sh AUTHORS +.An -nosplit +The +.Nm +was originally written by +.An Intel Corporation +and converted to the +.Xr iflib 4 +framework by +.An Netgate . diff --git a/sys/amd64/conf/GENERIC b/sys/amd64/conf/GENERIC index f16247e68137..f9e578a56902 100644 --- a/sys/amd64/conf/GENERIC +++ b/sys/amd64/conf/GENERIC @@ -234,6 +234,7 @@ device puc # Multi I/O cards and multi-channel UARTs # PCI/PCI-X/PCIe Ethernet NICs that use iflib infrastructure device iflib device em # Intel PRO/1000 Gigabit Ethernet Family +device igc # Intel I225 2.5G Ethernet device ix # Intel PRO/10GbE PCIE PF Ethernet device ixv # Intel PRO/10GbE PCIE VF Ethernet device ixl # Intel 700 Series Physical Function diff --git a/sys/amd64/conf/NOTES b/sys/amd64/conf/NOTES index 1b949fc24c8e..a3cb84698748 100644 --- a/sys/amd64/conf/NOTES +++ b/sys/amd64/conf/NOTES @@ -294,6 +294,7 @@ device cpufreq # adapters. # ice: Intel 800 Series Physical Function # Requires the ice_ddp module for full functionality +# igc: Intel I225 2.5Gb Ethernet adapter # ipw: Intel PRO/Wireless 2100 IEEE 802.11 adapter # Requires the ipw firmware module # iwi: Intel PRO/Wireless 2200BG/2225BG/2915ABG IEEE 802.11 adapters @@ -314,6 +315,7 @@ device bxe # Broadcom NetXtreme II BCM5771X/BCM578XX 10GbE options ED_3C503 options ED_HPP options ED_SIC +device igc # Intel I225 2.5G Ethernet device ipw # Intel 2100 wireless NICs. device iwi # Intel 2200BG/2225BG/2915ABG wireless NICs. device iwn # Intel 4965/1000/5000/6000 wireless NICs. diff --git a/sys/conf/files b/sys/conf/files index b0f313bb39de..5f6ec9a5c546 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1888,6 +1888,14 @@ dev/iicbus/gpio/tca6416.c optional tca6416 fdt dev/iir/iir.c optional iir dev/iir/iir_ctrl.c optional iir dev/iir/iir_pci.c optional iir pci +dev/igc/if_igc.c optional igc iflib pci +dev/igc/igc_api.c optional igc iflib pci +dev/igc/igc_base.c optional igc iflib pci +dev/igc/igc_i225.c optional igc iflib pci +dev/igc/igc_mac.c optional igc iflib pci +dev/igc/igc_nvm.c optional igc iflib pci +dev/igc/igc_phy.c optional igc iflib pci +dev/igc/igc_txrx.c optional igc iflib pci dev/intpm/intpm.c optional intpm pci # XXX Work around clang warning, until maintainer approves fix. dev/ips/ips.c optional ips \ diff --git a/sys/dev/igc/if_igc.c b/sys/dev/igc/if_igc.c new file mode 100644 index 000000000000..6d94a7c223c7 --- /dev/null +++ b/sys/dev/igc/if_igc.c @@ -0,0 +1,2984 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2016 Nicole Graziano + * All rights reserved. + * Copyright (c) 2021 Rubicon Communications, LLC (Netgate) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include "if_igc.h" +#include +#include + +#ifdef RSS +#include +#include +#endif + +/********************************************************************* + * PCI Device ID Table + * + * Used by probe to select devices to load on + * Last entry must be all 0s + * + * { Vendor ID, Device ID, String } + *********************************************************************/ + +static pci_vendor_info_t igc_vendor_info_array[] = +{ + /* Intel(R) PRO/1000 Network Connection - igc */ + PVID(0x8086, IGC_DEV_ID_I225_LM, "Intel(R) Ethernet Controller I225-LM"), + PVID(0x8086, IGC_DEV_ID_I225_V, "Intel(R) Ethernet Controller I225-V"), + PVID(0x8086, IGC_DEV_ID_I225_K, "Intel(R) Ethernet Controller I225-K"), + PVID(0x8086, IGC_DEV_ID_I225_I, "Intel(R) Ethernet Controller I225-I"), + PVID(0x8086, IGC_DEV_ID_I220_V, "Intel(R) Ethernet Controller I220-V"), + PVID(0x8086, IGC_DEV_ID_I225_K2, "Intel(R) Ethernet Controller I225-K(2)"), + PVID(0x8086, IGC_DEV_ID_I225_LMVP, "Intel(R) Ethernet Controller I225-LMvP(2)"), + PVID(0x8086, IGC_DEV_ID_I226_K, "Intel(R) Ethernet Controller I226-K"), + PVID(0x8086, IGC_DEV_ID_I225_IT, "Intel(R) Ethernet Controller I225-IT(2)"), + PVID(0x8086, IGC_DEV_ID_I226_LM, "Intel(R) Ethernet Controller I226-LM"), + PVID(0x8086, IGC_DEV_ID_I226_V, "Intel(R) Ethernet Controller I226-V"), + PVID(0x8086, IGC_DEV_ID_I226_IT, "Intel(R) Ethernet Controller I226-IT"), + PVID(0x8086, IGC_DEV_ID_I221_V, "Intel(R) Ethernet Controller I221-V"), + PVID(0x8086, IGC_DEV_ID_I226_BLANK_NVM, "Intel(R) Ethernet Controller I226(blankNVM)"), + PVID(0x8086, IGC_DEV_ID_I225_BLANK_NVM, "Intel(R) Ethernet Controller I225(blankNVM)"), + /* required last entry */ + PVID_END +}; + +/********************************************************************* + * Function prototypes + *********************************************************************/ +static void *igc_register(device_t dev); +static int igc_if_attach_pre(if_ctx_t ctx); +static int igc_if_attach_post(if_ctx_t ctx); +static int igc_if_detach(if_ctx_t ctx); +static int igc_if_shutdown(if_ctx_t ctx); +static int igc_if_suspend(if_ctx_t ctx); +static int igc_if_resume(if_ctx_t ctx); + +static int igc_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int ntxqs, int ntxqsets); +static int igc_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int nrxqs, int nrxqsets); +static void igc_if_queues_free(if_ctx_t ctx); + +static uint64_t igc_if_get_counter(if_ctx_t, ift_counter); +static void igc_if_init(if_ctx_t ctx); +static void igc_if_stop(if_ctx_t ctx); +static void igc_if_media_status(if_ctx_t, struct ifmediareq *); +static int igc_if_media_change(if_ctx_t ctx); +static int igc_if_mtu_set(if_ctx_t ctx, uint32_t mtu); +static void igc_if_timer(if_ctx_t ctx, uint16_t qid); +static void igc_if_vlan_register(if_ctx_t ctx, u16 vtag); +static void igc_if_vlan_unregister(if_ctx_t ctx, u16 vtag); +static void igc_if_watchdog_reset(if_ctx_t ctx); +static bool igc_if_needs_restart(if_ctx_t ctx, enum iflib_restart_event event); + +static void igc_identify_hardware(if_ctx_t ctx); +static int igc_allocate_pci_resources(if_ctx_t ctx); +static void igc_free_pci_resources(if_ctx_t ctx); +static void igc_reset(if_ctx_t ctx); +static int igc_setup_interface(if_ctx_t ctx); +static int igc_setup_msix(if_ctx_t ctx); + +static void igc_initialize_transmit_unit(if_ctx_t ctx); +static void igc_initialize_receive_unit(if_ctx_t ctx); + +static void igc_if_intr_enable(if_ctx_t ctx); +static void igc_if_intr_disable(if_ctx_t ctx); +static int igc_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t rxqid); +static int igc_if_tx_queue_intr_enable(if_ctx_t ctx, uint16_t txqid); +static void igc_if_multi_set(if_ctx_t ctx); +static void igc_if_update_admin_status(if_ctx_t ctx); +static void igc_if_debug(if_ctx_t ctx); +static void igc_update_stats_counters(struct igc_adapter *); +static void igc_add_hw_stats(struct igc_adapter *adapter); +static int igc_if_set_promisc(if_ctx_t ctx, int flags); +static void igc_setup_vlan_hw_support(struct igc_adapter *); +static int igc_sysctl_nvm_info(SYSCTL_HANDLER_ARGS); +static void igc_print_nvm_info(struct igc_adapter *); +static int igc_sysctl_debug_info(SYSCTL_HANDLER_ARGS); +static int igc_get_rs(SYSCTL_HANDLER_ARGS); +static void igc_print_debug_info(struct igc_adapter *); +static int igc_is_valid_ether_addr(u8 *); +static int igc_sysctl_int_delay(SYSCTL_HANDLER_ARGS); +static void igc_add_int_delay_sysctl(struct igc_adapter *, const char *, + const char *, struct igc_int_delay_info *, int, int); +/* Management and WOL Support */ +static void igc_get_hw_control(struct igc_adapter *); +static void igc_release_hw_control(struct igc_adapter *); +static void igc_get_wakeup(if_ctx_t ctx); +static void igc_enable_wakeup(if_ctx_t ctx); + +int igc_intr(void *arg); + +/* MSI-X handlers */ +static int igc_if_msix_intr_assign(if_ctx_t, int); +static int igc_msix_link(void *); +static void igc_handle_link(void *context); + +static int igc_set_flowcntl(SYSCTL_HANDLER_ARGS); +static int igc_sysctl_eee(SYSCTL_HANDLER_ARGS); + +static int igc_get_regs(SYSCTL_HANDLER_ARGS); + +static void igc_configure_queues(struct igc_adapter *adapter); + + +/********************************************************************* + * FreeBSD Device Interface Entry Points + *********************************************************************/ +static device_method_t igc_methods[] = { + /* Device interface */ + DEVMETHOD(device_register, igc_register), + DEVMETHOD(device_probe, iflib_device_probe), + DEVMETHOD(device_attach, iflib_device_attach), + DEVMETHOD(device_detach, iflib_device_detach), + DEVMETHOD(device_shutdown, iflib_device_shutdown), + DEVMETHOD(device_suspend, iflib_device_suspend), + DEVMETHOD(device_resume, iflib_device_resume), + DEVMETHOD_END +}; + +static driver_t igc_driver = { + "igc", igc_methods, sizeof(struct igc_adapter), +}; + +static devclass_t igc_devclass; +DRIVER_MODULE(igc, pci, igc_driver, igc_devclass, 0, 0); + +MODULE_DEPEND(igc, pci, 1, 1, 1); +MODULE_DEPEND(igc, ether, 1, 1, 1); +MODULE_DEPEND(igc, iflib, 1, 1, 1); + +IFLIB_PNP_INFO(pci, igc, igc_vendor_info_array); + +static device_method_t igc_if_methods[] = { + DEVMETHOD(ifdi_attach_pre, igc_if_attach_pre), + DEVMETHOD(ifdi_attach_post, igc_if_attach_post), + DEVMETHOD(ifdi_detach, igc_if_detach), + DEVMETHOD(ifdi_shutdown, igc_if_shutdown), + DEVMETHOD(ifdi_suspend, igc_if_suspend), + DEVMETHOD(ifdi_resume, igc_if_resume), + DEVMETHOD(ifdi_init, igc_if_init), + DEVMETHOD(ifdi_stop, igc_if_stop), + DEVMETHOD(ifdi_msix_intr_assign, igc_if_msix_intr_assign), + DEVMETHOD(ifdi_intr_enable, igc_if_intr_enable), + DEVMETHOD(ifdi_intr_disable, igc_if_intr_disable), + DEVMETHOD(ifdi_tx_queues_alloc, igc_if_tx_queues_alloc), + DEVMETHOD(ifdi_rx_queues_alloc, igc_if_rx_queues_alloc), + DEVMETHOD(ifdi_queues_free, igc_if_queues_free), + DEVMETHOD(ifdi_update_admin_status, igc_if_update_admin_status), + DEVMETHOD(ifdi_multi_set, igc_if_multi_set), + DEVMETHOD(ifdi_media_status, igc_if_media_status), + DEVMETHOD(ifdi_media_change, igc_if_media_change), + DEVMETHOD(ifdi_mtu_set, igc_if_mtu_set), + DEVMETHOD(ifdi_promisc_set, igc_if_set_promisc), + DEVMETHOD(ifdi_timer, igc_if_timer), + DEVMETHOD(ifdi_watchdog_reset, igc_if_watchdog_reset), + DEVMETHOD(ifdi_vlan_register, igc_if_vlan_register), + DEVMETHOD(ifdi_vlan_unregister, igc_if_vlan_unregister), + DEVMETHOD(ifdi_get_counter, igc_if_get_counter), + DEVMETHOD(ifdi_rx_queue_intr_enable, igc_if_rx_queue_intr_enable), + DEVMETHOD(ifdi_tx_queue_intr_enable, igc_if_tx_queue_intr_enable), + DEVMETHOD(ifdi_debug, igc_if_debug), + DEVMETHOD(ifdi_needs_restart, igc_if_needs_restart), + DEVMETHOD_END +}; + +static driver_t igc_if_driver = { + "igc_if", igc_if_methods, sizeof(struct igc_adapter) +}; + +/********************************************************************* + * Tunable default values. + *********************************************************************/ + +#define IGC_TICKS_TO_USECS(ticks) ((1024 * (ticks) + 500) / 1000) +#define IGC_USECS_TO_TICKS(usecs) ((1000 * (usecs) + 512) / 1024) + +#define MAX_INTS_PER_SEC 8000 +#define DEFAULT_ITR (1000000000/(MAX_INTS_PER_SEC * 256)) + +/* Allow common code without TSO */ +#ifndef CSUM_TSO +#define CSUM_TSO 0 +#endif + +static SYSCTL_NODE(_hw, OID_AUTO, igc, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, + "igc driver parameters"); + +static int igc_disable_crc_stripping = 0; +SYSCTL_INT(_hw_igc, OID_AUTO, disable_crc_stripping, CTLFLAG_RDTUN, + &igc_disable_crc_stripping, 0, "Disable CRC Stripping"); + +static int igc_tx_int_delay_dflt = IGC_TICKS_TO_USECS(IGC_TIDV_VAL); +static int igc_rx_int_delay_dflt = IGC_TICKS_TO_USECS(IGC_RDTR_VAL); +SYSCTL_INT(_hw_igc, OID_AUTO, tx_int_delay, CTLFLAG_RDTUN, &igc_tx_int_delay_dflt, + 0, "Default transmit interrupt delay in usecs"); +SYSCTL_INT(_hw_igc, OID_AUTO, rx_int_delay, CTLFLAG_RDTUN, &igc_rx_int_delay_dflt, + 0, "Default receive interrupt delay in usecs"); + +static int igc_tx_abs_int_delay_dflt = IGC_TICKS_TO_USECS(IGC_TADV_VAL); +static int igc_rx_abs_int_delay_dflt = IGC_TICKS_TO_USECS(IGC_RADV_VAL); +SYSCTL_INT(_hw_igc, OID_AUTO, tx_abs_int_delay, CTLFLAG_RDTUN, + &igc_tx_abs_int_delay_dflt, 0, + "Default transmit interrupt delay limit in usecs"); +SYSCTL_INT(_hw_igc, OID_AUTO, rx_abs_int_delay, CTLFLAG_RDTUN, + &igc_rx_abs_int_delay_dflt, 0, + "Default receive interrupt delay limit in usecs"); + +static int igc_smart_pwr_down = false; +SYSCTL_INT(_hw_igc, OID_AUTO, smart_pwr_down, CTLFLAG_RDTUN, &igc_smart_pwr_down, + 0, "Set to true to leave smart power down enabled on newer adapters"); + +/* Controls whether promiscuous also shows bad packets */ +static int igc_debug_sbp = true; +SYSCTL_INT(_hw_igc, OID_AUTO, sbp, CTLFLAG_RDTUN, &igc_debug_sbp, 0, + "Show bad packets in promiscuous mode"); + +/* How many packets rxeof tries to clean at a time */ +static int igc_rx_process_limit = 100; +SYSCTL_INT(_hw_igc, OID_AUTO, rx_process_limit, CTLFLAG_RDTUN, + &igc_rx_process_limit, 0, + "Maximum number of received packets to process " + "at a time, -1 means unlimited"); + +/* Energy efficient ethernet - default to OFF */ +static int igc_eee_setting = 1; +SYSCTL_INT(_hw_igc, OID_AUTO, eee_setting, CTLFLAG_RDTUN, &igc_eee_setting, 0, + "Enable Energy Efficient Ethernet"); + +/* +** Tuneable Interrupt rate +*/ +static int igc_max_interrupt_rate = 8000; +SYSCTL_INT(_hw_igc, OID_AUTO, max_interrupt_rate, CTLFLAG_RDTUN, + &igc_max_interrupt_rate, 0, "Maximum interrupts per second"); + +extern struct if_txrx igc_txrx; + +static struct if_shared_ctx igc_sctx_init = { + .isc_magic = IFLIB_MAGIC, + .isc_q_align = PAGE_SIZE, + .isc_tx_maxsize = IGC_TSO_SIZE + sizeof(struct ether_vlan_header), + .isc_tx_maxsegsize = PAGE_SIZE, + .isc_tso_maxsize = IGC_TSO_SIZE + sizeof(struct ether_vlan_header), + .isc_tso_maxsegsize = IGC_TSO_SEG_SIZE, + .isc_rx_maxsize = MAX_JUMBO_FRAME_SIZE, + .isc_rx_nsegments = 1, + .isc_rx_maxsegsize = MJUM9BYTES, + .isc_nfl = 1, + .isc_nrxqs = 1, + .isc_ntxqs = 1, + .isc_admin_intrcnt = 1, + .isc_vendor_info = igc_vendor_info_array, + .isc_driver_version = "1", + .isc_driver = &igc_if_driver, + .isc_flags = IFLIB_NEED_SCRATCH | IFLIB_TSO_INIT_IP | IFLIB_NEED_ZERO_CSUM, + + .isc_nrxd_min = {IGC_MIN_RXD}, + .isc_ntxd_min = {IGC_MIN_TXD}, + .isc_nrxd_max = {IGC_MAX_RXD}, + .isc_ntxd_max = {IGC_MAX_TXD}, + .isc_nrxd_default = {IGC_DEFAULT_RXD}, + .isc_ntxd_default = {IGC_DEFAULT_TXD}, +}; + +/***************************************************************** + * + * Dump Registers + * + ****************************************************************/ +#define IGC_REGS_LEN 739 + +static int igc_get_regs(SYSCTL_HANDLER_ARGS) +{ + struct igc_adapter *adapter = (struct igc_adapter *)arg1; + struct igc_hw *hw = &adapter->hw; + struct sbuf *sb; + u32 *regs_buff; + int rc; + + regs_buff = malloc(sizeof(u32) * IGC_REGS_LEN, M_DEVBUF, M_WAITOK); + memset(regs_buff, 0, IGC_REGS_LEN * sizeof(u32)); + + rc = sysctl_wire_old_buffer(req, 0); + MPASS(rc == 0); + if (rc != 0) { + free(regs_buff, M_DEVBUF); + return (rc); + } + + sb = sbuf_new_for_sysctl(NULL, NULL, 32*400, req); + MPASS(sb != NULL); + if (sb == NULL) { + free(regs_buff, M_DEVBUF); + return (ENOMEM); + } + + /* General Registers */ + regs_buff[0] = IGC_READ_REG(hw, IGC_CTRL); + regs_buff[1] = IGC_READ_REG(hw, IGC_STATUS); + regs_buff[2] = IGC_READ_REG(hw, IGC_CTRL_EXT); + regs_buff[3] = IGC_READ_REG(hw, IGC_ICR); + regs_buff[4] = IGC_READ_REG(hw, IGC_RCTL); + regs_buff[5] = IGC_READ_REG(hw, IGC_RDLEN(0)); + regs_buff[6] = IGC_READ_REG(hw, IGC_RDH(0)); + regs_buff[7] = IGC_READ_REG(hw, IGC_RDT(0)); + regs_buff[8] = IGC_READ_REG(hw, IGC_RXDCTL(0)); + regs_buff[9] = IGC_READ_REG(hw, IGC_RDBAL(0)); + regs_buff[10] = IGC_READ_REG(hw, IGC_RDBAH(0)); + regs_buff[11] = IGC_READ_REG(hw, IGC_TCTL); + regs_buff[12] = IGC_READ_REG(hw, IGC_TDBAL(0)); + regs_buff[13] = IGC_READ_REG(hw, IGC_TDBAH(0)); + regs_buff[14] = IGC_READ_REG(hw, IGC_TDLEN(0)); + regs_buff[15] = IGC_READ_REG(hw, IGC_TDH(0)); + regs_buff[16] = IGC_READ_REG(hw, IGC_TDT(0)); + regs_buff[17] = IGC_READ_REG(hw, IGC_TXDCTL(0)); + + sbuf_printf(sb, "General Registers\n"); + sbuf_printf(sb, "\tCTRL\t %08x\n", regs_buff[0]); + sbuf_printf(sb, "\tSTATUS\t %08x\n", regs_buff[1]); + sbuf_printf(sb, "\tCTRL_EXIT\t %08x\n\n", regs_buff[2]); + + sbuf_printf(sb, "Interrupt Registers\n"); + sbuf_printf(sb, "\tICR\t %08x\n\n", regs_buff[3]); + + sbuf_printf(sb, "RX Registers\n"); + sbuf_printf(sb, "\tRCTL\t %08x\n", regs_buff[4]); + sbuf_printf(sb, "\tRDLEN\t %08x\n", regs_buff[5]); + sbuf_printf(sb, "\tRDH\t %08x\n", regs_buff[6]); + sbuf_printf(sb, "\tRDT\t %08x\n", regs_buff[7]); + sbuf_printf(sb, "\tRXDCTL\t %08x\n", regs_buff[8]); + sbuf_printf(sb, "\tRDBAL\t %08x\n", regs_buff[9]); + sbuf_printf(sb, "\tRDBAH\t %08x\n\n", regs_buff[10]); + + sbuf_printf(sb, "TX Registers\n"); + sbuf_printf(sb, "\tTCTL\t %08x\n", regs_buff[11]); + sbuf_printf(sb, "\tTDBAL\t %08x\n", regs_buff[12]); + sbuf_printf(sb, "\tTDBAH\t %08x\n", regs_buff[13]); + sbuf_printf(sb, "\tTDLEN\t %08x\n", regs_buff[14]); + sbuf_printf(sb, "\tTDH\t %08x\n", regs_buff[15]); + sbuf_printf(sb, "\tTDT\t %08x\n", regs_buff[16]); + sbuf_printf(sb, "\tTXDCTL\t %08x\n", regs_buff[17]); + sbuf_printf(sb, "\tTDFH\t %08x\n", regs_buff[18]); + sbuf_printf(sb, "\tTDFT\t %08x\n", regs_buff[19]); + sbuf_printf(sb, "\tTDFHS\t %08x\n", regs_buff[20]); + sbuf_printf(sb, "\tTDFPC\t %08x\n\n", regs_buff[21]); + + free(regs_buff, M_DEVBUF); + +#ifdef DUMP_DESCS + { + if_softc_ctx_t scctx = adapter->shared; + struct rx_ring *rxr = &rx_que->rxr; + struct tx_ring *txr = &tx_que->txr; + int ntxd = scctx->isc_ntxd[0]; + int nrxd = scctx->isc_nrxd[0]; + int j; + + for (j = 0; j < nrxd; j++) { + u32 staterr = le32toh(rxr->rx_base[j].wb.upper.status_error); + u32 length = le32toh(rxr->rx_base[j].wb.upper.length); + sbuf_printf(sb, "\tReceive Descriptor Address %d: %08" PRIx64 " Error:%d Length:%d\n", j, rxr->rx_base[j].read.buffer_addr, staterr, length); + } + + for (j = 0; j < min(ntxd, 256); j++) { + unsigned int *ptr = (unsigned int *)&txr->tx_base[j]; + + sbuf_printf(sb, "\tTXD[%03d] [0]: %08x [1]: %08x [2]: %08x [3]: %08x eop: %d DD=%d\n", + j, ptr[0], ptr[1], ptr[2], ptr[3], buf->eop, + buf->eop != -1 ? txr->tx_base[buf->eop].upper.fields.status & IGC_TXD_STAT_DD : 0); + + } + } +#endif + + rc = sbuf_finish(sb); + sbuf_delete(sb); + return(rc); +} + +static void * +igc_register(device_t dev) +{ + return (&igc_sctx_init); +} + +static int +igc_set_num_queues(if_ctx_t ctx) +{ + int maxqueues; + + maxqueues = 4; + + return (maxqueues); +} + +#define IGC_CAPS \ + IFCAP_HWCSUM | IFCAP_VLAN_MTU | IFCAP_VLAN_HWTAGGING | \ + IFCAP_VLAN_HWCSUM | IFCAP_WOL | IFCAP_VLAN_HWFILTER | IFCAP_TSO4 | \ + IFCAP_LRO | IFCAP_VLAN_HWTSO | IFCAP_JUMBO_MTU | IFCAP_HWCSUM_IPV6 |\ + IFCAP_TSO6 + +/********************************************************************* + * Device initialization routine + * + * The attach entry point is called when the driver is being loaded. + * This routine identifies the type of hardware, allocates all resources + * and initializes the hardware. + * + * return 0 on success, positive on failure + *********************************************************************/ +static int +igc_if_attach_pre(if_ctx_t ctx) +{ + struct igc_adapter *adapter; + if_softc_ctx_t scctx; + device_t dev; + struct igc_hw *hw; + int error = 0; + + INIT_DEBUGOUT("igc_if_attach_pre: begin"); + dev = iflib_get_dev(ctx); + adapter = iflib_get_softc(ctx); + + adapter->ctx = adapter->osdep.ctx = ctx; + adapter->dev = adapter->osdep.dev = dev; + scctx = adapter->shared = iflib_get_softc_ctx(ctx); + adapter->media = iflib_get_media(ctx); + hw = &adapter->hw; + + adapter->tx_process_limit = scctx->isc_ntxd[0]; + + /* SYSCTL stuff */ + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "nvm", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, + adapter, 0, igc_sysctl_nvm_info, "I", "NVM Information"); + + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "debug", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, + adapter, 0, igc_sysctl_debug_info, "I", "Debug Information"); + + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "fc", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, + adapter, 0, igc_set_flowcntl, "I", "Flow Control"); + + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "reg_dump", + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NEEDGIANT, adapter, 0, + igc_get_regs, "A", "Dump Registers"); + + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "rs_dump", + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, adapter, 0, + igc_get_rs, "I", "Dump RS indexes"); + + /* Determine hardware and mac info */ + igc_identify_hardware(ctx); + + scctx->isc_tx_nsegments = IGC_MAX_SCATTER; + scctx->isc_nrxqsets_max = scctx->isc_ntxqsets_max = igc_set_num_queues(ctx); + if (bootverbose) + device_printf(dev, "attach_pre capping queues at %d\n", + scctx->isc_ntxqsets_max); + + scctx->isc_txqsizes[0] = roundup2(scctx->isc_ntxd[0] * sizeof(union igc_adv_tx_desc), IGC_DBA_ALIGN); + scctx->isc_rxqsizes[0] = roundup2(scctx->isc_nrxd[0] * sizeof(union igc_adv_rx_desc), IGC_DBA_ALIGN); + scctx->isc_txd_size[0] = sizeof(union igc_adv_tx_desc); + scctx->isc_rxd_size[0] = sizeof(union igc_adv_rx_desc); + scctx->isc_txrx = &igc_txrx; + scctx->isc_tx_tso_segments_max = IGC_MAX_SCATTER; + scctx->isc_tx_tso_size_max = IGC_TSO_SIZE; + scctx->isc_tx_tso_segsize_max = IGC_TSO_SEG_SIZE; + scctx->isc_capabilities = scctx->isc_capenable = IGC_CAPS; + scctx->isc_tx_csum_flags = CSUM_TCP | CSUM_UDP | CSUM_TSO | + CSUM_IP6_TCP | CSUM_IP6_UDP | CSUM_SCTP | CSUM_IP6_SCTP; + + /* + ** Some new devices, as with ixgbe, now may + ** use a different BAR, so we need to keep + ** track of which is used. + */ + scctx->isc_msix_bar = PCIR_BAR(IGC_MSIX_BAR); + if (pci_read_config(dev, scctx->isc_msix_bar, 4) == 0) + scctx->isc_msix_bar += 4; + + /* Setup PCI resources */ + if (igc_allocate_pci_resources(ctx)) { + device_printf(dev, "Allocation of PCI resources failed\n"); + error = ENXIO; + goto err_pci; + } + + /* Do Shared Code initialization */ + error = igc_setup_init_funcs(hw, true); + if (error) { + device_printf(dev, "Setup of Shared code failed, error %d\n", + error); + error = ENXIO; + goto err_pci; + } + + igc_setup_msix(ctx); + igc_get_bus_info(hw); + + /* Set up some sysctls for the tunable interrupt delays */ + igc_add_int_delay_sysctl(adapter, "rx_int_delay", + "receive interrupt delay in usecs", &adapter->rx_int_delay, + IGC_REGISTER(hw, IGC_RDTR), igc_rx_int_delay_dflt); + igc_add_int_delay_sysctl(adapter, "tx_int_delay", + "transmit interrupt delay in usecs", &adapter->tx_int_delay, + IGC_REGISTER(hw, IGC_TIDV), igc_tx_int_delay_dflt); + igc_add_int_delay_sysctl(adapter, "rx_abs_int_delay", + "receive interrupt delay limit in usecs", + &adapter->rx_abs_int_delay, + IGC_REGISTER(hw, IGC_RADV), + igc_rx_abs_int_delay_dflt); + igc_add_int_delay_sysctl(adapter, "tx_abs_int_delay", + "transmit interrupt delay limit in usecs", + &adapter->tx_abs_int_delay, + IGC_REGISTER(hw, IGC_TADV), + igc_tx_abs_int_delay_dflt); + igc_add_int_delay_sysctl(adapter, "itr", + "interrupt delay limit in usecs/4", + &adapter->tx_itr, + IGC_REGISTER(hw, IGC_ITR), + DEFAULT_ITR); + + hw->mac.autoneg = DO_AUTO_NEG; + hw->phy.autoneg_wait_to_complete = false; + hw->phy.autoneg_advertised = AUTONEG_ADV_DEFAULT; + + /* Copper options */ + if (hw->phy.media_type == igc_media_type_copper) { + hw->phy.mdix = AUTO_ALL_MODES; + } + + /* + * Set the frame limits assuming + * standard ethernet sized frames. + */ + scctx->isc_max_frame_size = adapter->hw.mac.max_frame_size = + ETHERMTU + ETHER_HDR_LEN + ETHERNET_FCS_SIZE; + + /* Allocate multicast array memory. */ + adapter->mta = malloc(sizeof(u8) * ETHER_ADDR_LEN * + MAX_NUM_MULTICAST_ADDRESSES, M_DEVBUF, M_NOWAIT); + if (adapter->mta == NULL) { + device_printf(dev, "Can not allocate multicast setup array\n"); + error = ENOMEM; + goto err_late; + } + + /* Check SOL/IDER usage */ + if (igc_check_reset_block(hw)) + device_printf(dev, "PHY reset is blocked" + " due to SOL/IDER session.\n"); + + /* Sysctl for setting Energy Efficient Ethernet */ + adapter->hw.dev_spec._i225.eee_disable = igc_eee_setting; + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "eee_control", + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, + adapter, 0, igc_sysctl_eee, "I", + "Disable Energy Efficient Ethernet"); + + /* + ** Start from a known state, this is + ** important in reading the nvm and + ** mac from that. + */ + igc_reset_hw(hw); + + /* Make sure we have a good EEPROM before we read from it */ + if (igc_validate_nvm_checksum(hw) < 0) { + /* + ** Some PCI-E parts fail the first check due to + ** the link being in sleep state, call it again, + ** if it fails a second time its a real issue. + */ + if (igc_validate_nvm_checksum(hw) < 0) { + device_printf(dev, + "The EEPROM Checksum Is Not Valid\n"); + error = EIO; + goto err_late; + } + } + + /* Copy the permanent MAC address out of the EEPROM */ + if (igc_read_mac_addr(hw) < 0) { + device_printf(dev, "EEPROM read error while reading MAC" + " address\n"); + error = EIO; + goto err_late; + } + + if (!igc_is_valid_ether_addr(hw->mac.addr)) { + device_printf(dev, "Invalid MAC address\n"); + error = EIO; + goto err_late; + } + + /* + * Get Wake-on-Lan and Management info for later use + */ + igc_get_wakeup(ctx); + + /* Enable only WOL MAGIC by default */ + scctx->isc_capenable &= ~IFCAP_WOL; + if (adapter->wol != 0) + scctx->isc_capenable |= IFCAP_WOL_MAGIC; + + iflib_set_mac(ctx, hw->mac.addr); + + return (0); + +err_late: + igc_release_hw_control(adapter); +err_pci: + igc_free_pci_resources(ctx); + free(adapter->mta, M_DEVBUF); + + return (error); +} + +static int +igc_if_attach_post(if_ctx_t ctx) +{ + struct igc_adapter *adapter = iflib_get_softc(ctx); + struct igc_hw *hw = &adapter->hw; *** 11493 LINES SKIPPED *** From owner-dev-commits-src-branches@freebsd.org Sun Aug 15 19:25:49 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6B02E664D3D; Sun, 15 Aug 2021 19:25:49 +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 4GnnMK2MPJz3vQv; Sun, 15 Aug 2021 19:25:49 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 392D31BD02; Sun, 15 Aug 2021 19:25:49 +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 17FJPnBu072505; Sun, 15 Aug 2021 19:25:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17FJPn5Q072504; Sun, 15 Aug 2021 19:25:49 GMT (envelope-from git) Date: Sun, 15 Aug 2021 19:25:49 GMT Message-Id: <202108151925.17FJPn5Q072504@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kevin Bowling Subject: git: 2257c7810cc5 - stable/13 - igc: sync igc_txrx with igb(4) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2257c7810cc5be6cc294e695471fa588c60870b9 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2021 19:25:49 -0000 The branch stable/13 has been updated by kbowling (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=2257c7810cc5be6cc294e695471fa588c60870b9 commit 2257c7810cc5be6cc294e695471fa588c60870b9 Author: Kevin Bowling AuthorDate: 2021-07-31 15:00:16 +0000 Commit: Kevin Bowling CommitDate: 2021-08-15 19:25:16 +0000 igc: sync igc_txrx with igb(4) Reviewed by: grehan MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D31227 (cherry picked from commit d02e436353d292e6fd50f70ea80507095543764e) --- sys/dev/igc/igc_txrx.c | 92 +++++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/sys/dev/igc/igc_txrx.c b/sys/dev/igc/igc_txrx.c index 2636aa77069a..ee4d5a5c0c6b 100644 --- a/sys/dev/igc/igc_txrx.c +++ b/sys/dev/igc/igc_txrx.c @@ -52,16 +52,20 @@ static int igc_isc_txd_credits_update(void *arg, uint16_t txqid, bool clear); static void igc_isc_rxd_refill(void *arg, if_rxd_update_t iru); -static void igc_isc_rxd_flush(void *arg, uint16_t rxqid, uint8_t flid __unused, qidx_t pidx); -static int igc_isc_rxd_available(void *arg, uint16_t rxqid, qidx_t idx, qidx_t budget); +static void igc_isc_rxd_flush(void *arg, uint16_t rxqid, uint8_t flid __unused, + qidx_t pidx); +static int igc_isc_rxd_available(void *arg, uint16_t rxqid, qidx_t idx, + qidx_t budget); static int igc_isc_rxd_pkt_get(void *arg, if_rxd_info_t ri); -static int igc_tx_ctx_setup(struct tx_ring *txr, if_pkt_info_t pi, u32 *cmd_type_len, u32 *olinfo_status); -static int igc_tso_setup(struct tx_ring *txr, if_pkt_info_t pi, u32 *cmd_type_len, u32 *olinfo_status); +static int igc_tx_ctx_setup(struct tx_ring *txr, if_pkt_info_t pi, + uint32_t *cmd_type_len, uint32_t *olinfo_status); +static int igc_tso_setup(struct tx_ring *txr, if_pkt_info_t pi, + uint32_t *cmd_type_len, uint32_t *olinfo_status); -static void igc_rx_checksum(u32 staterr, if_rxd_info_t ri, u32 ptype); -static int igc_determine_rsstype(u16 pkt_info); +static void igc_rx_checksum(uint32_t staterr, if_rxd_info_t ri, uint32_t ptype); +static int igc_determine_rsstype(uint16_t pkt_info); extern void igc_if_enable_intr(if_ctx_t ctx); extern int igc_intr(void *arg); @@ -119,12 +123,13 @@ igc_dump_rs(struct igc_adapter *adapter) * **********************************************************************/ static int -igc_tso_setup(struct tx_ring *txr, if_pkt_info_t pi, u32 *cmd_type_len, u32 *olinfo_status) +igc_tso_setup(struct tx_ring *txr, if_pkt_info_t pi, uint32_t *cmd_type_len, + uint32_t *olinfo_status) { struct igc_adv_tx_context_desc *TXD; - u32 type_tucmd_mlhl = 0, vlan_macip_lens = 0; - u32 mss_l4len_idx = 0; - u32 paylen; + uint32_t type_tucmd_mlhl = 0, vlan_macip_lens = 0; + uint32_t mss_l4len_idx = 0; + uint32_t paylen; switch(pi->ipi_etype) { case ETHERTYPE_IPV6: @@ -179,11 +184,12 @@ igc_tso_setup(struct tx_ring *txr, if_pkt_info_t pi, u32 *cmd_type_len, u32 *oli * **********************************************************************/ static int -igc_tx_ctx_setup(struct tx_ring *txr, if_pkt_info_t pi, u32 *cmd_type_len, u32 *olinfo_status) +igc_tx_ctx_setup(struct tx_ring *txr, if_pkt_info_t pi, uint32_t *cmd_type_len, + uint32_t *olinfo_status) { struct igc_adv_tx_context_desc *TXD; - u32 vlan_macip_lens, type_tucmd_mlhl; - u32 mss_l4len_idx; + uint32_t vlan_macip_lens, type_tucmd_mlhl; + uint32_t mss_l4len_idx; mss_l4len_idx = vlan_macip_lens = type_tucmd_mlhl = 0; /* First check if TSO is to be used */ @@ -242,7 +248,7 @@ igc_tx_ctx_setup(struct tx_ring *txr, if_pkt_info_t pi, u32 *cmd_type_len, u32 * type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_SCTP; *olinfo_status |= IGC_TXD_POPTS_TXSM << 8; } - break; + break; default: break; } @@ -267,7 +273,7 @@ igc_isc_txd_encap(void *arg, if_pkt_info_t pi) bus_dma_segment_t *segs = pi->ipi_segs; union igc_adv_tx_desc *txd = NULL; int i, j, pidx_last; - u32 olinfo_status, cmd_type_len, txd_flags; + uint32_t olinfo_status, cmd_type_len, txd_flags; qidx_t ntxd; pidx_last = olinfo_status = 0; @@ -422,7 +428,7 @@ igc_isc_rxd_available(void *arg, uint16_t rxqid, qidx_t idx, qidx_t budget) struct igc_rx_queue *que = &sc->rx_queues[rxqid]; struct rx_ring *rxr = &que->rxr; union igc_adv_rx_desc *rxd; - u32 staterr = 0; + uint32_t staterr = 0; int cnt, i; for (cnt = 0, i = idx; cnt < scctx->isc_nrxd[0] && cnt <= budget;) { @@ -453,16 +459,15 @@ igc_isc_rxd_pkt_get(void *arg, if_rxd_info_t ri) if_softc_ctx_t scctx = adapter->shared; struct igc_rx_queue *que = &adapter->rx_queues[ri->iri_qsidx]; struct rx_ring *rxr = &que->rxr; - struct ifnet *ifp = iflib_get_ifp(adapter->ctx); union igc_adv_rx_desc *rxd; - u16 pkt_info, len; - u16 vtag = 0; - u32 ptype; - u32 staterr = 0; + uint16_t pkt_info, len, vtag; + uint32_t ptype, staterr; + int i, cidx; bool eop; - int i = 0; - int cidx = ri->iri_cidx; + + staterr = i = vtag = 0; + cidx = ri->iri_cidx; do { rxd = (union igc_adv_rx_desc *)&rxr->rx_base[cidx]; @@ -507,14 +512,15 @@ igc_isc_rxd_pkt_get(void *arg, if_rxd_info_t ri) rxr->rx_packets++; - if ((ifp->if_capenable & IFCAP_RXCSUM) != 0) + if ((scctx->isc_capenable & IFCAP_RXCSUM) != 0) igc_rx_checksum(staterr, ri, ptype); - if ((ifp->if_capenable & IFCAP_VLAN_HWTAGGING) != 0 && + if ((scctx->isc_capenable & IFCAP_VLAN_HWTAGGING) != 0 && (staterr & IGC_RXD_STAT_VP) != 0) { ri->iri_vtag = vtag; ri->iri_flags |= M_VLANTAG; } + ri->iri_flowid = le32toh(rxd->wb.lower.hi_dword.rss); ri->iri_rsstype = igc_determine_rsstype(pkt_info); @@ -531,26 +537,34 @@ igc_isc_rxd_pkt_get(void *arg, if_rxd_info_t ri) * *********************************************************************/ static void -igc_rx_checksum(u32 staterr, if_rxd_info_t ri, u32 ptype) +igc_rx_checksum(uint32_t staterr, if_rxd_info_t ri, uint32_t ptype) { - u16 status = (u16)staterr; - u8 errors = (u8) (staterr >> 24); + uint16_t status = (uint16_t)staterr; + uint8_t errors = (uint8_t)(staterr >> 24); - /* Ignore Checksum bit is set */ - if (status & IGC_RXD_STAT_IXSM) { - ri->iri_csum_flags = 0; + if (__predict_false(status & IGC_RXD_STAT_IXSM)) return; - } - if (status & (IGC_RXD_STAT_TCPCS | IGC_RXD_STAT_UDPCS)) { - u64 type = (CSUM_DATA_VALID | CSUM_PSEUDO_HDR); - /* Did it pass? */ - if (!(errors & IGC_RXD_ERR_TCPE)) { - ri->iri_csum_flags |= type; + /* If there is a layer 3 or 4 error we are done */ + if (__predict_false(errors & (IGC_RXD_ERR_IPE | IGC_RXD_ERR_TCPE))) + return; + + /* IP Checksum Good */ + if (status & IGC_RXD_STAT_IPCS) + ri->iri_csum_flags = (CSUM_IP_CHECKED | CSUM_IP_VALID); + + /* Valid L4E checksum */ + if (__predict_true(status & + (IGC_RXD_STAT_TCPCS | IGC_RXD_STAT_UDPCS))) { + /* SCTP header present */ + if (__predict_false((ptype & IGC_RXDADV_PKTTYPE_ETQF) == 0 && + (ptype & IGC_RXDADV_PKTTYPE_SCTP) != 0)) { + ri->iri_csum_flags |= CSUM_SCTP_VALID; + } else { + ri->iri_csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR; ri->iri_csum_data = htons(0xffff); } } - return; } /******************************************************************** @@ -559,7 +573,7 @@ igc_rx_checksum(u32 staterr, if_rxd_info_t ri, u32 ptype) * ******************************************************************/ static int -igc_determine_rsstype(u16 pkt_info) +igc_determine_rsstype(uint16_t pkt_info) { switch (pkt_info & IGC_RXDADV_RSSTYPE_MASK) { case IGC_RXDADV_RSSTYPE_IPV4_TCP: From owner-dev-commits-src-branches@freebsd.org Sun Aug 15 21:03:16 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6DA42666706; Sun, 15 Aug 2021 21:03:16 +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 4GnqWm2TQbz4bCx; Sun, 15 Aug 2021 21:03:16 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 2B99F1CDE9; Sun, 15 Aug 2021 21:03:16 +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 17FL3GoA006032; Sun, 15 Aug 2021 21:03:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17FL3GnW006031; Sun, 15 Aug 2021 21:03:16 GMT (envelope-from git) Date: Sun, 15 Aug 2021 21:03:16 GMT Message-Id: <202108152103.17FL3GnW006031@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Piotrowski <0mp@FreeBSD.org> Subject: git: 5a1da25da26b - stable/13 - grep: Fix an incorrect description of the -C flag MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: 0mp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5a1da25da26ba462ea86f64c007530cfa873c5ea Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2021 21:03:16 -0000 The branch stable/13 has been updated by 0mp (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=5a1da25da26ba462ea86f64c007530cfa873c5ea commit 5a1da25da26ba462ea86f64c007530cfa873c5ea Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2021-02-05 18:38:09 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2021-08-15 21:01:01 +0000 grep: Fix an incorrect description of the -C flag It seems that the number of lines is no longer an optional parameter to the -C flag. Document it accordingly both in the manual page and the usage message. Reviewed by: yuripv Approved by: yuripv MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D28509 (cherry picked from commit be6b8b7a3a18acb3b044e144d946392fca05e5d0) --- usr.bin/grep/grep.1 | 21 +++++++++------------ usr.bin/grep/grep.c | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/usr.bin/grep/grep.1 b/usr.bin/grep/grep.1 index 338af7e6d454..5f314d0dff7c 100644 --- a/usr.bin/grep/grep.1 +++ b/usr.bin/grep/grep.1 @@ -30,7 +30,7 @@ .\" .\" @(#)grep.1 8.3 (Berkeley) 4/18/94 .\" -.Dd February 4, 2021 +.Dd April 17, 2021 .Dt GREP 1 .Os .Sh NAME @@ -45,13 +45,13 @@ .Op Fl abcdDEFGHhIiLlmnOopqRSsUVvwxz .Op Fl A Ar num .Op Fl B Ar num -.Op Fl C Ns Op Ar num +.Op Fl C Ar num .Op Fl e Ar pattern .Op Fl f Ar file .Op Fl Fl binary-files= Ns Ar value .Op Fl Fl color Ns Op Cm = Ns Ar when .Op Fl Fl colour Ns Op Cm = Ns Ar when -.Op Fl Fl context Ns Op Cm = Ns Ar num +.Op Fl Fl context= Ns Ar num .Op Fl Fl label .Op Fl Fl line-buffered .Op Fl Fl null @@ -123,18 +123,15 @@ options. .It Fl b , Fl Fl byte-offset The offset in bytes of a matched pattern is displayed in front of the respective matched line. -.It Fl C Ns Oo Ar num Oc , Fl Fl context Ns Oo = Ns Ar num Oc +.It Fl C Ar num , Fl Fl context= Ns Ar num Print .Ar num lines of leading and trailing context surrounding each match. -The default value of -.Ar num -is -.Dq 2 -and is equivalent to -.Dq Fl A Ar 2 Fl B Ar 2 . -Note: -no whitespace may be given between the option and its argument. +See also the +.Fl A +and +.Fl B +options. .It Fl c , Fl Fl count Only a count of selected lines is written to standard output. .It Fl Fl colour= Ns Oo Ar when Oc , Fl Fl color= Ns Oo Ar when Oc diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index 166d3451774a..6fbd6bee8ace 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -57,9 +57,9 @@ const char *errstr[] = { "", /* 1*/ "(standard input)", /* 2*/ "unknown %s option", -/* 3*/ "usage: %s [-abcDEFGHhIiLlmnOoPqRSsUVvwxz] [-A num] [-B num] [-C[num]]\n", +/* 3*/ "usage: %s [-abcDEFGHhIiLlmnOoPqRSsUVvwxz] [-A num] [-B num] [-C num]\n", /* 4*/ "\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n", -/* 5*/ "\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n", +/* 5*/ "\t[--context=num] [--directories=action] [--label] [--line-buffered]\n", /* 6*/ "\t[--null] [pattern] [file ...]\n", /* 7*/ "Binary file %s matches\n", /* 8*/ "%s (BSD grep, GNU compatible) %s\n", From owner-dev-commits-src-branches@freebsd.org Sun Aug 15 21:03:18 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 624816665F8; Sun, 15 Aug 2021 21:03:18 +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 4GnqWn3Hq3z4bBt; Sun, 15 Aug 2021 21:03:17 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 4DC561CFD5; Sun, 15 Aug 2021 21:03:17 +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 17FL3HQp006056; Sun, 15 Aug 2021 21:03:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17FL3Had006055; Sun, 15 Aug 2021 21:03:17 GMT (envelope-from git) Date: Sun, 15 Aug 2021 21:03:17 GMT Message-Id: <202108152103.17FL3Had006055@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Piotrowski <0mp@FreeBSD.org> Subject: git: c8faaf378709 - stable/13 - ports.7: Document DEBUG_FLAGS and the process of debugging ports MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: 0mp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c8faaf378709f4ce4661da7ca73ee88e1cc63d54 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2021 21:03:18 -0000 The branch stable/13 has been updated by 0mp (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=c8faaf378709f4ce4661da7ca73ee88e1cc63d54 commit c8faaf378709f4ce4661da7ca73ee88e1cc63d54 Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2021-04-17 20:51:54 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2021-08-15 21:02:08 +0000 ports.7: Document DEBUG_FLAGS and the process of debugging ports Loosely based on https://wiki.freebsd.org/BenWoods/DebuggingPorts. Reviewed by: crees MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D27296 (cherry picked from commit d25f7d324a9d0c33655876b920ba590918d16f4c) --- share/man/man7/ports.7 | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/share/man/man7/ports.7 b/share/man/man7/ports.7 index 1c3cce31d2f0..797fed0d3ec6 100644 --- a/share/man/man7/ports.7 +++ b/share/man/man7/ports.7 @@ -558,6 +558,13 @@ If set, debugging symbols are installed for ports binaries. .It Va WITH_DEBUG_PORTS A list of origins for which to set .Va WITH_DEBUG . +.It Va DEBUG_FLAGS +.Pq Default: Ql -g +Additional +.Va CFLAGS +to set when +.Va WITH_DEBUG +is set. .It Va WITH_CCACHE_BUILD .Pq Vt bool If set, enables the use of @@ -643,6 +650,58 @@ DISABLE_MAKE_JOBS= yes TRYBROKEN= yes \&.endif .Ed +.It Sy Example 6\&: No Debugging Ports +By default ports are built and packaged without debugging support (e.g., +debugging symbols are stripped from binaries, optimization flags are used for +compiling, verbose logging is disabled). +Whether ports are built with debugging symbols can be controlled by the +settings in +.Xr make.conf 5 , +e.g., +.Bd -literal -offset 2n +# Enable debugging for all ports. +WITH_DEBUG= yes +# Enable debugging for selected ports. +WITH_DEBUG_PORTS= mail/dovecot security/krb5 +.Ed +.Pp +It is also possible to use the debug variables on the command line: +.Bd -literal -offset 2n +.Li # Ic make -DWITH_DEBUG DEBUG_FLAGS="-g -O0" build +.Ed +.Pp +See the +.Sx MAKE VARIABLES +section to learn more about the debug variables. +.Pp +To understand the details of what happens when the debug variables are set it +is best to consult the files located at +.Pa ${PORTSDIR}/Mk/* +.Po Pa bsd.port.mk +in particular +.Pc . +.Pp +If debugging is enabled for a specific port, the ports framework will: +.Bl -bullet +.It +Add +.Va DEBUG_FLAGS +(defaults to +.Ql -g ) +to +.Va CFLAGS . +.It +Try to prevent the binaries from being stripped (including checking the install +target to replace +.Ql install-strip +with +.Ql install ) . +Whether a binary has been stripped can be checked with +.Xr file 1 . +.It +Try to enable other debugging features like debug build type or verbose logging. +However, this is port-specific and the ports framework might not be aware of +each supported debugging feature a given piece of software has to offer). .El .Sh SEE ALSO .Xr make 1 , From owner-dev-commits-src-branches@freebsd.org Sun Aug 15 21:15:53 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 25257666C0E; Sun, 15 Aug 2021 21:15:53 +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 4GnqpK0QlJz4f6H; Sun, 15 Aug 2021 21:15:53 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 EB99B1D40C; Sun, 15 Aug 2021 21:15: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 17FLFqY6020273; Sun, 15 Aug 2021 21:15:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17FLFqZe020272; Sun, 15 Aug 2021 21:15:52 GMT (envelope-from git) Date: Sun, 15 Aug 2021 21:15:52 GMT Message-Id: <202108152115.17FLFqZe020272@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Piotrowski <0mp@FreeBSD.org> Subject: git: 90146cfa3180 - stable/12 - grep: Fix an incorrect description of the -C flag MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: 0mp X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 90146cfa3180ee6f8e183f3fb31cdde2e4fc6417 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2021 21:15:53 -0000 The branch stable/12 has been updated by 0mp (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=90146cfa3180ee6f8e183f3fb31cdde2e4fc6417 commit 90146cfa3180ee6f8e183f3fb31cdde2e4fc6417 Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2021-02-05 18:38:09 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2021-08-15 21:08:29 +0000 grep: Fix an incorrect description of the -C flag It seems that the number of lines is no longer an optional parameter to the -C flag. Document it accordingly both in the manual page and the usage message. Reviewed by: yuripv Approved by: yuripv MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D28509 (cherry picked from commit be6b8b7a3a18acb3b044e144d946392fca05e5d0) --- usr.bin/grep/grep.1 | 21 +++++++++------------ usr.bin/grep/grep.c | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/usr.bin/grep/grep.1 b/usr.bin/grep/grep.1 index 9aac1cc6ca92..af3aec95cb19 100644 --- a/usr.bin/grep/grep.1 +++ b/usr.bin/grep/grep.1 @@ -30,7 +30,7 @@ .\" .\" @(#)grep.1 8.3 (Berkeley) 4/18/94 .\" -.Dd February 11, 2021 +.Dd April 17, 2021 .Dt GREP 1 .Os .Sh NAME @@ -45,13 +45,13 @@ .Op Fl abcdDEFGHhIiLlmnOopqRSsUVvwxz .Op Fl A Ar num .Op Fl B Ar num -.Op Fl C Ns Op Ar num +.Op Fl C Ar num .Op Fl e Ar pattern .Op Fl f Ar file .Op Fl Fl binary-files= Ns Ar value .Op Fl Fl color Ns Op Cm = Ns Ar when .Op Fl Fl colour Ns Op Cm = Ns Ar when -.Op Fl Fl context Ns Op Cm = Ns Ar num +.Op Fl Fl context= Ns Ar num .Op Fl Fl label .Op Fl Fl line-buffered .Op Fl Fl null @@ -123,18 +123,15 @@ options. .It Fl b , Fl Fl byte-offset The offset in bytes of a matched pattern is displayed in front of the respective matched line. -.It Fl C Ns Oo Ar num Oc , Fl Fl context Ns Oo = Ns Ar num Oc +.It Fl C Ar num , Fl Fl context= Ns Ar num Print .Ar num lines of leading and trailing context surrounding each match. -The default value of -.Ar num -is -.Dq 2 -and is equivalent to -.Dq Fl A Ar 2 Fl B Ar 2 . -Note: -no whitespace may be given between the option and its argument. +See also the +.Fl A +and +.Fl B +options. .It Fl c , Fl Fl count Only a count of selected lines is written to standard output. .It Fl Fl colour= Ns Oo Ar when Oc , Fl Fl color= Ns Oo Ar when Oc diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index a9c67c268b47..b9dc97661fd6 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -57,9 +57,9 @@ const char *errstr[] = { "", /* 1*/ "(standard input)", /* 2*/ "unknown %s option", -/* 3*/ "usage: %s [-abcDEFGHhIiLlmnOoPqRSsUVvwxz] [-A num] [-B num] [-C[num]]\n", +/* 3*/ "usage: %s [-abcDEFGHhIiLlmnOoPqRSsUVvwxz] [-A num] [-B num] [-C num]\n", /* 4*/ "\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n", -/* 5*/ "\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n", +/* 5*/ "\t[--context=num] [--directories=action] [--label] [--line-buffered]\n", /* 6*/ "\t[--null] [pattern] [file ...]\n", /* 7*/ "Binary file %s matches\n", /* 8*/ "%s (BSD grep) %s\n", From owner-dev-commits-src-branches@freebsd.org Sun Aug 15 21:19:42 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D6148666AB7; Sun, 15 Aug 2021 21:19:42 +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 4Gnqtk5YVRz4dpM; Sun, 15 Aug 2021 21:19:42 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 A313F1D2EA; Sun, 15 Aug 2021 21:19:42 +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 17FLJg1G020745; Sun, 15 Aug 2021 21:19:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17FLJgnv020744; Sun, 15 Aug 2021 21:19:42 GMT (envelope-from git) Date: Sun, 15 Aug 2021 21:19:42 GMT Message-Id: <202108152119.17FLJgnv020744@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Piotrowski <0mp@FreeBSD.org> Subject: git: 5cdee2441ed9 - stable/13 - getprogname.3: Add an example MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: 0mp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5cdee2441ed9cffca7462c88205e70bba61a4d6b Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2021 21:19:42 -0000 The branch stable/13 has been updated by 0mp (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=5cdee2441ed9cffca7462c88205e70bba61a4d6b commit 5cdee2441ed9cffca7462c88205e70bba61a4d6b Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2021-04-17 21:26:54 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2021-08-15 21:19:09 +0000 getprogname.3: Add an example It shows the difference between getprogname() and argv[0]. Reviewed by: yuripv Approved by: yuripv (src) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D27204 (cherry picked from commit 1ffdcdadf61423dd02ddad82fc4f3f6c39090c8c) --- lib/libc/gen/getprogname.3 | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/libc/gen/getprogname.3 b/lib/libc/gen/getprogname.3 index 53d39a60526b..f43a7b8c6b69 100644 --- a/lib/libc/gen/getprogname.3 +++ b/lib/libc/gen/getprogname.3 @@ -31,7 +31,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 1, 2001 +.Dd April 18, 2021 .Dt GETPROGNAME 3 .Os .Sh NAME @@ -84,6 +84,32 @@ Calling .Fn setprogname allows the aforementioned library to learn the program name without modifications to the start-up code. +.Sh EXAMPLES +The following example presents a simple program, which shows the difference +between +.Fn getprogname +and +.Va "argv[0]" . +.Bd -literal -offset indent +#include +#include + +int +main(int argc, char** argv) +{ + printf("getprogname(): %s\en", getprogname()); + printf("argv[0]: %s\en", argv[0]); + return (0); +} +.Ed +.Pp +When compiled and executed (e.g., with +.Ql ./a.out ) +the output of the program is going to look like this: +.Bd -literal -offset indent +getprogname(): a.out +argv[0]: ./a.out +.Ed .Sh SEE ALSO .Xr err 3 , .Xr setproctitle 3 From owner-dev-commits-src-branches@freebsd.org Sun Aug 15 21:20:21 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7DE57666AC6; Sun, 15 Aug 2021 21:20: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GnqvT1vNSz4f7f; Sun, 15 Aug 2021 21:20:21 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 2A4D71D3B2; Sun, 15 Aug 2021 21:20:21 +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 17FLKLgV028661; Sun, 15 Aug 2021 21:20:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17FLKLTs028655; Sun, 15 Aug 2021 21:20:21 GMT (envelope-from git) Date: Sun, 15 Aug 2021 21:20:21 GMT Message-Id: <202108152120.17FLKLTs028655@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Piotrowski <0mp@FreeBSD.org> Subject: git: 2e34e54d4bf5 - stable/12 - getprogname.3: Add an example MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: 0mp X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 2e34e54d4bf50258cbda4f14deb4863cf8fcbf65 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2021 21:20:21 -0000 The branch stable/12 has been updated by 0mp (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=2e34e54d4bf50258cbda4f14deb4863cf8fcbf65 commit 2e34e54d4bf50258cbda4f14deb4863cf8fcbf65 Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2021-04-17 21:26:54 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2021-08-15 21:20:07 +0000 getprogname.3: Add an example It shows the difference between getprogname() and argv[0]. Reviewed by: yuripv Approved by: yuripv (src) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D27204 (cherry picked from commit 1ffdcdadf61423dd02ddad82fc4f3f6c39090c8c) --- lib/libc/gen/getprogname.3 | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/libc/gen/getprogname.3 b/lib/libc/gen/getprogname.3 index 53d39a60526b..f43a7b8c6b69 100644 --- a/lib/libc/gen/getprogname.3 +++ b/lib/libc/gen/getprogname.3 @@ -31,7 +31,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 1, 2001 +.Dd April 18, 2021 .Dt GETPROGNAME 3 .Os .Sh NAME @@ -84,6 +84,32 @@ Calling .Fn setprogname allows the aforementioned library to learn the program name without modifications to the start-up code. +.Sh EXAMPLES +The following example presents a simple program, which shows the difference +between +.Fn getprogname +and +.Va "argv[0]" . +.Bd -literal -offset indent +#include +#include + +int +main(int argc, char** argv) +{ + printf("getprogname(): %s\en", getprogname()); + printf("argv[0]: %s\en", argv[0]); + return (0); +} +.Ed +.Pp +When compiled and executed (e.g., with +.Ql ./a.out ) +the output of the program is going to look like this: +.Bd -literal -offset indent +getprogname(): a.out +argv[0]: ./a.out +.Ed .Sh SEE ALSO .Xr err 3 , .Xr setproctitle 3 From owner-dev-commits-src-branches@freebsd.org Sun Aug 15 23:46:04 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5D23A668874; Sun, 15 Aug 2021 23:46:04 +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 4Gnv7c283Wz4rQ3; Sun, 15 Aug 2021 23:46:04 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 2E6151F0D0; Sun, 15 Aug 2021 23:46:04 +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 17FNk4Ev019329; Sun, 15 Aug 2021 23:46:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17FNk4FS019328; Sun, 15 Aug 2021 23:46:04 GMT (envelope-from git) Date: Sun, 15 Aug 2021 23:46:04 GMT Message-Id: <202108152346.17FNk4FS019328@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Rick Macklem Subject: git: a54cdded3d65 - stable/13 - nfscl: Cache an open stateid for the "oneopenown" mount option MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a54cdded3d6570997b8216df003767d663856533 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2021 23:46:04 -0000 The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=a54cdded3d6570997b8216df003767d663856533 commit a54cdded3d6570997b8216df003767d663856533 Author: Rick Macklem AuthorDate: 2021-07-28 22:48:27 +0000 Commit: Rick Macklem CommitDate: 2021-08-15 23:41:18 +0000 nfscl: Cache an open stateid for the "oneopenown" mount option For NFSv4.1/4.2, if the "oneopenown" mount option is used, there is, at most, only one open stateid for each NFS vnode. When an open stateid for a file is acquired, set a pointer to the open structure in the NFS vnode. This pointer can be used to acquire the open stateid without searching the open linked list when the following is true: - No delegations have been issued for the file. Since delegations can outlive an NFS vnode for a file, use the global NFSMNTP_DELEGISSUED flag on the mount to determine this. - No lock stateid has been issued for the file. To determine this, a new NFS vnode flag called NMIGHTBELOCKED is set when a lock stateid is issued, which can then be tested. When this open structure pointer can be used, it avoids the need to acquire the NFSCLSTATELOCK() and searching the open structure list for an open. The NFSCLSTATELOCK() can be highly contended when there are a lot of opens issued for the NFSv4.1/4.2 mount. This patch only affects NFSv4.1/4.2 mounts when the "oneopenown" mount option is used. (cherry picked from commit efea1bc1fd93831c29fa7594d67094e0c125fb88) --- sys/fs/nfsclient/nfs_clnode.c | 11 ++++++++--- sys/fs/nfsclient/nfs_clrpcops.c | 8 +++++++- sys/fs/nfsclient/nfs_clstate.c | 36 ++++++++++++++++++++++++++++++++++++ sys/fs/nfsclient/nfs_clvnops.c | 17 +++++++++++++++++ sys/fs/nfsclient/nfsnode.h | 2 ++ 5 files changed, 70 insertions(+), 4 deletions(-) diff --git a/sys/fs/nfsclient/nfs_clnode.c b/sys/fs/nfsclient/nfs_clnode.c index 1c0e855ff5a9..9718c2c36a3c 100644 --- a/sys/fs/nfsclient/nfs_clnode.c +++ b/sys/fs/nfsclient/nfs_clnode.c @@ -243,7 +243,11 @@ ncl_inactive(struct vop_inactive_args *ap) boolean_t retv; td = curthread; + np = VTONFS(vp); if (NFS_ISV4(vp) && vp->v_type == VREG) { + NFSLOCKNODE(np); + np->n_openstateid = NULL; + NFSUNLOCKNODE(np); /* * Since mmap()'d files do I/O after VOP_CLOSE(), the NFSv4 * Close operations are delayed until now. Any dirty @@ -263,7 +267,6 @@ ncl_inactive(struct vop_inactive_args *ap) } } - np = VTONFS(vp); NFSLOCKNODE(np); ncl_releasesillyrename(vp, td); @@ -303,9 +306,10 @@ ncl_reclaim(struct vop_reclaim_args *ap) NFSLOCKNODE(np); ncl_releasesillyrename(vp, td); - NFSUNLOCKNODE(np); if (NFS_ISV4(vp) && vp->v_type == VREG) { + np->n_openstateid = NULL; + NFSUNLOCKNODE(np); /* * We can now safely close any remaining NFSv4 Opens for * this file. Most opens will have already been closed by @@ -325,7 +329,8 @@ ncl_reclaim(struct vop_reclaim_args *ap) nfscl_delegreturnvp(vp, td); } else MNT_IUNLOCK(mp); - } + } else + NFSUNLOCKNODE(np); vfs_hash_remove(vp); diff --git a/sys/fs/nfsclient/nfs_clrpcops.c b/sys/fs/nfsclient/nfs_clrpcops.c index 6093f7c0adeb..2f6226e38415 100644 --- a/sys/fs/nfsclient/nfs_clrpcops.c +++ b/sys/fs/nfsclient/nfs_clrpcops.c @@ -457,8 +457,14 @@ else printf(" fhl=0\n"); * If error is non-zero, don't increment it, since the Open * hasn't succeeded yet. */ - if (!error) + if (!error) { op->nfso_opencnt++; + if (NFSHASNFSV4N(nmp) && NFSHASONEOPENOWN(nmp)) { + NFSLOCKNODE(np); + np->n_openstateid = op; + NFSUNLOCKNODE(np); + } + } nfscl_openrelease(nmp, op, error, newone); if (error == NFSERR_GRACE || error == NFSERR_STALECLIENTID || error == NFSERR_STALEDONTRECOVER || error == NFSERR_DELAY || diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c index 406dcc9d9b80..b90b500cc7a9 100644 --- a/sys/fs/nfsclient/nfs_clstate.c +++ b/sys/fs/nfsclient/nfs_clstate.c @@ -547,6 +547,34 @@ nfscl_getstateid(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t mode, return (EISDIR); np = VTONFS(vp); nmp = VFSTONFS(vp->v_mount); + + /* + * For "oneopenown" mounts, first check for a cached open in the + * NFS vnode, that can be used as a stateid. This can only be + * done if no delegations have been issued to the mount and no + * byte range file locking has been done for the file. + */ + if (NFSHASNFSV4N(nmp) && NFSHASONEOPENOWN(nmp) && fords == 0) { + NFSLOCKMNT(nmp); + NFSLOCKNODE(np); + if ((nmp->nm_privflag & NFSMNTP_DELEGISSUED) == 0 && + (np->n_flag & NMIGHTBELOCKED) == 0 && + np->n_openstateid != NULL) { + stateidp->seqid = 0; + stateidp->other[0] = + np->n_openstateid->nfso_stateid.other[0]; + stateidp->other[1] = + np->n_openstateid->nfso_stateid.other[1]; + stateidp->other[2] = + np->n_openstateid->nfso_stateid.other[2]; + NFSUNLOCKNODE(np); + NFSUNLOCKMNT(nmp); + return (0); + } + NFSUNLOCKNODE(np); + NFSUNLOCKMNT(nmp); + } + NFSLOCKCLSTATE(); clp = nfscl_findcl(nmp); if (clp == NULL) { @@ -4301,9 +4329,17 @@ nfscl_relock(vnode_t vp, struct nfsclclient *clp, struct nfsmount *nmp, { struct nfscllockowner *nlp; struct nfsfh *nfhp; + struct nfsnode *np; u_int64_t off, len; int error, newone, donelocally; + if (NFSHASNFSV4N(nmp) && NFSHASONEOPENOWN(nmp)) { + np = VTONFS(vp); + NFSLOCKNODE(np); + np->n_flag |= NMIGHTBELOCKED; + NFSUNLOCKNODE(np); + } + off = lop->nfslo_first; len = lop->nfslo_end - lop->nfslo_first; error = nfscl_getbytelock(vp, off, len, lop->nfslo_type, cred, p, diff --git a/sys/fs/nfsclient/nfs_clvnops.c b/sys/fs/nfsclient/nfs_clvnops.c index 2311ea099042..72d9eac8e962 100644 --- a/sys/fs/nfsclient/nfs_clvnops.c +++ b/sys/fs/nfsclient/nfs_clvnops.c @@ -3166,6 +3166,7 @@ nfs_advlock(struct vop_advlock_args *ap) struct vattr va; int ret, error; u_quad_t size; + struct nfsmount *nmp; error = NFSVOPLOCK(vp, LK_SHARED); if (error != 0) @@ -3195,6 +3196,22 @@ nfs_advlock(struct vop_advlock_args *ap) ap->a_flags)) (void) ncl_flush(vp, MNT_WAIT, td, 1, 0); + /* + * Mark NFS node as might have acquired a lock. + * This is separate from NHASBEENLOCKED, because it must + * be done before the nfsrpc_advlock() call, which might + * add a nfscllock structure to the client state. + * It is used to check for the case where a nfscllock + * state structure cannot exist for the file. + * Only done for "oneopenown" NFSv4.1/4.2 mounts. + */ + nmp = VFSTONFS(vp->v_mount); + if (NFSHASNFSV4N(nmp) && NFSHASONEOPENOWN(nmp)) { + NFSLOCKNODE(np); + np->n_flag |= NMIGHTBELOCKED; + NFSUNLOCKNODE(np); + } + /* * Loop around doing the lock op, while a blocking lock * must wait for the lock op to succeed. diff --git a/sys/fs/nfsclient/nfsnode.h b/sys/fs/nfsclient/nfsnode.h index 66a2de31551a..b34e362a8522 100644 --- a/sys/fs/nfsclient/nfsnode.h +++ b/sys/fs/nfsclient/nfsnode.h @@ -128,6 +128,7 @@ struct nfsnode { u_int64_t n_change; /* old Change attribute */ struct nfsv4node *n_v4; /* extra V4 stuff */ struct ucred *n_writecred; /* Cred. for putpages */ + struct nfsclopen *n_openstateid; /* Cached open stateid */ }; #define n_atim n_un1.nf_atim @@ -164,6 +165,7 @@ struct nfsnode { #define NHASBEENLOCKED 0x00080000 /* Has been file locked. */ #define NDSCOMMIT 0x00100000 /* Commit is done via the DS. */ #define NVNSETSZSKIP 0x00200000 /* Skipped vnode_pager_setsize() */ +#define NMIGHTBELOCKED 0x00400000 /* Might be file locked. */ /* * Convert between nfsnode pointers and vnode pointers From owner-dev-commits-src-branches@freebsd.org Sun Aug 15 23:50:35 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6C98D66877B; Sun, 15 Aug 2021 23:50:35 +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 4GnvDq2YwZz4rYY; Sun, 15 Aug 2021 23:50:35 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 403521F413; Sun, 15 Aug 2021 23:50:35 +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 17FNoZ1W027918; Sun, 15 Aug 2021 23:50:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17FNoZLh027917; Sun, 15 Aug 2021 23:50:35 GMT (envelope-from git) Date: Sun, 15 Aug 2021 23:50:35 GMT Message-Id: <202108152350.17FNoZLh027917@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Rick Macklem Subject: git: 181044a10169 - stable/13 - nfscl: Set correct lockowner for "oneopenown" mount option MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 181044a10169fc0c7568131a2a7f355340428f87 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2021 23:50:35 -0000 The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=181044a10169fc0c7568131a2a7f355340428f87 commit 181044a10169fc0c7568131a2a7f355340428f87 Author: Rick Macklem AuthorDate: 2021-07-28 22:23:05 +0000 Commit: Rick Macklem CommitDate: 2021-08-15 23:47:20 +0000 nfscl: Set correct lockowner for "oneopenown" mount option For NFSv4.1/4.2, the client may use either an open, lock or delegation stateid as the stateid argument for an I/O operation. RFC 5661 defines an order of preference of delegation, then lock and finally open stateid for the argument, although NFSv4.1/4.2 servers are expected to handle any stateid type. For the "oneopenown" mount option, the lock owner was not being correctly generated and, as such, the I/O operation would use an open stateid, even when a lock stateid existed. Although this did not and should not affect an NFSv4.1/4.2 server's behaviour, this patch makes the behaviour for "oneopenown" the same as when the mount option is not specified. Found during inspection of packet captures. No failure during testing against NFSv4.1/4.2 servers of the unpatched code occurred. (cherry picked from commit 54ff3b3986741b9cd06ce20b90c96711cbe146d0) --- sys/fs/nfsclient/nfs_clstate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c index b90b500cc7a9..bb2c78a72ed9 100644 --- a/sys/fs/nfsclient/nfs_clstate.c +++ b/sys/fs/nfsclient/nfs_clstate.c @@ -528,7 +528,7 @@ nfscl_getstateid(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t mode, struct nfscldeleg *dp; struct nfsnode *np; struct nfsmount *nmp; - u_int8_t own[NFSV4CL_LOCKNAMELEN]; + u_int8_t own[NFSV4CL_LOCKNAMELEN], lockown[NFSV4CL_LOCKNAMELEN]; int error; bool done; @@ -631,9 +631,10 @@ nfscl_getstateid(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t mode, nfscl_filllockowner(NULL, own, F_POSIX); else nfscl_filllockowner(p->td_proc, own, F_POSIX); + nfscl_filllockowner(p->td_proc, lockown, F_POSIX); lp = NULL; error = nfscl_getopen(NULL, clp->nfsc_openhash, nfhp, fhlen, - own, own, mode, &lp, &op); + own, lockown, mode, &lp, &op); if (error == 0 && lp != NULL && fords == 0) { /* Don't return a lock stateid for a DS. */ if (NFSHASNFSV4N(nmp))