]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
3 years agoloader: fix non-zfs build
tsoome [Wed, 23 Sep 2020 19:15:22 +0000 (19:15 +0000)]
loader: fix non-zfs build

We can not include zfs headers while building without zfs.

Reported by: Oscar Holmlund

3 years agoriscv: Trap cleanup - use nitems()
nick [Wed, 23 Sep 2020 18:54:14 +0000 (18:54 +0000)]
riscv: Trap cleanup - use nitems()

No functional changes, just cleanup.

Reviewed by: kp
Approved by: kp (mentor)
Sponsored by: Axiado

3 years agoDo not leak oldvmspace if image activation failed
kib [Wed, 23 Sep 2020 18:03:07 +0000 (18:03 +0000)]
Do not leak oldvmspace if image activation failed

and current address space is already destroyed, so kern_execve()
terminates the process.

While there, clean up some internals of post_execve() inlined in init_main.

Reported by: Peter <pmc@citylink.dinoex.sub.org>
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D26525

3 years agonextboot(8): Fix behavior on non-ZFS /boot systems
cem [Wed, 23 Sep 2020 17:04:27 +0000 (17:04 +0000)]
nextboot(8): Fix behavior on non-ZFS /boot systems

Fix unquoted test for an empty value, which broke nextboot(8) on non-ZFS /boot
systems after r365938.

Discussed with: allanjude, tsoome
X-MFC-With: r365938

3 years agoremove reference to obsolete arm NOTES files
emaste [Wed, 23 Sep 2020 14:52:43 +0000 (14:52 +0000)]
remove reference to obsolete arm NOTES files

We left these in the clean rule to avoid having stale files remain in
working trees, but enough time has now passed that it's no longer
relevant.

Discussed with: imp

3 years agobyacc: fix UBSan signed shift range error
arichardson [Wed, 23 Sep 2020 12:54:42 +0000 (12:54 +0000)]
byacc: fix UBSan signed shift range error

I've submitted this patch upstream, so apply this to contrib/ until a new
version containing this change has been released.

Reviewed By: jkim
Differential Revision: https://reviews.freebsd.org/D26505

3 years agoAdd github CI for testing cross-building from Linux and macOS
arichardson [Wed, 23 Sep 2020 12:54:37 +0000 (12:54 +0000)]
Add github CI for testing cross-building from Linux and macOS

This builds the kernel-toolchain target and an amd64 GENERIC kernel on
Ubuntu 18.04, 20.04 and the latest macOS to ensure that new changes
don't regress building on non-FreeBSD hosts.

Reviewed By: emaste, lwhsu
Differential Revision: https://reviews.freebsd.org/D26512

3 years agoBump __FreeBSD_version after cache_purgevfs change
mjg [Wed, 23 Sep 2020 11:02:23 +0000 (11:02 +0000)]
Bump __FreeBSD_version after cache_purgevfs change

3 years agocache: drop the force flag from purgevfs
mjg [Wed, 23 Sep 2020 10:46:07 +0000 (10:46 +0000)]
cache: drop the force flag from purgevfs

The optional scan is wasteful, thus it is removed altogether from unmount.

Callers which always want it anyway remain unaffected.

3 years agocache: reimplement purgevfs to iterate vnodes instead of the entire hash
mjg [Wed, 23 Sep 2020 10:44:49 +0000 (10:44 +0000)]
cache: reimplement purgevfs to iterate vnodes instead of the entire hash

The entire cache scan was a leftover from the old implementation.

It is incredibly wasteful in presence of several mount points and does not
win much even for single ones.

3 years agocache: clean up atomic ops on numneg and numcache
mjg [Wed, 23 Sep 2020 10:42:41 +0000 (10:42 +0000)]
cache: clean up atomic ops on numneg and numcache

- use subtract instead of adding -1
- drop the useless _rel fence

Note this should be converted to a scalable scheme.

3 years agoloader: zfs_probe_dev should pick first matching zfs pool
tsoome [Wed, 23 Sep 2020 08:22:14 +0000 (08:22 +0000)]
loader: zfs_probe_dev should pick first matching zfs pool

During devswitch probe, we pick boot pool based on boot disk, if the boot
disk happens to have multiple pools in freebsd-zfs partitions, the current
code does pick last pool from boot disk as boot pool. While there is no
way at that stage to test, the more logical approach would be to pick
first matching pool.

This patch is assuming we do pass pool guid pointer with guid value 0,
this will help us to determine, if the guid value is already set or not.

The general suggestion would be not to share disk between different pools.

Reported by: Alexander Leidinger

3 years agoFix build.
delphij [Wed, 23 Sep 2020 07:27:12 +0000 (07:27 +0000)]
Fix build.

Pointy hat to: delphij
MFC after: 3 days

3 years agosbin/fsck_msdosfs: Fix an integer overflow on 32-bit platforms.
delphij [Wed, 23 Sep 2020 06:52:22 +0000 (06:52 +0000)]
sbin/fsck_msdosfs: Fix an integer overflow on 32-bit platforms.

The purpose of checksize() is to verify that the referenced cluster
chain size matches the recorded file size (up to 2^32 - 1) in the
directory entry. We follow the cluster chain, then multiple the
cluster count by bytes per cluster to get the physical size, then
check it against the recorded size.

When a file is close to 4 GiB (between 4GiB - cluster size and 4GiB,
both non-inclusive), the product of cluster count and bytes per
cluster would be exactly 4 GiB. On 32-bit systems, because size_t
is 32-bit, this would wrap back to 0, which will cause the file be
truncated to 0.

Fix this by using 64-bit physicalSize instead.

This fix is inspired by an Android change request at
https://android-review.googlesource.com/c/platform/external/fsck_msdos/+/1428461

