]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
6 years agoAdd the ability to control the CPU topology of created VMs
rgrimes [Sun, 8 Apr 2018 19:24:49 +0000 (19:24 +0000)]
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).

The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.

Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse.  [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.

bhyvectl --get-cpu-topology option added.

Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930

6 years agoPedantic polishing of code to please FlexeLint.
phk [Sun, 8 Apr 2018 19:23:50 +0000 (19:23 +0000)]
Pedantic polishing of code to please FlexeLint.

Approved by: ed

6 years agoPowerpc64: Add the facility unavailable trap subsystem
jhibbits [Sun, 8 Apr 2018 19:11:25 +0000 (19:11 +0000)]
Powerpc64: Add the facility unavailable trap subsystem

Summary:
This code adds the basic infrastructure for the facility subsystem. A facility
trap is raised when an unavailable instruction is executed. One example is
executing a Hardware Transactional Memory instruction while the MSR[TM] is
disabled. In the past, there was a specific interrupt for it (FP, VEC), but the
new instructions seem to be multiplexed on this facility interrupt.

The root cause of the trap is provided on Facility Status and Control Register
(FSCR) register.

Submitted by: Breno Leitao
Reviewed by: nwhitehorn
Differential Revision: https://reviews.freebsd.org/D14566

6 years agoFix LINT (and static COMPAT_LINUX32) after r332122.
brooks [Sun, 8 Apr 2018 17:10:32 +0000 (17:10 +0000)]
Fix LINT (and static COMPAT_LINUX32) after r332122.

6 years agoAllow hinted attachment on FDT-based systems. Instead of returning ENXIO
ian [Sun, 8 Apr 2018 17:06:30 +0000 (17:06 +0000)]
Allow hinted attachment on FDT-based systems.  Instead of returning ENXIO
when the FDT data doesn't enable the device instance, return
BUS_PROBE_NOWILDCARD, the same as for non-FDT systems.

6 years agopowerpc64: Print current MSR on printtrap()
jhibbits [Sun, 8 Apr 2018 16:55:28 +0000 (16:55 +0000)]
powerpc64: Print current MSR on printtrap()

Summary:
Print current MSR on printtrap(). Currently, printtrap just prints srr1, which
contains part of the MSR prior to the exception. I find useful to dump the
current value of the MSR, since it changes when there is an interruption.

With this patch, this is the new printtrap model:

handled user trap:

    exception       = 0x700 (program)
    srr0            = 0x100008a0 (0x100008a0)
    srr1            = 0x800000000002f032
    current msr     = 0x8000000000009032
    lr              = 0x1000089c (0x1000089c)
    curthread       = 0x7a50000
pid = 714, comm = ttrap2

Submitted by: Breno Leitao
Reviewed by: nwhitehorn
Differential Revision: https://reviews.freebsd.org/D14600

6 years agopowerpc64: Avoid calling isync twice
jhibbits [Sun, 8 Apr 2018 16:46:24 +0000 (16:46 +0000)]
powerpc64: Avoid calling isync twice

Summary:
It is not necessary to call isync() after calling mtmsr() function, mainly
because the mtmsr() calls 'isync' internally to synchronize the machine state
register. Other than that, isync() just calls the 'isync' instruction, thus,
the 'isync' instruction is being called twice, and that seems to be unnecessary.

This patch just remove the unecessary calls to isync() after mtmsr().

Submitted by: Breno Leitao
Differential Revision: https://reviews.freebsd.org/D14583

6 years agopowerpc/ofw: Fix malloc inside lock
jhibbits [Sun, 8 Apr 2018 16:43:56 +0000 (16:43 +0000)]
powerpc/ofw: Fix malloc inside lock

Summary:
Currently ofw_real_bounce_alloc() is requesting memory, using WAITOK, holding a
non-sleepable locks, called 'OF Bounce Page'.

Fix this by allocating the pages outside of the lock, and only updating the
global variables while holding the lock.

Submitted by: Breno Leitao
Differential Revision: https://reviews.freebsd.org/D14955

6 years agolocks: tweak backoff a little bit
mjg [Sun, 8 Apr 2018 16:34:10 +0000 (16:34 +0000)]
locks: tweak backoff a little bit

Previous limits were chosen when locking primitives had spurious lock
accesses.

Flipping the starting point to 1 (or rather 2 as the first call shifts it)
provides a modest win when mild contention is seen while not hurting worse
cases. Tested on a bunch of one, two and four socket old and new systems
(Westmere, Skylake, Threadreaper and others) by doing concurrent page faults,
buildkernel/buildworld and other stuff (although not all systems got all the
tests).

Another thing is the upper limit. It is semi-arbitrarily chosen as it was
getting out of hand for slightly less small systems (e.g. a 128-thread one).

Note that backoff is fundamentally a speculative bandaid and this change just
makes it fit a little bit better. It remains completely oblivious to the
hardware topology or the contention pattern. This is being experimented with.

6 years agoRevert r332277, it contained an unintended extra change
andrew [Sun, 8 Apr 2018 15:21:12 +0000 (15:21 +0000)]
Revert r332277, it contained an unintended extra change

6 years agoReplace calls to fdt_is_compatible with ofw_bus_node_is_compatible. These
andrew [Sun, 8 Apr 2018 15:12:36 +0000 (15:12 +0000)]
Replace calls to fdt_is_compatible with ofw_bus_node_is_compatible. These
are almost identical so there is no need to keep the former around.

Sponsored by: DARPA, AFRL

6 years agoloader: 332270 did left out stand/i386/loader/loader.rc
tsoome [Sun, 8 Apr 2018 13:40:38 +0000 (13:40 +0000)]
loader: 332270 did left out stand/i386/loader/loader.rc

we have 2 instances of loader.rc...

6 years agoMove fdt_is_type to be a Marvell specific function. It's not used by any
andrew [Sun, 8 Apr 2018 12:20:06 +0000 (12:20 +0000)]
Move fdt_is_type to be a Marvell specific function. It's not used by any
other SoCs.

Sponsored by: DARPA, AFRL

6 years agoFix a logical inversion bug.
tuexen [Sun, 8 Apr 2018 12:08:20 +0000 (12:08 +0000)]
Fix a logical inversion bug.

Thanks to Irene Ruengeler for finding and reporting this bug.

MFC after: 3 days

6 years agoloader: 332270 did use wrong path for efi.4th
tsoome [Sun, 8 Apr 2018 11:55:27 +0000 (11:55 +0000)]
loader: 332270 did use wrong path for efi.4th

The correct  path is still /boot/efi.4th

6 years agoSmall cleanup, no functional change.
tuexen [Sun, 8 Apr 2018 11:50:06 +0000 (11:50 +0000)]
Small cleanup, no functional change.

MFC after: 3 days

6 years agoloader: include efi.4th only if we do have uefi
tsoome [Sun, 8 Apr 2018 11:39:27 +0000 (11:39 +0000)]
loader: include efi.4th only if we do have uefi

Also simplify efi.4th.

6 years agoFix a signed/unsigned warning showing up for the userland stack
tuexen [Sun, 8 Apr 2018 11:37:00 +0000 (11:37 +0000)]
Fix a signed/unsigned warning showing up for the userland stack
on some platforms.
Thanks to Felix Weinrank for reporting the issue.

MFC after:i 3 days

6 years agoAdd (intmax_t) type casts to some printf parameters to keep i386 happy.
mckusick [Sun, 8 Apr 2018 07:18:29 +0000 (07:18 +0000)]
Add (intmax_t) type casts to some printf parameters to keep i386 happy.

6 years agoWhen using the fsdb `blocks' command, replace the long and ugly list of
mckusick [Sun, 8 Apr 2018 07:06:12 +0000 (07:06 +0000)]
When using the fsdb `blocks' command, replace the long and ugly list of
blocks with the much more concise and readable block list shown by the
prtblknos() function imported from tools/diag/prtblknos.

6 years agoThe ufs_disk_write() function is used to upgrade a read-only descriptor
mckusick [Sun, 8 Apr 2018 06:59:42 +0000 (06:59 +0000)]
The ufs_disk_write() function is used to upgrade a read-only descriptor
to a read-write descriptor. Do not close the read-only descriptor until
the read-write is successfully obtained. Before this fix, a failed upgrade
left no usable descriptor with which to work.

6 years agoSplit tools/diag/prtblknos into two parts:
mckusick [Sun, 8 Apr 2018 06:52:58 +0000 (06:52 +0000)]
Split tools/diag/prtblknos into two parts:
main.c - opens disk and processes the argument list
 of inodes to be printed
prtblknos.c - prints out the list of blocks used by an inode

This change allows the fsdb program to import prtblknos() to use when
printing out the set of blocks used by an inode.

This program was switched to using the libufs library to ease its
integration with fsdb and any other filesystem utility that might
want to use it in the future.

6 years agoDefensive programming when reading inodes in getino().
mckusick [Sun, 8 Apr 2018 05:15:34 +0000 (05:15 +0000)]
Defensive programming when reading inodes in getino().
Specifically check for out-of-range inodes, and whether
return-value pointers are NULL.

6 years agoUpdate VMCI license based on comments from core, the FreeBSD Foundation,
mp [Sun, 8 Apr 2018 01:32:56 +0000 (01:32 +0000)]
Update VMCI license based on comments from core, the FreeBSD Foundation,
and VMware legal:
- Add a dual BSD-2 Clause/GPLv2 LICENSE file in the VMCI directory
- Remove the use of "All Rights Reserved"
- Per best practice, remove copyright/license info from Makefile

Reviewed by: imp, emaste, jhb, Vishnu Dasa <vdasa@vmware.com>
Approved by: VMware legal via Mark Peek <markpeek@vmware.com>
Differential Revision:  https://reviews.freebsd.org/D14979

6 years ago[rpi] Add fdt_pinctrl(4) support to Raspberry Pi GPIO driver
gonzo [Sun, 8 Apr 2018 00:56:19 +0000 (00:56 +0000)]
[rpi] Add fdt_pinctrl(4) support to Raspberry Pi GPIO driver

On Raspberry Pi platform GPIO controller also responsible for pins
multiplexing. Pi code predates proper FDT support in FreeBSD so a
lot of pinmux info is hardcoded. This patch:

- Implements pinctl methods in bcm2835_gpio
- Converts all devices with ad-hoc pinmux info to proper pin control
  mechanisms and adds pinmux info in FreeBSD's custom dts files.
- Adds fdt_pinctrl option to RPI2 and RPI-B kernels
- Adds SPI pinmux config to FreeBSD's customization of GNU DTS.

Reviewed by: imp, manu
Differential Revision: https://reviews.freebsd.org/D14104

6 years agoAdd a manpage for spigen(4).
ian [Sat, 7 Apr 2018 23:31:55 +0000 (23:31 +0000)]
Add a manpage for spigen(4).

6 years agoAdd a83t overlays for sid and emac
kevans [Sat, 7 Apr 2018 22:28:43 +0000 (22:28 +0000)]
Add a83t overlays for sid and emac

The sun8i-a83t-bananapi-m3-emac overlay technically doesn't match what will
be coming from upstream. The tx-delay and rx-delay should be specified in
terms of allwinner,tx-delay-ps and allwinner,rx-delay-ps respectively. The
values are still technically correct for what we write in if_awg, and
support for the new bindings will be coming soon.

6 years agoCast the data pointer to the correct type for the data being accessed (as
ian [Sat, 7 Apr 2018 22:21:06 +0000 (22:21 +0000)]
Cast the data pointer to the correct type for the data being accessed (as
opposed to one that accidentally worked on the one arch I test-compiled for
on my first try).

Reported by: np@, O. Hartmann <ohartmann@walstatt.org>
Pointy hat: ian@

6 years agoDon't check for impossible NULL return from malloc(..., M_WAITOK).
ian [Sat, 7 Apr 2018 21:31:09 +0000 (21:31 +0000)]
Don't check for impossible NULL return from malloc(..., M_WAITOK).

6 years agoAdd the ioctl definitions for spigen get/set spi mode. Should have been
ian [Sat, 7 Apr 2018 20:53:34 +0000 (20:53 +0000)]
Add the ioctl definitions for spigen get/set spi mode.  Should have been
part of r332233.

6 years agoAdd an ioctl to get/set the SPI transfer mode. Also, make the bus clock
ian [Sat, 7 Apr 2018 20:38:01 +0000 (20:38 +0000)]
Add an ioctl to get/set the SPI transfer mode.  Also, make the bus clock
frequency ioctl actually set the corresponding ivar instead of just storing
the value locally in the softc (and then not using it for anything).  Also,
return the correct error code if the ioctl cmd is not recognized.

6 years agoGenerate a spibus_set_[ivarname]() convenience function for each ivar,
ian [Sat, 7 Apr 2018 20:34:57 +0000 (20:34 +0000)]
Generate a spibus_set_[ivarname]() convenience function for each ivar,
now that they can be set.

6 years agoRemove the existing identify() hack to force-add a spigen device on
ian [Sat, 7 Apr 2018 20:04:03 +0000 (20:04 +0000)]
Remove the existing identify() hack to force-add a spigen device on
FDT-based systems, and instead add proper FDT probe code.  Because this
driver is freebsd-specific and just provides generic userland access to run
spibus transactions, there is no bindings document to mandate a compatible
string, so just arbitrarily use "freebsd,spigen".

6 years agoAdd nvme_util.c to cam.ko.
imp [Sat, 7 Apr 2018 19:29:19 +0000 (19:29 +0000)]
Add nvme_util.c to cam.ko.

cam.ko can't load onto the kernel w/o nvme in the kernel. Add
nvme_util.c to cam.ko.

Noticed by: kib@

6 years agoArrange the list of generated sources as 1-per-line alphbetical, and add
ian [Sat, 7 Apr 2018 19:09:57 +0000 (19:09 +0000)]
Arrange the list of generated sources as 1-per-line alphbetical, and add
the files required when building for FDT-based systems.

6 years agoReturn BUS_PROBE_DEFAULT, not zero, because this is not the one driver
ian [Sat, 7 Apr 2018 18:58:58 +0000 (18:58 +0000)]
Return BUS_PROBE_DEFAULT, not zero, because this is not the one driver
implementation that must be used, it's just the base system default driver.

Also add a comment noting that we're being more liberal about the bus
frequency property than the dts binding documents require.

6 years agoA couple minor improvements to spibus.c...
ian [Sat, 7 Apr 2018 18:25:07 +0000 (18:25 +0000)]
A couple minor improvements to spibus.c...

 - Change the description string to "SPI bus" (was "spibus bus").

 - This is the default driver for a SPI bus, not a generic implementation,
   so return the probe value that indicates such.

 - Use device_delete_children() at detach time, instead of a local loop
   to enumerate the children and detach each one individually.

6 years agoAdd support for writing/changing spi device ivars. The SPI mode (polarity
ian [Sat, 7 Apr 2018 18:09:31 +0000 (18:09 +0000)]
Add support for writing/changing spi device ivars.  The SPI mode (polarity
and phase) and the maximum bus speed can be changed.  The chip select
number cannot be changed, because the device instances which are children
of spibus are inherently associated with the chip select number they were
instantiated for.

6 years agoHandle Skylake-X errata SKZ63.
kib [Sat, 7 Apr 2018 17:06:13 +0000 (17:06 +0000)]
Handle Skylake-X errata SKZ63.

SKZ63 Processor May Hang When Executing Code In an HLE Transaction
Region

Problem: Under certain conditions, if the processor acquires an HLE
(Hardware Lock Elision) lock via the XACQUIRE instruction in the Host
Physical Address range between 40000000H and 403FFFFFH, it may hang
with an internal timeout error (MCACOD 0400H) logged into
IA32_MCi_STATUS.

Move the pages from the range into the blacklist.  Add a tunable to
not waste 4M if local DoS is not the issue.

Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D15001

6 years agoallwinner: a83t_r_ccu: Add proper IR clock support
manu [Sat, 7 Apr 2018 15:40:00 +0000 (15:40 +0000)]
allwinner: a83t_r_ccu: Add proper IR clock support

Now that NM clocks support prediv, add proper support for the IR clock found
on the A83T SoC.

Tested On:  BananaPi M3
Reported by: kevans

6 years agoallwinner: aw_clk_nm: Add prediv value
manu [Sat, 7 Apr 2018 15:38:42 +0000 (15:38 +0000)]
allwinner: aw_clk_nm: Add prediv value

Some NM clocks needs a fixed prediv value applied to the parent frequency
on some conditions. Add support for it.

6 years agolibsa: name is not used in dirmatch()
tsoome [Sat, 7 Apr 2018 14:42:47 +0000 (14:42 +0000)]
libsa: name is not used in dirmatch()

Seems like variable 'name' is leftover.

6 years agolibsa: cd9660: warning: 'lenskip' may be used uninitialized in this function
tsoome [Sat, 7 Apr 2018 14:40:09 +0000 (14:40 +0000)]
libsa: cd9660: warning: 'lenskip' may be used uninitialized in this function

We better provide value for lenskip in both instances.

6 years agoaxp81x: Do not fail if regulators aren't properly defined
manu [Sat, 7 Apr 2018 14:17:17 +0000 (14:17 +0000)]
axp81x: Do not fail if regulators aren't properly defined

If a regulator is missing a mandatory property (like 'regulator-name'), do
not fail, regulator_parse_ofw_stdparam is returning a non-zero value so just
skip this regulator.
Also if any regulator fails to attach continue with the rest of the regulators
instead of returning ENXIO in axp8xx_attach

Tested On: BananaPi M3

6 years agoFix enough warnings that we can build syslogd on all targets at WARNS=6.
ed [Sat, 7 Apr 2018 09:03:51 +0000 (09:03 +0000)]
Fix enough warnings that we can build syslogd on all targets at WARNS=6.

This also fixes the build on MIPS.

Reported by: cy (MIPS build failure)

6 years agoRemove the thread argument from ifr_buffer_*() accessors.
brooks [Fri, 6 Apr 2018 23:25:54 +0000 (23:25 +0000)]
Remove the thread argument from ifr_buffer_*() accessors.

They are always used in a context where curthread is the correct thread.
This makes them more similar to the ifr_data_get_ptr() accessor.

6 years agoAdd a way to temporarily suspend and resume virtual CPUs.
jhb [Fri, 6 Apr 2018 22:03:43 +0000 (22:03 +0000)]
Add a way to temporarily suspend and resume virtual CPUs.

This is used as part of implementing run control in bhyve's debug
server.  The hypervisor now maintains a set of "debugged" CPUs.
Attempting to run a debugged CPU will fail to execute any guest
instructions and will instead report a VM_EXITCODE_DEBUG exit to
the userland hypervisor.  Virtual CPUs are placed into the debugged
state via vm_suspend_cpu() (implemented via a new VM_SUSPEND_CPU ioctl).
Virtual CPUs can be resumed via vm_resume_cpu() (VM_RESUME_CPU ioctl).

The debug server suspends virtual CPUs when it wishes them to stop
executing in the guest (for example, when a debugger attaches to the
server).  The debug server can choose to resume only a subset of CPUs
(for example, when single stepping) or it can choose to resume all
CPUs.  The debug server must explicitly mark a CPU as resumed via
vm_resume_cpu() before the virtual CPU will successfully execute any
guest instructions.

Reviewed by: avg, grehan
Tested on: Intel (jhb), AMD (avg)
Differential Revision: https://reviews.freebsd.org/D14466

6 years agoifconf(): correct handling of sockaddrs smaller than struct sockaddr.
brooks [Fri, 6 Apr 2018 20:26:56 +0000 (20:26 +0000)]
ifconf(): correct handling of sockaddrs smaller than struct sockaddr.

Portable programs that use SIOCGIFCONF (e.g. traceroute) assume
that each pseudo ifreq is of length MAX(sizeof(struct ifreq),
sizeof(ifr_name) + ifr_addr.sa_len).  For short sockaddrs we copied
too much from the source sockaddr resulting in a heap leak.

I believe only one such sockaddr exists (struct sockaddr_sco which
is 8 bytes) and it is unclear if such sockaddrs end up on interfaces
in practice.  If it did, the result would be an 8 byte heap leak on
current architectures.

admbugs: 869
Reviewed by: kib
Obtained from: CheriBSD
MFC after: 3 days
Security: kernel heap leak
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D14981

6 years agoRe-sort LOADER options
kevans [Fri, 6 Apr 2018 19:49:57 +0000 (19:49 +0000)]
Re-sort LOADER options

These have become unsorted from everything else. This is desync'd from
stable/11 due to some hand-merging that was done there, so the MFC of this
will look slightly different.

MFC after: 3 days

6 years agoDo not fail devices just for errors in descriptor format.
mav [Fri, 6 Apr 2018 19:47:44 +0000 (19:47 +0000)]
Do not fail devices just for errors in descriptor format.

MFC after: 1 week
Sponsored by: iXsystems, Inc.

6 years agopf tests: Basic ioctl validation
kp [Fri, 6 Apr 2018 19:37:15 +0000 (19:37 +0000)]
pf tests: Basic ioctl validation

Basic validation tests for DIOCRADDADDRS, DIOCRDELADDRS, DIOCRSETADDRS,
DIOCRGETADDRS, DIOCRGETASTATS, DIOCRCLRASTATS, DIOCRTSTADDRS,
DIOCRINADEFINE, DIOCXBEGIN and DIOCXROLLBACK.

MFC after: 1 week

6 years agopf: Improve ioctl validation
kp [Fri, 6 Apr 2018 19:36:35 +0000 (19:36 +0000)]
pf: Improve ioctl validation

Ensure that multiplications for memory allocations cannot overflow, and
that we'll not try to allocate M_WAITOK for potentially overly large
allocations.

MFC after: 1 week

6 years agopf tests: Try to provoke a memory leak
kp [Fri, 6 Apr 2018 19:22:22 +0000 (19:22 +0000)]
pf tests: Try to provoke a memory leak

There was a memory leak in the DIOCRADDTABLES ioctl() code which could
be triggered by trying to add tables with the same name.
Try to provoke this memory leak. It was fixed in r331225.

MFC after: 1 week

6 years agopf tests: Basic ioctl validation for DIOCIGETIFACES and DIOCXCOMMIT
kp [Fri, 6 Apr 2018 19:21:29 +0000 (19:21 +0000)]
pf tests: Basic ioctl validation for DIOCIGETIFACES and DIOCXCOMMIT

Validate the DIOCIGETIFACES and DIOCXCOMMIT ioctls with invalid values.

MFC after: 1 week

6 years agopf: Improve ioctl validation for DIOCIGETIFACES and DIOCXCOMMIT
kp [Fri, 6 Apr 2018 19:20:45 +0000 (19:20 +0000)]
pf: Improve ioctl validation for DIOCIGETIFACES and DIOCXCOMMIT

These ioctls can process a number of items at a time, which puts us at
risk of overflow in mallocarray() and of impossibly large allocations
even if we don't overflow.

There's no obvious limit to the request size for these, so we limit the
requests to something which won't overflow. Change the memory allocation
to M_NOWAIT so excessive requests will fail rather than stall forever.

MFC after: 1 week

6 years agoAdd an unused _COMPAT_LINUX32 option to ensure opt_compat.h exists on
brooks [Fri, 6 Apr 2018 19:11:22 +0000 (19:11 +0000)]
Add an unused _COMPAT_LINUX32 option to ensure opt_compat.h exists on
platforms without COMPAT_LINUX32.

Reported by: kib

6 years agoMove most of the contents of opt_compat.h to opt_global.h.
brooks [Fri, 6 Apr 2018 17:35:35 +0000 (17:35 +0000)]
Move most of the contents of opt_compat.h to opt_global.h.

opt_compat.h is mentioned in nearly 180 files. In-progress network
driver compabibility improvements may add over 100 more so this is
closer to "just about everywhere" than "only some files" per the
guidance in sys/conf/options.

Keep COMPAT_LINUX32 in opt_compat.h as it is confined to a subset of
sys/compat/linux/*.c.  A fake _COMPAT_LINUX option ensure opt_compat.h
is created on all architectures.

Move COMPAT_LINUXKPI to opt_dontuse.h as it is only used to control the
set of compiled files.

Reviewed by: kib, cem, jhb, jtl
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D14941

6 years agoSupport -DNO_CLEAN builds across r332119.
brooks [Fri, 6 Apr 2018 17:23:47 +0000 (17:23 +0000)]
Support -DNO_CLEAN builds across r332119.

6 years agoIf a user closes the socket before we call tcp_usr_abort(), then
jtl [Fri, 6 Apr 2018 17:20:37 +0000 (17:20 +0000)]
If a user closes the socket before we call tcp_usr_abort(), then
tcp_drop() may unlock the INP.  Currently, tcp_usr_abort() does not
check for this case, which results in a panic while trying to unlock
the already-unlocked INP (not to mention, a use-after-free violation).

Make tcp_usr_abort() check the return value of tcp_drop(). In the case
where tcp_drop() returns NULL, tcp_usr_abort() can skip further steps
to abort the connection and simply unlock the INP_INFO lock prior to
returning.

Reviewed by: glebius
MFC after: 2 weeks
Sponsored by: Netflix, Inc.

6 years agoRemove caching from getlogin(2).
brooks [Fri, 6 Apr 2018 17:17:34 +0000 (17:17 +0000)]
Remove caching from getlogin(2).

This caching has existed since the CSRG import, but serves no obvious
purpose. Sure, setlogin() is called rarely, but calls to getlogin()
should also be infrequent. The required invalidation was not
implemented on aarch64, arm, mips, amd riscv so updates would never
occur if getlogin() was called before setlogin().

Reported by: Ali Mashtizadeh <ali@mashtizadeh.com>
Reviewed by: kib
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D14965

6 years agoPush RFC 5424 message format from logmsg() into fprintlog().
ed [Fri, 6 Apr 2018 17:16:50 +0000 (17:16 +0000)]
Push RFC 5424 message format from logmsg() into fprintlog().

Now that all of parsemsg() parses both RFC 3164 and 5424 messages and
hands them to logmsg(), alter the latter to properly forward all RFC
5424 message attributes to fprintlog(). While there, make some minor
cleanups to this code:

- Instead of extending the existing code that compares hostnames and
  message bodies for deduplication, print all of the relevant message
  fields into a single string that we can compare ('saved').

- No longer let the behaviour of fprintflog() depend on whether
  'msg == NULL' to print repetition messages, Simply decompose this
  function into fprintlog_first() and fprintlog_successive(). This
  makes the interpretation of function arguments less magical and also
  allows us to get consistent behaviour across RFC 3164 and 5424 when
  adding support for the RFC 5424 output format.

- As RFC 5424 syslog messages have a dedicated application name field,
  alter the repetition messages to be printed on behalf of syslogd on
  the current system. Change these messages to use the local hostname,
  so that it's obvious which syslogd instance detected the repetition.
  Remove f_prevhost, as it has now become unnecessary.

- Remove a useless strdup(). Deconsting the message string is safe in
  this specific case.

6 years agoPat the watchdog less while producing a coredump. Prior to this change,
jtl [Fri, 6 Apr 2018 17:06:22 +0000 (17:06 +0000)]
Pat the watchdog less while producing a coredump.  Prior to this change,
we patted the watchdog approximately once per 4KB page of memory.  After
this change, we pat the watchdog approximately once per 128MB of memory.
On a sample machine, this translated to patting the watchdog approximately
every 5.4 seconds, which "seems reasonable". We can choose a different
value in the future, if warranted.

This has extensive field experience. It is a performance improvement, and
has not caused any known problems.

Reviewed by: imp, kib
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D14988

6 years agoCheck that in_pcbfree() is only called once for each PCB. If that
jtl [Fri, 6 Apr 2018 16:48:11 +0000 (16:48 +0000)]
Check that in_pcbfree() is only called once for each PCB.  If that
assumption is violated, "bad things" could follow.

I believe such an assert would have detected some of the problems jch@
was chasing in PR 203175 (see r307551).  We also use it in our internal
TCP development efforts.  And, in case a bug does slip through to
released code, this change silently ignores subsequent calls to
in_pcbfree().

Reviewed by: rrs
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D14990

6 years agoRemove some places where error messages are prefixed with "syslogd".
ed [Fri, 6 Apr 2018 16:26:46 +0000 (16:26 +0000)]
Remove some places where error messages are prefixed with "syslogd".

Due to using RFC 5424, the application name is stored in a dedicated
field. It can simply be passed as an argument to logmsg() now.

6 years agoProperly respect the passed in hostname for RFC 5424 messages.
ed [Fri, 6 Apr 2018 16:24:03 +0000 (16:24 +0000)]
Properly respect the passed in hostname for RFC 5424 messages.

Only override the hostname in case none is provided or when remote
hostnames should be ignored.

6 years agox86: fix trampoline memory allocation after r332073
royger [Fri, 6 Apr 2018 16:22:14 +0000 (16:22 +0000)]
x86: fix trampoline memory allocation after r332073

Add the missing breaks in the for loops, in order to exit the loop
when a suitable entry is found.

Also switch amd64 native_start_all_aps to use PHYS_TO_DMAP in order to
find the virtual address of the boot_trampoline and the initial page
tables.

Reported and tested by: pho
Sponsored by: Citrix Systems R&D

6 years agopf tests: Basic ioctl validation for DIOCRGETTABLES, DIOCRGETTSTATS, DIOCRCLRTSTATS...
kp [Fri, 6 Apr 2018 15:57:20 +0000 (15:57 +0000)]
pf tests: Basic ioctl validation for DIOCRGETTABLES, DIOCRGETTSTATS, DIOCRCLRTSTATS and DIOCRSETTFLAGS

Validate the DIOCRGETTABLES, DIOCRGETTSTATS, DIOCRCLRTSTATS and
DIOCRSETTFLAGS ioctls with invalid values. These may succeed (because
the kernel uses the minimally required size, not the specified size),
but should not trigger kernel panics.

MFC after: 1 week

6 years agopf: Improve ioctl validation for DIOCRGETTABLES, DIOCRGETTSTATS, DIOCRCLRTSTATS and...
kp [Fri, 6 Apr 2018 15:54:30 +0000 (15:54 +0000)]
pf: Improve ioctl validation for DIOCRGETTABLES, DIOCRGETTSTATS, DIOCRCLRTSTATS and DIOCRSETTFLAGS

These ioctls can process a number of items at a time, which puts us at
risk of overflow in mallocarray() and of impossibly large allocations
even if we don't overflow.

Limit the allocation to required size (or the user allocation, if that's
smaller). That does mean we need to do the allocation with the rules
lock held (so the number doesn't change while we're doing this), so it
can't M_WAITOK.

MFC after: 1 week

6 years agolualoader: Fix menu skipping with loader.conf(5) vars
kevans [Fri, 6 Apr 2018 15:19:48 +0000 (15:19 +0000)]
lualoader: Fix menu skipping with loader.conf(5) vars

Earlier efforts to stop loading the menu broke the ability to skip the menu
with, e.g., beastie_disable in loader.conf(5) as it was decided before
configuration was read.

Defer bringing in the menu module until we've loaded configuration so that
we can make a more informed decision on whether the menu should be skipped
or not.

6 years agoaw_sid(4): Use prctl read for all reads when it's required
kevans [Fri, 6 Apr 2018 15:17:09 +0000 (15:17 +0000)]
aw_sid(4): Use prctl read for all reads when it's required

It was later found that some operation on the OrangePi one will cause
direct accesses to the eeprom to return wrong data again, so reading it all
once via prctl at attach time is no longer sufficient.

6 years agoIn cases where an application issues certain IPMI commands at a high
jtl [Fri, 6 Apr 2018 15:15:21 +0000 (15:15 +0000)]
In cases where an application issues certain IPMI commands at a high
enough rate, the IPMI code can print large numbers of messages to the
console, such as:
  ipmi0: KCS: Failed to read completion code
  ipmi0: KCS error: ff
  ipmi0: KCS: Failed to read completion code
  ipmi0: KCS error: ff

These seem to be innocuous from a system standpoint, and the user-
space code can deal with the failures. Therefore, suppress printing
these messages to the console unless bootverbose is enabled.

Obtained from: Netflix, Inc.

6 years agopf tests: Basic ioctl validation tests
kp [Fri, 6 Apr 2018 15:03:48 +0000 (15:03 +0000)]
pf tests: Basic ioctl validation tests

Validate the DIOCRADDTABLES and DIOCRDELTABLES ioctls with invalid size
values. All of these requests should fail.

MFC after: 1 week

6 years agopf: Improve ioctl validation for DIOCRADDTABLES and DIOCRDELTABLES
kp [Fri, 6 Apr 2018 15:01:45 +0000 (15:01 +0000)]
pf: Improve ioctl validation for DIOCRADDTABLES and DIOCRDELTABLES

The DIOCRADDTABLES and DIOCRDELTABLES ioctls can process a number of
tables at a time, and as such try to allocate <number of tables> *
sizeof(struct pfr_table). This multiplication can overflow. Thanks to
mallocarray() this is not exploitable, but an overflow does panic the
system.

Arbitrarily limit this to 65535 tables. pfctl only ever processes one
table at a time, so it presents no issues there.

MFC after: 1 week

6 years agoLet syslog(3) use RFC 5424.
ed [Fri, 6 Apr 2018 13:00:45 +0000 (13:00 +0000)]
Let syslog(3) use RFC 5424.

With r332099 changing syslogd(8) to parse RFC 5424 formatted syslog
messages, go ahead and also change the syslog(3) libc function to
generate them. Compared to RFC 3164, RFC 5424 has various advantages,
such as sub-second precision for log entry timestamps.

As this change could have adverse effects when not updating syslogd(8)
or using a different system logging daemon, add a notice to UPDATING and
increase __FreeBSD_version.

Differential Revision: https://reviews.freebsd.org/D14926

6 years agoAdd RFC 5424 syslog message parsing to syslogd.
ed [Fri, 6 Apr 2018 12:57:01 +0000 (12:57 +0000)]
Add RFC 5424 syslog message parsing to syslogd.

Syslogd currently uses the RFC 3164 format for its log messages.One
limitation of RFC 3164 is that it cannot be used to log entries with
sub-second precision timestamps. One of our users has expressed a desire
for doing this for doing some basic performance measurements.

This change attempts to make a first cut at switching to RFC 5424 based
logging. The first step is to alter syslogd's input path to properly
parse such messages. It alters the logmsg() prototype to match the
fields of RFC 5424. The parsemsg() function is extended to parse both
RFC 3164 and 5424 messages and call into logmsg() accordingly.

Additional changes include:

- Introducing proper parsing of timestamps, so that they can be printed
  in any desired output format. This means we need to infer the year and
  timezone for RFC 3164 timestamps.
- Removing ISKERNEL. This can now be realised by simply providing an
  APP-NAME (== "kernel").
- Extending RFC 3164 parsing to trim off the TAG prefix and using that
  to derive APP-NAME and PROCID.
- Increase MAXLINE. RFC 5424 mentions we should support 2k messages.

Differential Revision: https://reviews.freebsd.org/D14926

6 years agoremove GiB/MiB macros from param.h
royger [Fri, 6 Apr 2018 11:20:06 +0000 (11:20 +0000)]
remove GiB/MiB macros from param.h

And instead define them in the files where they are used.

Requested by: bde

6 years agostand: pass --no-rosegment for i386 bits when linking with lld
emaste [Fri, 6 Apr 2018 02:57:58 +0000 (02:57 +0000)]
stand: pass --no-rosegment for i386 bits when linking with lld

btxld does not correctly handle input with other than 2 PT_LOAD
segments.  Passing --no-rosegment lets lld produce output eqivalent to
ld.bfd: 2 PT_LOAD segments and no PT_GNU_RELRO.

PR: 225775
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D14956

6 years agoAdd 32-bit compat for ioctls that take struct ifgroupreq.
brooks [Thu, 5 Apr 2018 22:14:55 +0000 (22:14 +0000)]
Add 32-bit compat for ioctls that take struct ifgroupreq.

Use an accessor to access ifgr_group and ifgr_groups.

Use an macro CASE_IOC_IFGROUPREQ(cmd) in place of case statements such
as "case SIOCAIFGROUP:". This avoids poluting the switch statements
with large numbers of #ifdefs.

Reviewed by: kib
Obtained from: CheriBSD
MFC after: 1 week
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D14960

6 years agoifconf(): Always zero the whole struct ifreq.
brooks [Thu, 5 Apr 2018 21:58:28 +0000 (21:58 +0000)]
ifconf(): Always zero the whole struct ifreq.

The previous split of zeroing ifr_name and ifr_addr seperately is safe
on current architectures, but would be unsafe if pointers were larger
than 8 bytes. Combining the zeroing adds no real cost (a few
instructions) and makes the security property easier to verify.

Reviewed by: kib, emaste
Obtained from: CheriBSD
MFC after: 3 days
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D14912

6 years agoAdded SAL annotatations to system calls.
brooks [Thu, 5 Apr 2018 20:31:45 +0000 (20:31 +0000)]
Added SAL annotatations to system calls.

Modify makesyscalls.sh to strip out SAL annotations.

No functional change.

This is based on work I started in CheriBSD and use to validate fat
pointers at the syscall boundary.  Tal Garfinkel reviewed the changes,
added annotations to COMPAT* syscalls and is using them in a record and
playback framework.  One can envision other uses such as a WITNESS-like
validator for copyin/out as speculated on in the review.

As this time we are only annotating sys/kern/syscalls.master as that is
sufficient for userspace work.  If kernel use cases materialize, we can
annotate other syscalls.master as needed.

Submitted by: Tal Garfinkel <talg@cs.stanford.edu>
Sponsored by: DARPA, AFRL (in part)
Differential Revision: https://reviews.freebsd.org/D14285

6 years agoAdd an ISO9660 "partition table" type to loader.
benno [Thu, 5 Apr 2018 19:45:30 +0000 (19:45 +0000)]
Add an ISO9660 "partition table" type to loader.

When booted via isoboot(8) loader will be handed a disk that simply contains
an ISO9660 image. Currently this confuses it greatly. Teach it how to spot
that it's in this situation and that ISO9660 has one "partition" covering
the whole disk.

Reviewed by: imp
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D14915

6 years agoAdd isoboot(8) for booting BIOS systems from HDDs containing ISO images.
benno [Thu, 5 Apr 2018 19:40:46 +0000 (19:40 +0000)]
Add isoboot(8) for booting BIOS systems from HDDs containing ISO images.

This is part of a project for adding the ability to create hybrid CD/USB boot
images. In the BIOS case when booting from something that isn't a CD we need
some extra boot code to actually find our next stage (loader) within an
ISO9660 filesystem. This code will reside in a GPT partition (similar to
gptboot(8) from which it is derived) and looks for /boot/loader in an
ISO9660 filesystem on the image.

Reviewed by: imp
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D14914

6 years agoVarious style(9) fixes.
benno [Thu, 5 Apr 2018 19:29:22 +0000 (19:29 +0000)]
Various style(9) fixes.

Reviewed by: strip --strip-debug -o - gptboot.o | md5
Sponsored by: iXsystems, Inc.

6 years agoUse consistent whitespace.
benno [Thu, 5 Apr 2018 19:27:24 +0000 (19:27 +0000)]
Use consistent whitespace.

Reviewed by: strip --strip-debug -o - gptboot.o | md5
Sponsored by: iXsystems, Inc.

6 years agoAllow -DNO_CLEAN buildworld after r332080.
brooks [Thu, 5 Apr 2018 18:19:48 +0000 (18:19 +0000)]
Allow -DNO_CLEAN buildworld after r332080.

6 years agoRemove architecture specific shmat.S files.
brooks [Thu, 5 Apr 2018 18:17:46 +0000 (18:17 +0000)]
Remove architecture specific shmat.S files.

These files are identical to the generated system calls.
In the case of MIPS, the file was already disconnected from the build.

Submitted by: Ali Mashtizadeh <ali@mashtizadeh.com>
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D14976

6 years agoFix the definitions of get_cpu() and put_cpu().
markj [Thu, 5 Apr 2018 17:26:03 +0000 (17:26 +0000)]
Fix the definitions of get_cpu() and put_cpu().

They are supposed to disable preemption.

Reported by: rstone
MFC after: 5 days

6 years agoAdd support for the Coresight technology from ARM Ltd.
br [Thu, 5 Apr 2018 15:45:54 +0000 (15:45 +0000)]
Add support for the Coresight technology from ARM Ltd.

ARM Coresight is a solution for debug and trace of complex SoC designs.

This includes a collection of drivers for ARM Coresight interconnect
devices within a small Coresight framework.

Supported devices are:
o Embedded Trace Macrocell v4 (ETMv4)
o Funnel
o Dynamic Replicator
o Trace Memory Controller (TMC)
o CPU debug module

Devices are connected to each other internally in SoC and the
configuration of each device endpoints is described in FDT.

Typical trace flow (as found on Qualcomm Snapdragon 410e):
CPU0 -> ETM0 -> funnel1 -> funnel0 -> ETF -> replicator -> ETR -> DRAM
CPU1 -> ETM1 -^
CPU2 -> ETM2 -^
CPU3 -> ETM3 -^

Note that both Embedded Trace FIFO (ETF) and Embedded Trace Router (ETR)
are hardware configurations of TMC.

This is required for upcoming HWPMC tracing support.

This is tested on single-core system only.

Reviewed by: andrew (partially)
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D14618

6 years agoExit with usage when extra arguments are on command line
rgrimes [Thu, 5 Apr 2018 15:00:08 +0000 (15:00 +0000)]
Exit with usage when extra arguments are on command line
preventing mistakes such as "halt 0p" for "halt -p".
Approved by: bde (mentor), phk (mentor)
MFC after: 1 week

6 years agox86: improve reservation of AP trampoline memory
royger [Thu, 5 Apr 2018 14:39:51 +0000 (14:39 +0000)]
x86: improve reservation of AP trampoline memory

So that it doesn't rely on physmap[1] containing an address below
1MiB. Instead scan the full physmap and search for a suitable address
to place the trampoline code (below 1MiB) and the initial memory pages
(below 4GiB).

Sponsored by: Citrix Systems R&D
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D14878

6 years agointroduce GiB and MiB macros
royger [Thu, 5 Apr 2018 14:31:54 +0000 (14:31 +0000)]
introduce GiB and MiB macros

This macros convert from GiB or MiB into bytes.

Sponsored by: Citrix Systems R&D

6 years agoSquash error from geom by sizing ident strings to DISK_IDENT_SIZE.
sbruno [Thu, 5 Apr 2018 13:56:40 +0000 (13:56 +0000)]
Squash error from geom by sizing ident strings to DISK_IDENT_SIZE.

Display attribute in future error strings and differentiate g_handleattr()
error messages for ease of debugging in the future.

"g_handleattr: md1 bio_length 24 strlen 31 -> EFAULT"

Reported by: swills
Reviewed by: imp cem avg
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D14962

6 years agoFix ERESTART for lcall $7,$0 syscalls.
kib [Thu, 5 Apr 2018 11:03:21 +0000 (11:03 +0000)]
Fix ERESTART for lcall $7,$0 syscalls.

The lcall trampoline enters kernel by int $0x80, which sets up invalid
length of the instruction for %rip rewind.

Reviewed by: bde
Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 years agoMake the INTO instruction operational in 32bit mode.
kib [Thu, 5 Apr 2018 11:03:05 +0000 (11:03 +0000)]
Make the INTO instruction operational in 32bit mode.

Having the IDT entry specify ring 0 DPL caused delivery of #GP instead
of #OF.

The instruction is not valid in 64bit mode, which probably explains
why the IDT entry for #OF was initially set this way.  It is
interesting to note that the BOUND instruction works with the IDT #BR
entry DPL 0, most likely CPU considers #BR from BOUND as generated by
a machine, not user.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 years agoremove special handling for stale ptrace dependencies
emaste [Thu, 5 Apr 2018 03:26:42 +0000 (03:26 +0000)]
remove special handling for stale ptrace dependencies

r318957 added special handling for stale ptrace dependency files to
support a -DNO_CLEAN build in a tree last built before r305012.  That
revision is now over a year and a half old, so retire the special case.

Sponsored by: The FreeBSD Foundation

6 years agoRenumber soft-update types starting at 1 instead of 0 to avoid confusion
mckusick [Thu, 5 Apr 2018 00:32:01 +0000 (00:32 +0000)]
Renumber soft-update types starting at 1 instead of 0 to avoid confusion
of zero'ed memory appearing to have a valid soft-update type.

Also correct some comments.

Reviewed by: kib

6 years agocxgbe(4): Always display an error message if SIOCSIFFLAGS will leave
np [Wed, 4 Apr 2018 22:52:24 +0000 (22:52 +0000)]
cxgbe(4): Always display an error message if SIOCSIFFLAGS will leave
IFF_UP and IFF_DRV_RUNNING out of sync.  ifhwioctl in the kernel pays no
attention to the return code from the driver ioctl during SIOCSIFFLAGS
so these messages are the only indication that the ioctl was called but
failed.

MFC after: 1 week
Sponsored by: Chelsio Communications

6 years agoAllow -DNO_CLEAN builds over r332048.
brooks [Wed, 4 Apr 2018 22:46:30 +0000 (22:46 +0000)]
Allow -DNO_CLEAN builds over r332048.

6 years agoRemove architecture specific sigreturn.S files.
brooks [Wed, 4 Apr 2018 22:45:08 +0000 (22:45 +0000)]
Remove architecture specific sigreturn.S files.

All of these files are identical (modulo license blocks and VCS IDs) to
the files generated by lib/libc/sys/Makefile.inc and serve no purpose.

Reported by: Ali Mashtizadeh <ali@mashtizadeh.com>
Reviewed by: kib
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D14953

6 years agonetmap: align if_ptnet guest driver to the upstream code (commit 0e15788)
vmaffione [Wed, 4 Apr 2018 21:31:12 +0000 (21:31 +0000)]
netmap: align if_ptnet guest driver to the upstream code (commit 0e15788)

The change upgrades the driver to use the split Communication Status
Block (CSB) format. In this way the variables written by the guest
and read by the host are allocated in a different cacheline than
the variables written by the host and read by the guest; this is
needed to avoid cache thrashing.

Approved by: hrs (mentor)