]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
2 years agox86/iommu: Shrink the critical section in dmar_qi_task()
Alan Cox [Mon, 18 Jul 2022 00:56:39 +0000 (19:56 -0500)]
x86/iommu: Shrink the critical section in dmar_qi_task()

It is safe to test and clear the Invalidation Wait Descriptor
Complete flag before acquiring the DMAR lock in dmar_qi_task(),
rather than waiting until the lock is held.

Reviewed by: kib
MFC after: 2 weeks

2 years agox86: Remove 1 second DELAY from cpu_reset
Colin Percival [Wed, 13 Jul 2022 00:43:07 +0000 (17:43 -0700)]
x86: Remove 1 second DELAY from cpu_reset

On SMP systems, cpu_reset broadcasts a message telling the APs to stop
themselves, and then the BSP waits 1 second before actually resetting
itself; this behaviour dates back to 1998-05-17.

I assume that this delay was added in order to allow the APs to stop
themselves before the BSP resets; but we wait until the APs have all
acknowledged entering the "stopped" state, so it no longer seems to
serve any purpose.

Reviewed by: jhb, kib
Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D35797

2 years agoAdd kern.reboot_wait_time sysctl
Colin Percival [Wed, 13 Jul 2022 00:42:26 +0000 (17:42 -0700)]
Add kern.reboot_wait_time sysctl

Historic FreeBSD behaviour (dating back to 1994-04-02) when rebooting
is to print "Rebooting..." and then
/* wait 1 sec for printf's to complete and be read */

Prior to April 1994, there was a 100 ms delay (added 1993-11-12).

Since (a) most users will already be aware that the system is rebooting
and do not need to take time to read an additional message to that
effect, and (b) most FreeBSD systems don't have anyone actively looking
at the console anyway, this delay no longer serves much purpose.

This commit adds a kern.reboot_wait_time sysctl which defaults to 0;
historic behaviour can be regained by setting it to 1.

Reviewed by: imp
Relnotes: FreeBSD now reboots faster; to restore the traditional
wait after printing "Rebooting..." to the console, set
kern.reboot_wait_time=1 (or more).
Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D35796

2 years agomac_ddb: add some validation functions
Mitchell Horne [Mon, 18 Jul 2022 21:25:00 +0000 (17:25 -0400)]
mac_ddb: add some validation functions

These global objects are easy to validate, so provide the helper
functions to do so and include these commands in the allow lists.

Reviewed by: markj
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D35372

2 years agomac: add new mac_ddb(4) policy
Mitchell Horne [Mon, 18 Jul 2022 21:24:06 +0000 (17:24 -0400)]
mac: add new mac_ddb(4) policy

Generally, access to the kernel debugger is considered to be unsafe from
a security perspective since it presents an unrestricted interface to
inspect or modify the system state, including sensitive data such as
signing keys.

However, having some access to debugger functionality on production
systems may be useful in determining the cause of a panic or hang.
Therefore, it is desirable to have an optional policy which allows
limited use of ddb(4) while disabling the functionality which could
reveal system secrets.

This loadable MAC module allows for the use of some ddb(4) commands
while preventing the execution of others. The commands have been broadly
grouped into three categories:
 - Those which are 'safe' and will not emit sensitive data (e.g. trace).
   Generally, these commands are deterministic and don't accept
   arguments.
 - Those which are definitively unsafe (e.g. examine <addr>, search
   <addr> <value>)
 - Commands which may be safe to execute depending on the arguments
   provided (e.g. show thread <addr>).

Safe commands have been flagged as such with the DB_CMD_MEMSAFE flag.

Commands requiring extra validation can provide a function to do so.
For example, 'show thread <addr>' can be used as long as addr can be
checked against the system's list of process structures.

The policy also prevents debugger backends other than ddb(4) from
executing, for example gdb(4).

Reviewed by: markj, pauamma_gundo.com (manpages)
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D35371

2 years agomac: kdb/ddb framework hooks
Mitchell Horne [Mon, 18 Jul 2022 21:23:16 +0000 (17:23 -0400)]
mac: kdb/ddb framework hooks

Add three simple hooks to the debugger allowing for a loaded MAC policy
to intervene if desired:
 1. Before invoking the kdb backend
 2. Before ddb command registration
 3. Before ddb command execution

We extend struct db_command with a private pointer and two flag bits
reserved for policy use.

Reviewed by: markj
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D35370

2 years agoddb: tag core commands with DB_CMD_MEMSAFE
Mitchell Horne [Mon, 18 Jul 2022 21:22:36 +0000 (17:22 -0400)]
ddb: tag core commands with DB_CMD_MEMSAFE

Those which are statically defined in db_command.c.

Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D35584

2 years agoddb: annotate some commands with DB_CMD_MEMSAFE
Mitchell Horne [Mon, 18 Jul 2022 21:21:38 +0000 (17:21 -0400)]
ddb: annotate some commands with DB_CMD_MEMSAFE

This is not completely exhaustive, but covers a large majority of
commands in the tree.

Reviewed by: markj
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D35583

2 years agoddb: add the DB_CMD_MEMSAFE flag for commands
Mitchell Horne [Mon, 18 Jul 2022 20:04:24 +0000 (16:04 -0400)]
ddb: add the DB_CMD_MEMSAFE flag for commands

This flag value can be used to indicate if a command has the property of
being "memory safe". In this instance, memory safe means that the
command does not allow/enable reads or writes of arbitrary memory,
regardless of the arguments passed to it. For example, 'backtrace' is
considered a memory-safe command since its output is deterministic,
while 'show vnode' is not, since it requires a memory address as an
argument and will print the contents beginning at that location.

Apply the flag to the "show all" command macros. It is expected that
commands added to this table will always exhibit this property.

Reviewed by: markj
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D35581

2 years agobge: tell debugnet there are 2 rx rings, not 1,024
Eric van Gyzen [Mon, 18 Jul 2022 18:07:20 +0000 (13:07 -0500)]
bge: tell debugnet there are 2 rx rings, not 1,024

debugnet provides the network stack for netgdb and netdump.  Since it
must operate under panic/debugger conditions and can't rely on dynamic
memory allocation, it preallocates mbufs during boot or network
configuration.  At that time, it does not yet know which interface
will be used for debugging, so it does not know the required size and
quantity of mbufs to allocate.  It takes the worst-case approach by
calculating its requirements from the largest MTU and largest number
of receive queues across all interfaces that support debugnet.

