From 53b3b05944bcd16f747e4d6937488e9dd2f1229c Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Thu, 1 Jun 2017 23:04:44 +0000 Subject: [PATCH 01/45] META_MODE: Move ignoring of /usr/local/etc/libmap.d to proper place. This was added in r318194 but local.meta.sys.mk is only used for DIRDEPS_BUILD. --- share/mk/local.meta.sys.mk | 3 --- share/mk/sys.mk | 6 +++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/share/mk/local.meta.sys.mk b/share/mk/local.meta.sys.mk index 82de954945aa..2706683f210b 100644 --- a/share/mk/local.meta.sys.mk +++ b/share/mk/local.meta.sys.mk @@ -283,6 +283,3 @@ META_MODE+= missing-meta=yes .if empty(META_MODE:Mnofilemon) META_MODE+= missing-filemon=yes .endif -# We do not want everything out-of-date just because -# some unrelated shared lib updated this. -.MAKE.META.IGNORE_PATHS+= /usr/local/etc/libmap.d diff --git a/share/mk/sys.mk b/share/mk/sys.mk index c6c54f14aed9..cd300e8b7a15 100644 --- a/share/mk/sys.mk +++ b/share/mk/sys.mk @@ -91,7 +91,11 @@ META_MODE?= normal /usr/share \ .endif - +.if !empty(.MAKE.MODE:Mmeta) +# We do not want everything out-of-date just because +# some unrelated shared lib updated this. +.MAKE.META.IGNORE_PATHS+= /usr/local/etc/libmap.d +.endif .if ${MK_AUTO_OBJ} == "yes" # This needs to be done early - before .PATH is computed From 9f68573426cb29ff701ae0ef0bc64ae3124e5320 Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Fri, 2 Jun 2017 00:57:59 +0000 Subject: [PATCH 02/45] native-xtools: Connect lld. This will ensure that aarch64 gets a working native /usr/bin/ld rather than requiring the aarch64-binutils hack in Poudriere, or emulating the aarch64 lld. PR: 217189 Reported by: swills, jbeich --- Makefile.inc1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.inc1 b/Makefile.inc1 index e3b778d40dda..bde0d7b0f342 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -2019,6 +2019,7 @@ native-xtools: .PHONY ${_gcc_tools} \ ${_clang_libs} \ ${_clang} \ + ${_lld} \ sbin/md5 \ sbin/sysctl \ usr.bin/diff \ From f4d34383f924e0c0557d0c09eb97430b8f5347d6 Mon Sep 17 00:00:00 2001 From: Marcelo Araujo Date: Fri, 2 Jun 2017 02:35:16 +0000 Subject: [PATCH 03/45] Add VNC Authentication support based on RFC6143 section 7.2.2. Submitted by: Fabian Freyer Reworked by: myself Reviewed by: grehan, rgrimes and jilles MFC after: 1 week. Relnotes: Yes. Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D10818 --- usr.sbin/bhyve/Makefile | 8 +++ usr.sbin/bhyve/bhyve.8 | 9 ++- usr.sbin/bhyve/pci_fbuf.c | 6 +- usr.sbin/bhyve/rfb.c | 122 ++++++++++++++++++++++++++++++++++---- usr.sbin/bhyve/rfb.h | 2 +- 5 files changed, 131 insertions(+), 16 deletions(-) diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile index c4b1e37ca709..8159d7ddbd7a 100644 --- a/usr.sbin/bhyve/Makefile +++ b/usr.sbin/bhyve/Makefile @@ -2,6 +2,8 @@ # $FreeBSD$ # +.include + PROG= bhyve PACKAGE= bhyve @@ -63,6 +65,12 @@ SRCS+= vmm_instruction_emul.c LIBADD= vmmapi md pthread z +.if ${MK_OPENSSL} == "no" +CFLAGS+=-DNO_OPENSSL +.else +LIBADD+= crypto +.endif + CFLAGS+= -I${BHYVE_SYSDIR}/sys/dev/e1000 CFLAGS+= -I${BHYVE_SYSDIR}/sys/dev/mii CFLAGS+= -I${BHYVE_SYSDIR}/sys/dev/usb/controller diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8 index 16b2245d031f..c5d810cc807f 100644 --- a/usr.sbin/bhyve/bhyve.8 +++ b/usr.sbin/bhyve/bhyve.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 3, 2017 +.Dd May 22, 2017 .Dt BHYVE 8 .Os .Sh NAME @@ -309,7 +309,7 @@ Emergency write is advertised, but no-op at present. .Pp Framebuffer devices: .Bl -tag -width 10n -.It Oo rfb= Ns Oo Ar IP: Oc Ns Ar port Oc Ns Oo ,w= Ns Ar width Oc Ns Oo ,h= Ns Ar height Oc Ns Oo ,vga= Ns Ar vgaconf Oc Ns Oo Ns ,wait Oc +.It Oo rfb= Ns Oo Ar IP: Oc Ns Ar port Oc Ns Oo ,w= Ns Ar width Oc Ns Oo ,h= Ns Ar height Oc Ns Oo ,vga= Ns Ar vgaconf Oc Ns Oo Ns ,wait Oc Ns Oo ,password= Ns Ar password Oc .Bl -tag -width 8n .It Ar IP:port An @@ -368,6 +368,11 @@ Instruct to only boot upon the initiation of a VNC connection, simplifying the installation of operating systems that require immediate keyboard input. This can be removed for post-installation use. +.It password +This type of authentication is known to be cryptographically weak and is not +intended for use on untrusted networks. +Many implementations will want to use stronger security, such as running +the session over an encrypted channel provided by IPsec or SSH. .El .El .Pp diff --git a/usr.sbin/bhyve/pci_fbuf.c b/usr.sbin/bhyve/pci_fbuf.c index 67279d2162b9..5361c7b61b7a 100644 --- a/usr.sbin/bhyve/pci_fbuf.c +++ b/usr.sbin/bhyve/pci_fbuf.c @@ -93,6 +93,7 @@ struct pci_fbuf_softc { /* rfb server */ char *rfb_host; + char *rfb_password; int rfb_port; int rfb_wait; int vga_enabled; @@ -285,7 +286,8 @@ pci_fbuf_parse_opts(struct pci_fbuf_softc *sc, char *opts) goto done; } else if (sc->memregs.height == 0) sc->memregs.height = 1080; - + } else if (!strcmp(xopts, "password")) { + sc->rfb_password = config; } else { pci_fbuf_usage(xopts); ret = -1; @@ -407,7 +409,7 @@ pci_fbuf_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) memset((void *)sc->fb_base, 0, FB_SIZE); - error = rfb_init(sc->rfb_host, sc->rfb_port, sc->rfb_wait); + error = rfb_init(sc->rfb_host, sc->rfb_port, sc->rfb_wait, sc->rfb_password); done: if (error) free(sc); diff --git a/usr.sbin/bhyve/rfb.c b/usr.sbin/bhyve/rfb.c index f3e30244b5de..3eb67314c029 100644 --- a/usr.sbin/bhyve/rfb.c +++ b/usr.sbin/bhyve/rfb.c @@ -60,10 +60,23 @@ __FBSDID("$FreeBSD$"); #include "rfb.h" #include "sockstream.h" +#ifndef NO_OPENSSL +#include +#endif + static int rfb_debug = 0; #define DPRINTF(params) if (rfb_debug) printf params #define WPRINTF(params) printf params +#define AUTH_LENGTH 16 +#define PASSWD_LENGTH 8 + +#define SECURITY_TYPE_NONE 1 +#define SECURITY_TYPE_VNC_AUTH 2 + +#define AUTH_FAILED_UNAUTH 1 +#define AUTH_FAILED_ERROR 2 + struct rfb_softc { int sfd; pthread_t tid; @@ -72,9 +85,11 @@ struct rfb_softc { int width, height; - bool enc_raw_ok; - bool enc_zlib_ok; - bool enc_resize_ok; + char *password; + + bool enc_raw_ok; + bool enc_zlib_ok; + bool enc_resize_ok; z_stream zstream; uint8_t *zbuf; @@ -208,7 +223,7 @@ static void rfb_send_resize_update_msg(struct rfb_softc *rc, int cfd) { struct rfb_srvr_updt_msg supdt_msg; - struct rfb_srvr_rect_hdr srect_hdr; + struct rfb_srvr_rect_hdr srect_hdr; /* Number of rectangles: 1 */ supdt_msg.type = 0; @@ -739,8 +754,19 @@ rfb_handle(struct rfb_softc *rc, int cfd) { const char *vbuf = "RFB 003.008\n"; unsigned char buf[80]; + unsigned char *message; + +#ifndef NO_OPENSSL + unsigned char challenge[AUTH_LENGTH]; + unsigned char keystr[PASSWD_LENGTH]; + unsigned char crypt_expected[AUTH_LENGTH]; + + DES_key_schedule ks; + int i; +#endif + pthread_t tid; - uint32_t sres; + uint32_t sres; int len; rc->cfd = cfd; @@ -751,19 +777,91 @@ rfb_handle(struct rfb_softc *rc, int cfd) /* 1b. Read client version */ len = read(cfd, buf, sizeof(buf)); - /* 2a. Send security type 'none' */ + /* 2a. Send security type */ buf[0] = 1; - buf[1] = 1; /* none */ - stream_write(cfd, buf, 2); +#ifndef NO_OPENSSL + if (rc->password) + buf[1] = SECURITY_TYPE_VNC_AUTH; + else + buf[1] = SECURITY_TYPE_NONE; +#else + buf[1] = SECURITY_TYPE_NONE; +#endif + stream_write(cfd, buf, 2); /* 2b. Read agreed security type */ len = stream_read(cfd, buf, 1); - /* 2c. Write back a status of 0 */ - sres = 0; + /* 2c. Do VNC authentication */ + switch (buf[0]) { + case SECURITY_TYPE_NONE: + sres = 0; + break; + case SECURITY_TYPE_VNC_AUTH: + /* + * The client encrypts the challenge with DES, using a password + * supplied by the user as the key. + * To form the key, the password is truncated to + * eight characters, or padded with null bytes on the right. + * The client then sends the resulting 16-bytes response. + */ +#ifndef NO_OPENSSL + strncpy(keystr, rc->password, PASSWD_LENGTH); + + /* VNC clients encrypts the challenge with all the bit fields + * in each byte of the password mirrored. + * Here we flip each byte of the keystr. + */ + for (i = 0; i < PASSWD_LENGTH; i++) { + keystr[i] = (keystr[i] & 0xF0) >> 4 + | (keystr[i] & 0x0F) << 4; + keystr[i] = (keystr[i] & 0xCC) >> 2 + | (keystr[i] & 0x33) << 2; + keystr[i] = (keystr[i] & 0xAA) >> 1 + | (keystr[i] & 0x55) << 1; + } + + /* Initialize a 16-byte random challenge */ + arc4random_buf(challenge, sizeof(challenge)); + stream_write(cfd, challenge, AUTH_LENGTH); + + /* Receive the 16-byte challenge response */ + stream_read(cfd, buf, AUTH_LENGTH); + + memcpy(crypt_expected, challenge, AUTH_LENGTH); + + /* Encrypt the Challenge with DES */ + DES_set_key((C_Block *)keystr, &ks); + DES_ecb_encrypt((C_Block *)challenge, + (C_Block *)crypt_expected, &ks, DES_ENCRYPT); + DES_ecb_encrypt((C_Block *)(challenge + PASSWD_LENGTH), + (C_Block *)(crypt_expected + PASSWD_LENGTH), + &ks, DES_ENCRYPT); + + if (memcmp(crypt_expected, buf, AUTH_LENGTH) != 0) { + message = "Auth Failed: Invalid Password."; + sres = htonl(1); + } else + sres = 0; +#else + sres = 0; + WPRINTF(("Auth not supported, no OpenSSL in your system")); +#endif + + break; + } + + /* 2d. Write back a status */ stream_write(cfd, &sres, 4); + if (sres) { + *((uint32_t *) buf) = htonl(strlen(message)); + stream_write(cfd, buf, 4); + stream_write(cfd, message, strlen(message)); + goto done; + } + /* 3a. Read client shared-flag byte */ len = stream_read(cfd, buf, 1); @@ -869,7 +967,7 @@ sse42_supported(void) } int -rfb_init(char *hostname, int port, int wait) +rfb_init(char *hostname, int port, int wait, char *password) { struct rfb_softc *rc; struct sockaddr_in sin; @@ -887,6 +985,8 @@ rfb_init(char *hostname, int port, int wait) rc->crc_width = RFB_MAX_WIDTH; rc->crc_height = RFB_MAX_HEIGHT; + rc->password = password; + rc->sfd = socket(AF_INET, SOCK_STREAM, 0); if (rc->sfd < 0) { perror("socket"); diff --git a/usr.sbin/bhyve/rfb.h b/usr.sbin/bhyve/rfb.h index b3d3786669cc..1bd2eca3f7f1 100644 --- a/usr.sbin/bhyve/rfb.h +++ b/usr.sbin/bhyve/rfb.h @@ -31,6 +31,6 @@ #define RFB_PORT 5900 -int rfb_init(char *hostname, int port, int wait); +int rfb_init(char *hostname, int port, int wait, char *password); #endif /* _RFB_H_ */ From 13eb5b4943f93a10ea79990fb093a9c6bf80e27f Mon Sep 17 00:00:00 2001 From: Marcelo Araujo Date: Fri, 2 Jun 2017 02:37:17 +0000 Subject: [PATCH 04/45] Bump manpage date. --- usr.sbin/bhyve/bhyve.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8 index c5d810cc807f..77f36e28f524 100644 --- a/usr.sbin/bhyve/bhyve.8 +++ b/usr.sbin/bhyve/bhyve.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 22, 2017 +.Dd June 2, 2017 .Dt BHYVE 8 .Os .Sh NAME From ea67c7a015806b1435c5eb106204e31e323b14f3 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Fri, 2 Jun 2017 03:25:59 +0000 Subject: [PATCH 05/45] Add -H as an alias for --speed-large-file to match GNU diff. This is undocumented to match GNU diff where -H is also undocumented. Some existing software (such as kompare) uses this option by default. Reviewed by: emaste, rpokala Differential Revision: https://reviews.freebsd.org/D11022 --- usr.bin/diff/diff.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c index f314e9f76c3f..e12697c4e89e 100644 --- a/usr.bin/diff/diff.c +++ b/usr.bin/diff/diff.c @@ -46,7 +46,7 @@ struct stat stb1, stb2; struct excludes *excludes_list; regex_t ignore_re; -#define OPTIONS "0123456789aBbC:cdD:efhI:iL:lnNPpqrS:sTtU:uwX:x:" +#define OPTIONS "0123456789aBbC:cdD:efHhI:iL:lnNPpqrS:sTtU:uwX:x:" enum { OPT_TSIZE = CHAR_MAX + 1, OPT_STRIPCR, @@ -54,7 +54,6 @@ enum { OPT_NO_IGN_FN_CASE, OPT_NORMAL, OPT_HORIZON_LINES, - OPT_SPEED_LARGE_FILES, OPT_CHANGED_GROUP_FORMAT, }; @@ -66,6 +65,7 @@ static struct option longopts[] = { { "minimal", no_argument, 0, 'd' }, { "ed", no_argument, 0, 'e' }, { "forward-ed", no_argument, 0, 'f' }, + { "speed-large-files", no_argument, NULL, 'H' }, { "ignore-matching-lines", required_argument, 0, 'I' }, { "ignore-case", no_argument, 0, 'i' }, { "paginate", no_argument, NULL, 'l' }, @@ -88,7 +88,6 @@ static struct option longopts[] = { { "horizon-lines", required_argument, NULL, OPT_HORIZON_LINES }, { "no-ignore-file-name-case", no_argument, NULL, OPT_NO_IGN_FN_CASE }, { "normal", no_argument, NULL, OPT_NORMAL }, - { "speed-large-files", no_argument, NULL, OPT_SPEED_LARGE_FILES}, { "strip-trailing-cr", no_argument, NULL, OPT_STRIPCR }, { "tabsize", optional_argument, NULL, OPT_TSIZE }, { "changed-group-format", required_argument, NULL, OPT_CHANGED_GROUP_FORMAT}, @@ -159,6 +158,9 @@ main(int argc, char **argv) case 'f': diff_format = D_REVERSE; break; + case 'H': + /* ignore but needed for compatibility with GNU diff */ + break; case 'h': /* silently ignore for backwards compatibility */ break; @@ -252,8 +254,6 @@ main(int argc, char **argv) usage(); } break; - case OPT_SPEED_LARGE_FILES: - break; /* ignore but needed for compatibility with GNU diff */ case OPT_STRIPCR: dflags |= D_STRIPCR; break; From 60b67035f2bb1e013dbefc824f08a302f8a07085 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Fri, 2 Jun 2017 03:53:34 +0000 Subject: [PATCH 06/45] Remove stale cap_rights_get(2) manpage. The documentation moved to section 3 several years ago, but 'man cap_rights_get' pulls up cap_rights_limit(2) (which is MLINKed to cap_rights_get.2) instead of cap_rights_get(3). MFC after: 1 week --- ObsoleteFiles.inc | 2 ++ lib/libc/sys/Makefile.inc | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc index 12184a0f4616..0f8a17238d17 100644 --- a/ObsoleteFiles.inc +++ b/ObsoleteFiles.inc @@ -38,6 +38,8 @@ # xargs -n1 | sort | uniq -d; # done +# 20170601: remove stale manpage +OLD_FILES+=usr/share/man/man2/cap_rights_get.2.gz # 20170601: old libifconfig and libifc OLD_FILES+=usr/lib/libifc.a OLD_FILES+=usr/lib/libifc_p.a diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index b641125096d1..ad1abbb03e51 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -350,7 +350,6 @@ MLINKS+=brk.2 sbrk.2 MLINKS+=cap_enter.2 cap_getmode.2 MLINKS+=cap_fcntls_limit.2 cap_fcntls_get.2 MLINKS+=cap_ioctls_limit.2 cap_ioctls_get.2 -MLINKS+=cap_rights_limit.2 cap_rights_get.2 MLINKS+=chdir.2 fchdir.2 MLINKS+=chflags.2 chflagsat.2 \ chflags.2 fchflags.2 \ From c74415ed3b84cad5e0f42dc6c7a4c64026fa8cfd Mon Sep 17 00:00:00 2001 From: Colin Percival Date: Fri, 2 Jun 2017 07:03:31 +0000 Subject: [PATCH 07/45] Skip setting the MTU in the netfront driver (xn# devices) if the new MTU is the same as the old MTU. In particular, on Amazon EC2 "T2" instances without this change, the network interface is reinitialized every 30 minutes due to the MTU being (re)set when a new DHCP lease is obtained, causing packets to be dropped, along with annoying syslog messages about the link state changing. As a side note, the behaviour this commit fixes was responsible for exposing the locking problems fixed via r318523 and r318631. Maintainers of other network interface drivers may wish to consider making the corresponding change; the handling of SIOCSIFMTU does not seem to exhibit a great deal of consistency between drivers. MFC after: 1 week --- sys/dev/xen/netfront/netfront.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sys/dev/xen/netfront/netfront.c b/sys/dev/xen/netfront/netfront.c index ace76808769d..694338b2e528 100644 --- a/sys/dev/xen/netfront/netfront.c +++ b/sys/dev/xen/netfront/netfront.c @@ -1767,6 +1767,9 @@ xn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) #endif break; case SIOCSIFMTU: + if (ifp->if_mtu == ifr->ifr_mtu) + break; + ifp->if_mtu = ifr->ifr_mtu; ifp->if_drv_flags &= ~IFF_DRV_RUNNING; xn_ifinit(sc); From 7136a1d97aa22e7d0e50bbfb67013b1b96a3e7f1 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Fri, 2 Jun 2017 13:33:50 +0000 Subject: [PATCH 08/45] Decode the arguments passed to __cap_rights_get() and cap_rights_limit(). Submitted by: tobik --- usr.bin/truss/syscall.h | 3 ++- usr.bin/truss/syscalls.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/usr.bin/truss/syscall.h b/usr.bin/truss/syscall.h index 46bef46b2308..f0b39b468bbf 100644 --- a/usr.bin/truss/syscall.h +++ b/usr.bin/truss/syscall.h @@ -28,6 +28,7 @@ * Kevent -- a pointer to an array of struct kevents. Prints all elements. * Pathconf -- the 2nd argument of pathconf(). * Utrace -- utrace(2) buffer. + * CapRights -- a pointer to a cap_rights_t. Prints all set capabilities. * * In addition, the pointer types (String, Ptr) may have OUT masked in -- * this means that the data is set on *return* from the system call -- or @@ -47,7 +48,7 @@ enum Argtype { None = 1, Hex, Octal, Int, UInt, LongHex, Name, Ptr, Stat, Ioctl, Sysarch, ExecArgs, ExecEnv, PipeFds, QuadHex, Utrace, IntArray, Pipe2, CapFcntlRights, Fadvice, FileFlags, Flockop, Getfsstatmode, Kldsymcmd, Kldunloadflags, Sizet, Madvice, Socklent, Sockprotocol, Sockoptlevel, - Sockoptname, Msgflags, + Sockoptname, Msgflags, CapRights, CloudABIAdvice, CloudABIClockID, ClouduABIFDSFlags, CloudABIFDStat, CloudABIFileStat, CloudABIFileType, diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index 1bf1e88ed8ad..f8c1943125ec 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); * arguments. */ +#include #include #include #include @@ -76,6 +77,8 @@ __FBSDID("$FreeBSD$"); */ static struct syscall decoded_syscalls[] = { /* Native ABI */ + { .name = "__cap_rights_get", .ret_type = 1, .nargs = 3, + .args = { { Int, 0 }, { Int, 1 }, { CapRights | OUT, 2 } } }, { .name = "__getcwd", .ret_type = 1, .nargs = 2, .args = { { Name | OUT, 0 }, { Int, 1 } } }, { .name = "_umtx_op", .ret_type = 1, .nargs = 5, @@ -96,6 +99,8 @@ static struct syscall decoded_syscalls[] = { .args = { { Int, 0 }, { CapFcntlRights | OUT, 1 } } }, { .name = "cap_fcntls_limit", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { CapFcntlRights, 1 } } }, + { .name = "cap_rights_limit", .ret_type = 1, .nargs = 2, + .args = { { Int, 0 }, { CapRights, 1 } } }, { .name = "chdir", .ret_type = 1, .nargs = 1, .args = { { Name, 0 } } }, { .name = "chflags", .ret_type = 1, .nargs = 2, @@ -1976,6 +1981,18 @@ print_arg(struct syscall_args *sc, unsigned long *args, long *retval, case Msgflags: print_mask_arg(sysdecode_msg_flags, fp, args[sc->offset]); break; + case CapRights: { + cap_rights_t rights; + + if (get_struct(pid, (void *)args[sc->offset], &rights, + sizeof(rights)) != -1) { + fputs("{ ", fp); + sysdecode_cap_rights(fp, &rights); + fputs(" }", fp); + } else + fprintf(fp, "0x%lx", args[sc->offset]); + break; + } case CloudABIAdvice: fputs(xlookup(cloudabi_advice, args[sc->offset]), fp); From 88df15adf6bb1f79ac826d8ded8ccdb349e469c2 Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Fri, 2 Jun 2017 14:01:17 +0000 Subject: [PATCH 09/45] Fix device lookup of for the stdout-path chosen property. The stdout-path chosen property may include the serial connection details, e.g. the baud rate. When passing the device to OF_finddevice we need to strip off this information as it will cause the lookup to fail. Reviewed by: emaste, manu Differential Revision: https://reviews.freebsd.org/D6846 --- sys/dev/uart/uart_bus_fdt.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/dev/uart/uart_bus_fdt.c b/sys/dev/uart/uart_bus_fdt.c index 20f6daebadcd..bade2e45f825 100644 --- a/sys/dev/uart/uart_bus_fdt.c +++ b/sys/dev/uart/uart_bus_fdt.c @@ -117,9 +117,18 @@ static int phandle_chosen_propdev(phandle_t chosen, const char *name, phandle_t *node) { char buf[64]; + char *sep; if (OF_getprop(chosen, name, buf, sizeof(buf)) <= 0) return (ENXIO); + /* + * stdout-path may have a ':' to separate the device from the + * connection settings. Split the string so we just pass the former + * to OF_finddevice. + */ + sep = strchr(buf, ':'); + if (sep != NULL) + *sep = '\0'; if ((*node = OF_finddevice(buf)) == -1) return (ENXIO); From 5bb27fe15c041a7d310a63324c620ada21f3616b Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Fri, 2 Jun 2017 14:17:14 +0000 Subject: [PATCH 10/45] - Don't bother flushing the data cache for pages we're about to unmap, there's no need to. - Remove pmap_is_current(), pmap_[pte|l3]_valid_cacheable as there were only used to know if we had to write back pages. - In pmap_remove_pages(), don't bother invalidating each page in the TLB, we're about to flush the whole TLB anyway. This makes make world 8-9% faster on my hardware. Reviewed by: andrew --- sys/arm64/arm64/pmap.c | 49 ------------------------------------------ 1 file changed, 49 deletions(-) diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c index 36bcd231c630..4b4a67193401 100644 --- a/sys/arm64/arm64/pmap.c +++ b/sys/arm64/arm64/pmap.c @@ -494,14 +494,6 @@ pmap_get_tables(pmap_t pmap, vm_offset_t va, pd_entry_t **l0, pd_entry_t **l1, return (true); } -static __inline int -pmap_is_current(pmap_t pmap) -{ - - return ((pmap == pmap_kernel()) || - (pmap == curthread->td_proc->p_vmspace->vm_map.pmap)); -} - static __inline int pmap_l3_valid(pt_entry_t l3) { @@ -510,23 +502,7 @@ pmap_l3_valid(pt_entry_t l3) } -/* Is a level 1 or 2entry a valid block and cacheable */ CTASSERT(L1_BLOCK == L2_BLOCK); -static __inline int -pmap_pte_valid_cacheable(pt_entry_t pte) -{ - - return (((pte & ATTR_DESCR_MASK) == L1_BLOCK) && - ((pte & ATTR_IDX_MASK) == ATTR_IDX(CACHED_MEMORY))); -} - -static __inline int -pmap_l3_valid_cacheable(pt_entry_t l3) -{ - - return (((l3 & ATTR_DESCR_MASK) == L3_PAGE) && - ((l3 & ATTR_IDX_MASK) == ATTR_IDX(CACHED_MEMORY))); -} #define PTE_SYNC(pte) cpu_dcache_wb_range((vm_offset_t)pte, sizeof(*pte)) @@ -1180,8 +1156,6 @@ pmap_kremove(vm_offset_t va) KASSERT(pte != NULL, ("pmap_kremove: Invalid address")); KASSERT(lvl == 3, ("pmap_kremove: Invalid pte level %d", lvl)); - if (pmap_l3_valid_cacheable(pmap_load(pte))) - cpu_dcache_wb_range(va, L3_SIZE); pmap_load_clear(pte); PTE_SYNC(pte); pmap_invalidate_page(kernel_pmap, va); @@ -1292,8 +1266,6 @@ pmap_qremove(vm_offset_t sva, int count) KASSERT(lvl == 3, ("Invalid device pagetable level: %d != 3", lvl)); if (pte != NULL) { - if (pmap_l3_valid_cacheable(pmap_load(pte))) - cpu_dcache_wb_range(va, L3_SIZE); pmap_load_clear(pte); PTE_SYNC(pte); } @@ -2295,8 +2267,6 @@ pmap_remove_l3(pmap_t pmap, pt_entry_t *l3, vm_offset_t va, vm_page_t m; PMAP_LOCK_ASSERT(pmap, MA_OWNED); - if (pmap_is_current(pmap) && pmap_l3_valid_cacheable(pmap_load(l3))) - cpu_dcache_wb_range(va, L3_SIZE); old_l3 = pmap_load_clear(l3); PTE_SYNC(l3); pmap_invalidate_page(pmap, va); @@ -2518,9 +2488,6 @@ pmap_remove_all(vm_page_t m) pte = pmap_l2_to_l3(pde, pv->pv_va); tpte = pmap_load(pte); - if (pmap_is_current(pmap) && - pmap_l3_valid_cacheable(tpte)) - cpu_dcache_wb_range(pv->pv_va, L3_SIZE); pmap_load_clear(pte); PTE_SYNC(pte); pmap_invalidate_page(pmap, pv->pv_va); @@ -3004,10 +2971,6 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot, } goto validate; } - - /* Flush the cache, there might be uncommitted data in it */ - if (pmap_is_current(pmap) && pmap_l3_valid_cacheable(orig_l3)) - cpu_dcache_wb_range(va, L3_SIZE); } else { /* * Increment the counters. @@ -3673,20 +3636,8 @@ pmap_remove_pages(pmap_t pmap) ("pmap_remove_pages: bad pte %#jx", (uintmax_t)tpte)); - if (pmap_is_current(pmap)) { - if (lvl == 2 && - pmap_l3_valid_cacheable(tpte)) { - cpu_dcache_wb_range(pv->pv_va, - L3_SIZE); - } else if (lvl == 1 && - pmap_pte_valid_cacheable(tpte)) { - cpu_dcache_wb_range(pv->pv_va, - L2_SIZE); - } - } pmap_load_clear(pte); PTE_SYNC(pte); - pmap_invalidate_page(pmap, pv->pv_va); /* * Update the vm_page_t clean/reference bits. From 33c2a3cb16bd91563365c92af98ee2dcd98e4d59 Mon Sep 17 00:00:00 2001 From: Luiz Otavio O Souza Date: Fri, 2 Jun 2017 15:12:32 +0000 Subject: [PATCH 11/45] style(9) fixes, remove unnecessary headers, remove duplicate #defines and in some cases, shuffle the code around to simplify locking. No functional changes. Sponsored by: Rubicon Communications, LLC (Netgate) --- sys/dev/etherswitch/e6000sw/e6000sw.c | 222 +++++++++-------------- sys/dev/etherswitch/e6000sw/e6000swreg.h | 2 - 2 files changed, 88 insertions(+), 136 deletions(-) diff --git a/sys/dev/etherswitch/e6000sw/e6000sw.c b/sys/dev/etherswitch/e6000sw/e6000sw.c index 5884a23c5516..be2ec3008e75 100644 --- a/sys/dev/etherswitch/e6000sw/e6000sw.c +++ b/sys/dev/etherswitch/e6000sw/e6000sw.c @@ -28,40 +28,25 @@ #include __FBSDID("$FreeBSD$"); -#include #include -#include -#include +#include +#include #include #include -#include #include -#include -#include -#include -#include -#include +#include +#include #include #include #include -#include -#include - -#include -#include -#include - #include -#include #include #include -#include #include #include -#include #include "e6000swreg.h" #include "etherswitch_if.h" @@ -71,14 +56,10 @@ __FBSDID("$FreeBSD$"); MALLOC_DECLARE(M_E6000SW); MALLOC_DEFINE(M_E6000SW, "e6000sw", "e6000sw switch"); -#define E6000SW_LOCK(_sc) \ - sx_xlock(&(_sc)->sx) -#define E6000SW_UNLOCK(_sc) \ - sx_unlock(&(_sc)->sx) -#define E6000SW_LOCK_ASSERT(_sc, _what) \ - sx_assert(&(_sc)->sx, (_what)) -#define E6000SW_TRYLOCK(_sc) \ - sx_tryxlock(&(_sc)->sx) +#define E6000SW_LOCK(_sc) sx_xlock(&(_sc)->sx) +#define E6000SW_UNLOCK(_sc) sx_unlock(&(_sc)->sx) +#define E6000SW_LOCK_ASSERT(_sc, _what) sx_assert(&(_sc)->sx, (_what)) +#define E6000SW_TRYLOCK(_sc) sx_tryxlock(&(_sc)->sx) typedef struct e6000sw_softc { device_t dev; @@ -108,46 +89,43 @@ static etherswitch_info_t etherswitch_info = { .es_name = "Marvell 6000 series switch" }; -static void e6000sw_identify(driver_t *driver, device_t parent); -static int e6000sw_probe(device_t dev); -static int e6000sw_attach(device_t dev); -static int e6000sw_detach(device_t dev); -static int e6000sw_readphy(device_t dev, int phy, int reg); -static int e6000sw_writephy(device_t dev, int phy, int reg, int data); -static etherswitch_info_t* e6000sw_getinfo(device_t dev); -static void e6000sw_lock(device_t dev); -static void e6000sw_unlock(device_t dev); -static int e6000sw_getport(device_t dev, etherswitch_port_t *p); -static int e6000sw_setport(device_t dev, etherswitch_port_t *p); -static int e6000sw_readreg_wrapper(device_t dev, int addr_reg); -static int e6000sw_writereg_wrapper(device_t dev, int addr_reg, int val); -static int e6000sw_readphy_wrapper(device_t dev, int phy, int reg); -static int e6000sw_writephy_wrapper(device_t dev, int phy, int reg, int data); -static int e6000sw_getvgroup_wrapper(device_t dev, etherswitch_vlangroup_t *vg); -static int e6000sw_setvgroup_wrapper(device_t dev, etherswitch_vlangroup_t *vg); -static int e6000sw_setvgroup(device_t dev, etherswitch_vlangroup_t *vg); -static int e6000sw_getvgroup(device_t dev, etherswitch_vlangroup_t *vg); -static void e6000sw_setup(device_t dev, e6000sw_softc_t *sc); -static void e6000sw_port_vlan_conf(e6000sw_softc_t *sc); -static void e6000sw_tick(void *arg); -static void e6000sw_set_atustat(device_t dev, e6000sw_softc_t *sc, int bin, - int flag); -static int e6000sw_atu_flush(device_t dev, e6000sw_softc_t *sc, int flag); -static __inline void e6000sw_writereg(e6000sw_softc_t *sc, int addr, int reg, - int val); -static __inline uint32_t e6000sw_readreg(e6000sw_softc_t *sc, int addr, - int reg); -static int e6000sw_ifmedia_upd(struct ifnet *ifp); -static void e6000sw_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr); -static int e6000sw_atu_mac_table(device_t dev, e6000sw_softc_t *sc, struct - atu_opt *atu, int flag); -static int e6000sw_get_pvid(e6000sw_softc_t *sc, int port, int *pvid); -static int e6000sw_set_pvid(e6000sw_softc_t *sc, int port, int pvid); -static __inline int e6000sw_is_cpuport(e6000sw_softc_t *sc, int port); -static __inline int e6000sw_is_fixedport(e6000sw_softc_t *sc, int port); -static __inline int e6000sw_is_phyport(e6000sw_softc_t *sc, int port); -static __inline struct mii_data *e6000sw_miiforphy(e6000sw_softc_t *sc, - unsigned int phy); +static void e6000sw_identify(driver_t *, device_t); +static int e6000sw_probe(device_t); +static int e6000sw_attach(device_t); +static int e6000sw_detach(device_t); +static int e6000sw_readphy(device_t, int, int); +static int e6000sw_writephy(device_t, int, int, int); +static etherswitch_info_t* e6000sw_getinfo(device_t); +static void e6000sw_lock(device_t); +static void e6000sw_unlock(device_t); +static int e6000sw_getport(device_t, etherswitch_port_t *); +static int e6000sw_setport(device_t, etherswitch_port_t *); +static int e6000sw_readreg_wrapper(device_t, int); +static int e6000sw_writereg_wrapper(device_t, int, int); +static int e6000sw_readphy_wrapper(device_t, int, int); +static int e6000sw_writephy_wrapper(device_t, int, int, int); +static int e6000sw_getvgroup_wrapper(device_t, etherswitch_vlangroup_t *); +static int e6000sw_setvgroup_wrapper(device_t, etherswitch_vlangroup_t *); +static int e6000sw_setvgroup(device_t, etherswitch_vlangroup_t *); +static int e6000sw_getvgroup(device_t, etherswitch_vlangroup_t *); +static void e6000sw_setup(device_t, e6000sw_softc_t *); +static void e6000sw_port_vlan_conf(e6000sw_softc_t *); +static void e6000sw_tick(void *); +static void e6000sw_set_atustat(device_t, e6000sw_softc_t *, int, int); +static int e6000sw_atu_flush(device_t, e6000sw_softc_t *, int); +static __inline void e6000sw_writereg(e6000sw_softc_t *, int, int, int); +static __inline uint32_t e6000sw_readreg(e6000sw_softc_t *, int, int); +static int e6000sw_ifmedia_upd(struct ifnet *); +static void e6000sw_ifmedia_sts(struct ifnet *, struct ifmediareq *); +static int e6000sw_atu_mac_table(device_t, e6000sw_softc_t *, struct atu_opt *, + int); +static int e6000sw_get_pvid(e6000sw_softc_t *, int, int *); +static int e6000sw_set_pvid(e6000sw_softc_t *, int, int); +static __inline int e6000sw_is_cpuport(e6000sw_softc_t *, int); +static __inline int e6000sw_is_fixedport(e6000sw_softc_t *, int); +static __inline int e6000sw_is_phyport(e6000sw_softc_t *, int); +static __inline struct mii_data *e6000sw_miiforphy(e6000sw_softc_t *, + unsigned int); static device_method_t e6000sw_methods[] = { /* device interface */ @@ -190,14 +168,17 @@ DRIVER_MODULE(etherswitch, e6000sw, etherswitch_driver, etherswitch_devclass, 0, DRIVER_MODULE(miibus, e6000sw, miibus_driver, miibus_devclass, 0, 0); MODULE_DEPEND(e6000sw, mdio, 1, 1, 1); -#define SMI_CMD 0 -#define SMI_CMD_BUSY (1<<15) -#define SMI_CMD_OP_READ ((2<<10)|SMI_CMD_BUSY|(1<<12)) -#define SMI_CMD_OP_WRITE ((1<<10)|SMI_CMD_BUSY|(1<<12)) -#define SMI_DATA 1 +#define SMI_CMD 0 +#define SMI_CMD_BUSY (1 << 15) +#define SMI_CMD_OP_READ ((2 << 10) | SMI_CMD_BUSY | (1 << 12)) +#define SMI_CMD_OP_WRITE ((1 << 10) | SMI_CMD_BUSY | (1 << 12)) +#define SMI_DATA 1 + +#define MDIO_READ(dev, addr, reg) \ + MDIO_READREG(device_get_parent(dev), (addr), (reg)) +#define MDIO_WRITE(dev, addr, reg, val) \ + MDIO_WRITEREG(device_get_parent(dev), (addr), (reg), (val)) -#define MDIO_READ(dev, addr, reg) MDIO_READREG(device_get_parent(dev), (addr), (reg)) -#define MDIO_WRITE(dev, addr, reg, val) MDIO_WRITEREG(device_get_parent(dev), (addr), (reg), (val)) static void e6000sw_identify(driver_t *driver, device_t parent) { @@ -211,8 +192,8 @@ e6000sw_probe(device_t dev) { e6000sw_softc_t *sc; const char *description; - unsigned int id; phandle_t dsa_node, switch_node; + uint32_t id; dsa_node = fdt_find_compatible(OF_finddevice("/"), "marvell,dsa", 0); @@ -235,8 +216,8 @@ e6000sw_probe(device_t dev) /* Lock is necessary due to assertions. */ sx_init(&sc->sx, "e6000sw"); E6000SW_LOCK(sc); - id = e6000sw_readreg(sc, REG_PORT(0), SWITCH_ID); + E6000SW_UNLOCK(sc); switch (id & 0xfff0) { case 0x3520: @@ -249,7 +230,6 @@ e6000sw_probe(device_t dev) description = "Marvell 88E6176"; break; default: - E6000SW_UNLOCK(sc); sx_destroy(&sc->sx); device_printf(dev, "Unrecognized device, id 0x%x.\n", id); return (ENXIO); @@ -257,8 +237,6 @@ e6000sw_probe(device_t dev) device_set_desc(dev, description); - E6000SW_UNLOCK(sc); - return (BUS_PROBE_DEFAULT); } @@ -433,9 +411,9 @@ e6000sw_poll_done(e6000sw_softc_t *sc) { int i; - for (i = 0; i < 16; i++) { + for (i = 0; i < E6000SW_SMI_TIMEOUT; i++) { - if (!(e6000sw_readreg(sc, REG_GLOBAL2, PHY_CMD) & + if (!(e6000sw_readreg(sc, REG_GLOBAL2, SMI_PHY_CMD_REG) & (1 << PHY_CMD_SMI_BUSY))) return (0); @@ -457,8 +435,6 @@ e6000sw_readphy(device_t dev, int phy, int reg) int err; sc = device_get_softc(dev); - val = 0; - if (!e6000sw_is_phyport(sc, phy) || reg >= E6000SW_NUM_PHY_REGS) { device_printf(dev, "Wrong register address.\n"); return (EINVAL); @@ -472,7 +448,7 @@ e6000sw_readphy(device_t dev, int phy, int reg) return (err); } - val |= 1 << PHY_CMD_SMI_BUSY; + val = 1 << PHY_CMD_SMI_BUSY; val |= PHY_CMD_MODE_MDIO << PHY_CMD_MODE; val |= PHY_CMD_OPCODE_READ << PHY_CMD_OPCODE; val |= (reg << PHY_CMD_REG_ADDR) & PHY_CMD_REG_ADDR_MASK; @@ -485,10 +461,9 @@ e6000sw_readphy(device_t dev, int phy, int reg) return (err); } - val = e6000sw_readreg(sc, REG_GLOBAL2, SMI_PHY_DATA_REG) - & PHY_DATA_MASK; + val = e6000sw_readreg(sc, REG_GLOBAL2, SMI_PHY_DATA_REG); - return (val); + return (val & PHY_DATA_MASK); } static int @@ -499,8 +474,6 @@ e6000sw_writephy(device_t dev, int phy, int reg, int data) int err; sc = device_get_softc(dev); - val = 0; - if (!e6000sw_is_phyport(sc, phy) || reg >= E6000SW_NUM_PHY_REGS) { device_printf(dev, "Wrong register address.\n"); return (EINVAL); @@ -514,22 +487,20 @@ e6000sw_writephy(device_t dev, int phy, int reg, int data) return (err); } + val = 1 << PHY_CMD_SMI_BUSY; val |= PHY_CMD_MODE_MDIO << PHY_CMD_MODE; - val |= 1 << PHY_CMD_SMI_BUSY; val |= PHY_CMD_OPCODE_WRITE << PHY_CMD_OPCODE; val |= (reg << PHY_CMD_REG_ADDR) & PHY_CMD_REG_ADDR_MASK; val |= (phy << PHY_CMD_DEV_ADDR) & PHY_CMD_DEV_ADDR_MASK; e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_DATA_REG, - data & PHY_DATA_MASK); + data & PHY_DATA_MASK); e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_CMD_REG, val); err = e6000sw_poll_done(sc); - if (err != 0) { + if (err != 0) device_printf(dev, "Timeout while waiting for switch\n"); - return (err); - } - return (0); + return (err); } static int @@ -589,18 +560,14 @@ e6000sw_getport(device_t dev, etherswitch_port_t *p) int err; struct ifmediareq *ifmr; - err = 0; e6000sw_softc_t *sc = device_get_softc(dev); E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED); + if (p->es_port >= sc->num_ports || p->es_port < 0) + return (EINVAL); + + err = 0; E6000SW_LOCK(sc); - - if (p->es_port >= sc->num_ports || - p->es_port < 0) { - err = EINVAL; - goto out; - } - e6000sw_get_pvid(sc, p->es_port, &p->es_pvid); if (e6000sw_is_cpuport(sc, p->es_port)) { @@ -623,9 +590,8 @@ e6000sw_getport(device_t dev, etherswitch_port_t *p) err = ifmedia_ioctl(mii->mii_ifp, &p->es_ifr, &mii->mii_media, SIOCGIFMEDIA); } - -out: E6000SW_UNLOCK(sc); + return (err); } @@ -636,18 +602,14 @@ e6000sw_setport(device_t dev, etherswitch_port_t *p) int err; struct mii_data *mii; - err = 0; sc = device_get_softc(dev); E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED); + if (p->es_port >= sc->num_ports || p->es_port < 0) + return (EINVAL); + + err = 0; E6000SW_LOCK(sc); - - if (p->es_port >= sc->num_ports || - p->es_port < 0) { - err = EINVAL; - goto out; - } - if (p->es_pvid != 0) e6000sw_set_pvid(sc, p->es_port, p->es_pvid); if (!e6000sw_is_cpuport(sc, p->es_port)) { @@ -655,9 +617,8 @@ e6000sw_setport(device_t dev, etherswitch_port_t *p) err = ifmedia_ioctl(mii->mii_ifp, &p->es_ifr, &mii->mii_media, SIOCSIFMEDIA); } - -out: E6000SW_UNLOCK(sc); + return (err); } @@ -773,12 +734,10 @@ e6000sw_flush_port(e6000sw_softc_t *sc, int port) { uint32_t reg; - reg = e6000sw_readreg(sc, REG_PORT(port), - PORT_VLAN_MAP); + reg = e6000sw_readreg(sc, REG_PORT(port), PORT_VLAN_MAP); reg &= ~PORT_VLAN_MAP_TABLE_MASK; reg &= ~PORT_VLAN_MAP_FID_MASK; - e6000sw_writereg(sc, REG_PORT(port), - PORT_VLAN_MAP, reg); + e6000sw_writereg(sc, REG_PORT(port), PORT_VLAN_MAP, reg); if (sc->vgroup[port] != E6000SW_PORT_NO_VGROUP) { /* * If port belonged somewhere, owner-group @@ -795,14 +754,12 @@ e6000sw_port_assign_vgroup(e6000sw_softc_t *sc, int port, int fid, int vgroup, { uint32_t reg; - reg = e6000sw_readreg(sc, REG_PORT(port), - PORT_VLAN_MAP); + reg = e6000sw_readreg(sc, REG_PORT(port), PORT_VLAN_MAP); reg &= ~PORT_VLAN_MAP_TABLE_MASK; reg &= ~PORT_VLAN_MAP_FID_MASK; reg |= members & ~(1 << port); reg |= (fid << PORT_VLAN_MAP_FID) & PORT_VLAN_MAP_FID_MASK; - e6000sw_writereg(sc, REG_PORT(port), PORT_VLAN_MAP, - reg); + e6000sw_writereg(sc, REG_PORT(port), PORT_VLAN_MAP, reg); sc->vgroup[port] = vgroup; } @@ -897,19 +854,18 @@ e6000sw_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) ifmr->ifm_status = mii->mii_media_status; } - static int e6000sw_smi_waitready(e6000sw_softc_t *sc, int phy) { int i; for (i = 0; i < E6000SW_SMI_TIMEOUT; i++) { - if ((MDIO_READ(sc->dev, phy, SMI_CMD) - & SMI_CMD_BUSY) == 0) - return 0; + if ((MDIO_READ(sc->dev, phy, SMI_CMD) & SMI_CMD_BUSY) == 0) + return (0); + DELAY(1); } - return 1; + return (1); } static __inline uint32_t @@ -925,8 +881,8 @@ e6000sw_readreg(e6000sw_softc_t *sc, int addr, int reg) printf("e6000sw: readreg timeout\n"); return (0xffff); } - MDIO_WRITE(sc->dev, sc->sw_addr, SMI_CMD, SMI_CMD_OP_READ | - (addr << 5) | reg); + MDIO_WRITE(sc->dev, sc->sw_addr, SMI_CMD, + SMI_CMD_OP_READ | (addr << 5) | reg); if (e6000sw_smi_waitready(sc, sc->sw_addr)) { printf("e6000sw: readreg timeout\n"); return (0xffff); @@ -951,14 +907,12 @@ e6000sw_writereg(e6000sw_softc_t *sc, int addr, int reg, int val) return; } MDIO_WRITE(sc->dev, sc->sw_addr, SMI_DATA, val); - MDIO_WRITE(sc->dev, sc->sw_addr, SMI_CMD, SMI_CMD_OP_WRITE | - (addr << 5) | reg); + MDIO_WRITE(sc->dev, sc->sw_addr, SMI_CMD, + SMI_CMD_OP_WRITE | (addr << 5) | reg); if (e6000sw_smi_waitready(sc, sc->sw_addr)) { printf("e6000sw: readreg timeout\n"); return; } - - return; } static __inline int diff --git a/sys/dev/etherswitch/e6000sw/e6000swreg.h b/sys/dev/etherswitch/e6000sw/e6000swreg.h index d8206eac4519..4a7da579f39a 100644 --- a/sys/dev/etherswitch/e6000sw/e6000swreg.h +++ b/sys/dev/etherswitch/e6000sw/e6000swreg.h @@ -155,8 +155,6 @@ struct atu_opt { #define SMI_PHY_CMD_REG 0x18 #define SMI_PHY_DATA_REG 0x19 -#define PHY_CMD 0x18 -#define PHY_DATA 0x19 #define PHY_DATA_MASK 0xffff #define PHY_CMD_SMI_BUSY 15 From d04e6601fa9cc0c4e26e477215823c646b35b853 Mon Sep 17 00:00:00 2001 From: Edward Tomasz Napierala Date: Fri, 2 Jun 2017 15:32:11 +0000 Subject: [PATCH 12/45] Consistently use lowercase hex numbers in ascii(7). MFC after: 2 weeks --- share/man/man7/ascii.7 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/man/man7/ascii.7 b/share/man/man7/ascii.7 index 4d359f3c98cd..586a5374b6b3 100644 --- a/share/man/man7/ascii.7 +++ b/share/man/man7/ascii.7 @@ -64,9 +64,9 @@ The set: .Bd -literal -offset left 00 NUL 01 SOH 02 STX 03 ETX 04 EOT 05 ENQ 06 ACK 07 BEL -08 BS 09 HT 0A LF 0B VT 0C FF 0D CR 0E SO 0F SI +08 BS 09 HT 0a LF 0b VT 0c FF 0d CR 0e SO 0f SI 10 DLE 11 DC1 12 DC2 13 DC3 14 DC4 15 NAK 16 SYN 17 ETB -18 CAN 19 EM 1A SUB 1B ESC 1C FS 1D GS 1E RS 1F US +18 CAN 19 EM 1a SUB 1b ESC 1c FS 1d GS 1e RS 1f US 20 SP 21 ! 22 " 23 # 24 $ 25 % 26 & 27 ' 28 ( 29 ) 2a * 2b + 2c , 2d - 2e . 2f / 30 0 31 1 32 2 33 3 34 4 35 5 36 6 37 7 From 639af71ab14785fb12e6fd1a9abf428828166bab Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Fri, 2 Jun 2017 16:30:40 +0000 Subject: [PATCH 13/45] Add support for setting the non-blocking I/O flag for LinuxKPI character devices. In Linux the FIONBIO IOCTL is handled by the kernel and not the drivers. Also need return success for the FIOASYNC ioctl due to existing logic in kern_fcntl() even though it is not supported currently. MFC after: 1 week Sponsored by: Mellanox Technologies --- sys/compat/linuxkpi/common/src/linux_compat.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index 7bf098bf490c..6e0cfd958b5b 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -826,6 +826,10 @@ linux_dev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, return (error); filp->f_flags = file->f_flag; + /* the LinuxKPI supports blocking and non-blocking I/O */ + if (cmd == FIONBIO || cmd == FIOASYNC) + return (0); + linux_set_current(td); size = IOCPARM_LEN(cmd); /* refer to logic in sys_ioctl() */ From 67e984c8f2148c6150ec0f86829aca9b8ac5c2ff Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Fri, 2 Jun 2017 16:52:18 +0000 Subject: [PATCH 14/45] Improve kqueue() support in the LinuxKPI. Some applications using the kqueue() does not set non-blocking I/O mode for event driven read of file descriptors. This means the LinuxKPI internal kqueue read and write event flags must be updated before the next read and/or write system call. Else the read and/or write system call may block. This can happen when there is no more data to read following a previous read event. Then the application also gets blocked from processing other events. This situation can also be solved by the applications setting and using non-blocking I/O mode. MFC after: 1 week Sponsored by: Mellanox Technologies --- sys/compat/linuxkpi/common/src/linux_compat.c | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index 6e0cfd958b5b..2606030d9d5a 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -438,7 +438,7 @@ linux_kq_lock_unowned(void *arg) } static void -linux_dev_kqfilter_poll(struct linux_file *); +linux_dev_kqfilter_poll(struct linux_file *, int); struct linux_file * linux_file_alloc(void) @@ -856,9 +856,11 @@ linux_dev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, current->bsd_ioctl_len = 0; } - if (error == EWOULDBLOCK) - linux_dev_kqfilter_poll(filp); - else if (error == ERESTARTSYS) + if (error == EWOULDBLOCK) { + /* update kqfilter status, if any */ + linux_dev_kqfilter_poll(filp, + LINUX_KQ_FLAG_HAS_READ | LINUX_KQ_FLAG_HAS_WRITE); + } else if (error == ERESTARTSYS) error = ERESTART; return (error); } @@ -893,14 +895,15 @@ linux_dev_read(struct cdev *dev, struct uio *uio, int ioflag) uio->uio_resid -= bytes; } else { error = -bytes; - if (error == EWOULDBLOCK) - linux_dev_kqfilter_poll(filp); - else if (error == ERESTARTSYS) + if (error == ERESTARTSYS) error = ERESTART; } } else error = ENXIO; + /* update kqfilter status, if any */ + linux_dev_kqfilter_poll(filp, LINUX_KQ_FLAG_HAS_READ); + return (error); } @@ -934,14 +937,15 @@ linux_dev_write(struct cdev *dev, struct uio *uio, int ioflag) uio->uio_resid -= bytes; } else { error = -bytes; - if (error == EWOULDBLOCK) - linux_dev_kqfilter_poll(filp); - else if (error == ERESTARTSYS) + if (error == ERESTARTSYS) error = ERESTART; } } else error = ENXIO; + /* update kqfilter status, if any */ + linux_dev_kqfilter_poll(filp, LINUX_KQ_FLAG_HAS_WRITE); + return (error); } @@ -1032,21 +1036,20 @@ static struct filterops linux_dev_kqfiltops_write = { }; static void -linux_dev_kqfilter_poll(struct linux_file *filp) +linux_dev_kqfilter_poll(struct linux_file *filp, int kqflags) { int temp; - spin_lock(&filp->f_kqlock); - temp = (filp->f_kqflags & (LINUX_KQ_FLAG_HAS_READ | LINUX_KQ_FLAG_HAS_WRITE)); - filp->f_kqflags &= ~(LINUX_KQ_FLAG_NEED_READ | LINUX_KQ_FLAG_NEED_WRITE); - spin_unlock(&filp->f_kqlock); - - if (temp != 0) { + if (filp->f_kqflags & kqflags) { /* get the latest polling state */ temp = filp->f_op->poll(filp, NULL); + spin_lock(&filp->f_kqlock); + /* clear kqflags */ + filp->f_kqflags &= ~(LINUX_KQ_FLAG_NEED_READ | + LINUX_KQ_FLAG_NEED_WRITE); + /* update kqflags */ if (temp & (POLLIN | POLLOUT)) { - spin_lock(&filp->f_kqlock); if (temp & POLLIN) filp->f_kqflags |= LINUX_KQ_FLAG_NEED_READ; if (temp & POLLOUT) @@ -1054,8 +1057,8 @@ linux_dev_kqfilter_poll(struct linux_file *filp) /* make sure the "knote" gets woken up */ KNOTE_LOCKED(&filp->f_selinfo.si_note, 0); - spin_unlock(&filp->f_kqlock); } + spin_unlock(&filp->f_kqlock); } } @@ -1099,7 +1102,10 @@ linux_dev_kqfilter(struct cdev *dev, struct knote *kn) if (error == 0) { linux_set_current(td); - linux_dev_kqfilter_poll(filp); + + /* update kqfilter status, if any */ + linux_dev_kqfilter_poll(filp, + LINUX_KQ_FLAG_HAS_READ | LINUX_KQ_FLAG_HAS_WRITE); } return (error); } From 0c3c207ffd5da278bb3b2e00528ba926042bcd6e Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Fri, 2 Jun 2017 17:31:25 +0000 Subject: [PATCH 15/45] For UNIX sockets make vnode point not to the socket, but to the UNIX PCB, since the latter is the thing that links together VFS and sockets. While here, make the union in the struct vnode anonymous. --- sys/kern/uipc_usrreq.c | 16 +++++----------- sys/kern/vfs_default.c | 6 +++--- sys/kern/vfs_subr.c | 5 ++++- sys/kern/vnode_if.src | 4 ++-- sys/sys/vnode.h | 18 ++++++------------ 5 files changed, 20 insertions(+), 29 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index ada9080c623d..d4649a759fc7 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -552,7 +552,7 @@ uipc_bindat(int fd, struct socket *so, struct sockaddr *nam, struct thread *td) UNP_LINK_WLOCK(); UNP_PCB_LOCK(unp); - VOP_UNP_BIND(vp, unp->unp_socket); + VOP_UNP_BIND(vp, unp); unp->unp_vnode = vp; unp->unp_addr = soun; unp->unp_flags &= ~UNP_BINDING; @@ -670,9 +670,6 @@ uipc_detach(struct socket *so) UNP_LINK_WLOCK(); UNP_PCB_LOCK(unp); - /* - * XXXRW: Should assert vp->v_socket == so. - */ if ((vp = unp->unp_vnode) != NULL) { VOP_UNP_DETACH(vp); unp->unp_vnode = NULL; @@ -1386,11 +1383,12 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam, * and to protect simultaneous locking of multiple pcbs. */ UNP_LINK_WLOCK(); - VOP_UNP_CONNECT(vp, &so2); - if (so2 == NULL) { + VOP_UNP_CONNECT(vp, &unp2); + if (unp2 == NULL) { error = ECONNREFUSED; goto bad2; } + so2 = unp2->unp_socket; if (so->so_type != so2->so_type) { error = EPROTOTYPE; goto bad2; @@ -2454,7 +2452,6 @@ unp_scan(struct mbuf *m0, void (*op)(struct filedescent **, int)) void vfs_unp_reclaim(struct vnode *vp) { - struct socket *so; struct unpcb *unp; int active; @@ -2464,10 +2461,7 @@ vfs_unp_reclaim(struct vnode *vp) active = 0; UNP_LINK_WLOCK(); - VOP_UNP_CONNECT(vp, &so); - if (so == NULL) - goto done; - unp = sotounpcb(so); + VOP_UNP_CONNECT(vp, &unp); if (unp == NULL) goto done; UNP_PCB_LOCK(unp); diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c index cb8b5635dbd0..5c343e7f3ffc 100644 --- a/sys/kern/vfs_default.c +++ b/sys/kern/vfs_default.c @@ -1128,7 +1128,7 @@ int vop_stdunp_bind(struct vop_unp_bind_args *ap) { - ap->a_vp->v_socket = ap->a_socket; + ap->a_vp->v_unpcb = ap->a_unpcb; return (0); } @@ -1136,7 +1136,7 @@ int vop_stdunp_connect(struct vop_unp_connect_args *ap) { - *ap->a_socket = ap->a_vp->v_socket; + *ap->a_unpcb = ap->a_vp->v_unpcb; return (0); } @@ -1144,7 +1144,7 @@ int vop_stdunp_detach(struct vop_unp_detach_args *ap) { - ap->a_vp->v_socket = NULL; + ap->a_vp->v_unpcb = NULL; return (0); } diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 2ca95a8bbb34..afe4553cdc09 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -2994,7 +2994,10 @@ _vdrop(struct vnode *vp, bool locked) /* XXX Elsewhere we detect an already freed vnode via NULL v_op. */ vp->v_op = NULL; #endif - bzero(&vp->v_un, sizeof(vp->v_un)); + vp->v_mountedhere = NULL; + vp->v_unpcb = NULL; + vp->v_rdev = NULL; + vp->v_fifoinfo = NULL; vp->v_lasta = vp->v_clen = vp->v_cstart = vp->v_lastw = 0; vp->v_iflag = 0; vp->v_vflag = 0; diff --git a/sys/kern/vnode_if.src b/sys/kern/vnode_if.src index a6782fab32c5..30f5d752f62b 100644 --- a/sys/kern/vnode_if.src +++ b/sys/kern/vnode_if.src @@ -662,7 +662,7 @@ vop_advise { vop_unp_bind { IN struct vnode *vp; - IN struct socket *socket; + IN struct unpcb *unpcb; }; @@ -670,7 +670,7 @@ vop_unp_bind { vop_unp_connect { IN struct vnode *vp; - OUT struct socket **socket; + OUT struct unpcb **unpcb; }; diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 2e45ede7598e..7738341ae438 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -112,14 +112,13 @@ struct vnode { /* * Type specific fields, only one applies to any given vnode. - * See #defines below for renaming to v_* namespace. */ union { - struct mount *vu_mount; /* v ptr to mountpoint (VDIR) */ - struct socket *vu_socket; /* v unix domain net (VSOCK) */ - struct cdev *vu_cdev; /* v device (VCHR, VBLK) */ - struct fifoinfo *vu_fifoinfo; /* v fifo (VFIFO) */ - } v_un; + struct mount *v_mountedhere; /* v ptr to mountpoint (VDIR) */ + struct unpcb *v_unpcb; /* v unix domain net (VSOCK) */ + struct cdev *v_rdev; /* v device (VCHR, VBLK) */ + struct fifoinfo *v_fifoinfo; /* v fifo (VFIFO) */ + }; /* * vfs_hash: (mount + inode) -> vnode hash. The hash value @@ -175,11 +174,6 @@ struct vnode { #endif /* defined(_KERNEL) || defined(_KVM_VNODE) */ -#define v_mountedhere v_un.vu_mount -#define v_socket v_un.vu_socket -#define v_rdev v_un.vu_cdev -#define v_fifoinfo v_un.vu_fifoinfo - #define bo2vnode(bo) __containerof((bo), struct vnode, v_bufobj) /* XXX: These are temporary to avoid a source sweep at this time */ @@ -200,7 +194,7 @@ struct xvnode { long xv_numoutput; /* num of writes in progress */ enum vtype xv_type; /* vnode type */ union { - void *xvu_socket; /* socket, if VSOCK */ + void *xvu_socket; /* unpcb, if VSOCK */ void *xvu_fifo; /* fifo, if VFIFO */ dev_t xvu_rdev; /* maj/min, if VBLK/VCHR */ struct { From bd617e3b9887650446f7c75bb79497db9c517f33 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Fri, 2 Jun 2017 17:39:05 +0000 Subject: [PATCH 16/45] Remove write only flag UNP_HAVEPCCACHED. --- sys/kern/uipc_usrreq.c | 7 ------- sys/sys/unpcb.h | 6 ------ 2 files changed, 13 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index d4649a759fc7..1d396bab2f87 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -758,7 +758,6 @@ uipc_listen(struct socket *so, int backlog, struct thread *td) error = solisten_proto_check(so); if (error == 0) { cru2x(td->td_ucred, &unp->unp_peercred); - unp->unp_flags |= UNP_HAVEPCCACHED; solisten_proto(so, backlog); } SOCK_UNLOCK(so); @@ -1429,8 +1428,6 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam, * listen(); uipc_listen() cached that process's credentials * at that time so we can use them now. */ - KASSERT(unp2->unp_flags & UNP_HAVEPCCACHED, - ("unp_connect: listener without cached peercred")); memcpy(&unp->unp_peercred, &unp2->unp_peercred, sizeof(unp->unp_peercred)); unp->unp_flags |= UNP_HAVEPC; @@ -2497,10 +2494,6 @@ db_print_unpflags(int unp_flags) db_printf("%sUNP_HAVEPC", comma ? ", " : ""); comma = 1; } - if (unp_flags & UNP_HAVEPCCACHED) { - db_printf("%sUNP_HAVEPCCACHED", comma ? ", " : ""); - comma = 1; - } if (unp_flags & UNP_WANTCRED) { db_printf("%sUNP_WANTCRED", comma ? ", " : ""); comma = 1; diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h index a1194ca79783..f18786553de4 100644 --- a/sys/sys/unpcb.h +++ b/sys/sys/unpcb.h @@ -92,14 +92,8 @@ struct unpcb { * and is really the credentials of the connected peer. This is used * to determine whether the contents should be sent to the user or * not. - * - * UNP_HAVEPCCACHED - indicates that the unp_peercred member is filled - * in, but does *not* contain the credentials of the connected peer - * (there may not even be a peer). This is set in unp_listen() when - * it fills in unp_peercred for later consumption by unp_connect(). */ #define UNP_HAVEPC 0x001 -#define UNP_HAVEPCCACHED 0x002 #define UNP_WANTCRED 0x004 /* credentials wanted */ #define UNP_CONNWAIT 0x008 /* connect blocks until accepted */ From 810951ddc937da2334f3f2459393e4d2439292c1 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Fri, 2 Jun 2017 17:43:47 +0000 Subject: [PATCH 17/45] Style: unwrap lines that doesn't have a good reason to be wrapped. --- sys/kern/uipc_accf.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/sys/kern/uipc_accf.c b/sys/kern/uipc_accf.c index aa9ed741d905..3982b6172e0f 100644 --- a/sys/kern/uipc_accf.c +++ b/sys/kern/uipc_accf.c @@ -130,8 +130,7 @@ accept_filt_generic_mod_event(module_t mod, int event, void *data) switch (event) { case MOD_LOAD: - p = malloc(sizeof(*p), M_ACCF, - M_WAITOK); + p = malloc(sizeof(*p), M_ACCF, M_WAITOK); bcopy(accfp, p, sizeof(*p)); error = accept_filt_add(p); break; @@ -168,8 +167,7 @@ do_getopt_accept_filter(struct socket *so, struct sockopt *sopt) int error; error = 0; - afap = malloc(sizeof(*afap), M_TEMP, - M_WAITOK | M_ZERO); + afap = malloc(sizeof(*afap), M_TEMP, M_WAITOK | M_ZERO); SOCK_LOCK(so); if ((so->so_options & SO_ACCEPTCONN) == 0) { error = EINVAL; @@ -227,8 +225,7 @@ do_setopt_accept_filter(struct socket *so, struct sockopt *sopt) * Pre-allocate any memory we may need later to avoid blocking at * untimely moments. This does not optimize for invalid arguments. */ - afap = malloc(sizeof(*afap), M_TEMP, - M_WAITOK); + afap = malloc(sizeof(*afap), M_TEMP, M_WAITOK); error = sooptcopyin(sopt, afap, sizeof *afap, sizeof *afap); afap->af_name[sizeof(afap->af_name)-1] = '\0'; afap->af_arg[sizeof(afap->af_arg)-1] = '\0'; @@ -247,12 +244,10 @@ do_setopt_accept_filter(struct socket *so, struct sockopt *sopt) * attached properly, 'newaf' is NULLed to avoid a free() * while in use. */ - newaf = malloc(sizeof(*newaf), M_ACCF, M_WAITOK | - M_ZERO); + newaf = malloc(sizeof(*newaf), M_ACCF, M_WAITOK | M_ZERO); if (afp->accf_create != NULL && afap->af_name[0] != '\0') { size_t len = strlen(afap->af_name) + 1; - newaf->so_accept_filter_str = malloc(len, M_ACCF, - M_WAITOK); + newaf->so_accept_filter_str = malloc(len, M_ACCF, M_WAITOK); strcpy(newaf->so_accept_filter_str, afap->af_name); } From 971af2a3118485b93246ba44ebbd940163005f0c Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Fri, 2 Jun 2017 17:49:21 +0000 Subject: [PATCH 18/45] Rename accept filter getopt/setopt functions, so that they are prefixed with module name and match other functions in the module. There is no functional change. --- sys/kern/uipc_accf.c | 4 ++-- sys/kern/uipc_socket.c | 6 +++--- sys/sys/sockopt.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sys/kern/uipc_accf.c b/sys/kern/uipc_accf.c index 3982b6172e0f..3b85f9113860 100644 --- a/sys/kern/uipc_accf.c +++ b/sys/kern/uipc_accf.c @@ -161,7 +161,7 @@ accept_filt_generic_mod_event(module_t mod, int event, void *data) } int -do_getopt_accept_filter(struct socket *so, struct sockopt *sopt) +accept_filt_getopt(struct socket *so, struct sockopt *sopt) { struct accept_filter_arg *afap; int error; @@ -189,7 +189,7 @@ do_getopt_accept_filter(struct socket *so, struct sockopt *sopt) } int -do_setopt_accept_filter(struct socket *so, struct sockopt *sopt) +accept_filt_setopt(struct socket *so, struct sockopt *sopt) { struct accept_filter_arg *afap; struct accept_filter *afp; diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 0384b966b513..17118aee5bce 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -452,7 +452,7 @@ sodealloc(struct socket *so) &so->so_snd.sb_hiwat, 0, RLIM_INFINITY); /* remove accept filter if one is present. */ if (so->so_accf != NULL) - do_setopt_accept_filter(so, NULL); + accept_filt_setopt(so, NULL); #ifdef MAC mac_socket_destroy(so); #endif @@ -2526,7 +2526,7 @@ sosetopt(struct socket *so, struct sockopt *sopt) } else { switch (sopt->sopt_name) { case SO_ACCEPTFILTER: - error = do_setopt_accept_filter(so, sopt); + error = accept_filt_setopt(so, sopt); if (error) goto bad; break; @@ -2784,7 +2784,7 @@ sogetopt(struct socket *so, struct sockopt *sopt) } else { switch (sopt->sopt_name) { case SO_ACCEPTFILTER: - error = do_getopt_accept_filter(so, sopt); + error = accept_filt_getopt(so, sopt); break; case SO_LINGER: diff --git a/sys/sys/sockopt.h b/sys/sys/sockopt.h index 4131a5b7cd8c..029e5b4a3518 100644 --- a/sys/sys/sockopt.h +++ b/sys/sys/sockopt.h @@ -64,8 +64,8 @@ int sooptcopyout(struct sockopt *sopt, const void *buf, size_t len); int soopt_getm(struct sockopt *sopt, struct mbuf **mp); int soopt_mcopyin(struct sockopt *sopt, struct mbuf *m); int soopt_mcopyout(struct sockopt *sopt, struct mbuf *m); -int do_getopt_accept_filter(struct socket *so, struct sockopt *sopt); -int do_setopt_accept_filter(struct socket *so, struct sockopt *sopt); +int accept_filt_getopt(struct socket *, struct sockopt *); +int accept_filt_setopt(struct socket *, struct sockopt *); int so_setsockopt(struct socket *so, int level, int optname, void *optval, size_t optlen); From a59a14773a9194e83d2f3c8ec9b6dd58ec2f896b Mon Sep 17 00:00:00 2001 From: Navdeep Parhar Date: Fri, 2 Jun 2017 17:57:27 +0000 Subject: [PATCH 19/45] cxgbe(4): Update the statistics for compound tx work requests once per work request, not once per frame. MFC after: 1 week Sponsored by: Chelsio Communications --- sys/dev/cxgbe/t4_sge.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sys/dev/cxgbe/t4_sge.c b/sys/dev/cxgbe/t4_sge.c index 527bf46f4f8c..b34c02d5cf6e 100644 --- a/sys/dev/cxgbe/t4_sge.c +++ b/sys/dev/cxgbe/t4_sge.c @@ -4581,12 +4581,8 @@ write_txpkts_wr(struct sge_txq *txq, struct fw_eth_tx_pkts_wr *wr, if (checkwrap && (uintptr_t)cpl == (uintptr_t)&eq->desc[eq->sidx]) cpl = (void *)&eq->desc[0]; - txq->txpkts0_pkts += txp->npkt; - txq->txpkts0_wrs++; } else { cpl = flitp; - txq->txpkts1_pkts += txp->npkt; - txq->txpkts1_wrs++; } /* Checksum offload */ @@ -4621,6 +4617,14 @@ write_txpkts_wr(struct sge_txq *txq, struct fw_eth_tx_pkts_wr *wr, } + if (txp->wr_type == 0) { + txq->txpkts0_pkts += txp->npkt; + txq->txpkts0_wrs++; + } else { + txq->txpkts1_pkts += txp->npkt; + txq->txpkts1_wrs++; + } + txsd = &txq->sdesc[eq->pidx]; txsd->m = m0; txsd->desc_used = ndesc; From 6a1c2e1fce683ad48476b14e43f1ef53fd70ce01 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Fri, 2 Jun 2017 18:39:53 +0000 Subject: [PATCH 20/45] msdosfs: use mem{cpy,move,set} instead of bcopy,bzero This somewhat simplifies use of msdosfs code in userland (for makefs), reduces diffs with NetBSD and is standard C as of C89. Reviewed by: imp MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D11014 --- sys/fs/msdosfs/denode.h | 4 ++-- sys/fs/msdosfs/msdosfs_conv.c | 8 ++++---- sys/fs/msdosfs/msdosfs_denode.c | 2 +- sys/fs/msdosfs/msdosfs_fat.c | 2 +- sys/fs/msdosfs/msdosfs_vnops.c | 18 +++++++++--------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/sys/fs/msdosfs/denode.h b/sys/fs/msdosfs/denode.h index dbc4a893e539..7960f20ddf22 100644 --- a/sys/fs/msdosfs/denode.h +++ b/sys/fs/msdosfs/denode.h @@ -179,7 +179,7 @@ struct denode { #define DE_INTERNALIZE32(dep, dp) \ ((dep)->de_StartCluster |= getushort((dp)->deHighClust) << 16) #define DE_INTERNALIZE(dep, dp) \ - (bcopy((dp)->deName, (dep)->de_Name, 11), \ + (memcpy((dep)->de_Name, (dp)->deName, 11), \ (dep)->de_Attributes = (dp)->deAttributes, \ (dep)->de_LowerCase = (dp)->deLowerCase, \ (dep)->de_CHun = (dp)->deCHundredth, \ @@ -193,7 +193,7 @@ struct denode { (FAT32((dep)->de_pmp) ? DE_INTERNALIZE32((dep), (dp)) : 0)) #define DE_EXTERNALIZE(dp, dep) \ - (bcopy((dep)->de_Name, (dp)->deName, 11), \ + (memcpy((dp)->deName, (dep)->de_Name, 11), \ (dp)->deAttributes = (dep)->de_Attributes, \ (dp)->deLowerCase = (dep)->de_LowerCase, \ (dp)->deCHundredth = (dep)->de_CHun, \ diff --git a/sys/fs/msdosfs/msdosfs_conv.c b/sys/fs/msdosfs/msdosfs_conv.c index 6b81f0d17d3f..6d92c60be355 100644 --- a/sys/fs/msdosfs/msdosfs_conv.c +++ b/sys/fs/msdosfs/msdosfs_conv.c @@ -536,7 +536,7 @@ unix2winfn(const u_char *un, size_t unlen, struct winentry *wep, int cnt, /* * Initialize winentry to some useful default */ - for (wcp = (uint8_t *)wep, i = sizeof(*wep); --i >= 0; *wcp++ = 0xff); + memset(wep, 0xff, sizeof(*wep)); wep->weCnt = cnt; wep->weAttributes = ATTR_WIN95; wep->weReserved1 = 0; @@ -1043,11 +1043,11 @@ mbnambuf_write(struct mbnambuf *nbp, char *name, int id) sizeof(nbp->nb_buf)) return (ENAMETOOLONG); - bcopy(slot + WIN_CHARS, slot + count, nbp->nb_len); + memmove(slot + count, slot + WIN_CHARS, nbp->nb_len); } /* Copy in the substring to its slot and update length so far. */ - bcopy(name, slot, count); + memcpy(slot, name, count); nbp->nb_len = newlen; nbp->nb_last_id = id; @@ -1069,7 +1069,7 @@ mbnambuf_flush(struct mbnambuf *nbp, struct dirent *dp) mbnambuf_init(nbp); return (NULL); } - bcopy(&nbp->nb_buf[0], dp->d_name, nbp->nb_len); + memcpy(dp->d_name, &nbp->nb_buf[0], nbp->nb_len); dp->d_name[nbp->nb_len] = '\0'; dp->d_namlen = nbp->nb_len; diff --git a/sys/fs/msdosfs/msdosfs_denode.c b/sys/fs/msdosfs/msdosfs_denode.c index 51f6fe8b8ea8..4b1f0c70472b 100644 --- a/sys/fs/msdosfs/msdosfs_denode.c +++ b/sys/fs/msdosfs/msdosfs_denode.c @@ -410,7 +410,7 @@ detrunc(struct denode *dep, u_long length, int flags, struct ucred *cred) #endif return (error); } - bzero(bp->b_data + boff, pmp->pm_bpcluster - boff); + memset(bp->b_data + boff, 0, pmp->pm_bpcluster - boff); if (flags & IO_SYNC) bwrite(bp); else diff --git a/sys/fs/msdosfs/msdosfs_fat.c b/sys/fs/msdosfs/msdosfs_fat.c index 72584663213c..6f5786cda567 100644 --- a/sys/fs/msdosfs/msdosfs_fat.c +++ b/sys/fs/msdosfs/msdosfs_fat.c @@ -335,7 +335,7 @@ updatefats(struct msdosfsmount *pmp, struct buf *bp, u_long fatbn) /* getblk() never fails */ bpn = getblk(pmp->pm_devvp, fatbn, bp->b_bcount, 0, 0, 0); - bcopy(bp->b_data, bpn->b_data, bp->b_bcount); + memcpy(bpn->b_data, bp->b_data, bp->b_bcount); /* Force the clean bit on in the other copies. */ if (cleanfat == 16) ((uint8_t *)bpn->b_data)[3] |= 0x80; diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c index fb04bf3b5c16..db6add7ce528 100644 --- a/sys/fs/msdosfs/msdosfs_vnops.c +++ b/sys/fs/msdosfs/msdosfs_vnops.c @@ -165,7 +165,7 @@ msdosfs_create(struct vop_create_args *ap) if ((cnp->cn_flags & HASBUF) == 0) panic("msdosfs_create: no name"); #endif - bzero(&ndirent, sizeof(ndirent)); + memset(&ndirent, 0, sizeof(ndirent)); error = uniqdosname(pdep, cnp, ndirent.de_Name); if (error) goto bad; @@ -1156,13 +1156,13 @@ msdosfs_rename(struct vop_rename_args *ap) * we moved a directory, then update its .. entry to point * to the new parent directory. */ - bcopy(ip->de_Name, oldname, 11); - bcopy(toname, ip->de_Name, 11); /* update denode */ + memcpy(oldname, ip->de_Name, 11); + memcpy(ip->de_Name, toname, 11); /* update denode */ dp->de_fndoffset = to_diroffset; dp->de_fndcnt = to_count; error = createde(ip, dp, (struct denode **)0, tcnp); if (error) { - bcopy(oldname, ip->de_Name, 11); + memcpy(ip->de_Name, oldname, 11); if (newparent) VOP_UNLOCK(fdvp, 0); VOP_UNLOCK(fvp, 0); @@ -1178,7 +1178,7 @@ msdosfs_rename(struct vop_rename_args *ap) * to pass the correct name to createde(). Undo this. */ if ((ip->de_Attributes & ATTR_DIRECTORY) != 0) - bcopy(oldname, ip->de_Name, 11); + memcpy(ip->de_Name, oldname, 11); ip->de_refcnt++; zp->de_fndoffset = from_diroffset; error = removede(zp, ip); @@ -1324,7 +1324,7 @@ msdosfs_mkdir(struct vop_mkdir_args *ap) if (error) goto bad2; - bzero(&ndirent, sizeof(ndirent)); + memset(&ndirent, 0, sizeof(ndirent)); ndirent.de_pmp = pmp; ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE; getnanotime(&ts); @@ -1338,8 +1338,8 @@ msdosfs_mkdir(struct vop_mkdir_args *ap) bn = cntobn(pmp, newcluster); /* always succeeds */ bp = getblk(pmp->pm_devvp, bn, pmp->pm_bpcluster, 0, 0, 0); - bzero(bp->b_data, pmp->pm_bpcluster); - bcopy(&dosdirtemplate, bp->b_data, sizeof dosdirtemplate); + memset(bp->b_data, 0, pmp->pm_bpcluster); + memcpy(bp->b_data, &dosdirtemplate, sizeof dosdirtemplate); denp = (struct direntry *)bp->b_data; putushort(denp[0].deStartCluster, newcluster); putushort(denp[0].deCDate, ndirent.de_CDate); @@ -1504,7 +1504,7 @@ msdosfs_readdir(struct vop_readdir_args *ap) /* * To be safe, initialize dirbuf */ - bzero(dirbuf.d_name, sizeof(dirbuf.d_name)); + memset(dirbuf.d_name, 0, sizeof(dirbuf.d_name)); /* * If the user buffer is smaller than the size of one dos directory From e2005cef7fae8dfde46aae0f2e334c574b043162 Mon Sep 17 00:00:00 2001 From: "Stephen J. Kiernan" Date: Fri, 2 Jun 2017 20:25:25 +0000 Subject: [PATCH 21/45] Fix a memory leak with last free memory allocated to 'buf' Submitted by: Thomas Rix Reviewed by: ed Approved by: sjg (mentor) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D9850 --- usr.bin/last/last.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.bin/last/last.c b/usr.bin/last/last.c index ba1f54aa95c4..2ca43d76df5a 100644 --- a/usr.bin/last/last.c +++ b/usr.bin/last/last.c @@ -243,7 +243,7 @@ wtmp(void) /* Display them in reverse order. */ while (amount > 0) doentry(&buf[--amount]); - + free(buf); tm = localtime(&t); (void) strftime(ct, sizeof(ct), "%+", tm); printf("\n%s begins %s\n", ((file == NULL) ? "utx.log" : file), ct); From ebb2cc40d1f62e204166a72f9141416c16c11210 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Fri, 2 Jun 2017 22:35:18 +0000 Subject: [PATCH 22/45] Decode the argument passed to cap_getmode(). The returned integer value is output. --- usr.bin/truss/syscall.h | 2 +- usr.bin/truss/syscalls.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/usr.bin/truss/syscall.h b/usr.bin/truss/syscall.h index f0b39b468bbf..6c6babb5b241 100644 --- a/usr.bin/truss/syscall.h +++ b/usr.bin/truss/syscall.h @@ -48,7 +48,7 @@ enum Argtype { None = 1, Hex, Octal, Int, UInt, LongHex, Name, Ptr, Stat, Ioctl, Sysarch, ExecArgs, ExecEnv, PipeFds, QuadHex, Utrace, IntArray, Pipe2, CapFcntlRights, Fadvice, FileFlags, Flockop, Getfsstatmode, Kldsymcmd, Kldunloadflags, Sizet, Madvice, Socklent, Sockprotocol, Sockoptlevel, - Sockoptname, Msgflags, CapRights, + Sockoptname, Msgflags, CapRights, PUInt, CloudABIAdvice, CloudABIClockID, ClouduABIFDSFlags, CloudABIFDStat, CloudABIFileStat, CloudABIFileType, diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index f8c1943125ec..f4195642276d 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -99,6 +99,8 @@ static struct syscall decoded_syscalls[] = { .args = { { Int, 0 }, { CapFcntlRights | OUT, 1 } } }, { .name = "cap_fcntls_limit", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { CapFcntlRights, 1 } } }, + { .name = "cap_getmode", .ret_type = 1, .nargs = 1, + .args = { { PUInt | OUT, 0 } } }, { .name = "cap_rights_limit", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { CapRights, 1 } } }, { .name = "chdir", .ret_type = 1, .nargs = 1, @@ -1190,6 +1192,16 @@ print_arg(struct syscall_args *sc, unsigned long *args, long *retval, case UInt: fprintf(fp, "%u", (unsigned int)args[sc->offset]); break; + case PUInt: { + unsigned int val; + + if (get_struct(pid, (void *)args[sc->offset], &val, + sizeof(val)) == 0) + fprintf(fp, "{ %u }", val); + else + fprintf(fp, "0x%lx", args[sc->offset]); + break; + } case LongHex: fprintf(fp, "0x%lx", args[sc->offset]); break; From 953111c9c536daf5304062914c0083cea5efb46b Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Sat, 3 Jun 2017 02:42:49 +0000 Subject: [PATCH 23/45] xz: set noexec stack flag on FreeBSD Will also be proposed upstream. Reviewed by: delphij Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D11033 --- contrib/xz/src/liblzma/check/crc32_x86.S | 2 +- contrib/xz/src/liblzma/check/crc64_x86.S | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/xz/src/liblzma/check/crc32_x86.S b/contrib/xz/src/liblzma/check/crc32_x86.S index 67f68a4145f8..1ef7f7e37ae9 100644 --- a/contrib/xz/src/liblzma/check/crc32_x86.S +++ b/contrib/xz/src/liblzma/check/crc32_x86.S @@ -299,6 +299,6 @@ LZMA_CRC32: * use __linux__ here, but I don't know a way to detect when * we are using GNU assembler. */ -#if defined(__ELF__) && defined(__linux__) +#if defined(__ELF__) && (defined(__FreeBSD__) || defined(__linux__)) .section .note.GNU-stack,"",@progbits #endif diff --git a/contrib/xz/src/liblzma/check/crc64_x86.S b/contrib/xz/src/liblzma/check/crc64_x86.S index f5bb84b97e0a..81e06261e0f2 100644 --- a/contrib/xz/src/liblzma/check/crc64_x86.S +++ b/contrib/xz/src/liblzma/check/crc64_x86.S @@ -282,6 +282,6 @@ LZMA_CRC64: * use __linux__ here, but I don't know a way to detect when * we are using GNU assembler. */ -#if defined(__ELF__) && defined(__linux__) +#if defined(__ELF__) && (defined(__FreeBSD__) || defined(__linux__)) .section .note.GNU-stack,"",@progbits #endif From 873ed6f0081629cae9b70bfeb8dd898de5975811 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Sat, 3 Jun 2017 03:40:11 +0000 Subject: [PATCH 24/45] linux vdso: pass -fPIC to the assembler, not linker -fPIC has no effect on linking although it seems to be ignored by GNU ld.bfd. However, it causes ld.lld to terminate with an invalid argument error. This is equivalent to r296057 but for the kernel (not modules) case. MFC after: 2 months Sponsored by: The FreeBSD Foundation --- sys/conf/files.amd64 | 2 +- sys/conf/files.i386 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64 index b50f5fe0ffea..13f2ae822c2d 100644 --- a/sys/conf/files.amd64 +++ b/sys/conf/files.amd64 @@ -46,7 +46,7 @@ linux32_assym.h optional compat_linux32 \ # linux32_locore.o optional compat_linux32 \ dependency "linux32_assym.h $S/amd64/linux32/linux32_locore.s" \ - compile-with "${CC} -x assembler-with-cpp -DLOCORE -m32 -shared -s -pipe -I. -I$S -Werror -Wall -fno-common -nostdinc -nostdlib -Wl,-T$S/amd64/linux32/linux32_vdso.lds.s -Wl,-soname=linux32_vdso.so,--eh-frame-hdr,-fPIC,-warn-common ${.IMPSRC} -o ${.TARGET}" \ + compile-with "${CC} -x assembler-with-cpp -DLOCORE -m32 -shared -s -pipe -I. -I$S -Werror -Wall -fPIC -fno-common -nostdinc -nostdlib -Wl,-T$S/amd64/linux32/linux32_vdso.lds.s -Wl,-soname=linux32_vdso.so,--eh-frame-hdr,-warn-common ${.IMPSRC} -o ${.TARGET}" \ no-obj no-implicit-rule \ clean "linux32_locore.o" # diff --git a/sys/conf/files.i386 b/sys/conf/files.i386 index 3784d87f44b5..294379d000c4 100644 --- a/sys/conf/files.i386 +++ b/sys/conf/files.i386 @@ -33,7 +33,7 @@ linux_assym.h optional compat_linux \ # linux_locore.o optional compat_linux \ dependency "linux_assym.h $S/i386/linux/linux_locore.s" \ - compile-with "${CC} -x assembler-with-cpp -DLOCORE -shared -s -pipe -I. -I$S -Werror -Wall -fno-common -nostdinc -nostdlib -Wl,-T$S/i386/linux/linux_vdso.lds.s -Wl,-soname=linux_vdso.so,--eh-frame-hdr,-fPIC,-warn-common ${.IMPSRC} -o ${.TARGET}" \ + compile-with "${CC} -x assembler-with-cpp -DLOCORE -shared -s -pipe -I. -I$S -Werror -Wall -fPIC -fno-common -nostdinc -nostdlib -Wl,-T$S/i386/linux/linux_vdso.lds.s -Wl,-soname=linux_vdso.so,--eh-frame-hdr,-warn-common ${.IMPSRC} -o ${.TARGET}" \ no-obj no-implicit-rule \ clean "linux_locore.o" # From 5dc97550fb827d67aa8f5148d185be36d0d44981 Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Sat, 3 Jun 2017 10:38:41 +0000 Subject: [PATCH 25/45] Mark the non-INTRNG armv6 configs with NO_UNIVERSE to prepare for INTRNG being always enabled on armv6. --- sys/arm/conf/AML8726 | 3 +++ sys/arm/conf/ARMADAXP | 3 +++ 2 files changed, 6 insertions(+) diff --git a/sys/arm/conf/AML8726 b/sys/arm/conf/AML8726 index e41c05ad3591..267e3075af67 100644 --- a/sys/arm/conf/AML8726 +++ b/sys/arm/conf/AML8726 @@ -18,6 +18,9 @@ # # $FreeBSD$ +# TODO: Port to INTRNG +#NO_UNIVERSE + ident AML8726 include "std.armv6" diff --git a/sys/arm/conf/ARMADAXP b/sys/arm/conf/ARMADAXP index 19a11ea6b5eb..7e36f13126a0 100644 --- a/sys/arm/conf/ARMADAXP +++ b/sys/arm/conf/ARMADAXP @@ -18,6 +18,9 @@ # # $FreeBSD$ +# TODO: Port to INTRNG +#NO_UNIVERSE + ident MV-88F78XX0 include "std.armv6" From 08cda712b4ca972afceddaff3d702b244cc64d39 Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Sat, 3 Jun 2017 10:40:45 +0000 Subject: [PATCH 26/45] Make it an error to build armv6 without INTRNG enabled. Most kernel configs have been updated for this, with the exception of the two marked as NO_UNIVERSE in r319514. --- sys/arm/arm/machdep.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/arm/arm/machdep.c b/sys/arm/arm/machdep.c index 1a90486e897e..5d3baa770d2c 100644 --- a/sys/arm/arm/machdep.c +++ b/sys/arm/arm/machdep.c @@ -103,6 +103,10 @@ __FBSDID("$FreeBSD$"); #error FreeBSD/arm doesn't provide compatibility with releases prior to 10 #endif +#if __ARM_ARCH >= 6 && !defined(INTRNG) +#error armv6 requires INTRNG +#endif + struct pcpu __pcpu[MAXCPU]; struct pcpu *pcpup = &__pcpu[0]; From c7f875df5d66dc27c8b1f7ee59de5a33c53d4441 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Sat, 3 Jun 2017 13:13:57 +0000 Subject: [PATCH 27/45] tsan: set noexec stack on aarch64 This may be refined upstream. Reviewed by: dim MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D11034 --- contrib/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S b/contrib/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S index ef06f0444ae4..c2a69816be2f 100644 --- a/contrib/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S +++ b/contrib/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S @@ -252,7 +252,7 @@ __sigsetjmp: CFI_ENDPROC .size __sigsetjmp, .-__sigsetjmp -#if defined(__linux__) +#if defined(__FreeBSD__) || defined(__linux__) /* We do not need executable stack. */ .section .note.GNU-stack,"",@progbits #endif From 2bdd2e7e614d6b58e8e401413afa2243f91b5d9f Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Sat, 3 Jun 2017 14:10:09 +0000 Subject: [PATCH 28/45] Add a cross-reference to sysdecode_socket_protocol(3). --- lib/libsysdecode/sysdecode.3 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/libsysdecode/sysdecode.3 b/lib/libsysdecode/sysdecode.3 index b5ed3c1471a8..7158b0a0fd65 100644 --- a/lib/libsysdecode/sysdecode.3 +++ b/lib/libsysdecode/sysdecode.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 17, 2016 +.Dd June 3, 2017 .Dt SYSDECODE 3 .Os .Sh NAME @@ -76,6 +76,7 @@ A placeholder for use when the ABI is not known. .Xr sysdecode_mask 3 , .Xr sysdecode_quotactl_cmd 3 , .Xr sysdecode_sigcode 3 , +.Xr sysdecode_socket_protocol 3 , .Xr sysdecode_sockopt_name 3 , .Xr sysdecode_syscallnames 3 , .Xr sysdecode_utrace 3 From a7ca2c6ad045ae12db1a75303e7497babc28a8ef Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Sat, 3 Jun 2017 14:12:17 +0000 Subject: [PATCH 29/45] Ensure that cached struct thread does not keep spurious td_su reference on an UFS mount point. Reported and tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week --- sys/kern/kern_proc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index c029567b6c44..10fdee4ee1e1 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -226,6 +226,8 @@ proc_dtor(void *mem, int size, void *arg) #endif /* Free all OSD associated to this thread. */ osd_thread_exit(td); + td_softdep_cleanup(td); + MPASS(td->td_su == NULL); /* Make sure all thread destructors are executed */ EVENTHANDLER_INVOKE(thread_dtor, td); From 4cbc378c612eea82211e87cfd3f65cb52666e9f1 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Sat, 3 Jun 2017 14:15:14 +0000 Subject: [PATCH 30/45] Clean possible td_su reference on the struct mount being unmounted as the last step of ffs_unmount(). It is possible that the mount point is recorded for cleanup in AST context while softdep flush is executed during unmount. The workitems are flushed by other means for the unmount, but the stray reference to struct mount blocks destruction of mount. Check for the situation and manually call vfs_rel() before returning from ffs_unmount(). Reported and tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week --- sys/ufs/ffs/ffs_vfsops.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index f20db52a67c0..1439dc720ada 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -1319,6 +1319,10 @@ ffs_unmount(mp, mntflags) MNT_ILOCK(mp); mp->mnt_flag &= ~MNT_LOCAL; MNT_IUNLOCK(mp); + if (td->td_su == mp) { + td->td_su = NULL; + vfs_rel(mp); + } return (error); fail: From ee8aa41dca9c2b80c69530257748c98ec748a04c Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Sat, 3 Jun 2017 14:22:15 +0000 Subject: [PATCH 31/45] Decode the 'who' argument passed to getrusage(). Add a new sysdecode_getrusage_who() which decodes the RUSAGE_* constant passed as the first argument to getrusage(). Use this function in both kdump and truss to decode the first argument to getrusage(). PR: 215448 Submitted by: Anton Yuzhaninov MFC after: 1 month --- lib/libsysdecode/Makefile | 1 + lib/libsysdecode/flags.c | 7 +++++++ lib/libsysdecode/mktables | 1 + lib/libsysdecode/sysdecode.h | 1 + lib/libsysdecode/sysdecode_enum.3 | 6 +++++- usr.bin/kdump/kdump.c | 7 +++++++ usr.bin/truss/syscall.h | 4 ++-- usr.bin/truss/syscalls.c | 5 ++++- 8 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/libsysdecode/Makefile b/lib/libsysdecode/Makefile index ddd7c72ade98..c094a668219f 100644 --- a/lib/libsysdecode/Makefile +++ b/lib/libsysdecode/Makefile @@ -32,6 +32,7 @@ MLINKS+=sysdecode_enum.3 sysdecode_acltype.3 \ sysdecode_enum.3 sysdecode_fadvice.3 \ sysdecode_enum.3 sysdecode_fcntl_cmd.3 \ sysdecode_enum.3 sysdecode_getfsstat_mode.3 \ + sysdecode_enum.3 sysdecode_getrusage_who.3 \ sysdecode_enum.3 sysdecode_idtype.3 \ sysdecode_enum.3 sysdecode_ipproto.3 \ sysdecode_enum.3 sysdecode_kldsym_cmd.3 \ diff --git a/lib/libsysdecode/flags.c b/lib/libsysdecode/flags.c index ea477b0e239c..bf0319f5dcaf 100644 --- a/lib/libsysdecode/flags.c +++ b/lib/libsysdecode/flags.c @@ -486,6 +486,13 @@ sysdecode_getfsstat_mode(int mode) return (lookup_value(getfsstatmode, mode)); } +const char * +sysdecode_getrusage_who(int who) +{ + + return (lookup_value(rusage, who)); +} + const char * sysdecode_kldsym_cmd(int cmd) { diff --git a/lib/libsysdecode/mktables b/lib/libsysdecode/mktables index 317bf341e151..8074d184b7bf 100644 --- a/lib/libsysdecode/mktables +++ b/lib/libsysdecode/mktables @@ -114,6 +114,7 @@ gen_table "quotactlcmds" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ gen_table "rebootopt" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h" gen_table "rforkflags" "RF[A-Z]+[[:space:]]+\([0-9]+<<[0-9]+\)" "sys/unistd.h" gen_table "rlimit" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h" +gen_table "rusage" "RUSAGE_[A-Z]+[[:space:]]+[-0-9]+" "sys/resource.h" gen_table "schedpolicy" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h" gen_table "sendfileflags" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h" gen_table "shmatflags" "SHM_[A-Z]+[[:space:]]+[0-9]{6}+" "sys/shm.h" diff --git a/lib/libsysdecode/sysdecode.h b/lib/libsysdecode/sysdecode.h index 03c12a5a7f8b..7619fa51736a 100644 --- a/lib/libsysdecode/sysdecode.h +++ b/lib/libsysdecode/sysdecode.h @@ -55,6 +55,7 @@ bool sysdecode_filemode(FILE *_fp, int _mode, int *_rem); bool sysdecode_flock_operation(FILE *_fp, int _operation, int *_rem); int sysdecode_freebsd_to_abi_errno(enum sysdecode_abi _abi, int _error); const char *sysdecode_getfsstat_mode(int _mode); +const char *sysdecode_getrusage_who(int _who); const char *sysdecode_idtype(int _idtype); const char *sysdecode_ioctlname(unsigned long _val); const char *sysdecode_ipproto(int _protocol); diff --git a/lib/libsysdecode/sysdecode_enum.3 b/lib/libsysdecode/sysdecode_enum.3 index 3e2f3902d82f..a1aa3ba51a91 100644 --- a/lib/libsysdecode/sysdecode_enum.3 +++ b/lib/libsysdecode/sysdecode_enum.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 2, 2017 +.Dd June 3, 2017 .Dt sysdecode_enum 3 .Os .Sh NAME @@ -36,6 +36,7 @@ .Nm sysdecode_fadvice , .Nm sysdecode_fcntl_cmd , .Nm sysdecode_getfsstat_mode , +.Nm sysdecode_getrusage_who , .Nm sysdecode_idtype , .Nm sysdecode_ipproto , .Nm sysdecode_kldsym_cmd , @@ -89,6 +90,8 @@ .Ft const char * .Fn sysdecode_getfsstat_mode "int mode" .Ft const char * +.Fn sysdecode_getrusage_who "int who" +.Ft const char * .Fn sysdecode_idtype "int idtype" .Ft const char * .Fn sysdecode_ipproto "int protocol" @@ -188,6 +191,7 @@ Most of these functions decode an argument passed to a system call: .It Fn sysdecode_ptrace_request Ta Xr ptrace 2 Ta Fa request .It Fn sysdecode_rlimit Ta Xr getrlimit 2 Ta Fa resource .It Fn sysdecode_rtprio_function Ta Xr rtprio 2 Ta Fa function +.It Fn sysdecode_getrusage_who Ta Xr getrusage 2 Ta Fa who .It Fn sysdecode_scheduler_policy Ta Xr sched_setscheduler 2 Ta Fa policy .It Fn sysdecode_semctl_cmd Ta Xr semctl 2 Ta Fa cmd .It Fn sysdecode_shmctl_cmd Ta Xr shmctl 2 Ta Fa cmd diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index 0432449755bb..262396169d6d 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -1190,6 +1190,13 @@ ktrsyscall(struct ktr_syscall *ktr, u_int sv_flags) narg--; c = ','; break; + case SYS_getrusage: + putchar('('); + print_integer_arg(sysdecode_getrusage_who, *ip); + ip++; + narg--; + c = ','; + break; case SYS_quotactl: print_number(ip, narg, c); putchar(','); diff --git a/usr.bin/truss/syscall.h b/usr.bin/truss/syscall.h index 6c6babb5b241..51f7f67a4bb1 100644 --- a/usr.bin/truss/syscall.h +++ b/usr.bin/truss/syscall.h @@ -42,8 +42,8 @@ enum Argtype { None = 1, Hex, Octal, Int, UInt, LongHex, Name, Ptr, Stat, Ioctl, Quad, Signal, Sockaddr, StringArray, Timespec, Timeval, Itimerval, Pollfd, Fd_set, Sigaction, Fcntl, Mprot, Mmapflags, Whence, Readlinkres, Sigset, Sigprocmask, StatFs, Kevent, Sockdomain, Socktype, Open, - Fcntlflag, Rusage, BinString, Shutdown, Resource, Rlimit, Timeval2, - Pathconf, Rforkflags, ExitStatus, Waitoptions, Idtype, Procctl, + Fcntlflag, Rusage, RusageWho, BinString, Shutdown, Resource, Rlimit, + Timeval2, Pathconf, Rforkflags, ExitStatus, Waitoptions, Idtype, Procctl, LinuxSockArgs, Umtxop, Atfd, Atflags, Timespec2, Accessmode, Long, Sysarch, ExecArgs, ExecEnv, PipeFds, QuadHex, Utrace, IntArray, Pipe2, CapFcntlRights, Fadvice, FileFlags, Flockop, Getfsstatmode, Kldsymcmd, diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index f4195642276d..7a923198024a 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -176,7 +176,7 @@ static struct syscall decoded_syscalls[] = { { .name = "getrlimit", .ret_type = 1, .nargs = 2, .args = { { Resource, 0 }, { Rlimit | OUT, 1 } } }, { .name = "getrusage", .ret_type = 1, .nargs = 2, - .args = { { Int, 0 }, { Rusage | OUT, 1 } } }, + .args = { { RusageWho, 0 }, { Rusage | OUT, 1 } } }, { .name = "getsid", .ret_type = 1, .nargs = 1, .args = { { Int, 0 } } }, { .name = "getsockname", .ret_type = 1, .nargs = 3, @@ -1596,6 +1596,9 @@ print_arg(struct syscall_args *sc, unsigned long *args, long *retval, case Resource: print_integer_arg(sysdecode_rlimit, fp, args[sc->offset]); break; + case RusageWho: + print_integer_arg(sysdecode_getrusage_who, fp, args[sc->offset]); + break; case Pathconf: fputs(xlookup(pathconf_arg, args[sc->offset]), fp); break; From 423c8343428beb627c27ede4d9548ab6c1db49ae Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Sat, 3 Jun 2017 14:28:19 +0000 Subject: [PATCH 32/45] makefs: rename variable for NetBSD diff reduction --- usr.sbin/makefs/ffs/buf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr.sbin/makefs/ffs/buf.c b/usr.sbin/makefs/ffs/buf.c index 2820bcafa0e0..bdd7ec1d3ab2 100644 --- a/usr.sbin/makefs/ffs/buf.c +++ b/usr.sbin/makefs/ffs/buf.c @@ -60,7 +60,7 @@ bread(struct vnode *vp, daddr_t blkno, int size, struct ucred *u1 __unused, { off_t offset; ssize_t rv; - fsinfo_t *fsinfo = vp->fs; + fsinfo_t *fs = vp->fs; assert (bpp != NULL); @@ -68,7 +68,7 @@ bread(struct vnode *vp, daddr_t blkno, int size, struct ucred *u1 __unused, printf("%s: blkno %lld size %d\n", __func__, (long long)blkno, size); *bpp = getblk(vp, blkno, size, 0, 0, 0); - offset = (*bpp)->b_blkno * fsinfo->sectorsize + fsinfo->offset; + offset = (*bpp)->b_blkno * fs->sectorsize + fs->offset; if (debug & DEBUG_BUF_BREAD) printf("%s: blkno %lld offset %lld bcount %ld\n", __func__, (long long)(*bpp)->b_blkno, (long long) offset, From 62e2e02278e12d4edb5ee2b8c8ebc47247ae1dbd Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Sat, 3 Jun 2017 14:45:46 +0000 Subject: [PATCH 33/45] Remove RT1310 from universe as it fails to build. --- sys/arm/conf/RT1310 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/arm/conf/RT1310 b/sys/arm/conf/RT1310 index 923c5b37423a..2084a69b2d0d 100644 --- a/sys/arm/conf/RT1310 +++ b/sys/arm/conf/RT1310 @@ -3,6 +3,8 @@ # # $FreeBSD$ # +# TODO: This fails to build under universe, irnore it until it's fixed +#NO_UNIVERSE ident RT1310 include "std.arm" From b32611238e25e3be45deffdb03b1fd6ba4aa9a5d Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Sat, 3 Jun 2017 15:39:23 +0000 Subject: [PATCH 34/45] Enable MULTIDELAY in the i.MX5 kernel configs. This will help adding them to GENERIC. --- sys/arm/conf/EFIKA_MX | 1 + sys/arm/conf/IMX53 | 1 + sys/arm/freescale/imx/imx51_machdep.c | 2 +- sys/arm/freescale/imx/imx53_machdep.c | 3 +-- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sys/arm/conf/EFIKA_MX b/sys/arm/conf/EFIKA_MX index a77a5a8eb1c6..759dfa257387 100644 --- a/sys/arm/conf/EFIKA_MX +++ b/sys/arm/conf/EFIKA_MX @@ -31,6 +31,7 @@ options SCHED_4BSD # 4BSD scheduler #options MD_ROOT # MD is a potential root device #options NFSD # Network Filesystem Server options PLATFORM +options MULTIDELAY options INCLUDE_CONFIG_FILE # Include this file in kernel # NFS root from boopt/dhcp diff --git a/sys/arm/conf/IMX53 b/sys/arm/conf/IMX53 index 0cf6205fe7f3..a168dcd4cb48 100644 --- a/sys/arm/conf/IMX53 +++ b/sys/arm/conf/IMX53 @@ -28,6 +28,7 @@ options SOC_IMX53 options SCHED_4BSD # 4BSD scheduler #options NFSD # Network Filesystem Server options PLATFORM +options MULTIDELAY options INCLUDE_CONFIG_FILE # Include this file in kernel # kernel/memory size reduction diff --git a/sys/arm/freescale/imx/imx51_machdep.c b/sys/arm/freescale/imx/imx51_machdep.c index cbf6c9690eb7..281210f80a11 100644 --- a/sys/arm/freescale/imx/imx51_machdep.c +++ b/sys/arm/freescale/imx/imx51_machdep.c @@ -99,4 +99,4 @@ static platform_method_t imx51_methods[] = { PLATFORMMETHOD_END, }; -FDT_PLATFORM_DEF(imx51, "i.MX51", 0, "fsl,imx51", 0); +FDT_PLATFORM_DEF(imx51, "i.MX51", 0, "fsl,imx51", 100); diff --git a/sys/arm/freescale/imx/imx53_machdep.c b/sys/arm/freescale/imx/imx53_machdep.c index f2486d1fba88..76630bbfb64c 100644 --- a/sys/arm/freescale/imx/imx53_machdep.c +++ b/sys/arm/freescale/imx/imx53_machdep.c @@ -95,5 +95,4 @@ static platform_method_t imx53_methods[] = { PLATFORMMETHOD_END, }; -FDT_PLATFORM_DEF(imx53, "i.MX53", 0, "fsl,imx53", 0); - +FDT_PLATFORM_DEF(imx53, "i.MX53", 0, "fsl,imx53", 100); From 35c4874e8d0604424650a6bd073a3e99f3004813 Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Sat, 3 Jun 2017 15:40:34 +0000 Subject: [PATCH 35/45] Add MULTIDELAY to the Beaglebone kenrel config to help moving it to GENERIC. --- sys/arm/conf/BEAGLEBONE | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/arm/conf/BEAGLEBONE b/sys/arm/conf/BEAGLEBONE index fec1f2859a61..77a7bdba25e8 100644 --- a/sys/arm/conf/BEAGLEBONE +++ b/sys/arm/conf/BEAGLEBONE @@ -29,6 +29,7 @@ include "../ti/am335x/std.am335x" makeoptions MODULES_EXTRA="dtb/am335x am335x_dmtpps" options INTRNG +options MULTIDELAY options SCHED_4BSD # 4BSD scheduler options PLATFORM From 78527f28d3d0f533bb663aead19cc54f8bfc5cd7 Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Sat, 3 Jun 2017 15:48:03 +0000 Subject: [PATCH 36/45] Add MULTIDELAY support to the sp804 driver. --- sys/arm/versatile/sp804.c | 57 ++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/sys/arm/versatile/sp804.c b/sys/arm/versatile/sp804.c index 894415ba11c7..ecc3b7cba8ff 100644 --- a/sys/arm/versatile/sp804.c +++ b/sys/arm/versatile/sp804.c @@ -42,6 +42,10 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef MULTIDELAY +#include /* For arm_set_delay */ +#endif + #include #include #include @@ -109,6 +113,7 @@ struct sp804_timer_softc { bus_space_write_4(sc->bst, sc->bsh, reg, val) static unsigned sp804_timer_tc_get_timecount(struct timecounter *); +static void sp804_timer_delay(int, void *); static unsigned sp804_timer_tc_get_timecount(struct timecounter *tc) @@ -287,6 +292,10 @@ sp804_timer_attach(device_t dev) (sp804_timer_tc_read_4(SP804_PRIMECELL_ID0 + i*4) & 0xff); } +#ifdef MULTIDELAY + arm_set_delay(sp804_timer_delay, sc); +#endif + device_printf(dev, "PrimeCell ID: %08x\n", id); sc->timer_initialized = 1; @@ -310,11 +319,36 @@ static devclass_t sp804_timer_devclass; DRIVER_MODULE(sp804_timer, simplebus, sp804_timer_driver, sp804_timer_devclass, 0, 0); +static void +sp804_timer_delay(int usec, void *arg) +{ + struct sp804_timer_softc *sc = arg; + int32_t counts; + uint32_t first, last; + + /* Get the number of times to count */ + counts = usec * ((sc->tc.tc_frequency / 1000000) + 1); + + first = sp804_timer_tc_get_timecount(&sc->tc); + + while (counts > 0) { + last = sp804_timer_tc_get_timecount(&sc->tc); + if (last == first) + continue; + if (last > first) { + counts -= (int32_t)(last - first); + } else { + counts -= (int32_t)((0xFFFFFFFF - first) + last); + } + first = last; + } +} + +#ifndef MULTIDELAY void DELAY(int usec) { int32_t counts; - uint32_t first, last; device_t timer_dev; struct sp804_timer_softc *sc; int timer_initialized = 0; @@ -336,23 +370,8 @@ DELAY(int usec) for (counts = 200; counts > 0; counts--) /* Prevent gcc from optimizing out the loop */ cpufunc_nullop(); - return; - } - - /* Get the number of times to count */ - counts = usec * ((sc->tc.tc_frequency / 1000000) + 1); - - first = sp804_timer_tc_get_timecount(&sc->tc); - - while (counts > 0) { - last = sp804_timer_tc_get_timecount(&sc->tc); - if (last == first) - continue; - if (last>first) { - counts -= (int32_t)(last - first); - } else { - counts -= (int32_t)((0xFFFFFFFF - first) + last); - } - first = last; + } else { + sp804_timer_delay(usec, sc); } } +#endif From 95bae5e40c57089ba6de52a3c9bfc9612ca726a8 Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Sat, 3 Jun 2017 15:56:54 +0000 Subject: [PATCH 37/45] Add MULTIDELAY support to the mpcore timer driver. This is needed when using this with GENERIC. While here remove the weak symbol, it doesn't seem to be needed anymore. --- sys/arm/arm/mpcore_timer.c | 74 ++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/sys/arm/arm/mpcore_timer.c b/sys/arm/arm/mpcore_timer.c index e68a5e921baf..0cf039c47962 100644 --- a/sys/arm/arm/mpcore_timer.c +++ b/sys/arm/arm/mpcore_timer.c @@ -59,6 +59,10 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef MULTIDELAY +#include /* For arm_set_delay */ +#endif + #include #include #include @@ -115,6 +119,8 @@ static boolean_t arm_tmr_freq_varies; #define tmr_gbl_read_4(sc, reg) bus_read_4((sc)->gbl_mem, reg) #define tmr_gbl_write_4(sc, reg, val) bus_write_4((sc)->gbl_mem, reg, val) +static void arm_tmr_delay(int, void *); + static timecounter_get_t arm_tmr_get_timecount; static struct timecounter arm_tmr_timecount = { @@ -431,6 +437,11 @@ arm_tmr_attach(device_t dev) if (tc_err != 0 && et_err != 0) { return (ENXIO); } + +#ifdef MULTIDELAY + arm_set_delay(arm_tmr_delay, sc); +#endif + return (0); } @@ -482,37 +493,14 @@ arm_tmr_change_frequency(uint64_t newfreq) et_change_frequency(arm_tmr_et, newfreq); } -/** - * DELAY - Delay for at least usec microseconds. - * @usec: number of microseconds to delay by - * - * This function is called all over the kernel and is suppose to provide a - * consistent delay. This function may also be called before the console - * is setup so no printf's can be called here. - * - * RETURNS: - * nothing - */ -static void __used /* Must emit function code for the weak ref below. */ -arm_tmr_DELAY(int usec) +static void +arm_tmr_delay(int usec, void *arg) { - struct arm_tmr_softc *sc; + struct arm_tmr_softc *sc = arg; int32_t counts_per_usec; int32_t counts; uint32_t first, last; - /* Check the timers are setup, if not just use a for loop for the meantime */ - if (arm_tmr_tc == NULL || arm_tmr_timecount.tc_frequency == 0) { - for (; usec > 0; usec--) - for (counts = 200; counts > 0; counts--) - cpufunc_nullop(); /* Prevent gcc from optimizing - * out the loop - */ - return; - } - - sc = arm_tmr_tc->tc_priv; - /* Get the number of times to count */ counts_per_usec = ((arm_tmr_timecount.tc_frequency / 1000000) + 1); @@ -536,10 +524,34 @@ arm_tmr_DELAY(int usec) } } -/* - * Supply a DELAY() implementation via weak linkage. A platform may want to use - * the mpcore per-cpu eventtimers but provide its own DELAY() routine, - * especially when the core frequency can change on the fly. +#ifndef MULTIDELAY +/** + * DELAY - Delay for at least usec microseconds. + * @usec: number of microseconds to delay by + * + * This function is called all over the kernel and is suppose to provide a + * consistent delay. This function may also be called before the console + * is setup so no printf's can be called here. + * + * RETURNS: + * nothing */ -__weak_reference(arm_tmr_DELAY, DELAY); +void +DELAY(int usec) +{ + struct arm_tmr_softc *sc; + int32_t counts; + /* Check the timers are setup, if not just use a for loop for the meantime */ + if (arm_tmr_tc == NULL || arm_tmr_timecount.tc_frequency == 0) { + for (; usec > 0; usec--) + for (counts = 200; counts > 0; counts--) + cpufunc_nullop(); /* Prevent gcc from optimizing + * out the loop + */ + } else { + sc = arm_tmr_tc->tc_priv; + arm_tmr_delay(usec, sc); + } +} +#endif From 698f05ab9527da200740ba99bb3851054e8b1044 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Sat, 3 Jun 2017 16:18:50 +0000 Subject: [PATCH 38/45] Mitigate several problems with the softdep_request_cleanup() on busy host. Problems start appearing when there are several threads all doing operations on a UFS volume and the SU workqueue needs a cleanup. It is possible that each thread calling softdep_request_cleanup() owns the lock for some dirty vnode (e.g. all of them are executing mkdir(2), mknod(2), creat(2) etc) and all vnodes which must be flushed are locked by corresponding thread. Then, we get all the threads simultaneously entering softdep_request_cleanup(). There are two problems: - Several threads execute MNT_VNODE_FOREACH_ALL() loops in parallel. Due to the locking, they quickly start executing 'in phase' with the speed of the slowest thread. - Since each thread already owns the lock for a dirty vnode, other threads non-blocking attempt to lock the vnode owned by other thread fail, and loops executing without making the progress. Retry logic does not allow the situation to recover. The result is a livelock. Fix these problems by making the following changes: - Allow only one thread to enter MNT_VNODE_FOREACH_ALL() loop per mp. A new flag FLUSH_RC_ACTIVE guards the loop. - If there were failed locking attempts during the loop, abort retry even if there are still work items on the mp work list. An assumption is that the items will be cleaned when other thread either fsyncs its vnode, or unlock and allow yet another thread to make the progress. It is possible now that some calls would get undeserved ENOSPC from ffs_alloc(), because the cleanup is not aggressive enough. But I do not see how can we reliably clean up workitems if calling softdep_request_cleanup() while still owning the vnode lock. I thought about scheme where ffs_alloc() returns ERESTART and saves the retry counter somewhere in struct thread, to return to the top level, unlock the vnode and retry. But IMO the very rare (and unproven) spurious ENOSPC is not worth the complications. Reported and tested by: pho Style and comments by: mckusick Reviewed by: mckusick Sponsored by: The FreeBSD Foundation MFC after: 2 weeks --- sys/ufs/ffs/ffs_softdep.c | 97 +++++++++++++++++++++++++++++---------- sys/ufs/ffs/softdep.h | 1 + 2 files changed, 73 insertions(+), 25 deletions(-) diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index be7f00680677..e348b0dfca59 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -901,6 +901,7 @@ static int pagedep_find(struct pagedep_hashhead *, ino_t, ufs_lbn_t, struct pagedep **); static void pause_timer(void *); static int request_cleanup(struct mount *, int); +static int softdep_request_cleanup_flush(struct mount *, struct ufsmount *); static void schedule_cleanup(struct mount *); static void softdep_ast_cleanup_proc(struct thread *); static int process_worklist_item(struct mount *, int, int); @@ -13274,10 +13275,9 @@ softdep_request_cleanup(fs, vp, cred, resource) { struct ufsmount *ump; struct mount *mp; - struct vnode *lvp, *mvp; long starttime; ufs2_daddr_t needed; - int error; + int error, failed_vnode; /* * If we are being called because of a process doing a @@ -13368,41 +13368,88 @@ softdep_request_cleanup(fs, vp, cred, resource) * to the worklist that we can then process to reap addition * resources. We walk the vnodes associated with the mount point * until we get the needed worklist requests that we can reap. + * + * If there are several threads all needing to clean the same + * mount point, only one is allowed to walk the mount list. + * When several threads all try to walk the same mount list, + * they end up competing with each other and often end up in + * livelock. This approach ensures that forward progress is + * made at the cost of occational ENOSPC errors being returned + * that might otherwise have been avoided. */ + error = 1; if ((resource == FLUSH_BLOCKS_WAIT && fs->fs_cstotal.cs_nbfree <= needed) || (resource == FLUSH_INODES_WAIT && fs->fs_pendinginodes > 0 && fs->fs_cstotal.cs_nifree <= needed)) { - MNT_VNODE_FOREACH_ALL(lvp, mp, mvp) { - if (TAILQ_FIRST(&lvp->v_bufobj.bo_dirty.bv_hd) == 0) { - VI_UNLOCK(lvp); - continue; + ACQUIRE_LOCK(ump); + if ((ump->um_softdep->sd_flags & FLUSH_RC_ACTIVE) == 0) { + ump->um_softdep->sd_flags |= FLUSH_RC_ACTIVE; + FREE_LOCK(ump); + failed_vnode = softdep_request_cleanup_flush(mp, ump); + ACQUIRE_LOCK(ump); + ump->um_softdep->sd_flags &= ~FLUSH_RC_ACTIVE; + FREE_LOCK(ump); + if (ump->softdep_on_worklist > 0) { + stat_cleanup_retries += 1; + if (!failed_vnode) + goto retry; } - if (vget(lvp, LK_EXCLUSIVE | LK_INTERLOCK | LK_NOWAIT, - curthread)) - continue; - if (lvp->v_vflag & VV_NOSYNC) { /* unlinked */ - vput(lvp); - continue; - } - (void) ffs_syncvnode(lvp, MNT_NOWAIT, 0); - vput(lvp); - } - lvp = ump->um_devvp; - if (vn_lock(lvp, LK_EXCLUSIVE | LK_NOWAIT) == 0) { - VOP_FSYNC(lvp, MNT_NOWAIT, curthread); - VOP_UNLOCK(lvp, 0); - } - if (ump->softdep_on_worklist > 0) { - stat_cleanup_retries += 1; - goto retry; + } else { + FREE_LOCK(ump); + error = 0; } stat_cleanup_failures += 1; } if (time_second - starttime > stat_cleanup_high_delay) stat_cleanup_high_delay = time_second - starttime; UFS_LOCK(ump); - return (1); + return (error); +} + +/* + * Scan the vnodes for the specified mount point flushing out any + * vnodes that can be locked without waiting. Finally, try to flush + * the device associated with the mount point if it can be locked + * without waiting. + * + * We return 0 if we were able to lock every vnode in our scan. + * If we had to skip one or more vnodes, we return 1. + */ +static int +softdep_request_cleanup_flush(mp, ump) + struct mount *mp; + struct ufsmount *ump; +{ + struct thread *td; + struct vnode *lvp, *mvp; + int failed_vnode; + + failed_vnode = 0; + td = curthread; + MNT_VNODE_FOREACH_ALL(lvp, mp, mvp) { + if (TAILQ_FIRST(&lvp->v_bufobj.bo_dirty.bv_hd) == 0) { + VI_UNLOCK(lvp); + continue; + } + if (vget(lvp, LK_EXCLUSIVE | LK_INTERLOCK | LK_NOWAIT, + td) != 0) { + failed_vnode = 1; + continue; + } + if (lvp->v_vflag & VV_NOSYNC) { /* unlinked */ + vput(lvp); + continue; + } + (void) ffs_syncvnode(lvp, MNT_NOWAIT, 0); + vput(lvp); + } + lvp = ump->um_devvp; + if (vn_lock(lvp, LK_EXCLUSIVE | LK_NOWAIT) == 0) { + VOP_FSYNC(lvp, MNT_NOWAIT, td); + VOP_UNLOCK(lvp, 0); + } + return (failed_vnode); } static bool diff --git a/sys/ufs/ffs/softdep.h b/sys/ufs/ffs/softdep.h index 009e3b30a964..f13342243781 100644 --- a/sys/ufs/ffs/softdep.h +++ b/sys/ufs/ffs/softdep.h @@ -1065,6 +1065,7 @@ struct mount_softdeps { #define FLUSH_EXIT 0x0001 /* time to exit */ #define FLUSH_CLEANUP 0x0002 /* need to clear out softdep structures */ #define FLUSH_STARTING 0x0004 /* flush thread not yet started */ +#define FLUSH_RC_ACTIVE 0x0008 /* a thread is flushing the mount point */ /* * Keep the old names from when these were in the ufsmount structure. From d712b799b533935eddc24310926478e2daa3e418 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 3 Jun 2017 16:19:33 +0000 Subject: [PATCH 39/45] The data type returned by vmoff() is too narrow in its range. This could break the transmission of files longer than 4 GB on 32-bit architectures. Reviewed by: glebius, kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D10019 --- sys/kern/kern_sendfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_sendfile.c b/sys/kern/kern_sendfile.c index 296c629ec863..30995fe4def1 100644 --- a/sys/kern/kern_sendfile.c +++ b/sys/kern/kern_sendfile.c @@ -207,12 +207,12 @@ xfsize(int i, int n, off_t off, off_t len) /* * Helper function to get offset within object for i page. */ -static inline vm_offset_t +static inline vm_ooffset_t vmoff(int i, off_t off) { if (i == 0) - return ((vm_offset_t)off); + return ((vm_ooffset_t)off); return (trunc_page(off + i * PAGE_SIZE)); } From e23ce9ef7aa732ff3a8ab27493b995f50b0fb17e Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Sat, 3 Jun 2017 16:24:17 +0000 Subject: [PATCH 40/45] Stop making cpu_initclocks weak when using event timers. A weak symbol could be overridden in the SoC specific code, but this would break GENERIC as it is likely to be incorrect. Remove the versatile implementation of cpu_initclocks as it's unneeded. --- sys/arm/annapurna/alpine/files.alpine | 1 - sys/arm/arm/machdep.c | 12 ++++-- sys/arm/versatile/files.versatile | 1 - sys/arm/versatile/versatile_timer.c | 56 --------------------------- 4 files changed, 9 insertions(+), 61 deletions(-) delete mode 100644 sys/arm/versatile/versatile_timer.c diff --git a/sys/arm/annapurna/alpine/files.alpine b/sys/arm/annapurna/alpine/files.alpine index cec277c18d85..73ebfcf8a872 100644 --- a/sys/arm/annapurna/alpine/files.alpine +++ b/sys/arm/annapurna/alpine/files.alpine @@ -3,7 +3,6 @@ kern/kern_clocksource.c standard arm/versatile/sp804.c standard -arm/versatile/versatile_timer.c standard dev/uart/uart_dev_ns8250.c optional uart arm/annapurna/alpine/common.c standard diff --git a/sys/arm/arm/machdep.c b/sys/arm/arm/machdep.c index 5d3baa770d2c..3bfc39e12524 100644 --- a/sys/arm/arm/machdep.c +++ b/sys/arm/arm/machdep.c @@ -301,6 +301,7 @@ cpu_idle_wakeup(int cpu) return (0); } +#ifdef NO_EVENTTIMERS /* * Most ARM platforms don't need to do anything special to init their clocks * (they get intialized during normal device attachment), and by not defining a @@ -311,8 +312,14 @@ cpu_idle_wakeup(int cpu) void arm_generic_initclocks(void) { +} +__weak_reference(arm_generic_initclocks, cpu_initclocks); + +#else +void +cpu_initclocks(void) +{ -#ifndef NO_EVENTTIMERS #ifdef SMP if (PCPU_GET(cpuid) == 0) cpu_initclocks_bsp(); @@ -321,9 +328,8 @@ arm_generic_initclocks(void) #else cpu_initclocks_bsp(); #endif -#endif } -__weak_reference(arm_generic_initclocks, cpu_initclocks); +#endif #ifdef MULTIDELAY void diff --git a/sys/arm/versatile/files.versatile b/sys/arm/versatile/files.versatile index d805abf879aa..38c1058d0261 100644 --- a/sys/arm/versatile/files.versatile +++ b/sys/arm/versatile/files.versatile @@ -8,6 +8,5 @@ arm/versatile/versatile_common.c standard arm/versatile/versatile_pci.c optional pci arm/versatile/versatile_scm.c standard arm/versatile/versatile_sic.c standard -arm/versatile/versatile_timer.c standard kern/kern_clocksource.c standard diff --git a/sys/arm/versatile/versatile_timer.c b/sys/arm/versatile/versatile_timer.c deleted file mode 100644 index b6f508393c8e..000000000000 --- a/sys/arm/versatile/versatile_timer.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2012 Oleksandr Tymoshenko - * All rights reserved. - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -void -cpu_initclocks(void) -{ - cpu_initclocks_bsp(); -} - - From d118a00f3cfe46cc822dfde349e824bfb640851e Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 3 Jun 2017 17:24:13 +0000 Subject: [PATCH 41/45] Eliminate duplication of the pmap and pv list unlock operations in pmap_enter() by implementing a single return path. Otherwise, the duplication will only increase with the upcoming support for psind == 1. Reviewed by: kib (some time ago) --- sys/amd64/amd64/pmap.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c index cfb146313e94..1ff2b2f15981 100644 --- a/sys/amd64/amd64/pmap.c +++ b/sys/amd64/amd64/pmap.c @@ -4313,6 +4313,7 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot, pv_entry_t pv; vm_paddr_t opa, pa; vm_page_t mpte, om; + int rv; boolean_t nosleep; PG_A = pmap_accessed_bit(pmap); @@ -4387,10 +4388,8 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot, mpte = _pmap_allocpte(pmap, pmap_pde_pindex(va), nosleep ? NULL : &lock); if (mpte == NULL && nosleep) { - if (lock != NULL) - rw_wunlock(lock); - PMAP_UNLOCK(pmap); - return (KERN_RESOURCE_SHORTAGE); + rv = KERN_RESOURCE_SHORTAGE; + goto out; } goto retry; } else @@ -4516,10 +4515,12 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot, vm_reserv_level_iffullpop(m) == 0) pmap_promote_pde(pmap, pde, va, &lock); + rv = KERN_SUCCESS; +out: if (lock != NULL) rw_wunlock(lock); PMAP_UNLOCK(pmap); - return (KERN_SUCCESS); + return (rv); } /* From 5f0aff893ee76c35da4b388b2a47a82b5f16c779 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sat, 3 Jun 2017 17:56:31 +0000 Subject: [PATCH 42/45] Stylistic tweaks Move opening braces of functions from the last column to column 0. MFC after: 18 days MFC with: r319339 Sponsored by: Dell EMC Isilon --- bin/dd/tests/dd2_test.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/dd/tests/dd2_test.sh b/bin/dd/tests/dd2_test.sh index 8e19ab2f8847..7770de2259c5 100755 --- a/bin/dd/tests/dd2_test.sh +++ b/bin/dd/tests/dd2_test.sh @@ -27,10 +27,12 @@ atf_test_case seek_overflow -seek_overflow_head() { +seek_overflow_head() +{ atf_set "descr" "dd(1) should reject too-large seek values" } -seek_overflow_body() { +seek_overflow_body() +{ touch f.in # Positive tests seek=`echo "2^63 / 4096 - 1" | bc` From 141173eb9fe578b0a0a107b83d12474b04282738 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sat, 3 Jun 2017 17:59:10 +0000 Subject: [PATCH 43/45] Mark :seek_overflow as an expected failure MFC after: 18 days MFC with: r319339 PR: 219757 Sponsored by: Dell EMC Isilon --- bin/dd/tests/dd2_test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/dd/tests/dd2_test.sh b/bin/dd/tests/dd2_test.sh index 7770de2259c5..80b9fe224de5 100755 --- a/bin/dd/tests/dd2_test.sh +++ b/bin/dd/tests/dd2_test.sh @@ -33,6 +33,8 @@ seek_overflow_head() } seek_overflow_body() { + atf_expect_fail "fails with 'dd: truncating f.out: File too large' - bug 219757" + touch f.in # Positive tests seek=`echo "2^63 / 4096 - 1" | bc` From f54f69008fd0a3bf2768a83a1757ca83bfbea2d4 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sat, 3 Jun 2017 18:10:04 +0000 Subject: [PATCH 44/45] Don't execute the TODO cases in a subshell This messes up the testcase counter, as seen in bug 219756. PR: 212160, 219756 Sponsored by: Dell EMC Isilon --- usr.sbin/newsyslog/tests/legacy_test.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/usr.sbin/newsyslog/tests/legacy_test.sh b/usr.sbin/newsyslog/tests/legacy_test.sh index fb2d957e19da..342ae58d431a 100644 --- a/usr.sbin/newsyslog/tests/legacy_test.sh +++ b/usr.sbin/newsyslog/tests/legacy_test.sh @@ -380,7 +380,6 @@ tests_time_rotate() { sleep 1.1 - ( TODO="rotate time 2-4 fail today; bug 212160" begin "rotate time 2 ${name_postfix}" @@ -404,7 +403,7 @@ tests_time_rotate() { ckfe ${LOGFNAME} chkfcnt 3 ${dir}${LOGFNAME}.*${ext} end - ) + unset TODO begin "noaction ${name_postfix}" ofiles=`ls -1 ${dir}${LOGFNAME}.*${ext} | tr -d '\n'` From 81341eb13956a70207c45ea87ccbda0897ca5daf Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sat, 3 Jun 2017 18:12:00 +0000 Subject: [PATCH 45/45] Fix the testplan after ^/head@r318960 The number of executed testcases is 128, not 126. MFC after: 18 days MFC with: r318960 Sponsored by: Dell EMC Isilon --- usr.sbin/newsyslog/tests/legacy_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.sbin/newsyslog/tests/legacy_test.sh b/usr.sbin/newsyslog/tests/legacy_test.sh index 342ae58d431a..11738e54aab3 100644 --- a/usr.sbin/newsyslog/tests/legacy_test.sh +++ b/usr.sbin/newsyslog/tests/legacy_test.sh @@ -454,7 +454,7 @@ tests_rfc5424() { tmpdir_clean } -echo 1..126 +echo 1..128 mkdir -p ${TMPDIR} cd ${TMPDIR}