]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
6 years agoLoad balance sockets with new SO_REUSEPORT_LB option.
sbruno [Wed, 6 Jun 2018 15:45:57 +0000 (15:45 +0000)]
Load balance sockets with new SO_REUSEPORT_LB option.

This patch adds a new socket option, SO_REUSEPORT_LB, which allow multiple
programs or threads to bind to the same port and incoming connections will be
load balanced using a hash function.

Most of the code was copied from a similar patch for DragonflyBSD.

However, in DragonflyBSD, load balancing is a global on/off setting and can not
be set per socket. This patch allows for simultaneous use of both the current
SO_REUSEPORT and the new SO_REUSEPORT_LB options on the same system.

Required changes to structures:
Globally change so_options from 16 to 32 bit value to allow for more options.
Add hashtable in pcbinfo to hold all SO_REUSEPORT_LB sockets.

Limitations:
As DragonflyBSD, a load balance group is limited to 256 pcbs (256 programs or
threads sharing the same socket).

This is a substantially different contribution as compared to its original
incarnation at svn r332894 and reverted at svn r332967.  Thanks to rwatson@
for the substantive feedback that is included in this commit.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
Obtained from: DragonflyBSD
Relnotes: Yes
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D11003

6 years agoRewrite code using atomic_fcmpset_int() in the LinuxKPI.
hselasky [Wed, 6 Jun 2018 15:31:47 +0000 (15:31 +0000)]
Rewrite code using atomic_fcmpset_int() in the LinuxKPI.

Suggested by: mjg@
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoImplement the __add_wait_queue_entry_tail() function in the LinuxKPI.
hselasky [Wed, 6 Jun 2018 15:19:30 +0000 (15:19 +0000)]
Implement the __add_wait_queue_entry_tail() function in the LinuxKPI.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoRevert r334708
jhibbits [Wed, 6 Jun 2018 15:12:19 +0000 (15:12 +0000)]
Revert r334708

This is the wrong place to put the barrier.
Requested by: kib,mjg

6 years agoImplement the might_sleep_if() function macro in the LinuxKPI.
hselasky [Wed, 6 Jun 2018 15:10:11 +0000 (15:10 +0000)]
Implement the might_sleep_if() function macro in the LinuxKPI.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoRename two structure field members while keeping backwards compatibility in
hselasky [Wed, 6 Jun 2018 15:06:21 +0000 (15:06 +0000)]
Rename two structure field members while keeping backwards compatibility in
the LinuxKPI. Add a comment saying in which Linux version this change was made.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoImplement the init_wait_entry() function macro in the LinuxKPI.
hselasky [Wed, 6 Jun 2018 14:59:23 +0000 (14:59 +0000)]
Implement the init_wait_entry() function macro in the LinuxKPI.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoImplement the atomic_dec_if_positive() function in the LinuxKPI.
hselasky [Wed, 6 Jun 2018 13:59:51 +0000 (13:59 +0000)]
Implement the atomic_dec_if_positive() function in the LinuxKPI.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoImplement the ktime_compare() and ktime_after() functions in the LinuxKPI.
hselasky [Wed, 6 Jun 2018 13:37:31 +0000 (13:37 +0000)]
Implement the ktime_compare() and ktime_after() functions in the LinuxKPI.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoImplement the rdmsrl_safe() function macro in the LinuxKPI.
hselasky [Wed, 6 Jun 2018 13:29:52 +0000 (13:29 +0000)]
Implement the rdmsrl_safe() function macro in the LinuxKPI.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoMake in_delayed_cksum() be similar to IPv6 implementation.
ae [Wed, 6 Jun 2018 13:01:53 +0000 (13:01 +0000)]
Make in_delayed_cksum() be similar to IPv6 implementation.

Use m_copyback() function to write checksum when it isn't located
in the first mbuf of the chain. Handmade analog doesn't handle the
case when parts of checksum are located in different mbufs.
Also in case when mbuf is too short, m_copyback() will allocate new
mbuf in the chain instead of making out of bounds write.

Also wrap long line and remove now useless KASSERTs.

X-MFC after: r334705

6 years agoAdd a memory barrier after taking a reference on the vnode holdcnt in _vhold
jhibbits [Wed, 6 Jun 2018 12:57:11 +0000 (12:57 +0000)]
Add a memory barrier after taking a reference on the vnode holdcnt in _vhold

This is needed to avoid a race between the VNASSERT() below, and another
thread updating the VI_FREE flag, on weakly-ordered architectures.

On a 72-thread POWER9, without this barrier a 'make -j72 buildworld' would
panic on the assert regularly.

It may be possible to use a weaker barrier, and I'll investigate that once
all stability issues are worked out on POWER9.

6 years agoUse m_copyback() function to write delayed checksum when it isn't located
ae [Wed, 6 Jun 2018 10:46:24 +0000 (10:46 +0000)]
Use m_copyback() function to write delayed checksum when it isn't located
in the first mbuf of the chain.