Unfortunately, the bge NIC driver told debugnet that it supports 1,024
receive queues.  It actually supports only 2 queues (with 1,024 slots,
thus the error).  This greatly exaggerated debugnet's preallocation,
so with an MTU of 9000 on any interface, it allocated 600 MB of memory.
A tiny fraction of this memory would be used if netgdb or netdump were
invoked; the rest is completely wasted.

Reviewed by: markj, rlibby
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D35845

2 years agosched_ule: Ensure we hold the thread lock when modifying td_flags
Mark Johnston [Mon, 18 Jul 2022 19:50:45 +0000 (15:50 -0400)]
sched_ule: Ensure we hold the thread lock when modifying td_flags

The load balancer may force a running thread to reschedule and pick a
new CPU.  To do this it sets some flags in the thread running on a
loaded CPU.  But the code assumed that a running thread's lock is the
same as that of the corresponding runqueue, and there are small windows
where this is not true.  In this case, we can end up with non-atomic
modifications to td_flags.

Since this load balancing is best-effort, simply give up if the thread's
lock doesn't match; in this case the thread is about to enter the
scheduler anyway.

Reviewed by: kib
Reported by: glebius
Fixes: e745d729be60 ("sched_ule(4): Improve long-term load balancer.")
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35821

2 years agoi386: fix pmap_trm_arena_last atomic load type
Mateusz Guzik [Mon, 18 Jul 2022 18:42:40 +0000 (18:42 +0000)]
i386: fix pmap_trm_arena_last atomic load type

Sponsored by: Rubicon Communications, LLC ("Netgate")

2 years agovtfontcvt: correct usage
Ed Maste [Mon, 18 Jul 2022 17:21:22 +0000 (13:21 -0400)]
vtfontcvt: correct usage

Commit e7fd9688ea97 changed vtfontcvt's command line parsing, but did
not correctly update the usage (it omitted the new -o flag).

Fixes: e7fd9688ea97 ("Move font related data structured to...")
MFC after: 1 week
Sponsored by: The FreeBSD Foundation

2 years agoImplement shared page address randomization
Kornel Dulęba [Tue, 10 May 2022 13:22:55 +0000 (15:22 +0200)]
Implement shared page address randomization

It used to be mapped at the top of the UVA.
If the randomization is enabled any address above .data section will be
randomly chosen and a guard page will be inserted in the shared page
default location.
The shared page is now mapped in exec_map_stack, instead of
exec_new_vmspace. The latter function is called before image activator
has a chance to parse ASLR related flags.
The KERN_PROC_VM_LAYOUT sysctl was extended to provide shared page
address.
The feature is enabled by default for 64 bit applications on all
architectures.
It can be toggled kern.elf64.aslr.shared_page sysctl.

Approved by: mw(mentor)
Sponsored by: Stormshield
Obtained from: Semihalf
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D35349

2 years agoRework how shared page related data is stored
Kornel Dulęba [Thu, 2 Jun 2022 07:58:12 +0000 (09:58 +0200)]
Rework how shared page related data is stored

Store the shared page address in struct vmspace.
Also instead of storing absolute addresses of various shared page
segments save their offsets with respect to the shared page address.
This will be more useful when the shared page address is randomized.

Approved by: mw(mentor)
Sponsored by: Stormshield
Obtained from: Semihalf
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D35393

2 years agoIntroduce the PROC_SIGCODE() macro
Kornel Dulęba [Thu, 2 Jun 2022 08:45:54 +0000 (10:45 +0200)]
Introduce the PROC_SIGCODE() macro

Use a getter macro instead of fetching the sigcode address directly
from a sysent of a given process. It assumes that the sigcode is stored
in the shared page, which is true in all cases, except for a.out
binaries. This will be later useful when the shared page address
randomization is introduced.
No functional change intended.

Approved by: mw(mentor)
Sponsored by: Stormshield
Obtained from: Semihalf
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D35392

2 years agoBump __FreeBSD_version after the removal of OBJT_DEFAULT
Mark Johnston [Mon, 18 Jul 2022 13:44:59 +0000 (09:44 -0400)]
Bump __FreeBSD_version after the removal of OBJT_DEFAULT

Out-of-tree modules which allocate an object of type OBJT_DEFAULT need
to be recompiled.  No other changes are required, however.

2 years agoofed/infiniband: fix ifdefs for new INET changes, fixing LINT-NOIP
Mike Karels [Sat, 16 Jul 2022 21:05:58 +0000 (16:05 -0500)]
ofed/infiniband: fix ifdefs for new INET changes, fixing LINT-NOIP

Some of the ofed/infiniband code has INET and INET6 address handling
code without using ifdefs.  This failed with a recent change to INET,
in which IN_LOOPBACK() started using a VNET variable, and which is not
present if INET is not configured.  Add #ifdef INET, and INET6 for good
measure, in cma_loopback_addr(), along with inclusion of the options
headers in ib_cma.c.

Reviewed by: hselasky rgrimes bz
Differential Revision: https://reviews.freebsd.org/D35835

(cherry picked from commit 752b7632776237f9c071783acdd1136ebf5f287d)

2 years agoblacklistd: Handle 0 sized messages
Ed Maste [Mon, 18 Jul 2022 00:43:52 +0000 (20:43 -0400)]
blacklistd: Handle 0 sized messages

Patch obtained from https://github.com/zoulasc/blocklist commit
ada75856bc6fcabbdd25ffbe08fbad5cf2a2c08a

PR: 264599
MFC after: 1 week

2 years agoarm64, qoriq_therm: fix handling sites on version 1 and 2
Bjoern A. Zeeb [Sun, 10 Jul 2022 13:38:56 +0000 (13:38 +0000)]
arm64, qoriq_therm: fix handling sites on version 1 and 2

For version 2 extend the TMUV2_TMSAR() write loop over all site_ids
registered for a particular SoC and actually use the site_id rather
than always just the first [0] (which for the LX2080 would be a
problem given there is no site0).

Later, while version 2 adds the SITEs to enable to TMSR in bits 0..<n>,
version 1 (e.g., LS1028, LS1046, LS1088) add MSITEs to TMR
bits 16..31 or rather 15..0(16-<n>).  Adjust the loops to only enable
the site_ids listed for the particular SoC for monitoring.  This now
also deals with sparse site_ids (not starting at 0, or not being
contiguous).

MFC after: 1 week
Sponsored by: Traverse Technologies (providing Ten64 HW for testing)
Reviewed by: mmel
Differential Revision: https://reviews.freebsd.org/D35764

2 years agoarm64, qoriq_therm: configure the number of sites base don SoC
Bjoern A. Zeeb [Sat, 9 Jul 2022 00:30:17 +0000 (00:30 +0000)]
arm64, qoriq_therm: configure the number of sites base don SoC