PR: 249533
Reviewed by: kevlo
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D26524

3 years ago[PowerPC64LE] Fix RTAS LE calls in pseries.
bdragon [Wed, 23 Sep 2020 04:09:02 +0000 (04:09 +0000)]
[PowerPC64LE] Fix RTAS LE calls in pseries.

Similar to OPAL calls, switch to big endian to do calls to RTAS.

(Missed this one when I was doing the bulk commit of PowerPC64LE support.)

Sponsored by: Tag1 Consulting, Inc.

3 years ago__FreeBSD_version bump for introduction of the powerpc64le arch.
bdragon [Wed, 23 Sep 2020 03:19:20 +0000 (03:19 +0000)]
__FreeBSD_version bump for introduction of the powerpc64le arch.

Although this is technically not a breaking change, I believe it is best
to have a fresh version to use to define where the starting point was
here.

3 years agoarch(7): PowerPC64LE architecture definition
bdragon [Wed, 23 Sep 2020 03:12:58 +0000 (03:12 +0000)]
arch(7): PowerPC64LE architecture definition

Document the new powerpc64le arch's initial specifications.

Certain things are subject to change while this is experimental. The most
likely change is that long double may switch to quad, dependent on POWER8
emulation assistance for __float128 being set up in the compiler (as
POWER8 does not have IEEE-compatible 128-bit hardware float, unlike POWER9.)

Sponsored by: Tag1 Consulting, Inc.

3 years agocp: tests: fix weird 20 insertion
kevans [Wed, 23 Sep 2020 03:02:45 +0000 (03:02 +0000)]
cp: tests: fix weird 20 insertion

This slipped in at the last moment. =(

3 years agocp: add some basic tests
kevans [Wed, 23 Sep 2020 03:01:14 +0000 (03:01 +0000)]
cp: add some basic tests

There are some tests available in the NetBSD test suite, but we don't
currently pass all of those; further investigation will go into that. For
now, just add a basic test as well as a test that copies from /dev/null to a
file.

The /dev/null test confirms that the file gets created if it's empty, then
that it truncates the file if it's non-empty. This matches some usage that
was previously employed in the build and was replaced in r366042 by a
simpler shell construct.

I will also plan on coming back to expand these in due time.

MFC after: 1 week

3 years ago[PowerPC] Fix multiple ntp configuration issues
bdragon [Wed, 23 Sep 2020 02:37:27 +0000 (02:37 +0000)]
[PowerPC] Fix multiple ntp configuration issues

* powerpc time_t is 64 bit, not 32 bit.

* Add definition for powerpc64le.

With this, powerpc64le ntpd and ntpdate operate correctly instead of
corrupting the clock and exiting.

Tested on powerpc64, powerpc64le, and powerpc.

No feedback from cy@.

I am a bit confused as to how SIZEOF_TIME_T being wrong ever worked on
powerpc, it being big endian and all.

Sponsored by: Tag1 Consulting, Inc.
Differential Revision: https://reviews.freebsd.org/D26379

3 years ago[PowerPC64LE] Fix sleeping on POWER8.
bdragon [Wed, 23 Sep 2020 02:28:19 +0000 (02:28 +0000)]
[PowerPC64LE] Fix sleeping on POWER8.

Due to enter_idle_powerx fabricating a MSR from scratch, it is necessary
for it to care about the endianness, so we don't accidentally switch
endian the first time we idle a thread.

Took about five seconds to spot after seeing an unmangled backtrace.

The hard bit was needing to temporarily set up a mutex to sort out the
logjam that happens when every thread simultaneously wakes up in the wrong
endian due to the panic IPI and panics, leaving what I can best describe as
"alphabet soup" on the console.

Luckily, I already had a patch sitting around to do that.

This brings POWER8 up to equivilence with POWER9 on PPC64LE.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Pass our byte order to the sqlite3 build.
bdragon [Wed, 23 Sep 2020 02:17:44 +0000 (02:17 +0000)]
[PowerPC64LE] Pass our byte order to the sqlite3 build.

Due to the sqlite3 endian detection code preferring to check platform defines
instead of checking endian defines, it is necessary to manually set
the endianness on PowerPC64LE.

Unlike other bi-endian platforms, PowerPC64LE relies entirely on the
generic endianness macros like __BYTE_ORDER__ and has no platform-specific
define to denote little endian.

Add -DSQLITE_BYTEORDER=1234 to the CFLAGS when building libsqlite3 on
powerpc64le.

Fixes runtime operation of sqlite on PowerPC64LE.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] libkvm powerpc64le support.
bdragon [Wed, 23 Sep 2020 02:11:24 +0000 (02:11 +0000)]
[PowerPC64LE] libkvm powerpc64le support.

* Add missing _kvm16toh() function.
* Teach libkvm about powerpc64le.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Fix gdtoa configurations on LE.
bdragon [Wed, 23 Sep 2020 02:05:44 +0000 (02:05 +0000)]
[PowerPC64LE] Fix gdtoa configurations on LE.

gdtoa wins the award for "most outdated endianness naming convention"
with its IEEE_8087 vs IEEE_MC68k defines. I had a good chuckle.

Update softfloat and arith.h to adjust to BE or LE automatically
based on the low level preprocessor defines.

Fixes printf/scanf on PowerPC64LE, although there is still a problem
lurking regarding Signalling NaNs...

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Fix AP spinup on powernv.
bdragon [Wed, 23 Sep 2020 01:56:26 +0000 (01:56 +0000)]
[PowerPC64LE] Fix AP spinup on powernv.

OPAL unconditionally enters secondary CPUs with only HV and SF set.

I tried writing a secondary entry point instead, but OPAL rejected it
and I am unsure why, so I resorted to making the system reset interrupt
endian-flexible.

