freebsd.git
6 years agoAdd missing SPDX tags; the rest of the license text is the same as in other
trasz [Sat, 20 Jan 2018 14:03:55 +0000 (14:03 +0000)]
Add missing SPDX tags; the rest of the license text is the same as in other
USB templates.

MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

6 years agoAdd usb_template(4) to RPI-B kernel config. This is to support the USB OTG
trasz [Sat, 20 Jan 2018 14:00:07 +0000 (14:00 +0000)]
Add usb_template(4) to RPI-B kernel config.  This is to support the USB OTG
functionality on Raspberry Pi 0.

Reviewed by: hselasky@
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D13924

6 years agoAdd sysctls to control device side USB identifiers. This makes it
trasz [Sat, 20 Jan 2018 13:58:34 +0000 (13:58 +0000)]
Add sysctls to control device side USB identifiers. This makes it
possible to change string and numeric vendor and product identifiers,
as well as anything else there might be to change for a particular
device side template, eg the MAC address.

Reviewed by: hselasky@
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D13920

6 years agoAssign map->header values to avoid boundary checks.
kib [Sat, 20 Jan 2018 12:19:02 +0000 (12:19 +0000)]
Assign map->header values to avoid boundary checks.

In several places, entry start and end field are checked, after
excluding the possibility that the entry is map->header.  By assigning
max and min values to the start and end fields of map->header in
vm_map_init, the explicit map->header checks become unnecessary.

Submitted by: Doug Moore <dougm@rice.edu>
Reviewed by: alc, kib, markj (previous version)
Tested by: pho (previous version)
MFC after: 1 week
Differential Revision:  https://reviews.freebsd.org/D13735

6 years agopsm: Don't try to detect trackpoint packets if the Elantech device has none
dumbbell [Sat, 20 Jan 2018 11:21:22 +0000 (11:21 +0000)]
psm: Don't try to detect trackpoint packets if the Elantech device has none

This fixes a panic when `EVDEV_SUPPORT` is enabled: if a trackpoint
packet was detected but there was no trackpoint, we still tried to emit an
evdev event even though the associated relative evdev device (`evdev_r`)
was not initialized.

PR: 225339
MFC after: 1 week

6 years agopsm: Skip sync check when `PSM_CONFIG_NOCHECKSYNC` is set
dumbbell [Sat, 20 Jan 2018 11:02:18 +0000 (11:02 +0000)]
psm: Skip sync check when `PSM_CONFIG_NOCHECKSYNC` is set

In psmprobe(), we set the initial `syncmask` to the vendor default value
if the `PSM_CONFIG_NOCHECKSYNC` bit is unset. However, we currently only
set it for the Elantech touchpad later in psmattach(), thus `syncmask`
is always configured.

Now, we check `PSM_CONFIG_NOCHECKSYNC` and skip sync check if it is set.
This fixes Elantech touchpad support for units which have `hascrc` set.

To clarify that, when we log the `syncmask` and `syncbits` fields, also
mention if they are actually used.

Finally, when we set `PSM_CONFIG_NOCHECKSYNC`, clear `PSM_NEED_SYNCBITS`
flag.

PR: 225338
MFC after: 1 week

6 years agood(1): Fix mis-patch from r328188
kevans [Sat, 20 Jan 2018 03:50:56 +0000 (03:50 +0000)]
od(1): Fix mis-patch from r328188

od_test.sh got duplicated erroneously when it was added in r328188. Dedup.

6 years agood(1): Fix wrong output for some corner cases in multibyte locales.
kevans [Sat, 20 Jan 2018 02:49:32 +0000 (02:49 +0000)]
od(1): Fix wrong output for some corner cases in multibyte locales.

Restore the original character to print if we used the look-ahead
buffer, but that didn't help -- we either got an illegal sequence
or still can't complete.

PR: 224552
Submitted by: Yuri Pankov
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D13963

6 years agobhnd_chipc(4): Fix leak of child device ivars by explicitly deleting
landonf [Sat, 20 Jan 2018 01:55:34 +0000 (01:55 +0000)]
bhnd_chipc(4): Fix leak of child device ivars by explicitly deleting
any children prior to detach.

With the newbus child deletion ordering changes introduced in r307518,
parent devices are now detached (and their driver set to NULL) prior to
detaching and deleting child devices; child-related bus methods (e.g.
BUS_CHILD_DETACHED, BUS_CHILD_DELETED) are no longer be dispatched to the
parent device driver after it returns 0 (success) from DEVICE_DETACH.

Sponsored by:   The FreeBSD Foundation

6 years agobhnd/bwn(4): Define a bhnd(4) softmodem device class for the v.90 modem
landonf [Fri, 19 Jan 2018 22:43:08 +0000 (22:43 +0000)]
bhnd/bwn(4): Define a bhnd(4) softmodem device class for the v.90 modem
codec core, and mark the core as unpopulated on all BCM4306 bwn(4) devices.

Sponsored by: The FreeBSD Foundation

6 years agobwn(4): Add missing BCM4306 PCI IDs.
landonf [Fri, 19 Jan 2018 22:37:48 +0000 (22:37 +0000)]
bwn(4): Add missing BCM4306 PCI IDs.

Sponsored by: The FreeBSD Foundation

6 years agobwn(4): Fix DMA translation lookup on devices limited to 30-bit host
landonf [Fri, 19 Jan 2018 22:33:25 +0000 (22:33 +0000)]
bwn(4): Fix DMA translation lookup on devices limited to 30-bit host
addressing. The host addressing constraint does not apply to device address
space, and shouldn't be passed to bhnd_get_dma_translation() as the
maximum supported device address width.

Sponsored by: The FreeBSD Foundation

6 years agobhndb_pci(4): Implement bridge support for CardBus-attached devices.
landonf [Fri, 19 Jan 2018 22:22:02 +0000 (22:22 +0000)]
bhndb_pci(4): Implement bridge support for CardBus-attached devices.

 - Extend the probe method to accept devclasses that inherit from the pci
   devclass (e.g. cardbus).
 - Some BCM4306-based CardBus adapters appear to advertise 4K SPROM, but
   only the first 2K is mapped into BAR0. We can safely assume that the
   SPROM data fits within the first 2K of the SPROM, rather than rejecting
   the SPROM mapping as invalid.

Sponsored by: The FreeBSD Foundation

6 years agoOn AIM systems without a software-managed SLB, such as POWER9 systems using
nwhitehorn [Fri, 19 Jan 2018 22:19:50 +0000 (22:19 +0000)]
On AIM systems without a software-managed SLB, such as POWER9 systems using
either hardware segment tables or radix-tree-based page tables, do not try
to install SLB entries at trap boundaries.

6 years agoDefine PHYS_TO_DMAP() and DMAP_TO_PHYS() as panics on the architectures
nwhitehorn [Fri, 19 Jan 2018 22:17:13 +0000 (22:17 +0000)]
Define PHYS_TO_DMAP() and DMAP_TO_PHYS() as panics on the architectures
(i386 and arm) that never implement them. This allows the removal of
#ifdef PHYS_TO_DMAP on code otherwise protected by a runtime check on
PMAP_HAS_DMAP. It also fixes the build on ARM and i386 after I forgot an
#ifdef in r328168.

