Commit graph

139039 commits

Author SHA1 Message Date
Vitaliy Gusev
b1ced97e75 vmm: vlapic resume can eat 100% CPU by vlapic_callout_handler
Suspend/Resume of Win10 leads that CPU0 is busy on handling interrupts.

Win10 does not use LAPIC timer to often and in most cases, and I see it
is disabled by writing 0 to Initial Count Register (for Timer).

During resume, restart timer only for enabled LAPIC and enabled timer
for that LAPIC.

Reviewed by:	markj

(cherry picked from commit c72e914cf1)
2022-01-25 09:55:09 -05:00
Andriy Gapon
82acfc0d78 add and use defintions for ATA power modes
Those can be returned by CHECK POWER MODE command (0xe5).
Note that some of the definitions duplicate definitions for Extended
Power Conditions.

(cherry picked from commit 75bc7150f4)
2022-01-25 09:43:11 +02:00
Ka Ho Ng
192c87bf7d iscsi: Fix missing is_lock unlock after cam_simq_alloc() failed
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit fa66950534)
2022-01-25 01:02:33 -05:00
Jessica Clarke
5272c66a00 hwpmc: Fix amd/arm64/armv7/uncore sampling overflow race
If a counter more than overflows just as we read it on switch out then,
if using sampling mode, we will negate this small value to give a huge
reload count, and if we later switch back in that context we will
validate that value against pm_reloadcount and panic an INVARIANTS
kernel with:

  panic: [pmc,1470] pmcval outside of expected range cpu=2 ri=16 pmcval=fffff292 pm_reloadcount=10000

or similar. Presumably in a non-INVARIANTS kernel we will instead just
use the provided value as the reload count, which would lead to the
overflow not happing for a very long time (e.g. 78 minutes for a 48-bit
counter incrementing at an averate rate of 1GHz).

Instead, clamp the reload count to 0 (which corresponds precisely to the
value we would compute if it had just overflowed and no more), which
will result in hwpmc using the full original reload count again. This is
the approach used by core for Intel (for both fixed and programmable
counters).

As part of this, armv7 and arm64 are made conceptually simpler; rather
than skipping modifying the overflow count for sampling mode counters so
it's always kept as ~0, those special cases are removed so it's always
applicable and the concatentation of it and the hardware counter can
always be viewed as a 64-bit counter, which also makes them look more
like other architectures.

Whilst here, fix an instance of UB (shifting a 1 into the sign bit) for
amd in its sign-extension code.

Reviewed by:	andrew, mhorne, kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33654

(cherry picked from commit e74c7ffcb1)
2022-01-25 00:00:01 +00:00
Jessica Clarke
942bc09fc2 arm64: Check for intrng-reported errors in gicv3_its
Currently, any errors when adding a PIC child handler are ignored,
instead just continuing on to registering that PIC as an MSI, and
ignoring any errors that occur for that too.

Reviewed by:	andrew
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33342

(cherry picked from commit 3582b9e372)
2022-01-24 23:59:58 +00:00
Jessica Clarke
f63a2e288c intrng: Use less confusing return value for intr_pic_add_handler
Currently intr_pic_add_handler either returns the PIC you gave it (which
is useless and risks causing confusion about whether it's creating
another PIC) or, on error, NULL. Instead, convert it to return an int
error code as one would expect.

Note that the only consumer of this API, arm64's gicv3_its, does not use
the return value, so no uses need updating to work with the revised API.

Reviewed by:	markj, mmel
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33341

(cherry picked from commit a3e828c91d)
2022-01-24 23:59:55 +00:00
Jessica Clarke
b85b57e0f4 arm64: Don't rely on host readelf for u-boot booti image generation
readelf is not a bootstrap tool and so cannot be relied upon to exist.
On macOS there is no system readelf, and even on Linux or FreeBSD where
it does exist, BUILD_WITH_STRICT_TMPPATH builds won't be able to use it.
Instead of making it a bootstrap tool, just use nm as that suffices and
already is a bootstrap tool.