MFC after: 1 week

6 years agotop(1): fix err again
eadler [Wed, 6 Jun 2018 07:13:27 +0000 (07:13 +0000)]
top(1): fix err again

I am amazed at my ability to get a one-line error reporting line wrong
thrice.

6 years agoUse UDP len when calculating UDP checksums
thj [Wed, 6 Jun 2018 07:04:40 +0000 (07:04 +0000)]
Use UDP len when calculating UDP checksums

The length of the IP payload is normally equal to the UDP length, UDP Options
(draft-ietf-tsvwg-udp-options-02) suggests using the difference between IP
length and UDP length to create space for trailing data.

Correct checksum length calculation to use the UDP length rather than the IP
length when not offloading UDP checksums.

Approved by: jtl (mentor)
Differential Revision: https://reviews.freebsd.org/D15222

6 years agotop(1): make error message happy
eadler [Wed, 6 Jun 2018 06:42:12 +0000 (06:42 +0000)]
top(1): make error message happy

We don't use a "size" variable, so just don't report it.

Reported by: bapt

6 years agoFix LINT-NOINET build.
ae [Wed, 6 Jun 2018 05:17:21 +0000 (05:17 +0000)]
Fix LINT-NOINET build.

Use known at build time size for min_length value. Also remove the
check from in6_gre_encapcheck(), now it is done in generic code.

6 years agomalloc: elaborate on r334545 due to frequent questions
mjg [Wed, 6 Jun 2018 05:08:05 +0000 (05:08 +0000)]
malloc: elaborate on r334545 due to frequent questions

While here annotate the NULL check as probably true.

6 years agohwpmc: add summary command and further metadata extensions
mmacy [Wed, 6 Jun 2018 02:48:09 +0000 (02:48 +0000)]
hwpmc: add summary command and further metadata extensions

metadata changes:
- log pmc sample rate with pmcallocate
- log proc flags with thread / process logging
  to identify user vs kernel threads

fixes:
- use log cpuid to translate event id to event name

Implement rudimentary summary command to track sample
counts by thread and process name within a pmc log.

% make -j4 buildkernel >& /dev/null &
% sudo pmcstat -S unhalted_core_cycles -S llc-misses -O foo sleep 15
% pmc summary foo
cpu_clk_unhalted.thread_p_any:
        idle: 138108207162
        clang-6.0: 105336158004
        sh: 72340108510
        make: 8642012963
        kernel: 7754011631
longest_lat_cache.miss:
        clang-6.0: 87502625
        sh: 40901227
        make: 5500165
        kernel: 3300099
        awk: 2000060

%  pmc summary -f ~/foo
idx: 278 name: cpu_clk_unhalted.thread_p_any rate: 2000003
idle: 69054
clang-6.0: 52668
sh: 36170
make: 4321
kernel: 3877
hwpmc: proc(7445): 3319
awk: 1289
xargs: 357
rand_harvestq: 181
mtree: 102
intr: 53
zfskern: 31
usb: 7
pagedaemon: 4
ntpd: 3
syslogd: 1
acpi_thermal: 1
logger: 1
syncer: 1
snmptrapd: 1
sleep: 1
idx: 17 name: longest_lat_cache.miss rate: 100003
clang-6.0: 875
sh: 409
make: 55
kernel: 33
awk: 20
hwpmc: proc(7445): 14
xargs: 9
idle: 8
intr: 3
zfskern: 2

6 years agoOnly create /var/log/sendmail.st if start sendmail.
brd [Wed, 6 Jun 2018 01:51:05 +0000 (01:51 +0000)]
Only create /var/log/sendmail.st if start sendmail.

For those of us that never use or start sendmail, it is unneeded.

Approved by: bapt (mentor)

6 years agoRemove comments and assertions that are no longer valid after r330809.
ian [Tue, 5 Jun 2018 22:13:45 +0000 (22:13 +0000)]
Remove comments and assertions that are no longer valid after r330809.

r330809 replaced duplication of devdesc struct fields with an embedded copy
of the devdesc struct, to avoid fragility.  That means all the scattered
comments indicating that structs must match are no longer valid.  Likewise
asserts that attempted to mitigate some of the old fragility.

Reviewed by: imp@

6 years agoRework if_gif(4) to use new encap_lookup_t method to speedup lookup
ae [Tue, 5 Jun 2018 21:24:59 +0000 (21:24 +0000)]
Rework if_gif(4) to use new encap_lookup_t method to speedup lookup
of needed interface when many gif interfaces are present.

Remove rmlock from gif_softc, use epoch(9) and CK_LIST instead.
Move more AF-related code into AF-related locations.
Use hash table to speedup lookup of needed softc. Interfaces
with GIF_IGNORE_SOURCE flag are stored in plain CK_LIST.
Sysctl net.link.gif.parallel_tunnels is removed. The removal was planed
16 years ago, and actually it could work only for outbound direction.
Each protocol, that can be handled by if_gif(4) interface is registered
by separate encap handler, this helps avoid invoking the handler
for unrelated protocols (GRE, PIM, etc.).

