From 7ab7abddce4a942f9422174bd2ba61c5ada389e3 Mon Sep 17 00:00:00 2001 From: Martin Matuska Date: Fri, 7 Sep 2018 00:11:43 +0000 Subject: [PATCH 01/54] Update vendor/libarchive/dist to git 5fe69dd018745a88eecf1f7db40daf12d26f7ed0 libarchive 3.3.3 --- CMakeLists.txt | 1 + NEWS | 10 ++++++ README.md | 4 ++- build/cmake/config.h.in | 4 +++ build/version | 2 +- configure.ac | 4 +-- cpio/test/test_basic.c | 60 ++++++++++++++++++++++++++--------- cpio/test/test_format_newc.c | 40 ++++++++++++++++------- libarchive/archive.h | 2 +- libarchive/archive_cryptor.c | 2 +- libarchive/archive_pack_dev.c | 3 ++ 11 files changed, 99 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8d430c21513..80871bc941cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -639,6 +639,7 @@ LA_CHECK_INCLUDE_FILE("sys/select.h" HAVE_SYS_SELECT_H) LA_CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H) LA_CHECK_INCLUDE_FILE("sys/statfs.h" HAVE_SYS_STATFS_H) LA_CHECK_INCLUDE_FILE("sys/statvfs.h" HAVE_SYS_STATVFS_H) +LA_CHECK_INCLUDE_FILE("sys/sysmacros.h" HAVE_SYS_SYSMACROS_H) LA_CHECK_INCLUDE_FILE("sys/time.h" HAVE_SYS_TIME_H) LA_CHECK_INCLUDE_FILE("sys/utime.h" HAVE_SYS_UTIME_H) LA_CHECK_INCLUDE_FILE("sys/utsname.h" HAVE_SYS_UTSNAME_H) diff --git a/NEWS b/NEWS index 9527e662a86e..45b40b499a69 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,13 @@ +Sep 03, 2018: libarchive 3.3.3 released + +Jul 19, 2018: Avoid super-linear slowdown on malformed mtree files + +Jan 27, 2018: Many fixes for building with Visual Studio + +Oct 19, 2017: NO_OVERWRITE doesn't change existing directory attributes + +Aug 12, 2017: New support for Zstandard read and write filters + Jul 09, 2017: libarchive 3.3.2 released Mar 16, 2017: NFSv4 ACL support for Linux (librichacl) diff --git a/README.md b/README.md index be6c13b3f03d..b48142191f2f 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ The library also detects and handles any of the following before evaluating the * lzma, lzip, and xz compression * lz4 compression * lzop compression + * zstandard compression The library can create archives in any of the following formats: * POSIX ustar @@ -125,6 +126,7 @@ When creating archives, the result can be filtered with any of the following: * lzma, lzip, and xz compression * lz4 compression * lzop compression + * zstandard compression ## Notes about the Library Design @@ -159,7 +161,7 @@ questions we are asked about libarchive: * On read, compression and format are always detected automatically. -* The same API is used for all formats; in particular, it's very +* The same API is used for all formats; it should be very easy for software using libarchive to transparently handle any of libarchive's archiving formats. diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in index 50978ce961ee..04f938d3f7f3 100644 --- a/build/cmake/config.h.in +++ b/build/cmake/config.h.in @@ -1068,6 +1068,10 @@ typedef uint64_t uintmax_t; /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_SYSMACROS_H 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_TIME_H 1 diff --git a/build/version b/build/version index 014eda6dc5a9..2427eab0f0b2 100644 --- a/build/version +++ b/build/version @@ -1 +1 @@ -3003003dev +3003003 diff --git a/configure.ac b/configure.ac index 84888e475c3c..cc61e724d4b2 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ dnl First, define all of the version numbers up front. dnl In particular, this allows the version macro to be used in AC_INIT dnl These first two version numbers are updated automatically on each release. -m4_define([LIBARCHIVE_VERSION_S],[3.3.3dev]) +m4_define([LIBARCHIVE_VERSION_S],[3.3.3]) m4_define([LIBARCHIVE_VERSION_N],[3003003]) dnl bsdtar and bsdcpio versioning tracks libarchive @@ -290,7 +290,7 @@ AC_CHECK_HEADERS([stdarg.h stdint.h stdlib.h string.h]) AC_CHECK_HEADERS([sys/acl.h sys/cdefs.h sys/ea.h sys/extattr.h]) AC_CHECK_HEADERS([sys/ioctl.h sys/mkdev.h sys/mount.h]) AC_CHECK_HEADERS([sys/param.h sys/poll.h sys/richacl.h]) -AC_CHECK_HEADERS([sys/select.h sys/statfs.h sys/statvfs.h]) +AC_CHECK_HEADERS([sys/select.h sys/statfs.h sys/statvfs.h sys/sysmacros.h]) AC_CHECK_HEADERS([sys/time.h sys/utime.h sys/utsname.h sys/vfs.h sys/xattr.h]) AC_CHECK_HEADERS([time.h unistd.h utime.h wchar.h wctype.h]) AC_CHECK_HEADERS([windows.h]) diff --git a/cpio/test/test_basic.c b/cpio/test/test_basic.c index f3a048002a55..6e45d1856983 100644 --- a/cpio/test/test_basic.c +++ b/cpio/test/test_basic.c @@ -144,49 +144,79 @@ DEFINE_TEST(test_basic) /* File with 10 bytes content. */ assertMakeFile("file", 0644, "1234567890"); fprintf(filelist, "file\n"); - if (is_LargeInode("file")) + if (is_LargeInode("file")) { strncat(result, - "bsdcpio: file: large inode number truncated: " - "Numerical result out of range\n", + "bsdcpio: file: large inode number truncated: ", sizeof(result) - strlen(result) -1); + strncat(result, + strerror(ERANGE), + sizeof(result) - strlen(result) -1); + strncat(result, + "\n", + sizeof(result) - strlen(result) -1); + } /* hardlink to above file. */ assertMakeHardlink("linkfile", "file"); fprintf(filelist, "linkfile\n"); - if (is_LargeInode("linkfile")) + if (is_LargeInode("linkfile")) { strncat(result, - "bsdcpio: linkfile: large inode number truncated: " - "Numerical result out of range\n", + "bsdcpio: linkfile: large inode number truncated: ", sizeof(result) - strlen(result) -1); + strncat(result, + strerror(ERANGE), + sizeof(result) - strlen(result) -1); + strncat(result, + "\n", + sizeof(result) - strlen(result) -1); + } /* Symlink to above file. */ if (canSymlink()) { assertMakeSymlink("symlink", "file"); fprintf(filelist, "symlink\n"); - if (is_LargeInode("symlink")) + if (is_LargeInode("symlink")) { strncat(result, - "bsdcpio: symlink: large inode number truncated: " - "Numerical result out of range\n", + "bsdcpio: symlink: large inode number truncated: ", sizeof(result) - strlen(result) -1); + strncat(result, + strerror(ERANGE), + sizeof(result) - strlen(result) -1); + strncat(result, + "\n", + sizeof(result) - strlen(result) -1); + } } /* Another file with different permissions. */ assertMakeFile("file2", 0777, "1234567890"); fprintf(filelist, "file2\n"); - if (is_LargeInode("file2")) + if (is_LargeInode("file2")) { strncat(result, - "bsdcpio: file2: large inode number truncated: " - "Numerical result out of range\n", + "bsdcpio: file2: large inode number truncated: ", sizeof(result) - strlen(result) -1); + strncat(result, + strerror(ERANGE), + sizeof(result) - strlen(result) -1); + strncat(result, + "\n", + sizeof(result) - strlen(result) -1); + } /* Directory. */ assertMakeDir("dir", 0775); fprintf(filelist, "dir\n"); - if (is_LargeInode("dir")) + if (is_LargeInode("dir")) { strncat(result, - "bsdcpio: dir: large inode number truncated: " - "Numerical result out of range\n", + "bsdcpio: dir: large inode number truncated: ", sizeof(result) - strlen(result) -1); + strncat(result, + strerror(ERANGE), + sizeof(result) - strlen(result) -1); + strncat(result, + "\n", + sizeof(result) - strlen(result) -1); + } strncat(result, "2 blocks\n", sizeof(result) - strlen(result) -1); /* All done. */ diff --git a/cpio/test/test_format_newc.c b/cpio/test/test_format_newc.c index d2daa46ab71c..258640443fe6 100644 --- a/cpio/test/test_format_newc.c +++ b/cpio/test/test_format_newc.c @@ -124,26 +124,42 @@ DEFINE_TEST(test_format_newc) /* Setup result message. */ memset(result, 0, sizeof(result)); - if (is_LargeInode("file1")) + if (is_LargeInode("file1")) { strncat(result, - "bsdcpio: file1: large inode number truncated: " - "Numerical result out of range\n", + "bsdcpio: file1: large inode number truncated: ", sizeof(result) - strlen(result) -1); - if (canSymlink() && is_LargeInode("symlink")) + strncat(result, strerror(ERANGE), + sizeof(result) - strlen(result) -1); + strncat(result, "\n", + sizeof(result) - strlen(result) -1); + } + if (canSymlink() && is_LargeInode("symlink")) { strncat(result, - "bsdcpio: symlink: large inode number truncated: " - "Numerical result out of range\n", + "bsdcpio: symlink: large inode number truncated: ", sizeof(result) - strlen(result) -1); - if (is_LargeInode("dir")) + strncat(result, strerror(ERANGE), + sizeof(result) - strlen(result) -1); + strncat(result, "\n", + sizeof(result) - strlen(result) -1); + } + if (is_LargeInode("dir")) { strncat(result, - "bsdcpio: dir: large inode number truncated: " - "Numerical result out of range\n", + "bsdcpio: dir: large inode number truncated: ", sizeof(result) - strlen(result) -1); - if (is_LargeInode("hardlink")) + strncat(result, strerror(ERANGE), + sizeof(result) - strlen(result) -1); + strncat(result, "\n", + sizeof(result) - strlen(result) -1); + } + if (is_LargeInode("hardlink")) { strncat(result, - "bsdcpio: hardlink: large inode number truncated: " - "Numerical result out of range\n", + "bsdcpio: hardlink: large inode number truncated: ", sizeof(result) - strlen(result) -1); + strncat(result, strerror(ERANGE), + sizeof(result) - strlen(result) -1); + strncat(result, "\n", + sizeof(result) - strlen(result) -1); + } /* Record some facts about what we just created: */ now = time(NULL); /* They were all created w/in last two seconds. */ diff --git a/libarchive/archive.h b/libarchive/archive.h index 32710201298d..cdbbeddf1d3c 100644 --- a/libarchive/archive.h +++ b/libarchive/archive.h @@ -155,7 +155,7 @@ __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_ONLY_STRING "3.3.3dev" +#define ARCHIVE_VERSION_ONLY_STRING "3.3.3" #define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING __LA_DECL const char * archive_version_string(void); diff --git a/libarchive/archive_cryptor.c b/libarchive/archive_cryptor.c index ced52fd7062a..71967c9d46f0 100644 --- a/libarchive/archive_cryptor.c +++ b/libarchive/archive_cryptor.c @@ -153,7 +153,7 @@ aes_ctr_encrypt_counter(archive_crypto_ctx *ctx) CCCryptorStatus r; r = CCCryptorReset(ref, NULL); - if (r != kCCSuccess) + if (r != kCCSuccess && r != kCCUnimplemented) return -1; r = CCCryptorUpdate(ref, ctx->nonce, AES_BLOCK_SIZE, ctx->encr_buf, AES_BLOCK_SIZE, NULL); diff --git a/libarchive/archive_pack_dev.c b/libarchive/archive_pack_dev.c index 098881b678cd..53bddd790a30 100644 --- a/libarchive/archive_pack_dev.c +++ b/libarchive/archive_pack_dev.c @@ -57,6 +57,9 @@ __RCSID("$NetBSD$"); #ifdef HAVE_SYS_STAT_H #include #endif +#ifdef HAVE_SYS_SYSMACROS_H +#include +#endif #ifdef HAVE_UNISTD_H #include #endif From 08d0704d749d79c0184eace471c266d812349202 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Tue, 11 Sep 2018 19:19:07 +0000 Subject: [PATCH 02/54] Switch reproducible builds to unmodified src tree mode newvers.sh supports two modes for reproducible builds: -r Reproducible build. Do not embed directory names, user names, time stamps or other dynamic information into the output file. This is intended to allow two builds done at different times and even by different people on different hosts to produce identical output. -R Reproducible build if the tree represents an unmodified checkout from a version control system. Metadata is included if the tree is modified. Switch to the second mode when reproducible builds are enabled. The value of a reproducible build is much less when building from an uncontrolled, modified src tree, and -R likely provides the best compromise in allowing the REPRODUCIBLE_BUILD knob to be enabled by default for the release. Approved by: re (kib) Sponsored by: The FreeBSD Foundation --- sys/conf/kern.post.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/conf/kern.post.mk b/sys/conf/kern.post.mk index 0c5cfe04f329..046080f42f1c 100644 --- a/sys/conf/kern.post.mk +++ b/sys/conf/kern.post.mk @@ -382,7 +382,7 @@ config.o env.o hints.o vers.o vnode_if.o: ${NORMAL_CTFCONVERT} .if ${MK_REPRODUCIBLE_BUILD} != "no" -REPRO_FLAG="-r" +REPRO_FLAG="-R" .endif vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP} MAKE="${MAKE}" sh $S/conf/newvers.sh ${REPRO_FLAG} ${KERN_IDENT} From 5a9066b4de550334cb265453f54e42d0ec1a4ad7 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Tue, 11 Sep 2018 20:32:57 +0000 Subject: [PATCH 03/54] remove doubled name in objcopy manpage We generate the installed objcopy man page from ELF Tool Chain's elfcopy, but the sed expresion used for this ended up producing "objcopy, objcopy - copy and translate object files". Instead of replacing the first "elfcopy" with objcopy, just remove it. Approved by: re (gjb) --- usr.bin/objcopy/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.bin/objcopy/Makefile b/usr.bin/objcopy/Makefile index 5fc78a0186d9..87472a4cd848 100644 --- a/usr.bin/objcopy/Makefile +++ b/usr.bin/objcopy/Makefile @@ -10,7 +10,7 @@ ELFCOPYDIR= ${ELFTCDIR}/elfcopy PROG= objcopy objcopy.1: elfcopy.1 sed -e 's/\.Dt ELFCOPY 1/.Dt OBJCOPY 1/' \ - -e 's/\.Nm elfcopy/.Nm objcopy/' < ${.ALLSRC} > ${.TARGET} + -e '/\.Nm elfcopy ,/d' < ${.ALLSRC} > ${.TARGET} CLEANFILES+= objcopy.1 SRCS= archive.c ascii.c binary.c main.c pe.c sections.c segments.c symbols.c From 3f8b4bf28d0a0e2fb7a237b756e6b1d28fff2179 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 11 Sep 2018 21:14:07 +0000 Subject: [PATCH 04/54] Add a couple of basic regression tests for SO_REUSEPORT_LB. Reviewed by: asomers Approved by: re (kib) Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D17110 --- tests/sys/netinet/Makefile | 2 + tests/sys/netinet/reuseport_lb.c | 242 +++++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+) create mode 100644 tests/sys/netinet/reuseport_lb.c diff --git a/tests/sys/netinet/Makefile b/tests/sys/netinet/Makefile index 9e1150ebf61b..97376fcfe2bc 100644 --- a/tests/sys/netinet/Makefile +++ b/tests/sys/netinet/Makefile @@ -3,6 +3,8 @@ TESTSDIR= ${TESTSBASE}/sys/netinet BINDIR= ${TESTSDIR} +ATF_TESTS_C= reuseport_lb + ATF_TESTS_SH= fibs_test PROGS= udp_dontroute tcp_user_cookie diff --git a/tests/sys/netinet/reuseport_lb.c b/tests/sys/netinet/reuseport_lb.c new file mode 100644 index 000000000000..e80e54463c57 --- /dev/null +++ b/tests/sys/netinet/reuseport_lb.c @@ -0,0 +1,242 @@ +/*- + * Copyright (c) 2018 The FreeBSD Foundation + * + * This software was developed by Mark Johnston under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * 1. Redistributions of source code must retain the above copyright + * notice, 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 + +/* + * Given an array of non-blocking listening sockets configured in a LB group + * for "addr", try connecting to "addr" in a loop and verify that connections + * are roughly balanced across the sockets. + */ +static void +lb_simple_accept_loop(int domain, const struct sockaddr *addr, int sds[], + size_t nsds, int nconns) +{ + size_t i; + int *acceptcnt; + int csd, error, excnt, sd; + + /* + * We expect each listening socket to accept roughly nconns/nsds + * connections, but allow for some error. + */ + excnt = nconns / nsds / 8; + acceptcnt = calloc(nsds, sizeof(*acceptcnt)); + ATF_REQUIRE_MSG(acceptcnt != NULL, "calloc() failed: %s", + strerror(errno)); + + while (nconns-- > 0) { + sd = socket(domain, SOCK_STREAM, 0); + ATF_REQUIRE_MSG(sd >= 0, "socket() failed: %s", + strerror(errno)); + + error = connect(sd, addr, addr->sa_len); + ATF_REQUIRE_MSG(error == 0, "connect() failed: %s", + strerror(errno)); + + /* + * Poll the listening sockets. + */ + do { + for (i = 0; i < nsds; i++) { + csd = accept(sds[i], NULL, NULL); + if (csd < 0) { + ATF_REQUIRE_MSG(errno == EWOULDBLOCK || + errno == EAGAIN, + "accept() failed: %s", + strerror(errno)); + continue; + } + + error = close(csd); + ATF_REQUIRE_MSG(error == 0, + "close() failed: %s", strerror(errno)); + + acceptcnt[i]++; + break; + } + } while (i == nsds); + + error = close(sd); + ATF_REQUIRE_MSG(error == 0, "close() failed: %s", + strerror(errno)); + } + + for (i = 0; i < nsds; i++) + ATF_REQUIRE_MSG(acceptcnt[i] > excnt, "uneven balancing"); +} + +static int +lb_listen_socket(int domain, int flags) +{ + size_t one; + int error, sd; + + sd = socket(domain, SOCK_STREAM | flags, 0); + ATF_REQUIRE_MSG(sd >= 0, "socket() failed: %s", strerror(errno)); + + one = 1; + error = setsockopt(sd, SOL_SOCKET, SO_REUSEPORT_LB, &one, sizeof(one)); + ATF_REQUIRE_MSG(error == 0, "setsockopt(SO_REUSEPORT_LB) failed: %s", + strerror(errno)); + + return (sd); +} + +ATF_TC_WITHOUT_HEAD(basic_ipv4); +ATF_TC_BODY(basic_ipv4, tc) +{ + struct sockaddr_in addr; + socklen_t slen; + size_t i; + const int nconns = 16384; + int error, sds[16]; + uint16_t port; + + sds[0] = lb_listen_socket(PF_INET, SOCK_NONBLOCK); + + memset(&addr, 0, sizeof(addr)); + addr.sin_len = sizeof(addr); + addr.sin_family = AF_INET; + addr.sin_port = htons(0); + addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + error = bind(sds[0], (const struct sockaddr *)&addr, sizeof(addr)); + ATF_REQUIRE_MSG(error == 0, "bind() failed: %s", strerror(errno)); + error = listen(sds[0], 1); + ATF_REQUIRE_MSG(error == 0, "listen() failed: %s", strerror(errno)); + + slen = sizeof(addr); + error = getsockname(sds[0], (struct sockaddr *)&addr, &slen); + ATF_REQUIRE_MSG(error == 0, "getsockname() failed: %s", + strerror(errno)); + ATF_REQUIRE_MSG(slen == sizeof(addr), "sockaddr size changed"); + port = addr.sin_port; + + memset(&addr, 0, sizeof(addr)); + addr.sin_len = sizeof(addr); + addr.sin_family = AF_INET; + addr.sin_port = port; + addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + for (i = 1; i < nitems(sds); i++) { + sds[i] = lb_listen_socket(PF_INET, SOCK_NONBLOCK); + + error = bind(sds[i], (const struct sockaddr *)&addr, + sizeof(addr)); + ATF_REQUIRE_MSG(error == 0, "bind() failed: %s", + strerror(errno)); + error = listen(sds[i], 1); + ATF_REQUIRE_MSG(error == 0, "listen() failed: %s", + strerror(errno)); + } + + lb_simple_accept_loop(PF_INET, (struct sockaddr *)&addr, sds, + nitems(sds), nconns); + for (i = 0; i < nitems(sds); i++) { + error = close(sds[i]); + ATF_REQUIRE_MSG(error == 0, "close() failed: %s", + strerror(errno)); + } +} + +ATF_TC_WITHOUT_HEAD(basic_ipv6); +ATF_TC_BODY(basic_ipv6, tc) +{ + const struct in6_addr loopback6 = IN6ADDR_LOOPBACK_INIT; + struct sockaddr_in6 addr; + socklen_t slen; + size_t i; + const int nconns = 16384; + int error, sds[16]; + uint16_t port; + + sds[0] = lb_listen_socket(PF_INET6, SOCK_NONBLOCK); + + memset(&addr, 0, sizeof(addr)); + addr.sin6_len = sizeof(addr); + addr.sin6_family = AF_INET6; + addr.sin6_port = htons(0); + addr.sin6_addr = loopback6; + error = bind(sds[0], (const struct sockaddr *)&addr, sizeof(addr)); + ATF_REQUIRE_MSG(error == 0, "bind() failed: %s", strerror(errno)); + error = listen(sds[0], 1); + ATF_REQUIRE_MSG(error == 0, "listen() failed: %s", strerror(errno)); + + slen = sizeof(addr); + error = getsockname(sds[0], (struct sockaddr *)&addr, &slen); + ATF_REQUIRE_MSG(error == 0, "getsockname() failed: %s", + strerror(errno)); + ATF_REQUIRE_MSG(slen == sizeof(addr), "sockaddr size changed"); + port = addr.sin6_port; + + memset(&addr, 0, sizeof(addr)); + addr.sin6_len = sizeof(addr); + addr.sin6_family = AF_INET6; + addr.sin6_port = port; + addr.sin6_addr = loopback6; + for (i = 1; i < nitems(sds); i++) { + sds[i] = lb_listen_socket(PF_INET6, SOCK_NONBLOCK); + + error = bind(sds[i], (const struct sockaddr *)&addr, + sizeof(addr)); + ATF_REQUIRE_MSG(error == 0, "bind() failed: %s", + strerror(errno)); + error = listen(sds[i], 1); + ATF_REQUIRE_MSG(error == 0, "listen() failed: %s", + strerror(errno)); + } + + lb_simple_accept_loop(PF_INET6, (struct sockaddr *)&addr, sds, + nitems(sds), nconns); + for (i = 0; i < nitems(sds); i++) { + error = close(sds[i]); + ATF_REQUIRE_MSG(error == 0, "close() failed: %s", + strerror(errno)); + } +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, basic_ipv4); + ATF_TP_ADD_TC(tp, basic_ipv6); + + return (atf_no_error()); +} From e382dd47aa55ddba0497a93bdeddcd9ff92b6877 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Tue, 11 Sep 2018 23:54:31 +0000 Subject: [PATCH 05/54] amd64: enable options NUMA in GENERIC and MINIMAL Reviewed by: gallatin, cem, scottl Approved by: re (kib) Relnotes: yes Sponsored by: Dell EMC Isilon, Netflix Differential Revision: https://reviews.freebsd.org/D17059 --- sys/amd64/conf/GENERIC | 1 + sys/amd64/conf/MINIMAL | 1 + 2 files changed, 2 insertions(+) diff --git a/sys/amd64/conf/GENERIC b/sys/amd64/conf/GENERIC index 3d1056189ebe..f2d4d0d37222 100644 --- a/sys/amd64/conf/GENERIC +++ b/sys/amd64/conf/GENERIC @@ -25,6 +25,7 @@ makeoptions DEBUG=-g # Build kernel with gdb(1) debug symbols makeoptions WITH_CTF=1 # Run ctfconvert(1) for DTrace support options SCHED_ULE # ULE scheduler +options NUMA # Non-Uniform Memory Architecture support options PREEMPTION # Enable kernel thread preemption options VIMAGE # Subsystem virtualization, e.g. VNET options INET # InterNETworking diff --git a/sys/amd64/conf/MINIMAL b/sys/amd64/conf/MINIMAL index 010148ff2d86..011400f3967f 100644 --- a/sys/amd64/conf/MINIMAL +++ b/sys/amd64/conf/MINIMAL @@ -39,6 +39,7 @@ makeoptions DEBUG=-g # Build kernel with gdb(1) debug symbols makeoptions WITH_CTF=1 # Run ctfconvert(1) for DTrace support options SCHED_ULE # ULE scheduler +options NUMA # Non-Uniform Memory Architecture support options PREEMPTION # Enable kernel thread preemption options INET # InterNETworking options INET6 # IPv6 communications protocols From c9e562b188682eb9be39a8124893aa172b57d3ca Mon Sep 17 00:00:00 2001 From: Gordon Tetlow Date: Wed, 12 Sep 2018 04:57:34 +0000 Subject: [PATCH 06/54] Correct ELF header parsing code to prevent invalid ELF sections from disclosing memory. Submitted by: markj Reported by: Thomas Barabosch, Fraunhofer FKIE Approved by: re (implicit) Approved by: so Security: FreeBSD-SA-18:12.elf Security: CVE-2018-6924 Sponsored by: The FreeBSD Foundation --- sys/kern/imgact_elf.c | 8 +++++++- sys/kern/vfs_vnops.c | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 2a73a7221488..f4302d466651 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -839,7 +839,8 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) break; case PT_INTERP: /* Path to interpreter */ - if (phdr[i].p_filesz > MAXPATHLEN) { + if (phdr[i].p_filesz < 2 || + phdr[i].p_filesz > MAXPATHLEN) { uprintf("Invalid PT_INTERP\n"); error = ENOEXEC; goto ret; @@ -870,6 +871,11 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) } else { interp = __DECONST(char *, imgp->image_header) + phdr[i].p_offset; + if (interp[interp_name_len - 1] != '\0') { + uprintf("Invalid PT_INTERP\n"); + error = ENOEXEC; + goto ret; + } } break; case PT_GNU_STACK: diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 09f665e8f3fb..00392ee3a072 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -527,6 +527,8 @@ vn_rdwr(enum uio_rw rw, struct vnode *vp, void *base, int len, off_t offset, struct vn_io_fault_args args; int error, lock_flags; + if (offset < 0 && vp->v_type != VCHR) + return (EINVAL); auio.uio_iov = &aiov; auio.uio_iovcnt = 1; aiov.iov_base = base; From 86c5937532768ce2936c70b1be159af4c11d35ef Mon Sep 17 00:00:00 2001 From: Ruslan Bukin Date: Wed, 12 Sep 2018 08:05:33 +0000 Subject: [PATCH 07/54] Don't mark module data as static on RISC-V. Similar to arm64, riscv compiler uses PC-relative loads/stores, and with static data compiler does not emit relocations. In result, kernel module linker has nothing to fix and data accessed from the wrong location. Approved by: re (gjb) Sponsored by: DARPA, AFRL --- sys/net/vnet.h | 2 +- sys/sys/pcpu.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/net/vnet.h b/sys/net/vnet.h index 514519a327b1..b4168750e026 100644 --- a/sys/net/vnet.h +++ b/sys/net/vnet.h @@ -273,7 +273,7 @@ extern struct sx vnet_sxlock; /* struct _hack is to stop this from being used with static data */ #define VNET_DEFINE(t, n) \ struct _hack; t VNET_NAME(n) __section(VNET_SETNAME) __used -#if defined(KLD_MODULE) && defined(__aarch64__) +#if defined(KLD_MODULE) && (defined(__aarch64__) || defined(__riscv)) /* * As with DPCPU_DEFINE_STATIC we are unable to mark this data as static * in modules on some architectures. diff --git a/sys/sys/pcpu.h b/sys/sys/pcpu.h index d2084b77b3df..19bc4a8b9076 100644 --- a/sys/sys/pcpu.h +++ b/sys/sys/pcpu.h @@ -84,7 +84,7 @@ extern uintptr_t dpcpu_off[]; /* struct _hack is to stop this from being used with the static keyword. */ #define DPCPU_DEFINE(t, n) \ struct _hack; t DPCPU_NAME(n) __section(DPCPU_SETNAME) __used -#if defined(KLD_MODULE) && defined(__aarch64__) +#if defined(KLD_MODULE) && (defined(__aarch64__) || defined(__riscv)) /* * On some architectures the compiler will use PC-relative load to * find the address of DPCPU data with the static keyword. We then From 752a8ea48e18975251892b1468bb01db82494546 Mon Sep 17 00:00:00 2001 From: Ruslan Bukin Date: Wed, 12 Sep 2018 08:12:34 +0000 Subject: [PATCH 08/54] Use elf_relocaddr() to find the address for R_RISCV_RELATIVE relocation. elf_relocaddr() has a hook to handle VIMAGE data addresses. This fixes VIMAGE support for RISC-V when built as a module. Approved by: re (gjb) Sponsored by: DARPA, AFRL --- sys/riscv/riscv/elf_machdep.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sys/riscv/riscv/elf_machdep.c b/sys/riscv/riscv/elf_machdep.c index 974397cf22c6..f3f589b6f14f 100644 --- a/sys/riscv/riscv/elf_machdep.c +++ b/sys/riscv/riscv/elf_machdep.c @@ -330,11 +330,9 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data, break; case R_RISCV_RELATIVE: - val = relocbase + addend; - before64 = *where; - if (*where != val) - *where = val; + + *where = elf_relocaddr(lf, relocbase + addend); if (debug_kld) printf("%p %c %-24s %016lx -> %016lx\n", From bd528a398ec8f8583711fbcc1cb4cbbecc231917 Mon Sep 17 00:00:00 2001 From: Ruslan Bukin Date: Wed, 12 Sep 2018 08:13:54 +0000 Subject: [PATCH 09/54] Enable VIMAGE support for RISC-V. Approved by: re (gjb) Sponsored by: DARPA, AFRL --- sys/riscv/conf/GENERIC | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/riscv/conf/GENERIC b/sys/riscv/conf/GENERIC index 2975ecbec413..b712260d5361 100644 --- a/sys/riscv/conf/GENERIC +++ b/sys/riscv/conf/GENERIC @@ -30,7 +30,7 @@ makeoptions WITHOUT_MODULES="usb otusfw mwlfw ispfw mwlfw ralfw rtwnfw" options SCHED_ULE # ULE scheduler options PREEMPTION # Enable kernel thread preemption -# options VIMAGE # Subsystem virtualization, e.g. VNET +options VIMAGE # Subsystem virtualization, e.g. VNET options INET # InterNETworking options INET6 # IPv6 communications protocols options TCP_HHOOK # hhook(9) framework for TCP From e6895e80490be42c13efe6009373fa70391d0c96 Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Wed, 12 Sep 2018 10:09:59 +0000 Subject: [PATCH 10/54] Fix for backends which doesn't support capsicum. Not all libpcap backends use the BPF compatible set of IOCTLs. For example the mlx5 backend uses libibverbs which is currently not capsicum compatible. Disable sandboxing for such backends. MFC after: 3 days Discussed with: emaste@ Approved by: re (kib) Sponsored by: Mellanox Technologies --- contrib/tcpdump/tcpdump.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contrib/tcpdump/tcpdump.c b/contrib/tcpdump/tcpdump.c index d08c33ee6eb8..31adfed016a6 100644 --- a/contrib/tcpdump/tcpdump.c +++ b/contrib/tcpdump/tcpdump.c @@ -2069,6 +2069,9 @@ main(int argc, char **argv) #else cansandbox = (cansandbox && ndo->ndo_nflag); #endif /* HAVE_CASPER */ + cansandbox = (cansandbox && (pcap_fileno(pd) != -1 || + RFileName != NULL)); + if (cansandbox && cap_enter() < 0 && errno != ENOSYS) error("unable to enter the capability mode"); #endif /* HAVE_CAPSICUM */ From a8a8a8a8085df85c69ee6bfde47d9c20501cea26 Mon Sep 17 00:00:00 2001 From: Michael Tuexen Date: Wed, 12 Sep 2018 10:27:58 +0000 Subject: [PATCH 11/54] Fix TCP Fast Open for the TCP RACK stack. * Fix a bug where the SYN handling during established state was applied to a front state. * Move a check for retransmission after the timer handling. This was suppressing timer based retransmissions. * Fix an off-by one byte in the sequence number of retransmissions. * Apply fixes corresponding to https://svnweb.freebsd.org/changeset/base/336934 Reviewed by: rrs@ Approved by: re (kib@) MFC after: 1 month Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D16912 --- sys/netinet/tcp_stacks/rack.c | 53 ++++++++++++++++------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/sys/netinet/tcp_stacks/rack.c b/sys/netinet/tcp_stacks/rack.c index 53aa20bad928..20369d3444c4 100644 --- a/sys/netinet/tcp_stacks/rack.c +++ b/sys/netinet/tcp_stacks/rack.c @@ -5400,14 +5400,6 @@ rack_do_syn_recv(struct mbuf *m, struct tcphdr *th, struct socket *so, } if (thflags & TH_RST) return (rack_process_rst(m, th, so, tp)); - /* - * RFC5961 Section 4.2 Send challenge ACK for any SYN in - * synchronized state. - */ - if (thflags & TH_SYN) { - rack_challenge_ack(m, th, tp, &ret_val); - return (ret_val); - } /* * RFC 1323 PAWS: If we have a timestamp reply on this segment and * it's less than ts_recent, drop it. @@ -5478,6 +5470,16 @@ rack_do_syn_recv(struct mbuf *m, struct tcphdr *th, struct socket *so, * FIN-WAIT-1 */ tp->t_starttime = ticks; + if (IS_FASTOPEN(tp->t_flags) && tp->t_tfo_pending) { + tcp_fastopen_decrement_counter(tp->t_tfo_pending); + tp->t_tfo_pending = NULL; + + /* + * Account for the ACK of our SYN prior to + * regular ACK processing below. + */ + tp->snd_una++; + } if (tp->t_flags & TF_NEEDFIN) { tcp_state_change(tp, TCPS_FIN_WAIT_1); tp->t_flags &= ~TF_NEEDFIN; @@ -5485,16 +5487,6 @@ rack_do_syn_recv(struct mbuf *m, struct tcphdr *th, struct socket *so, tcp_state_change(tp, TCPS_ESTABLISHED); TCP_PROBE5(accept__established, NULL, tp, mtod(m, const char *), tp, th); - if (IS_FASTOPEN(tp->t_flags) && tp->t_tfo_pending) { - tcp_fastopen_decrement_counter(tp->t_tfo_pending); - tp->t_tfo_pending = NULL; - - /* - * Account for the ACK of our SYN prior to regular - * ACK processing below. - */ - tp->snd_una++; - } /* * TFO connections call cc_conn_init() during SYN * processing. Calling it again here for such connections @@ -6924,16 +6916,6 @@ rack_output(struct tcpcb *tp) if (tp->t_flags & TF_TOE) return (tcp_offload_output(tp)); #endif - - /* - * For TFO connections in SYN_RECEIVED, only allow the initial - * SYN|ACK and those sent by the retransmit timer. - */ - if (IS_FASTOPEN(tp->t_flags) && - (tp->t_state == TCPS_SYN_RECEIVED) && - SEQ_GT(tp->snd_max, tp->snd_una) && /* initial SYN|ACK sent */ - (rack->r_ctl.rc_resend == NULL)) /* not a retransmit */ - return (0); #ifdef INET6 if (rack->r_state) { /* Use the cache line loaded if possible */ @@ -6975,6 +6957,17 @@ rack_output(struct tcpcb *tp) } rack->r_wanted_output = 0; rack->r_timer_override = 0; + /* + * For TFO connections in SYN_SENT or SYN_RECEIVED, + * only allow the initial SYN or SYN|ACK and those sent + * by the retransmit timer. + */ + if (IS_FASTOPEN(tp->t_flags) && + ((tp->t_state == TCPS_SYN_RECEIVED) || + (tp->t_state == TCPS_SYN_SENT)) && + SEQ_GT(tp->snd_max, tp->snd_una) && /* initial SYN or SYN|ACK sent */ + (tp->t_rxtshift == 0)) /* not a retransmit */ + return (0); /* * Determine length of data that should be transmitted, and flags * that will be used. If there is some data or critical controls @@ -7353,8 +7346,10 @@ rack_output(struct tcpcb *tp) (((flags & TH_SYN) && (tp->t_rxtshift > 0)) || ((tp->t_state == TCPS_SYN_SENT) && (tp->t_tfo_client_cookie_len == 0)) || - (flags & TH_RST))) + (flags & TH_RST))) { + sack_rxmit = 0; len = 0; + } /* Without fast-open there should never be data sent on a SYN */ if ((flags & TH_SYN) && (!IS_FASTOPEN(tp->t_flags))) len = 0; From 540c72297da10838dcdc009520f68cbc33b08217 Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Wed, 12 Sep 2018 15:06:30 +0000 Subject: [PATCH 12/54] Fix issues about cancelling USB transfers in LibUSB when the USB device has been detached. When a USB device has been detached the kernel file handle stops responding to commands. USB applications which continue to run after the USB device has been detached, depend on LibUSB generated events to tear down its pending USB transfers. Add code to handle the needed cleanup when processing the USB transfer(s) fails and prevent new USB transfer(s) from being submitted. Found by: Ludovic Rousseau PR: 231076 MFC after: 1 week Approved by: re (gjb) Sponsored by: Mellanox Technologies --- lib/libusb/libusb10.c | 107 +++++++++++++++++++++++++++------------ lib/libusb/libusb10.h | 3 ++ lib/libusb/libusb10_io.c | 24 ++++----- 3 files changed, 91 insertions(+), 43 deletions(-) diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index 407237feb71a..09f4795afaa1 100644 --- a/lib/libusb/libusb10.c +++ b/lib/libusb/libusb10.c @@ -114,6 +114,19 @@ libusb_set_nonblocking(int f) fcntl(f, F_SETFL, flags); } +static void +libusb10_wakeup_event_loop(libusb_context *ctx) +{ + uint8_t dummy = 0; + int err; + + err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); + if (err < (int)sizeof(dummy)) { + /* ignore error, if any */ + DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "Waking up event loop failed!"); + } +} + int libusb_init(libusb_context **context) { @@ -484,7 +497,6 @@ libusb_open(libusb_device *dev, libusb_device_handle **devh) { libusb_context *ctx = dev->ctx; struct libusb20_device *pdev = dev->os_priv; - uint8_t dummy; int err; if (devh == NULL) @@ -506,12 +518,8 @@ libusb_open(libusb_device *dev, libusb_device_handle **devh) POLLOUT | POLLRDNORM | POLLWRNORM); /* make sure our event loop detects the new device */ - dummy = 0; - err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); - if (err < (int)sizeof(dummy)) { - /* ignore error, if any */ - DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_open write failed!"); - } + libusb10_wakeup_event_loop(ctx); + *devh = pdev; return (0); @@ -564,8 +572,6 @@ libusb_close(struct libusb20_device *pdev) { libusb_context *ctx; struct libusb_device *dev; - uint8_t dummy; - int err; if (pdev == NULL) return; /* be NULL safe */ @@ -581,12 +587,7 @@ libusb_close(struct libusb20_device *pdev) libusb_unref_device(dev); /* make sure our event loop detects the closed device */ - dummy = 0; - err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); - if (err < (int)sizeof(dummy)) { - /* ignore error, if any */ - DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_close write failed!"); - } + libusb10_wakeup_event_loop(ctx); } libusb_device * @@ -1314,7 +1315,6 @@ libusb10_submit_transfer_sub(struct libusb20_device *pdev, uint8_t endpoint) int buffsize; int maxframe; int temp; - uint8_t dummy; dev = libusb_get_device(pdev); @@ -1415,10 +1415,8 @@ libusb10_submit_transfer_sub(struct libusb20_device *pdev, uint8_t endpoint) failure: libusb10_complete_transfer(pxfer0, sxfer, LIBUSB_TRANSFER_ERROR); - /* make sure our event loop spins the done handler */ - dummy = 0; - err = write(dev->ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); + libusb10_wakeup_event_loop(dev->ctx); } /* The following function must be called unlocked */ @@ -1459,6 +1457,8 @@ libusb_submit_transfer(struct libusb_transfer *uxfer) (libusb20_tr_get_priv_sc1(pxfer0) == sxfer) || (libusb20_tr_get_priv_sc1(pxfer1) == sxfer)) { err = LIBUSB_ERROR_BUSY; + } else if (dev->device_is_gone != 0) { + err = LIBUSB_ERROR_NO_DEVICE; } else { /* set pending state */ @@ -1490,6 +1490,7 @@ libusb_cancel_transfer(struct libusb_transfer *uxfer) struct libusb20_transfer *pxfer1; struct libusb_super_transfer *sxfer; struct libusb_device *dev; + struct libusb_device_handle *devh; uint8_t endpoint; int retval; @@ -1497,12 +1498,12 @@ libusb_cancel_transfer(struct libusb_transfer *uxfer) return (LIBUSB_ERROR_INVALID_PARAM); /* check if not initialised */ - if (uxfer->dev_handle == NULL) + if ((devh = uxfer->dev_handle) == NULL) return (LIBUSB_ERROR_NOT_FOUND); endpoint = uxfer->endpoint; - dev = libusb_get_device(uxfer->dev_handle); + dev = libusb_get_device(devh); DPRINTF(dev->ctx, LIBUSB_DEBUG_FUNCTION, "libusb_cancel_transfer enter"); @@ -1513,8 +1514,8 @@ libusb_cancel_transfer(struct libusb_transfer *uxfer) CTX_LOCK(dev->ctx); - pxfer0 = libusb10_get_transfer(uxfer->dev_handle, endpoint, 0); - pxfer1 = libusb10_get_transfer(uxfer->dev_handle, endpoint, 1); + pxfer0 = libusb10_get_transfer(devh, endpoint, 0); + pxfer1 = libusb10_get_transfer(devh, endpoint, 1); if (sxfer->state != LIBUSB_SUPER_XFER_ST_PEND) { /* only update the transfer status */ @@ -1526,23 +1527,38 @@ libusb_cancel_transfer(struct libusb_transfer *uxfer) sxfer->entry.tqe_prev = NULL; libusb10_complete_transfer(NULL, sxfer, LIBUSB_TRANSFER_CANCELLED); + /* make sure our event loop spins the done handler */ + libusb10_wakeup_event_loop(dev->ctx); } else if (pxfer0 == NULL || pxfer1 == NULL) { /* not started */ retval = LIBUSB_ERROR_NOT_FOUND; } else if (libusb20_tr_get_priv_sc1(pxfer0) == sxfer) { libusb10_complete_transfer(pxfer0, sxfer, LIBUSB_TRANSFER_CANCELLED); - libusb20_tr_stop(pxfer0); - /* make sure the queue doesn't stall */ - libusb10_submit_transfer_sub( - uxfer->dev_handle, endpoint); + if (dev->device_is_gone != 0) { + /* clear transfer pointer */ + libusb20_tr_set_priv_sc1(pxfer0, NULL); + /* make sure our event loop spins the done handler */ + libusb10_wakeup_event_loop(dev->ctx); + } else { + libusb20_tr_stop(pxfer0); + /* make sure the queue doesn't stall */ + libusb10_submit_transfer_sub(devh, endpoint); + } } else if (libusb20_tr_get_priv_sc1(pxfer1) == sxfer) { libusb10_complete_transfer(pxfer1, sxfer, LIBUSB_TRANSFER_CANCELLED); - libusb20_tr_stop(pxfer1); - /* make sure the queue doesn't stall */ - libusb10_submit_transfer_sub( - uxfer->dev_handle, endpoint); + /* check if handle is still active */ + if (dev->device_is_gone != 0) { + /* clear transfer pointer */ + libusb20_tr_set_priv_sc1(pxfer1, NULL); + /* make sure our event loop spins the done handler */ + libusb10_wakeup_event_loop(dev->ctx); + } else { + libusb20_tr_stop(pxfer1); + /* make sure the queue doesn't stall */ + libusb10_submit_transfer_sub(devh, endpoint); + } } else { /* not started */ retval = LIBUSB_ERROR_NOT_FOUND; @@ -1571,6 +1587,35 @@ libusb10_cancel_all_transfer(libusb_device *dev) } } +UNEXPORTED void +libusb10_cancel_all_transfer_locked(struct libusb20_device *pdev, struct libusb_device *dev) +{ + struct libusb_super_transfer *sxfer; + unsigned x; + + for (x = 0; x != LIBUSB_NUM_SW_ENDPOINTS; x++) { + struct libusb20_transfer *xfer; + + xfer = libusb20_tr_get_pointer(pdev, x); + if (xfer == NULL) + continue; + if (libusb20_tr_pending(xfer) == 0) + continue; + sxfer = libusb20_tr_get_priv_sc1(xfer); + if (sxfer == NULL) + continue; + /* complete pending transfer */ + libusb10_complete_transfer(xfer, sxfer, LIBUSB_TRANSFER_ERROR); + } + + while ((sxfer = TAILQ_FIRST(&dev->tr_head))) { + TAILQ_REMOVE(&dev->tr_head, sxfer, entry); + + /* complete pending transfer */ + libusb10_complete_transfer(NULL, sxfer, LIBUSB_TRANSFER_ERROR); + } +} + uint16_t libusb_cpu_to_le16(uint16_t x) { diff --git a/lib/libusb/libusb10.h b/lib/libusb/libusb10.h index e516de17b1e9..7c34f895b0aa 100644 --- a/lib/libusb/libusb10.h +++ b/lib/libusb/libusb10.h @@ -116,6 +116,8 @@ struct libusb_context { struct libusb_device { int refcnt; + int device_is_gone; + uint32_t claimed_interfaces; struct libusb_super_pollfd dev_poll; @@ -134,5 +136,6 @@ extern struct libusb_context *usbi_default_context; void libusb10_add_pollfd(libusb_context *ctx, struct libusb_super_pollfd *pollfd, struct libusb20_device *pdev, int fd, short events); void libusb10_remove_pollfd(libusb_context *ctx, struct libusb_super_pollfd *pollfd); void libusb10_cancel_all_transfer(libusb_device *dev); +void libusb10_cancel_all_transfer_locked(struct libusb20_device *pdev, struct libusb_device *dev); #endif /* __LIBUSB10_H__ */ diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c index e25b6a37d77d..42fbd0e2e30b 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -161,17 +161,19 @@ libusb10_handle_events_sub(struct libusb_context *ctx, struct timeval *tv) if (ppdev[i] != NULL) { dev = libusb_get_device(ppdev[i]); - if (fds[i].revents == 0) - err = 0; /* nothing to do */ - else + if (fds[i].revents != 0) { err = libusb20_dev_process(ppdev[i]); - if (err) { - /* cancel all transfers - device is gone */ - libusb10_cancel_all_transfer(dev); + if (err) { + /* set device is gone */ + dev->device_is_gone = 1; - /* remove USB device from polling loop */ - libusb10_remove_pollfd(dev->ctx, &dev->dev_poll); + /* remove USB device from polling loop */ + libusb10_remove_pollfd(dev->ctx, &dev->dev_poll); + + /* cancel all pending transfers */ + libusb10_cancel_all_transfer_locked(ppdev[i], dev); + } } CTX_UNLOCK(ctx); libusb_unref_device(dev); @@ -180,10 +182,8 @@ libusb10_handle_events_sub(struct libusb_context *ctx, struct timeval *tv) } else { uint8_t dummy; - while (1) { - if (read(fds[i].fd, &dummy, 1) != 1) - break; - } + while (read(fds[i].fd, &dummy, 1) == 1) + ; } } From 19b4f0dca0cf914fa9a60c824f5dfe6be962c703 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Wed, 12 Sep 2018 19:41:16 +0000 Subject: [PATCH 13/54] Fix unlink(1) for files starting with - Restore the original behavior of unlink(1), passing the provided filename directly to unlink(2), handling the first argument being "--" correctly. This fixes "unlink -foo", broken in r97533. PR: 228448 Submitted by: Brennan Vincent (original version) Submitted by: Yuri Pankov Reported by: Brennan Vincent Reviewed by: emaste, kevans, vangyzen, 0mp Approved by: re (delphij) Differential Revision: https://reviews.freebsd.org/D17132 --- bin/rm/Makefile | 5 ++++ bin/rm/rm.1 | 9 ++++++-- bin/rm/rm.c | 13 +++++------ bin/rm/tests/Makefile | 5 ++++ bin/rm/tests/Makefile.depend | 11 +++++++++ bin/rm/tests/rm_test.sh | 45 ++++++++++++++++++++++++++++++++++++ etc/mtree/BSD.tests.dist | 2 ++ 7 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 bin/rm/tests/Makefile create mode 100644 bin/rm/tests/Makefile.depend create mode 100755 bin/rm/tests/rm_test.sh diff --git a/bin/rm/Makefile b/bin/rm/Makefile index e0d27134825a..b044ba86e55e 100644 --- a/bin/rm/Makefile +++ b/bin/rm/Makefile @@ -1,10 +1,15 @@ # @(#)Makefile 8.1 (Berkeley) 5/31/93 # $FreeBSD$ +.include + PACKAGE=runtime PROG= rm LINKS= ${BINDIR}/rm ${BINDIR}/unlink MLINKS= rm.1 unlink.1 +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include diff --git a/bin/rm/rm.1 b/bin/rm/rm.1 index 192b1652bc5e..295082b07cf2 100644 --- a/bin/rm/rm.1 +++ b/bin/rm/rm.1 @@ -32,7 +32,7 @@ .\" @(#)rm.1 8.5 (Berkeley) 12/5/94 .\" $FreeBSD$ .\" -.Dd November 7, 2015 +.Dd September 12, 2018 .Dt RM 1 .Os .Sh NAME @@ -45,6 +45,7 @@ .Op Fl dIPRrvWx .Ar .Nm unlink +.Op Fl - .Ar file .Sh DESCRIPTION The @@ -154,6 +155,9 @@ No options may be supplied in this simple mode of operation, which performs an .Xr unlink 2 operation on the passed argument. +However, the usual option-end delimiter, +.Fl - , +may optionally precede the argument. .Sh EXIT STATUS The .Nm @@ -201,11 +205,12 @@ directory hierarchy: .Pp .Dl $ rm -rf foobar .Pp -Either of these commands will remove the file +Any of these commands will remove the file .Pa -f : .Bd -literal -offset indent $ rm -- -f $ rm ./-f +$ unlink -f .Ed .Sh COMPATIBILITY The diff --git a/bin/rm/rm.c b/bin/rm/rm.c index 0aa110248d46..ba69ece1151e 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -101,13 +101,12 @@ main(int argc, char *argv[]) else ++p; if (strcmp(p, "unlink") == 0) { - while (getopt(argc, argv, "") != -1) + if (argc == 2) + rm_file(&argv[1]); + else if (argc == 3 && strcmp(argv[1], "--") == 0) + rm_file(&argv[2]); + else usage(); - argc -= optind; - argv += optind; - if (argc != 1) - usage(); - rm_file(&argv[0]); exit(eval); } @@ -634,7 +633,7 @@ usage(void) (void)fprintf(stderr, "%s\n%s\n", "usage: rm [-f | -i] [-dIPRrvWx] file ...", - " unlink file"); + " unlink [--] file"); exit(EX_USAGE); } diff --git a/bin/rm/tests/Makefile b/bin/rm/tests/Makefile new file mode 100644 index 000000000000..aa0984b529d5 --- /dev/null +++ b/bin/rm/tests/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +ATF_TESTS_SH+= rm_test + +.include diff --git a/bin/rm/tests/Makefile.depend b/bin/rm/tests/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bin/rm/tests/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bin/rm/tests/rm_test.sh b/bin/rm/tests/rm_test.sh new file mode 100755 index 000000000000..31ee64961a97 --- /dev/null +++ b/bin/rm/tests/rm_test.sh @@ -0,0 +1,45 @@ +# +# Copyright 2018 Yuri Pankov +# +# 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. +# +# $FreeBSD$ +# + +atf_test_case unlink_dash_filename +unlink_dash_filename_head() +{ + atf_set "descr" "unlink correctly handles -filename" +} +unlink_dash_filename_body() +{ + touch -- foo bar -foo -bar + atf_check -s exit:0 unlink foo + atf_check -s exit:0 unlink -- bar + atf_check -s exit:0 unlink -foo + atf_check -s exit:0 unlink -- -bar +} + +atf_init_test_cases() +{ + atf_add_test_case unlink_dash_filename +} diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 35107e8dc0c7..24bad91a0fdf 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -34,6 +34,8 @@ .. pwait .. + rm + .. rmdir .. sh From 219cf81b4d9fb7b1651a9e4b85ba77aa92f99fd3 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 13 Sep 2018 04:08:48 +0000 Subject: [PATCH 14/54] Move all pam related config to lib/libpam/ Approved by: re (rgrimes), will (mentor), des Differential Revision: https://reviews.freebsd.org/D17122 --- etc/Makefile | 1 - lib/libpam/Makefile | 2 +- {etc => lib/libpam}/pam.d/Makefile | 23 +++++++---------------- {etc => lib/libpam}/pam.d/README | 0 {etc => lib/libpam}/pam.d/atrun | 0 {etc => lib/libpam}/pam.d/convert.pl | 0 {etc => lib/libpam}/pam.d/cron | 0 {etc => lib/libpam}/pam.d/ftpd | 0 {etc => lib/libpam}/pam.d/imap | 0 {etc => lib/libpam}/pam.d/login | 0 {etc => lib/libpam}/pam.d/other | 0 {etc => lib/libpam}/pam.d/passwd | 0 {etc => lib/libpam}/pam.d/pop3 | 0 {etc => lib/libpam}/pam.d/sshd | 0 {etc => lib/libpam}/pam.d/su | 0 {etc => lib/libpam}/pam.d/system | 0 {etc => lib/libpam}/pam.d/telnetd | 0 {etc => lib/libpam}/pam.d/xdm | 0 18 files changed, 8 insertions(+), 18 deletions(-) rename {etc => lib/libpam}/pam.d/Makefile (56%) rename {etc => lib/libpam}/pam.d/README (100%) rename {etc => lib/libpam}/pam.d/atrun (100%) rename {etc => lib/libpam}/pam.d/convert.pl (100%) rename {etc => lib/libpam}/pam.d/cron (100%) rename {etc => lib/libpam}/pam.d/ftpd (100%) rename {etc => lib/libpam}/pam.d/imap (100%) rename {etc => lib/libpam}/pam.d/login (100%) rename {etc => lib/libpam}/pam.d/other (100%) rename {etc => lib/libpam}/pam.d/passwd (100%) rename {etc => lib/libpam}/pam.d/pop3 (100%) rename {etc => lib/libpam}/pam.d/sshd (100%) rename {etc => lib/libpam}/pam.d/su (100%) rename {etc => lib/libpam}/pam.d/system (100%) rename {etc => lib/libpam}/pam.d/telnetd (100%) rename {etc => lib/libpam}/pam.d/xdm (100%) diff --git a/etc/Makefile b/etc/Makefile index 0fa9ec64245e..71283a973eaa 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -121,7 +121,6 @@ distribution: ${_+_}cd ${.CURDIR}/mtree; ${MAKE} install ${_+_}cd ${SRCTOP}/share/termcap; ${MAKE} etc-termcap ${_+_}cd ${SRCTOP}/usr.sbin/rmt; ${MAKE} etc-rmt - ${_+_}cd ${.CURDIR}/pam.d; ${MAKE} install .if ${MK_UNBOUND} != "no" if [ ! -e ${DESTDIR}/etc/unbound ]; then \ ${INSTALL_SYMLINK} ../var/unbound ${DESTDIR}/etc/unbound; \ diff --git a/lib/libpam/Makefile b/lib/libpam/Makefile index fa73b95b140d..95d922880813 100644 --- a/lib/libpam/Makefile +++ b/lib/libpam/Makefile @@ -25,7 +25,7 @@ # $FreeBSD$ # The modules link in libpam. They build the static modules as well. -SUBDIR+= libpam modules +SUBDIR+= libpam modules pam.d SUBDIR_DEPEND_modules= libpam SUBDIR+= static_libpam SUBDIR_DEPEND_static_libpam= modules diff --git a/etc/pam.d/Makefile b/lib/libpam/pam.d/Makefile similarity index 56% rename from etc/pam.d/Makefile rename to lib/libpam/pam.d/Makefile index 195274fae541..86aaacfca3c9 100644 --- a/etc/pam.d/Makefile +++ b/lib/libpam/pam.d/Makefile @@ -4,9 +4,8 @@ NO_OBJ= -FILESGROUPS= FILES - -FILES= README \ +CONFGROUPS= CONFS +CONFS= README \ cron \ imap \ login \ @@ -15,34 +14,26 @@ FILES= README \ sshd su system \ xdm -FILESDIR= /etc/pam.d -FILESMODE= 644 +CONFDIR= /etc/pam.d +CONFSMODE_README= 444 .if ${MK_AT} != "no" -FILESGROUPS+= AT +CONFGROUPS+= AT AT+= atrun ATPACKAGE+= at -ATDIR= ${FILESDIR} -ATMODE= ${FILESMODE} .endif .if ${MK_FTP} != "no" -FILESGROUPS+= FTP +CONFGROUPS+= FTP FTP+= ftpd FTPPACKAGE+= ftp -FTPDIR= ${FILESDIR} -FTPMODE= ${FILESMODE} LINKS= ${FILESDIR}/ftpd ${FILESDIR}/ftp .endif .if ${MK_TELNET} != "no" -FILESGROUPS+= TELNET +CONFGROUPS+= TELNET TELNET+= telnetd TELNETPACKAGE+= telnet -TELNETDIR= ${FILESDIR} -TELNETMODE= ${FILESMODE} .endif -FILESMODE_README= 444 - .include diff --git a/etc/pam.d/README b/lib/libpam/pam.d/README similarity index 100% rename from etc/pam.d/README rename to lib/libpam/pam.d/README diff --git a/etc/pam.d/atrun b/lib/libpam/pam.d/atrun similarity index 100% rename from etc/pam.d/atrun rename to lib/libpam/pam.d/atrun diff --git a/etc/pam.d/convert.pl b/lib/libpam/pam.d/convert.pl similarity index 100% rename from etc/pam.d/convert.pl rename to lib/libpam/pam.d/convert.pl diff --git a/etc/pam.d/cron b/lib/libpam/pam.d/cron similarity index 100% rename from etc/pam.d/cron rename to lib/libpam/pam.d/cron diff --git a/etc/pam.d/ftpd b/lib/libpam/pam.d/ftpd similarity index 100% rename from etc/pam.d/ftpd rename to lib/libpam/pam.d/ftpd diff --git a/etc/pam.d/imap b/lib/libpam/pam.d/imap similarity index 100% rename from etc/pam.d/imap rename to lib/libpam/pam.d/imap diff --git a/etc/pam.d/login b/lib/libpam/pam.d/login similarity index 100% rename from etc/pam.d/login rename to lib/libpam/pam.d/login diff --git a/etc/pam.d/other b/lib/libpam/pam.d/other similarity index 100% rename from etc/pam.d/other rename to lib/libpam/pam.d/other diff --git a/etc/pam.d/passwd b/lib/libpam/pam.d/passwd similarity index 100% rename from etc/pam.d/passwd rename to lib/libpam/pam.d/passwd diff --git a/etc/pam.d/pop3 b/lib/libpam/pam.d/pop3 similarity index 100% rename from etc/pam.d/pop3 rename to lib/libpam/pam.d/pop3 diff --git a/etc/pam.d/sshd b/lib/libpam/pam.d/sshd similarity index 100% rename from etc/pam.d/sshd rename to lib/libpam/pam.d/sshd diff --git a/etc/pam.d/su b/lib/libpam/pam.d/su similarity index 100% rename from etc/pam.d/su rename to lib/libpam/pam.d/su diff --git a/etc/pam.d/system b/lib/libpam/pam.d/system similarity index 100% rename from etc/pam.d/system rename to lib/libpam/pam.d/system diff --git a/etc/pam.d/telnetd b/lib/libpam/pam.d/telnetd similarity index 100% rename from etc/pam.d/telnetd rename to lib/libpam/pam.d/telnetd diff --git a/etc/pam.d/xdm b/lib/libpam/pam.d/xdm similarity index 100% rename from etc/pam.d/xdm rename to lib/libpam/pam.d/xdm From d01d12de14aa6c93c21a9b6cfb515933394b380a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Thu, 13 Sep 2018 07:04:00 +0000 Subject: [PATCH 15/54] x86bios: use M_NOWAIT with mallocs Or else it triggers the following bug: APIC: CPU 6 has ACPI ID 6 APIC: CPU 7 has ACPI ID 7 panic: vm_wait in early boot cpuid = 0 time = 1 KDB: stack backtrace: db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xffffffff826ff8d0 vpanic() at vpanic+0x1a3/frame 0xffffffff826ff930 panic() at panic+0x43/frame 0xffffffff826ff990 vm_wait_domain() at vm_wait_domain+0xf9/frame 0xffffffff826ff9c0 kmem_alloc_contig_domain() at kmem_alloc_contig_domain+0x252/frame 0xffffffff826ffa50 kmem_alloc_contig() at kmem_alloc_contig+0x6c/frame 0xffffffff826ffad0 contigmalloc() at contigmalloc+0x2e/frame 0xffffffff826ffb00 x86bios_modevent() at x86bios_modevent+0x225/frame 0xffffffff826ffb20 module_register_init() at module_register_init+0xc0/frame 0xffffffff826ffb50 mi_startup() at mi_startup+0x118/frame 0xffffffff826ffb70 start_kernel() at start_kernel+0x10 While there also make x86bios_unmap_mem idempotent. Reviewed by: kib Approved by: re (gjb) Sponsored by: Citrix Systems R&D Differential revision: https://reviews.freebsd.org/D17000 --- sys/compat/x86bios/x86bios.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/sys/compat/x86bios/x86bios.c b/sys/compat/x86bios/x86bios.c index d9917383d13d..542f04cc0b0d 100644 --- a/sys/compat/x86bios/x86bios.c +++ b/sys/compat/x86bios/x86bios.c @@ -656,17 +656,24 @@ static __inline void x86bios_unmap_mem(void) { - free(x86bios_map, M_DEVBUF); - if (x86bios_ivt != NULL) + if (x86bios_map != NULL) { + free(x86bios_map, M_DEVBUF); + x86bios_map = NULL; + } + if (x86bios_ivt != NULL) { #ifdef X86BIOS_NATIVE_ARCH pmap_unmapbios((vm_offset_t)x86bios_ivt, X86BIOS_IVT_SIZE); #else free(x86bios_ivt, M_DEVBUF); + x86bios_ivt = NULL; #endif + } if (x86bios_rom != NULL) pmap_unmapdev((vm_offset_t)x86bios_rom, X86BIOS_ROM_SIZE); - if (x86bios_seg != NULL) + if (x86bios_seg != NULL) { contigfree(x86bios_seg, X86BIOS_SEG_SIZE, M_DEVBUF); + x86bios_seg = NULL; + } } static __inline int @@ -674,7 +681,9 @@ x86bios_map_mem(void) { x86bios_map = malloc(sizeof(*x86bios_map) * X86BIOS_PAGES, M_DEVBUF, - M_WAITOK | M_ZERO); + M_NOWAIT | M_ZERO); + if (x86bios_map == NULL) + goto fail; #ifdef X86BIOS_NATIVE_ARCH x86bios_ivt = pmap_mapbios(X86BIOS_IVT_BASE, X86BIOS_IVT_SIZE); @@ -688,7 +697,9 @@ x86bios_map_mem(void) rounddown(x86bios_rom_phys, X86BIOS_PAGE_SIZE); else #else - x86bios_ivt = malloc(X86BIOS_IVT_SIZE, M_DEVBUF, M_ZERO | M_WAITOK); + x86bios_ivt = malloc(X86BIOS_IVT_SIZE, M_DEVBUF, M_NOWAIT | M_ZERO); + if (x86bios_ivt == NULL) + goto fail; #endif x86bios_rom_phys = X86BIOS_ROM_BASE; @@ -703,8 +714,10 @@ x86bios_map_mem(void) goto fail; #endif - x86bios_seg = contigmalloc(X86BIOS_SEG_SIZE, M_DEVBUF, M_WAITOK, + x86bios_seg = contigmalloc(X86BIOS_SEG_SIZE, M_DEVBUF, M_NOWAIT, X86BIOS_RAM_BASE, x86bios_rom_phys, X86BIOS_PAGE_SIZE, 0); + if (x86bios_seg == NULL) + goto fail; x86bios_seg_phys = vtophys(x86bios_seg); x86bios_set_pages((vm_offset_t)x86bios_ivt, X86BIOS_IVT_BASE, From a515acf7bbe3b6e8c9c925e5fc87149246cf0be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Thu, 13 Sep 2018 07:05:51 +0000 Subject: [PATCH 16/54] msi: remove the check that interrupt sources have been added When running as a specific type of Xen guest the hypervisor won't provide any emulated IO-APICs or legacy PICs at all, thus hitting the following assert in the MSI code: panic: Assertion num_io_irqs > 0 failed at /usr/src/sys/x86/x86/msi.c:334 cpuid = 0 time = 1 KDB: stack backtrace: db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xffffffff826ffa70 vpanic() at vpanic+0x1a3/frame 0xffffffff826ffad0 panic() at panic+0x43/frame 0xffffffff826ffb30 msi_init() at msi_init+0xed/frame 0xffffffff826ffb40 apic_setup_io() at apic_setup_io+0x72/frame 0xffffffff826ffb50 mi_startup() at mi_startup+0x118/frame 0xffffffff826ffb70 start_kernel() at start_kernel+0x10 Fix this by removing the assert in the MSI code, since it's possible to get to the MSI initialization without having registered any other interrupt sources. Reviewed by: jhb Approved by: re (gjb) Sponsored by: Citrix Systems R&D Differential revision: https://reviews.freebsd.org/D17001 --- sys/x86/x86/msi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sys/x86/x86/msi.c b/sys/x86/x86/msi.c index 1c5502cedde6..971b07d7c46f 100644 --- a/sys/x86/x86/msi.c +++ b/sys/x86/x86/msi.c @@ -331,7 +331,6 @@ msi_init(void) } #endif - MPASS(num_io_irqs > 0); first_msi_irq = max(MINIMUM_MSI_INT, num_io_irqs); num_io_irqs = first_msi_irq + NUM_MSI_INTS; From fae9a0cb9b52299b1e32d0ee07d1881c24268962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Thu, 13 Sep 2018 07:07:13 +0000 Subject: [PATCH 17/54] xen: fix PV IPI setup So that it's done when the vcpu_id has been set. For the BSP the vcpu_id is set at SUB_INTR, while for the APs it's done in init_secondary_tail that's called at SUB_SMP order FIRST. Reported and tested by: cperciva Approved by: re (gjb) Sponsored by: Citrix Systems R&D Differential revision: https://reviews.freebsd.org/D17013 --- sys/x86/xen/xen_apic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/x86/xen/xen_apic.c b/sys/x86/xen/xen_apic.c index 09ba28f9e46b..7d254ef3f734 100644 --- a/sys/x86/xen/xen_apic.c +++ b/sys/x86/xen/xen_apic.c @@ -592,6 +592,6 @@ xen_setup_cpus(void) apic_ops.ipi_vectored = xen_pv_lapic_ipi_vectored; } -/* We need to setup IPIs before APs are started */ -SYSINIT(xen_setup_cpus, SI_SUB_SMP-1, SI_ORDER_FIRST, xen_setup_cpus, NULL); +/* Switch to using PV IPIs as soon as the vcpu_id is set. */ +SYSINIT(xen_setup_cpus, SI_SUB_SMP, SI_ORDER_SECOND, xen_setup_cpus, NULL); #endif /* SMP */ From c9a591b0f6f98ba1de5d66ad43361f56545ebf9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Thu, 13 Sep 2018 07:08:31 +0000 Subject: [PATCH 18/54] xen: remove xenpv_set_ids The vcpu_id for legacy PVH mode can be set from the output of cpuid, so there's no need to have a special function to set it. Also note that xenpv_set_ids should have been executed only for PV guests, but was executed for all guests types and vcpu_id was later fixed up for HVM guests. Reported by: cperciva Approved by: re (gjb) Sponsored by: Citrix Systems R&D --- sys/x86/xen/hvm.c | 3 +++ sys/x86/xen/pvcpu_enum.c | 16 ---------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/sys/x86/xen/hvm.c b/sys/x86/xen/hvm.c index 24b5f1d2e72e..fc657411812c 100644 --- a/sys/x86/xen/hvm.c +++ b/sys/x86/xen/hvm.c @@ -419,6 +419,9 @@ xen_hvm_cpu_init(void) */ KASSERT(cpuid_base != 0, ("Invalid base Xen CPUID leaf")); cpuid_count(cpuid_base + 4, 0, regs); + KASSERT((regs[0] & XEN_HVM_CPUID_VCPU_ID_PRESENT) || + !xen_pv_domain(), + ("Xen PV domain without vcpu_id in cpuid")); PCPU_SET(vcpu_id, (regs[0] & XEN_HVM_CPUID_VCPU_ID_PRESENT) ? regs[1] : PCPU_GET(acpi_id)); diff --git a/sys/x86/xen/pvcpu_enum.c b/sys/x86/xen/pvcpu_enum.c index e647a6fe8e9d..b65f2bdb3a69 100644 --- a/sys/x86/xen/pvcpu_enum.c +++ b/sys/x86/xen/pvcpu_enum.c @@ -249,19 +249,3 @@ xenpv_register(void *dummy __unused) } } SYSINIT(xenpv_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST, xenpv_register, NULL); - -/* - * Setup per-CPU vCPU IDs - */ -static void -xenpv_set_ids(void *dummy) -{ - struct pcpu *pc; - int i; - - CPU_FOREACH(i) { - pc = pcpu_find(i); - pc->pc_vcpu_id = i; - } -} -SYSINIT(xenpv_set_ids, SI_SUB_CPU, SI_ORDER_MIDDLE, xenpv_set_ids, NULL); From ddbc1b4387277d0f331e5b63a1bd070c60942d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Thu, 13 Sep 2018 07:09:41 +0000 Subject: [PATCH 19/54] xen: fix initial kenv setup for legacy PVH When adding support for the new PVH mode the kenv handling was switched to use a boot time allocated scratch space, however the legacy PVH early boot code was not modified to allocate such space. Approved by: re (gjb) Sponsored by: Citrix Systems R&D --- sys/x86/xen/pv.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c index 3f85b156d828..4505907172c0 100644 --- a/sys/x86/xen/pv.c +++ b/sys/x86/xen/pv.c @@ -204,6 +204,7 @@ hammer_time_xen_legacy(start_info_t *si, uint64_t xenstack) uint64_t *PT3 = (u_int64_t *)(xenstack + PAGE_SIZE); uint64_t *PT2 = (u_int64_t *)(xenstack + 2 * PAGE_SIZE); int i; + char *kenv; xen_domain_type = XEN_PV_DOMAIN; vm_guest = VM_GUEST_XEN; @@ -252,6 +253,15 @@ hammer_time_xen_legacy(start_info_t *si, uint64_t xenstack) } load_cr3(((uint64_t)&PT4[0]) - KERNBASE); + /* + * Init an empty static kenv using a free page. The contents will be + * filled from the parse_preload_data hook. + */ + kenv = (void *)(physfree + KERNBASE); + physfree += PAGE_SIZE; + bzero(kenv, PAGE_SIZE); + init_static_kenv(kenv, PAGE_SIZE); + /* Set the hooks for early functions that diverge from bare metal */ init_ops = xen_legacy_init_ops; apic_ops = xen_apic_ops; From 4fcd5f3003cc7d4d7d59adf8ffb9b2876a9ba136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Thu, 13 Sep 2018 07:11:11 +0000 Subject: [PATCH 20/54] xen: limit the usage of PIRQs to a legacy PVH Dom0 That's the only mode in FreeBSD that requires the usage of PIRQs, so there's no need to attach the PIRQ PIC when running in other modes. Approved by: re (gjb) Sponsored by: Citrix Systems R&D --- sys/x86/xen/xen_intr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/x86/xen/xen_intr.c b/sys/x86/xen/xen_intr.c index 559f3192255a..59eeea2ad1fd 100644 --- a/sys/x86/xen/xen_intr.c +++ b/sys/x86/xen/xen_intr.c @@ -656,7 +656,8 @@ xen_intr_init(void *dummy __unused) xen_intr_pirq_eoi_map_enabled = true; intr_register_pic(&xen_intr_pic); - intr_register_pic(&xen_intr_pirq_pic); + if (xen_pv_domain() && xen_initial_domain()) + intr_register_pic(&xen_intr_pirq_pic); if (bootverbose) printf("Xen interrupt system initialized\n"); From 4edbde911bc4e3af277987a9305f296be7789db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Thu, 13 Sep 2018 07:12:16 +0000 Subject: [PATCH 21/54] xen: fix setting legacy PVH vcpu id The recommended way to obtain the vcpu id is using the cpuid instruction with a specific leaf value. This leaf value must be obtained at runtime, and it's done when populating the hypercall page. Legacy PVH however will get the hypercall page populated by the hypervisor itself before booting, so the cpuid leaf was not actually set, thus preventing setting the vcpu id value from cpuid. Fix this by making sure the cpuid leaf has been probed before attempting to set the vcpu id. Approved by: re (gjb) Sponsored by: Citrix Systems R&D --- sys/x86/xen/hvm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/x86/xen/hvm.c b/sys/x86/xen/hvm.c index fc657411812c..6983a20ecf82 100644 --- a/sys/x86/xen/hvm.c +++ b/sys/x86/xen/hvm.c @@ -163,6 +163,12 @@ xen_hvm_init_hypercall_stubs(enum xen_hvm_init_type init_type) { uint32_t regs[4]; + /* Legacy PVH will get here without the cpuid leaf being set. */ + if (cpuid_base == 0) + cpuid_base = xen_hvm_cpuid_base(); + if (cpuid_base == 0) + return (ENXIO); + if (xen_domain() && init_type == XEN_HVM_INIT_LATE) { /* * If the domain type is already set we can assume that the @@ -173,10 +179,6 @@ xen_hvm_init_hypercall_stubs(enum xen_hvm_init_type init_type) return 0; } - cpuid_base = xen_hvm_cpuid_base(); - if (cpuid_base == 0) - return (ENXIO); - if (init_type == XEN_HVM_INIT_LATE) hypervisor_version(); From d7627401ecaa772ca6034eb64c8810369448e579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Thu, 13 Sep 2018 07:13:13 +0000 Subject: [PATCH 22/54] lapic: skip setting intrcnt if lapic is not present Instead of panicking. Legacy PVH mode doesn't provide a lapic, and since native_lapic_intrcnt is called unconditionally this would cause the assert to trigger. Change the assert into a continue in order to take into account the possibility of systems without a lapic. Reviewed by: jhb Approved by: re (gjb) Sponsored by: Citrix Systems R&D Differential revision: https://reviews.freebsd.org/D17015 --- sys/x86/x86/local_apic.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/x86/x86/local_apic.c b/sys/x86/x86/local_apic.c index 92e71977da4f..75a3adb90bdc 100644 --- a/sys/x86/x86/local_apic.c +++ b/sys/x86/x86/local_apic.c @@ -855,7 +855,8 @@ native_lapic_intrcnt(void *dummy __unused) STAILQ_FOREACH(pc, &cpuhead, pc_allcpu) { la = &lapics[pc->pc_apic_id]; - KASSERT(la->la_present, ("missing APIC structure")); + if (!la->la_present) + continue; snprintf(buf, sizeof(buf), "cpu%d:timer", pc->pc_cpuid); intrcnt_add(buf, &la->la_timer_count); From a74cdf4e747667a8d7db4dcdc57cf97db822444d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Thu, 13 Sep 2018 07:14:11 +0000 Subject: [PATCH 23/54] xen: legacy PVH fixes for the new interrupt count Register interrupts using the PIC pic_register_sources method instead of doing it in apic_setup_io. This is now required, since the internal interrupt structures are not yet setup when calling apic_setup_io. Approved by: re (gjb) Sponsored by: Citrix Systems R&D --- sys/x86/xen/pvcpu_enum.c | 93 +++++++++++++++++++++++----------------- sys/x86/xen/xen_intr.c | 3 ++ sys/xen/xen_intr.h | 10 +++++ 3 files changed, 66 insertions(+), 40 deletions(-) diff --git a/sys/x86/xen/pvcpu_enum.c b/sys/x86/xen/pvcpu_enum.c index b65f2bdb3a69..4c4bcec186bb 100644 --- a/sys/x86/xen/pvcpu_enum.c +++ b/sys/x86/xen/pvcpu_enum.c @@ -193,54 +193,67 @@ xenpv_setup_io(void) { if (xen_initial_domain()) { - int i, ret; - - /* Map MADT */ - madt_physaddr = acpi_find_table(ACPI_SIG_MADT); - madt = acpi_map_table(madt_physaddr, ACPI_SIG_MADT); - madt_length = madt->Header.Length; - - /* Try to initialize ACPI so that we can access the FADT. */ - i = acpi_Startup(); - if (ACPI_FAILURE(i)) { - printf("MADT: ACPI Startup failed with %s\n", - AcpiFormatException(i)); - printf("Try disabling either ACPI or apic support.\n"); - panic("Using MADT but ACPI doesn't work"); - } - - /* Run through the table to see if there are any overrides. */ - madt_walk_table(madt_parse_ints, NULL); - /* - * If there was not an explicit override entry for the SCI, - * force it to use level trigger and active-low polarity. + * NB: we could iterate over the MADT IOAPIC entries in order + * to figure out the exact number of IOAPIC interrupts, but + * this is legacy code so just keep using the previous + * behaviour and assume a maximum of 256 interrupts. */ - if (!madt_found_sci_override) { - printf( - "MADT: Forcing active-low polarity and level trigger for SCI\n"); - ret = xen_register_pirq(AcpiGbl_FADT.SciInterrupt, - INTR_TRIGGER_LEVEL, INTR_POLARITY_LOW); - if (ret != 0) - panic("Unable to register SCI IRQ"); - } - - /* Register legacy ISA IRQs */ - for (i = 1; i < 16; i++) { - if (intr_lookup_source(i) != NULL) - continue; - ret = xen_register_pirq(i, INTR_TRIGGER_EDGE, - INTR_POLARITY_LOW); - if (ret != 0 && bootverbose) - printf("Unable to register legacy IRQ#%d: %d\n", - i, ret); - } + num_io_irqs = max(MINIMUM_MSI_INT - 1, num_io_irqs); acpi_SetDefaultIntrModel(ACPI_INTR_APIC); } return (0); } +void +xenpv_register_pirqs(struct pic *pic __unused) +{ + unsigned int i; + int ret; + + /* Map MADT */ + madt_physaddr = acpi_find_table(ACPI_SIG_MADT); + madt = acpi_map_table(madt_physaddr, ACPI_SIG_MADT); + madt_length = madt->Header.Length; + + /* Try to initialize ACPI so that we can access the FADT. */ + ret = acpi_Startup(); + if (ACPI_FAILURE(ret)) { + printf("MADT: ACPI Startup failed with %s\n", + AcpiFormatException(ret)); + printf("Try disabling either ACPI or apic support.\n"); + panic("Using MADT but ACPI doesn't work"); + } + + /* Run through the table to see if there are any overrides. */ + madt_walk_table(madt_parse_ints, NULL); + + /* + * If there was not an explicit override entry for the SCI, + * force it to use level trigger and active-low polarity. + */ + if (!madt_found_sci_override) { + printf( +"MADT: Forcing active-low polarity and level trigger for SCI\n"); + ret = xen_register_pirq(AcpiGbl_FADT.SciInterrupt, + INTR_TRIGGER_LEVEL, INTR_POLARITY_LOW); + if (ret != 0) + panic("Unable to register SCI IRQ"); + } + + /* Register legacy ISA IRQs */ + for (i = 1; i < 16; i++) { + if (intr_lookup_source(i) != NULL) + continue; + ret = xen_register_pirq(i, INTR_TRIGGER_EDGE, + INTR_POLARITY_LOW); + if (ret != 0 && bootverbose) + printf("Unable to register legacy IRQ#%u: %d\n", i, + ret); + } +} + static void xenpv_register(void *dummy __unused) { diff --git a/sys/x86/xen/xen_intr.c b/sys/x86/xen/xen_intr.c index 59eeea2ad1fd..c1cb0707cde9 100644 --- a/sys/x86/xen/xen_intr.c +++ b/sys/x86/xen/xen_intr.c @@ -178,6 +178,9 @@ struct pic xen_intr_pic = { * physical interrupt sources. */ struct pic xen_intr_pirq_pic = { +#ifdef __amd64__ + .pic_register_sources = xenpv_register_pirqs, +#endif .pic_enable_source = xen_intr_pirq_enable_source, .pic_disable_source = xen_intr_pirq_disable_source, .pic_eoi_source = xen_intr_pirq_eoi_source, diff --git a/sys/xen/xen_intr.h b/sys/xen/xen_intr.h index eb3436d601b8..4aa4a9a8b8ea 100644 --- a/sys/xen/xen_intr.h +++ b/sys/xen/xen_intr.h @@ -274,4 +274,14 @@ int xen_intr_add_handler(const char *name, driver_filter_t filter, int xen_intr_get_evtchn_from_port(evtchn_port_t port, xen_intr_handle_t *handlep); +/** + * Register the IO-APIC PIRQs when running in legacy PVH Dom0 mode. + * + * \param pic PIC instance. + * + * NB: this should be removed together with the support for legacy PVH mode. + */ +struct pic; +void xenpv_register_pirqs(struct pic *pic); + #endif /* _XEN_INTR_H_ */ From 5ff6c7f3638411bf7e82dedd57f0f7cba57bc77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Thu, 13 Sep 2018 07:15:02 +0000 Subject: [PATCH 24/54] xen: temporary disable SMAP when forwarding hypercalls from user-space The Xen page-table walker used to resolve the virtual addresses in the hypercalls will refuse to access user-space pages when SMAP is enabled unless the AC flag in EFLAGS is set (just like normal hardware with SMAP support would do). Since privcmd allows forwarding hypercalls (and buffers) from user-space into Xen make sure SMAP is temporary disabled for the duration of the hypercall from user-space. Approved by: re (gjb) Sponsored by: Citrix Systems R&D --- sys/dev/xen/privcmd/privcmd.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/dev/xen/privcmd/privcmd.c b/sys/dev/xen/privcmd/privcmd.c index 246390e3b7c2..e09886f42adb 100644 --- a/sys/dev/xen/privcmd/privcmd.c +++ b/sys/dev/xen/privcmd/privcmd.c @@ -232,9 +232,21 @@ privcmd_ioctl(struct cdev *dev, unsigned long cmd, caddr_t arg, struct ioctl_privcmd_hypercall *hcall; hcall = (struct ioctl_privcmd_hypercall *)arg; - +#ifdef __amd64__ + /* + * The hypervisor page table walker will refuse to access + * user-space pages if SMAP is enabled, so temporary disable it + * while performing the hypercall. + */ + if (cpu_stdext_feature & CPUID_STDEXT_SMAP) + stac(); +#endif error = privcmd_hypercall(hcall->op, hcall->arg[0], hcall->arg[1], hcall->arg[2], hcall->arg[3], hcall->arg[4]); +#ifdef __amd64__ + if (cpu_stdext_feature & CPUID_STDEXT_SMAP) + clac(); +#endif if (error >= 0) { hcall->retval = error; error = 0; From aad4d67d9c72607f761c40ea096f853b4b7683cb Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 13 Sep 2018 07:48:49 +0000 Subject: [PATCH 25/54] Fix build after r338621 by avoiding LINKS and installing the link manually. Approved by: re (rgrimes), will (mentor) --- lib/libpam/pam.d/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/libpam/pam.d/Makefile b/lib/libpam/pam.d/Makefile index 86aaacfca3c9..97bb296d3462 100644 --- a/lib/libpam/pam.d/Makefile +++ b/lib/libpam/pam.d/Makefile @@ -27,7 +27,9 @@ ATPACKAGE+= at CONFGROUPS+= FTP FTP+= ftpd FTPPACKAGE+= ftp -LINKS= ${FILESDIR}/ftpd ${FILESDIR}/ftp + +afterinstallconfig: + ${INSTALL_LINK} ${TAG_ARGS} ${CONFDIR}/ftpd ${CONFDIR}/ftp .endif .if ${MK_TELNET} != "no" From 9696ba7fc0403b54e68788ed8c81b8f9ba033a33 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Thu, 13 Sep 2018 13:57:42 +0000 Subject: [PATCH 26/54] umount: remove sync(2) call when used with -f It completely unnecessarily iterates over all filesystems and happens to be executed a lot e.g. by synth. Reviewed by: kib Approved by: re (gjb) Differential Revision: https://reviews.freebsd.org/D17143 --- sbin/umount/umount.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sbin/umount/umount.c b/sbin/umount/umount.c index 9e8c71d0f1f6..b936c9dc174a 100644 --- a/sbin/umount/umount.c +++ b/sbin/umount/umount.c @@ -136,10 +136,6 @@ main(int argc, char *argv[]) if ((fflag & MNT_FORCE) != 0 && (fflag & MNT_NONBUSY) != 0) err(1, "-f and -n are mutually exclusive"); - /* Start disks transferring immediately. */ - if ((fflag & (MNT_FORCE | MNT_NONBUSY)) == 0 && nfsforce == 0) - sync(); - if ((argc == 0 && !all) || (argc != 0 && all)) usage(); From 0f73f7016baa6015b1b0b582033af2f1c7760af5 Mon Sep 17 00:00:00 2001 From: Edward Tomasz Napierala Date: Thu, 13 Sep 2018 14:06:01 +0000 Subject: [PATCH 27/54] Add new option to the geom(8) utility, "-p". It makes it easy to look up the GEOM class instance from the provider name. Reviewed by: oshogbo, 0mp Approved by: re (kib) MFC after: 2 weeks Relnotes: yes Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D17116 --- sbin/geom/core/geom.8 | 12 +++++++- sbin/geom/core/geom.c | 69 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/sbin/geom/core/geom.8 b/sbin/geom/core/geom.8 index ab960ff9e07b..8cd88cb7792f 100644 --- a/sbin/geom/core/geom.8 +++ b/sbin/geom/core/geom.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 5, 2011 +.Dd September 13, 2018 .Dt GEOM 8 .Os .Sh NAME @@ -52,6 +52,9 @@ .Ar class .Cm unload .Op Fl v +.Nm +.Fl p +.Ar provider-name .Sh DESCRIPTION The .Nm @@ -103,6 +106,13 @@ This command is only available if the given class is loaded as a kernel module. .El .Pp +Additional options include: +.Bl -tag -width ".Cm status" +.It Fl p Ar provider-name +Print detailed information about the geom which provides +.Ar provider-name . +.El +.Pp Class-specific commands are implemented as shared libraries which are stored in .Pa /lib/geom/ diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c index b6142d78e957..9f1655c61a51 100644 --- a/sbin/geom/core/geom.c +++ b/sbin/geom/core/geom.c @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -68,6 +69,7 @@ static struct g_command *class_commands = NULL; #define GEOM_CLASS_CMDS 0x01 #define GEOM_STD_CMDS 0x02 static struct g_command *find_command(const char *cmdstr, int flags); +static void list_one_geom_by_provider(const char *provider_name); static int std_available(const char *name); static void std_help(struct gctl_req *req, unsigned flags); @@ -146,6 +148,7 @@ usage(void) if (class_name == NULL) { fprintf(stderr, "usage: geom [options]\n"); + fprintf(stderr, " geom -p \n"); exit(EXIT_FAILURE); } else { struct g_command *cmd; @@ -650,9 +653,56 @@ get_class(int *argc, char ***argv) usage(); } +static struct ggeom * +find_geom_by_provider(struct gmesh *mesh, const char *name) +{ + struct gclass *classp; + struct ggeom *gp; + struct gprovider *pp; + + LIST_FOREACH(classp, &mesh->lg_class, lg_class) { + LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { + LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { + if (strcmp(pp->lg_name, name) == 0) + return (gp); + } + } + } + + return (NULL); +} + int main(int argc, char *argv[]) { + char *provider_name; + int ch; + + provider_name = NULL; + + if (strcmp(getprogname(), "geom") == 0) { + while ((ch = getopt(argc, argv, "hp:")) != -1) { + switch (ch) { + case 'p': + provider_name = strdup(optarg); + if (provider_name == NULL) + err(1, "strdup"); + break; + case 'h': + default: + usage(); + } + } + + /* + * Don't adjust argc and argv, it would break get_class(). + */ + } + + if (provider_name != NULL) { + list_one_geom_by_provider(provider_name); + return (0); + } get_class(&argc, &argv); run_command(argc, argv); @@ -767,6 +817,25 @@ list_one_geom(struct ggeom *gp) printf("\n"); } +static void +list_one_geom_by_provider(const char *provider_name) +{ + struct gmesh mesh; + struct ggeom *gp; + int error; + + error = geom_gettree(&mesh); + if (error != 0) + errc(EXIT_FAILURE, error, "Cannot get GEOM tree"); + + gp = find_geom_by_provider(&mesh, provider_name); + if (gp == NULL) + errx(EXIT_FAILURE, "Cannot find provider '%s'.", provider_name); + + printf("Geom class: %s\n", gp->lg_class->lg_name); + list_one_geom(gp); +} + static void std_help(struct gctl_req *req __unused, unsigned flags __unused) { From f9d40f5cca4c65aede2ad8abecd5b312792ece89 Mon Sep 17 00:00:00 2001 From: Emmanuel Vadot Date: Thu, 13 Sep 2018 14:08:10 +0000 Subject: [PATCH 28/54] arm64: Make aw_sid and aw_thermal depend on nvmem Both drivers use this interface so add a dependancy on it. Since awg uses aw_sid for generating the MAC address, make it depend on both aw_sid and nmvem so when only removing nvmem from kernel config it will not include this driver. Reported by: sbruno Approved by: re (gjb) --- sys/conf/files.arm64 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 index 33bf1b281eaf..76e9e8e36479 100644 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -33,14 +33,14 @@ arm/allwinner/aw_nmi.c optional aw_nmi fdt \ compile-with "${NORMAL_C} -I$S/gnu/dts/include" arm/allwinner/aw_rsb.c optional aw_rsb fdt arm/allwinner/aw_rtc.c optional aw_rtc fdt -arm/allwinner/aw_sid.c optional aw_sid fdt +arm/allwinner/aw_sid.c optional aw_sid nvmem fdt arm/allwinner/aw_spi.c optional aw_spi fdt arm/allwinner/aw_syscon.c optional aw_syscon ext_resources syscon fdt -arm/allwinner/aw_thermal.c optional aw_thermal fdt +arm/allwinner/aw_thermal.c optional aw_thermal nvmem fdt arm/allwinner/aw_usbphy.c optional ehci aw_usbphy fdt arm/allwinner/aw_wdog.c optional aw_wdog fdt arm/allwinner/axp81x.c optional axp81x fdt -arm/allwinner/if_awg.c optional awg ext_resources syscon fdt +arm/allwinner/if_awg.c optional awg ext_resources syscon aw_sid nvmem fdt # Allwinner clock driver arm/allwinner/clkng/aw_ccung.c optional aw_ccu fdt From 657b6006ba3b82feac209def515a0062eb385566 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Thu, 13 Sep 2018 14:26:53 +0000 Subject: [PATCH 29/54] Enable reproducible builds in advance of 12.0-REL We want to build the 12.0 release artifacts with reproducible builds mode enabled. Switch it on in HEAD now to enable testing with upcoming ALPHA builds. We can revisit the default setting for HEAD after the branch is created. This change eliminates the build metadata (user, hostname, timestamp, etc.) from the kernel and loader. If the src tree is a git, svn or p4 checkout with changes then the metadata is retained. The WITHOUT_REPRODUCIBLE_BUILD src.conf(5) knob can be used to revert to the previous behaviour. Approved by: re (gjb) Sponsored by: The FreeBSD Foundation --- share/mk/src.opts.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/mk/src.opts.mk b/share/mk/src.opts.mk index ac76994b2c75..7667b97bdf2f 100644 --- a/share/mk/src.opts.mk +++ b/share/mk/src.opts.mk @@ -159,6 +159,7 @@ __DEFAULT_YES_OPTIONS = \ QUOTAS \ RADIUS_SUPPORT \ RBOOTD \ + REPRODUCIBLE_BUILD \ RESCUE \ ROUTED \ SENDMAIL \ @@ -201,7 +202,6 @@ __DEFAULT_NO_OPTIONS = \ NAND \ OFED_EXTRA \ OPENLDAP \ - REPRODUCIBLE_BUILD \ RPCBIND_WARMSTART_SUPPORT \ SHARED_TOOLCHAIN \ SORT_THREADS \ From cc41fd23ea58fa3c87d40abb04a9de3259d8e654 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Thu, 13 Sep 2018 14:52:59 +0000 Subject: [PATCH 30/54] Enable reproducible builds in advance of 12.0-REL r338642 toggled the REPRODUCIBLE_BUILD knob but missed the corresponding kern.opts.mk change. We want to build the 12.0 release artifacts with reproducible builds mode enabled. Switch it on in HEAD now to enable testing with upcoming ALPHA builds. We can revisit the default setting for HEAD after the branch is created. This change eliminates the build metadata (user, hostname, timestamp, etc.) from the kernel and loader. If the src tree is a git, svn or p4 checkout with changes then the metadata is retained. The WITHOUT_REPRODUCIBLE_BUILD src.conf(5) knob can be used to revert to the previous behaviour. Approved by: re (gjb) Sponsored by: The FreeBSD Foundation --- sys/conf/kern.opts.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/conf/kern.opts.mk b/sys/conf/kern.opts.mk index 0a229822607c..b5663dc6509a 100644 --- a/sys/conf/kern.opts.mk +++ b/sys/conf/kern.opts.mk @@ -42,6 +42,7 @@ __DEFAULT_YES_OPTIONS = \ MODULE_DRM2 \ NETGRAPH \ PF \ + REPRODUCIBLE_BUILD \ SOURCELESS_HOST \ SOURCELESS_UCODE \ TESTS \ @@ -53,8 +54,7 @@ __DEFAULT_NO_OPTIONS = \ KERNEL_RETPOLINE \ NAND \ OFED \ - RATELIMIT \ - REPRODUCIBLE_BUILD + RATELIMIT # Some options are totally broken on some architectures. We disable # them. If you need to enable them on an experimental basis, you From e6f0c1bba2ecb4b0aba897bca22232d1a04139ed Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Thu, 13 Sep 2018 14:53:42 +0000 Subject: [PATCH 31/54] Add WITHOUT_REPRODUCIBLE_BUILD description Approved by: re (gjb) Sponsored by: The FreeBSD Foundation --- tools/build/options/WITHOUT_REPRODUCIBLE_BUILD | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tools/build/options/WITHOUT_REPRODUCIBLE_BUILD diff --git a/tools/build/options/WITHOUT_REPRODUCIBLE_BUILD b/tools/build/options/WITHOUT_REPRODUCIBLE_BUILD new file mode 100644 index 000000000000..015a6432ccd5 --- /dev/null +++ b/tools/build/options/WITHOUT_REPRODUCIBLE_BUILD @@ -0,0 +1,4 @@ +.\" $FreeBSD$ +Set to include build metadata (such as the build time, user, and host) +in the kernel, boot loaders, and uname output. +Successive builds will not be bit-for-bit identical. From 13ea074dc3d60682bd7e56a9499e045546ef28da Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Thu, 13 Sep 2018 14:53:51 +0000 Subject: [PATCH 32/54] amd64: implement ERMS-based memmove, memcpy and memset Reviewed by: kib Approved by: re (gjb) Differential Revision: https://reviews.freebsd.org/D17124 --- sys/amd64/amd64/machdep.c | 32 ++++++++++++++++++++ sys/amd64/amd64/support.S | 64 +++++++++++++++++++++++++++++++++++---- 2 files changed, 90 insertions(+), 6 deletions(-) diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index e1f148be16fa..092dc095bf65 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -131,6 +131,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef SMP #include #endif @@ -2661,3 +2662,34 @@ outb_(u_short port, u_char data) } #endif /* KDB */ + +#undef memset +#undef memmove +#undef memcpy + +void *memset_std(void *buf, int c, size_t len); +void *memset_erms(void *buf, int c, size_t len); +DEFINE_IFUNC(, void *, memset, (void *, int, size_t), static) +{ + + return ((cpu_stdext_feature & CPUID_STDEXT_ERMS) != 0 ? + memset_erms : memset_std); +} + +void *memmove_std(void * _Nonnull dst, const void * _Nonnull src, size_t len); +void *memmove_erms(void * _Nonnull dst, const void * _Nonnull src, size_t len); +DEFINE_IFUNC(, void *, memmove, (void * _Nonnull, const void * _Nonnull, size_t), static) +{ + + return ((cpu_stdext_feature & CPUID_STDEXT_ERMS) != 0 ? + memmove_erms : memmove_std); +} + +void *memcpy_std(void * _Nonnull dst, const void * _Nonnull src, size_t len); +void *memcpy_erms(void * _Nonnull dst, const void * _Nonnull src, size_t len); +DEFINE_IFUNC(, void *, memcpy, (void * _Nonnull, const void * _Nonnull, size_t), static) +{ + + return ((cpu_stdext_feature & CPUID_STDEXT_ERMS) != 0 ? + memcpy_erms : memcpy_std); +} diff --git a/sys/amd64/amd64/support.S b/sys/amd64/amd64/support.S index 714f100a9749..db89a6fadd3c 100644 --- a/sys/amd64/amd64/support.S +++ b/sys/amd64/amd64/support.S @@ -96,7 +96,7 @@ END(sse2_pagezero) * Adapted from bcopy written by: * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800 */ -ENTRY(memmove) +ENTRY(memmove_std) PUSH_FRAME_POINTER movq %rdi,%r9 movq %rdx,%rcx @@ -142,7 +142,37 @@ ENTRY(memmove) movq %r9,%rax POP_FRAME_POINTER ret -END(memmove) +END(memmove_std) + +ENTRY(memmove_erms) + PUSH_FRAME_POINTER + movq %rdi,%r9 + movq %rdx,%rcx + + movq %rdi,%rax + subq %rsi,%rax + cmpq %rcx,%rax /* overlapping && src < dst? */ + jb 1f + + rep + movsb + movq %r9,%rax + POP_FRAME_POINTER + ret + +1: + addq %rcx,%rdi /* copy backwards */ + addq %rcx,%rsi + decq %rdi + decq %rsi + std + rep + movsb + cld + movq %r9,%rax + POP_FRAME_POINTER + ret +END(memmove_erms) /* * memcpy(dst, src, len) @@ -150,7 +180,7 @@ END(memmove) * * Note: memcpy does not support overlapping copies */ -ENTRY(memcpy) +ENTRY(memcpy_std) PUSH_FRAME_POINTER movq %rdi,%rax movq %rdx,%rcx @@ -167,13 +197,23 @@ ENTRY(memcpy) movsb POP_FRAME_POINTER ret -END(memcpy) +END(memcpy_std) + +ENTRY(memcpy_erms) + PUSH_FRAME_POINTER + movq %rdi,%rax + movq %rdx,%rcx + rep + movsb + POP_FRAME_POINTER + ret +END(memcpy_erms) /* * memset(dst, c, len) * rdi, rsi, rdx */ -ENTRY(memset) +ENTRY(memset_std) PUSH_FRAME_POINTER movq %rdi,%r9 movq %rdx,%rcx @@ -195,7 +235,19 @@ ENTRY(memset) movq %r9,%rax POP_FRAME_POINTER ret -END(memset) +END(memset_std) + +ENTRY(memset_erms) + PUSH_FRAME_POINTER + movq %rdi,%r9 + movq %rdx,%rcx + movb %sil,%al + rep + stosb + movq %r9,%rax + POP_FRAME_POINTER + ret +END(memset_erms) /* fillw(pat, base, cnt) */ /* %rdi,%rsi, %rdx */ From ac5d5b054f0b1b92ae322a4be8122bd9edca84fa Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Thu, 13 Sep 2018 14:54:46 +0000 Subject: [PATCH 33/54] dd(1): Correct padding in status=progress Output padding is specified via outlen, which is set using the return value of fprintf. Because it's printing that padding plus a trailing byte, it grows by one each iteration rather than reflecting actual length. Additionally, iec was sized improperly for scaling up similarly to si. Fixing this revealed that the humanize_number(3) call to populate persec was using the wrong width. Submitted by: Thomas Hurst Reviewed by: imp Approved by: re (kib) Differential Revision: https://reviews.freebsd.org/D16960 --- bin/dd/misc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/dd/misc.c b/bin/dd/misc.c index dfe83fd1ef9a..405448eb1cb0 100644 --- a/bin/dd/misc.c +++ b/bin/dd/misc.c @@ -111,7 +111,7 @@ progress(void) { static int outlen; char si[4 + 1 + 2 + 1]; /* 123 NUL */ - char iec[4 + 1 + 2 + 1]; /* 123 NUL */ + char iec[4 + 1 + 3 + 1]; /* 123 NUL */ char persec[4 + 1 + 2 + 1]; /* 123 NUL */ char *buf; double secs; @@ -121,11 +121,11 @@ progress(void) HN_DECIMAL | HN_DIVISOR_1000); humanize_number(iec, sizeof(iec), (int64_t)st.bytes, "B", HN_AUTOSCALE, HN_DECIMAL | HN_IEC_PREFIXES); - humanize_number(persec, sizeof(iec), (int64_t)(st.bytes / secs), "B", + humanize_number(persec, sizeof(persec), (int64_t)(st.bytes / secs), "B", HN_AUTOSCALE, HN_DECIMAL | HN_DIVISOR_1000); asprintf(&buf, " %'ju bytes (%s, %s) transferred %.3fs, %s/s", (uintmax_t)st.bytes, si, iec, secs, persec); - outlen = fprintf(stderr, "%-*s\r", outlen, buf); + outlen = fprintf(stderr, "%-*s\r", outlen, buf) - 1; fflush(stderr); free(buf); need_progress = 0; From a06833f9518049c69457f18c2cc5b8f2c87a347e Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Thu, 13 Sep 2018 14:54:52 +0000 Subject: [PATCH 34/54] regenerate src.conf.5 after r338642 and r338643 Approved by: re (gjb) Sponsored by: The FreeBSD Foundation --- share/man/man5/src.conf.5 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/share/man/man5/src.conf.5 b/share/man/man5/src.conf.5 index 628a0e7d38e8..8a0104171975 100644 --- a/share/man/man5/src.conf.5 +++ b/share/man/man5/src.conf.5 @@ -1,6 +1,6 @@ .\" DO NOT EDIT-- this file is @generated by tools/build/options/makeman. .\" $FreeBSD$ -.Dd August 28, 2018 +.Dd September 13, 2018 .Dt SRC.CONF 5 .Os .Sh NAME @@ -1534,10 +1534,10 @@ by proxy. .It Va WITHOUT_RBOOTD Set to not build or install .Xr rbootd 8 . -.It Va WITH_REPRODUCIBLE_BUILD -Set to exclude build metadata (such as the build time, user, or host) -from the kernel, boot loaders, and uname output, so that builds produce -bit-for-bit identical output. +.It Va WITHOUT_REPRODUCIBLE_BUILD +Set to include build metadata (such as the build time, user, and host) +in the kernel, boot loaders, and uname output. +Successive builds will not be bit-for-bit identical. .It Va WITHOUT_RESCUE Set to not build .Xr rescue 8 . From 0d77d170afafe86d7f7a261a9785f98c3208f3d9 Mon Sep 17 00:00:00 2001 From: Ian Lepore Date: Thu, 13 Sep 2018 15:16:05 +0000 Subject: [PATCH 35/54] If a user skips the pre-world mergemaster, an installworld check notices the missing ntpd user and refers to UPDATING. This change makes it more clear which aspect of UPDATING is important for the ntpd change. PR: 231334 Approved by: re (gjb) --- UPDATING | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/UPDATING b/UPDATING index bd314d07df12..122b0600e827 100644 --- a/UPDATING +++ b/UPDATING @@ -113,7 +113,9 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 12.x IS SLOW: 20180719: New uid:gid added, ntpd:ntpd (123:123). Be sure to run mergemaster or take steps to update /etc/passwd before doing installworld on - existing systems. Also, rc.d/ntpd now starts ntpd(8) as user ntpd + existing systems. Do not skip the "mergemaster -Fp" step before + installworld, as described in the update procedures near the bottom + of this document. Also, rc.d/ntpd now starts ntpd(8) as user ntpd if the new mac_ntpd(4) policy is available, unless ntpd_flags or the ntp config file contain options that change file/dir locations. When such options (e.g., "statsdir" or "crypto") are used, ntpd can From becaaa9be9db201639cd0b5c55858c426981a42c Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 13 Sep 2018 16:14:33 +0000 Subject: [PATCH 36/54] Really fix pam install. Don't commit late at night or you make simple mistakes. Reported by: dumbbell Approved by: re (gjb), will (mentor) --- lib/libpam/pam.d/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libpam/pam.d/Makefile b/lib/libpam/pam.d/Makefile index 97bb296d3462..62c6ff16830d 100644 --- a/lib/libpam/pam.d/Makefile +++ b/lib/libpam/pam.d/Makefile @@ -29,7 +29,7 @@ FTP+= ftpd FTPPACKAGE+= ftp afterinstallconfig: - ${INSTALL_LINK} ${TAG_ARGS} ${CONFDIR}/ftpd ${CONFDIR}/ftp + ${INSTALL_LINK} ${TAG_ARGS} ${DESTDIR}${CONFDIR}/ftpd ${DESTDIR}${CONFDIR}/ftp .endif .if ${MK_TELNET} != "no" From 6f3a49c3173123066b34b55d7bb303304ca3f872 Mon Sep 17 00:00:00 2001 From: Navdeep Parhar Date: Thu, 13 Sep 2018 16:27:21 +0000 Subject: [PATCH 37/54] cxgbe/iw_cxgbe: Fix reported build breakage when the kernel configuration has "device cxgbe' but no VIMAGE. Reported by: mav@ Approved by: re@ (kib@) --- sys/dev/cxgbe/iw_cxgbe/cm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/dev/cxgbe/iw_cxgbe/cm.c b/sys/dev/cxgbe/iw_cxgbe/cm.c index 9eab1750bb11..f3978a41d768 100644 --- a/sys/dev/cxgbe/iw_cxgbe/cm.c +++ b/sys/dev/cxgbe/iw_cxgbe/cm.c @@ -2524,8 +2524,10 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) struct c4iw_dev *dev = to_c4iw_dev(cm_id->device); struct c4iw_ep *ep = NULL; struct ifnet *nh_ifp; /* Logical egress interface */ +#ifdef VIMAGE struct rdma_cm_id *rdma_id = (struct rdma_cm_id*)cm_id->context; struct vnet *vnet = rdma_id->route.addr.dev_addr.net; +#endif CTR2(KTR_IW_CXGBE, "%s:ccB %p", __func__, cm_id); From fa8050170aa817e57db4854c068231ad47af687f Mon Sep 17 00:00:00 2001 From: Glen Barber Date: Thu, 13 Sep 2018 16:41:15 +0000 Subject: [PATCH 38/54] Remove __DATE__ and __TIME__ from ibdiag_common.c, replacing with the hard-coded string "not available" to ensure reproducible builds. Discussed with: emaste Approved by: re (rgrimes) Sponsored by: The FreeBSD Foundation --- contrib/ofed/infiniband-diags/src/ibdiag_common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contrib/ofed/infiniband-diags/src/ibdiag_common.c b/contrib/ofed/infiniband-diags/src/ibdiag_common.c index d668b7ef0557..ddaee8c5b559 100644 --- a/contrib/ofed/infiniband-diags/src/ibdiag_common.c +++ b/contrib/ofed/infiniband-diags/src/ibdiag_common.c @@ -84,8 +84,7 @@ static const struct ibdiag_opt *opts_map[256]; static const char *get_build_version(void) { - return "BUILD VERSION: " IBDIAG_VERSION " Build date: " __DATE__ " " - __TIME__; + return "BUILD VERSION: " IBDIAG_VERSION; } static void pretty_print(int start, int width, const char *str) From 6fb3c89473e6bfa056db3ce45d83df289f4e5489 Mon Sep 17 00:00:00 2001 From: Oleksandr Tymoshenko Date: Thu, 13 Sep 2018 17:36:55 +0000 Subject: [PATCH 39/54] [ig4] Add PCI IDs for I2C controller on Intel Kaby Lake systems PR: 221777 Approved by: re (kib) Submitted by: marc.priggemeyer@gmail.com --- sys/dev/ichiic/ig4_pci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/dev/ichiic/ig4_pci.c b/sys/dev/ichiic/ig4_pci.c index 7bb8590aa1ef..eed7d651bfde 100644 --- a/sys/dev/ichiic/ig4_pci.c +++ b/sys/dev/ichiic/ig4_pci.c @@ -80,6 +80,8 @@ static int ig4iic_pci_detach(device_t dev); #define PCI_CHIP_SKYLAKE_I2C_3 0x9d638086 #define PCI_CHIP_SKYLAKE_I2C_4 0x9d648086 #define PCI_CHIP_SKYLAKE_I2C_5 0x9d658086 +#define PCI_CHIP_KABYLAKE_I2C_0 0xa1608086 +#define PCI_CHIP_KABYLAKE_I2C_1 0xa1618086 #define PCI_CHIP_APL_I2C_0 0x5aac8086 #define PCI_CHIP_APL_I2C_1 0x5aae8086 #define PCI_CHIP_APL_I2C_2 0x5ab08086 @@ -110,6 +112,8 @@ static struct ig4iic_pci_device ig4iic_pci_devices[] = { { PCI_CHIP_SKYLAKE_I2C_3, "Intel Sunrise Point-LP I2C Controller-3", IG4_SKYLAKE}, { PCI_CHIP_SKYLAKE_I2C_4, "Intel Sunrise Point-LP I2C Controller-4", IG4_SKYLAKE}, { PCI_CHIP_SKYLAKE_I2C_5, "Intel Sunrise Point-LP I2C Controller-5", IG4_SKYLAKE}, + { PCI_CHIP_KABYLAKE_I2C_0, "Intel Sunrise Point-LP I2C Controller-0", IG4_SKYLAKE}, + { PCI_CHIP_KABYLAKE_I2C_1, "Intel Sunrise Point-LP I2C Controller-1", IG4_SKYLAKE}, { PCI_CHIP_APL_I2C_0, "Intel Apollo Lake I2C Controller-0", IG4_APL}, { PCI_CHIP_APL_I2C_1, "Intel Apollo Lake I2C Controller-1", IG4_APL}, { PCI_CHIP_APL_I2C_2, "Intel Apollo Lake I2C Controller-2", IG4_APL}, From 23679408cec0d18046592c5503763352a562f89e Mon Sep 17 00:00:00 2001 From: Oleksandr Tymoshenko Date: Thu, 13 Sep 2018 17:39:08 +0000 Subject: [PATCH 40/54] [ig4] Update list of supported hardware Reflect the fact that ig4(4) is not an Intel-specific device but a driver for Synopsys DesignWare I2C controller that now ships in AMD systems too. Approved by: re (kib), rpokala --- share/man/man4/ig4.4 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/share/man/man4/ig4.4 b/share/man/man4/ig4.4 index 9237b96635d7..3ca88dee8016 100644 --- a/share/man/man4/ig4.4 +++ b/share/man/man4/ig4.4 @@ -24,12 +24,12 @@ .\" .\" $FreeBSD$ .\" -.Dd October 03, 2016 +.Dd September 13, 2018 .Dt IG4 4 .Os .Sh NAME .Nm ig4 -.Nd Intel(R) fourth generation mobile CPU integrated I2C driver +.Nd Synopsys DesignWare I2C Controller .Sh SYNOPSIS To compile this driver into the kernel, place the following lines into the kernel configuration file: @@ -49,9 +49,9 @@ The driver provides access to peripherals attached to an I2C controller. .Sh HARDWARE .Nm -supports the I2C controllers found in fourth generation Intel(R) Core(TM) -processors based on the mobile U-processor line for intelligent systems. -This includes the i7-4650U, i5-4300U, i3-4010U, and 2980U. +supports the I2C controllers based on Synopsys DesignWare IP that can be found +in Intel(R) Core(TM) processors starting from the fourth generation, Intel(R) +Bay Trail, Apollo Lake SoC families, and some AMD systems. .Sh SYSCTL VARIABLES These .Xr sysctl 8 From 73511c241bab29b078c84d992082cc44513c608d Mon Sep 17 00:00:00 2001 From: Eric van Gyzen Date: Thu, 13 Sep 2018 17:56:48 +0000 Subject: [PATCH 41/54] Set zfs_arc_meta_strategy to metadata only The previous default of "balanced" appears to have caused pathological behavior, including very poor performance and 100% CPU load in the arc_reclaim_thread. The symptoms appeared when the daily periodic run started. With this change, the system--and the ARC in particular--behaved normally during a manual daily periodic run. From Mark Johnston: The port of the balanced strategy is incomplete, since arc_prune_async() is a no-op on FreeBSD. (This also seems to imply that r337653 is a no-op.) After 12 is branched we can port the remaining bits and consider changing the default back. Submitted by: markj (essentially) Reviewed by: markj Approved by: re (gjb) Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D17156 --- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c index 2bc065e12509..37aa9bb3dc96 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c @@ -538,9 +538,14 @@ typedef struct arc_state { */ int zfs_arc_meta_prune = 10000; unsigned long zfs_arc_dnode_limit_percent = 10; -int zfs_arc_meta_strategy = ARC_STRATEGY_META_BALANCED; +int zfs_arc_meta_strategy = ARC_STRATEGY_META_ONLY; int zfs_arc_meta_adjust_restarts = 4096; +SYSCTL_INT(_vfs_zfs, OID_AUTO, arc_meta_strategy, CTLFLAG_RWTUN, + &zfs_arc_meta_strategy, 0, + "ARC metadata reclamation strategy " + "(0 = metadata only, 1 = balance data and metadata)"); + /* The 6 states: */ static arc_state_t ARC_anon; static arc_state_t ARC_mru; From f2990e6c19d33bf5284d45211d5f8184d021afdb Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Thu, 13 Sep 2018 21:00:17 +0000 Subject: [PATCH 42/54] Enable Capsicum on armv6/armv7 We ought to be consistent across our Tier-1 and nearly-Tier-1 architectures, so enable Capsicum for 32-bit armv6/armv7 by default. PR: 204008 Reviewed by: ian, oshogbo Approved by: re (gjb) Relnotes: Yes Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D17023 --- sys/arm/conf/std.armv6 | 2 ++ sys/arm/conf/std.armv7 | 2 ++ 2 files changed, 4 insertions(+) diff --git a/sys/arm/conf/std.armv6 b/sys/arm/conf/std.armv6 index 2f6f9c93af4f..52685a9b13bf 100644 --- a/sys/arm/conf/std.armv6 +++ b/sys/arm/conf/std.armv6 @@ -41,6 +41,8 @@ options _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions options PRINTF_BUFR_SIZE=128 # Prevent printf output being interspersed. options KBD_INSTALL_CDEV # install a CDEV entry in /dev options HWPMC_HOOKS # Necessary kernel hooks for hwpmc(4) +options CAPABILITY_MODE # Capsicum capability mode +options CAPABILITIES # Capsicum capabilites options FREEBSD_BOOT_LOADER # Process metadata passed from loader(8) options VFP # Enable floating point hardware support options MAC # Support for Mandatory Access Control (MAC) diff --git a/sys/arm/conf/std.armv7 b/sys/arm/conf/std.armv7 index 5754f4780fea..c3ab6852e615 100644 --- a/sys/arm/conf/std.armv7 +++ b/sys/arm/conf/std.armv7 @@ -41,6 +41,8 @@ options _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions options PRINTF_BUFR_SIZE=128 # Prevent printf output being interspersed. options KBD_INSTALL_CDEV # install a CDEV entry in /dev options HWPMC_HOOKS # Necessary kernel hooks for hwpmc(4) +options CAPABILITY_MODE # Capsicum capability mode +options CAPABILITIES # Capsicum capabilites options FREEBSD_BOOT_LOADER # Process metadata passed from loader(8) options VFP # Enable floating point hardware support options MAC # Support for Mandatory Access Control (MAC) From 4bb64e96e4d50b852d9947d3bd90c81b05e5b654 Mon Sep 17 00:00:00 2001 From: Navdeep Parhar Date: Thu, 13 Sep 2018 22:58:13 +0000 Subject: [PATCH 43/54] cxgbe(4): Use the correct number of parameters when querying the tid range for hashfilters. Approved by: re@ (gjb@) --- sys/dev/cxgbe/t4_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/dev/cxgbe/t4_main.c b/sys/dev/cxgbe/t4_main.c index d6bf50121a15..60bdff978b69 100644 --- a/sys/dev/cxgbe/t4_main.c +++ b/sys/dev/cxgbe/t4_main.c @@ -3954,7 +3954,7 @@ get_params__post_init(struct adapter *sc) sc->toecaps = 0; param[0] = FW_PARAM_DEV(NTID); - rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val); + rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val); if (rc != 0) { device_printf(sc->dev, "failed to query HASHFILTER parameters: %d.\n", rc); From b79672bb0899e90b57371592762da859f2002cf1 Mon Sep 17 00:00:00 2001 From: Glen Barber Date: Thu, 13 Sep 2018 23:59:59 +0000 Subject: [PATCH 44/54] Update head from ALPHA5 to ALPHA6 as part of the 12.0-RELEASE cycle. Approved by: re (implicit) Sponsored by: The FreeBSD Foundation --- sys/conf/newvers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh index 9e83b6379f51..ce32cf2950af 100644 --- a/sys/conf/newvers.sh +++ b/sys/conf/newvers.sh @@ -46,7 +46,7 @@ TYPE="FreeBSD" REVISION="12.0" -BRANCH="ALPHA5" +BRANCH="ALPHA6" if [ -n "${BRANCH_OVERRIDE}" ]; then BRANCH=${BRANCH_OVERRIDE} fi From 3b9156971f7ec928aa3e03ac8dc5eea87ffe8cb7 Mon Sep 17 00:00:00 2001 From: Matt Macy Date: Fri, 14 Sep 2018 01:11:10 +0000 Subject: [PATCH 45/54] re-enable pmcstat, pmccontrol, and pmcannotate for gcc4 builds I had disabled building of the aforementioned targets due to warnings breaking tinderbox. This silences the warning and restores them to the build. Reported by: jhibbits Reviewed by: jhibbits Approved by: re (gjb) --- lib/Makefile | 5 ++--- lib/libpmc/Makefile | 2 +- usr.sbin/Makefile | 8 ++++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index da30e8403a21..4332aa13a70c 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -70,6 +70,8 @@ SUBDIR= ${SUBDIR_BOOTSTRAP} \ libpathconv \ libpcap \ libpjdlog \ + libpmc \ + libpmcstat \ ${_libproc} \ libprocstat \ libregex \ @@ -198,9 +200,6 @@ _libdl= libdl .endif SUBDIR.${MK_OPENSSL}+= libmp -.if (${COMPILER_TYPE} == "clang" || (${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 60100 && ${MACHINE_CPUARCH} != "riscv")) -SUBDIR.${MK_PMC}+= libpmc libpmcstat -.endif SUBDIR.${MK_RADIUS_SUPPORT}+= libradius SUBDIR.${MK_SENDMAIL}+= libmilter libsm libsmdb libsmutil SUBDIR.${MK_TELNET}+= libtelnet diff --git a/lib/libpmc/Makefile b/lib/libpmc/Makefile index 48e94a2a078c..f40ba3b28271 100644 --- a/lib/libpmc/Makefile +++ b/lib/libpmc/Makefile @@ -7,7 +7,7 @@ SRCS= libpmc.c pmclog.c libpmc_pmu_util.c libpmc_json.cc INCS= pmc.h pmclog.h pmcformat.h CFLAGS+= -I${.CURDIR} -CWARNFLAGS.gcc+= -Wno-shadow +CWARNFLAGS.gcc+= -Wno-shadow -Wno-cast-align .if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386" diff --git a/usr.sbin/Makefile b/usr.sbin/Makefile index 20a101eaef5b..25e3265b6992 100644 --- a/usr.sbin/Makefile +++ b/usr.sbin/Makefile @@ -59,6 +59,9 @@ SUBDIR= adduser \ nologin \ pciconf \ periodic \ + pmcannotate \ + pmccontrol \ + pmcstat \ pnfsdscopymr \ pnfsdsfile \ pnfsdskill \ @@ -185,11 +188,8 @@ SUBDIR.${MK_OPENSSL}+= keyserv SUBDIR.${MK_PC_SYSINSTALL}+= pc-sysinstall SUBDIR.${MK_PF}+= ftp-proxy SUBDIR.${MK_PKGBOOTSTRAP}+= pkg -.if (${COMPILER_TYPE} == "clang" || (${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 60100 && ${MACHINE_CPUARCH} != "riscv")) +.if ${COMPILER_FEATURES:Mc++11} SUBDIR.${MK_PMC}+= pmc -SUBDIR.${MK_PMC}+= pmcannotate -SUBDIR.${MK_PMC}+= pmccontrol -SUBDIR.${MK_PMC}+= pmcstat .endif SUBDIR.${MK_PMC}+= pmcstudy SUBDIR.${MK_PORTSNAP}+= portsnap From 0204d85a62dd18966eae15cc71e9be117b2433c2 Mon Sep 17 00:00:00 2001 From: Matt Macy Date: Fri, 14 Sep 2018 01:30:05 +0000 Subject: [PATCH 46/54] hwpmc: set default rate if event description lacks one / filter rate against misuse Not all event descriptions have a sample rate (such as inst_retired.any) this will restore the legacy behavior of using 65536 in that case. It also prevents accidental API misuse that could lead to panic. PR: 230985 Reported by: markj Reviewed by: markj Approved by: re (gjb) Sponsored by: Limelight Networks Differential Revision: https://reviews.freebsd.org/D16958 --- lib/libpmc/libpmc_pmu_util.c | 1 + sys/dev/hwpmc/hwpmc_mod.c | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/libpmc/libpmc_pmu_util.c b/lib/libpmc/libpmc_pmu_util.c index 7aaf6f2a5b18..583a2d36bc74 100644 --- a/lib/libpmc/libpmc_pmu_util.c +++ b/lib/libpmc/libpmc_pmu_util.c @@ -237,6 +237,7 @@ pmu_parse_event(struct pmu_event_desc *ped, const char *eventin) return (ENOMEM); r = event; bzero(ped, sizeof(*ped)); + ped->ped_period = DEFAULT_SAMPLE_COUNT; ped->ped_umask = -1; while ((kvp = strsep(&event, ",")) != NULL) { key = strsep(&kvp, "="); diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c index 4d7a4535d27b..20df37d24bd6 100644 --- a/sys/dev/hwpmc/hwpmc_mod.c +++ b/sys/dev/hwpmc/hwpmc_mod.c @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -3942,9 +3943,16 @@ pmc_syscall_handler(struct thread *td, void *syscall_args) pmc->pm_flags = pa.pm_flags; /* XXX set lower bound on sampling for process counters */ - if (PMC_IS_SAMPLING_MODE(mode)) - pmc->pm_sc.pm_reloadcount = pa.pm_count; - else + if (PMC_IS_SAMPLING_MODE(mode)) { + /* + * Don't permit requested sample rate to be less than 1000 + */ + if (pa.pm_count < 1000) + log(LOG_WARNING, + "pmcallocate: passed sample rate %ju - setting to 1000\n", + (uintmax_t)pa.pm_count); + pmc->pm_sc.pm_reloadcount = MAX(1000, pa.pm_count); + } else pmc->pm_sc.pm_initial = pa.pm_count; /* switch thread to CPU 'cpu' */ @@ -4460,9 +4468,16 @@ pmc_syscall_handler(struct thread *td, void *syscall_args) break; } - if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) - pm->pm_sc.pm_reloadcount = sc.pm_count; - else + if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) { + /* + * Don't permit requested sample rate to be less than 1000 + */ + if (sc.pm_count < 1000) + log(LOG_WARNING, + "pmcsetcount: passed sample rate %ju - setting to 1000\n", + (uintmax_t)sc.pm_count); + pm->pm_sc.pm_reloadcount = MAX(1000, sc.pm_count); + } else pm->pm_sc.pm_initial = sc.pm_count; } break; From 5b21ba5c5d5c1a0595d5db53ac5b2ae8d7363405 Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Fri, 14 Sep 2018 13:41:37 +0000 Subject: [PATCH 47/54] Improve LibUSB debugging by simultaneously allowing both function and transfer prints. Make sure the debug level comes from the correct USB context. Found by: Ludovic Rousseau PR: 231264 MFC after: 1 week Approved by: re (kib) Sponsored by: Mellanox Technologies --- lib/libusb/libusb10.h | 34 ++++++++++++++++++---------------- lib/libusb/libusb10_io.c | 21 ++++++++++++++++++--- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/lib/libusb/libusb10.h b/lib/libusb/libusb10.h index 7c34f895b0aa..c3deb562c6d4 100644 --- a/lib/libusb/libusb10.h +++ b/lib/libusb/libusb10.h @@ -41,22 +41,24 @@ #define HOTPLUG_LOCK(ctx) pthread_mutex_lock(&(ctx)->hotplug_lock) #define HOTPLUG_UNLOCK(ctx) pthread_mutex_unlock(&(ctx)->hotplug_lock) -#define DPRINTF(ctx, dbg, format, args...) do { \ - if ((ctx)->debug == dbg) { \ - switch (dbg) { \ - case LIBUSB_DEBUG_FUNCTION: \ - printf("LIBUSB_FUNCTION: " \ - format "\n", ## args); \ - break; \ - case LIBUSB_DEBUG_TRANSFER: \ - printf("LIBUSB_TRANSFER: " \ - format "\n", ## args); \ - break; \ - default: \ - break; \ - } \ - } \ -} while(0) +#define DPRINTF(ctx, dbg, format, ...) do { \ + switch (dbg) { \ + case LIBUSB_DEBUG_FUNCTION: \ + if ((ctx)->debug & LIBUSB_DEBUG_FUNCTION) { \ + printf("LIBUSB_FUNCTION: " \ + format "\n", ## __VA_ARGS__); \ + } \ + break; \ + case LIBUSB_DEBUG_TRANSFER: \ + if ((ctx)->debug & LIBUSB_DEBUG_TRANSFER) { \ + printf("LIBUSB_TRANSFER: " \ + format "\n", ## __VA_ARGS__); \ + } \ + break; \ + default: \ + break; \ + } \ +} while (0) /* internal structures */ diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c index 42fbd0e2e30b..13c9e786c00e 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -489,13 +489,26 @@ libusb_control_transfer(libusb_device_handle *devh, return (actlen); } +static libusb_context * +libusb10_get_context_by_device_handle(libusb_device_handle *devh) +{ + libusb_context *ctx; + + if (devh != NULL) + ctx = libusb_get_device(devh)->ctx; + else + ctx = NULL; + + return (GET_CONTEXT(ctx)); +} + static void libusb10_do_transfer_cb(struct libusb_transfer *transfer) { libusb_context *ctx; int *pdone; - ctx = GET_CONTEXT(NULL); + ctx = libusb10_get_context_by_device_handle(transfer->dev_handle); DPRINTF(ctx, LIBUSB_DEBUG_TRANSFER, "sync I/O done"); @@ -585,7 +598,8 @@ libusb_bulk_transfer(libusb_device_handle *devh, libusb_context *ctx; int ret; - ctx = GET_CONTEXT(NULL); + ctx = libusb10_get_context_by_device_handle(devh); + DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_bulk_transfer enter"); ret = libusb10_do_transfer(devh, endpoint, data, length, transferred, @@ -603,7 +617,8 @@ libusb_interrupt_transfer(libusb_device_handle *devh, libusb_context *ctx; int ret; - ctx = GET_CONTEXT(NULL); + ctx = libusb10_get_context_by_device_handle(devh); + DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_interrupt_transfer enter"); ret = libusb10_do_transfer(devh, endpoint, data, length, transferred, From 1ae9615a9a4f8d6c0626822f8526c4434e341770 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Fri, 14 Sep 2018 15:15:16 +0000 Subject: [PATCH 48/54] lld: add -z interpose support -z interpose sets the DF_1_INTERPOSE flag, marking the object as an interposer. Committed upstream as LLVM r342239. PR: 230604 Reported by: jbeich Reviewed by: markj Approved by: re (kib) MFC after: 1 week Relnotes: Yes Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D17172 --- contrib/llvm/tools/lld/ELF/Config.h | 1 + contrib/llvm/tools/lld/ELF/Driver.cpp | 1 + contrib/llvm/tools/lld/ELF/SyntheticSections.cpp | 2 ++ usr.bin/clang/lld/ld.lld.1 | 8 +++++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/contrib/llvm/tools/lld/ELF/Config.h b/contrib/llvm/tools/lld/ELF/Config.h index a9f3e7d3d2de..df688a76017e 100644 --- a/contrib/llvm/tools/lld/ELF/Config.h +++ b/contrib/llvm/tools/lld/ELF/Config.h @@ -156,6 +156,7 @@ struct Configuration { bool ZExecstack; bool ZHazardplt; bool ZIfuncnoplt; + bool ZInterpose; bool ZNocopyreloc; bool ZNodelete; bool ZNodlopen; diff --git a/contrib/llvm/tools/lld/ELF/Driver.cpp b/contrib/llvm/tools/lld/ELF/Driver.cpp index e6f4eea18b13..93cf7180314f 100644 --- a/contrib/llvm/tools/lld/ELF/Driver.cpp +++ b/contrib/llvm/tools/lld/ELF/Driver.cpp @@ -670,6 +670,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) { Config->ZExecstack = hasZOption(Args, "execstack"); Config->ZHazardplt = hasZOption(Args, "hazardplt"); Config->ZIfuncnoplt = hasZOption(Args, "ifunc-noplt"); + Config->ZInterpose = hasZOption(Args, "interpose"); Config->ZNocopyreloc = hasZOption(Args, "nocopyreloc"); Config->ZNodelete = hasZOption(Args, "nodelete"); Config->ZNodlopen = hasZOption(Args, "nodlopen"); diff --git a/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp b/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp index a5a851f95400..bc787bc59070 100644 --- a/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp +++ b/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp @@ -1034,6 +1034,8 @@ template void DynamicSection::finalizeContents() { uint32_t DtFlags1 = 0; if (Config->Bsymbolic) DtFlags |= DF_SYMBOLIC; + if (Config->ZInterpose) + DtFlags1 |= DF_1_INTERPOSE; if (Config->ZNodelete) DtFlags1 |= DF_1_NODELETE; if (Config->ZNodlopen) diff --git a/usr.bin/clang/lld/ld.lld.1 b/usr.bin/clang/lld/ld.lld.1 index 1149866f5a01..948411fb05c3 100644 --- a/usr.bin/clang/lld/ld.lld.1 +++ b/usr.bin/clang/lld/ld.lld.1 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 22, 2018 +.Dd September 14, 2018 .Dt LD.LLD 1 .Os .Sh NAME @@ -450,6 +450,12 @@ be applied by a run-time loader. Note that this feature requires special loader support and will generally result in application crashes when used outside of freestanding environments. +.It Cm interpose +Set the +.Dv DF_1_INTERPOSE +flag to indicate that the object is an interposer. +Runtime linkers perform symbol resolution by first searching the application, +followed by interposers, and then any other dependencies. .It Cm muldefs Do not error if a symbol is defined multiple times. The first definition will be used. From c51b7ab9e3fb35cfa179ebf532421e94bad97c41 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Fri, 14 Sep 2018 15:29:35 +0000 Subject: [PATCH 49/54] amd64: implement pagezero_erms Intel docs claim such a memset (rep stosb + 4096 bytes) is special-cased by microarchs. They also switched Linux to use it for this purpose. Approved by: re (gjb) --- sys/amd64/amd64/machdep.c | 9 +++++++++ sys/amd64/amd64/support.S | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 092dc095bf65..d9b6e0a04d5a 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -2693,3 +2693,12 @@ DEFINE_IFUNC(, void *, memcpy, (void * _Nonnull, const void * _Nonnull, size_t), return ((cpu_stdext_feature & CPUID_STDEXT_ERMS) != 0 ? memcpy_erms : memcpy_std); } + +void pagezero_std(void *addr); +void pagezero_erms(void *addr); +DEFINE_IFUNC(, void , pagezero, (void *), static) +{ + + return ((cpu_stdext_feature & CPUID_STDEXT_ERMS) != 0 ? + pagezero_erms : pagezero_std); +} diff --git a/sys/amd64/amd64/support.S b/sys/amd64/amd64/support.S index db89a6fadd3c..e683b24162ec 100644 --- a/sys/amd64/amd64/support.S +++ b/sys/amd64/amd64/support.S @@ -41,7 +41,7 @@ .text /* Address: %rdi */ -ENTRY(pagezero) +ENTRY(pagezero_std) PUSH_FRAME_POINTER movq $PAGE_SIZE/8,%rcx xorl %eax,%eax @@ -49,7 +49,17 @@ ENTRY(pagezero) stosq POP_FRAME_POINTER ret -END(pagezero) +END(pagezero_std) + +ENTRY(pagezero_erms) + PUSH_FRAME_POINTER + movq $PAGE_SIZE,%rcx + xorl %eax,%eax + rep + stosb + POP_FRAME_POINTER + ret +END(pagezero_erms) /* * pagecopy(%rdi=from, %rsi=to) From 6a02738229be1d312f4e4af22d64e662a2084eee Mon Sep 17 00:00:00 2001 From: Edward Tomasz Napierala Date: Fri, 14 Sep 2018 15:29:45 +0000 Subject: [PATCH 50/54] Add the "-t" option to geom(8) utility, to display geoms hierarchy. Sample output: % geom -t Geom Class Provider da0 DISK da0 da0 PART da0s1 da0s1 PART da0s1a ffs.da0s1a VFS da0s1a DEV da0s1 DEV da0 DEV da1 DISK da1 swap SWAP da1 DEV cd0 DISK cd0 cd0 DEV Reviewed by: oshogbo Approved by: re (kib) MFC after: 2 weeks Relnotes: yes Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D17151 --- sbin/geom/core/geom.8 | 6 +- sbin/geom/core/geom.c | 140 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 142 insertions(+), 4 deletions(-) diff --git a/sbin/geom/core/geom.8 b/sbin/geom/core/geom.8 index 8cd88cb7792f..298fc2b1d4fd 100644 --- a/sbin/geom/core/geom.8 +++ b/sbin/geom/core/geom.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 13, 2018 +.Dd September 14, 2018 .Dt GEOM 8 .Os .Sh NAME @@ -55,6 +55,8 @@ .Nm .Fl p .Ar provider-name +.Nm +.Fl t .Sh DESCRIPTION The .Nm @@ -111,6 +113,8 @@ Additional options include: .It Fl p Ar provider-name Print detailed information about the geom which provides .Ar provider-name . +.It Fl t +Display geoms hierarchy as a tree. .El .Pp Class-specific commands are implemented as shared libraries which diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c index 9f1655c61a51..e6d6d789908f 100644 --- a/sbin/geom/core/geom.c +++ b/sbin/geom/core/geom.c @@ -66,8 +66,11 @@ static uint32_t *version = NULL; static int verbose = 0; static struct g_command *class_commands = NULL; -#define GEOM_CLASS_CMDS 0x01 -#define GEOM_STD_CMDS 0x02 +#define GEOM_CLASS_CMDS 0x01 +#define GEOM_STD_CMDS 0x02 + +#define GEOM_CLASS_WIDTH 10 + static struct g_command *find_command(const char *cmdstr, int flags); static void list_one_geom_by_provider(const char *provider_name); static int std_available(const char *name); @@ -149,6 +152,7 @@ usage(void) if (class_name == NULL) { fprintf(stderr, "usage: geom [options]\n"); fprintf(stderr, " geom -p \n"); + fprintf(stderr, " geom -t\n"); exit(EXIT_FAILURE); } else { struct g_command *cmd; @@ -672,22 +676,142 @@ find_geom_by_provider(struct gmesh *mesh, const char *name) return (NULL); } +static int +compute_tree_width_geom(struct gmesh *mesh, struct ggeom *gp, int indent) +{ + struct gclass *classp2; + struct ggeom *gp2; + struct gconsumer *cp2; + struct gprovider *pp; + int max_width, width; + + max_width = width = indent + strlen(gp->lg_name); + + LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { + LIST_FOREACH(classp2, &mesh->lg_class, lg_class) { + LIST_FOREACH(gp2, &classp2->lg_geom, lg_geom) { + LIST_FOREACH(cp2, + &gp2->lg_consumer, lg_consumer) { + if (pp != cp2->lg_provider) + continue; + width = compute_tree_width_geom(mesh, + gp2, indent + 2); + if (width > max_width) + max_width = width; + } + } + } + } + + return (max_width); +} + +static int +compute_tree_width(struct gmesh *mesh) +{ + struct gclass *classp; + struct ggeom *gp; + int max_width, width; + + max_width = width = 0; + + LIST_FOREACH(classp, &mesh->lg_class, lg_class) { + LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { + if (!LIST_EMPTY(&gp->lg_consumer)) + continue; + width = compute_tree_width_geom(mesh, gp, 0); + if (width > max_width) + max_width = width; + } + } + + return (max_width); +} + +static void +show_tree_geom(struct gmesh *mesh, struct ggeom *gp, int indent, int width) +{ + struct gclass *classp2; + struct ggeom *gp2; + struct gconsumer *cp2; + struct gprovider *pp; + + if (LIST_EMPTY(&gp->lg_provider)) { + printf("%*s%-*.*s %-*.*s\n", indent, "", + width - indent, width - indent, gp->lg_name, + GEOM_CLASS_WIDTH, GEOM_CLASS_WIDTH, gp->lg_class->lg_name); + return; + } + + LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { + printf("%*s%-*.*s %-*.*s %s\n", indent, "", + width - indent, width - indent, gp->lg_name, + GEOM_CLASS_WIDTH, GEOM_CLASS_WIDTH, gp->lg_class->lg_name, + pp->lg_name); + + LIST_FOREACH(classp2, &mesh->lg_class, lg_class) { + LIST_FOREACH(gp2, &classp2->lg_geom, lg_geom) { + LIST_FOREACH(cp2, + &gp2->lg_consumer, lg_consumer) { + if (pp != cp2->lg_provider) + continue; + show_tree_geom(mesh, gp2, + indent + 2, width); + } + } + } + } +} + +static void +show_tree(void) +{ + struct gmesh mesh; + struct gclass *classp; + struct ggeom *gp; + int error, width; + + error = geom_gettree(&mesh); + if (error != 0) + errc(EXIT_FAILURE, error, "Cannot get GEOM tree"); + + width = compute_tree_width(&mesh); + + printf("%-*.*s %-*.*s %s\n", + width, width, "Geom", + GEOM_CLASS_WIDTH, GEOM_CLASS_WIDTH, "Class", + "Provider"); + + LIST_FOREACH(classp, &mesh.lg_class, lg_class) { + LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { + if (!LIST_EMPTY(&gp->lg_consumer)) + continue; + show_tree_geom(&mesh, gp, 0, width); + } + } +} + int main(int argc, char *argv[]) { char *provider_name; + bool tflag; int ch; provider_name = NULL; + tflag = false; if (strcmp(getprogname(), "geom") == 0) { - while ((ch = getopt(argc, argv, "hp:")) != -1) { + while ((ch = getopt(argc, argv, "hp:t")) != -1) { switch (ch) { case 'p': provider_name = strdup(optarg); if (provider_name == NULL) err(1, "strdup"); break; + case 't': + tflag = true; + break; case 'h': default: usage(); @@ -699,11 +823,21 @@ main(int argc, char *argv[]) */ } + if (tflag && provider_name != NULL) { + errx(EXIT_FAILURE, + "At most one of -P and -t may be specified."); + } + if (provider_name != NULL) { list_one_geom_by_provider(provider_name); return (0); } + if (tflag) { + show_tree(); + return (0); + } + get_class(&argc, &argv); run_command(argc, argv); /* NOTREACHED */ From 6bfb487b6e7128476241acb775b35f436e6997c5 Mon Sep 17 00:00:00 2001 From: "Bjoern A. Zeeb" Date: Fri, 14 Sep 2018 15:46:31 +0000 Subject: [PATCH 51/54] Set ident for GENERIC-MMCCAM to not announce itself as GENERIC anymore. Reviewed by: andrew Approved by: re (gjb) --- sys/arm64/conf/GENERIC-MMCCAM | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/arm64/conf/GENERIC-MMCCAM b/sys/arm64/conf/GENERIC-MMCCAM index 0d1e91cd58c8..ab45fcb8168d 100644 --- a/sys/arm64/conf/GENERIC-MMCCAM +++ b/sys/arm64/conf/GENERIC-MMCCAM @@ -9,6 +9,7 @@ #NO_UNIVERSE include GENERIC +ident GENERIC-MMCCAM # Add CAMDEBUG stuff options CAMDEBUG From d5089b3aed7fab659a38ea1d0a6a281f04a66f7c Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Fri, 14 Sep 2018 17:04:36 +0000 Subject: [PATCH 52/54] Log a message after a successful boot-time microcode update. Reviewed by: kib Approved by: re (delphij) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D17135 --- sys/dev/cpuctl/cpuctl.c | 2 +- sys/x86/include/ucode.h | 3 +- sys/x86/x86/ucode.c | 117 ++++++++++++++++++++++------------------ 3 files changed, 67 insertions(+), 55 deletions(-) diff --git a/sys/dev/cpuctl/cpuctl.c b/sys/dev/cpuctl/cpuctl.c index 33ac83eb731a..4f91b4fbbf28 100644 --- a/sys/dev/cpuctl/cpuctl.c +++ b/sys/dev/cpuctl/cpuctl.c @@ -362,7 +362,7 @@ update_intel(int cpu, cpuctl_update_args_t *args, struct thread *td) set_cpu(cpu, td); critical_enter(); - ret = ucode_intel_load(ptr, true); + ret = ucode_intel_load(ptr, true, NULL, NULL); critical_exit(); restore_cpu(oldcpu, is_bound, td); diff --git a/sys/x86/include/ucode.h b/sys/x86/include/ucode.h index d9c860d20ca8..5c8868108930 100644 --- a/sys/x86/include/ucode.h +++ b/sys/x86/include/ucode.h @@ -58,7 +58,8 @@ struct ucode_intel_extsig_table { } entries[0]; }; -int ucode_intel_load(void *data, bool unsafe); +int ucode_intel_load(void *data, bool unsafe, + uint64_t *nrevp, uint64_t *orevp); size_t ucode_load_bsp(uintptr_t free); void ucode_load_ap(int cpu); void ucode_reload(void); diff --git a/sys/x86/x86/ucode.c b/sys/x86/x86/ucode.c index e1229a8401ec..50a5cbe4462b 100644 --- a/sys/x86/x86/ucode.c +++ b/sys/x86/x86/ucode.c @@ -59,7 +59,7 @@ static int ucode_intel_verify(struct ucode_intel_header *hdr, static struct ucode_ops { const char *vendor; - int (*load)(void *, bool); + int (*load)(void *, bool, uint64_t *, uint64_t *); void *(*match)(uint8_t *, size_t *); } loaders[] = { { @@ -72,35 +72,46 @@ static struct ucode_ops { /* Selected microcode update data. */ static void *early_ucode_data; static void *ucode_data; +static struct ucode_ops *ucode_loader; -static char errbuf[128]; - -static void __printflike(1, 2) -log_err(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vsnprintf(errbuf, sizeof(errbuf), fmt, ap); - va_end(ap); -} +/* Variables used for reporting success or failure. */ +enum { + NO_ERROR, + NO_MATCH, + VERIFICATION_FAILED, +} ucode_error = NO_ERROR; +static uint64_t ucode_nrev, ucode_orev; static void -print_err(void *arg __unused) +log_msg(void *arg __unused) { - if (errbuf[0] != '\0') - printf("microcode load error: %s\n", errbuf); + if (ucode_nrev != 0) { + printf("CPU microcode: updated from %#jx to %#jx\n", + (uintmax_t)ucode_orev, (uintmax_t)ucode_nrev); + return; + } + + switch (ucode_error) { + case NO_MATCH: + printf("CPU microcode: no matching update found\n"); + break; + case VERIFICATION_FAILED: + printf("CPU microcode: microcode verification failed\n"); + break; + default: + break; + } } -SYSINIT(ucode_print_err, SI_SUB_CPU, SI_ORDER_FIRST, print_err, NULL); +SYSINIT(ucode_log, SI_SUB_CPU, SI_ORDER_FIRST, log_msg, NULL); int -ucode_intel_load(void *data, bool unsafe) +ucode_intel_load(void *data, bool unsafe, uint64_t *nrevp, uint64_t *orevp) { - uint64_t rev0, rev1; + uint64_t nrev, orev; uint32_t cpuid[4]; - rev0 = rdmsr(MSR_BIOS_SIGN); + orev = rdmsr(MSR_BIOS_SIGN) >> 32; /* * Perform update. Flush caches first to work around seemingly @@ -118,8 +129,15 @@ ucode_intel_load(void *data, bool unsafe) */ do_cpuid(0, cpuid); - rev1 = rdmsr(MSR_BIOS_SIGN); - if (rev1 <= rev0) + /* + * Verify that the microcode revision changed. + */ + nrev = rdmsr(MSR_BIOS_SIGN) >> 32; + if (nrevp != NULL) + *nrevp = nrev; + if (orevp != NULL) + *orevp = orev; + if (nrev <= orev) return (EEXIST); return (0); } @@ -130,36 +148,26 @@ ucode_intel_verify(struct ucode_intel_header *hdr, size_t resid) uint32_t cksum, *data, size; int i; - if (resid < sizeof(struct ucode_intel_header)) { - log_err("truncated update header"); + if (resid < sizeof(struct ucode_intel_header)) return (1); - } size = hdr->total_size; if (size == 0) size = UCODE_INTEL_DEFAULT_DATA_SIZE + sizeof(struct ucode_intel_header); - if (hdr->header_version != 1) { - log_err("unexpected header version %u", hdr->header_version); + if (hdr->header_version != 1) return (1); - } - if (size % 16 != 0) { - log_err("unexpected update size %u", hdr->total_size); + if (size % 16 != 0) return (1); - } - if (resid < size) { - log_err("truncated update"); + if (resid < size) return (1); - } cksum = 0; data = (uint32_t *)hdr; for (i = 0; i < size / sizeof(uint32_t); i++) cksum += data[i]; - if (cksum != 0) { - log_err("checksum failed"); + if (cksum != 0) return (1); - } return (0); } @@ -182,8 +190,10 @@ ucode_intel_match(uint8_t *data, size_t *len) for (resid = *len; resid > 0; data += total_size, resid -= total_size) { hdr = (struct ucode_intel_header *)data; - if (ucode_intel_verify(hdr, resid) != 0) + if (ucode_intel_verify(hdr, resid) != 0) { + ucode_error = VERIFICATION_FAILED; break; + } data_size = hdr->data_size; total_size = hdr->total_size; @@ -264,7 +274,7 @@ ucode_load_ap(int cpu) #endif if (ucode_data != NULL) - (void)ucode_intel_load(ucode_data, false); + (void)ucode_loader->load(ucode_data, false, NULL, NULL); } static void * @@ -308,11 +318,12 @@ ucode_load_bsp(uintptr_t free) uint32_t regs[4]; char vendor[13]; } cpuid; - struct ucode_ops *loader; uint8_t *addr, *fileaddr, *match; char *type; + uint64_t nrev, orev; caddr_t file; - size_t i, len, ucode_len; + size_t i, len; + int error; KASSERT(free % PAGE_SIZE == 0, ("unaligned boundary %p", (void *)free)); @@ -320,17 +331,16 @@ ucode_load_bsp(uintptr_t free) cpuid.regs[0] = cpuid.regs[1]; cpuid.regs[1] = cpuid.regs[3]; cpuid.vendor[12] = '\0'; - for (i = 0, loader = NULL; i < nitems(loaders); i++) + for (i = 0; i < nitems(loaders); i++) if (strcmp(cpuid.vendor, loaders[i].vendor) == 0) { - loader = &loaders[i]; + ucode_loader = &loaders[i]; break; } - if (loader == NULL) + if (ucode_loader == NULL) return (0); file = 0; fileaddr = match = NULL; - ucode_len = 0; for (;;) { file = preload_search_next_name(file); if (file == 0) @@ -341,7 +351,7 @@ ucode_load_bsp(uintptr_t free) fileaddr = preload_fetch_addr(file); len = preload_fetch_size(file); - match = loader->match(fileaddr, &len); + match = ucode_loader->match(fileaddr, &len); if (match != NULL) { addr = map_ucode(free, len); /* We can't use memcpy() before ifunc resolution. */ @@ -349,18 +359,19 @@ ucode_load_bsp(uintptr_t free) addr[i] = ((volatile uint8_t *)match)[i]; match = addr; - if (loader->load(match, false) == 0) { - ucode_data = match; - ucode_len = len; - early_ucode_data = ucode_data; - break; + error = ucode_loader->load(match, false, &nrev, &orev); + if (error == 0) { + ucode_data = early_ucode_data = match; + ucode_nrev = nrev; + ucode_orev = orev; + return (len); } unmap_ucode(free, len); } } - if (fileaddr != NULL && ucode_data == NULL) - log_err("no matching update found"); - return (ucode_len); + if (fileaddr != NULL && ucode_error == NO_ERROR) + ucode_error = NO_MATCH; + return (0); } /* From 6760585add4d5f21bf9059176afdafe477d821bb Mon Sep 17 00:00:00 2001 From: Eric van Gyzen Date: Fri, 14 Sep 2018 18:12:30 +0000 Subject: [PATCH 53/54] Fix "fasthalt" to halt instead of reboot fasthalt has behaved like reboot, instead of like halt, since r228408 (2011, 10.0-RELEASE). Fix it. One wonders if anyone will notice. Approved by: re (kib) MFC after: 3 days Sponsored by: Dell EMC Isilon --- sbin/reboot/reboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c index 28b84ff25bce..4dcade7611c2 100644 --- a/sbin/reboot/reboot.c +++ b/sbin/reboot/reboot.c @@ -73,7 +73,7 @@ main(int argc, char *argv[]) u_int pageins; const char *user, *kernel = NULL; - if (strcmp(getprogname(), "halt") == 0) { + if (strstr(getprogname(), "halt") != NULL) { dohalt = 1; howto = RB_HALT; } else From df57b3139f5e58b9f900deb4ee2e74f961b75328 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Fri, 14 Sep 2018 19:25:23 +0000 Subject: [PATCH 54/54] Pull in r335365 from upstream llvm trunk (by Krzysztof Parzyszek): Initialize LiveRegs once in BranchFolder::mergeCommonTails This should fix '(TRI && "LivePhysRegs is not initialized."' assertions when building the lang/qt5-qml port in certain configurations. Approved by: re (kib) Reported by: Piotr Kubaj PR: 231355 MFC after: 3 days --- contrib/llvm/lib/CodeGen/BranchFolding.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/llvm/lib/CodeGen/BranchFolding.cpp b/contrib/llvm/lib/CodeGen/BranchFolding.cpp index 7f358a679366..5f3cfacfd991 100644 --- a/contrib/llvm/lib/CodeGen/BranchFolding.cpp +++ b/contrib/llvm/lib/CodeGen/BranchFolding.cpp @@ -884,11 +884,12 @@ void BranchFolder::mergeCommonTails(unsigned commonTailIndex) { if (UpdateLiveIns) { LivePhysRegs NewLiveIns(*TRI); computeLiveIns(NewLiveIns, *MBB); + LiveRegs.init(*TRI); // The flag merging may lead to some register uses no longer using the // flag, add IMPLICIT_DEFs in the predecessors as necessary. for (MachineBasicBlock *Pred : MBB->predecessors()) { - LiveRegs.init(*TRI); + LiveRegs.clear(); LiveRegs.addLiveOuts(*Pred); MachineBasicBlock::iterator InsertBefore = Pred->getFirstTerminator(); for (unsigned Reg : NewLiveIns) {