Fixes:		28482babd0 ("arm64: Use new arm_kernel_boothdr script for generating booti images.")
Reviewed by:	emaste, mmel
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D32734

(cherry picked from commit 1846bbd1b3)
2022-01-24 23:59:51 +00:00
Jessica Clarke
3c7f332f71 Fix buffer overread in preloaded hostuuid parsing
Commit b6be9566d2 stopped prison0_init writing outside of the
preloaded hostuuid's bounds. However, the preloaded data will not
(normally) have a NUL in it, and so validate_uuid will walk off the end
of the buffer in its call to sscanf. Previously if there was any
whitespace in the string we'd at least know there's a NUL one past the
end due to the off-by-one error, but now no such byte is guaranteed.

Fix this by copying to a temporary buffer and explicitly adding a NUL.

Whilst here, change the strlcpy call to use a far less suspicious
argument for dstsize; in practice it's fine, but it's an unusual pattern
and not necessary.

Found by:	CHERI
Reviewed by:	emaste, kevans, jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33616

(cherry picked from commit d2ef377430)
2022-01-24 23:59:49 +00:00
Jessica Clarke
3ca6bdef85 xdma: Fix another -Wunused-but-set-variable warning previously missed
MFC after:	1 week

(cherry picked from commit fa5af3219f)
2022-01-24 23:59:38 +00:00
Jessica Clarke
297c86f8bc riscv: Fix PLIC -Wunused-but-set-variable warnings
(cherry picked from commit 434cb1c4a6)
2022-01-24 23:59:35 +00:00
Jessica Clarke
c95bc1a7f9 xdma: Fix -Wunused-but-set-variable warnings
MFC after:	1 week

(cherry picked from commit d90c3b51cc)
2022-01-24 23:59:33 +00:00
Jessica Clarke
1c818a7e57 amd64: Pass DEBUG when building VDSO wrapper
Not doing so results in ctfconvert failing with

  ERROR: ctfconvert: elf-vdso.so.o doesn't have type data to convert

On FreeBSD this is non-fatal, since the ctf tools have a hack to make
such errors not fail the build and instead just silently continue
without CTF data (which is a bad idea these days and should probably be
removed; they date back to the original import). However, those are
under #ifdef __FreeBSD__ so do not apply when cross-building from
non-FreeBSD, causing the build to fail.

Fix this by forwarding DEBUG on to the compiler invocation for the VDSO
wrapper. It's assembly so it's not hugely useful, but there is a
non-zero amount of information preserved, and other assembly files are
built with -g by default too so this matches them; the alternative would
be to tag the files.amd64 entries with no-ctfmerge. Note that the VDSO
itself is still compiled without debug info, this only affects the
wrapper linked into the kernel.

Fixes:		98c8b62524 ("vdso for ia32 on amd64"), ab4524b3d7 ("amd64: wrap 64bit sigtramp into vdso")
MFC after:	1 month

(cherry picked from commit 169b368a62)
2022-01-24 23:59:30 +00:00
Jessica Clarke
85e89ae421 zlib: Fix bootstrap build on macOS
gzlib.c uses lseek but does not include unistd.h, where it is defined to
live. On FreeBSD this happens to work due to sys/types.h declaring it,
but on macOS it fails due to being only implicitly declared, which is
treated as an error by default by the system Clang.

MFC after:	1 week

(cherry picked from commit 6010a892b4)
2022-01-24 23:59:16 +00:00
Mark Johnston
c595625abe Revert "kern_exec: Add kern.stacktop sysctl."
The current ASLR stack gap feature will be removed, and with that the
need for the kern.stacktop sysctl is gone.  All consumers have been
removed.

This reverts commit a97d697122.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 1544f5add8)
2022-01-24 09:20:21 -05:00
Mark Johnston
1a97674b46 setrlimit: Remove special handling for RLIMIT_STACK with a stack gap
This will not be required with a forthcoming reimplementation of ASLR
stack randomization.  Moreover, this change was not sufficient to enable
the use of a stack size limit smaller than the stack gap itself.