This change allows dramatically improve performance when many gif(4)
interfaces are used.

Sponsored by: Yandex LLC

6 years agoConstify argument of in6_getscope().
ae [Tue, 5 Jun 2018 20:54:29 +0000 (20:54 +0000)]
Constify argument of in6_getscope().

6 years agoRework IP encapsulation handling code.
ae [Tue, 5 Jun 2018 20:51:01 +0000 (20:51 +0000)]
Rework IP encapsulation handling code.

Currently it has several disadvantages:
- it uses single mutex to protect internal structures. It is used by
  data- and control- path, thus there are no parallelism at all.
- it uses single list to keep encap handlers for both INET and INET6
  families.
- struct encaptab keeps unneeded information (src, dst, masks, protosw),
  that isn't used by code in the source tree.
- matches are prioritized and when many tunneling interfaces are
  registered, encapcheck handler of each interface is invoked for each
  packet. The search takes O(n) for n interfaces. All this work is done
  with exclusive lock held.

What this patch includes:
- the datapath is converted to be lockless using epoch(9) KPI.
- struct encaptab now linked using CK_LIST.
- all unused fields removed from struct encaptab. Several new fields
  addedr: min_length is the minimum packet length, that encapsulation
  handler expects to see; exact_match is maximum number of bits, that
  can return an encapsulation handler, when it wants to consume a packet.
- IPv6 and IPv4 handlers are stored in separate lists;
- added new "encap_lookup_t" method, that will be used later. It is
  targeted to speedup lookup of needed interface, when gif(4)/gre(4) have
  many interfaces.
- the need to use protosw structure is eliminated. The only pr_input
  method was used from this structure, so I don't see the need to keep
  using it.
- encap_input_t method changed to avoid using mbuf tags to store softc
  pointer. Now it is passed directly trough encap_input_t method.
  encap_getarg() funtions is removed.
- all sockaddr structures and code that uses them removed. We don't have
  any code in the tree that uses them. All consumers use encap_attach_func()
  method, that relies on invoking of encapcheck() to determine the needed
  handler.
- introduced struct encap_config, it contains parameters of encap handler
  that is going to be registered by encap_attach() function.
- encap handlers are stored in lists ordered by exact_match value, thus
  handlers that need more bits to match will be checked first, and if
  encapcheck method returns exact_match value, the search will be stopped.
- all current consumers changed to use new KPI.

Reviewed by: mmacy
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D15617

6 years agoMake Coverity more happy with r334545
vangyzen [Tue, 5 Jun 2018 20:34:11 +0000 (20:34 +0000)]
Make Coverity more happy with r334545

Coverity complains about:

if (((flags) & M_WAITOK) || _malloc_item != NULL)

saying:

The expression
1 /* (2 | 0x100) & 2 */ || _malloc_item != NULL
is suspicious because it performs a Boolean operation
on a constant other than 0 or 1.

Although the code is correct, add "!= 0" to make it slightly
more legible and to silence hundreds(?) of Coverity warnings.

Reported by: Coverity
Discussed with: mjg
Sponsored by: Dell EMC

6 years agoaudit(4): add tests for open(2) and openat(2)
asomers [Tue, 5 Jun 2018 20:13:24 +0000 (20:13 +0000)]
audit(4): add tests for open(2) and openat(2)

These syscalls are atypical, because each one corresponds to several
different audit events, and they each pass several different audit class
filters.

Submitted by: aniketp
MFC after: 2 weeks
Sponsored by: Google, Inc. (GSoC 2018)
Differential Revision: https://reviews.freebsd.org/D15657

6 years agotcp_lro.h requires <netinet/in.h>, include it directly instead of
ae [Tue, 5 Jun 2018 19:23:23 +0000 (19:23 +0000)]
tcp_lro.h requires <netinet/in.h>, include it directly instead of
indirect inclusion trough if_gif.h

6 years agoHandle -DNO_CLEAN builds across brk/sbrk rewrite in r334626
emaste [Tue, 5 Jun 2018 18:27:09 +0000 (18:27 +0000)]
Handle -DNO_CLEAN builds across brk/sbrk rewrite in r334626

Sponsored by: The FreeBSD Foundation

6 years agoMake the v*printf() functions in libsa return int instead of void.
ian [Tue, 5 Jun 2018 17:18:10 +0000 (17:18 +0000)]
Make the v*printf() functions in libsa return int instead of void.
This makes them compatible with the C standard signatures, avoiding
spurious mismatch errors in the places where the oddball requirements
of standalone code end up putting two declarations of the same function
in play.