This means we take a slight performance hit on wakeup on LE, but it is
a good stopgap until we can figure out a reliable way to make OPAL enter
where we want it to.

It probably makes sense to have it around anyway, because I can imagine
scenarios where the cpu resets itself to BE and does a software reset.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Endian fix for opal_hmi.c
bdragon [Wed, 23 Sep 2020 01:51:01 +0000 (01:51 +0000)]
[PowerPC64LE] Endian fix for opal_hmi.c

Another boring one. We need to endian swap before checking flags.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Get XIVE up and running.
bdragon [Wed, 23 Sep 2020 01:49:37 +0000 (01:49 +0000)]
[PowerPC64LE] Get XIVE up and running.

More endian conversion.

* Install TCEs correctly (i.e. in big endian)

* Convert to big endian and back when setting up queue pages and IRQs.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Endian fix for opal_dev.c.
bdragon [Wed, 23 Sep 2020 01:41:51 +0000 (01:41 +0000)]
[PowerPC64LE] Endian fix for opal_dev.c.

Not much to say here, another missing be64toh() in memory that was written
from OPAL.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Endian fixes for opal_pci.c.
bdragon [Wed, 23 Sep 2020 01:37:01 +0000 (01:37 +0000)]
[PowerPC64LE] Endian fixes for opal_pci.c.

Since OPAL runs in big endian, any data being passed back and forth
via memory instead of registers needs to be byteswapped.

From my notes during development:

"A good way to find candidates is to look for vtophys() in opal_call()
parameters. The memory being passed will be written into in BE."

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Implement endian-independent dword atomic PTE lock.
bdragon [Wed, 23 Sep 2020 01:33:54 +0000 (01:33 +0000)]
[PowerPC64LE] Implement endian-independent dword atomic PTE lock.

It's much easier to implement this in an endian-independent way when we
don't also have to worry about masking half of the dword off.

Given that this code ran on a machine that ran a poudriere bulk with no
kernel oddities, I am relatively certain it is correctly implemented. ;)

This should be a minor performance boost on BE as well.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Fix endian conversion bugs in moea64.
bdragon [Wed, 23 Sep 2020 01:29:33 +0000 (01:29 +0000)]
[PowerPC64LE] Fix endian conversion bugs in moea64.

For a body of code that had its endian conversion bits written blind without
the ability to test, moea64 was VERY close to being correct.

There were only four instances where the existing code was getting it wrong.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Add release building script for powerpc64le.
bdragon [Wed, 23 Sep 2020 01:13:29 +0000 (01:13 +0000)]
[PowerPC64LE] Add release building script for powerpc64le.

This was originally part of the initial commit, but after discussion in
D26399, I split it out into its own commit after the kernel config file.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Initial GENERIC64LE kernel config.
bdragon [Wed, 23 Sep 2020 01:07:55 +0000 (01:07 +0000)]
[PowerPC64LE] Initial GENERIC64LE kernel config.

This is slightly stripped down from GENERIC64, as PowerMac G5 machines
are incapable of running in LE mode (so we can skip the Mac drivers.)

While technically POWER6 and POWER7 have the hardware capability of running
in LE mode, they have a tendency to trap excessively when a load/store is
misaligned. (an extremely common occurrence in LE code, and one of the main
reasons I consider BE to be superior, as it turns potential security issues
into immediately obvious mangled numbers.)

Additionally, there was no mechanism to control what endian interrupts
are delivered in, so supporting LE operation on POWER6 and POWER7 involves
some really dirty tricks in the interrupt vectors that I would rather
avoid.

IBM drew the line in the sand at POWER8 some time around 2013, embracing
full support for LE in the platform, and making a push across the board
for LE code to target POWER8 as a minimum requirement. As such, usage of
LE kernels on POWER6 and POWER7 is practically nil, despite it being
technically possible to do.

The so-called "TRUELE" feature bit which is the baseline requirement for
 needed for PowerPC64LE was introduced in POWER8.

Sponsored by: Tag1 Consulting, Inc.

3 years agoWork around cp breakage in current from last week
imp [Wed, 23 Sep 2020 01:04:25 +0000 (01:04 +0000)]
Work around cp breakage in current from last week

There was a small window cp was broken. Work around this by using :>
instead of cp /dev/null. Ideally, we'd keep the cp /dev/null in the
build as a regression test, but doing so breaks people that upgraded
during the cp breakage and this is simpler than bootstrapping a
working cp since there's no good __FreeBSD_version sign posts for
that.

Suggested by: lots of people
Too stubborn for his own good: imp

3 years ago[PowerPC64LE] powernv ILE setup code.
bdragon [Wed, 23 Sep 2020 00:32:50 +0000 (00:32 +0000)]
[PowerPC64LE] powernv ILE setup code.

When running without a hypervisor, we need to set the ILE bit in the LPCR
ourselves.

For the boot processor, handle it in powernv_attach() like we do for other
LPCR bits.

No change for the APs, as they will use the lpcr global to set up their own
LPCR when they do their own cpudep_ap_early_bootstrap() and pick up this
automatically.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] LE opal_call() implementation
bdragon [Wed, 23 Sep 2020 00:28:47 +0000 (00:28 +0000)]
[PowerPC64LE] LE opal_call() implementation

OPAL runs in big endian, so we need to rfid into it to switch endian
atomically when branching to it, and we need to do the
RETURN_TO_NATIVE_ENDIAN dance when it returns to us.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Use a shared LIBC_ARCH for powerpc64le.
bdragon [Wed, 23 Sep 2020 00:21:51 +0000 (00:21 +0000)]
[PowerPC64LE] Use a shared LIBC_ARCH for powerpc64le.