PR:		260303
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 5a8413e779)
2022-01-24 09:16:52 -05:00
Mark Johnston
9795d85d2e posixshm: Report output buffer truncation from kern.ipc.posix_shm_list
PR:		240573
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit dc7526170d)
2022-01-24 09:16:37 -05:00
Alexander Motin
70201cc45d Reduce minimum idle hardclock rate from 2Hz to 1Hz.
On idle 80-thread system it allows to improve package-level idle state
residency and so power consumption by several percent.

MFC after:	2 weeks

(cherry picked from commit cb1f5d1136)
2022-01-23 21:35:58 -05:00
Alexander Motin
15e1d8f69b Fix inverse sleep logic in buf_daemon().
Before commit 3cec5c77d6 buf_daemon() went to longer 1s sleep if
numdirtybuffers <= lodirtybuffers.  After that commit new condition
!BIT_EMPTY(BUF_DOMAINS, &bdlodirty) got opposite -- true when one
or more more domains is above lodirtybuffers.  As result, on freshly
booted system with no dirty buffers buf_daemon() wakes up 10 times
per second and probably only 1 time per second when there is actual
work to do.

MFC after:	1 week
Reviewed by:	kib, markj
Tested by:	pho
Differential revision:	https://reviews.freebsd.org/D33890

(cherry picked from commit e76c010899)
2022-01-23 14:57:35 -05:00
Alexander Motin
3540f6b4af nfsd: Reduce callouts rate.
Before this callouts were scheduled twice a seconds even if nfsd was
never used.  This reduces the rate to ~1Hz and only after nfsd first
started.

MFC after:	2 weeks

(cherry picked from commit 3455c738ac)
2022-01-23 14:57:35 -05:00
Alexander Motin
0dc8e3fe6f mps/mpr: Relax doorbell polling precision.
It does not matter how often do we check firmware for crashes.

MFC after:	2 weeks

(cherry picked from commit 1849bc5f3f)
2022-01-23 14:57:35 -05:00
Vladimir Kondratyev
dee0854a00 Bump __FreeBSD_version for LinuxKPI changes
(cherry picked from commit ed6417cd8d)
2022-01-22 22:34:38 +03:00
Vladimir Kondratyev
ba0f2d7807 LinuxKPI: Add sort() wrapper.
swap parameter is not supported as it is rarely used in Linux kernel
and its implementation will add some preprocessor spaghetti to qsort.

Required by drm-kmod.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33675

(cherry picked from commit 7356f661e8)
2022-01-22 22:34:38 +03:00
Vladimir Kondratyev
ef743744f0 LinuxKPI: Use negative bit field size to trigger BUILD_BUG_ON_ZERO
compile time assertion on non-NULL pointers. Tests conducted show that
_Static_assert, negative array size method and current code does not
handle pointers well enough. Bit field method solves this problem.

This change is derrived from Linux implementation of BUILD_BUG_ON_ZERO.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33674

(cherry picked from commit 64dab63f3b)
2022-01-22 22:34:38 +03:00
Vladimir Kondratyev
2d0694b953 LinuxKPI: Constantly use _LINUXKPI_ prefix in include guards
MFC after:	1 week
Reviewed by:	bz, emaste, hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33562

(cherry picked from commit 307f78f3ed)
2022-01-22 22:34:38 +03:00
Vladimir Kondratyev
2d90567415 LinuxKPI: Import MTRR support functions from drm-kmod
They are superseded by PAT and mostly useless nowadays but still can be
used on Pentium III/IV era processors. Unlike drm-kmod version, this one
ignores MTRR if PAT is available that fixes confusing "Failed to add WC
MTRR for [0xXXXX-0xYYYY]: 22; performance may suffer" message often
appearing during drm-kmod initialization process.

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33561

(cherry picked from commit 98b129783c)
2022-01-22 22:34:37 +03:00
Vladimir Kondratyev
2db63c396d LinuxKPI: Import linux/ratelimit.h
Required by drm-kmod.