6 years agoDeclare and set the global "system_highpri_wq" workqueue structure pointer
hselasky [Tue, 5 Jun 2018 15:49:35 +0000 (15:49 +0000)]
Declare and set the global "system_highpri_wq" workqueue structure pointer
in the LinuxKPI.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoImplement the INIT_DELAYED_WORK_ONSTACK() function macro in the LinuxKPI.
hselasky [Tue, 5 Jun 2018 15:46:16 +0000 (15:46 +0000)]
Implement the INIT_DELAYED_WORK_ONSTACK() function macro in the LinuxKPI.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoDefine the __kernel_size_t type in the LinuxKPI.
hselasky [Tue, 5 Jun 2018 15:42:35 +0000 (15:42 +0000)]
Define the __kernel_size_t type in the LinuxKPI.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoImplement the task_pid_vnr() function macro in the LinuxKPI.
hselasky [Tue, 5 Jun 2018 15:40:09 +0000 (15:40 +0000)]
Implement the task_pid_vnr() function macro in the LinuxKPI.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoAdd "access" function pointer to the "vm_operations_struct" structure
hselasky [Tue, 5 Jun 2018 15:37:28 +0000 (15:37 +0000)]
Add "access" function pointer to the "vm_operations_struct" structure
in the LinuxKPI. While at it document when to use the "virtual_address" or
the "address" field in the "vm_fault" structure.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoImplement mul_u32_u32() function in the LinuxKPI.
hselasky [Tue, 5 Jun 2018 15:30:36 +0000 (15:30 +0000)]
Implement mul_u32_u32() function in the LinuxKPI.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoImplement timer_setup() and from_timer() function macros in the LinuxKPI.
hselasky [Tue, 5 Jun 2018 15:20:20 +0000 (15:20 +0000)]
Implement timer_setup() and from_timer() function macros in the LinuxKPI.

Submitted by: Johannes Lundberg <johalun0@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Sponsored by: Limelight Networks

6 years agoIssue:
ram [Tue, 5 Jun 2018 15:05:26 +0000 (15:05 +0000)]
Issue:
   Utility hangs when  OCS_IOCTL_CMD_MGMT_GET_ALL called in parallel on port 0 and port 1.

Fix: Using static structure for results is corrupting the second ioctl request. Removed static for results structure.
Approved by: ken
MFC after: 3 days

6 years agoAdd vsnprintf() to libsa. Alpha-sort the printf prototypes in stand.h.
ian [Tue, 5 Jun 2018 14:47:13 +0000 (14:47 +0000)]
Add vsnprintf() to libsa.  Alpha-sort the printf prototypes in stand.h.

I'm not sure why the v*printf() functions in libsa return void instead of
int, but this maintains that convention for the new function.

6 years agoDon't build brk_test on platforms that don't support brk().
markj [Tue, 5 Jun 2018 13:06:06 +0000 (13:06 +0000)]
Don't build brk_test on platforms that don't support brk().

X-MFC with: r334626

6 years agoEnable high-speed on the card before increasing frequency on the controller
kibab [Tue, 5 Jun 2018 11:03:24 +0000 (11:03 +0000)]
Enable high-speed on the card before increasing frequency on the controller

Increasing operating frequency without telling card to switch
to high-speed mode first upsets some cards and generates CRC errors.

While here, deselect / reselect cards after CMD6 and SCR fetch, as in original code.

Approved by: imp (mentor)
Differential Revision: https://reviews.freebsd.org/D15568

6 years agousbdevs: sync from NetBSD
eadler [Tue, 5 Jun 2018 09:52:38 +0000 (09:52 +0000)]
usbdevs: sync from NetBSD

This adds several vendors from NetBSD's copy of the same file (r1.749).
Prefer longer more "canonical" names where the names differed.

Sort while here.

6 years agoSince we don't enable BUF_TRACKING and FULL_BUF_TRACKING buffer debugging
kevlo [Tue, 5 Jun 2018 05:24:42 +0000 (05:24 +0000)]
Since we don't enable BUF_TRACKING and FULL_BUF_TRACKING buffer debugging
options in GENERIC kernels on arm and arm64, there's no need to disable
them.

Sponsored by: MSI/FUNTORO

6 years agoAdd support for SIMCom SIM7600E.
kevlo [Tue, 5 Jun 2018 05:19:04 +0000 (05:19 +0000)]
Add support for SIMCom SIM7600E.

Sponsored by: MSI/FUNTORO

6 years agohwpmc: log name->pid, name->tid mappings
mmacy [Tue, 5 Jun 2018 04:26:40 +0000 (04:26 +0000)]
hwpmc: log name->pid, name->tid mappings

By logging all threads and processes 'pmc filter'
can now filter on process or thread name, relieving
the user of the burden of determining which tid or
pid was which when the sample was taken.

% pmc filter -T if_io_tqg -P nginx pmc.log pmc-iflib.log

% pmc filter -x -T idle pmc.log pmc-noidle.log