Given that we have converted to ELFv2 for BE already, endianness is the only
difference between the two ARCHs.

As such, there is no need to differentiate LIBC_ARCH between the two.

Combining them like this lets us avoid needing to have two copies of several
bits for no good reason.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Fix endianness issues in phyp_vscsi.
bdragon [Wed, 23 Sep 2020 00:13:58 +0000 (00:13 +0000)]
[PowerPC64LE] Fix endianness issues in phyp_vscsi.

Unlike virtio, which in legacy mode is guest endian, the hypervisor vscsi
interface operates in big endian, so we must convert back and forth in several
places.

These changes are enough to attach a rootdisk.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Work around qemu TCG bug in mtmsrd emulation.
bdragon [Wed, 23 Sep 2020 00:09:29 +0000 (00:09 +0000)]
[PowerPC64LE] Work around qemu TCG bug in mtmsrd emulation.

The TCG implementation of mtmsrd in qemu blindly copies the entire register
to the MSR, instead of the specific bit positions listed in the ISA.

This means that qemu will prematurely switch endian out from under the
running code instead of waiting for the rfid, causing an immediate trap
as it attempts to interpret the next instruction in the wrong endianness.

To work around this, ensure PSL_LE is still set before doing the mtmsrd.

In the future, we may wish to just turn off translation and unconditionally
use rfid to switch to the ofmsr instead of quasi-switching to the ofmsr.

Add a new platform option so this can be disabled. (And so that we can
conditonalize additional QEMU-specific hacks in the platform code.)

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Fix endianness issues in phyp and opal consoles.
bdragon [Wed, 23 Sep 2020 00:06:48 +0000 (00:06 +0000)]
[PowerPC64LE] Fix endianness issues in phyp and opal consoles.

This applies to both pseries and powernv, which were tested at different
points during the patchset development.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Tell the hypervisor to switch interrupts to LE at CHRP attach.
bdragon [Wed, 23 Sep 2020 00:03:35 +0000 (00:03 +0000)]
[PowerPC64LE] Tell the hypervisor to switch interrupts to LE at CHRP attach.

Since we will need to be able to take traps relatively early in the process,
ensure that the hypervisor changes our ILE for us as soon as we are ready.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Fix endian dependence of ofw_real.c.
bdragon [Tue, 22 Sep 2020 23:59:02 +0000 (23:59 +0000)]
[PowerPC64LE] Fix endian dependence of ofw_real.c.

Since OFW always runs in big endian in practice, we need to convert several
bits back and forth.

This is necessary to communicate with SLOF on LE pseries.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] LE bringup work: locore / machdep / platform
bdragon [Tue, 22 Sep 2020 23:55:34 +0000 (23:55 +0000)]
[PowerPC64LE] LE bringup work: locore / machdep / platform

This is the initial LE changes required in the machdep code to get as far
as platform attachment on qemu pseries.

Sponsored by: Tag1 Consulting, Inc.

3 years ago[PowerPC64LE] Set up powerpc.powerpc64le architecture
bdragon [Tue, 22 Sep 2020 23:49:30 +0000 (23:49 +0000)]
[PowerPC64LE] Set up powerpc.powerpc64le architecture

This is the initial set up for PowerPC64LE.

The current plan is for this arch to remain experimental for FreeBSD 13.

This started as a weekend learning project for me and kinda snowballed from
there.

(More to follow momentarily.)

Reviewed by: imp (earlier version), emaste
Sponsored by: Tag1 Consulting, Inc.
Differential Revision: https://reviews.freebsd.org/D26399

3 years agoRemove stray line
kib [Tue, 22 Sep 2020 23:39:14 +0000 (23:39 +0000)]
Remove stray line

3 years agoamd64 pmap: More unification for psind = 1 vs 2 in pmap_enter_largepage().
kib [Tue, 22 Sep 2020 23:28:06 +0000 (23:28 +0000)]
amd64 pmap: More unification for psind = 1 vs 2 in pmap_enter_largepage().

Move
  pkru check
  wait for page alloc
  wire accounting update
  asserting allowed updates for valid mappings
out of psind conditions.

Also add assert that psind references supported page size.
Remove not true comment.
Avoid uneccessary page table walks from top level.

Reviewed by: alc, markj (previous version)
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D26513

3 years agoTweak ficl definition from r365724
bdragon [Tue, 22 Sep 2020 23:27:09 +0000 (23:27 +0000)]
Tweak ficl definition from r365724

I had overthought how to do the FICL_TRUE change. We do not need to
explicitly specify how big the 0 is before the cast to the correct size.

The same change was suggested by both imp@ and Gunther Nikl independently.

Tested on powerpc.

Reported by: imp, Gunther Nikl

3 years agoAdd devctl_notify(9) man page
imp [Tue, 22 Sep 2020 23:02:01 +0000 (23:02 +0000)]
Add devctl_notify(9) man page

Document the calls to send messages to userland via devctl.
devctl_notify will create a message for the specified system,
subsystem and type, optionally adding additional information.

Reviewed by: bcr
Differential Revision: https://reviews.freebsd.org/D26520

3 years agoDocument quoting requirements for the devctl protocol
imp [Tue, 22 Sep 2020 23:01:57 +0000 (23:01 +0000)]
Document quoting requirements for the devctl protocol

Belatedly document the quoting requirements for the devctl protocol. I
thought they'd been previously documented.

Also, while I'm here, make igor happy.

Reviewed by: bcr
Differential Revision: https://reviews.freebsd.org/D26520

3 years agoDocument devctl_safe_quote_sb
imp [Tue, 22 Sep 2020 23:01:53 +0000 (23:01 +0000)]
Document devctl_safe_quote_sb