Obtained from:	OpenBSD
MFC after:	1 week
Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D33560

(cherry picked from commit 1456816425)
2022-01-22 22:34:37 +03:00
Vladimir Kondratyev
64a0cd9aae LinuxKPI: Add linux/capability.h header
Required by drm-kmod.

Obtained from:	DragonflyBSD
MFC after:	1 week
Reviewed by:	hselasky, manu

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

(cherry picked from commit f9c8b5880d)
2022-01-22 22:34:37 +03:00
Vladimir Kondratyev
272f8b9c28 LinuxKPI: Add readx_poll_timeout wrapper
Required by drm-kmod 5.7

MFC after:	1 week
Reviewed by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D33307

(cherry picked from commit 2e194c20c1)
2022-01-22 22:34:37 +03:00
Vladimir Kondratyev
b42bc4d602 LinuxKPI: Add static_cpu_has() implementation
static_cpu_has returns true if CPU supports requested feature.

Obtained from:	OpenBSD
MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33301

(cherry picked from commit f3ddb82d9a)
2022-01-22 22:34:37 +03:00
Vladimir Kondratyev
0576a1c277 LinuxKPI: Implement efi_enabled(EFI_BOOT)
efi_enabled(EFI_BOOT) returns true if machine was booted from EFI
Used by drm-kmod and some unported drm drivers like hyperv

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33300

(cherry picked from commit 89bb7f9bda)
2022-01-22 22:34:37 +03:00
Vladimir Kondratyev
1e467a609a LinuxKPI: Import linux/jump_label.h
Required by drm-kmod

Obtained from:	DragonflyBSD
Differential Revision:	https://reviews.freebsd.org/D33299

(cherry picked from commit 882f8d059c)
2022-01-22 22:34:37 +03:00
Vladimir Kondratyev
a692caea30 LinuxKPI: Move kfree_async() functionality in to kfree()
Obsolete it usage but keep for a while for drm-kmod 5.4 compatibility

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33298

(cherry picked from commit 0b1244bd79)
2022-01-22 22:34:37 +03:00
Vladimir Kondratyev
6fda5ef279 LinuxKPI: Add stdarg.h proxy header
To reduce amount of drm-kmod patching

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33297

(cherry picked from commit 35235d5ff6)
2022-01-22 22:34:36 +03:00
Vladimir Kondratyev
df10d8c667 LinuxKPI: Add some typical header pollution
To reduce amount of drm-kmod patching

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33297

(cherry picked from commit f1a7639a16)
2022-01-22 22:34:36 +03:00
Vladimir Kondratyev
b4f5d92c88 LinuxKPI: Implement smp_*mb barriers with atomic_thread_fence_*
for x86 and move them to asm/barrier.h

MFC after:	1 week
Reviewed by:	bz, hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33296

(cherry picked from commit 2fb5be7978)
2022-01-22 22:34:36 +03:00
Vladimir Kondratyev
1cf90ce241 LinuxKPI: Make lockdep*_pin_lock macros useable for drm-kmod
Summary:
- Add dummy struct pin_cookie definition;
- Convert lockdep_pin_lock macro to function;
- Fix 'unused variable' compile-time errors;

MFC after:	1 week
Reviewers:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33295

(cherry picked from commit 68fcdba38b)
2022-01-22 22:34:36 +03:00
Vladimir Kondratyev
d93c8a4d5a LinuxKPI: Convert schedule() to inlined function
to prevent name clashing with drm-kmod

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33294

(cherry picked from commit 7ec6cbf1d2)
2022-01-22 22:34:36 +03:00
Vladimir Kondratyev
8dc3f129c4 LinuxKPI: Add support for XA_FLAGS_ALLOC1 xarray flag
XA_FLAGS_ALLOC1 causes allocation of xarray entries starting at 1

Required by drm-kmod 5.7

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33293

(cherry picked from commit e705066cd8)
2022-01-22 22:34:36 +03:00
Vladimir Kondratyev
9e736b8b8a LinuxKPI: Implement default sysfs kobject attribute operations
Required by drm-kmod 5.7