6 years agocxgbetool: Disallow negative values for numeric parameters.
np [Mon, 4 Jun 2018 23:17:18 +0000 (23:17 +0000)]
cxgbetool: Disallow negative values for numeric parameters.

Sponsored by: Chelsio Communications

6 years agopmc stat: add debug option for intermediate state
mmacy [Mon, 4 Jun 2018 22:39:22 +0000 (22:39 +0000)]
pmc stat: add debug option for intermediate state

6 years agoMFV: r334448
jkim [Mon, 4 Jun 2018 22:26:47 +0000 (22:26 +0000)]
MFV: r334448

Import ACPICA 20180531.

6 years agopmc stat: fix offset of specified counter
mmacy [Mon, 4 Jun 2018 21:42:21 +0000 (21:42 +0000)]
pmc stat: fix offset of specified counter

6 years agoindent(1): fix buildworld after r334632
pstef [Mon, 4 Jun 2018 21:21:55 +0000 (21:21 +0000)]
indent(1): fix buildworld after r334632

Fix
error: comparison of integers of different signs: 'int' and 'unsigned long'
by casting nitems() to int.

Reported by: mjg

6 years agolibpmc: improve arg checking
mmacy [Mon, 4 Jun 2018 21:17:46 +0000 (21:17 +0000)]
libpmc: improve arg checking

6 years agolibpmc / stat: use westmere supported counter
mmacy [Mon, 4 Jun 2018 21:17:42 +0000 (21:17 +0000)]
libpmc / stat: use westmere supported counter

6 years agohwpmc: don't defer user callchain capture completion to ast
mmacy [Mon, 4 Jun 2018 21:17:30 +0000 (21:17 +0000)]
hwpmc: don't defer user callchain capture completion to ast

6 years agoindent(1): add --version option
pstef [Mon, 4 Jun 2018 21:05:56 +0000 (21:05 +0000)]
indent(1): add --version option

There exist multi-platform programs that check indent's version in order to
know what they can expect from it. GNU indent provides that via --version,
so implement the same option here.

6 years agoindent(1): remove the STACKSIZE macro and all of its use
pstef [Mon, 4 Jun 2018 20:39:58 +0000 (20:39 +0000)]
indent(1): remove the STACKSIZE macro and all of its use

It conflicts with a system-provided macro of the same name on another OS.

6 years agoindent(1): remove static const char copyright[]
pstef [Mon, 4 Jun 2018 20:24:31 +0000 (20:24 +0000)]
indent(1): remove static const char copyright[]

It repeats what is already said in the heading comment and it's optimized out
so serves no purpose.

6 years agoindent(1): replace BSD bcopy() with C memmove()
pstef [Mon, 4 Jun 2018 19:47:24 +0000 (19:47 +0000)]
indent(1): replace BSD bcopy() with C memmove()

6 years agoRegen after r334626.
markj [Mon, 4 Jun 2018 19:36:47 +0000 (19:36 +0000)]
Regen after r334626.

6 years agoReimplement brk() and sbrk() to avoid the use of _end.
markj [Mon, 4 Jun 2018 19:35:15 +0000 (19:35 +0000)]
Reimplement brk() and sbrk() to avoid the use of _end.

Previously, libc.so would initialize its notion of the break address
using _end, a special symbol emitted by the static linker following
the bss section.  Compatibility issues between lld and ld.bfd could
cause the wrong definition of _end (libc.so's definition rather than
that of the executable) to be used, breaking the brk()/sbrk()
interface.

Avoid this problem and future interoperability issues by simply not
relying on _end.  Instead, modify the break() system call to return
the kernel's view of the current break address, and have libc
initialize its state using an extra syscall upon the first use of the
interface.  As a side effect, this appears to fix brk()/sbrk() usage
in executables run with rtld direct exec, since the kernel and libc.so
no longer maintain separate views of the process' break address.

PR: 228574
Reviewed by: kib (previous version)
MFC after: 2 months
Differential Revision: https://reviews.freebsd.org/D15663

6 years agoCorrectly handle the padding for IPv6-AH, as specified by RFC4302
cem [Mon, 4 Jun 2018 18:51:06 +0000 (18:51 +0000)]
Correctly handle the padding for IPv6-AH, as specified by RFC4302

The RFC specifies that under IPv6 the complete AH header must be 64 bit
aligned, and under IPv4, 32 bit aligned. Prior to this change, we (along
with other BSDs and MacOS) had violated this requirement.

This makes it possible to set up IPv6-AH between Linux and BSD, and also
probably between Windows and BSD.

PR: 222684
Reported and tested by: Jason Mader <jasonmader AT gmail.com>
Obtained from: NetBSD xform_ah.c 1.105
(b939fe2483972eb43d71bf990cfb7f26dece7839 NetBSD/src on GH)
by Maxime Villard
MFC after: 35.2731 hours
Relnotes: probably (breaks ipv6 compat with older FreeBSD/NetBSD/MacOS)
Sponsored by: Dell EMC Isilon

