From 9d0d4debab6b33678f17c87094af9c1429612496 Mon Sep 17 00:00:00 2001 From: adrian Date: Tue, 7 Feb 2017 02:21:34 +0000 Subject: [PATCH 01/18] [ath] prepare for station side quiet time support. * Track the current quiet time configuration in the ath_vap struct. * Add an accessor method for calling the quiet time HAL method. --- sys/dev/ath/if_athvar.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sys/dev/ath/if_athvar.h b/sys/dev/ath/if_athvar.h index ce2abc1f2404..2a183ad0ed8a 100644 --- a/sys/dev/ath/if_athvar.h +++ b/sys/dev/ath/if_athvar.h @@ -490,6 +490,7 @@ struct ath_vap { int (*av_set_tim)(struct ieee80211_node *, int); void (*av_recv_pspoll)(struct ieee80211_node *, struct mbuf *); + struct ieee80211_quiet_ie quiet_ie; }; #define ATH_VAP(vap) ((struct ath_vap *)(vap)) @@ -1484,6 +1485,8 @@ void ath_intr(void *); ((*(_ah)->ah_get11nExtBusy)((_ah))) #define ath_hal_setchainmasks(_ah, _txchainmask, _rxchainmask) \ ((*(_ah)->ah_setChainMasks)((_ah), (_txchainmask), (_rxchainmask))) +#define ath_hal_set_quiet(_ah, _p, _d, _o, _f) \ + ((*(_ah)->ah_setQuiet)((_ah), (_p), (_d), (_o), (_f))) #define ath_hal_spectral_supported(_ah) \ (ath_hal_getcapability(_ah, HAL_CAP_SPECTRAL_SCAN, 0, NULL) == HAL_OK) From 937892382ced99b305593bf8d56dcba99c8778b2 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 7 Feb 2017 02:32:49 +0000 Subject: [PATCH 02/18] hcreate(3): fix the ERRORS section and bump .Dd - Add missing comma between functions that trigger ENOMEM error. - Fix the description for ESRCH. The action that triggers this error is FIND, not SEARCH (SEARCH does not exist). MFC after: 1 week Sponsored by: Dell EMC Isilon --- lib/libc/stdlib/hcreate.3 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/libc/stdlib/hcreate.3 b/lib/libc/stdlib/hcreate.3 index 57091570dcb6..260aa91b6c7d 100644 --- a/lib/libc/stdlib/hcreate.3 +++ b/lib/libc/stdlib/hcreate.3 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 26, 2015 +.Dd February 6, 2017 .Dt HCREATE 3 .Os .Sh NAME @@ -265,9 +265,9 @@ main(void) .Ed .Sh ERRORS The -.Fn hcreate +.Fn hcreate , .Fn hcreate_r , -.Fn hsearch +.Fn hsearch , and .Fn hsearch_r functions will fail if: @@ -281,7 +281,7 @@ The and .Fn hsearch_r functions will also fail if the action is -.Dv SEARCH +.Dv FIND and the element is not found: .Bl -tag -width Er .It Bq Er ESRCH From 542a9440cd9c7a103ee05616f7f2fc2950c0d6b6 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 7 Feb 2017 03:46:48 +0000 Subject: [PATCH 03/18] Fix :hexadecimal_floating_point on i386 Don't exclude i386 from LDBL_MANT_DIG == 64; it works properly in that case. While here, replace strcmp + atf_tc_fail with ATF_CHECK_MSG for 2 reasons: - Gather as many results as possible instead of failing early and not testing the rest of the cases. - Simplify logic when checking test inputs vs outputs and printing test result. Tested on: amd64, i386 MFC after: 1 week Sponsored by: Dell EMC Isilon --- lib/libc/tests/stdio/printfloat_test.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/libc/tests/stdio/printfloat_test.c b/lib/libc/tests/stdio/printfloat_test.c index 974374fae5ca..97629fb0d2b1 100644 --- a/lib/libc/tests/stdio/printfloat_test.c +++ b/lib/libc/tests/stdio/printfloat_test.c @@ -70,22 +70,19 @@ _testfmt(const char *result, const char *argstr, const char *fmt,...) va_copy(ap2, ap); smash_stack(); vsnprintf(s, sizeof(s), fmt, ap); - if (strcmp(result, s) != 0) { - atf_tc_fail( - "printf(\"%s\", %s) ==> [%s], expected [%s]", - fmt, argstr, s, result); - } + ATF_CHECK_MSG(strcmp(result, s) == 0, + "printf(\"%s\", %s) ==> [%s], expected [%s]", + fmt, argstr, s, result); smash_stack(); mbstowcs(ws, s, BUF - 1); mbstowcs(wfmt, fmt, BUF - 1); mbstowcs(wresult, result, BUF - 1); vswprintf(ws, sizeof(ws) / sizeof(ws[0]), wfmt, ap2); - if (wcscmp(wresult, ws) != 0) { - atf_tc_fail( - "wprintf(\"%ls\", %s) ==> [%ls], expected [%ls]", - wfmt, argstr, ws, wresult); - } + ATF_CHECK_MSG(wcscmp(wresult, ws) == 0, + "wprintf(\"%ls\", %s) ==> [%ls], expected [%ls]", + wfmt, argstr, ws, wresult); + va_end(ap); va_end(ap2); } @@ -318,7 +315,7 @@ ATF_TC_BODY(hexadecimal_floating_point, tc) testfmt("0x1p-1074", "%a", 0x1p-1074); testfmt("0x1.2345p-1024", "%a", 0x1.2345p-1024); -#if (LDBL_MANT_DIG == 64) && !defined(__i386__) +#if (LDBL_MANT_DIG == 64) testfmt("0x1.921fb54442d18468p+1", "%La", 0x3.243f6a8885a308dp0L); testfmt("0x1p-16445", "%La", 0x1p-16445L); testfmt("0x1.30ecap-16381", "%La", 0x9.8765p-16384L); From 570d6c8453ea2a986c81cdc25fc1dccd8faa006a Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 7 Feb 2017 04:15:41 +0000 Subject: [PATCH 04/18] Expect :floatunditf to fail on FreeBSD/i386 The precision error on FreeBSD/i386 doesn't match the expected output in long double form. MFC after: 1 week Sponsored by: Dell EMC Isilon --- contrib/netbsd-tests/lib/libc/gen/t_floatunditf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contrib/netbsd-tests/lib/libc/gen/t_floatunditf.c b/contrib/netbsd-tests/lib/libc/gen/t_floatunditf.c index ef372f76762b..c3417bb538b4 100644 --- a/contrib/netbsd-tests/lib/libc/gen/t_floatunditf.c +++ b/contrib/netbsd-tests/lib/libc/gen/t_floatunditf.c @@ -119,6 +119,11 @@ ATF_TC_BODY(floatunditf, tc) #else size_t i; +#if defined(__FreeBSD__) && defined(__i386__) + atf_tc_expect_fail("the floating point error on FreeBSD/i386 doesn't " + "match the expected floating point error on NetBSD"); +#endif + for (i = 0; i < __arraycount(testcases); ++i) ATF_CHECK_MSG( testcases[i].ld == (long double)testcases[i].u64, From 3c2fa92d70dafa42d15110b1bf066d1ec22a9c08 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 7 Feb 2017 04:25:21 +0000 Subject: [PATCH 05/18] Wrap strcmp/wcscmp calls with ATF_CHECK_MSG and drop atf_tc_fail use The reasoning here was the same as what was done in r313376: - Gather as many results as possible instead of failing early and not testing the rest of the cases. - Simplify logic when checking test inputs vs outputs and printing test result. MFC after: 1 week Sponsored by: Dell EMC Isilon --- lib/libc/tests/stdio/printbasic_test.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/libc/tests/stdio/printbasic_test.c b/lib/libc/tests/stdio/printbasic_test.c index 7f7c6cbbd65c..e1220a35f830 100644 --- a/lib/libc/tests/stdio/printbasic_test.c +++ b/lib/libc/tests/stdio/printbasic_test.c @@ -78,22 +78,19 @@ _testfmt(const char *result, const char *argstr, const char *fmt,...) va_copy(ap2, ap); smash_stack(); vsnprintf(s, sizeof(s), fmt, ap); - if (strcmp(result, s) != 0) { - atf_tc_fail( - "printf(\"%s\", %s) ==> [%s], expected [%s]", - fmt, argstr, s, result); - } + ATF_CHECK_MSG(strcmp(result, s) == 0, + "printf(\"%s\", %s) ==> [%s], expected [%s]", + fmt, argstr, s, result); smash_stack(); mbstowcs(ws, s, BUF - 1); mbstowcs(wfmt, fmt, BUF - 1); mbstowcs(wresult, result, BUF - 1); vswprintf(ws, sizeof(ws) / sizeof(ws[0]), wfmt, ap2); - if (wcscmp(wresult, ws) != 0) { - atf_tc_fail( - "wprintf(\"%ls\", %s) ==> [%ls], expected [%ls]", - wfmt, argstr, ws, wresult); - } + ATF_CHECK_MSG(wcscmp(wresult, ws) == 0, + "wprintf(\"%ls\", %s) ==> [%ls], expected [%ls]", + wfmt, argstr, ws, wresult); + va_end(ap); va_end(ap2); } From 78a63023611417790859038275788d94b454e095 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 7 Feb 2017 05:39:00 +0000 Subject: [PATCH 06/18] Expect :int_within_limits to fail when ptrdiff_t/*intmax_t differ in base type The %t{d,u} (ptrdiff_t) tests fail for the following reasons: - ptrdiff_t is by definition int32_t on !LP64 architectures and int64_t on LP64 architectures. - intmax_t is by definition fixed to int64_t on all architectures. - Some of the code in lib/libc/stdio/... is promoting ptrdiff_t to *intmax_t when parsing/representing the value. PR: 191674 MFC after: 1 week Sponsored by: Dell EMC Isilon --- lib/libc/tests/stdio/printbasic_test.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/libc/tests/stdio/printbasic_test.c b/lib/libc/tests/stdio/printbasic_test.c index e1220a35f830..322e7477da25 100644 --- a/lib/libc/tests/stdio/printbasic_test.c +++ b/lib/libc/tests/stdio/printbasic_test.c @@ -111,6 +111,11 @@ ATF_TC_BODY(int_within_limits, tc) testfmt("-1", "%jd", (intmax_t)-1); testfmt(S_UINT64MAX, "%ju", UINT64_MAX); + if (sizeof(ptrdiff_t) != sizeof(uintmax_t)) + atf_tc_expect_fail("the %%t qualifier is broken on 32-bit " + "platforms where there's a mismatch between ptrdiff_t and " + "uintmax_t's type width; bug # 191674"); + testfmt("-1", "%td", (ptrdiff_t)-1); testfmt(S_SIZEMAX, "%tu", (size_t)-1); From b796cf8107f60debf33d8c78155141dccab037ea Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 7 Feb 2017 12:04:04 +0000 Subject: [PATCH 07/18] Add support for PLATFORM and PLATFORM_SMP to the Altera SOCFPGA SoC. This will help with moving it to GENERIC. Reviewed by: br Sponsored by: ABT Systems Ltd Differential Revision: https://reviews.freebsd.org/D9461 --- sys/arm/altera/socfpga/socfpga_common.c | 24 -------- sys/arm/altera/socfpga/socfpga_machdep.c | 74 +++++++++++++++--------- sys/arm/altera/socfpga/socfpga_mp.c | 9 ++- sys/arm/altera/socfpga/socfpga_mp.h | 34 +++++++++++ sys/arm/conf/SOCKIT.common | 2 + 5 files changed, 91 insertions(+), 52 deletions(-) create mode 100644 sys/arm/altera/socfpga/socfpga_mp.h diff --git a/sys/arm/altera/socfpga/socfpga_common.c b/sys/arm/altera/socfpga/socfpga_common.c index 12a2cc5c4716..1017f3e71d00 100644 --- a/sys/arm/altera/socfpga/socfpga_common.c +++ b/sys/arm/altera/socfpga/socfpga_common.c @@ -43,27 +43,3 @@ __FBSDID("$FreeBSD$"); #include -void -cpu_reset(void) -{ - uint32_t paddr; - bus_addr_t vaddr; - phandle_t node; - - if (rstmgr_warmreset() == 0) - goto end; - - node = OF_finddevice("rstmgr"); - if (node == -1) - goto end; - - if ((OF_getencprop(node, "reg", &paddr, sizeof(paddr))) > 0) { - if (bus_space_map(fdtbus_bs_tag, paddr, 0x8, 0, &vaddr) == 0) { - bus_space_write_4(fdtbus_bs_tag, vaddr, - RSTMGR_CTRL, CTRL_SWWARMRSTREQ); - } - } - -end: - while (1); -} diff --git a/sys/arm/altera/socfpga/socfpga_machdep.c b/sys/arm/altera/socfpga/socfpga_machdep.c index bcfdd5ceded8..ca48c0f69b3c 100644 --- a/sys/arm/altera/socfpga/socfpga_machdep.c +++ b/sys/arm/altera/socfpga/socfpga_machdep.c @@ -28,7 +28,6 @@ * SUCH DAMAGE. */ -#include "opt_ddb.h" #include "opt_platform.h" #include @@ -41,38 +40,22 @@ __FBSDID("$FreeBSD$"); #include +#include + #include #include +#include #include #include +#include -vm_offset_t -platform_lastaddr(void) -{ +#include +#include - return (devmap_lastaddr()); -} +#include "platform_if.h" -void -platform_probe_and_attach(void) -{ - -} - -void -platform_gpio_init(void) -{ - -} - -void -platform_late_init(void) -{ - -} - -int -platform_devmap_init(void) +static int +socfpga_devmap_init(platform_t plat) { /* UART */ @@ -99,3 +82,42 @@ platform_devmap_init(void) return (0); } + +static void +socfpga_cpu_reset(platform_t plat) +{ + uint32_t paddr; + bus_addr_t vaddr; + phandle_t node; + + if (rstmgr_warmreset() == 0) + goto end; + + node = OF_finddevice("rstmgr"); + if (node == -1) + goto end; + + if ((OF_getencprop(node, "reg", &paddr, sizeof(paddr))) > 0) { + if (bus_space_map(fdtbus_bs_tag, paddr, 0x8, 0, &vaddr) == 0) { + bus_space_write_4(fdtbus_bs_tag, vaddr, + RSTMGR_CTRL, CTRL_SWWARMRSTREQ); + } + } + +end: + while (1); +} + +static platform_method_t socfpga_methods[] = { + PLATFORMMETHOD(platform_devmap_init, socfpga_devmap_init), + PLATFORMMETHOD(platform_cpu_reset, socfpga_cpu_reset), + +#ifdef SMP + PLATFORMMETHOD(platform_mp_setmaxid, socfpga_mp_setmaxid), + PLATFORMMETHOD(platform_mp_start_ap, socfpga_mp_start_ap), +#endif + + PLATFORMMETHOD_END, +}; + +FDT_PLATFORM_DEF(socfpga, "socfpga", 0, "altr,socfpga", 0); diff --git a/sys/arm/altera/socfpga/socfpga_mp.c b/sys/arm/altera/socfpga/socfpga_mp.c index 5ea561fb854b..aa8e1e84874c 100644 --- a/sys/arm/altera/socfpga/socfpga_mp.c +++ b/sys/arm/altera/socfpga/socfpga_mp.c @@ -28,6 +28,8 @@ * SUCH DAMAGE. */ +#include "opt_platform.h" + #include __FBSDID("$FreeBSD$"); #include @@ -45,6 +47,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include + +#include #define SCU_PHYSBASE 0xFFFEC000 #define SCU_SIZE 0x100 @@ -85,7 +90,7 @@ socfpga_trampoline(void) } void -platform_mp_setmaxid(void) +socfpga_mp_setmaxid(platform_t plat) { int hwcpu, ncpu; @@ -105,7 +110,7 @@ platform_mp_setmaxid(void) } void -platform_mp_start_ap(void) +socfpga_mp_start_ap(platform_t plat) { bus_space_handle_t scu, rst, ram; int reg; diff --git a/sys/arm/altera/socfpga/socfpga_mp.h b/sys/arm/altera/socfpga/socfpga_mp.h new file mode 100644 index 000000000000..d0927db4d933 --- /dev/null +++ b/sys/arm/altera/socfpga/socfpga_mp.h @@ -0,0 +1,34 @@ +/*- + * Copyright (c) 2017 Andrew Turner + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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$ + */ + +#ifndef _SOCFPGA_MP_H_ +#define _SOCFPGA_MP_H_ + +void socfpga_mp_setmaxid(platform_t); +void socfpga_mp_start_ap(platform_t); + +#endif /* _SOCFPGA_MP_H_ */ diff --git a/sys/arm/conf/SOCKIT.common b/sys/arm/conf/SOCKIT.common index 91020020e716..5ff60a8ef7a4 100644 --- a/sys/arm/conf/SOCKIT.common +++ b/sys/arm/conf/SOCKIT.common @@ -26,6 +26,8 @@ makeoptions MODULES_OVERRIDE="" makeoptions WERROR="-Werror" options SCHED_ULE # ULE scheduler +options PLATFORM # Platform based SoC +options PLATFORM_SMP options SMP # Enable multiple cores # NFS root from boopt/dhcp From 210d7e9a559dd7736f3c6e609a535e7359457966 Mon Sep 17 00:00:00 2001 From: mjg Date: Tue, 7 Feb 2017 14:49:36 +0000 Subject: [PATCH 08/18] locks: change backoff to exponential Previous implementation would use a random factor to spread readers and reduce chances of starvation. This visibly reduces effectiveness of the mechanism. Switch to the more traditional exponential variant. Try to limit starvation by imposing an upper limit of spins after which spinning is half of what other threads get. Note the mechanism is turned off by default. Reviewed by: kib (previous version) --- sys/kern/kern_mutex.c | 54 ++++++----------------------------- sys/kern/kern_rwlock.c | 24 ++-------------- sys/kern/kern_sx.c | 24 ++-------------- sys/kern/subr_lock.c | 64 +++++++++++++++++++++++++++++------------- sys/sys/lock.h | 14 +++++---- 5 files changed, 69 insertions(+), 111 deletions(-) diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index e37fb34cd521..76617cf6b76f 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -140,63 +140,27 @@ struct lock_class lock_class_mtx_spin = { #ifdef ADAPTIVE_MUTEXES static SYSCTL_NODE(_debug, OID_AUTO, mtx, CTLFLAG_RD, NULL, "mtx debugging"); -static struct lock_delay_config __read_mostly mtx_delay = { - .initial = 1000, - .step = 500, - .min = 100, - .max = 5000, -}; +static struct lock_delay_config __read_mostly mtx_delay; -SYSCTL_INT(_debug_mtx, OID_AUTO, delay_initial, CTLFLAG_RW, &mtx_delay.initial, - 0, ""); -SYSCTL_INT(_debug_mtx, OID_AUTO, delay_step, CTLFLAG_RW, &mtx_delay.step, - 0, ""); -SYSCTL_INT(_debug_mtx, OID_AUTO, delay_min, CTLFLAG_RW, &mtx_delay.min, +SYSCTL_INT(_debug_mtx, OID_AUTO, delay_base, CTLFLAG_RW, &mtx_delay.base, 0, ""); SYSCTL_INT(_debug_mtx, OID_AUTO, delay_max, CTLFLAG_RW, &mtx_delay.max, 0, ""); -static void -mtx_delay_sysinit(void *dummy) -{ - - mtx_delay.initial = mp_ncpus * 25; - mtx_delay.step = (mp_ncpus * 25) / 2; - mtx_delay.min = mp_ncpus * 5; - mtx_delay.max = mp_ncpus * 25 * 10; -} -LOCK_DELAY_SYSINIT(mtx_delay_sysinit); +LOCK_DELAY_SYSINIT_DEFAULT(mtx_delay); #endif static SYSCTL_NODE(_debug, OID_AUTO, mtx_spin, CTLFLAG_RD, NULL, "mtx spin debugging"); -static struct lock_delay_config __read_mostly mtx_spin_delay = { - .initial = 1000, - .step = 500, - .min = 100, - .max = 5000, -}; +static struct lock_delay_config __read_mostly mtx_spin_delay; -SYSCTL_INT(_debug_mtx_spin, OID_AUTO, delay_initial, CTLFLAG_RW, - &mtx_spin_delay.initial, 0, ""); -SYSCTL_INT(_debug_mtx_spin, OID_AUTO, delay_step, CTLFLAG_RW, &mtx_spin_delay.step, - 0, ""); -SYSCTL_INT(_debug_mtx_spin, OID_AUTO, delay_min, CTLFLAG_RW, &mtx_spin_delay.min, - 0, ""); -SYSCTL_INT(_debug_mtx_spin, OID_AUTO, delay_max, CTLFLAG_RW, &mtx_spin_delay.max, - 0, ""); +SYSCTL_INT(_debug_mtx_spin, OID_AUTO, delay_base, CTLFLAG_RW, + &mtx_spin_delay.base, 0, ""); +SYSCTL_INT(_debug_mtx_spin, OID_AUTO, delay_max, CTLFLAG_RW, + &mtx_spin_delay.max, 0, ""); -static void -mtx_spin_delay_sysinit(void *dummy) -{ - - mtx_spin_delay.initial = mp_ncpus * 25; - mtx_spin_delay.step = (mp_ncpus * 25) / 2; - mtx_spin_delay.min = mp_ncpus * 5; - mtx_spin_delay.max = mp_ncpus * 25 * 10; -} -LOCK_DELAY_SYSINIT(mtx_spin_delay_sysinit); +LOCK_DELAY_SYSINIT_DEFAULT(mtx_spin_delay); /* * System-wide mutexes diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index 0a59bf94f3f8..365c0c452b48 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -100,32 +100,14 @@ static SYSCTL_NODE(_debug, OID_AUTO, rwlock, CTLFLAG_RD, NULL, SYSCTL_INT(_debug_rwlock, OID_AUTO, retry, CTLFLAG_RW, &rowner_retries, 0, ""); SYSCTL_INT(_debug_rwlock, OID_AUTO, loops, CTLFLAG_RW, &rowner_loops, 0, ""); -static struct lock_delay_config __read_mostly rw_delay = { - .initial = 1000, - .step = 500, - .min = 100, - .max = 5000, -}; +static struct lock_delay_config __read_mostly rw_delay; -SYSCTL_INT(_debug_rwlock, OID_AUTO, delay_initial, CTLFLAG_RW, &rw_delay.initial, - 0, ""); -SYSCTL_INT(_debug_rwlock, OID_AUTO, delay_step, CTLFLAG_RW, &rw_delay.step, - 0, ""); -SYSCTL_INT(_debug_rwlock, OID_AUTO, delay_min, CTLFLAG_RW, &rw_delay.min, +SYSCTL_INT(_debug_rwlock, OID_AUTO, delay_base, CTLFLAG_RW, &rw_delay.base, 0, ""); SYSCTL_INT(_debug_rwlock, OID_AUTO, delay_max, CTLFLAG_RW, &rw_delay.max, 0, ""); -static void -rw_delay_sysinit(void *dummy) -{ - - rw_delay.initial = mp_ncpus * 25; - rw_delay.step = (mp_ncpus * 25) / 2; - rw_delay.min = mp_ncpus * 5; - rw_delay.max = mp_ncpus * 25 * 10; -} -LOCK_DELAY_SYSINIT(rw_delay_sysinit); +LOCK_DELAY_SYSINIT_DEFAULT(rw_delay); #endif /* diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c index c0fc26aabd32..777f31e535dc 100644 --- a/sys/kern/kern_sx.c +++ b/sys/kern/kern_sx.c @@ -148,32 +148,14 @@ static SYSCTL_NODE(_debug, OID_AUTO, sx, CTLFLAG_RD, NULL, "sxlock debugging"); SYSCTL_UINT(_debug_sx, OID_AUTO, retries, CTLFLAG_RW, &asx_retries, 0, ""); SYSCTL_UINT(_debug_sx, OID_AUTO, loops, CTLFLAG_RW, &asx_loops, 0, ""); -static struct lock_delay_config __read_mostly sx_delay = { - .initial = 1000, - .step = 500, - .min = 100, - .max = 5000, -}; +static struct lock_delay_config __read_mostly sx_delay; -SYSCTL_INT(_debug_sx, OID_AUTO, delay_initial, CTLFLAG_RW, &sx_delay.initial, - 0, ""); -SYSCTL_INT(_debug_sx, OID_AUTO, delay_step, CTLFLAG_RW, &sx_delay.step, - 0, ""); -SYSCTL_INT(_debug_sx, OID_AUTO, delay_min, CTLFLAG_RW, &sx_delay.min, +SYSCTL_INT(_debug_sx, OID_AUTO, delay_base, CTLFLAG_RW, &sx_delay.base, 0, ""); SYSCTL_INT(_debug_sx, OID_AUTO, delay_max, CTLFLAG_RW, &sx_delay.max, 0, ""); -static void -sx_delay_sysinit(void *dummy) -{ - - sx_delay.initial = mp_ncpus * 25; - sx_delay.step = (mp_ncpus * 25) / 2; - sx_delay.min = mp_ncpus * 5; - sx_delay.max = mp_ncpus * 25 * 10; -} -LOCK_DELAY_SYSINIT(sx_delay_sysinit); +LOCK_DELAY_SYSINIT_DEFAULT(sx_delay); #endif void diff --git a/sys/kern/subr_lock.c b/sys/kern/subr_lock.c index f83ba58f7aa4..2ed5fdb6bb72 100644 --- a/sys/kern/subr_lock.c +++ b/sys/kern/subr_lock.c @@ -56,6 +56,9 @@ __FBSDID("$FreeBSD$"); #include +SDT_PROVIDER_DEFINE(lock); +SDT_PROBE_DEFINE1(lock, , , starvation, "u_int"); + CTASSERT(LOCK_CLASS_MAX == 15); struct lock_class *lock_classes[LOCK_CLASS_MAX + 1] = { @@ -103,32 +106,56 @@ lock_destroy(struct lock_object *lock) lock->lo_flags &= ~LO_INITIALIZED; } +static SYSCTL_NODE(_debug, OID_AUTO, lock, CTLFLAG_RD, NULL, "lock debugging"); +static SYSCTL_NODE(_debug_lock, OID_AUTO, delay, CTLFLAG_RD, NULL, + "lock delay"); + +static u_int __read_mostly starvation_limit = 131072; +SYSCTL_INT(_debug_lock_delay, OID_AUTO, starvation_limit, CTLFLAG_RW, + &starvation_limit, 0, ""); + +static u_int __read_mostly restrict_starvation = 0; +SYSCTL_INT(_debug_lock_delay, OID_AUTO, restrict_starvation, CTLFLAG_RW, + &restrict_starvation, 0, ""); + void lock_delay(struct lock_delay_arg *la) { - u_int i, delay, backoff, min, max; struct lock_delay_config *lc = la->config; + u_int i; - delay = la->delay; + la->delay <<= 1; + if (__predict_false(la->delay > lc->max)) + la->delay = lc->max; - if (delay == 0) - delay = lc->initial; - else { - delay += lc->step; - max = lc->max; - if (delay > max) - delay = max; - } - - backoff = cpu_ticks() % delay; - min = lc->min; - if (backoff < min) - backoff = min; - for (i = 0; i < backoff; i++) + for (i = la->delay; i > 0; i++) cpu_spinwait(); - la->delay = delay; - la->spin_cnt += backoff; + la->spin_cnt += la->delay; + if (__predict_false(la->spin_cnt > starvation_limit)) { + SDT_PROBE1(lock, , , starvation, la->delay); + if (restrict_starvation) + la->delay = lc->base; + } +} + +static u_int +lock_roundup_2(u_int val) +{ + u_int res; + + for (res = 1; res <= val; res <<= 1) + continue; + + return (res); +} + +void +lock_delay_default_init(struct lock_delay_config *lc) +{ + + lc->base = lock_roundup_2(mp_ncpus) / 4; + lc->max = lc->base * 1024; } #ifdef DDB @@ -655,7 +682,6 @@ lock_profile_release_lock(struct lock_object *lo) critical_exit(); } -static SYSCTL_NODE(_debug, OID_AUTO, lock, CTLFLAG_RD, NULL, "lock debugging"); static SYSCTL_NODE(_debug_lock, OID_AUTO, prof, CTLFLAG_RD, NULL, "lock profiling"); SYSCTL_INT(_debug_lock_prof, OID_AUTO, skipspin, CTLFLAG_RW, diff --git a/sys/sys/lock.h b/sys/sys/lock.h index dbe715a31540..89b61ab73ddd 100644 --- a/sys/sys/lock.h +++ b/sys/sys/lock.h @@ -202,9 +202,7 @@ extern struct lock_class lock_class_lockmgr; extern struct lock_class *lock_classes[]; struct lock_delay_config { - u_int initial; - u_int step; - u_int min; + u_int base; u_int max; }; @@ -215,19 +213,25 @@ struct lock_delay_arg { }; static inline void -lock_delay_arg_init(struct lock_delay_arg *la, struct lock_delay_config *lc) { +lock_delay_arg_init(struct lock_delay_arg *la, struct lock_delay_config *lc) +{ la->config = lc; - la->delay = 0; + la->delay = lc->base; la->spin_cnt = 0; } #define LOCK_DELAY_SYSINIT(func) \ SYSINIT(func##_ld, SI_SUB_LOCK, SI_ORDER_ANY, func, NULL) +#define LOCK_DELAY_SYSINIT_DEFAULT(lc) \ + SYSINIT(lock_delay_##lc##_ld, SI_SUB_LOCK, SI_ORDER_ANY, \ + lock_delay_default_init, &lc) + void lock_init(struct lock_object *, struct lock_class *, const char *, const char *, int); void lock_destroy(struct lock_object *); void lock_delay(struct lock_delay_arg *); +void lock_delay_default_init(struct lock_delay_config *); void spinlock_enter(void); void spinlock_exit(void); void witness_init(struct lock_object *, const char *); From 8966cdb0eec9604adccaf06a7221aec8502fe92a Mon Sep 17 00:00:00 2001 From: manu Date: Tue, 7 Feb 2017 15:16:01 +0000 Subject: [PATCH 09/18] efipart is also using the '%S' printf format, add -Wno-format for it. This fix building for armv6. --- sys/boot/efi/libefi/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/boot/efi/libefi/Makefile b/sys/boot/efi/libefi/Makefile index 7f22dc4a8f40..33a8f3e7e04e 100644 --- a/sys/boot/efi/libefi/Makefile +++ b/sys/boot/efi/libefi/Makefile @@ -26,6 +26,7 @@ SRCS+= time_event.c # of a short. There's no good cast to use here so just ignore the # warnings for now. CWARNFLAGS.efinet.c+= -Wno-format +CWARNFLAGS.efipart.c+= -Wno-format CWARNFLAGS.env.c+= -Wno-format .if ${MACHINE_CPUARCH} == "aarch64" From da602db6ef366ed0d1d0d3e41c3aad34488e2b6b Mon Sep 17 00:00:00 2001 From: mjg Date: Tue, 7 Feb 2017 16:01:07 +0000 Subject: [PATCH 10/18] locks: follow up r313386 Unfinished diff was committed by accident. The loop in lock_delay was changed to decrement, but the loop iterator was still incrementing. --- sys/kern/subr_lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/kern/subr_lock.c b/sys/kern/subr_lock.c index 2ed5fdb6bb72..8584525922fd 100644 --- a/sys/kern/subr_lock.c +++ b/sys/kern/subr_lock.c @@ -128,7 +128,7 @@ lock_delay(struct lock_delay_arg *la) if (__predict_false(la->delay > lc->max)) la->delay = lc->max; - for (i = la->delay; i > 0; i++) + for (i = la->delay; i > 0; i--) cpu_spinwait(); la->spin_cnt += la->delay; From 81b684fbac8b763e4275116361c50c46a86f51be Mon Sep 17 00:00:00 2001 From: mjg Date: Tue, 7 Feb 2017 17:03:22 +0000 Subject: [PATCH 11/18] Bump struct thread alignment to 32. This gives additional bits to use in locking primitives which store the lock thread pointer in the lock value. Discussed with: kib --- sys/kern/init_main.c | 2 +- sys/kern/kern_thread.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 82b733077b39..4c0e4960b401 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -99,7 +99,7 @@ void mi_startup(void); /* Should be elsewhere */ static struct session session0; static struct pgrp pgrp0; struct proc proc0; -struct thread0_storage thread0_st __aligned(16); +struct thread0_storage thread0_st __aligned(32); struct vmspace vmspace0; struct proc *initproc; diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c index 3a7309899896..0c8365a96ad0 100644 --- a/sys/kern/kern_thread.c +++ b/sys/kern/kern_thread.c @@ -281,7 +281,7 @@ threadinit(void) thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(), thread_ctor, thread_dtor, thread_init, thread_fini, - 16 - 1, UMA_ZONE_NOFREE); + 32 - 1, UMA_ZONE_NOFREE); tidhashtbl = hashinit(maxproc / 2, M_TIDHASH, &tidhash); rw_init(&tidhash_lock, "tidhash"); } From 58e05ff8086b71a2d4e9394d8d3d4fcdfeee3543 Mon Sep 17 00:00:00 2001 From: mjg Date: Tue, 7 Feb 2017 17:04:31 +0000 Subject: [PATCH 12/18] rwlock: implement RW_LOCK_WRITER_RECURSED bit This moves recursion handling out of the inlined wunlock path and in particular saves a read and a branch. Discussed with: --- sys/kern/kern_rwlock.c | 21 +++++++++++++-------- sys/sys/rwlock.h | 13 +++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index 365c0c452b48..4ffe402ab013 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -312,6 +312,7 @@ __rw_try_wlock(volatile uintptr_t *c, const char *file, int line) if (rw_wlocked(rw) && (rw->lock_object.lo_flags & LO_RECURSABLE) != 0) { rw->rw_recurse++; + atomic_set_ptr(&rw->rw_lock, RW_LOCK_WRITER_RECURSED); rval = 1; } else rval = atomic_cmpset_acq_ptr(&rw->rw_lock, RW_UNLOCKED, @@ -345,10 +346,8 @@ _rw_wunlock_cookie(volatile uintptr_t *c, const char *file, int line) WITNESS_UNLOCK(&rw->lock_object, LOP_EXCLUSIVE, file, line); LOCK_LOG_LOCK("WUNLOCK", &rw->lock_object, 0, rw->rw_recurse, file, line); - if (rw->rw_recurse) - rw->rw_recurse--; - else - _rw_wunlock_hard(rw, (uintptr_t)curthread, file, line); + + _rw_wunlock_hard(rw, (uintptr_t)curthread, file, line); TD_LOCKS_DEC(curthread); } @@ -802,6 +801,7 @@ __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v, uintptr_t tid, ("%s: recursing but non-recursive rw %s @ %s:%d\n", __func__, rw->lock_object.lo_name, file, line)); rw->rw_recurse++; + atomic_set_ptr(&rw->rw_lock, RW_LOCK_WRITER_RECURSED); if (LOCK_LOG_TEST(&rw->lock_object, 0)) CTR2(KTR_LOCK, "%s: %p recursing", __func__, rw); return; @@ -994,12 +994,17 @@ __rw_wunlock_hard(volatile uintptr_t *c, uintptr_t tid, const char *file, return; rw = rwlock2rw(c); - MPASS(!rw_recursed(rw)); - LOCKSTAT_PROFILE_RELEASE_RWLOCK(rw__release, rw, - LOCKSTAT_WRITER); - if (_rw_write_unlock(rw, tid)) + if (!rw_recursed(rw)) { + LOCKSTAT_PROFILE_RELEASE_RWLOCK(rw__release, rw, + LOCKSTAT_WRITER); + if (_rw_write_unlock(rw, tid)) + return; + } else { + if (--(rw->rw_recurse) == 0) + atomic_clear_ptr(&rw->rw_lock, RW_LOCK_WRITER_RECURSED); return; + } KASSERT(rw->rw_lock & (RW_LOCK_READ_WAITERS | RW_LOCK_WRITE_WAITERS), ("%s: neither of the waiter flags are set", __func__)); diff --git a/sys/sys/rwlock.h b/sys/sys/rwlock.h index d6dd4f078753..6e4d0696faf5 100644 --- a/sys/sys/rwlock.h +++ b/sys/sys/rwlock.h @@ -58,9 +58,10 @@ #define RW_LOCK_READ_WAITERS 0x02 #define RW_LOCK_WRITE_WAITERS 0x04 #define RW_LOCK_WRITE_SPINNER 0x08 +#define RW_LOCK_WRITER_RECURSED 0x10 #define RW_LOCK_FLAGMASK \ (RW_LOCK_READ | RW_LOCK_READ_WAITERS | RW_LOCK_WRITE_WAITERS | \ - RW_LOCK_WRITE_SPINNER) + RW_LOCK_WRITE_SPINNER | RW_LOCK_WRITER_RECURSED) #define RW_LOCK_WAITERS (RW_LOCK_READ_WAITERS | RW_LOCK_WRITE_WAITERS) #define RW_OWNER(x) ((x) & ~RW_LOCK_FLAGMASK) @@ -111,13 +112,9 @@ #define __rw_wunlock(rw, tid, file, line) do { \ uintptr_t _tid = (uintptr_t)(tid); \ \ - if ((rw)->rw_recurse) \ - (rw)->rw_recurse--; \ - else { \ - if (__predict_false(LOCKSTAT_PROFILE_ENABLED(rw__release) ||\ - !_rw_write_unlock((rw), _tid))) \ - _rw_wunlock_hard((rw), _tid, (file), (line)); \ - } \ + if (__predict_false(LOCKSTAT_PROFILE_ENABLED(rw__release) || \ + !_rw_write_unlock((rw), _tid))) \ + _rw_wunlock_hard((rw), _tid, (file), (line)); \ } while (0) /* From 1aca5acdcfd60fd0dc8769ab543297996cd80f37 Mon Sep 17 00:00:00 2001 From: manu Date: Tue, 7 Feb 2017 17:15:13 +0000 Subject: [PATCH 13/18] Switch to the Linux device tree upstream names for Allwinner boards. Newer u-boot that uses the u-boot-master port uses these names. --- sys/modules/dtb/allwinner/Makefile | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/sys/modules/dtb/allwinner/Makefile b/sys/modules/dtb/allwinner/Makefile index cc2db41d75f1..f96063b3097b 100644 --- a/sys/modules/dtb/allwinner/Makefile +++ b/sys/modules/dtb/allwinner/Makefile @@ -1,17 +1,26 @@ # $FreeBSD$ # All the dts files for allwinner systems we support. DTS= \ - bananapi.dts \ - bananapim2.dts \ - cubieboard.dts \ - cubieboard2.dts \ nanopi-neo.dts \ - olimex-a20-som-evb.dts \ - olinuxino-lime.dts \ orangepi-plus-2e.dts \ - pcduino3.dts \ sinovoip-bpi-m3.dts \ + sun4i-a10-cubieboard.dts \ + sun4i-a10-olinuxino-lime.dts \ + sun6i-a31s-sinovoip-bpi-m2.dts \ sun5i-a13-olinuxino.dts \ - sun5i-r8-chip.dts + sun5i-r8-chip.dts \ + sun7i-a20-bananapi.dts \ + sun7i-a20-cubieboard2.dts \ + sun7i-a20-olimex-som-evb.dts \ + sun7i-a20-pcduino3.dts + +LINKS= \ + ${DTBDIR}/sun4i-a10-cubieboard.dtb ${DTBDIR}/cubieboard.dtb \ + ${DTBDIR}/sun4i-a10-olinuxino-lime.dtb ${DTBDIR}/olinuxino-lime.dtb \ + ${DTBDIR}/sun6i-a31s-sinovoip-bpi-m2.dtb ${DTBDIR}/bananapim2.dtb \ + ${DTBDIR}/sun7i-a20-bananapi.dtb ${DTBDIR}/bananapi.dtb \ + ${DTBDIR}/sun7i-a20-cubieboard2.dtb ${DTBDIR}/cubieboard2.dtb \ + ${DTBDIR}/sun7i-a20-olimex-som-evb.dtb ${DTBDIR}/olimex-a20-som-evb.dtb \ + ${DTBDIR}/sun7i-a20-pcduino3.dtb ${DTBDIR}/pcduino3.dtb .include From f48ffd97cc5c4f2208de3a57d58ad879368f5ca9 Mon Sep 17 00:00:00 2001 From: manu Date: Tue, 7 Feb 2017 17:31:24 +0000 Subject: [PATCH 14/18] subr_sfbus.c need sys/proc.h for struct thread definition. This fixes kernel build for armv6. Discussed with: kib --- sys/kern/subr_sfbuf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/kern/subr_sfbuf.c b/sys/kern/subr_sfbuf.c index 707ace220639..fa1aa4224c1e 100644 --- a/sys/kern/subr_sfbuf.c +++ b/sys/kern/subr_sfbuf.c @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include From e9a823d18f3641cc44c26e340bb0ac7475cbf53d Mon Sep 17 00:00:00 2001 From: asomers Date: Tue, 7 Feb 2017 17:40:59 +0000 Subject: [PATCH 15/18] Add fibs_test:udp_dontroute6, another IPv6 multi-FIB test PR: 196361 MFC after: 3 weeks Sponsored by: Spectra Logic Corp --- tests/sys/netinet/fibs_test.sh | 62 ++++++++++++++++++++++++++++++- tests/sys/netinet/udp_dontroute.c | 53 +++++++++++++++++++------- 2 files changed, 100 insertions(+), 15 deletions(-) diff --git a/tests/sys/netinet/fibs_test.sh b/tests/sys/netinet/fibs_test.sh index bf5a54b451a2..16213071baff 100755 --- a/tests/sys/netinet/fibs_test.sh +++ b/tests/sys/netinet/fibs_test.sh @@ -595,6 +595,61 @@ udp_dontroute_cleanup() cleanup_tap } +atf_test_case udp_dontroute6 cleanup +udp_dontroute6_head() +{ + atf_set "descr" "Source address selection for UDP IPv6 packets with SO_DONTROUTE on non-default FIBs works" + atf_set "require.user" "root" + atf_set "require.config" "fibs" +} + +udp_dontroute6_body() +{ + # Configure the TAP interface to use an RFC3849 nonrouteable address + # and a non-default fib + ADDR0="2001:db8::2" + ADDR1="2001:db8::3" + SUBNET="2001:db8::" + MASK="64" + # Use a different IP on the same subnet as the target + TARGET="2001:db8::100" + SRCDIR=`atf_get_srcdir` + + atf_expect_fail "PR196361 IPv6 network routes don't respect net.add_addr_allfibs=0" + + # Check system configuration + if [ 0 != `sysctl -n net.add_addr_allfibs` ]; then + atf_skip "This test requires net.add_addr_allfibs=0" + fi + get_fibs 2 + + # Configure the TAP interfaces. Use no_dad so the addresses will be + # ready right away and won't be marked as tentative until DAD + # completes. + setup_tap ${FIB0} inet6 ${ADDR0} ${MASK} no_dad + TARGET_TAP=${TAP} + setup_tap ${FIB1} inet6 ${ADDR1} ${MASK} no_dad + + # Send a UDP packet with SO_DONTROUTE. In the failure case, it will + # return ENETUNREACH, or send the packet to the wrong tap + atf_check -o ignore setfib ${FIB0} \ + ${SRCDIR}/udp_dontroute -6 ${TARGET} /dev/${TARGET_TAP} + cleanup_tap + + # Repeat, but this time target the other tap + setup_tap ${FIB0} inet6 ${ADDR0} ${MASK} no_dad + setup_tap ${FIB1} inet6 ${ADDR1} ${MASK} no_dad + TARGET_TAP=${TAP} + + atf_check -o ignore setfib ${FIB1} \ + ${SRCDIR}/udp_dontroute -6 ${TARGET} /dev/${TARGET_TAP} +} + +udp_dontroute6_cleanup() +{ + cleanup_tap +} + atf_init_test_cases() { @@ -609,6 +664,7 @@ atf_init_test_cases() atf_add_test_case subnet_route_with_multiple_fibs_on_same_subnet atf_add_test_case subnet_route_with_multiple_fibs_on_same_subnet_inet6 atf_add_test_case udp_dontroute + atf_add_test_case udp_dontroute6 } # Looks up one or more fibs from the configuration data and validates them. @@ -656,6 +712,7 @@ get_tap() # Protocol (inet or inet6) # IP address # Netmask in number of bits (eg 24 or 8) +# Extra flags # Return: the tap interface name as the env variable TAP setup_tap() { @@ -663,9 +720,10 @@ setup_tap() local PROTO=$2 local ADDR=$3 local MASK=$4 + local FLAGS=$5 get_tap - echo setfib ${FIB} ifconfig $TAP ${PROTO} ${ADDR}/${MASK} fib $FIB - setfib ${FIB} ifconfig $TAP ${PROTO} ${ADDR}/${MASK} fib $FIB + echo setfib ${FIB} ifconfig $TAP ${PROTO} ${ADDR}/${MASK} fib $FIB $FLAGS + setfib ${FIB} ifconfig $TAP ${PROTO} ${ADDR}/${MASK} fib $FIB $FLAGS } cleanup_tap() diff --git a/tests/sys/netinet/udp_dontroute.c b/tests/sys/netinet/udp_dontroute.c index 79421fd0b707..24e3fc4166aa 100644 --- a/tests/sys/netinet/udp_dontroute.c +++ b/tests/sys/netinet/udp_dontroute.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,7 @@ int main(int argc, char **argv) { - struct sockaddr_in dst; + struct sockaddr_storage dst; int s, t; int opt; int ret; @@ -60,17 +61,33 @@ main(int argc, char **argv) const char* sendbuf = "Hello, World!"; const size_t buflen = 80; char recvbuf[buflen]; + bool v6 = false; + const char *addr, *tapdev; + const uint16_t port = 46120; - if (argc != 3) { - fprintf(stderr, "Usage: %s ip_address tapdev\n", argv[0]); + bzero(&dst, sizeof(dst)); + if (argc < 3 || argc > 4) { + fprintf(stderr, "Usage: %s [-6] ip_address tapdev\n", argv[0]); exit(2); } - t = open(argv[2], O_RDWR | O_NONBLOCK); + if (strcmp("-6", argv[1]) == 0) { + v6 = true; + addr = argv[2]; + tapdev = argv[3]; + } else { + addr = argv[1]; + tapdev = argv[2]; + } + + t = open(tapdev, O_RDWR | O_NONBLOCK); if (t < 0) err(EXIT_FAILURE, "open"); - s = socket(PF_INET, SOCK_DGRAM, 0); + if (v6) + s = socket(PF_INET6, SOCK_DGRAM, 0); + else + s = socket(PF_INET, SOCK_DGRAM, 0); if (s < 0) err(EXIT_FAILURE, "socket"); opt = 1; @@ -79,16 +96,26 @@ main(int argc, char **argv) if (ret == -1) err(EXIT_FAILURE, "setsockopt(SO_DONTROUTE)"); - dst.sin_len = sizeof(dst); - dst.sin_family = AF_INET; - dst.sin_port = htons(46120); - dst.sin_addr.s_addr = inet_addr(argv[1]); - if (dst.sin_addr.s_addr == htonl(INADDR_NONE)) { - fprintf(stderr, "Invalid address: %s\n", argv[1]); - exit(2); + if (v6) { + struct sockaddr_in6 *dst6 = ((struct sockaddr_in6*)&dst); + + dst.ss_len = sizeof(struct sockaddr_in6); + dst.ss_family = AF_INET6; + dst6->sin6_port = htons(port); + ret = inet_pton(AF_INET6, addr, &dst6->sin6_addr); + } else { + struct sockaddr_in *dst4 = ((struct sockaddr_in*)&dst); + + dst.ss_len = sizeof(struct sockaddr_in); + dst.ss_family = AF_INET; + dst4->sin_port = htons(port); + ret = inet_pton(AF_INET, addr, &dst4->sin_addr); } + if (ret != 1) + err(EXIT_FAILURE, "inet_pton returned %d", ret); + ret = sendto(s, sendbuf, strlen(sendbuf), 0, (struct sockaddr*)&dst, - dst.sin_len); + dst.ss_len); if (ret == -1) err(EXIT_FAILURE, "sendto"); From d431cd542b4503ced11f6239f233d0f2d3835378 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 7 Feb 2017 18:19:11 +0000 Subject: [PATCH 16/18] Push reading of ESR_EL1 to assembly. Among other uses this will allow us to expose this to signal handlers, e.g. for the clang sanitizers. Sponsored by: DARPA, AFRL --- sys/arm64/arm64/exception.S | 4 +++- sys/arm64/arm64/genassym.c | 1 + sys/arm64/arm64/trap.c | 6 +++--- sys/arm64/include/frame.h | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sys/arm64/arm64/exception.S b/sys/arm64/arm64/exception.S index 63aa04c8458b..432c4d48aca4 100644 --- a/sys/arm64/arm64/exception.S +++ b/sys/arm64/arm64/exception.S @@ -56,10 +56,12 @@ __FBSDID("$FreeBSD$"); stp x0, x1, [sp, #(TF_X + 0 * 8)] mrs x10, elr_el1 mrs x11, spsr_el1 + mrs x12, esr_el1 .if \el == 0 mrs x18, sp_el0 .endif - stp x10, x11, [sp, #(TF_ELR)] + str x10, [sp, #(TF_ELR)] + stp w11, w12, [sp, #(TF_SPSR)] stp x18, lr, [sp, #(TF_SP)] mrs x18, tpidr_el1 add x29, sp, #(TF_SIZE) diff --git a/sys/arm64/arm64/genassym.c b/sys/arm64/arm64/genassym.c index 36ad877f66c8..8d75ffa0bfad 100644 --- a/sys/arm64/arm64/genassym.c +++ b/sys/arm64/arm64/genassym.c @@ -62,4 +62,5 @@ ASSYM(TD_LOCK, offsetof(struct thread, td_lock)); ASSYM(TF_SIZE, sizeof(struct trapframe)); ASSYM(TF_SP, offsetof(struct trapframe, tf_sp)); ASSYM(TF_ELR, offsetof(struct trapframe, tf_elr)); +ASSYM(TF_SPSR, offsetof(struct trapframe, tf_spsr)); ASSYM(TF_X, offsetof(struct trapframe, tf_x)); diff --git a/sys/arm64/arm64/trap.c b/sys/arm64/arm64/trap.c index 6ae347ef4343..ef63494b3514 100644 --- a/sys/arm64/arm64/trap.c +++ b/sys/arm64/arm64/trap.c @@ -257,7 +257,7 @@ print_registers(struct trapframe *frame) printf(" sp: %16lx\n", frame->tf_sp); printf(" lr: %16lx\n", frame->tf_lr); printf(" elr: %16lx\n", frame->tf_elr); - printf("spsr: %16lx\n", frame->tf_spsr); + printf("spsr: %8x\n", frame->tf_spsr); } void @@ -267,7 +267,7 @@ do_el1h_sync(struct trapframe *frame) uint64_t esr, far; /* Read the esr register to get the exception details */ - esr = READ_SPECIALREG(esr_el1); + esr = frame->tf_esr; exception = ESR_ELx_EXCEPTION(esr); #ifdef KDTRACE_HOOKS @@ -352,7 +352,7 @@ do_el0_sync(struct trapframe *frame) td = curthread; td->td_frame = frame; - esr = READ_SPECIALREG(esr_el1); + esr = frame->tf_esr; exception = ESR_ELx_EXCEPTION(esr); switch (exception) { case EXCP_UNKNOWN: diff --git a/sys/arm64/include/frame.h b/sys/arm64/include/frame.h index 6d43e133c2c5..198ae69bdb91 100644 --- a/sys/arm64/include/frame.h +++ b/sys/arm64/include/frame.h @@ -45,7 +45,8 @@ struct trapframe { uint64_t tf_sp; uint64_t tf_lr; uint64_t tf_elr; - uint64_t tf_spsr; + uint32_t tf_spsr; + uint32_t tf_esr; uint64_t tf_x[30]; }; From 7381b6787fc52c4fbc009f68e66565e644036636 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 7 Feb 2017 18:23:44 +0000 Subject: [PATCH 17/18] Don't expect :inplace_symlink_src to fail anymore (post-r313277) The S_ISREG check was restored, such that the code will again fail with in-place replacements on symlinks MFC after: 12 days X-MFC with: r313277 Sponsored by: Dell EMC Isilon --- usr.bin/sed/tests/sed2_test.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/usr.bin/sed/tests/sed2_test.sh b/usr.bin/sed/tests/sed2_test.sh index 3ce3008deeba..a32f09d4bbab 100755 --- a/usr.bin/sed/tests/sed2_test.sh +++ b/usr.bin/sed/tests/sed2_test.sh @@ -47,8 +47,6 @@ inplace_symlink_src_head() } inplace_symlink_src_body() { - atf_expect_fail "Check for S_IFREG reverted in r312404" - echo foo > a atf_check ln -s a b atf_check -e not-empty -s not-exit:0 sed -i '' -e 's,foo,bar,g' b From 337e20c4869d5b6215175c5dbcd5f756678037b8 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 7 Feb 2017 18:37:46 +0000 Subject: [PATCH 18/18] Apply r274475's to expr.oxout.tab.c to fix the test on FreeBSD YYINT on FreeBSD is int, not short I'll work with the upstream maintainer or come up with a build method of modifying their definitions on install instead of having to modify tests to match our forked YYINT definition. PR: 216891 Sponsored by: Dell EMC Isilon --- contrib/byacc/test/yacc/expr.oxout.tab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/byacc/test/yacc/expr.oxout.tab.c b/contrib/byacc/test/yacc/expr.oxout.tab.c index b4b7ec41bd0c..fb16527c849b 100644 --- a/contrib/byacc/test/yacc/expr.oxout.tab.c +++ b/contrib/byacc/test/yacc/expr.oxout.tab.c @@ -178,7 +178,7 @@ extern int YYPARSE_DECL(); #define ID 257 #define CONST 258 #define YYERRCODE 256 -typedef short YYINT; +typedef int YYINT; static const YYINT expr.oxout_lhs[] = { -1, 2, 0, 1, 3, 3, 3, 3, 3, 3, 3, };