Configure the number of sites (sensors) based on SoC.
This avoids timeouts reading non-existent sensors.

The changes are based on mmel's initial work at:
https://github.com/strejda/freebsd/commit/914e3f0098b090cb5c1492b0d24992012c5c553b

MFC after: 1 week
Sponsored by: Traverse Technologies (providing Ten64 HW for testing)
Reviewed by: mmel
Differential Revision: https://reviews.freebsd.org/D35759

2 years agojail.8: Fix formatting of synopsis and some code examples
Mateusz Piotrowski [Mon, 18 Jul 2022 11:38:00 +0000 (13:38 +0200)]
jail.8: Fix formatting of synopsis and some code examples

MFC after: 3 days

2 years agobeinstall.8: Update example distsites for BSDINSTALL_DISTSITE
Mateusz Piotrowski [Mon, 18 Jul 2022 10:22:42 +0000 (12:22 +0200)]
beinstall.8: Update example distsites for BSDINSTALL_DISTSITE

MFC after: 1 week

2 years agousr.bin/cksum: localize _total variables.
Xin LI [Mon, 18 Jul 2022 00:24:31 +0000 (17:24 -0700)]
usr.bin/cksum: localize _total variables.

2 years agocallout: Simplify the inner loop in callout_process() a bit
Mark Johnston [Fri, 1 Jul 2022 00:16:33 +0000 (20:16 -0400)]
callout: Simplify the inner loop in callout_process() a bit

- Use LIST_FOREACH_SAFE.
- Simplify control flow.

No functional change intended.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

2 years agocallout: Remove a redundant parameter to callout_cc_add()
Mark Johnston [Thu, 30 Jun 2022 17:31:57 +0000 (13:31 -0400)]
callout: Remove a redundant parameter to callout_cc_add()

The passed cpuid is always equal to the one stored in the callout
structure.  No functional change intended.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

2 years agoFix clang 15 warning in cxgbe
Dimitry Andric [Sat, 16 Jul 2022 19:19:51 +0000 (21:19 +0200)]
Fix clang 15 warning in cxgbe

Clang 15 warns:

    sys/dev/cxgbe/cudbg/cudbg_lib.c:2949:6: error: variable 'i' set but not used [-Werror,-Wunused-but-set-variable]
            int i = 0;
                ^

Apparently 'i' was meant as the current retry counter, but '1' was used
in the while loop comparison instead, making the loop potentially
infinite, if 'busy' never gets reset.

MFC after: 3 days
Reviewed by: np
Differential Revision: https://reviews.freebsd.org/D35834

2 years agounbound: Update version strings to 1.16.1
Cy Schubert [Sun, 17 Jul 2022 13:54:32 +0000 (06:54 -0700)]
unbound: Update version strings to 1.16.1

The last number of unbound upgrades failed to manually update the
version strings in usr.sbin/unbound/config.h. This commit fixes that.

Reported by: "Herbert J. Skuhra" <herbert@gojira.at>
Fixes: 0a92a9fca737edafbad03ee5a8efebe302851cff
a39a5a6905612447def27b66ffe73b9d11efd80c
9cf5bc93f6ba1711ae7bf96a982a2b3c8b073a18
273016e836aa378789612e0a0e08d50f28be778e
24e365220007c415f495cf8dcb228ece6002b8b7
5469a9953005a9a4d4aad7be88545d441622e9a0
MFC after: 3 days

2 years agocd9660: Use ANSI (c89) prototypes
Ed Maste [Sun, 17 Jul 2022 12:14:49 +0000 (08:14 -0400)]
cd9660: Use ANSI (c89) prototypes

Sponsored by: The FreeBSD Foundation

2 years agovm_pager: Remove references to KVME_TYPE_DEFAULT in the kernel
Mark Johnston [Sat, 16 Jul 2022 15:31:08 +0000 (11:31 -0400)]
vm_pager: Remove references to KVME_TYPE_DEFAULT in the kernel

Keep the definition around since it's used by userspace.

Reviewed by: alc, imp, kib
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35791

2 years agovm_pager: Remove the default pager
Mark Johnston [Sat, 16 Jul 2022 15:30:19 +0000 (11:30 -0400)]
vm_pager: Remove the default pager

It's unused now.  Keep the OBJ_DEFAULT identifier, but make it an alias
of OBJT_SWAP for the benefit of out-of-tree code.

Reviewed by: alc, imp, kib
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35790

2 years agovm_object: Remove redundant OBJ_SWAP checks
Mark Johnston [Sat, 16 Jul 2022 15:29:53 +0000 (11:29 -0400)]
vm_object: Remove redundant OBJ_SWAP checks

With the removal of OBJT_DEFAULT, OBJ_ANON implies OBJ_SWAP.

Note, this means that vm_object_split() is more expensive than it used
to be, as it holds busy locks until the end of the range is reached,
even if the object has no swap blocks allocated.

Reviewed by: alc, kib
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35789

2 years agovm: Remove handling for OBJT_DEFAULT objects
Mark Johnston [Sat, 16 Jul 2022 15:29:19 +0000 (11:29 -0400)]
vm: Remove handling for OBJT_DEFAULT objects

Now that OBJT_DEFAULT objects can't be instantiated, we can simplify
checks of the form object->type == OBJT_DEFAULT || (object->flags &
OBJ_SWAP) != 0.  No functional change intended.

Reviewed by: alc, kib
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35788

2 years agovm_object: Release object swap charge in the swap pager destructor
Mark Johnston [Sat, 16 Jul 2022 15:28:55 +0000 (11:28 -0400)]
vm_object: Release object swap charge in the swap pager destructor

With the removal of OBJT_DEFAULT, we can simply handle this in
swap_pager_dealloc().  No functional change intended.

Suggested by: alc
Reviewed by: alc, kib
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35787

2 years agoswap_pager: Removing handling for objects with OBJ_SWAP clear
Mark Johnston [Sat, 16 Jul 2022 15:28:09 +0000 (11:28 -0400)]
swap_pager: Removing handling for objects with OBJ_SWAP clear

With the removal of OBJT_DEFAULT, we can assume that pager operations
provide an object with OBJ_SWAP set.  Also, we do not need to convert
objects from type OBJT_DEFAULT.  Thus, remove checks for OBJ_SWAP and
remove code which modifies the object type.  In some places, replace the
check for OBJ_SWAP with a check for whether any swap blocks are
assigned.

Reviewed by: alc, kib
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35786

2 years agovm_object: Modify vm_object_allocate_anon() to return OBJT_SWAP objects
Mark Johnston [Sat, 16 Jul 2022 15:27:27 +0000 (11:27 -0400)]
vm_object: Modify vm_object_allocate_anon() to return OBJT_SWAP objects