This routine centralizes the knowledge needed for properly quoting
'value' in all key="value" items that appear in devctl messages.

Reviewed by: bcr
Differential Revision: https://reviews.freebsd.org/D26520

3 years agoAdd a devctl_process_running man page.
imp [Tue, 22 Sep 2020 23:01:44 +0000 (23:01 +0000)]
Add a devctl_process_running man page.

Reviewed by: bcr
Differential Revision: https://reviews.freebsd.org/D26520

3 years agoDocument {O,AT}_RESOLVE_BENEATH and new O_BENEATH behavior for relative paths.
kib [Tue, 22 Sep 2020 22:54:54 +0000 (22:54 +0000)]
Document {O,AT}_RESOLVE_BENEATH and new O_BENEATH behavior for relative paths.

PR: 248335
Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D25886

3 years agoAdd O_RESOLVE_BENEATH and AT_RESOLVE_BENEATH to mimic Linux' RESOLVE_BENEATH.
kib [Tue, 22 Sep 2020 22:48:12 +0000 (22:48 +0000)]
Add O_RESOLVE_BENEATH and AT_RESOLVE_BENEATH to mimic Linux' RESOLVE_BENEATH.

It is like O_BENEATH, but disables to walk out of the subtree rooted
in the starting directory. O_BENEATH does not care if path walks out
if it returned.

Requested by: Dan Gohman <dev@sunfishcode.online>
PR: 248335
Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D25886

3 years agoChange O_BENEATH to handle relative paths same as absolute.
kib [Tue, 22 Sep 2020 22:43:32 +0000 (22:43 +0000)]
Change O_BENEATH to handle relative paths same as absolute.

Do not care if path walks out of the topping directory if it returns back.

Requested and reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D25886

3 years agoOnly clear latch for BENEATH when we walk out of the startdir,
kib [Tue, 22 Sep 2020 22:36:02 +0000 (22:36 +0000)]
Only clear latch for BENEATH when we walk out of the startdir,

not unconditionally on any dotdot component.

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

3 years agoAdd open2nameif()
kib [Tue, 22 Sep 2020 22:23:58 +0000 (22:23 +0000)]
Add open2nameif()

the helper to calculate namei flags both for open(2) and creat(2).

Suggested and reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D25886

3 years agoAdd at2cnpflags()
kib [Tue, 22 Sep 2020 22:22:29 +0000 (22:22 +0000)]
Add at2cnpflags()

the helper to convert AT_ flags for *at() syscalls to namei flags.

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

3 years agoAdd NIRES_STRICTREL.
kib [Tue, 22 Sep 2020 22:06:20 +0000 (22:06 +0000)]
Add NIRES_STRICTREL.

Stop abusing internal namei flag NI_LCF_STRICTRELATIVE as indicator of
cap-restricted lookup.  Add designated returned flag NIRES_STRICTREL
to inform kern_openat() that lookup was restricted.

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

3 years agolookup: Track last lookup component if it is directory.
kib [Tue, 22 Sep 2020 21:59:18 +0000 (21:59 +0000)]
lookup: Track last lookup component if it is directory.

This makes open("/a/../a", O_BENEATH) with cwd == "/a" work.

Reviewed by: markj
Reported and tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D25886

3 years agoImprove comment above nameicap_check_dotdot().
kib [Tue, 22 Sep 2020 21:54:30 +0000 (21:54 +0000)]
Improve comment above nameicap_check_dotdot().

Explain why tracker is needed at all.

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

3 years agoFix a bunch of mdoc issues found by mandoc -Tlint.
brueffer [Tue, 22 Sep 2020 21:13:26 +0000 (21:13 +0000)]
Fix a bunch of mdoc issues found by mandoc -Tlint.

3 years agolibnetmap: fix cast from uint64_t to void*
vmaffione [Tue, 22 Sep 2020 20:20:43 +0000 (20:20 +0000)]
libnetmap: fix cast from uint64_t to void*

We use uintptr_t as an intermediate cast to avoid compiler
warnings on 32 bit architectures.

Reported by: adrian
MFC after: 3 days

3 years agoudf: Validate the full file entry length
markj [Tue, 22 Sep 2020 17:05:01 +0000 (17:05 +0000)]
udf: Validate the full file entry length

Otherwise a corrupted file entry containing invalid extended attribute
lengths or allocation descriptor lengths can trigger an overflow when
the file entry is loaded.

admbug: 965
PR: 248613
Reported by: C Turt <ecturt@gmail.com>
MFC after: 3 days
Sponsored by: The FreeBSD Foundation

3 years agoMerge OpenSSL 1.1.1h.
jkim [Tue, 22 Sep 2020 16:18:31 +0000 (16:18 +0000)]
Merge OpenSSL 1.1.1h.

3 years agoftpd: Add missing braces around a statfd check
markj [Tue, 22 Sep 2020 15:54:18 +0000 (15:54 +0000)]
ftpd: Add missing braces around a statfd check

This was harmless but looked incorrect.  No functional change intended.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

3 years agotftpd: Check for errors from chdir()
markj [Tue, 22 Sep 2020 15:54:05 +0000 (15:54 +0000)]
tftpd: Check for errors from chdir()

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

3 years agoRISC-V: build SiFive drivers and DTB in GENERIC
mhorne [Tue, 22 Sep 2020 13:00:02 +0000 (13:00 +0000)]
RISC-V: build SiFive drivers and DTB in GENERIC

In the spirit of the GENERIC config, we should include the drivers required to
run on most supported platforms.

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D26501

3 years agocxgbe(4): let the PF driver use VM work requests for transmit.
np [Tue, 22 Sep 2020 04:16:40 +0000 (04:16 +0000)]
cxgbe(4): let the PF driver use VM work requests for transmit.