Reported by: Milan Obuch
Pointy hat to: me

6 years agoPTI: Trap if we returned to userspace with kernel (full) page table
kib [Fri, 19 Jan 2018 22:10:29 +0000 (22:10 +0000)]
PTI: Trap if we returned to userspace with kernel (full) page table
still active.

Map userspace portion of VA in the PTI kernel-mode page table as
non-executable. This way, if we ever miss reloading ucr3 into %cr3 on
the return to usermode, the process traps instead of executing in
potentially vulnerable setup.  Catch the condition of such trap and
verify user-mode %cr3, which is saved by page fault handler.

I peek this trick in some article about Linux implementation.

Reviewed by: alc, markj (previous version)
Sponsored by: The FreeBSD Foundation
MFC after: 12 days
DIfferential revision: https://reviews.freebsd.org/D13956

6 years agobhnd(4): fix a few bugs in pwrctl/fixed-clock device support.
landonf [Fri, 19 Jan 2018 21:58:48 +0000 (21:58 +0000)]
bhnd(4): fix a few bugs in pwrctl/fixed-clock device support.

 - Do not panic on siba(4) detach when the bhnd(4) bus calls
   bhnd_get_pmu_info() on a PMU-less device.
 - Fix bhnd_pwrctl attach/detach on fixed-clock devices:
    - Treat bhnd_pwrctl_updateclk() as a no-op on fixed-clock devices.
    - Use bhnd_pwrctl_updateclk() to perform the appropriate clock
      transition on detach.

Sponsored by: The FreeBSD Foundation

6 years agobhnd_chipc(4): Fix the assignment of non-wildcard child unit numbers
landonf [Fri, 19 Jan 2018 21:36:28 +0000 (21:36 +0000)]
bhnd_chipc(4): Fix the assignment of non-wildcard child unit numbers
introduced in r326102 and r326109; all chipc children should be added with
a wildcard unit (-1).

Sponsored by: The FreeBSD Foundation

6 years agodtc(1): Update to upstream ea3c233
kevans [Fri, 19 Jan 2018 21:20:24 +0000 (21:20 +0000)]
dtc(1): Update to upstream ea3c233

Highlights of this update:
- /__local_fixups__ is now generated to be GPL dtc and libfdt compliant
- Compiling with -@ will now cause dtc to assign phandles to all labelled
  nodes
- /include/ and /incbin/ now handle absolute paths correctly
- The manpage now has information about overlays, including how to apply
  them and how to generate them
- Syntactic sugar for overlays is now supported, allowing an overlay DTS
  like:

=
/dts-v1/;
/plugin/;

&foo {
    foo,status = "okay";
};
=

to generate a fragment targetting <&foo>.

6 years agoRename "index" variable to "idx" since gcc complains that it shadows
ae [Fri, 19 Jan 2018 20:33:47 +0000 (20:33 +0000)]
Rename "index" variable to "idx" since gcc complains that it shadows
index(3) function declaration.

Reported by: lwhsu
MFC after: 2 weeks

6 years agoFix compile errors in r328165
scottl [Fri, 19 Jan 2018 19:18:14 +0000 (19:18 +0000)]
Fix compile errors in r328165

Reported by: O. Hartmann
Sponsored by: Netflix

6 years agoRemove extra copy of bootinfo.c. It's a bit rotted copy of the one in
imp [Fri, 19 Jan 2018 19:09:17 +0000 (19:09 +0000)]
Remove extra copy of bootinfo.c. It's a bit rotted copy of the one in
efi/loader.

Differential Review: https://reviews.freebsd.org/D13986

6 years agoRemove SFBUF_OPTIONAL_DIRECT_MAP and such hacks, replacing them across the
nwhitehorn [Fri, 19 Jan 2018 17:46:31 +0000 (17:46 +0000)]
Remove SFBUF_OPTIONAL_DIRECT_MAP and such hacks, replacing them across the
kernel by PHYS_TO_DMAP() as previously present on amd64, arm64, riscv, and
powerpc64. This introduces a new MI macro (PMAP_HAS_DMAP) that can be
evaluated at runtime to determine if the architecture has a direct map;
if it does not (or does) unconditionally and PMAP_HAS_DMAP is either 0 or
1, the compiler can remove the conditional logic.

As part of this, implement PHYS_TO_DMAP() on sparc64 and mips64, which had
similar things but spelled differently. 32-bit MIPS has a partial direct-map
that maps poorly to this concept and is unchanged.

Reviewed by: kib
Suggestions from: marius, alc, kib
Runtime tested on: amd64, powerpc64, powerpc, mips64

6 years agoEnable KPTI by default on amd64 for non-AMD CPUs
emaste [Fri, 19 Jan 2018 15:42:34 +0000 (15:42 +0000)]
Enable KPTI by default on amd64 for non-AMD CPUs

Kernel Page Table Isolation (KPTI) was introduced in r328083 as a
mitigation for the 'Meltdown' vulnerability.  AMD CPUs are not affected,
per https://www.amd.com/en/corporate/speculative-execution:

    We believe AMD processors are not susceptible due to our use of
    privilege level protections within paging architecture and no
    mitigation is required.

Thus default KPTI to off for AMD CPUs, and to on for others.  This may
be refined later as we obtain more specific information on the sets of
CPUs that are and are not affected.

Submitted by: Mitchell Horne
Reviewed by: cem
Relnotes: Yes
Security: CVE-2017-5754
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D13971

6 years agoRevert ABI breakage to CAM that came in with MMC/SD support in r320844.
scottl [Fri, 19 Jan 2018 15:32:27 +0000 (15:32 +0000)]
Revert ABI breakage to CAM that came in with MMC/SD support in r320844.
Make it possible to retrieve mmc parameters via the XPT_GET_ADVINFO
call instead.  Convert camcontrol to the new scheme.

Reviewed by: imp. kibab
Sponsored by: Netflix
Differential Revision: D13868

6 years agolibnv: Use mallocarray(9) for the nv_calloc.
pfg [Fri, 19 Jan 2018 14:50:53 +0000 (14:50 +0000)]
libnv: Use mallocarray(9) for the nv_calloc.

6 years agoAdd new USB ID to U3G driver.
hselasky [Fri, 19 Jan 2018 13:06:36 +0000 (13:06 +0000)]
Add new USB ID to U3G driver.

PR: 134299
MFC after: 1 week
Sponsored by: Mellanox Technologies

6 years agoImprove support for USB based 3G/4G/5G dongles from Huawei.
hselasky [Fri, 19 Jan 2018 12:59:14 +0000 (12:59 +0000)]
Improve support for USB based 3G/4G/5G dongles from Huawei.

PR: 192345
Sponsored by: Mellanox Technologies

6 years agoAdd UDPLite support to ipfw(4).
ae [Fri, 19 Jan 2018 12:50:03 +0000 (12:50 +0000)]
Add UDPLite support to ipfw(4).

Now it is possible to use UDPLite's port numbers in rules,
create dynamic states for UDPLite packets and see "UDPLite" for matched
packets in log.

Obtained from: Yandex LLC
MFC after: 2 weeks
Sponsored by: Yandex LLC