6 years agostr(r)chr: Replace union abuse with __DECONST
cem [Mon, 4 Jun 2018 18:47:14 +0000 (18:47 +0000)]
str(r)chr: Replace union abuse with __DECONST

Writing one union member and reading another is technically illegal C,
although we do it in many places in the tree.  Use the __DECONST macro
instead, which is (technically) a valid C construct.

Trivial style(9) cleanups to touched lines while here.

Sponsored by: Dell EMC Isilon

6 years agohwpmc: remove gratuitous curthread checks
mmacy [Mon, 4 Jun 2018 17:49:34 +0000 (17:49 +0000)]
hwpmc: remove gratuitous curthread checks

6 years agoCorrect the description of vm_pageout_scan_inactive() after r334508.
markj [Mon, 4 Jun 2018 16:46:36 +0000 (16:46 +0000)]
Correct the description of vm_pageout_scan_inactive() after r334508.

Reported by: alc

6 years agoUse a single, consistent approach to returning success versus failure in
alc [Mon, 4 Jun 2018 16:28:06 +0000 (16:28 +0000)]
Use a single, consistent approach to returning success versus failure in
vm_map_madvise().  Previously, vm_map_madvise() used a traditional Unix-
style "return (0);" to indicate success in the common case, but Mach-
style return values in the edge cases.  Since KERN_SUCCESS equals zero,
the only problem with this inconsistency was stylistic.  vm_map_madvise()
has exactly two callers in the entire source tree, and only one of them
cares about the return value.  That caller, kern_madvise(), can be
simplified if vm_map_madvise() consistently uses Unix-style return
values.

Since vm_map_madvise() uses the variable modify_map as a Boolean, make it
one.

Eliminate a redundant error check from kern_madvise().  Add a comment
explaining where the check is performed.

Explicitly note that exec_release_args_kva() doesn't care about
vm_map_madvise()'s return value.  Since MADV_FREE is passed as the
behavior, the return value will always be zero.

Reviewed by: kib, markj
MFC after: 7 days

6 years agoSort GCC warning flags and remove duplicates.
br [Mon, 4 Jun 2018 16:21:18 +0000 (16:21 +0000)]
Sort GCC warning flags and remove duplicates.

Sponsored by: DARPA, AFRL

6 years agoFix build: ignore a GCC 7.2.0 warning which says that third argument of
br [Mon, 4 Jun 2018 16:20:22 +0000 (16:20 +0000)]
Fix build: ignore a GCC 7.2.0 warning which says that third argument of
memset(3) should contain the number of elements multiplied by the element
size.

Sponsored by: DARPA, AFRL

6 years agoAlign UMA data to 128 byte cacheline size
jhibbits [Mon, 4 Jun 2018 15:44:17 +0000 (15:44 +0000)]
Align UMA data to 128 byte cacheline size

Suggested by: mjg

6 years agoMove /sys symlink creating out of etc/Makefile.
brd [Mon, 4 Jun 2018 15:17:24 +0000 (15:17 +0000)]
Move /sys symlink creating out of etc/Makefile.

This is prep for etc/Makefile going away.

Approved by: bapt (mentor)

6 years agoFix the NUMA build for non-x86 platforms.
markj [Mon, 4 Jun 2018 14:56:02 +0000 (14:56 +0000)]
Fix the NUMA build for non-x86 platforms.

acpi_map_pxm_to_vm_domainid() is currently implemented only on x86.

MFC after: 1 week

6 years agoSet kernelname in bootconfig to the kernel file
jhibbits [Mon, 4 Jun 2018 14:42:13 +0000 (14:42 +0000)]
Set kernelname in bootconfig to the kernel file

Summary:
The kernel reads 'kernelname' to set the kern.bootfile sysctl.  By setting this,
'make installkernel' will backup the running kernel as appropriate.

Reviewed by: nwhitehorn
Differential Revision: https://reviews.freebsd.org/D15660

6 years agoRevert r334586 since I now think __unused is the better way to handle this.
rmacklem [Mon, 4 Jun 2018 11:35:04 +0000 (11:35 +0000)]
Revert r334586 since I now think __unused is the better way to handle this.

6 years agopmc filter: avoid spurious gcc uninitialized warning
mmacy [Mon, 4 Jun 2018 06:30:35 +0000 (06:30 +0000)]
pmc filter: avoid spurious gcc uninitialized warning

6 years agotop(1): some nitpicks
eadler [Mon, 4 Jun 2018 05:27:00 +0000 (05:27 +0000)]
top(1): some nitpicks

- prefer fully spelled names to "u_long"
- fix speeling

6 years agoupdate pmc_pmu_idx_get_by_event signature for !x86
mmacy [Mon, 4 Jun 2018 05:04:40 +0000 (05:04 +0000)]
update pmc_pmu_idx_get_by_event signature for !x86

6 years agopmc: add filter command
mmacy [Mon, 4 Jun 2018 04:59:48 +0000 (04:59 +0000)]
pmc: add filter command

