]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
4 years agoMFC r359166: objcopy: add new sections also when there is no .shstrtab
Ed Maste [Tue, 12 May 2020 23:51:04 +0000 (23:51 +0000)]
MFC r359166: objcopy: add new sections also when there is no .shstrtab

Previously objcopy (elfcopy) --add-sections inserted new sections before
.shstrtab, but omitted them if there was no .shstrtab.

Now, after processing existing sections add new sections if they were
not yet added.

PR: 241437
Reported by: arrowd
Submitted by: Tiger Gao <tig@FreeBSDFoundation.org>
Sponsored by: The FreeBSD Foundation

4 years agoMFC r343969 by nwhitehorn:
Justin Hibbits [Tue, 12 May 2020 21:51:56 +0000 (21:51 +0000)]
MFC r343969 by nwhitehorn:

Performance improvements for octe(4):
- Distribute RX load across multiple cores, if present. This reverts
r217212, which is no longer relevant (I think because of the newer
SDK).
- Use newer APIs for pinning taskqueue entries to specific cores.
- Deepen RX buffers.

This more than doubles NAT forwarding throughput on an EdgeRouter Lite from,
with typical packet mixture, 90 Mbps to over 200 Mbps. The result matches
forwarding throughput in Linux without the UBNT hardware offload on the same
hardware, and thus likely reflects hardware limits.

4 years agoMFC r360777: Optimize ENA Rx refill for low memory conditions
Marcin Wojtas [Tue, 12 May 2020 18:44:41 +0000 (18:44 +0000)]
MFC r360777: Optimize ENA Rx refill for low memory conditions

Sometimes, especially when there is not much memory in the system left,
allocating mbuf jumbo clusters (like 9KB or 16KB) can take a lot of time
and it is not guaranteed that it'll succeed. In that situation, the
fallback will work, but if the refill needs to take a place for a lot of
descriptors at once, the time spent in m_getjcl looking for memory can
cause system unresponsiveness due to high priority of the Rx task. This
can also lead to driver reset, because Tx cleanup routine is being
blocked and timer service could detect that Tx packets aren't cleaned
up. The reset routine can further create another unresponsiveness - Rx
rings are being refilled there, so m_getjcl will again burn the CPU.
This was causing NVMe driver timeouts and resets, because network driver
is having higher priority.

Instead of 16KB jumbo clusters for the Rx buffers, 9KB clusters are
enough - ENA MTU is being set to 9K anyway, so it's very unlikely that
more space than 9KB will be needed.

However, 9KB jumbo clusters can still cause issues, so by default the
page size mbuf cluster will be used for the Rx descriptors. This can have a
small (~2%) impact on the throughput of the device, so to restore
original behavior, one must change sysctl "hw.ena.enable_9k_mbufs" to
"1" in "/boot/loader.conf" file.

As a part of this patch (important fix), the version of the driver
was updated to v2.1.2.

Submitted by:   cperciva
PR:             225791, 234838, 235856, 236989, 243531

4 years agoMFC r360968: libalias: fix potential memory disclosure from ftp module
Ed Maste [Tue, 12 May 2020 16:52:08 +0000 (16:52 +0000)]
MFC r360968: libalias: fix potential memory disclosure from ftp module

admbugs: 956
Submitted by: markj
Reported by: Vishnu Dev TJ working with Trend Micro Zero Day Initiative
Approved by: so
Security: FreeBSD-SA-20:13.libalias
Security: CVE-2020-7455
Security: ZDI-CAN-10849

4 years agoMFC r360967: libalias: validate packet lengths before accessing headers
Ed Maste [Tue, 12 May 2020 16:49:04 +0000 (16:49 +0000)]
MFC r360967: libalias: validate packet lengths before accessing headers

admbugs: 956
Submitted by: ae
Reported by: Lucas Leong (@_wmliang_) of Trend Micro Zero Day Initiative
Reported by: Vishnu working with Trend Micro Zero Day Initiative
Approved by: so
Security: FreeBSD-SA-20:12.libalias
Security: CVE-2020-7454
Security: ZDI-CAN-10624, ZDI-CAN-10850

4 years agoMFC 358394: Use stream_read() to read all 12 bytes of the RFB client version.
John Baldwin [Tue, 12 May 2020 16:05:21 +0000 (16:05 +0000)]
MFC 358394: Use stream_read() to read all 12 bytes of the RFB client version.

read() can return a short read, whereas stream_read() waits until the
full version string is read.

4 years agoMFC r360438:
Mark Johnston [Tue, 12 May 2020 14:01:14 +0000 (14:01 +0000)]
MFC r360438:
Make sendfile(SF_SYNC)'s CV wait interruptible.

4 years agoMFC r360844:
Konstantin Belousov [Tue, 12 May 2020 12:29:39 +0000 (12:29 +0000)]
MFC r360844:
Document BUS_OOMERR.

4 years agoMFC r360676: elfctl: update earliest FreeBSD revision to 12.2
Ed Maste [Tue, 12 May 2020 01:01:48 +0000 (01:01 +0000)]
MFC r360676: elfctl: update earliest FreeBSD revision to 12.2

elfctl has been merged to stable/12, and so will appear in FreeBSD 12.2

Reported by: Dewayne Geraghty
Sponsored by: The FreeBSD Foundation

4 years agoMFC 357643: Tidy the _set_tp function for RISC-V.
John Baldwin [Mon, 11 May 2020 21:24:22 +0000 (21:24 +0000)]
MFC 357643: Tidy the _set_tp function for RISC-V.

- Use a constant for the offset instead of a magic number.
- Use an addi instruction that writes to tp directly instead of a mv
  that writes the result of a compiler-generated addi.

4 years agoMFC 357632: Use the context created in makectx() for stack traces.
John Baldwin [Mon, 11 May 2020 20:58:27 +0000 (20:58 +0000)]
MFC 357632: Use the context created in makectx() for stack traces.

Always use the kdb_thr_ctx() for db_trace_thread() as on other
architectures.  Initialize pcb_ra to be the sepc from the saved
trapframe rather than the saved ra to avoid skipping a frame.

4 years agoMFC 357630: Fix DDB to unwind across exception frames.
John Baldwin [Mon, 11 May 2020 20:41:27 +0000 (20:41 +0000)]
MFC 357630: Fix DDB to unwind across exception frames.

While here, add an extra line of information for exceptions and
interrupts and compress the per-frame line down to one line to match
other architectures.

4 years agoMFC r350571:
Justin Hibbits [Mon, 11 May 2020 20:10:01 +0000 (20:10 +0000)]
MFC r350571:

Fix the build after r350570.

Signed char cannot compare to values above 0x7f.  Use unsigned instead.

4 years agoMFC 357594: Use csr_read() to read sstatus instead of inline assembly.
John Baldwin [Mon, 11 May 2020 19:57:45 +0000 (19:57 +0000)]
MFC 357594: Use csr_read() to read sstatus instead of inline assembly.

While here, remove a local variable to avoid the CSR read in non-debug
kernels.

4 years agoMFC 357595: Fix EXCP_MASK to include all relevant bits from scause.
John Baldwin [Mon, 11 May 2020 18:47:51 +0000 (18:47 +0000)]
MFC 357595: Fix EXCP_MASK to include all relevant bits from scause.

While cause codes higher than 16 are reserved, the exception code
field of the register is defined to be all bits but the upper-most
bit.

4 years agoMFC 356840,357344: Add stricter checks on user changes to SSTATUS.
John Baldwin [Mon, 11 May 2020 16:14:20 +0000 (16:14 +0000)]
MFC 356840,357344: Add stricter checks on user changes to SSTATUS.

356840:
Check for invalid sstatus values in set_mcontext().

Previously, this check was only in sys_sigreturn() which meant that
user applications could write invalid values to the register via
setcontext() or swapcontext().

357344:
Add stricter checks on user changes to SSTATUS.

Rather than trying to blacklist which bits userland can't write to via
sigreturn() or setcontext(), only permit changes to whitelisted bits.

- Permit arbitrary writes to bits in the user-writable USTATUS
  register that shadows SSTATUS.

- Ignore changes in write-only bits maintained by the CPU.

- Ignore the user-supplied value of the FS field used to track
  floating point state and instead set it to a value matching the
  actions taken by set_fpcontext().

4 years agoMFC r360381:
Mark Johnston [Mon, 11 May 2020 15:21:03 +0000 (15:21 +0000)]
MFC r360381:
Add some regression tests for read and write kevents on pipes.