6 years agoAdd to bsnmpd(1) ability to specify multiple community strings with
ae [Fri, 19 Jan 2018 08:48:14 +0000 (08:48 +0000)]
Add to bsnmpd(1) ability to specify multiple community strings with
different access rights.

By default there are two community strings with index 1 and 2, one for
read-only access and second for read-write access:

  begemotSnmpdCommunityString.0.1 = $(read)
  begemotSnmpdCommunityString.0.2 = $(write)

Now it is possible to define additional community strings using different
indexes:

  begemotSnmpdCommunityString.0.3 = "SomeString1"
  begemotSnmpdCommunityPermission.0.3 = 1
  begemotSnmpdCommunityString.0.4 = "SomeString2"
  begemotSnmpdCommunityPermission.0.4 = 2
  begemotSnmpdCommunityString.0.5 = "SomeString3"
  begemotSnmpdCommunityString.0.6 = "SomeString4"

New attribute begemotSnmpdCommunityPermission can be used to specify access
rights: 1 means "read-only" access, 2 means "read-write" access. If
attribute is not specified for some index this means "read-only" rights.

Community strings must be unique, i.e. must not be the same for different
indexes.

Obtained from: Yandex LLC
MFC after: 2 weeks
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D13785

6 years agoUnbreak i386 build
cem [Fri, 19 Jan 2018 04:34:06 +0000 (04:34 +0000)]
Unbreak i386 build

The logical result of a right shift >= the width of a type is zero, but our
compiler decides this is a warning (and thus, error).  Just remove ccp(4)
from i386.

Reported by: cy
Sponsored by: Dell EMC Isilon

6 years agoRecognize mchk_calltrap as a trapframe generator.
jhb [Fri, 19 Jan 2018 01:36:25 +0000 (01:36 +0000)]
Recognize mchk_calltrap as a trapframe generator.

Should have been included in r328157.

6 years agoUse a dedicated per-CPU stack for machine check exceptions.
jhb [Thu, 18 Jan 2018 23:50:21 +0000 (23:50 +0000)]
Use a dedicated per-CPU stack for machine check exceptions.

Similar to NMIs, machine check exceptions can fire at any time and are
not masked by IF.  This means that machine checks can fire when the
kstack is too deep to hold a trap frame, or at critical sections in
trap handlers when a user %gs is used with a kernel %cs.  Use the same
strategy used for NMIs of using a dedicated per-CPU stack configured
in IST 3.  Store the CPU's pcpu pointer at the stop of the stack so
that the machine check handler can reliably find the proper value for
%gs (also borrowed from NMIs).

This should also fix a similar issue with PTI with a MC# occurring
while the CPU is executing on the trampoline stack.