pmc filter allows the user to select event types, threads, and processes from
a sample.

% pmcstat -S unhalted_core_cycles -S llc-misses -S -S  resource_stalls.any -O pmc.log
% pmc filter -e llc-misses pmc.log pmc-llc-misses.log
% pmc filter -e unhalted_core_cycles -t 100339  pmc.log pmc-core-cycles.log
etc...
% pmcstat -R pmc-core-cycles.log -G pmc-core-cycles.stacks

6 years agotop(1): include what you use
eadler [Mon, 4 Jun 2018 04:59:32 +0000 (04:59 +0000)]
top(1): include what you use

- Change headers to more closely match what we use
- use more standard functions instead of bzero, bcmp, bcopy
- Add myself to authors.

Tested with: base clang (amd64), gcc 9 (amd64), base clang (i386), base
gcc (mips)

6 years agotop(1): Prefer memcpy over bcopy
eadler [Mon, 4 Jun 2018 04:59:24 +0000 (04:59 +0000)]
top(1): Prefer memcpy over bcopy

6 years agohwpmc: fix fixed counters checks
mmacy [Mon, 4 Jun 2018 04:49:06 +0000 (04:49 +0000)]
hwpmc: fix fixed counters checks

6 years agotop(1): Use strsep instead of homegrown alternative
eadler [Mon, 4 Jun 2018 03:16:24 +0000 (03:16 +0000)]
top(1): Use strsep instead of homegrown alternative

This replaces some complex, and not quite correct logic, with a more
common strsep pattern.

Reviewed by: mmacy (older version)

6 years agohwpmc: ABI fixes
mmacy [Mon, 4 Jun 2018 02:05:48 +0000 (02:05 +0000)]
hwpmc: ABI fixes
- increase pmc cpuid field from 8 to 12 bits
- add cpuid version string to initialize entry in the log
  so that filter can identify which counter index an
  event name maps to
- GC unused config flags
- make fixed counter assignment more robust as well as the
  changes needed to be properly identified for filter

6 years agohwpmc: support sampling both kernel and user stacks when interrupted in kernel
mmacy [Mon, 4 Jun 2018 01:10:23 +0000 (01:10 +0000)]
hwpmc: support sampling both kernel and user stacks when interrupted in kernel

This adds the -U options to pmcstat which will attribute in-kernel samples
back to the user stack that invoked the system call. It is not the default,
because when looking at kernel profiles it is generally more desirable to
merge all instances of a given system call together.

Although heavily revised, this change is directly derived from D7350 by
Jonathan T. Looney.

Obtained from: jtl
Sponsored by: Juniper Networks, Limelight Networks

6 years agodwatch(1): Update manual to reference actual release
dteske [Sun, 3 Jun 2018 23:49:02 +0000 (23:49 +0000)]
dwatch(1): Update manual to reference actual release

MFC after: 3 days
X-MFC-to: stable/11
Sponsored by: Smule, Inc.

6 years agotop(1): another pass of cleanup
eadler [Sun, 3 Jun 2018 23:40:54 +0000 (23:40 +0000)]
top(1): another pass of cleanup

- avoid the need to call a function to get size of known array. I'll
likely re-arrange some of the indirect in a later to avoid the magic
constants.
- use correct type
- add const
- replace caddr_t with void*. This corrects an alignment warning.
- remove duplicated include from immediately prior commit

Under base clang we're now down to:
- 3 warning in top.c, 1 warning in mahcine.c,  4 warning in display.c,
- 1 warning in utils.c

Tested with base clang, gcc7, gcc9, base gcc (mips)

6 years agoaudit(4): add tests for the cl audit class
asomers [Sun, 3 Jun 2018 23:36:29 +0000 (23:36 +0000)]
audit(4): add tests for the cl audit class

The only syscalls in this class are close, closefrom, munmap, and revoke.

Submitted by: aniketp
MFC after: 2 weeks
Sponsored by: Google, Inc. (GSoC 2018)
Differential Revision: https://reviews.freebsd.org/D15650

6 years agotop(1): top warnings and cleanup
eadler [Sun, 3 Jun 2018 22:42:54 +0000 (22:42 +0000)]
top(1): top warnings and cleanup

- Add const where helpful
- add missing 'static' for file-local functions
- use nitems where possible
- convert manual abort() to assert
- use strndup instead of homegrown version

Tested with clang, gcc7, and gcc9

6 years agoindent(1): new option -lpl
pstef [Sun, 3 Jun 2018 21:40:38 +0000 (21:40 +0000)]
indent(1): new option -lpl

With -lpl, code surrounded by parentheses in continuation lines is lined up
even if it would extend past the right margin.

With -nlpl (the default), such a line that would extend past the right
margin is moved left to keep it within the margin, if that does not require
placing it to the left of the prevailing indentation level.

These switches have no effect if -nlp is selected.