With this change, OBJT_DEFAULT objects are no longer allocated.
Instead, anonymous objects are always of type OBJT_SWAP and always have
OBJ_SWAP set.

Modify the page fault handler to check the swap block radix tree in
places where it checked for objects of type OBJT_DEFAULT.  In
particular, there's no need to invoke getpages for an OBJT_SWAP object
with no swap blocks assigned.

Reviewed by: alc, kib
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35785

2 years agostress2: Update the exclude list
Peter Holm [Sun, 17 Jul 2022 07:16:03 +0000 (09:16 +0200)]
stress2: Update the exclude list

2 years agox86/iommu: Eliminate redundant wrappers
Alan Cox [Sat, 16 Jul 2022 04:25:11 +0000 (23:25 -0500)]
x86/iommu: Eliminate redundant wrappers

Reviewed by: kib
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D35832

2 years agoRemove unused but set variable in cxgb_sge
Dimitry Andric [Sat, 16 Jul 2022 18:16:36 +0000 (20:16 +0200)]
Remove unused but set variable in cxgb_sge

Clang 15 warns:

    sys/dev/cxgb/cxgb_sge.c:1290:21: error: variable 'txsd' set but not used [-Werror,-Wunused-but-set-variable]
            struct tx_sw_desc *txsd = &txq->sdesc[txqs->pidx];
                               ^

It appears 'txsd' is a leftover from a previous refactoring (see
3f345a5d09b6), but is no longer used for anything, and can be removed
without any functional change.

MFC after: 3 days
Reviewed by: np
Differential Revision: https://reviews.freebsd.org/D35833

2 years agoAdditional check for UFS/FFS superblock integrity checks.
Kirk McKusick [Sat, 16 Jul 2022 17:31:52 +0000 (10:31 -0700)]
Additional check for UFS/FFS superblock integrity checks.

Tested by:   Peter Holm
PR:          265162

2 years agoClarify when GEOM utilities exit with success or failure.
Kirk McKusick [Sat, 16 Jul 2022 17:25:22 +0000 (10:25 -0700)]
Clarify when GEOM utilities exit with success or failure.

Historically, GEOM utilities (gpart(8), gstripe(8), gmirror(8),
etc) used the gctl_error() routine to report errors. If they called
gctl_error() they would exit with EXIT_FAILURE, otherwise they would
return with EXIT_SUCCESS. If they used gctl_error() to output an
informational message, for example when run with the -v (verbose)
option, they would mistakenly exit with EXIT_FAILURE. A further
limitation of the gctl_error() function was that it could only be
called once. Messages from any additional calls to gctl_error()
would be silently discarded.

To resolve these problems a new function, gctl_msg() has been added.
It can be called multiple times to output multiple messages. It
also has an additional errno argument which should be zero if it is
an informational message or an errno value (EINVAL, EBUSY, etc) if
it is an error. When done the gctl_post_messages() function should
be called to indicate that all messages have been posted. If any
of the messages had a non-zero errno, the utility will EXIT_FAILURE.
If only informational messages (with zero errno) were posted, the
utility will EXIT_SUCCESS.

Tested by:   Peter Holm
PR:          265184
MFC after:   1 week

2 years agoWPA_DISTDIR does not need to end in a slash
Dimitry Andric [Sat, 16 Jul 2022 15:45:26 +0000 (17:45 +0200)]
WPA_DISTDIR does not need to end in a slash

Since all uses of the macro also append a slash, this leads to double
slashes.

MFC after: 3 days

2 years agoAdjust agp_find_device() definition in agp.c to avoid clang 15 warning
Dimitry Andric [Sat, 16 Jul 2022 14:46:21 +0000 (16:46 +0200)]
Adjust agp_find_device() definition in agp.c to avoid clang 15 warning

With clang 15, the following -Werror warning is produced:

    sys/dev/agp/agp.c:910:16: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    agp_find_device()
                   ^
                    void

This is because agp_find_device() is declared with a (void) argument
list, and defined with an empty argument list. Make the definition match
the declaration.

MFC after: 3 days

2 years agoule: unbreak UP builds
Mateusz Guzik [Sat, 16 Jul 2022 12:45:09 +0000 (12:45 +0000)]
ule: unbreak UP builds

Sponsored by: Rubicon Communications, LLC ("Netgate")

2 years agoqat(4): Fix a typo in a source code comment
Gordon Bergling [Sat, 16 Jul 2022 12:26:24 +0000 (14:26 +0200)]
qat(4): Fix a typo in a source code comment

- s/mirco/micro/

Obtained from: NetBSD
MFC after: 3 days

2 years agocommitters-doc.dot: add grahamperrin (Graham Perrin)
Graham Perrin [Sun, 10 Jul 2022 15:25:20 +0000 (16:25 +0100)]
committers-doc.dot: add grahamperrin (Graham Perrin)
Reviewed by:           gjb
Approved by:           gjb
Differential revision: https://reviews.freebsd.org/D35746

2 years agopfctl(8): Fix a typo in a source code comment
Gordon Bergling [Sat, 16 Jul 2022 11:48:30 +0000 (13:48 +0200)]
pfctl(8): Fix a typo in a source code comment

- s/bufer/buffer/

MFC after: 3 days

2 years agoqat(4): Fix a typo in a source code comment
Gordon Bergling [Sat, 16 Jul 2022 11:47:14 +0000 (13:47 +0200)]
qat(4): Fix a typo in a source code comment

- s/bufer/buffer/

Obtained from: NetBSD
MFC after: 3 days

2 years agolinux(4): Fix a typo in a source code comment
Gordon Bergling [Sat, 16 Jul 2022 11:39:17 +0000 (13:39 +0200)]
linux(4): Fix a typo in a source code comment

- s/alredy/already/

MFC after: 3 days

2 years agocxgbe(4): Fix a typo in a source code comment
Gordon Bergling [Sat, 16 Jul 2022 11:38:57 +0000 (13:38 +0200)]
cxgbe(4): Fix a typo in a source code comment

- s/alredy/already/

MFC after: 3 days

2 years agoenetc: Fix a typo in a source code comment
Gordon Bergling [Sat, 16 Jul 2022 11:38:27 +0000 (13:38 +0200)]
enetc: Fix a typo in a source code comment

- s/alredy/already/

MFC after: 3 days

2 years agocrunchide(1): Fix a typo in a comment
Gordon Bergling [Sat, 16 Jul 2022 11:32:47 +0000 (13:32 +0200)]
crunchide(1): Fix a typo in a comment