4 years agoMFC r360380:
Mark Johnston [Mon, 11 May 2020 15:20:40 +0000 (15:20 +0000)]
MFC r360380:
Fix handling of EV_EOF for named pipes.

PR: 203366, 224615, 246350

4 years agoMFC r360379:
Mark Johnston [Mon, 11 May 2020 15:20:05 +0000 (15:20 +0000)]
MFC r360379:
Call pipeselwakeup() after toggling PIPE_EOF.

4 years agoMFC r360378:
Mark Johnston [Mon, 11 May 2020 15:17:57 +0000 (15:17 +0000)]
MFC r360378:
Avoid returning POLLIN if the pipe descriptor is not open for reading.

4 years agoMFC r360619:
Xin LI [Mon, 11 May 2020 07:20:37 +0000 (07:20 +0000)]
MFC r360619:
 - Fix logic error in swapoff case: follow same handling of p and
   linelen in the swapon case.
 - Use strlcpy instead of strncpy.

4 years agoMFC r360836:
Toomas Soome [Mon, 11 May 2020 06:59:01 +0000 (06:59 +0000)]
MFC r360836:

loader: vdev_read() can corrupt memory

When reading less than sector size but from sector boundary,
the vdev_read() will read full sector into the provided buffer
and therefore corrupting memory past buffer end.

4 years agoMFC r360801: Merge commit 21e5e1724b75 from llvm git:
Ed Maste [Sun, 10 May 2020 14:56:25 +0000 (14:56 +0000)]
MFC r360801: Merge commit 21e5e1724b75 from llvm git:

  getMainExecutable: Fix hand-rolled AT_EXECPATH for older FreeBSD

  Once we hit AT_NULL, we need to bail out of the loop; not just the
  enclosing switch.  This fixes basic usage (e.g. `cc --version`) when
  AT_EXECPATH isn't present on older branches (e.g. under
  emu-user-static, at the moment), where we would previously run off
  the end of ::environ.

  Patch By: kevans

  Reviewed By: arichardson

4 years agoMFC 356839: Save and restore floating point registers in get/set_mcontext().
John Baldwin [Sun, 10 May 2020 14:53:08 +0000 (14:53 +0000)]
MFC 356839: Save and restore floating point registers in get/set_mcontext().

arm64 and riscv were only saving and restoring floating point
registers for sendsig() and sys_sigreturn(), but not for getcontext(),
setcontext(), and swapcontext().

While here, remove an always-false check for uap being NULL from
sys_sigreturn().

4 years agoMerge r360138:
Gleb Smirnoff [Sun, 10 May 2020 14:46:46 +0000 (14:46 +0000)]
Merge r360138:

  Fix immediate crash when snmpd is bound to a specific IP address.

  The code that sets up msghdr must first fully fill in the msghdr
  itself, and only then use CMSG_xxx() macros.

PR: 246323

4 years agoMFC r360609:
Kristof Provost [Sun, 10 May 2020 09:50:44 +0000 (09:50 +0000)]
MFC r360609:

pf: Improve DIOCADDRULE validation

We expect the addrwrap.p.dyn value to be set to NULL (and assert such),
but do not verify it on input.

Reported-by: syzbot+936a89182e7d8f927de1@syzkaller.appspotmail.com

4 years agoMFC r360610: Add session locking in cfiscsi_ioctl_handoff().
Alexander Motin [Sun, 10 May 2020 02:13:38 +0000 (02:13 +0000)]
MFC r360610: Add session locking in cfiscsi_ioctl_handoff().

While there, remove ifdef around cs_target check in cfiscsi_ioctl_list().
I am not sure why this ifdef was added, but without this check code will
crash below on NULL dereference.

4 years agoMFC 357255,357337: Fix definition of SSTATUS_SD and MSTATUS_SD.
John Baldwin [Sun, 10 May 2020 00:34:09 +0000 (00:34 +0000)]
MFC 357255,357337: Fix definition of SSTATUS_SD and MSTATUS_SD.

357255:
Fix definition of SSTATUS_SD

The SD bit is defined as the MSB of the sstatus register, meaning its
position will vary depending on the CSR's length. Previously, there were
two (unused) defines for this, for the 32 and 64-bit cases, but their
definitions were swapped.

Consolidate these into one define: SSTATUS_SD, and make the definition
dependent on the value of __riscv_xlen.

357337:
Fix 64-bit value of SSTATUS_SD to use an unsigned long.

While here, fix MSTATUS_SD to match SSTATUS_SD.

4 years agoMFC 357313: Trim duplicate CSR swaps from user exceptions.
John Baldwin [Sat, 9 May 2020 21:34:50 +0000 (21:34 +0000)]
MFC 357313: Trim duplicate CSR swaps from user exceptions.

The stack pointer is swapped with the sscratch CSR just before the
jump to cpu_exception_handler_user where the first instruction swaps
it again.  The two swaps together are a no-op, but the csr swap
instructions can be expensive (e.g. on Bluespec RISC-V cores csr swap
instructions force a full pipeline stall).

4 years agoMFC 357305: Remove unused fields from struct pcb.
John Baldwin [Sat, 9 May 2020 21:32:44 +0000 (21:32 +0000)]
MFC 357305: Remove unused fields from struct pcb.

cpu_switch/throw() and savectx() do not save or restore any values in
these fields which mostly held non-callee-save registers.

makectx() copied these fields from kdb_frame, but they weren't used
except for PC_REGS using pcb_sepc.  Change PC_REGS to use
kdb_frame->tf_sepc directly instead.

4 years agoMFC 357591:
John Baldwin [Sat, 9 May 2020 20:14:05 +0000 (20:14 +0000)]
MFC 357591:
Read the breakpoint instruction to determine its length in BKPT_SKIP.

This fixes continuing from debug.kdb.enter=1 after enabling the use of
compressed instructions since the compiler can emit the two byte
c.ebreak instead of the 4 byte ebreak.

4 years agoMFC 357593: Remove stale workaround for the htif console.
John Baldwin [Sat, 9 May 2020 20:10:01 +0000 (20:10 +0000)]
MFC 357593: Remove stale workaround for the htif console.

In practice this discarded all characters entered at the DDB prompt.

4 years agoMFC 354289,354441,355095: Use lld on armv6.
John Baldwin [Sat, 9 May 2020 20:02:48 +0000 (20:02 +0000)]
MFC 354289,354441,355095: Use lld on armv6.

354289:
armv6: Switch to LLD by default

This could just be ${__TT} == "arm", except armv5 isn't slated for death until
EOY.

arm tinderbox builds.  Let's see what else shakes out.

354441:
arch.7: armv6 uses lld by default as of r354289

355095:
remove armv6 LLVM workaround introduced in r341812

r341812 enabled only arm target support in LLVM on arm and armv6,
because ld.bfd 2.17.50 lacked support for range extensions required for
linking such large binaries/libraries.  r341812 indicated that the
workaround should be removed once the userland can be linked by lld.

r354289 switched armv6 to use lld by default, so remove the workaround
on armv6.  The workaround remains in place for arm (v5), and will
presumably be removed when arm is retired.

4 years agoMFC 356499: Use clang and lld as the default toolchain for RISCV.
John Baldwin [Sat, 9 May 2020 17:14:59 +0000 (17:14 +0000)]
MFC 356499: Use clang and lld as the default toolchain for RISCV.

- Enable clang and lld as system toolchains.
- Don't use external GCC for universe by default.
- Re-enable riscv64sf since it builds fine with clang + lld.

Sponsored by: DARPA

4 years agoMFC r358689 (by jhibbits):
Dimitry Andric [Sat, 9 May 2020 11:18:34 +0000 (11:18 +0000)]
MFC r358689 (by jhibbits):

Fix a mistaken conditional in mfi_tbolt_send_frame()

As written, the condition of (cdb[0] != 0x28 || cdb[0] != 0x2A) will always
be true, since if it's one, it's obviously not the other.  Reading the code,
the intent appears to be that it should only perform the operation if it's
neither, otherwise the conditional can be elided.

Found by clang 10.

4 years agoMFC of 356666
Kirk McKusick [Sat, 9 May 2020 05:04:02 +0000 (05:04 +0000)]
MFC of 356666

Fix the way 'factor' behaves when using OpenSSL to match the description
of how it works when not compiled with OpenSSL.

4 years agoMFC 354603,354604,354717,354718: Sync PLIC code with head.
John Baldwin [Fri, 8 May 2020 15:05:05 +0000 (15:05 +0000)]
MFC 354603,354604,354717,354718: Sync PLIC code with head.

354603:
plic: fix PLIC_MAX_IRQS