MFC after:	1 week
Reviewed by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D33292

(cherry picked from commit 04d42cb453)
2022-01-22 22:34:36 +03:00
Vladimir Kondratyev
b30c794854 LinuxKPI: Implement kstrtoull
Required by drm-kmod 5.7

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33291

(cherry picked from commit c427456fd5)
2022-01-22 22:34:36 +03:00
Vladimir Kondratyev
bc3e9499ca LinuxKPI: Implement dev_driver_string()
Required by drm-kmod 5.7

MFC after:	1 week
Reviewed by:	bz, hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33290

(cherry picked from commit bc923d93df)
2022-01-22 22:34:36 +03:00
Vladimir Kondratyev
b3407b54d3 LinuxKPI: Implement clflush_cache_range()
Required by drm-kmod 5.7

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D33289

(cherry picked from commit db562aeff7)
2022-01-22 22:34:36 +03:00
Vladimir Kondratyev
e2cc6a467f LinuxKPI: Add clflush argument type conversion wrapper
to reduce amount of source patching in drm-kmod.

MFC after:	1 week
Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D33288

(cherry picked from commit 9a79e08ae7)
2022-01-22 22:34:35 +03:00
Vladimir Kondratyev
10cb54117e LinuxKPI: Implement interval_tree
Required by drm-kmod

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision: https://reviews.freebsd.org/D32869

(cherry picked from commit dbc920bd9a)
2022-01-22 22:34:35 +03:00
Vladimir Kondratyev
c8ddc214cf LinuxKPI: Import some linux/rbtree.h functions from OpenBSD
Required by drm-kmod

Obtained from:	OpenBSD
MFC after:	1 week

(cherry picked from commit dd52763387)
2022-01-22 22:34:35 +03:00
Warner Losh
67873a4fca nvd: For AHCI attached devices, report ahci bridge
When an NVME device is attached via a AHCI controller, we have no access
to its config space. So instead of information about the nvme drive
itself, return info about the AHCI controller as the next best
thing. Since the Intel Hardware RAID support looks at these values, this
likely is best.

Sponsored by:		Netflix
Reviewed by:		mav
Differential Revision:	https://reviews.freebsd.org/D33286

(cherry picked from commit b8194f3766)
2022-01-21 13:49:57 -05:00
Gleb Smirnoff
f7735c3952 carp: fix send error demotion recovery
The problem is that carp(4) would clear the error counter on first
successful send, and stop counting successes after that.  Fix this
logic and document it in human language.

PR:			260499
Differential revision:	https://reviews.freebsd.org/D33536

(cherry picked from commit 9a8cf950b2)
2022-01-21 10:41:46 -08:00
Andriy Gapon
89ac48cf3b adaspindown: check disk power mode before sending IDLE command
If a disk is already in STANDBY mode, then setting IDLE mode can
actually spin it up.

(cherry picked from commit 15910dc0bc)
2022-01-21 09:01:09 +02:00
Alexander Motin
fb56e14ce6 nvme: Do not rearm timeout for commands without one.
Admin queues almost always have several ASYNC_EVENT_REQUEST outstanding.
They have no timeouts, but their presence in qpair->outstanding_tr caused
useless timeout callout rearming twice a second.

While there, relax timeout callout period from 0.5s to 0.5-1s to improve
aggregation.  Command timeouts are measured in seconds, so we don't need
to be precise here.

Reviewed by:	imp
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D33781

(cherry picked from commit b3c9b6060f)
2022-01-20 21:07:31 -05:00
Warner Losh
f102ae7159 nvme_sim: Only report PCI related stats when we can
For AHCI attached devices, we report the location and identification
information of the AHCI controller that we're attached to. We also
don't reprot link speed in that case, since we can't get to the PCIe
config space registers to find that out.

Sponsored by:		Netflix
Reviewed by:		mav
Differential Revision:	https://reviews.freebsd.org/D33287

(cherry picked from commit 8f07932272)
2022-01-20 21:07:31 -05:00