This allows the PF interfaces to communicate with the VF interfaces over
the internal switch in the ASIC.  Fix the GL limits for VM work requests
while here.

MFC after: 3 days
Sponsored by: Chelsio Communications

3 years agoAdd missing cylinder group check-hash updates when doing large expansions
mckusick [Tue, 22 Sep 2020 03:57:48 +0000 (03:57 +0000)]
Add missing cylinder group check-hash updates when doing large expansions
of filesystems.

Reported by:  Colin Percival (cperciva@)
Tested by:    Colin Percival (cperciva@)
MFC after:    3 days
Sponsored by: Netflix

3 years agocxgbe(4): add counters for mbuf pullups and defrags.
np [Tue, 22 Sep 2020 03:06:36 +0000 (03:06 +0000)]
cxgbe(4): add counters for mbuf pullups and defrags.

MFC after: 3 days
Sponsored by: Chelsio Communications

3 years agoRemove claim that Allied Forces created "West Germany" in 1953. I can
grog [Mon, 21 Sep 2020 22:55:51 +0000 (22:55 +0000)]
Remove claim that Allied Forces created "West Germany" in 1953.  I can
find no historic substantiation for such a claim.  The Federal
Republic of Germany was created by Germans on 23 May 1949, as also
noted in this file.

3 years agostand/reloc_elf: Handle relative relocations for arm{,64} and riscv
scottph [Mon, 21 Sep 2020 22:24:46 +0000 (22:24 +0000)]
stand/reloc_elf: Handle relative relocations for arm{,64} and riscv

Extend the powerpc relative relocation handling from r240782 to a
handful of other architectures.  This is needed to properly read
dependency information from kernel modules.

Reviewed by: jhb
Approved by: scottl (implicit)
MFC after: 1 week
Sponsored by: Ampere Computing, Inc.
Differential Revision: https://reviews.freebsd.org/D26365

3 years agoarm64/pmap: Sparsify pv_table
scottph [Mon, 21 Sep 2020 22:23:57 +0000 (22:23 +0000)]
arm64/pmap: Sparsify pv_table

Reviewed by: markj, kib
Approved by: scottl (implicit)
MFC after: 1 week
Sponsored by: Ampere Computing, Inc.
Differential Revision: https://reviews.freebsd.org/D26132

3 years agovm_reserv: Sparsify the vm_reserv_array when VM_PHYSSEG_SPARSE
scottph [Mon, 21 Sep 2020 22:22:53 +0000 (22:22 +0000)]
vm_reserv: Sparsify the vm_reserv_array when VM_PHYSSEG_SPARSE

On an Ampere Altra system, the physical memory is populated
sparsely within the physical address space, with only about 0.4%
of physical addresses backed by RAM in the range [0, last_pa].

This is causing the vm_reserv_array to be over-sized by a few
orders of magnitude, wasting roughly 5 GiB on a system with
256 GiB of RAM.

The sparse allocation of vm_reserv_array is controlled by defining
VM_PHYSSEG_SPARSE, with the dense allocation still remaining for
platforms with VM_PHYSSEG_DENSE.

Reviewed by: markj, alc, kib
Approved by: scottl (implicit)
MFC after: 1 week
Sponsored by: Ampere Computing, Inc.
Differential Revision: https://reviews.freebsd.org/D26130

3 years agoSparsify the vm_page_dump bitmap
scottph [Mon, 21 Sep 2020 22:21:59 +0000 (22:21 +0000)]
Sparsify the vm_page_dump bitmap

On Ampere Altra systems, the sparse population of RAM within the
physical address space causes the vm_page_dump bitmap to be much
larger than necessary, increasing the size from ~8 Mib to > 2 Gib
(and overflowing `int` for the size).

Changing the page dump bitmap also changes the minidump file
format, so changes are also necessary in libkvm.

Reviewed by: jhb
Approved by: scottl (implicit)
MFC after: 1 week
Sponsored by: Ampere Computing, Inc.
Differential Revision: https://reviews.freebsd.org/D26131

3 years agoMove vm_page_dump bitset array definition to MI code
scottph [Mon, 21 Sep 2020 22:20:37 +0000 (22:20 +0000)]
Move vm_page_dump bitset array definition to MI code

These definitions were repeated by all architectures, with small
variations. Consolidate the common definitons in machine
independent code and use bitset(9) macros for manipulation. Many
opportunities for deduplication remain in the machine dependent
minidump logic. The only intended functional change is increasing
the bit index type to vm_pindex_t, allowing the indexing of pages
with address of 8 TiB and greater.

Reviewed by: kib, markj
Approved by: scottl (implicit)
MFC after: 1 week
Sponsored by: Ampere Computing, Inc.
Differential Revision: https://reviews.freebsd.org/D26129

3 years agoWeaken assertions in pmap_l1_to_l2() and pmap_l2_to_l3().
markj [Mon, 21 Sep 2020 22:19:21 +0000 (22:19 +0000)]
Weaken assertions in pmap_l1_to_l2() and pmap_l2_to_l3().

pmap_update_entry() will temporarily clear the valid bit of page table
entries in order to satisfy the arm64 pmap's break-before-make
constraint.  pmap_kextract() may operate concurrently on kernel page
table pages, introducing windows where the assertions added in r365879
may fail incorrectly since they implicitly assert that the valid bit is
set.  Modify the assertions to handle this.

Reviewed by: andrew, mmel (previous version)
Reviewed by: alc, kib
Reported by: mmel, scottph
MFC with: r365879

3 years agobitset: expand bit index type to `long`
scottph [Mon, 21 Sep 2020 22:19:12 +0000 (22:19 +0000)]
bitset: expand bit index type to `long`