- s/maek/make/

Obtained from: NetBSD
MFC after: 3 days

2 years agokdump(1): Sort options in alphabetical order.
Dmitry Chagin [Sat, 16 Jul 2022 09:47:54 +0000 (12:47 +0300)]
kdump(1): Sort options in alphabetical order.

Reviewed by: imp (early rev)
Differential Revision: https://reviews.freebsd.org/D35775
MFC after: 2 weeks

2 years agoktrace: Increase precision of timestamps.
Dmitry Chagin [Sat, 16 Jul 2022 09:46:12 +0000 (12:46 +0300)]
ktrace: Increase precision of timestamps.

Replace struct timeval in header with struct timespec.
To differentiate header formats, add a new KTR_VERSIONED flag
set in the header type field similar to the existing KTRDROP flag.

To make it easier to extend ktrace headers in the future,
extend the existing header with a version field (version 0 is
reserved for older records without KTR_VERSIONED) as well as
new fields holding the thread ID and CPU ID.

Reviewed by: jhb, pauamma
Differential Revision: https://reviews.freebsd.org/D35774
MFC after: 2 weeks

2 years agoiommu: Shrink the iommu map entry structure
Alan Cox [Mon, 11 Jul 2022 03:52:52 +0000 (22:52 -0500)]
iommu: Shrink the iommu map entry structure

Eliminate the unroll_entry field from struct iommu_map_entry, shrinking
the struct by 16 bytes on 64-bit architectures.

Reviewed by: kib
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D35769

2 years agorelease: Support GNU stat in mkisoimages.sh
Jessica Clarke [Fri, 15 Jul 2022 22:04:48 +0000 (23:04 +0100)]
release: Support GNU stat in mkisoimages.sh

BSD stat and GNU stat differ significantly when it comes to using a
custom format string, both in the option name and in the format string
itself. Handle both here (assuming Linux means GNU stat rather than BSD
stat).

Reviewed by: brooks, gjb
Obtained from: CheriBSD
Differential Revision: https://reviews.freebsd.org/D35814

2 years agoMakefile.inc1 release bsd.own.mk: Introduce and use TAR_CMD
Jessica Clarke [Fri, 15 Jul 2022 22:04:34 +0000 (23:04 +0100)]
Makefile.inc1 release bsd.own.mk: Introduce and use TAR_CMD

Our uses of tar rely on BSDisms, and so do not work in environments
where GNU tar is the default tar. Providing a TAR_CMD variable like
some other commands allows it to be overridden to use bsdtar in such
cases.

Reviewed by: brooks, delphij, gjb
Obtained from: CheriBSD
Differential Revision: https://reviews.freebsd.org/D35813

2 years agoMakefile.inc1: Set LC_COLLATE in distributeworld for glibc compatibility
Jessica Clarke [Fri, 15 Jul 2022 22:04:26 +0000 (23:04 +0100)]
Makefile.inc1: Set LC_COLLATE in distributeworld for glibc compatibility

distributeworld relies on "foo" sorting directly before "foo type=...",
but with glibc both en_US and en_GB have "fooa" sort between "foo" and
"foo z", resulting in some files (in particular, id due to "ident"
sorting before "id type=" but after "id") not being included in the meta
files and thus not included in the dist tarballs. Forcing use of the C
locale ensures this does not occur.

Reviewed by: brooks
Obtained from: CheriBSD
Differential Revision: https://reviews.freebsd.org/D35812

2 years agoetc: Fix distrib-dirs to not rely on a BSDism
Jessica Clarke [Fri, 15 Jul 2022 22:04:16 +0000 (23:04 +0100)]
etc: Fix distrib-dirs to not rely on a BSDism

FreeBSD and macOS have a test that treats == as an alias for =, but
Linux tends to use GNU coreutils (when not a builtin) which does not.
Use the standard syntax instead for compatibility.

Obtained from: CheriBSD
Differential Revision: https://reviews.freebsd.org/D35811

2 years agoMakefile.inc1: Honour DB_FROM_SRC for NO_ROOT distributeworld
Jessica Clarke [Fri, 15 Jul 2022 22:03:49 +0000 (23:03 +0100)]
Makefile.inc1: Honour DB_FROM_SRC for NO_ROOT distributeworld

Currently the host's database files are used, but on non-FreeBSD these
are not necessarily sufficient; in particular, Linux does not have a
wheel group. Instead, use -N to use the in-tree database files when
creating the METALOG entries, as is done for the recursive makes via
IMAKE_MTREE.

Reviewed by: brooks
Obtained from: CheriBSD
Differential Revision: https://reviews.freebsd.org/D35810

2 years agoAdjust parse() definition in boot2 to avoid clang 15 warning
Dimitry Andric [Fri, 15 Jul 2022 19:15:11 +0000 (21:15 +0200)]
Adjust parse() definition in boot2 to avoid clang 15 warning

With clang 15, the following -Werror warning is produced:

    stand/i386/boot2/boot2.c:358:6: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]

This is because parse() is declared with a (void) argument list, and
defined with an empty argument list. Make the definition match the
declaration.

MFC after: 3 days

2 years agoMerge fix for zfs readmmap test from CheriBSD
Dimitry Andric [Fri, 15 Jul 2022 19:10:09 +0000 (21:10 +0200)]
Merge fix for zfs readmmap test from CheriBSD

Merge commit 1737d8397a0 by Brooks Davis:

  time() is declared in time.h

This fixes a -Werror warning from clang 15:

  tests/sys/cddl/zfs/bin/readmmap.c:97:9: error: call to undeclared function 'time'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

Obtained from: https://github.com/CTSRD-CHERI/cheribsd/commit/1737d8397a0
MFC after: 3 days

2 years agoRemove unnecessary const and volatile qualifiers from __fp_type_select()
Dimitry Andric [Thu, 14 Jul 2022 11:20:52 +0000 (13:20 +0200)]
Remove unnecessary const and volatile qualifiers from __fp_type_select()