While here, bypass trap() entirely and just call mca_intr().  This
avoids a bogus call to kdb_reenter() (there's no reason to try to
reenter kdb if a MC# is raised).

Reviewed by: kib
Tested by: avg (on AMD without PTI)
Differential Revision: https://reviews.freebsd.org/D13962

6 years agostand: Move sections around to fix stand/ build with ld.lld on armv7
kevans [Thu, 18 Jan 2018 22:46:47 +0000 (22:46 +0000)]
stand: Move sections around to fix stand/ build with ld.lld on armv7

When building loader bits, lld fails with the following error:
"ld: error: section: .dynamic is not contiguous with other relro sections"
on both ubldr and EFI loader.

Move .dynamic up to make ld.lld happy, adjust .got as necessary for ubldr.

Tested on: OrangePi One (ld.lld, ubldr)
Tested on: Banana Pi-M3 (ld.lld, ubldr)
Tested on: qemu-armv7 (ld.lld, EFI)
Tested on: qemu-armv7 (ld.bfd, EFI)
Tested on: Raspberry Pi 2 (ld.bfd, ubldr) [manu]
Tested on: Banana Pi-M2 (ld.bfd, ubldr) [manu]
Reviewed by: andrew, emaste, imp
Differential Revision: https://reviews.freebsd.org/D13942

6 years agoNo need for the zero width space now that I put the comma in.
imp [Thu, 18 Jan 2018 22:23:16 +0000 (22:23 +0000)]
No need for the zero width space now that I put the comma in.

6 years agoMake igor happier with this file:
imp [Thu, 18 Jan 2018 22:20:30 +0000 (22:20 +0000)]
Make igor happier with this file:
o Don't use contractions.
o Add common after e.g. where needed

6 years agoRemove two no-longer-used labels from the NMI interrupt handler.
jhb [Thu, 18 Jan 2018 22:13:53 +0000 (22:13 +0000)]
Remove two no-longer-used labels from the NMI interrupt handler.

Reviewed by: kib

6 years agoAdd ccp(4): experimental driver for AMD Crypto Co-Processor
cem [Thu, 18 Jan 2018 22:01:30 +0000 (22:01 +0000)]
Add ccp(4): experimental driver for AMD Crypto Co-Processor

* Registers TRNG source for random(4)
* Finds available queues, LSBs; allocates static objects
* Allocates a shared MSI-X for all queues.  The hardware does not have
  separate interrupts per queue.  Working interrupt mode driver.
* Computes SHA hashes, HMAC.  Passes cryptotest.py, cryptocheck tests.
* Does AES-CBC, CTR mode, and XTS.  cryptotest.py and cryptocheck pass.
* Support for "authenc" (AES + HMAC).  (SHA1 seems to result in
  "unaligned" cleartext inputs from cryptocheck -- which the engine
  cannot handle.  SHA2 seems to work fine.)
* GCM passes for block-multiple AAD, input lengths

Largely based on ccr(4), part of cxgbe(4).

Rough performance averages on AMD Ryzen 1950X (4kB buffer):
aesni:      SHA1: ~8300 Mb/s    SHA256: ~8000 Mb/s
ccp:               ~630 Mb/s    SHA256:  ~660 Mb/s  SHA512:  ~700 Mb/s
cryptosoft:       ~1800 Mb/s    SHA256: ~1800 Mb/s  SHA512: ~2700 Mb/s

As you can see, performance is poor in comparison to aesni(4) and even
cryptosoft (due to high setup cost).  At a larger buffer size (128kB),
throughput is a little better (but still worse than aesni(4)):

aesni:      SHA1:~10400 Mb/s    SHA256: ~9950 Mb/s
ccp:              ~2200 Mb/s    SHA256: ~2600 Mb/s  SHA512: ~3800 Mb/s
cryptosoft:       ~1750 Mb/s    SHA256: ~1800 Mb/s  SHA512: ~2700 Mb/s

AES performance has a similar story:

aesni:      4kB: ~11250 Mb/s    128kB: ~11250 Mb/s
ccp:               ~350 Mb/s    128kB:  ~4600 Mb/s
cryptosoft:       ~1750 Mb/s    128kB:  ~1700 Mb/s

This driver is EXPERIMENTAL.  You should verify cryptographic results on
typical and corner case inputs from your application against a known- good
implementation.

Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D12723

6 years agoPull in r322106 from upstream llvm trunk (by Alexey Bataev):
dim [Thu, 18 Jan 2018 21:46:09 +0000 (21:46 +0000)]
Pull in r322106 from upstream llvm trunk (by Alexey Bataev):

  [COST]Fix PR35865: Fix cost model evaluation for shuffle on X86.

  Summary:
  If the vector type is transformed to non-vector single type, the
  compile may crash trying to get vector information about non-vector
  type.

  Reviewers: RKSimon, spatel, mkuper, hfinkel

  Subscribers: llvm-commits

  Differential Revision: https://reviews.llvm.org/D41862

This should fix "Not a vector MVT!" errors when building the
games/dhewm3 port.

Reported by: jbeich
PR: 225271

6 years agoPull in r322016 from upstream llvm trunk (by Sanjay Patel):
dim [Thu, 18 Jan 2018 21:44:07 +0000 (21:44 +0000)]
Pull in r322016 from upstream llvm trunk (by Sanjay Patel):

  [ValueTracking] remove overzealous assert

  The test is derived from a failing fuzz test:
  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=5008

  Credit to @rksimon for pointing out the problem.

This should fix "Bad flavor while matching min/max" errors when building
the graphics/libsixel and science/kst2 ports.

Reported by: jbeich
PR: 225268, 225269

6 years agolld: Fix incorrect physical address on self-referencing AT command.
emaste [Thu, 18 Jan 2018 21:39:59 +0000 (21:39 +0000)]
lld: Fix incorrect physical address on self-referencing AT command.

When a section placement (AT) command references the section itself,
the physical address of the section in the ELF header was calculated
incorrectly due to alignment happening right after the location
pointer's value was captured.

The problem was diagnosed and the first version of the patch written
by Erick Reyes.

Obtained from: LLVM r322421 by Rafael Espindola

6 years agolld: Handle parsing AT(ADDR(.foo-bar)).
emaste [Thu, 18 Jan 2018 21:39:19 +0000 (21:39 +0000)]
lld: Handle parsing AT(ADDR(.foo-bar)).

The problem we had with it is that anything inside an AT is an
expression, so we failed to parse the section name because of the - in
it.

Requested by: royger
Obtained from: LLVM r322801 by Rafael Espindola

6 years agolld: Fix for ld.lld does not accept "AT" syntax for declaring LMA region
emaste [Thu, 18 Jan 2018 21:38:21 +0000 (21:38 +0000)]
lld: Fix for ld.lld does not accept "AT" syntax for declaring LMA region

AT> lma_region expression allows to specify the memory region
for section load address.

Should fix [upstream LLVM] PR35684.

LLVM review: https://reviews.llvm.org/D41397

Obtained from: LLVM r322359 by George Rimar

6 years agoAdd Elf_Nhdr definition to match NetBSD, OpenBSD, Linux
cem [Thu, 18 Jan 2018 21:19:57 +0000 (21:19 +0000)]
Add Elf_Nhdr definition to match NetBSD, OpenBSD, Linux

The mesa port started to use this type and fails to build without it.

NetBSD: http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/sys/exec_elf.h.diff?r1=1.26&r2=1.27&f=h
OpenBSD: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/sys/exec_elf.h.diff?r1=1.21&r2=1.22&f=h

PR: 225302
Reported by: Greg V <greg AT unrelenting.technology>
Sponsored by: Dell EMC Isilon

6 years agoTeach the resolv startup script to respect its enable flag.
brd [Thu, 18 Jan 2018 20:45:41 +0000 (20:45 +0000)]
Teach the resolv startup script to respect its enable flag.

Reviewed by: will, imp
Approved by: imp

6 years agoAdjust branch target in NMI handler for the !PTI case.
jhb [Thu, 18 Jan 2018 20:12:12 +0000 (20:12 +0000)]
Adjust branch target in NMI handler for the !PTI case.

In the !PTI case the NMI handler jumped past the instructions that set
%rdi to point to the current PCB, but the target instructions assumed %rdi
were set.

Reviewed by: kib
Tested by: pho

6 years agoUpdate various statements in vmstat(8) to match reality.
jhb [Thu, 18 Jan 2018 19:43:02 +0000 (19:43 +0000)]
Update various statements in vmstat(8) to match reality.

- The process stats are actually thread counts rather than process
  counts.
- Simplify various descriptions to remove mention of stats that are
  updated every 5 seconds (all VM related stats are now "instant",
  only the load average is updated every 5 seconds).
- Don't make any mention of special treatment for processes that have
  been active in the last 20 seconds.  We don't track that stat.
- Rework the description of active virtual memory.  Call it mapped
  virtual memory and explicitly point out it is not the same as the
  active page queue (which corresponds to "Active" in top(1)), and
  also hint at the possible bogusness of the value (e.g. if a process
  maps a single page out of a multiple GB file, the entire file's size
  is considered mapped).
- Simplify a few descriptions that implied their output was a value
  per interval.  All of the "rate" values are per-second rates scaled
  across the interval.
- Update a few comments for 'struct vmtotal' along similar lines.

Reported by: mwlucas (indirectly)
Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D13905

6 years agoUART Clock Selection Register holds a divider value for a supplied clock,
br [Thu, 18 Jan 2018 18:19:31 +0000 (18:19 +0000)]
UART Clock Selection Register holds a divider value for a supplied clock,
not a final baud rate. The value for this register has to be calculated.

Sponsored by: DARPA, AFRL

6 years agoSupport for UART device found in Qualcomm Snapdragon 410E SoC.
br [Thu, 18 Jan 2018 17:43:32 +0000 (17:43 +0000)]
Support for UART device found in Qualcomm Snapdragon 410E SoC.

Tested on DragonBoard 410c.

Reviewed by: andrew
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D13972

6 years agoSet the base address of translation table 0.
br [Thu, 18 Jan 2018 16:20:09 +0000 (16:20 +0000)]
Set the base address of translation table 0.

This fixes operation on Qualcomm Snapdragon and some other platforms.

During boot time on subsystems initialization we have some amount of
kernel threads created, then scheduler gives CPU time to each thread.
Eventually scheduler returns CPU execution back to thread 0. In this
case writing zero to ttbr0 in cpu_switch leads Qualcomm board to
reboot (asynchronously, CPU continues execution).

Similar to other kernel threads install a valid physical address
(kernel pmap) to user page table base register ttbr0.

Reviewed by: andrew
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D13536

6 years agonfs: Do not printf each time a lock structure is freed during module unload
manu [Thu, 18 Jan 2018 15:28:49 +0000 (15:28 +0000)]
nfs: Do not printf each time a lock structure is freed during module unload

There can be a lot of those structures and printing a line each time we free
one on module unload.

MFC after: 3 days

6 years agoMove the kernphys declaration to machine/md_var.h.
kib [Thu, 18 Jan 2018 15:15:35 +0000 (15:15 +0000)]
Move the kernphys declaration to machine/md_var.h.

Apparently machinde/cpu.h is supposed to contain MD implementations of
MI interfaces.  Also, remove kernphys declaration from machdep.c,
since it is already provided by md_var.h.

Requested and reviewed by: bde
MFC after: 13 days

6 years agocorrect read-ahead calculations in vfs_bio_getpages
avg [Thu, 18 Jan 2018 12:59:04 +0000 (12:59 +0000)]
correct read-ahead calculations in vfs_bio_getpages

Previously the calculations were done as if the requested region
ended at the start of the last requested page, not its end.
The problem as actually quite minor as it affected only stats and
page prefaulting, not the actual page data, and only with specific
parameters.

Reviewed by: kib (previous version)
MFC after: 2 weeks

6 years agoFix compilation with gcc.
kib [Thu, 18 Jan 2018 11:21:03 +0000 (11:21 +0000)]
Fix compilation with gcc.

etext is already declared in machine/cpu.h, move kernphys declaration
there too.

Based on the patch by: bde
MFC after: 13 days

6 years agoFix compilation with gas.
kib [Thu, 18 Jan 2018 11:19:58 +0000 (11:19 +0000)]
Fix compilation with gas.

Submitted by: bde
MFC after: 13 days

6 years agoRemove the 'last' argument from the pmap_pti_free_page().
kib [Thu, 18 Jan 2018 11:01:41 +0000 (11:01 +0000)]
Remove the 'last' argument from the pmap_pti_free_page().

It is in fact unused.

Noted and reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 13 days

6 years agoAdd a pmap invalidate that doesn't call sched_pin.
andrew [Thu, 18 Jan 2018 10:52:31 +0000 (10:52 +0000)]
Add a pmap invalidate that doesn't call sched_pin.

When demoting DMAP pages curthread may be pointing to data within the
page we are demoting. Create a new invalidate that doesn't pin and use
it in the demote case.

As the demote has both interrupts disabled, and is within a critical section
this is safe from having the scheduler from switching to another CPU.

Reported by: loos
Reviewed by: loos
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D13955

6 years agoCall platform_smp_ap_init before decr_ap_init
wma [Thu, 18 Jan 2018 08:34:20 +0000 (08:34 +0000)]
Call platform_smp_ap_init before decr_ap_init

    In platform_smp_ap_init we are doing some crucial code (eg. set LPCR register)
    which have influence over further execution.

    Practiculary in PowerNV platform we have experienced Data Storage Interrupt
    before we set apropriate LPCR. It caused code execution from location which was
    legal in bootloader (petitboot based on linux) but illegal in FreeBSD

6 years agoPPC64: fix TOC behavior on process initialization
wma [Thu, 18 Jan 2018 07:42:51 +0000 (07:42 +0000)]
PPC64: fix TOC behavior on process initialization

Set stack pointer to correct value after thread's stack pointer restore

Restoring new thread's stack pointer caused stack corruption because
restored stack pointer didn't point to callee (cpu_switch) stack frame but
caller stack frame.

As a result we had mysterious errors in caller function (sched_switch).

Solution: simply set stack pointer to correct value

Also, initialize TOC to a valid pointer once the thread is being
created.

Created by:            Patryk Duda <pdk@semihalf.com>
Submitted by:          Wojciech Macek <wma@semihalf.com>
Obtained from:         Semihalf
Reviewed by:           nwhitehorn
Differential revision: https://reviews.freebsd.org/D13947
Sponsored by:          QCM Technologies

6 years agoPPC: machdep, zero BSS always but BookE
wma [Thu, 18 Jan 2018 07:41:04 +0000 (07:41 +0000)]
PPC: machdep, zero BSS always but BookE

Zero BSS always. The only case when this operation is
ommitted is when booting on BookE.

Created by:            Wojciech Macek <wma@semihalf.com>
Obtained from:         Semihalf
Reviewed by:           imp, nwhitehorn
Differential revision: https://reviews.freebsd.org/D13948
Sponsored by:          QCM Technologies

6 years agoKDB: restart only CPUs stopped by KDB
wma [Thu, 18 Jan 2018 07:38:54 +0000 (07:38 +0000)]
KDB: restart only CPUs stopped by KDB

There is a case when not all CPUs went online. In that situation,
restart only APs which were operational before entering KDB.

Created by:            Wojciech Macek <wma@semihalf.com>
Obtained from:         Semihalf
Reviewed by:           nwhitehorn
Differential revision: https://reviews.freebsd.org/D13949
Sponsored by:          QCM Technologies

6 years agoPPC64: add AHCI back to GENERIC64
wma [Thu, 18 Jan 2018 06:28:21 +0000 (06:28 +0000)]
PPC64: add AHCI back to GENERIC64

> Description of fields to fill in above:                     76 columns --|
> PR:                       If a GNATS PR is affected by the change.
> Submitted by:             If someone else sent in the change.
> Reviewed by:              If someone else reviewed your modification.
> Approved by:              If you needed approval for this commit.
> Obtained from:            If the change is from a third party.
> MFC after:                N [day[s]|week[s]|month[s]].  Request a reminder email.
> MFH:                      Ports tree branch name.  Request approval for merge.
> Relnotes:                 Set to 'yes' for mention in release notes.
> Security:                 Vulnerability reference (one per line) or description.
> Sponsored by:             If the change was sponsored by an organization.
> Differential Revision:    https://reviews.freebsd.org/D### (*full* phabric URL needed).
> Empty fields above will be automatically removed.

M    sys/powerpc/conf/GENERIC64

6 years agognop(8): add the ability to set a nop provider's physical path
asomers [Thu, 18 Jan 2018 05:57:10 +0000 (05:57 +0000)]
gnop(8): add the ability to set a nop provider's physical path

While I'm here, expand the existing tests a bit.

MFC after: 3 weeks
Differential Revision: https://reviews.freebsd.org/D13579

6 years agostand: Add /boot/overlays to allow separation of overlays from base FDT
kevans [Thu, 18 Jan 2018 04:58:54 +0000 (04:58 +0000)]
stand: Add /boot/overlays to allow separation of overlays from base FDT

This matches directory structure used commonly in Linux-land, and it's
cleaner than mixing overlays into the existing module paths. Overlays are
still mixed in by specifying fdt_overlays in loader.conf(5).

Reviewed by: manu
Differential Revision: https://reviews.freebsd.org/D13922

6 years agolibfdt: Update to 1.4.6, switch to using libfdt for overlay support
kevans [Thu, 18 Jan 2018 04:39:09 +0000 (04:39 +0000)]
libfdt: Update to 1.4.6, switch to using libfdt for overlay support

libfdt highlights since 1.4.3:

- fdt_property_placeholder added to create a property without specifying its
value at creation time
- stringlist helper functions added to libfdt
- Improved overlay support
- Various internal cleanup

Also switch stand/fdt over to using libfdt for overlay support with this
update. Our current overlay implementation works only for limited use cases
with overlays generated only by some specific versions of our dtc(1). Swap
it out for the libfdt implementation, which supports any properly generated
overlay being applied to a properly generated base.

This will be followed up fairly soon with an update to dtc(1) in tree to
properly generate overlays.

MFC note: the <stdlib.h> include this update introduces in libfdt_env.h is
apparently not necessary in the context we use this in. It's not immediately
clear to me the motivation for it being introduced, but it came in with
overlay support. I've left it in for the sake of accuracy and because it's
not harmful here on HEAD, but MFC'ing this to stable/11 will require
wrapping the #include in an `#ifndef _STANDALONE` block or else it will
cause build failures.

Tested on: Banana Pi-M3 (ARMv7)
Tested on: Pine64 (aarch64)
Tested on: PowerPC [nwhitehorn]
Reviewed by: manu, nwhitehorn
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D13893

6 years agoAdjust format string to fix build.
jhb [Thu, 18 Jan 2018 00:24:05 +0000 (00:24 +0000)]
Adjust format string to fix build.

6 years agoTidy some whitespace.
jhb [Thu, 18 Jan 2018 00:23:11 +0000 (00:23 +0000)]
Tidy some whitespace.

6 years agoSave and restore guest debug registers.
jhb [Wed, 17 Jan 2018 23:11:25 +0000 (23:11 +0000)]
Save and restore guest debug registers.

Currently most of the debug registers are not saved and restored
during VM transitions allowing guest and host debug register values to
leak into the opposite context.  One result is that hardware
watchpoints do not work reliably within a guest under VT-x.

Due to differences in SVM and VT-x, slightly different approaches are
used.

For VT-x:

- Enable debug register save/restore for VM entry/exit in the VMCS for
  DR7 and MSR_DEBUGCTL.
- Explicitly save DR0-3,6 of the guest.
- Explicitly save DR0-3,6-7, MSR_DEBUGCTL, and the trap flag from
  %rflags for the host.  Note that because DR6 is "software" managed
  and not stored in the VMCS a kernel debugger which single steps
  through VM entry could corrupt the guest DR6 (since a single step
  trap taken after loading the guest DR6 could alter the DR6
  register).  To avoid this, explicitly disable single-stepping via
  the trace flag before loading the guest DR6.  A determined debugger
  could still defeat this by setting a breakpoint after the guest DR6
  was loaded and then single-stepping.

For SVM:
- Enable debug register caching in the VMCB for DR6/DR7.
- Explicitly save DR0-3 of the guest.
- Explicitly save DR0-3,6-7, and MSR_DEBUGCTL for the host.  Since SVM
  saves the guest DR6 in the VMCB, the race with single-stepping
  described for VT-x does not exist.

For both platforms, expose all of the guest DRx values via --get-drX
and --set-drX flags to bhyvectl.

Discussed with: avg, grehan
Tested by: avg (SVM), myself (VT-x)
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D13229

6 years agoRequire the SHF_ALLOC flag for program sections from kernel object modules.
jhb [Wed, 17 Jan 2018 22:51:59 +0000 (22:51 +0000)]
Require the SHF_ALLOC flag for program sections from kernel object modules.

ELF object files can contain program sections which are not supposed
to be loaded into memory (e.g. .comment).  Normally the static linker
uses these flags to decide which sections are allocated to loadable
program segments in ELF binaries and shared objects (including kernels
on all architectures and kernel modules on architectures other than
amd64).

Mapping ELF object files (such as amd64 kernel modules) into memory
directly is a bit of a grey area.  ELF object files are intended to be
used as inputs to the static linker.  As a result, there is not a
standardized definition for what the memory layout of an ELF object
should be (none of the section headers have valid virtual memory
addresses for example).

The kernel and loader were not checking the SHF_ALLOC flag but loading
any program sections with certain types such as SHT_PROGBITS.  As a
result, the kernel and loader would load into RAM some sections that
weren't marked with SHF_ALLOC such as .comment that are not loaded
into RAM for kernel modules on other architectures (which are
implemented as ELF shared objects).  Aside from possibly requiring
slightly more RAM to hold a kernel module this does not affect runtime
correctness as the kernel relocates symbols based on the layout it
uses.

Debuggers such as gdb and lldb do not extract symbol tables from a
running process or kernel.  Instead, they replicate the memory layout
of ELF executables and shared objects and use that to construct their
own symbol tables.  For executables and shared objects this works
fine.  For ELF objects the current logic in kgdb (and probably lldb
based on a simple reading) assumes that only sections with SHF_ALLOC
are memory resident when constructing a memory layout.  If the
debugger constructs a different memory layout than the kernel, then it
will compute different addresses for symbols causing symbols in the
debugger to appear to have the wrong values (though the kernel itself
is working fine).  The current port of mdb does not check SHF_ALLOC as
it replicates the kernel's logic in its existing kernel support.

The bfd linker sorts the sections in ELF object files such that all of
the allocated sections (sections with SHF_ALLOCATED) are placed first
followed by unallocated sections.  As a result, when kgdb composed a
memory layout using only the allocated sections, this layout happened
to match the layout used by the kernel and loader.  The lld linker
does not sort the sections in ELF object files and mixed allocated and
unallocated sections.  This resulted in kgdb composing a different
memory layout than the kernel and loader.

We could either patch kgdb (and possibly in the future lldb) to use
custom handling when generating memory layouts for kernel modules that
are ELF objects, or we could change the kernel and loader to check
SHF_ALLOCATED.  I chose the latter as I feel we shouldn't be loading
things into RAM that the module won't use.  This should mostly be a
NOP when linking with bfd but will allow the existing kgdb to work
with amd64 kernel modules linked with lld.

Note that we only require SHF_ALLOC for "program" sections for types
like SHT_PROGBITS and SHT_NOBITS.  Other section types such as symbol
tables, string tables, and relocations must also be loaded and are not
marked with SHF_ALLOC.

Reported by: np
Reviewed by: kib, emaste
MFC after: 1 month
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D13926

6 years agoConvert ls(1) to not use libxo(3)
cem [Wed, 17 Jan 2018 22:47:34 +0000 (22:47 +0000)]
Convert ls(1) to not use libxo(3)

libxo imposes a large burden on system utilities. In the case of ls, that
burden is difficult to justify -- any language that can interact with json
output can use readdir(3) and stat(2).

Logically, this reverts r291607, r285857, r285803, r285734, r285425,
r284494, r284489, r284252, and r284198.

Kyua tests continue to pass (libxo integration was entirely untested).

Reported by: many
Reviewed by: imp
Discussed with: manu, bdrewery
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D13959

6 years agoUse long for the last argument to VOP_PATHCONF rather than a register_t.
jhb [Wed, 17 Jan 2018 22:36:58 +0000 (22:36 +0000)]
Use long for the last argument to VOP_PATHCONF rather than a register_t.

pathconf(2) and fpathconf(2) both return a long.  The kern_[f]pathconf()
functions now accept a pointer to a long value rather than modifying
td_retval directly.  Instead, the system calls explicitly store the
returned long value in td_retval[0].

Requested by: bde
Reviewed by: kib
Sponsored by: Chelsio Communications

6 years agobwn(4): Enable, by default, the opt-in support for bhnd(4) introduced in
landonf [Wed, 17 Jan 2018 22:33:19 +0000 (22:33 +0000)]
bwn(4): Enable, by default, the opt-in support for bhnd(4) introduced in
r326454.

bwn(4)/bhnd(4) has been tested with most chipsets currently supported by
bwn(4), and this change should be transparent to existing bwn(4) users;
please report any regressions that you do encounter.

To revert to using siba_bwn(4) instead of bhnd(4), place the following
lines in loader.conf(5):

  hw.bwn_pci.preferred="0"

Once we're satisfied that the switch to bhnd(4) has seen sufficient broader
testing, bwn(4) will be migrated to use the native bhnd(9) interface
directly, and support for siba_bwn(4) will be dropped (see D13518).

Sponsored by: The FreeBSD Foundation

6 years agoAnnotate a couple of changes from r328083.
markj [Wed, 17 Jan 2018 21:52:12 +0000 (21:52 +0000)]
Annotate a couple of changes from r328083.

Reviewed by: kib
X-MFC with: r328083

6 years agokldxref: additional sytle(9) cleanup
emaste [Wed, 17 Jan 2018 20:43:30 +0000 (20:43 +0000)]
kldxref: additional sytle(9) cleanup

Reported by: kib (via comments in D13957)
Sponsored by: The FreeBSD Foundation

6 years agokldxref: improve style(9)
emaste [Wed, 17 Jan 2018 19:59:43 +0000 (19:59 +0000)]
kldxref: improve style(9)

Address style issues including some previously raised in D13923.

- Use designated initializers for structs
- Always use bracketed return style
- No initialization in declarations
- Align function prototype names
- Remove old commented code/unused includes

Submitted by: Mitchell Horne <mhorne063@gmail.com>
Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D13943

6 years agoufs: use mallocarray(9).
pfg [Wed, 17 Jan 2018 18:18:33 +0000 (18:18 +0000)]
ufs: use mallocarray(9).

Basic use of mallocarray to prevent overflows: static analyzers are also
likely to perform additional checks.

Since mallocarray expects unsigned parameters, unsign some
related variables to minimize sign conversions.

Reviewed by: mckusick

6 years agoCorrect fsck journal-recovery code to update a cylinder-group
mckusick [Wed, 17 Jan 2018 17:58:24 +0000 (17:58 +0000)]
Correct fsck journal-recovery code to update a cylinder-group
check-hash after making changes to the cylinder group. The problem
was that the journal-recovery code was calling the libufs bwrite()
function instead of the cgput() function. The cgput() function updates
the cylinder-group check-hash before writing the cylinder group.

This change required the additions of the cgget() and cgput() functions
to the libufs API to avoid a gratuitous bcopy of every cylinder group
to be read or written. These new functions have been added to the
libufs manual pages. This was the first opportunity that I have had
to use and document the use of the EDOOFUS error code.

Reviewed by: kib
Reported by: emaste and others

6 years agoRevert r327340, as the workaround for rep prefixes followed by .byte
dim [Wed, 17 Jan 2018 17:14:19 +0000 (17:14 +0000)]
Revert r327340, as the workaround for rep prefixes followed by .byte
directives is no longer needed after r328090.

6 years agoPull in r322623 from upstream llvm trunk (by Andrew V. Tischenko):
dim [Wed, 17 Jan 2018 17:11:55 +0000 (17:11 +0000)]
Pull in r322623 from upstream llvm trunk (by Andrew V. Tischenko):

  Allow usage of X86-prefixes as separate instrs.
  Differential Revision: https://reviews.llvm.org/D42102

This should fix parse errors when x86 prefixes (such as 'lock' and
'rep') are followed by various non-mnemonic tokens, e.g. comments, .byte
directives and labels.

PR: 224669,225054

6 years agoMove setting of CAM_SIM_QUEUED to before we actually submit it to the
imp [Wed, 17 Jan 2018 17:08:26 +0000 (17:08 +0000)]
Move setting of CAM_SIM_QUEUED to before we actually submit it to the
hardware. Setting it after is racy, and we can lose the race on a
heavily loaded system.

Reviewed by: scottl@, gallatin@
Sponsored by: Netflix

6 years agoOnly call flush in pipe mode.
fabient [Wed, 17 Jan 2018 16:55:35 +0000 (16:55 +0000)]
Only call flush in pipe mode.
It fixes a crash with a socket in top mode.

Ex:
# pmcstat -R 127.0.0.1:8080 -T -w1
then
# pmcstat -n1 -Sclock.prof -Slock.failed -O 127.0.0.1:8080

MFC after: 1 week
Sponsored by: Stormshield

6 years agoFix pmcstat exit from kernel introduced by r325275.
fabient [Wed, 17 Jan 2018 16:41:22 +0000 (16:41 +0000)]
Fix pmcstat exit from kernel introduced by r325275.
pmcstat request for close will generate a close event.
This event will be in turn received by pmcstat to close the file.

Reviewed by: kib
Tested by: pho
MFC after: 1 week
Sponsored by: Stormshield

6 years agoUpdate pciids to 2018.01.14
bapt [Wed, 17 Jan 2018 13:25:41 +0000 (13:25 +0000)]
Update pciids to 2018.01.14

MFC after: 3 days

6 years agoFix buildworld after r328075, by also renaming cgget to cglookup in
dim [Wed, 17 Jan 2018 13:19:37 +0000 (13:19 +0000)]
Fix buildworld after r328075, by also renaming cgget to cglookup in
fsdb.

Reported by: ohartmann@walstatt.org,david@catwhisker.org
Pointy hat to: mckusick

6 years agoPTI for amd64.
kib [Wed, 17 Jan 2018 11:44:21 +0000 (11:44 +0000)]
PTI for amd64.

The implementation of the Kernel Page Table Isolation (KPTI) for
amd64, first version. It provides a workaround for the 'meltdown'
vulnerability.  PTI is turned off by default for now, enable with the
loader tunable vm.pmap.pti=1.

The pmap page table is split into kernel-mode table and user-mode
table. Kernel-mode table is identical to the non-PTI table, while
usermode table is obtained from kernel table by leaving userspace
mappings intact, but only leaving the following parts of the kernel
mapped:

    kernel text (but not modules text)
    PCPU
    GDT/IDT/user LDT/task structures
    IST stacks for NMI and doublefault handlers.

Kernel switches to user page table before returning to usermode, and
restores full kernel page table on the entry. Initial kernel-mode
stack for PTI trampoline is allocated in PCPU, it is only 16
qwords.  Kernel entry trampoline switches page tables. then the
hardware trap frame is copied to the normal kstack, and execution
continues.

IST stacks are kept mapped and no trampoline is needed for
NMI/doublefault, but of course page table switch is performed.

On return to usermode, the trampoline is used again, iret frame is
copied to the trampoline stack, page tables are switched and iretq is
executed.  The case of iretq faulting due to the invalid usermode
context is tricky, since the frame for fault is appended to the
trampoline frame.  Besides copying the fault frame and original
(corrupted) frame to kstack, the fault frame must be patched to make
it look as if the fault occured on the kstack, see the comment in
doret_iret detection code in trap().

Currently kernel pages which are mapped during trampoline operation
are identical for all pmaps.  They are registered using
pmap_pti_add_kva().  Besides initial registrations done during boot,
LDT and non-common TSS segments are registered if user requested their
use.  In principle, they can be installed into kernel page table per
pmap with some work.  Similarly, PCPU can be hidden from userspace
mapping using trampoline PCPU page, but again I do not see much
benefits besides complexity.

PDPE pages for the kernel half of the user page tables are
pre-allocated during boot because we need to know pml4 entries which
are copied to the top-level paging structure page, in advance on a new
pmap creation.  I enforce this to avoid iterating over the all
existing pmaps if a new PDPE page is needed for PTI kernel mappings.
The iteration is a known problematic operation on i386.

The need to flush hidden kernel translations on the switch to user
mode make global tables (PG_G) meaningless and even harming, so PG_G
use is disabled for PTI case.  Our existing use of PCID is
incompatible with PTI and is automatically disabled if PTI is
enabled.  PCID can be forced on only for developer's benefit.

MCE is known to be broken, it requires IST stack to operate completely
correctly even for non-PTI case, and absolutely needs dedicated IST
stack because MCE delivery while trampoline did not switched from PTI
stack is fatal.  The fix is pending.

Reviewed by: markj (partially)
Tested by: pho (previous version)
Discussed with: jeff, jhb
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks

6 years agoAmd64 user_ldt_deref() is not used outside sys_machdep.c. Mark it as
kib [Wed, 17 Jan 2018 11:21:03 +0000 (11:21 +0000)]
Amd64 user_ldt_deref() is not used outside sys_machdep.c.  Mark it as
static.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 years agoAdd missing assignment to make sure non-first cmsgs are handled as such.
tuexen [Wed, 17 Jan 2018 10:30:49 +0000 (10:30 +0000)]
Add missing assignment to make sure non-first cmsgs are handled as such.

6 years agoPPC64: implement missing busdma ops
wma [Wed, 17 Jan 2018 09:45:18 +0000 (09:45 +0000)]
PPC64: implement missing busdma ops

Add missing little-endian 64-bit read and write. Since there
is no direct ASM opcode for this, perform byte swap if
necessary.

Created by:            Wojciech Macek <wma@semihalf.com>
Obtained from:         Semihalf
Sponsored by:          QCM Technologies

6 years agoPPC64: fix copyinout ranges
wma [Wed, 17 Jan 2018 09:36:48 +0000 (09:36 +0000)]
PPC64: fix copyinout ranges

Use current userspace address for segment mapping. Previously,
there was a bug which made the funciton constantly using the userspace
base address which could cause data integrity issues.

Created by:            Wojciech Macek <wma@semihalf.com>
Obtained from:         Semihalf
Sponsored by:          QCM Technologies

6 years agoPPC64: add CXGBE and remove AHCI from GENERIC64
wma [Wed, 17 Jan 2018 09:33:16 +0000 (09:33 +0000)]
PPC64: add CXGBE and remove AHCI from GENERIC64

Add CXGBE driver which is required for PowerNV system.
Also, remove AHCI which does not work in BigEndian.

Created by:            Wojciech Macek <wma@semihalf.com>
Obtained from:         Semihalf
Sponsored by:          QCM Technologies

6 years agoPowerNV: workaround console on OPAL 5.4
wma [Wed, 17 Jan 2018 08:01:51 +0000 (08:01 +0000)]
PowerNV: workaround console on OPAL 5.4

FreeBSD prints text char-by-char, which is not what OPAL
is designed to. Poll events more frequently to avoid buffer
overflow and loosing data.

Created by:            Wojciech Macek <wma@semihalf.com>
Obtained from:         Semihalf
Sponsored by:          QCM Technologies

6 years agoPowerNV: make PowerNV PCIe working on a real hardware
wma [Wed, 17 Jan 2018 07:39:11 +0000 (07:39 +0000)]
PowerNV: make PowerNV PCIe working on a real hardware

Fixes:
- map all devices to PE0
- use 1:1 TCE mapping
- provide the same TCE mapping for all PEs (not only PE0)
- add TCE reset and alignment (required by OPAL)

Created by:            Wojciech Macek <wma@semihalf.com>
Obtained from:         Semihalf
Sponsored by:          QCM Technologies

6 years agoRename cgget => cglookup to clear name space for new libufs function cgget.
mckusick [Wed, 17 Jan 2018 06:31:21 +0000 (06:31 +0000)]
Rename cgget => cglookup to clear name space for new libufs function cgget.
No functional change.

6 years agobhndb_pci(4): fix incorrect BHND_PCI_SRSH_PI workaround
landonf [Wed, 17 Jan 2018 03:34:26 +0000 (03:34 +0000)]
bhndb_pci(4): fix incorrect BHND_PCI_SRSH_PI workaround

On a SPROM-less device, the PCI(e) bridge core will be initialized with its
power-on-reset defaults; this can leave the SPROM-derived BHND_PCI_SRSH_PI
value pointing to the wrong backplane address. This value is used by the
PCI core when performing address translation between the static register
windows in BAR0 that map the PCI core's register block, and backplane
address space.

Previously, bhndb_pci(4) incorrectly used the potentially invalid static
BAR0 PCI register windows when attempting to correct the BHND_PCI_SRSH_PI
value in the PCI core's SPROM shadow.

Instead, we now read/update BHND_PCI_SRSH_PI by fetching the PCI core's
backplane address from the core enumeration table, and then using a dynamic
register window to explicitly map the PCI core's register block into BAR0.

Sponsored by: The FreeBSD Foundation

6 years agoSPDX: finish tagging sys/cam.
pfg [Tue, 16 Jan 2018 23:19:57 +0000 (23:19 +0000)]
SPDX: finish tagging sys/cam.

6 years agoRemove redundant critical_enter/exit() calls. The block of code delimited
ian [Tue, 16 Jan 2018 23:18:52 +0000 (23:18 +0000)]
Remove redundant critical_enter/exit() calls.  The block of code delimited
by these calls is now protected by a spin mutex (obscured within the
RTC_LOCK/RTC_UNLOCK macros).

Reported by: bde@

6 years agoMove some code around and rename a couple variables; no functional changes.
ian [Tue, 16 Jan 2018 23:14:12 +0000 (23:14 +0000)]
Move some code around and rename a couple variables; no functional changes.

The static atrtc_set() function was called only from clock_settime(), so
just move its contents entirely into clock_settime() and delete atrtc_set().

Rename the struct bcd_clocktime variables from 'ct' to 'bct'.  I had
originally wanted to emphasize how identical the clocktime and bcd_clocktime
structs were, but things evolved to the point where the structs are not at
all identical anymore, so now emphasizing the difference seems better.

6 years agoscsi_ch.c: Small cleanups to the comments.
pfg [Tue, 16 Jan 2018 23:08:25 +0000 (23:08 +0000)]
scsi_ch.c: Small cleanups to the comments.

Move the the NetBSD tag near to the related licence. Update it to reflect
better the point where we started diverging.

Use grouping parenthesis for the SPDX tag.

No functional change.

6 years agoFix a bug related to fast retransmissions.
tuexen [Tue, 16 Jan 2018 21:58:38 +0000 (21:58 +0000)]
Fix a bug related to fast retransmissions.

When processing a SACK advancing the cumtsn-ack in fast recovery,
increment the miss-indications for all TSN's reported as missing.

Thanks to Fabian Ising for finding the bug and to Timo Voelker
for provinding a fix.

This fix moves also CMT related initialisation of some variables
to a more appropriate place.

MFC after: 1 week

6 years agoUse ln -n instead of -h to allow building the kernel on Linux
arichardson [Tue, 16 Jan 2018 21:43:57 +0000 (21:43 +0000)]
Use ln -n instead of -h to allow building the kernel on Linux

Both flags do the same thing but -n is more widely supported.

Reviewed By: jhb, emaste
Approved By: jhb (mentor)
Differential Revision: https://reviews.freebsd.org/D13936