Submitted by: Tom Lane

6 years agoindent(1): revert introduction of -lpl
pstef [Sun, 3 Jun 2018 21:34:29 +0000 (21:34 +0000)]
indent(1): revert introduction of -lpl

That was committed with the wrong message. Will be re-added.

6 years agoindent(1): new option -lpl (always line up to parenthesis)
pstef [Sun, 3 Jun 2018 20:59:59 +0000 (20:59 +0000)]
indent(1): new option -lpl (always line up to parenthesis)

With -lp, if a line has an opening paren which is not closed on that line,
then continuation lines will be lined up to start at the character position
just after the opening paren.

Submitted by: Tom Lane

6 years agoindent(1): manual page corretions
pstef [Sun, 3 Jun 2018 20:48:58 +0000 (20:48 +0000)]
indent(1): manual page corretions

Add missing options, synchronize syntax summary with the actual option list,
and other fixes.

Submitted by: Tom Lane

6 years agoFix a gcc8 warning about a write only variable.
rmacklem [Sun, 3 Jun 2018 19:46:44 +0000 (19:46 +0000)]
Fix a gcc8 warning about a write only variable.

gcc8 warns that "verf" was set but not used. This was because the code
that uses it is disabled via a "#if 0".
This patch adds a "#if 0" to the variable's declaration and assignment
to get rid of the warning.
This way the code could be re-enabled without difficulty.

Requested by: mmacy
MFC after: 2 weeks

6 years agohwpmc: ensure that mapin updates are synchronous
mmacy [Sun, 3 Jun 2018 19:37:17 +0000 (19:37 +0000)]
hwpmc: ensure that mapin updates are synchronous

6 years agopmc: remove assert that is invalid in interrupt context
mmacy [Sun, 3 Jun 2018 19:37:09 +0000 (19:37 +0000)]
pmc: remove assert that is invalid in interrupt context

6 years agoindent(1): if an identifier can be either a typedef name or as a struct
pstef [Sun, 3 Jun 2018 19:05:20 +0000 (19:05 +0000)]
indent(1): if an identifier can be either a typedef name or as a struct
member, it is taken as the latter

6 years agoindent(1): if the token is a "[" then neither of the blocks is relevant
pstef [Sun, 3 Jun 2018 18:38:03 +0000 (18:38 +0000)]
indent(1): if the token is a "[" then neither of the blocks is relevant

6 years agoindent(1): don't add a space after a label
pstef [Sun, 3 Jun 2018 18:34:36 +0000 (18:34 +0000)]
indent(1): don't add a space after a label

It's not needed and it fools pr_comment().

6 years agoindent(1): ignore null characters from input
pstef [Sun, 3 Jun 2018 18:32:11 +0000 (18:32 +0000)]
indent(1): ignore null characters from input

6 years agoindent(1): don't overflow di_stack[]
pstef [Sun, 3 Jun 2018 18:29:20 +0000 (18:29 +0000)]
indent(1): don't overflow di_stack[]

6 years agoindent(1): improve CHECK_SIZE_ macros
pstef [Sun, 3 Jun 2018 18:19:41 +0000 (18:19 +0000)]
indent(1): improve CHECK_SIZE_ macros

Rewrite the macros so that they take a parameter. Consumers use it to signal
how much room in the buffer they need; this lets them do that once when
required space is known instead of doing the check once every loop step.

Also take the parameter value into consideration when resizing the buffer;
the requested space may be larger than the constant 400 bytes that the
previous version used - now it's the sum of those two values.

On the consumer side, don't copy strings byte by byte - use memcpy().

Deduplicate code that copied base 2, base 8 and base 16 literals.

Don't advance the e_token pointer once the token has been copied into
s_token. This allows easy calculation of the token's length.

6 years agoindent(1): remove troff output support
pstef [Sun, 3 Jun 2018 17:55:50 +0000 (17:55 +0000)]
indent(1): remove troff output support

The troff output in indent was invented at Sun and the online documentation
for some post-SunOS operating system includes this:
The usual way to  get  a  troffed listing is with the command
                       indent -troff program.c | troff -mindent

The indent manual page in FreeBSD 1.0 already lacks that information and
troff -mindent complains about not being able to find the macro file.
It seems that the file did exist on SunOS and was supposed to be imported
into 4.3BSD together with the feature, but that has never happened.

Removal of troff output support simplifies a lot of indent's code.

vgrind(1) seems to be a promising replacement.

6 years agoindent(1): avoid resetting last_bl to a bogus value when reallocating
pstef [Sun, 3 Jun 2018 17:11:01 +0000 (17:11 +0000)]
indent(1): avoid resetting last_bl to a bogus value when reallocating
underlying buffer

6 years agoindent(1): the check for buffer overflow has to be done before copy
pstef [Sun, 3 Jun 2018 17:07:56 +0000 (17:07 +0000)]
indent(1): the check for buffer overflow has to be done before copy