Since https://github.com/llvm/llvm-project/commit/ca75ac5f04f2, clang 15
has a new warning about _Generic selection expressions, such as used in
math.h:

    lib/libc/gdtoa/_ldtoa.c:82:10: error: due to lvalue conversion of the controlling expression, association of type 'volatile float' will never be selected because it is qualified [-Werror,-Wunreachable-code-generic-assoc]
            switch (fpclassify(u.e)) {
                    ^
    lib/msun/src/math.h:109:2: note: expanded from macro 'fpclassify'
            __fp_type_select(x, __fpclassifyf, __fpclassifyd, __fpclassifyl)
            ^
    lib/msun/src/math.h:85:14: note: expanded from macro '__fp_type_select'
        volatile float: f(x),                                               \
                 ^

This is because the controlling expression always undergoes lvalue
conversion first, dropping any cv-qualifiers. The 'const', 'volatile',
and 'volatile const' associations will therefore never be used.

MFC after: 1 week
Reviewed by: theraven
Differential Revision: https://reviews.freebsd.org/D35815

2 years agokboot: Pull in constants from Linux's mmap.h api
Warner Losh [Tue, 28 Jun 2022 16:43:42 +0000 (10:43 -0600)]
kboot: Pull in constants from Linux's mmap.h api

Define the usual #defines for mmap(2) (with HOST_ prepended) and use
them instead of hard coding constants.

Sponsored by: Netflix

2 years agokboot: Properly cap number of segments loaded for kexec
Warner Losh [Wed, 29 Jun 2022 22:31:23 +0000 (16:31 -0600)]
kboot: Properly cap number of segments loaded for kexec

Linux has an arbitrary limit of 16 segments. Make sure we don't load too
many.

Sponsored by: Netflix

2 years agokboot: Refinements to host_kexec_load
Warner Losh [Tue, 28 Jun 2022 16:40:04 +0000 (10:40 -0600)]
kboot: Refinements to host_kexec_load

Move kexec_segments to host_syscall.h and pre-pend host_ to it.  Correct
args to host_exec_load.

Sponsored by: Netflix

2 years agokboot: Use #defines for magic reboot constants
Warner Losh [Tue, 28 Jun 2022 14:44:16 +0000 (08:44 -0600)]
kboot: Use #defines for magic reboot constants

Sponsored by: Netflix

2 years agokboot: Implement mount(2)
Warner Losh [Thu, 30 Jun 2022 18:16:46 +0000 (12:16 -0600)]
kboot: Implement mount(2)

Create a wrapper for the mount system call. To ensure a sane early boot
environment and to gather data we need for kexec, we may need to mount
some special filesystems.

Sponsored by: Netflix

2 years agokboot: Implement mkdir(2)
Warner Losh [Thu, 30 Jun 2022 18:09:26 +0000 (12:09 -0600)]
kboot: Implement mkdir(2)

mkdir() may be needed early in boot to create missing
directories. Provide a syscall wrapper for it.

Sponsored by: Netflix

2 years agokboot: Implement dup(2)
Warner Losh [Thu, 30 Jun 2022 18:25:49 +0000 (12:25 -0600)]
kboot: Implement dup(2)

Early in boot, we need to create the normal stdin/out/err env for the
boot loader to run in. To do that, we need to open the console and
duplicate the file descriptors which requires dup(2). Implement a
wrapper as host_dup.

Sponsored by: Netflix

2 years agokboot: Implement symlink(2)
Warner Losh [Thu, 30 Jun 2022 18:22:33 +0000 (12:22 -0600)]
kboot: Implement symlink(2)

Linux's /dev/fd is implemented inside of /proc/self/fd, so we may need
to create a symlink to it early in boot. "/dev/fd" and "/dev/std*" might
not be strictly required for the boot loader, but should be present for
maximum flexibility.

Sponsored by: Netflix

2 years agokboot: Implement getpid(2)
Warner Losh [Thu, 30 Jun 2022 18:12:51 +0000 (12:12 -0600)]
kboot: Implement getpid(2)

Add host_getpid() so we can know if we're running as init(8) or not.  If
we are, we may chose to do early system setup / sanity operations.

Sponsored by: Netflix

2 years agokboot: Implement munmap(2)
Warner Losh [Mon, 27 Jun 2022 23:49:21 +0000 (17:49 -0600)]
kboot: Implement munmap(2)

Define host_munmap so we can use it in the x86 code to find things for
the BIOS/CMS boot path and unmap after we find it.

Sponsored by: Netflix

2 years agokboot: Implement stat(2) and fstat(2) system calls
Warner Losh [Fri, 15 Jul 2022 05:19:18 +0000 (23:19 -0600)]
kboot: Implement stat(2) and fstat(2) system calls

Implement stat(2) and fstat(2) in terms of newfstatat and newfstat
system calls respectively (assume we have a compat #define when
there's no newfstat and just a regular fstat and do so for ppc).

Snag struct kstat (the Linux kernel stat(2), et al interface) from musl
and attribute properly.

Sponsored by: Netflix

2 years agokboot: Add HOST_O_ constants for open, etc
Warner Losh [Fri, 1 Jul 2022 17:57:02 +0000 (11:57 -0600)]
kboot: Add HOST_O_ constants for open, etc

Add the common O_ constants for the open, fcntl, etc system calls. They
are different than FreeBSD's. While they can differ based on
architecture, they are constant for architectures we care about, and
those architectures use the 'generic' version so future architectures
will also work.

Sponsored by: Netflix

2 years agokboot: Enhance kboot_getdev to cope with NULLs
Warner Losh [Fri, 15 Jul 2022 13:32:16 +0000 (07:32 -0600)]
kboot: Enhance kboot_getdev to cope with NULLs

Fallback to currdev when NULL is passed in when 'rootdev' is NULL. Other
getdevs do this. Additional features are needed here still, though.

Sponsored by: Netflix

2 years agokboot: Reimplement older system calls in terms of newer ones
Warner Losh [Thu, 7 Jul 2022 22:58:27 +0000 (16:58 -0600)]
kboot: Reimplement older system calls in terms of newer ones

aarch64 doesn't have open, just openat, etc. Cope.

Sponsored by: Netflix

2 years agokboot: Rework _start
Warner Losh [Thu, 14 Jul 2022 03:41:17 +0000 (21:41 -0600)]
kboot: Rework _start

Split _start into _start and _start_c (inspired by musl and the powerpc
impl is copied from there). This allows us to actually get the command
line arguments on all the platforms. We have a very simplified startup
that supports only static linking.

Sponsored by: Netflix

2 years agostand: Remove extra efi.h include
Warner Losh [Thu, 7 Jul 2022 22:58:01 +0000 (16:58 -0600)]
stand: Remove extra efi.h include

There's nothing EFI specific about this file, so remove including efi.h.

Sponsored by: Netflix

2 years agotcp: Undo the increase in sequence number by 1 due to the FIN flag in case of a trans...
Richard Scheffenegger [Thu, 14 Jul 2022 00:49:10 +0000 (02:49 +0200)]
tcp: Undo the increase in sequence number by 1 due to the FIN flag in case of a transient error.

If an error occurs while processing a TCP segment with some data and the FIN
flag, the back out of the sequence number advance does not take into account the
increase by 1 due to the FIN flag.

Reviewed By: jch, gnn, #transport, tuexen
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D2970

2 years agotelnet: Fix telnet segfault when invalid set or help help commands
Cy Schubert [Thu, 14 Jul 2022 04:42:06 +0000 (21:42 -0700)]
telnet: Fix telnet segfault when invalid set or help help commands

Silently ignore invalid set ' ' and invalid help help commands.
This is the same fix applied by NetBSD in hg commit 1019940:4f248823eaff.

PR: 265097
Reported by: Simon Josefsson <simon@josefsson.org>
Obtained from: NetBSD hg commit 1019940:4f248823eaff
NetBSD PR/56918
MFC after: 1 week

2 years agostress2: Enable more swap disk usage
Peter Holm [Fri, 15 Jul 2022 08:19:39 +0000 (10:19 +0200)]
stress2: Enable more swap disk usage

2 years agostress2: Handle "gunion create" error exit
Peter Holm [Fri, 15 Jul 2022 08:17:23 +0000 (10:17 +0200)]
stress2: Handle "gunion create" error exit

2 years agoinet.4 tcp.4 udp.4: update date, fix typo
Mike Karels [Thu, 14 Jul 2022 21:31:28 +0000 (16:31 -0500)]
inet.4 tcp.4 udp.4: update date, fix typo

Update .Dd for man pages pushed yesterday; fix typo in inet.4.

2 years agoBootstrap crunchgen after removing -dc from linker invocation
Dimitry Andric [Thu, 14 Jul 2022 21:13:41 +0000 (23:13 +0200)]
Bootstrap crunchgen after removing -dc from linker invocation

In ec81497cc726 crunchgen was updated to remove -dc from the linker
invocations in its generated makefile output, as this flag is no longer
necessary, and is going to be an error with lld 15.

Update the BOOTSTRAPPING conditions for copying the crunchgen binary
from the host, or actually bootstrapping it when necessary. Since
ec81497cc726 did not bump __FreeBSD_version, I have chosen the nearest
values.

Fixes: ec81497cc726
MFC after: 3 days

2 years agoDelay GEOM disk_create() until CAM periph probe completes.
Alexander Motin [Thu, 14 Jul 2022 19:38:14 +0000 (15:38 -0400)]
Delay GEOM disk_create() until CAM periph probe completes.

Before this patch CAM periph drivers called both disk_alloc() and
disk_create() same time on periph creation.  But then prevented disks
from opening until the periph probe completion with cam_periph_hold().
As result, especially if disk misbehaves during the probe, GEOM event
thread, triggered to taste the disk, got blocked on open attempt,
potentially for a long time, unable to process other events.

This patch moves disk_create() call from periph creation to the end of
the probe. To allow disk_create() calls from non-sleepable CAM contexts
some of its duties requiring memory allocations are moved either back
to disk_alloc() or forward to g_disk_create(), so now disk_alloc() and
disk_add_alias() are the only disk methods that require sleeping.  If
disk fails during the probe disk_create() may just be skipped, going
directly to disk_destroy().  Other method calls during that time are
just ignored.  Since GEOM may now see the disks after CAM bus scan is
already completed, introduce per-periph boot hold functions. Enclosure
driver already had such mechanism, so just generalize it.

Reviewed by: imp
MFC after: 1 month
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D35784

2 years agoReclaim unused ithread priorities for user time-sharing threads.
John Baldwin [Thu, 14 Jul 2022 20:14:58 +0000 (13:14 -0700)]
Reclaim unused ithread priorities for user time-sharing threads.

Leave one band of ithread priorities available below PI_SOFT for
demoted ithreads but reclaim additional ithread priorities for use by
user time-sharing threads.  This is an ABI change in that PZERO moves
up so old ps and top binaries will not format priorities correctly on
newer kernels, but that is a cosmetic rather than functional change.

Reviewed by: kib, markj
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D35647

2 years agoCollapse interrupt thread priorities.
John Baldwin [Thu, 14 Jul 2022 20:14:33 +0000 (13:14 -0700)]
Collapse interrupt thread priorities.

Allow high priority hardware interrupts to run at PI_REALTIME via
INTR_TYPE_CLK, but collapse all other hardware interrupt threads to
the next priority level (PI_INTR).  Collapse all SWI priorities to
the same priority level (PI_SOFT) just below PI_INTR.

Reviewed by: kib, markj
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D35646

2 years ago4bsd: Simplistic time-sharing for interrupt threads.
John Baldwin [Thu, 14 Jul 2022 20:14:17 +0000 (13:14 -0700)]
4bsd: Simplistic time-sharing for interrupt threads.

If an interrupt thread runs for a full quantum without yielding the
CPU, demote its priority and schedule a preemption to give other
ithreads a turn.

Reviewed by: kib
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D35645

2 years agoule: Simplistic time-sharing for interrupt threads.
John Baldwin [Thu, 14 Jul 2022 20:13:57 +0000 (13:13 -0700)]
ule: Simplistic time-sharing for interrupt threads.

If an interrupt thread runs for a full quantum without yielding the
CPU, demote its priority and schedule a preemption to give other
ithreads a turn.

Reviewed by: kib, markj
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D35644

2 years agoithreads: Support priority adjustment by schedulers.
John Baldwin [Thu, 14 Jul 2022 20:13:35 +0000 (13:13 -0700)]
ithreads: Support priority adjustment by schedulers.

Use sched_wakeup instead of sched_add when marking an ithread
runnable.  This allows schedulers to reset their internal time slice
tracking state and restore the base ithread priority when an ithread
resumes from idle.

Reviewed by: markj
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D35643

2 years agoAdd sched_ithread_prio to set the base priority of an interrupt thread.
John Baldwin [Thu, 14 Jul 2022 20:13:10 +0000 (13:13 -0700)]
Add sched_ithread_prio to set the base priority of an interrupt thread.

Use it instead of sched_prio when setting the priority of an interrupt
thread.

Reviewed by: kib, markj
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D35642

2 years agodepend-cleanup.sh: Handle kqtest being renamed to kqueue_test.
John Baldwin [Thu, 14 Jul 2022 20:03:59 +0000 (13:03 -0700)]
depend-cleanup.sh: Handle kqtest being renamed to kqueue_test.

bmake will not think that object files such as read.o are out of date
due to common.h changing since the dependency is only recorded in
.depend.kqtest.read.o in an old object directory.

Reviewed by: markj
Fixes: 68fe988a40ca kqueue tests: Simplify the test runner
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D35820

2 years agogcore: Trim stale bits from elf32core.c.
John Baldwin [Thu, 14 Jul 2022 20:03:34 +0000 (13:03 -0700)]
gcore: Trim stale bits from elf32core.c.

These should have been removed in
d95657a1a758e8d993a0eb92259f8c860a309207.

Reviewed by: markj
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D35748

2 years agosched_ule: Use the correct atomic_load variant for tdq_lowpri
Mark Johnston [Thu, 14 Jul 2022 19:34:02 +0000 (15:34 -0400)]
sched_ule: Use the correct atomic_load variant for tdq_lowpri

Reported by: tuexen
Fixes: 11484ad8a2b0 ("sched_ule: Use explicit atomic accesses for tdq fields")

2 years agosched_ule: Use explicit atomic accesses for tdq fields
Mark Johnston [Thu, 14 Jul 2022 14:43:53 +0000 (10:43 -0400)]
sched_ule: Use explicit atomic accesses for tdq fields

Different fields in the tdq have different synchronization protocols.
Some are constant, some are accessed only while holding the tdq lock,
some are modified with the lock held but accessed without the lock, some
are accessed only on the tdq's CPU, and some are not synchronized by the
lock at all.

Convert ULE to stop using volatile and instead use atomic_load_* and
atomic_store_* to provide the desired semantics for lockless accesses.
This makes the intent of the code more explicit, gives more freedom to
the compiler when accesses do not need to be qualified, and lets KCSAN
intercept unlocked accesses.

Thus:
- Introduce macros to provide unlocked accessors for certain fields.
- Use atomic_load/store for all accesses of tdq_cpu_idle, which is not
  synchronized by the mutex.
- Use atomic_load/store for accesses of the switch count, which is
  updated by sched_clock().
- Add some comments to fields of struct tdq describing how accesses are
  synchronized.

No functional change intended.

Reviewed by: mav, kib
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35737

2 years agox86: Add a required store-load barrier in cpu_idle()
Mark Johnston [Thu, 14 Jul 2022 14:24:25 +0000 (10:24 -0400)]
x86: Add a required store-load barrier in cpu_idle()

ULE's tdq_notify() tries to avoid delivering IPIs to the idle thread.
In particular, it tries to detect whether the idle thread is running.
There are two mechanisms for this:
- tdq_cpu_idle, an MI flag which is set prior to calling cpu_idle().  If
  tdq_cpu_idle == 0, then no IPI is needed;
- idle_state, an x86-specific state flag which is updated after
  cpu_idleclock() is called.

The implementation of the second mechanism is racy; the race can cause a
CPU to go to sleep with pending work.  Specifically, cpu_idle_*() set
idle_state = STATE_SLEEPING, then check for pending work by loading the
tdq_load field of the CPU's runqueue.  These operations can be reordered
so that the idle thread observes tdq_load == 0, and tdq_notify()
observes idle_state == STATE_RUNNING.

Some counters indicate that the idle_state check in tdq_notify()
frequently elides an IPI.  So, fix the problem by inserting a fence
after the store to idle_state, immediately before idling the CPU.

PR: 264867
Reviewed by: mav, kib, jhb
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35777

2 years agosched_ule: Enable preemption of curthread in the load balancer
Mark Johnston [Thu, 14 Jul 2022 14:23:43 +0000 (10:23 -0400)]
sched_ule: Enable preemption of curthread in the load balancer

The load balancer executes from statclock and periodically tries to move
threads among CPUs in order to balance load.  It may move a thread to
the current CPU (the loader balancer always runs on CPU 0).  When it
does so, it may need to schedule preemption of the interrupted thread.
Use sched_setpreempt() to do so, same as sched_add().

PR: 264867
Reviewed by: mav, kib, jhb
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35744

2 years agosched_ule: Fix racy loads of pc_curthread
Mark Johnston [Thu, 14 Jul 2022 14:21:28 +0000 (10:21 -0400)]
sched_ule: Fix racy loads of pc_curthread

Thread switching used to be atomic with respect to the current CPU's
tdq lock.  Since commit 686bcb5c14ab that is no longer the case.  Now
sched_switch() does this:

1.  lock tdq (might already be locked)
2.  maybe put the current thread in the tdq, choose a new thread to run
2a. update tdq_lowpri
3.  unlock tdq
4.  switch CPU context, update curthread

Some code paths in ULE will load pc_curthread from a remote CPU with
that CPU's tdq lock held, usually to inspect its priority.  But, as of
the aforementioned commit this is racy.

The problem I noticed is in tdq_notify(), which optionally sends an IPI
to a remote CPU when a new thread is added to its runqueue.  If the new
thread's priority is higher (lower) than the currently running thread's
priority, then we deliver an IPI.  But inspecting
pc_curthread->td_priority doesn't work, since pc_curthread might be
between steps 3 and 4 above.  If pc_curthread's priority is higher than
that of the newly added thread, but pc_curthread is switching to a
lower-priority thread, then tdq_notify() might fail to deliever an IPI,
leaving a high priority thread stuck on the runqueue for longer than it
should.  This can cause multi-millisecond stalls in
interactive/ithread/realtime threads.

Fix this problem by modifying tdq_add() and tdq_move() to return the
value of tdq_lowpri before the addition of the new thread.  This ensures
that tdq_notify() has the correct priority value to compare against.

The other two uses of pc_curthread are susceptible to the same race.  To
fix the one in sched_rem()->tdq_setlowpri() we need to have an exact
value for curthread.  Thus, introduce a new tdq_curthread field to the
tdq which gets updated any time a new thread is selected to run on the
CPU.  Because this field is synchronized by the thread lock, its
priority reflects the correct lowpri value for the tdq.

PR: 264867
Fixes: 686bcb5c14ab ("schedlock 4/4")
Reviewed by: mav, kib, jhb
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35736

2 years agoinet.4 tcp.4 udp.4: Replace *CTL_* OID macro names with sysctl names
Mike Karels [Wed, 13 Jul 2022 17:50:23 +0000 (12:50 -0500)]
inet.4 tcp.4 udp.4: Replace *CTL_* OID macro names with sysctl names

Older sysctls with constant OID macros were identified with those
in inet.4, tcp.4, and udp.4; newer sysctls with automatic numbering
were identified by sysctl names.  No one remembers the OID macros,
or knows what they are; sysctls are always done by name now, usually
via sysctl(8).

Replace the OID macro names with sysctl names so that there is one
uniform identifier type; sysctl names were previously in parens.
Make the formatting a little more consistent in this area.  In inet.4
and udp.4, move the "ip." or "udp." prefix from each entry into the
top-level name at the start of the section, as they are all the same.

Reviewed by: rpokala
Differential Revision: https://reviews.freebsd.org/D35806