An upcoming patch to use the bitset macros for tracking vm page
dump information could conceivably need more than INT_MAX bits.
Expand the bit type to long so that the extra range is available
on 64-bit platforms where it would most likely be needed.

CPUSET_COUNT and DOMAINSET_COUNT are also modified to remain of
type `int`.

Reviewed by: kib, markj
Approved by: scottl (implicit)
MFC after: 1 week
Sponsored by: Ampere Computing, Inc.
Differential Revision: https://reviews.freebsd.org/D26190

3 years agovchi: rename bitset macros to avoid collision with bitset(9)
scottph [Mon, 21 Sep 2020 22:18:09 +0000 (22:18 +0000)]
vchi: rename bitset macros to avoid collision with bitset(9)

An upcoming change to include bitset(9) macros from vm_page.h
causes a macro name collision with vchi's custom bitset macros.

This change was performed mechanically by:

  sed -i .orig s/BITSET/VCHI_BITSET/g $(grep -rl BITSET sys/contrib/vchiq)

Reviewed by: andrew
Approved by: scottl (implicit)
MFC after: 1 week
Sponsored by: Ampere Computing, Inc.
Differential Revision: https://reviews.freebsd.org/D26177

3 years agoRework part of routing code to reduce difference to D26449.
melifaro [Mon, 21 Sep 2020 20:02:26 +0000 (20:02 +0000)]
Rework part of routing code to reduce difference to D26449.

* Split rt_setmetrics into get_info_weight() and rt_set_expire_info(),
 as these two can be applied at different entities and at different times.
* Start filling route weight in route change notifications
* Pass flowid to UDP/raw IP route lookups
* Rework nd6_subscription_cb() and sysctl_dumpentry() to prepare for the fact
 that rtentry can contain multiple nexthops.

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

3 years agobsdbox: fix build after recent libifconfig changes
kevans [Mon, 21 Sep 2020 19:50:39 +0000 (19:50 +0000)]
bsdbox: fix build after recent libifconfig changes

libifconfig now generates file(s) into its .OBJDIR that are essential to the
build. Make sure we -I that in, like we already do in the ^/rescue build.

3 years agomkcsmapper: Fix UBSan signed shift error
arichardson [Mon, 21 Sep 2020 19:03:17 +0000 (19:03 +0000)]
mkcsmapper: Fix UBSan signed shift error

usr.bin/mkcsmapper/yacc.y:466:18: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

3 years agoFix another UBSan error in awk
arichardson [Mon, 21 Sep 2020 19:03:12 +0000 (19:03 +0000)]
Fix another UBSan error in awk

This applies my upstreamed fix: https://github.com/onetrueawk/awk/commit/ad9bd2f40a89ec9533b92254b86a756cf4f40fd4
Found By: UBSan

3 years agoawk: Fix subobject out-of-bounds access
arichardson [Mon, 21 Sep 2020 19:03:07 +0000 (19:03 +0000)]
awk: Fix subobject out-of-bounds access

When matching a regex with ^, it would attempt to access
gototab[NSTATES][NCHARS+2], and therefore access the state for the \002
character instead. This change is required to run awk under CHERI (with
sub-object bounds) and when running with UBSan instrumentation.

This was committed upstream as https://github.com/onetrueawk/awk/commit/cbf924342b63a095a4c6842280c3085b1b63ae45

Found by: CHERI (with subobject bounds enabled)
Obtained from: CheriBSD
Reviewed By: imp
Differential Revision: https://reviews.freebsd.org/D26509

3 years agoWhitespace fix after r365948
dab [Mon, 21 Sep 2020 18:34:13 +0000 (18:34 +0000)]
Whitespace fix after r365948

MFC after: 1 week
Sponsored by: Dell EMC Isilon

3 years agoAdd support for Winbond USB CDC modem device found in Tenma power supply.
hselasky [Mon, 21 Sep 2020 18:32:57 +0000 (18:32 +0000)]
Add support for Winbond USB CDC modem device found in Tenma power supply.

PR: 249384
MFC after: 1 week
Submitted by: darius@dons.net.au
Sponsored by: Mellanox Technologies // NVIDIA Networking

3 years agoAdd example to ng_bpf(4) showing how ng_bpf(4) can be used to prevent spoofing.
hselasky [Mon, 21 Sep 2020 18:17:01 +0000 (18:17 +0000)]
Add example to ng_bpf(4) showing how ng_bpf(4) can be used to prevent spoofing.

Differential Revision: https://reviews.freebsd.org/D26488
MFC after: 1 week
Reviewed by: pi, bcr (manpages)
Submitted by: lutz_donnerhacke.de (Lutz Donnerhacke)
Sponsored by: Mellanox Technologies // NVIDIA Networking

3 years ago[rcorder] [crunch] Fix C function declarations to include void
adrian [Mon, 21 Sep 2020 17:59:45 +0000 (17:59 +0000)]
[rcorder] [crunch] Fix C function declarations to include void

This fixes a compile issue under gcc6 which complains about
legacy style C function declarations.

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

3 years agofsx: fix build with WARNS=6
asomers [Mon, 21 Sep 2020 17:48:28 +0000 (17:48 +0000)]
fsx: fix build with WARNS=6

* signed/unsigned comparisons
* use standard warn(3)
* Suppress warnings about local vars and funcs not declared static
* const-correctness
* declaration shadows a variable in the global scope

Reviewed by: kevans
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D26516

3 years agoHide tunable definitions behind _KERNEL
mhorne [Mon, 21 Sep 2020 17:28:41 +0000 (17:28 +0000)]
Hide tunable definitions behind _KERNEL

Some userspace code include sys/kernel.h. Namely, some OpenZFS tests do
this, and it was causing breakage after r365945 due to a lack of bool
typedef. Userspace should not need the TUNABLE_** stuff, so hide it
behind an #ifdef _KERNEL.