The maximum number of PLIC interrupts is defined in the PLIC spec[1]
as 1024.

354604:
plic: check for sifive compatible string

The Linux dts for the HiFive Unleashed does not contain the usual
"riscv,plic0" compat string, but our PLIC driver is compatible.

354717:
plic: fix context calculation

The RISC-V PLIC (platform level interrupt controller) registers are divided up
by "context", which is purposefully left ambiguous in the PLIC spec. Currently
we assume each CPU number corresponds 1-to-1 with a context number, but that is
not correct. Most existing PLIC implementations (such as SiFive's) have
multiple contexts per-cpu. For example, a single CPU might have a context for
machine mode interrupts and a context for supervisor mode interrupts. To
complicate things further, FreeBSD renumbers the CPUs during boot, but the PLIC
driver still assumes that CPU ID equals the RISC-V hart number, meaning
interrupt enables/claims might be performed for the wrong context registers.

To fix this, we must calculate each CPU's context number during
attachment. This is done by reading the interrupt properties from the
device tree, from which a mapping from context to RISC-V hart to CPU
number can be created.

354718:
plic: support irq distribution

Our PLIC implementation only enables interrupts on the boot cpu.
Implement plic_bind_intr() so that they can be redistributed near the
end of boot during intr_irq_shuffle().

This also slightly modifies how enable bits are handled in an attempt to
better fit the PIC interface. plic_enable_intr()/plic_disable_intr() are
converted to manage an interrupt source's threshold value, since this
value can be used as to globally enable/disable an irq. All handing of the
per-context enable bits is moved to the new methods plic_setup_intr()
and plic_bind_intr().

4 years agoMFC 348611: Expose the kernel's build-ID through sysctl
John Baldwin [Fri, 8 May 2020 14:48:45 +0000 (14:48 +0000)]
MFC 348611: Expose the kernel's build-ID through sysctl

After our migration (of certain architectures) to lld the kernel is built
with a unique build-ID.  Make it available via a sysctl and uname(1) to
allow the user to identify their running kernel.

4 years agoMFC r360277:
Mark Johnston [Fri, 8 May 2020 14:13:30 +0000 (14:13 +0000)]
MFC r360277:
Fix handling of 1GB mappings in the arm64 minidump code.

4 years agoMFC r360280:
Mark Johnston [Fri, 8 May 2020 14:10:47 +0000 (14:10 +0000)]
MFC r360280:
Fix a race between _pmap_unwire_ptp() and MipsDoTLBMiss().

4 years agoMFC r360281:
Mark Johnston [Fri, 8 May 2020 14:10:29 +0000 (14:10 +0000)]
MFC r360281:
Fix a race in pmap_emulate_modified().

4 years agoMFC 354719,354720,354721,354722,357480: OpenSBI support.
John Baldwin [Fri, 8 May 2020 05:30:10 +0000 (05:30 +0000)]
MFC 354719,354720,354721,354722,357480: OpenSBI support.

354719:
RISC-V: pass arg6 in sbi_call

Allow for an additional argument to sbi_call which will be passed in a6.
This is required for SBI spec 0.2 support, as a6 will indicate the SBI
function ID.

While here, introduce some macros to clean up the calls.

354720:
RISC-V: add support for SBI spec v0.2

The Supervisor Binary Interface (SBI) specification v0.2 is a backwards
incompatible update to the SBI call interface for kernels running in
supervisor mode. The goal of this update was to make it easier for new
and optional functionality to be added to the SBI.

SBI functions are now called by passing an "extension ID" and a
"function ID" which are passed in a7 and a6 respectively. SBI calls
will also return an error and value in the following struct:

struct sbi_ret {
    long error;
    long value;
}

This version introduces several new functions under the "base"
extension. It is expected that all SBI implementations >= 0.2 will
support this base set of functions, as they implement some essential
services such as obtaining the SBI version, CPU implementation info, and
extension probing.

Existing SBI functions have been designated as "legacy". For the time
being they will remain implemented, but it is expected that in the
future their functionality will be duplicated or replaced by new SBI
extensions. Each legacy function has been assigned its own extension ID,
and for now we simply probe and assert for their existence.

Compatibility with legacy SBI implementations (such as BBL) is
maintained by checking the output of sbi_get_spec_version(). This
function is guaranteed to succeed by the new spec, but will return an
error in legacy implementations. We use this as an indicator of whether
or not we can rely on the new SBI base extensions.

For further info on the Supervisor Binary Interface, see:
https://github.com/riscv/riscv-sbi-doc/blob/master/riscv-sbi.adoc

354721:
Add missing files from r354720

354722:
RISC-V: Print SBI info at startup

SBI version 0.2 introduces functions for obtaining the details of the
SBI implementation, such as version and implemntation ID. Print this
info at startup when it is available.

357480:
Set the LMA of the riscv kernel to the OpenSBI jump target by default

This allows us to boot FreeBSD RISCV on QEMU using the -kernel command line
options. When using that option, QEMU maps the kernel ELF file to the
addresses specified in the LMAs in the program headers.

Since version 4.2 QEMU ships with OpenSBI fw_jump by default so this allows
booting FreeBSD using the following command line:
qemu-system-riscv64 -bios default -kernel /.../boot/kernel/kernel -nographic -M virt

Without this change the -kernel option cannot be used since the LMAs start
at address zero and QEMU already maps a ROM to these low physical addresses.

For targets that require a different kernel LMA the make variable
KERNEL_LMA can be overwritten in the config file. For example, adding
`makeoptions    KERNEL_LMA=0xc0200000` will create an ELF file that will be
loaded at 0xc0200000.

Before:
There are 4 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  LOAD           0x001000 0xffffffc000000000 0x0000000000000000 0x75e598 0x8be318 RWE 0x1000
  DYNAMIC        0x71fb20 0xffffffc00071eb20 0x000000000071eb20 0x000100 0x000100 RW  0x8
  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x0
  NOTE           0x693400 0xffffffc000692400 0x0000000000692400 0x000024 0x000024 R   0x4

After:

There are 4 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  LOAD           0x001000 0xffffffc000000000 0x0000000080200000 0x734198 0x893e18 RWE 0x1000
  DYNAMIC        0x6f7810 0xffffffc0006f6810 0x00000000808f6810 0x000100 0x000100 RW  0x8
  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x0
  NOTE           0x66ca70 0xffffffc00066ba70 0x000000008086ba70 0x000024 0x000024 R   0x4

4 years agoMFC r360231:
Kristof Provost [Thu, 7 May 2020 21:14:11 +0000 (21:14 +0000)]
MFC r360231:

libc: Shortcut if_indextoname() if index == 0

If the index we're trying to convert is 0 we can avoid a potentially
expensive call to getifaddrs(). No interface has an ifindex of zero, so
we can handle this as an error: set the errno to ENXIO and return NULL.

Submitted by: Nick Rogers
Sponsored by: RG Nets

4 years agoMFC r358887:
Li-Wen Hsu [Thu, 7 May 2020 20:27:32 +0000 (20:27 +0000)]
MFC r358887:

Temporarily skip 2 failing tests after llvm10 import

PR: 244732
Sponsored by: The FreeBSD Foundation

4 years agoMFC 356481:
John Baldwin [Thu, 7 May 2020 19:19:39 +0000 (19:19 +0000)]
MFC 356481:
Work around lld's inability to handle undefined weak symbols on risc-v.

lld on RISC-V is not yet able to handle undefined weak symbols for
non-PIC code in the code model (medany/medium) used by the RISC-V
kernel.

Both GCC and clang emit an auipc / addi pair of instructions to
generate an address relative to the current PC with a 31-bit offset.
Undefined weak symbols need to have an address of 0, but the kernel
runs with PC values much greater than 2^31, so there is no way to
construct a NULL pointer as a PC-relative value.  The bfd linker
rewrites the instruction pair to use lui / addi with values of 0 to
force a NULL pointer address.  (There are similar cases for 'ld'
becoming auipc / ld that bfd rewrites to lui / ld with an address of
0.)

To work around this, compile the kernel with -fPIE when using lld.
This does not make the kernel position-independent, but it does
force the compiler to indirect address lookups through GOT entries
(so auipc / ld against a GOT entry to fetch the address).  This
adds extra memory indirections for global symbols, so should be
disabled once lld is finally fixed.

A few 'la' instructions in locore that depend on PC-relative
addressing to load physical addresses before paging is enabled have to
use auipc / addi and not indirect via GOT entries, so change those to
use 'lla' which always uses auipc / addi for both PIC and non-PIC.

Note that the followup fix for SMP (r356675) was previously merged to
stable/12.

4 years agoMFC 357145: Compile hack.c with normal CFLAGS + -shared -nostdlib.
John Baldwin [Thu, 7 May 2020 18:47:54 +0000 (18:47 +0000)]
MFC 357145: Compile hack.c with normal CFLAGS + -shared -nostdlib.

Originally, hack.c was compiled into a shard object with just -shared
-nostdlib.  This assumed that ${CC} did not require any additional
flags for ABIs, cross-building, etc.

When kern.post.mk was created in r89509 by reducing duplication in
kernel Makefile.<arch> files, the -shared flag was moved into a
HACK_EXTRA_FLAGS variable so that sparc64 could override it with
-Wl,-shared.  The sparc64 hack was removed in r111650, but
HACK_EXTRA_FLAGS was left in place.  Over time, we have started
support toolchains that require flags to support alternate ABIs on
MIPS and PowerPC and started (ab)using HACK_EXTRA_FLAGS to set only
those flags.

I need to fix risc-v to pass -mno-relax to the hack.c build for lld in
llvm 10, and the patches to support cross-build from non-FreeBSD hosts
need to include -target for clang in CFLAGS for hack.c.  Rather than
adding more hacks into HACK_EXTRA_FLAGS, just use the full set of
CFLAGS with hack.c.

4 years agoMFC 355403: Use "far" calls and branches so that lld uses valid relocations.
John Baldwin [Thu, 7 May 2020 15:59:55 +0000 (15:59 +0000)]
MFC 355403: Use "far" calls and branches so that lld uses valid relocations.

Conditional branch and jump instructions do not always call via PLT
stubs and thus will not honor LD_PRELOAD, etc.  lld warns about using
non-preemptible relocations for preemptible or unknown symbols whereas
bfd does not (at least for RISC-V).

4 years agoMFC r360498:
Mark Johnston [Thu, 7 May 2020 14:49:17 +0000 (14:49 +0000)]
MFC r360498:
Increase the iflib txq callout mutex name length to 32 bytes.

PR: 245712

4 years agoMFC 355428,356504: Add a new "riscv-relaxations" linker feature.
John Baldwin [Thu, 7 May 2020 14:20:52 +0000 (14:20 +0000)]
MFC 355428,356504: Add a new "riscv-relaxations" linker feature.

355428:
Add a new "riscv-relaxations" linker feature.

When the linker doesn't have this feature, add -mno-relax to CFLAGS
on RISC-V.

Define the feature for ld.bfd, but not lld.  If lld gains relaxation
support in a newer version, we can enable it for those versions of lld
in bsd.linker.mk.

356504:
Add -mno-relax to CFLAGS in bsd.prog/lib.mk instead of bsd.cpu.mk.

bsd.cpu.mk is included by bsd.init.mk before bsd.linker.mk, so it
was always setting the flag since LINKER_FEATURES wasn't defined.

4 years agoMFC 360202,360206: Deprecate 3des support in IPsec for FreeBSD 13.
John Baldwin [Wed, 6 May 2020 23:23:22 +0000 (23:23 +0000)]
MFC 360202,360206: Deprecate 3des support in IPsec for FreeBSD 13.

360202:
Deprecate 3des support in IPsec for FreeBSD 13.

RFC 8221 does not outright ban 3des as the algorithms deprecated for
13 in r348205, but it is listed as a SHOULD NOT and will likely be a
MUST NOT by the time 13 ships.

360206:
Fix name of 3DES cipher in deprecation warning.

Sponsored by: Chelsio Communications

4 years agoMFC 358415: Rename TOE TLS stats from [rt]x_tls_* to [rt]x_toe_tls_*.
John Baldwin [Wed, 6 May 2020 22:49:21 +0000 (22:49 +0000)]
MFC 358415: Rename TOE TLS stats from [rt]x_tls_* to [rt]x_toe_tls_*.

This more clearly differentiates TLS records encrypted and decrypted
in TOE connections from those encrypted via NIC TLS.

Sponsored by: Chelsio Communications

4 years agoMFC 354667,354686: Share routines for dealing with T6 key contexts.
John Baldwin [Wed, 6 May 2020 22:44:53 +0000 (22:44 +0000)]
MFC 354667,354686: Share routines for dealing with T6 key contexts.

354667:
Create a file to hold shared routines for dealing with T6 key contexts.

ccr(4) and TLS support in cxgbe(4) construct key contexts used by the
crypto engine in the T6.  This consolidates some duplicated code for
helper functions used to build key contexts.

354686:
Add t4_keyctx.c to sys/conf/files for the non-module build.

Missed in r354667.

Sponsored by: Chelsio Communications

4 years agoMFC 355724,360166: Software breakpoints on Intel CPUs.
John Baldwin [Wed, 6 May 2020 22:20:37 +0000 (22:20 +0000)]
MFC 355724,360166: Software breakpoints on Intel CPUs.

355724:
Support software breakpoints in the debug server on Intel CPUs.

- Allow the userland hypervisor to intercept breakpoint exceptions
  (BP#) in the guest.  A new capability (VM_CAP_BPT_EXIT) is used to
  enable this feature.  These exceptions are reported to userland via
  a new VM_EXITCODE_BPT that includes the length of the original
  breakpoint instruction.  If userland wishes to pass the exception
  through to the guest, it must be explicitly re-injected via
  vm_inject_exception().

- Export VMCS_ENTRY_INST_LENGTH as a VM_REG_GUEST_ENTRY_INST_LENGTH
  pseudo-register.  Injecting a BP# on Intel requires setting this to
  the length of the breakpoint instruction.  AMD SVM currently ignores
  writes to this register (but reports success) and fails to read it.

- Rework the per-vCPU state tracked by the debug server.  Rather than
  a single 'stepping_vcpu' global, add a structure for each vCPU that
  tracks state about that vCPU ('stepping', 'stepped', and
  'hit_swbreak').  A global 'stopped_vcpu' tracks which vCPU is
  currently reporting an event.  Event handlers for MTRAP and
  breakpoint exits loop until the associated event is reported to the
  debugger.

  Breakpoint events are discarded if the breakpoint is not present
  when a vCPU resumes in the breakpoint handler to retry submitting
  the breakpoint event.

- Maintain a linked-list of active breakpoints in response to the GDB
  'Z0' and 'z0' packets.

360166:
Add description string for VM_CAP_BPT_EXIT.

While here, replace the array of mapping structures with an array of
string pointers where the index is the capability value.

4 years agoMFC r360519:
Mitchell Horne [Wed, 6 May 2020 19:58:37 +0000 (19:58 +0000)]
MFC r360519:

Add RISC-V interpreter example

4 years agoMFC r360082:
Mitchell Horne [Wed, 6 May 2020 19:50:27 +0000 (19:50 +0000)]
MFC r360082:

Convert arm's physmem interface to MI code

4 years agoMFC r359974:
Brooks Davis [Wed, 6 May 2020 17:12:26 +0000 (17:12 +0000)]
MFC r359974:

Don't directly access userspace memory.

Rather then using the racy useracc() followed by direct access to
userspace memory, perform a copyin() and use the result if it succeeds.

Reviewed by: jhb
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D24410

4 years agoUpdate a few more kernel configs for tun -> tuntap.
John Baldwin [Wed, 6 May 2020 05:29:00 +0000 (05:29 +0000)]
Update a few more kernel configs for tun -> tuntap.

4 years agoMFC r360460: liblua: ensure that "require" will fail in bootstrap flua
Ed Maste [Wed, 6 May 2020 00:25:43 +0000 (00:25 +0000)]
MFC r360460: liblua: ensure that "require" will fail in bootstrap flua

We do not want to support bootstrapping lua modules, so ensure that
require will fail by providing a nonexistent path.

Sponsored by: The FreeBSD Foundation

4 years agoMFC 357062: Correct the return types of fueword*().
John Baldwin [Tue, 5 May 2020 04:42:47 +0000 (04:42 +0000)]
MFC 357062: Correct the return types of fueword*().

4 years agoMFC 356508: Use falloc_noinstall + finstall for crypto file descriptors.
John Baldwin [Tue, 5 May 2020 04:37:05 +0000 (04:37 +0000)]
MFC 356508: Use falloc_noinstall + finstall for crypto file descriptors.

4 years agoMFC 355683: Don't call into the debug server if it isn't configured.
John Baldwin [Tue, 5 May 2020 04:25:25 +0000 (04:25 +0000)]
MFC 355683: Don't call into the debug server if it isn't configured.

4 years agoMFC: r360517
Jung-uk Kim [Mon, 4 May 2020 21:09:35 +0000 (21:09 +0000)]
MFC: r360517

Merge ACPICA 20200430.

4 years agoMFC r360126, r360132: Change kern.evdev.rcpt_mask to 12 by default
Niclas Zeising [Mon, 4 May 2020 18:40:56 +0000 (18:40 +0000)]
MFC r360126, r360132: Change kern.evdev.rcpt_mask to 12 by default

Original commit messages:
Change kern.evdev.rcpt_mask from 3 to 12 by default.  This makes us much
more evdev-friendly, and will prevent everyone using xorg and wayland with
evdev devices (the default) from needing to change this locally.

powerpc32 still uses the old value for the keyboard part, becaues the adb
keyboard driver used there is not evdev compatible.

In r360126, I meant to have a different mask only on powerpc, not powerpc64.
Update the check to check that we're not compiling for powerpc64.

Approved by: wulf (implicit, mfc)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D24370

4 years agoMFC 355600: Add a callout_func_t typedef for functions used with callout_*().
John Baldwin [Mon, 4 May 2020 16:30:36 +0000 (16:30 +0000)]
MFC 355600: Add a callout_func_t typedef for functions used with callout_*().

This typedef is the same as timeout_t except that it is in the callout
namespace and header.

Use this typedef in various places of the callout implementation that
were either using the raw type or timeout_t.

While here, add <sys/callout.h> to the manpage.

4 years agoMFC r340701: Add NT_FREEBSD_FEATURE_CTL ELF note to csu
Ed Maste [Mon, 4 May 2020 15:57:13 +0000 (15:57 +0000)]
MFC r340701: Add NT_FREEBSD_FEATURE_CTL ELF note to csu

This note will be used to allow binaries to opt out of, or in to,
upcoming vulnerability mitigation and other features.  It is not yet
connected but being added now to facilitate testing and ensure
compatibility with existing kernels and tools.

Sponsored by: The FreeBSD Foundation

4 years agoMFC r360373:
Mark Johnston [Mon, 4 May 2020 12:28:44 +0000 (12:28 +0000)]
MFC r360373:
iwm: Print the command code for any unhandled commands.

4 years agoMFC r360384:
Mark Johnston [Mon, 4 May 2020 12:27:46 +0000 (12:27 +0000)]
MFC r360384:
Document handling of connection-mode sockets by sendto(2).

PR: 245817

4 years agoMove id_mapped to end of bus_dma_impl structure to preserve KPI for 12-stable.
Hans Petter Selasky [Mon, 4 May 2020 07:57:55 +0000 (07:57 +0000)]
Move id_mapped to end of bus_dma_impl structure to preserve KPI for 12-stable.

This is a direct commit.

Bump the __FreeBSD_version to force recompilation of external kernel modules.

Reported by: kib @
Sponsored by: Mellanox Technologies

4 years agoMFC r360355:
Vladimir Kondratyev [Sun, 3 May 2020 23:40:16 +0000 (23:40 +0000)]
MFC r360355:

ig4(4): Add PCI IDs for Intel Bay Trail I2C controllers.

PR: 245654
Reported by: <xspbe3ho3p5uac@protonmail.com>

4 years agoMFC r360353:
Vladimir Kondratyev [Sun, 3 May 2020 23:38:21 +0000 (23:38 +0000)]
MFC r360353:

psm(4): Fix wrong key-release event occuring after trackpoint use.

Some models of laptops e.g. "X1 Carbon 3rd Gen Thinkpad" have LRM buttons
wired as so called "Synaptic touchpads extended buttons" rather thah real
trackpoint buttons. Handle this case with merging of events from both
sources.

PR: 245877
Reported by: Raichoo <raichoo@googlemail.com>

4 years agoMFC r360260:
Mark Johnston [Sun, 3 May 2020 17:50:24 +0000 (17:50 +0000)]
MFC r360260:
Stop setting PG_U in bootstrap mappings.

4 years agoMFC r360344:
Kristof Provost [Sun, 3 May 2020 16:06:17 +0000 (16:06 +0000)]
MFC r360344:

pf: Improve input validation

If we pass an anchor name which doesn't exist pfr_table_count() returns
-1, which leads to an overflow in mallocarray() and thus a panic.

Explicitly check that pfr_table_count() does not return an error.

Reported-by: syzbot+bd09d55d897d63d5f4f4@syzkaller.appspotmail.com

4 years agoMFC r360356:
Ryan Moeller [Sun, 3 May 2020 08:13:44 +0000 (08:13 +0000)]
MFC r360356:

sockstat: Attach to jail if in new vnet

Attach sockstat -j to the specified jail if the jail is in a new vnet.
Otherwise we do not see all sockets belonging to the jail.

Reviewed by:    jamie
Approved by:    mmacy (mentor)
Differential Revision:  https://reviews.freebsd.org/D24413

4 years agoMFC lualoader read-conf support: r360420-r360423, r360425, r360427, r360486,
Kyle Evans [Sun, 3 May 2020 03:53:38 +0000 (03:53 +0000)]
MFC lualoader read-conf support: r360420-r360423, r360425, r360427, r360486,
\r360505-r360506

r360420:
lualoader config: don't call loader.getenv() as much

We don't actually need to fetch loader_conf_files as much as we do; we've
already fetched it once at the beginning, we only really need to fetch it
again after each file we've processed. If it changes, then we can stash that
off into our local prefiles.

While here, drop a note about the recursion so that I stop trying to
change it. It may very well make redundant some of the work we're doing, but
that's OK.

r360421:
lualoader: config: start exporting readConfFiles

In the process, change it slightly: readConfFiles will take a string like
loader_conf_files in addition to the loaded_files table that it normally
takes. This is to facilitate the addition of a read-conf CLI command, which
will just pass in the single file to read and an empty table.

r360422:
lualoader: cli: add read-conf

This is a straightforward match to the command used by many in forthloader;
it uses the newly-exported config.readConfFiles() to make sure that any
loader_conf_files gets done as appropriate.

r360423:
lualoader: cli: clobber loader_conf_files before proceeding

This makes sure that config.readConfFiles doesn't see a stale
loader_conf_files from before, in case the newly loaded file doesn't set it.

r360425:
config.lua(8): "may should" is not proper grammar

r360427:
config.lua(8): catch up to recently added hooks

While we're here, let's stylize these as functions instead of just raw text.
A future change may allow arbitrary data arguments to be passed some of
these, and the distinction is useful.

r360486:
loader.conf(5): document that loader_conf_files may be clobbered

A future change in lualoader may take some liberties with the
loader_conf_files in the name of efficiency; namely, it may start omitting
it from the loader environment entirely so that it doesn't need to worry
about maintaining any specific value.

This variable has historically been incredibly volatile anyways, as it may
get set to completely different values in any given configuration file to
trigger a load of more files.

Document now that we may not maintain it in the future, but perhaps we'll
reserve the right to change our minds and eventually formally export all of
the loader configuration files that were read using this variable.

r360505:
lualoader: config: add a table for restricted environment vars

This new table should be used for transient values that don't need to end up
in the loader environment. Generally, these will be things that are internal
details that really aren't needed or interesting outside of the config
module (e.g. if we changed how ${module}_* directives work, they might use
this instead).

To start, populate it with loader_conf_files. Any specific value of
loader_conf_files isn't all that interesting; if we're going to export it,
we should really instead export a loader_conf_files that indicates all of
the configuration files we processed. This will be used to reduce
bookkeeping overhead in a future commit that cleans up readConfFiles.

r360506:
lualoader: config: improve readConfFiles, rename to readConf

The previous interface was pretty bad, and required the caller to get some
implementation details correct that it really shouldn't need to (e.g.
loader_conf_files handling) and pass in an empty table for it to use.

The new and much improved interface, readConf, is much less of a hack;
hiding these implementation details and just doing the right thing.
config.lua will now use it to process /boot/defaults/loader.conf and the
subsequent loader_conf_files from there, and read-conf will also use it.

This improvement submitted by Olivier (cited below), loader_conf_files
handling from the original patch was changed to just clobber it before
processing and not bother restoring it after the fact following r360505
where it's now guaranteed to evade the loader environment.

PR: 244640

4 years agoMFC r360437: diff(1): don't reject specifying the same format multiple times
Kyle Evans [Sun, 3 May 2020 03:44:58 +0000 (03:44 +0000)]
MFC r360437: diff(1): don't reject specifying the same format multiple times

This may happen, for instance, if one happens to have an alias of diff to
diff -up and attempts to specify the amount of context on top of that.

Aliases like this may cause other problems, but if they're really not ever
generating non-unified diffs then we should at least not break that
use-case.

In addition, we'll now pick up a format mismatch if -p is specified with
!contextual && !unified && !unset.

Fix up a small trailing whitespace nit in the tests while we're here, and
add tests to make sure that we can double up all the formatting options.

4 years agoMFC r360100:
Cy Schubert [Sun, 3 May 2020 03:21:42 +0000 (03:21 +0000)]
MFC r360100:

fib4_free_nh_ext is an empty function. It does nothing. Don't call it.

4 years agoMFC 354661,354693: Fix WITH_CLANG_BOOTSTRAP without WITH_CLANG_IS_CC.
John Baldwin [Sat, 2 May 2020 13:42:03 +0000 (13:42 +0000)]
MFC 354661,354693: Fix WITH_CLANG_BOOTSTRAP without WITH_CLANG_IS_CC.

354661:
Force MK_CLANG_IS_CC on in XMAKE.

This ensures that a bootstrap clang compiler is always installed as cc
in WORLDTMP.  If it is only installed as 'clang' then /usr/bin/cc is
used during the build instead of the bootstrap compiler.

354693:
Refine r354661 to unbreak the GCC_BOOTSTRAP case.

MK_CLANG_IS_CC controls installing links for GCC, not just clang.  Set
MK_CLANG_IS_CC to the value of MK_CLANG_BOOTSTRAP.  This will leave it
as "no" if no bootstrap compiler is being built or GCC 4.2.1 is being
used as the bootstrap compiler, and "yes" if clang is being used as
the bootstrap compiler.

4 years agoMFC: r360032
Rick Macklem [Fri, 1 May 2020 22:37:09 +0000 (22:37 +0000)]
MFC: r360032
Add a sanity check for nes_numsecflavor to the NFS server.

Ryan Moeller reported crashes in the NFS server that appear to be
caused by stack corruption in nfsrv_compound(). It appears that
the stack got corrupted just after a NFSv4.1 Lookup that crosses
a server mount point.
Although it is just a "theory" at this point, the most obvious way
the stack could get corrupted would be if nfsvno_checkexp() somehow
acquires an export with a bogus nes_numsecflavor value. This would
cause the copying of the secflavors to run off the end of the array,
which is allocated on the stack below where the corruption occurs.

This sanity check is simple to do and would stop the stack corruption
if the theory is correct. Otherwise, doing the sanity check seems to
be a reasonable safety belt to add to the code.

4 years agoMFC r360211:
Navdeep Parhar [Fri, 1 May 2020 21:22:26 +0000 (21:22 +0000)]
MFC r360211:

cxgbe/iw_cxgbe: Create a LinuxKPI pci device for an adapter and use it
as the dma_device during RDMA registration.

cxgbe's struct device cannot be used as-is because it's a native FreeBSD
driver and ibcore is LinuxKPI based.

Sponsored by: Chelsio Communications

4 years agoMerge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
Dimitry Andric [Fri, 1 May 2020 20:20:23 +0000 (20:20 +0000)]
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
10.0.0 release.

MFC r356479 (by bdragon):

[PowerPC] Fix libllvmminimal build when building from powerpc64 ELFv1.

When bootstrapping on powerpc64 ELFv1, it is necessary to use binutils
ld.bfd from ports for the bootstrap, as this is the only modern linker for
ELFv1 host tools.

As binutils ld.bfd is rather strict in its handling of undefined symbols,
it is necessary to pull in Support/Atomic.cpp to avoid an undefined symbol.

Reviewed by: dim, emaste
Sponsored by: Tag1 Consulting, Inc.
Differential Revision: https://reviews.freebsd.org/D23072

MFC r356930:

Add more Subversion mergeinfo bootstrap information, to hopefully
increase the probability of merging in vendor changes.

MFC r358408 (by brooks):

Merge commit 7214f7a79 from llvm git (by Sam Elliott):

  [RISCV] Lower llvm.trap and llvm.debugtrap

  Summary:
  Until this commit, these have lowered to a call to abort().

  `llvm.trap()` now lowers to `unimp`, which should trap on all systems.

  `llvm.debugtrap()` now lowers to `ebreak`, which is exactly what this
  instruction is for.

  Reviewers: asb, luismarques

  Reviewed By: asb

  Tags: #llvm

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

This fixes miscompilation resulting in linking failures with
INVARIANTS disabled.

Reviewed by: dim
Differential Revision: https://reviews.freebsd.org/D23857

MFC r358851:

Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
10.0.0-rc3 c290cb61fdc.

Release notes for llvm, clang, lld and libc++ 10.0.0 will become
available here:

https://releases.llvm.org/10.0.0/docs/ReleaseNotes.html
https://releases.llvm.org/10.0.0/tools/clang/docs/ReleaseNotes.html
https://releases.llvm.org/10.0.0/tools/lld/docs/ReleaseNotes.html
https://releases.llvm.org/10.0.0/projects/libcxx/docs/ReleaseNotes.html

PR: 244251

MFC r358854:

Add one additional file to libllvmminimal, to help the ppc64 bootstrap.

Reported by: bdragon
PR: 244251

MFC r358857:

Move another file in libllvm from sources required for world, to sources
required for bootstrap, as the PowerPC builds need this.

Reported by: bdragon
PR: 244251

MFC r358907:

Allow -DNO_CLEAN build across r358851.

The openmp 10.0.0 import renamed one .c file to .cpp, and this is
something our dependency system does not handle correctly.  Add another
ad-hoc cleanup to get rid of the stale dependency.

PR: 244251

MFC r358909 (by emaste):

Extend r358907 to explicitly remove stale lib32 dependency

After r325072 stale lib32 dependencies were not remooved.  A more
holistic approach is needed to address this but for the immediate issue
(-DNO_CLEAN builds across r358851) just readd the explicit lib32 path.

Reported by: dim
Sponsored by: The FreeBSD Foundation

MFC r358910 (by emaste):

Makefile.inc1: move dependency hack comment to the block it applies to

MFC r359035 (by emaste):

Makefile.inc1: add a note when deleting stale dependencies

We have ad-hoc stale dependency handling in Makefile.inc1 to handle the
cases where file extensions change, but it appears that some cases are
not functional.  Add a note when about to clean stale deps to help
when investigating failure reports.

Sponsored by: The FreeBSD Foundation

MFC r359082:

Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
llvmorg-10.0.0-rc4-5-g52c365aa9ca.  The actual release should follow Real
Soon Now.

PR:             244251
MFC after:      6 weeks

MFC r359083 (by emaste):

invoke _cleanobj_fast_depend_hack unconditionally

Apparently make ${CLEANDIR} is leaving stale entries in .depend files;
for now invoke the hacky cleanup in both the -DNO_CLEAN and normal
(no -DNO_CLEAN) cases.

In collaboration with: dim
Sponsored by: The FreeBSD Foundation

MFC r359084:

Merge commit 00925aadb from llvm git (by Fangrui Song):

  [ELF][PPC32] Fix canonical PLTs when the order does not match the PLT order

  Reviewed By: Bdragon28

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

This is needed to fix miscompiled canonical PLTs on ppc32/lld10.

Requested by: bdragon
Differential Revision: https://reviews.freebsd.org/D24109

MFC r359085:

Merge commit 315f8a55f from llvm git (by Fangrui Song):

  [ELF][PPC32] Don't report "relocation refers to a discarded section"
  for .got2

  Similar to D63182 [ELF][PPC64] Don't report "relocation refers to a
  discarded section" for .toc

  Reviewed By: Bdragon28

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

This is needed to fix compile errors when building for ppc32/lld10.

Requested by: bdragon
Differential Revision: https://reviews.freebsd.org/D24110

MFC r359086:

Merge commit b8ebc11f0 from llvm git (by Sanjay Patel):

  [EarlyCSE] avoid crashing when detecting min/max/abs patterns (PR41083)

  As discussed in PR41083:
  https://bugs.llvm.org/show_bug.cgi?id=41083
  ...we can assert/crash in EarlyCSE using the current hashing scheme
  and instructions with flags.

  ValueTracking's matchSelectPattern() may rely on overflow (nsw, etc)
  or other flags when detecting patterns such as min/max/abs composed
  of compare+select. But the value numbering / hashing mechanism used
  by EarlyCSE intersects those flags to allow more CSE.

  Several alternatives to solve this are discussed in the bug report.
  This patch avoids the issue by doing simple matching of min/max/abs
  patterns that never requires instruction flags. We give up some CSE
  power because of that, but that is not expected to result in much
  actual performance difference because InstCombine will canonicalize
  these patterns when possible. It even has this comment for abs/nabs:

    /// Canonicalize all these variants to 1 pattern.
    /// This makes CSE more likely.

  (And this patch adds PhaseOrdering tests to verify that the expected
  transforms are still happening in the standard optimization
  pipelines.

  I left this code to use ValueTracking's "flavor" enum values, so we
  don't have to change the callers' code. If we decide to go back to
  using the ValueTracking call (by changing the hashing algorithm
  instead), it should be obvious how to replace this chunk.

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

This fixes an assertion when building the math/gsl port on PowerPC64.

Requested by: pkubja

MFC r359087:

Merge commit 585a3cc31 from llvm git (by me):

  Fix -Wdeprecated-copy-dtor and -Wdeprecated-dynamic-exception-spec
  warnings.

  Summary:
  The former are like:

  libcxx/include/typeinfo:322:11: warning: definition of implicit copy
  constructor for 'bad_cast' is deprecated because it has a
  user-declared destructor [-Wdeprecated-copy-dtor]
    virtual ~bad_cast() _NOEXCEPT;
    ^
  libcxx/include/typeinfo:344:11: note: in implicit copy constructor
  for 'std::bad_cast' first required here
      throw bad_cast();
    ^

  Fix these by adding an explicitly defaulted copy constructor.

  The latter are like:

  libcxx/include/codecvt:105:37: warning: dynamic exception
  specifications are deprecated [-Wdeprecated-dynamic-exception-spec]
      virtual int do_encoding() const throw();
      ^~~~~~~

  Fix these by using the _NOEXCEPT macro instead.

  Reviewers: EricWF, mclow.lists, ldionne, #libc

  Reviewed By: EricWF, #libc

  Subscribers: dexonsmith, libcxx-commits

  Tags: #libc

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

This is because we use -Wsystem-headers during buildworld, and the two
warnings above are now triggered by default with clang 10, preventing
most C++ code from compiling without NO_WERROR.

Requested by: brooks
Differential Revision: https://reviews.freebsd.org/D24049

MFC r359089 (by emaste):

Revert r359083, fixed properly by r359088

r359083 introduced a workaround for stale libomp dependencies during a
regular (no -DNO_CLEAN) buildworld.  r359088 addressed the reason the
clean step missed libomp, so revert the workaround.

Sponsored by: The FreeBSD Foundation

MFC r359333:

Merge commit f0990e104 from llvm git (by Justin Hibbits):

  [PowerPC]: e500 target can't use lwsync, use msync instead

  The e500 core has a silicon bug that triggers an illegal instruction
  program trap on any sync other than msync. Other cores will typically
  ignore illegal sync types, and the documentation even implies that
  the 'illegal' bits are ignored.

  Address this hardware deficiency by only using msync, like the PPC440.

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

Requested by: jhibbits

MFC r359334:

Merge commit 459e8e948 from llvm git (by Justin Hibbits):

  [PowerPC]: Don't allow r0 as a target for LD_GOT_TPREL_L/32

  Summary:
  The linker is free to relax this (relocation R_PPC_GOT_TPREL16)
  against R_PPC_TLS, if it sees fit (initial exec to local exec). If r0
  is used, this can generate execution-invalid code (converts to 'addi
  %rX, %r0, FOO, which translates in PPC-lingo to li %rX, FOO). Forbid
  this instead.

  This fixes static binaries using locales on FreeBSD/powerpc (tested
  on FreeBSD/powerpcspe).

  Reviewed By: nemanjai
  Differential Revision: https://reviews.llvm.org/D76662

Requested by: jhibbits

MFC r359338:

Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
llvmorg-10.0.0-0-gd32170dbd5b (aka 10.0.0 release).

PR: 244251

MFC r359506 (by emaste):

lldb: stop excluding bindings/ subdir

With liblua in the tree we should be able to enable lldb's lua
scripting.  We'll need the files in bindings/, so start by allowing them
to come in with the next import.

Approved by: dim
Sponsored by: The FreeBSD Foundation

MFC r359578:

Merge once more from ^/vendor/llvm-project/release-10.x, to get the
lldb/bindings directory, which will be used to provide lua bindings for
lldb.

Requested by: emaste

MFC r359826:

Merge commit 30588a739 from llvm git (by Erich Keane):

  Make target features check work with ctor and dtor-

  The problem was reported in PR45468, applying target features to an
  always_inline constructor/destructor runs afoul of GlobalDecl
  construction assert when checking for target-feature compatibility.

  The core problem is fixed by using the version of the check that
  takes a FunctionDecl rather than the GlobalDecl. However, while
  writing the test, I discovered that source locations weren't properly
  set for this check on ctors/dtors. This patch also fixes constructors
  and CALLED destructors.

  Unfortunately, it doesn't seem too possible to get a meaningful
  source location for a 'cleanup' destructor, so those are still
  'frontend' level errors unfortunately. A fixme was added to the test
  to cover that situation.

This should fix 'Assertion failed: (!isa<CXXConstructorDecl>(D) && "Use
other ctor with ctor decls!"), function Init, file
/usr/src/contrib/llvm-project/clang/include/clang/AST/GlobalDecl.h, line
45' when compiling the security/botan2 port.

PR: 245550

MFC r359981:

Revert commit a9ad65a2b from llvm git (by Nemanja Ivanovic):

  [PowerPC] Change default for unaligned FP access for older subtargets

  This is a fix for https://bugs.llvm.org/show_bug.cgi?id=40554

  Some CPU's trap to the kernel on unaligned floating point access and
  there are kernels that do not handle the interrupt. The program then
  fails with a SIGBUS according to the PR. This just switches the
  default for unaligned access to only allow it on recent server CPUs
  that are known to allow this.

  Differential revision: https://reviews.llvm.org/D71954

This upstream commit causes a compiler hang when building certain ports
(e.g. security/nss, multimedia/x264) for powerpc64.  The hang has been
reported in https://bugs.llvm.org/show_bug.cgi?id=45186, but in the mean
time it is more convenient to revert the commit.

Requested by: jhibbits

MFC r359994:

Revert commit b6cf400aa fro llvm git (by Nemanja Ivanovic):

  Fix bots after a9ad65a2b34f

  In the last commit, I neglected to initialize the new subtarget
  feature I added which caused failures on a few bots. This should fix
  that.

This unbreaks the build after r359981, which reverted upstream commit
a9ad65a2b34f.

Reported by: jhibbits (and jenkins :)

MFC r360129:

Merge commit ce5173c0e from llvm git (by Reid Kleckner):

  Use FinishThunk to finish musttail thunks

  FinishThunk, and the invariant of setting and then unsetting
  CurCodeDecl, was added in 7f416cc42638 (2015). The invariant didn't
  exist when I added this musttail codepath in ab2090d10765 (2014).
  Recently in 28328c3771, I started using this codepath on non-Windows
  platforms, and users reported problems during release testing
  (PR44987).

  The issue was already present for users of EH on i686-windows-msvc,
  so I added a test for that case as well.

  Reviewed By: hans

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

This should fix 'Assertion failed: (!empty() && "popping exception stack
when not empty"), function popTerminate, file
/usr/src/contrib/llvm-project/clang/lib/CodeGen/CGCleanup.h, line 583'
when building the net-p2p/libtorrent-rasterbar

PR: 244830
Reported by: jbeich, yuri

MFC r360134:

Merge commit 64b31d96d from llvm git (by Nemanja Ivanovic):

  [PowerPC] Do not attempt to reuse load for 64-bit FP_TO_UINT without
  FPCVT

  We call the function that attempts to reuse the conversion without
  checking whether the target matches the constraints that the callee
  expects. This patch adds the check prior to the call.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=43976
  Differential revision: https://reviews.llvm.org/D77564

This should fix 'Assertion failed: ((Op.getOpcode() == ISD::FP_TO_SINT
|| Subtarget.hasFPCVT()) && "i64 FP_TO_UINT is supported only with
FPCVT"), function LowerFP_TO_INTForReuse, file
/usr/src/contrib/llvm/lib/Target/PowerPC/PPCISelLowering.cpp, line 7276'
when building the devel/libslang2 port (and a few others) for PowerPC64.

Requested by: pkubaj

MFC r360350:

Tentatively apply https://reviews.llvm.org/D78877 (by Dave Green):

  [ARM] Only produce qadd8b under hasV6Ops

  When compiling for a arm5te cpu from clang, the +dsp attribute is
  set. This meant we could try and generate qadd8 instructions where we
  would end up having no pattern. I've changed the condition here to be
  hasV6Ops && hasDSP, which is what other parts of ARMISelLowering seem
  to use for similar instructions.

  Fixed PR45677.

This fixes "fatal error: error in backend: Cannot select: t37: i32 =
ARMISD::QADD8b t43, t44" when compiling sys/dev/sound/pcm/feeder_mixer.c
for armv5. For some reason we do not encounter this on head, but this
error popped up while building universes for stable/12.

4 years agoUnbreak DRM KMS build by adding the needed compatibility field in the LinuxKPI.
Hans Petter Selasky [Fri, 1 May 2020 19:07:26 +0000 (19:07 +0000)]
Unbreak DRM KMS build by adding the needed compatibility field in the LinuxKPI.

Reported by: zeising @
Sponsored by: Mellanox Technologies

4 years agoMFC r360322:
Dimitry Andric [Fri, 1 May 2020 18:27:14 +0000 (18:27 +0000)]
MFC r360322:

Fix race between prebuilding libsbuf and libgeom

The latter needs the former, but with a multi-job build on a fast
machine, the race is sometimes lost. This leads to "ld: error: unable to
find library -lsbuf", when linking libgeom.so.

Submitted by: kevans

4 years agoMFC r360196:
Hans Petter Selasky [Fri, 1 May 2020 09:50:36 +0000 (09:50 +0000)]
MFC r360196:
Factor code in LinuxKPI to allow attach and detach using any BSD device.
This allows non-LinuxKPI based infiniband device drivers to attach
correctly to ibcore.

No functional change intended.

Reviewed by: np @
Differential Revision: https://reviews.freebsd.org/D24514
Sponsored by: Mellanox Technologies

4 years agoMFC r346645, r346664, r346687, r347387, r347836, r347088, 347089, r346956,
Hans Petter Selasky [Fri, 1 May 2020 09:46:27 +0000 (09:46 +0000)]
MFC r346645, r346664, r346687, r347387, r347836, r347088, 347089, r346956,
    r346957, r346958, r347088, r347089, r347385, r353938, r350570,
    r350572 and r350573:

Implement full bus_dma(9) support in the LinuxKPI and pull in all dependencies.

Bump FreeBSD version to force recompilation of external modules.

Sponsored by: Mellanox Technologies

4 years agoMFC r360428: Do not overflow when calculating file system size.
Xin LI [Fri, 1 May 2020 04:16:57 +0000 (04:16 +0000)]
MFC r360428: Do not overflow when calculating file system size.

4 years agoMFC r360269: Map family 0x5F (Denverton) to goldmont.
Alexander Motin [Fri, 1 May 2020 00:41:41 +0000 (00:41 +0000)]
MFC r360269: Map family 0x5F (Denverton) to goldmont.

According to the 325462-071US document, they should be the same.

4 years agoMFC r360266: Add family 0x5F (Denverton) to PMC_CPU_INTEL_ATOM_GOLDMONT.
Alexander Motin [Fri, 1 May 2020 00:40:18 +0000 (00:40 +0000)]
MFC r360266: Add family 0x5F (Denverton) to PMC_CPU_INTEL_ATOM_GOLDMONT.

According to the 325462-071US document, they should be the same.

4 years agoMFC r360010: Reduce the delayed ACK timeout from 100ms to 40ms.
Richard Scheffenegger [Thu, 30 Apr 2020 21:16:08 +0000 (21:16 +0000)]
MFC r360010: Reduce the delayed ACK timeout from 100ms to 40ms.

Reviewed by: kbowling, tuexen
Approved by: tuexen (mentor)
MFC after: 2 weeks
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D23281

4 years agoMFC 354660: Enable the RISC-V LLVM backend by default.
John Baldwin [Thu, 30 Apr 2020 15:24:05 +0000 (15:24 +0000)]
MFC 354660: Enable the RISC-V LLVM backend by default.

4 years agoMFC r360071-r360072: force -fcommon in kernel/modules where needed
Kyle Evans [Thu, 30 Apr 2020 14:51:31 +0000 (14:51 +0000)]
MFC r360071-r360072: force -fcommon in kernel/modules where needed

This contains some extra bits over the original commits, as things are
slightly different in earlier branches.

r360071:
Allow kernel modules to build with a compiler that defaults to -fno-common

This uses the same approach as r359691.

r360072:
More fixes to build the kernel with a compiler that defaults to -fno-common

Using the same approach as the last commit for the files used by genassym.sh.

4 years agoMFC r355423: UPDATING: Add [less] long-belated note about certs in base
Kyle Evans [Thu, 30 Apr 2020 14:38:55 +0000 (14:38 +0000)]
MFC r355423: UPDATING: Add [less] long-belated note about certs in base

While the interaction between this and the ETCSYMLINK option of
security/ca_root_nss isn't necessarily fatal, one should be aware and
attempt to understand the ramifications of mixing the two.

ports-secteam will be contacted to discuss the default option for branches
where certs are being included in base.

4 years agoFix build: redo MFC r360059 and revert unwanted portion.
Xin LI [Thu, 30 Apr 2020 05:28:48 +0000 (05:28 +0000)]
Fix build: redo MFC r360059 and revert unwanted portion.

4 years agoMFC r360359: Fix a bug with dirty file system handling.
Xin LI [Thu, 30 Apr 2020 04:00:53 +0000 (04:00 +0000)]
MFC r360359: Fix a bug with dirty file system handling.

4 years agoDefine enum for so_qstate outside of struct.
Simon J. Gerraty [Thu, 30 Apr 2020 00:20:31 +0000 (00:20 +0000)]
Define enum for so_qstate outside of struct.

LLVM-9.0 clang++ throws an error for enum defined within
an anonymous struct.

MFC of r360059

Reviewed by: jtl, rpokala
Differential Revision: https://reviews.freebsd.org//D24477

4 years agoMFC r345646: readelf: add newline after dumping dynamic FLAGS / FLAGS_1
Ed Maste [Wed, 29 Apr 2020 17:02:37 +0000 (17:02 +0000)]
MFC r345646: readelf: add newline after dumping dynamic FLAGS / FLAGS_1

All three dump_flags() callers need a newline after printing the flags.

Reported by: kib
Sponsored by: The FreeBSD Foundation

4 years agoMFC 350069: Use PT_GET_SC_ARGS and PT_GET_SC_RET in truss.
John Baldwin [Wed, 29 Apr 2020 16:04:59 +0000 (16:04 +0000)]
MFC 350069: Use PT_GET_SC_ARGS and PT_GET_SC_RET in truss.

This removes all of the architecture-specific functions from truss.

A per-ABI structure is still needed to map syscall numbers to names
and FreeBSD errno values to ABI error values as well as hold syscall
counters.  However, the linker set of ABI structures is now replaced
with a simple table mapping ABI names to structures.  This approach
permits sharing the same ABI structure among separate names such as
i386 a.out and ELF binaries as well as ELF v1 vs ELF v2 for powerpc64.

A few differences are visible due to using PT_GET_SC_RET to fetch the
error value of a system call.  Note that ktrace/kdump have had the
"new" behaviors for a long time already:
- System calls that return with EJUSTRETURN or ERESTART will now be
  noticed and logged as such.  Previously sigreturn (which uses
  EJUSTRETURN) would report whatever random value was in the register
  holding errno from the previous system call for example.  Now it
  reports EJUSTRETURN.
- System calls that return errno as their error value such as
  posix_fallocate() and posix_fadvise() now report non-zero return
  values as errors instead of success with a non-zero return value.

4 years agoMFC r360091:
Konstantin Belousov [Wed, 29 Apr 2020 10:57:21 +0000 (10:57 +0000)]
MFC r360091:
Align initial-exec TLS segments to the p_vaddr % align.

4 years agoMFC r360201:
Konstantin Belousov [Wed, 29 Apr 2020 10:54:58 +0000 (10:54 +0000)]
MFC r360201:
rtld: ignore static TLS segments when tracing.

4 years agoMFC r359997:
Konstantin Belousov [Wed, 29 Apr 2020 10:53:35 +0000 (10:53 +0000)]
MFC r359997:
Improve TSC calibration logic.

4 years agoMFC r360199
Ryan Moeller [Wed, 29 Apr 2020 05:11:17 +0000 (05:11 +0000)]
MFC r360199

menu.lua: Give names to menu entries

Make menu customizations easier by naming the entries and using the
names to build the table entries.

Reviewed by:    kevans
Approved by:    mav (mentor)
Sponsored by:   iXsystems, Inc.
Differential Revision:  https://reviews.freebsd.org/D24527