Sorry for the breakage.

Reported by: andrew, Michael Butler, Jenkins
Discussed with: kevans, allanjude

3 years agoxargs: add some long options for GNU compatibility
kevans [Mon, 21 Sep 2020 17:06:36 +0000 (17:06 +0000)]
xargs: add some long options for GNU compatibility

These are low-effort to add, so let's just do it.

Reported by: "LukeShu" on Hacker News (-r / --no-run-if-empty)
MFC after: 1 week

3 years agoPull in fix from upstream NetBSD rev. 1.5:
phk [Mon, 21 Sep 2020 16:43:38 +0000 (16:43 +0000)]
Pull in fix from upstream NetBSD rev. 1.5:

    If Unwind_Backtrace is broken, ctx.n will still contain ~0, and we will
    return that which poor behavior for the user, so return 0 instead.
    We could document ~0 to be an error, but that would deviate from the
    Linux behavior which is not desirable. Noted by Poul-Henning Kamp

PR: 209842

3 years agoamd64 pmap: only calculate page table page when needed.
kib [Mon, 21 Sep 2020 15:53:41 +0000 (15:53 +0000)]
amd64 pmap: only calculate page table page when needed.

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

3 years agoWhen building on Ubuntu bootstrap bmake with bash as the default shell
arichardson [Mon, 21 Sep 2020 15:49:02 +0000 (15:49 +0000)]
When building on Ubuntu bootstrap bmake with bash as the default shell

The Ubuntu /bin/sh (dash) removes all environment variables that contain
characters outside the [a-zA-Z0-9_] range and this breaks the bmake tests that
run as part of bootstrapping bmake.
This can be reverted when the bmake tests have been updated.

3 years agoAdd a tools/build/make.py script that bootstraps bmake and then runs the build
arichardson [Mon, 21 Sep 2020 15:48:57 +0000 (15:48 +0000)]
Add a tools/build/make.py script that bootstraps bmake and then runs the build

This makes it possible to compile on non-FreeBSD systems since make will
usually be GNU make there. Even if they include bmake, it will often
either be a broken version or too old to build FreeBSD.

This should be the last commit needed to compile FreeBSD on Linux+macOS.
After over two years, I've finally managed to upstream all our local CheriBSD
changes to allow building on Linux (and as a result of being reviewed by more
people they are slightly less ugly than they were before).

It should now be possible to run the following to build on Linux+macOS if you
have LLVM/Clang 10 or newer installed:
MAKEOBJDIRPREFIX=/somewhere ./tools/build/make.py TARGET=amd64 TARGET_ARCH=amd64 buildworld

I have only tested macOS 15, Ubuntu 18.04 and openSUSE Leap, but other Linux
distributions might also work (as long as they ship a recent GLibc and compiler).

Reviewed By: emaste (should be fine to commit to tools/)
Differential Revision: https://reviews.freebsd.org/D16767

3 years agoHonor the FWUG value of some drives in nvmecontrol
dab [Mon, 21 Sep 2020 15:45:49 +0000 (15:45 +0000)]
Honor the FWUG value of some drives in nvmecontrol

nvmecontrol tries to upload firmware in chunks as large as it thinks
the device permits. It fails to take into account the FWUG value used
by some drives to advertise the size and alignment limits for firmware
chunks.

  - Use the firwmare update granularity value from the
  - If the granularity is not reported or not restricted, fall back to
    the previously existing logic that calculates the max transfer
    size based on MDTS.
  - Add firmware update granularity to the identify-controller output.

Reviewed by: imp (previous version), chuck
Obtained from: Dell EMC Isilon
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D26390

3 years agoUse getenv_is_true() in init_static_kenv()
mhorne [Mon, 21 Sep 2020 15:44:23 +0000 (15:44 +0000)]
Use getenv_is_true() in init_static_kenv()

A small example of how these functions can be used to simplify checks of
this nature.

Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D26271

3 years agoAdd an ioctl to get an NVMe device's maximum transfer size
dab [Mon, 21 Sep 2020 15:41:47 +0000 (15:41 +0000)]
Add an ioctl to get an NVMe device's maximum transfer size

Reviewed by: imp, chuck
Obtained from: Dell EMC Isilon
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D26390

3 years agoAdd getenv(9) boolean parsing functions
mhorne [Mon, 21 Sep 2020 15:24:44 +0000 (15:24 +0000)]
Add getenv(9) boolean parsing functions

This adds the getenv_bool() function, to parse a boolean value from a
kernel environment variable or tunable. This works for traditional
boolean values like "0" and "1", and also "true" and "false"
(case-insensitive). These semantics do not yet apply to sysctls declared
using SYSCTL_BOOL with CTLFLAG_TUN (they still only parse 1 and 0).

Also added are two wrapper functions, getenv_is_true() and
getenv_is_false(). These are slightly simpler for callers wishing to
perform a single check of a configuration variable.

Reviewed by: jhb (slightly earlier version)
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D26270

3 years agoaw_usbphy: add support for device mode operation
avg [Mon, 21 Sep 2020 10:02:11 +0000 (10:02 +0000)]
aw_usbphy: add support for device mode operation

OTG mode is not supported still.  It's easy to do it as a one-off
detection, but the proper support requires continuous monitoring and
communicating the current state to the USB layer.

Also, fix phy0_route setting for H3.  Remove duplicate register
definitions.

Tested on Orange Pi PC Plus with dr_mode="peripheral" using
  hw.usb.template=3
  umodem_load="YES"

Reviewed by: manu
MFC after: 5 weeks
Differential Revision: https://reviews.freebsd.org/D26348