Commit Graph

133925 Commits

Author SHA1 Message Date
Konstantin Belousov
a720b31c2a Allow consumer to customize physical pager.
Add support for user-supplied callbacks into phys pager operations,
providing custom getpages(), haspage(), and populate() methods
implementations.  Pager stores user data ptr/val in the object to
provide context.

Add phys_pager_allocate() helper that takes user ops table as one of
the arguments.

Current code for these methods is moved to the 'default' ops table,
assigned automatically when vm_pager_alloc() is used.

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D24652
2020-09-09 00:00:43 +00:00
Brandon Bergren
6957645145 [PowerPC64] Fix xive order calculation in qemu TCG
When emulating a single thread system for testing reasons, mp_maxid can
be 0. This trips up our math for calculating the order.

Account for this to fix xive attachment when emulating a single-thread
core on qemu powernv (a configuration that doesn't exist in the real world.)

Sponsored by:	Tag1 Consulting, Inc.
2020-09-08 23:48:49 +00:00
Konstantin Belousov
67a659d282 Add kern_mmap_racct_check(), a helper to verify limits in vm_mmap*().
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D24652
2020-09-08 23:48:19 +00:00
Konstantin Belousov
fbf2a77876 Convert allocations of the phys pager to vm_pager_allocate().
Future changes would require additional initialization of OBJT_PHYS
objects, and vm_object_allocate() is not suitable for it.

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D24652
2020-09-08 23:38:49 +00:00
Konstantin Belousov
89d2fb14d5 Add interruptible variant of vm_wait(9), vm_wait_intr(9).
Also add msleep flags argument to vm_wait_doms(9).

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D24652
2020-09-08 23:28:09 +00:00
Brandon Bergren
95090cd024 [PowerPC64] Hide dssall instruction from llvm assembler
When doing a build for a modern CPUTYPE, llvm will throw errors if obsolete
instructions are used, even if they will never run due to runtime checks.

Hiding the dssall instruction from the assembler fixes kernel build when
overriding CPUTYPE, without having any effect on the generated binary.

This has been in my local tree for over a year and is well tested across
a variety of machines.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-08 22:59:43 +00:00
Brandon Bergren
d20ae9cca2 [PowerPC] Add root_pic assertion.
When enabling an interrupt, assert that we do in fact have a root PIC.

This would have saved me some debugging effort.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-08 22:42:41 +00:00
John Baldwin
895c98cc29 Don't return errors from the cryptodev_process() method.
The cryptodev_process() method should either return 0 if it has
completed a request, or ERESTART to defer the request until later.  If
a request encounters an error, the error should be reported via
crp_etype before completing the request via crypto_done().

Fix a few more drivers noticed by asomers@ similar to the fix in
r365389.  This is an old bug, but went unnoticed since crypto requests
did not start failing as a normal part of operation until digest
verification was introduced which can fail requests with EBADMSG.

PR:		247986
Reported by:	asomers
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D26361
2020-09-08 22:41:35 +00:00
Eugene Grosbein
cea05ed9a9 geom_part: extend kern.geom.part.check_integrity to work on GPT
There are multiple USB/SATA bridges on the market that unconditionally
cut some LBAs off connected media. This could be a problem
for pre-partitioned drives so GEOM complains and does not create
devices in /dev for slices/partitions preventing access to existing data.

We have kern.geom.part.check_integrity that allows us to correct
partitioning if changed from default 1 to 0 but it works for MBR only.
If backup copy of GPT is unavailable due to decreases number of LBAs,
kernel still does not give access to partitions and prints to dmesg:

GEOM: md0: corrupt or invalid GPT detected.
GEOM: md0: GPT rejected -- may not be recoverable.

This change makes it work for GPT too, so it created partitions in /dev
and prints to dmesg this instead:

GEOM: md0: the secondary GPT table is corrupt or invalid.
GEOM: md0: using the primary only -- recovery suggested.

Then "gpart recover" re-created backup copy of GPT
and allows further manipulations with partitions.

This change is no-op for default configuration having
kern.geom.part.check_integrity=1

Reported by:	Alex Korchmar
MFC after:	3 days.
2020-09-08 22:23:53 +00:00
Alexander V. Chernikov
4a8201c13a Fix panic with net.fibs tunable set in loader.conf.
Fix by removing forgotten CTLFLAG_RWTUN flag from the sysctl,
 loader variable will be read later in vnet_rtables_init().

Reported by:	mav
2020-09-08 21:39:34 +00:00
Matt Macy
692aa83d53 ZFS: remove some extra defines
When merging a number of defines that are needed in the standalone
build made it in to the module makefile.

Reported by:	markj@
2020-09-08 17:47:30 +00:00
Mateusz Guzik
54052edaa0 fd: fix fhold on an uninitialized var in fdcopy_remapped
Reported by:	gcc9
2020-09-08 16:07:47 +00:00
Mateusz Guzik
da62ed4f1a cache: drop write-only tvp_seqc vars 2020-09-08 16:06:46 +00:00
Mateusz Guzik
2bcfa5ba6f vfs: drop a write-only var in vfs_periodic_msync_inactive 2020-09-08 16:06:26 +00:00
Mitchell Horne
66245bc536 arm64: check for CRC32 support via HWCAP
Doing it this way eliminates the assumption about homogeneous support
for the feature, since HWCAP values are only set if support is present
on all CPUs.

Reviewed by:	tuexen, markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D26032
2020-09-08 15:39:19 +00:00
Mitchell Horne
752eb6a995 arm64: export new HWCAP features
Expose some of the new HWCAP features added in r65304. This includes the
addition of elf_hwcap2 into the sysvec, and a separate function to parse
for those features.

This only exposes features which require no further configuration, e.g.
indicating the presence of certain instructions. Larger features (SVE)
will not be advertised until we actually support them. The exact list of
features/extensions this patch exposes is:
  - ARMv8.0-DGH
  - ARMv8.0-SB
  - ARMv8.2-BF16
  - ARMv8.2-DCCVADP
  - ARMv8.2-I8MM
  - ARMv8.4-LRCPC
  - ARMv8.5-CondM
  - ARMv8.5-FRINT
  - ARMv8.5-RNG
  - PSTATE.SSBS

While here, annotate elf_hwcap and elf_hwcap2 as __read_frequently, and
move the declarations to the machine/md_var.h header.

Submitted by:	mikael@ (D22314 portion)
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D26031
Differential Revision:	https://reviews.freebsd.org/D22314
2020-09-08 15:36:38 +00:00
Mitchell Horne
d81d009c6c arm64: fix incorrect HWCAP definitions
FreeBSD exports CPU features as bits in the AT_HWCAP and AT_HWCAP2
vectors via elf_aux_info(3). This interface is similar to getauxval(3)
on Linux, and for simplicity to consumers we try to maintain an
identical set of feature flags on arm64.

The first batch of AT_HWCAP flags were added in r350166, corresponding
to definitions that already existed in Linux. Unfortunately, one flag
was missed, and a portion of the values are shifted one bit to the right
as a result.

Add the missing definition for HWCAP_ASIMDHP, and adjust the affected
values to match their Linux counterparts.

Although this is an ABI-breaking change, there is no plan to provide
compat code for old binaries. An audit of our ports tree and other
software via Debian code search indicates that there are not yet any
consumers of this interface for FreeBSD/arm64.

Bump __FreeBSD_version to be on the safe side, in case compat code needs
to be added in the future.

Reviewed by:	emaste, manu
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D26329
2020-09-08 15:08:20 +00:00
Kristof Provost
a969635b83 net: mitigate vnet / epair cleanup races
There's a race where dying vnets move their interfaces back to their original
vnet, and if_epair cleanup (where deleting one interface also deletes the other
end of the epair). This is commonly triggered by the pf tests, but also by
cleanup of vnet jails.

As we've not yet been able to fix the root cause of the issue work around the
panic by not dereferencing a NULL softc in epair_qflush() and by not
re-attaching DYING interfaces.

This isn't a full fix, but makes a very common panic far less likely.

PR:		244703, 238870
Reviewed by:	lutz_donnerhacke.de
MFC after:	4 days
Differential Revision:	https://reviews.freebsd.org/D26324
2020-09-08 14:54:10 +00:00
Mitchell Horne
bc42dacb0e RISC-V: enable MK_FORMAT_EXTENSIONS
This option was marked as broken because our riscv64-xtoolchain-gcc
package lacked support. Since we are moving away from xtoolchain gcc in
favor of freebsd-gcc9, there should be no issue in enabling this option
by default.

Notably, this enables -Wformat errors.

Reviewed by:	kp, jhb
Differential Revision:	https://reviews.freebsd.org/D26320
2020-09-08 13:24:44 +00:00
Mitchell Horne
7c7b8f577e RISC-V: fix some mismatched format specifiers
RISC-V is currently built with -Wno-format, which is how these went
undetected. Address them now before re-enabling those warnings.

Differential Revision:	https://reviews.freebsd.org/D26319
2020-09-08 13:21:13 +00:00
Andrew Turner
88e43c7ca4 Move gpio and hwpmc to the correct place in files.arm64
Sponsored by:	Innovate UK
2020-09-08 11:46:33 +00:00
Andrew Turner
1fc1a22868 Add a GPIO driver for the Arm pl061 controller
A PL061 is a simple 8 pin GPIO controller. This GPIO device is used to
signal an internal request for shutdown on some virtual machines including
Arm-based Amazon EC2 instances.

Submitted by:	Ali Saidi <alisaidi_amazon.com> (previouss version)
Reviewed by:	Ali Saidi, manu
Differential Revision:	https://reviews.freebsd.org/D24065
2020-09-08 11:35:35 +00:00
Andriy Gapon
15f4848ab7 mmc_da: universally use uint8_t for the partition index
Also, assert in sdda_init_switch_part() that the index is within the
defined range.

MFC after:	1 week
2020-09-08 06:19:23 +00:00
Andriy Gapon
fd38fa398a mmc_da: fix a typo and a too long line
MFC after:	1 week
2020-09-08 06:18:34 +00:00
Andriy Gapon
4dfdaf4d92 mmc_da: make sure that part_index is not used uninitialized in sddastart
This is a fix to r334065.

Without this change I once got stuck I/O with endless partition switching:

(sdda0:aw_mmc_sim2:0:0:0): sddastart
(sdda0:aw_mmc_sim2:0:0:0): Partition  0 -> -525703168
(sdda0:aw_mmc_sim2:0:0:0): xpt_action: func 0x91d XPT_MMC_IO
(sdda0:aw_mmc_sim2:0:0:0): xpt_done: func= 0x91d XPT_MMC_IO status 0x1
(sdda0:aw_mmc_sim2:0:0:0): sddadone
(sdda0:aw_mmc_sim2:0:0:0): Card status: 00000000
(sdda0:aw_mmc_sim2:0:0:0): Current state: 4
(sdda0:aw_mmc_sim2:0:0:0): Compteting partition switch to 0

Note that -525703168 (an int) is 0xe0aa6800 in binary representation.
The partition indexes are actually stored as uint8_t, so that value
was converted / truncated to zero.

MFC after:	1 week
2020-09-08 05:46:10 +00:00
Li-Wen Hsu
3202fefa01 Add support to BELKIN B2B128 USB3 Ethernet Adapter to axge(4)
Github PR:	https://github.com/freebsd/freebsd/pull/439
Submitted by:	https://github.com/jdpc86
MFC after:	2 weeks
2020-09-08 04:44:37 +00:00
Brandon Bergren
328b5f2570 [PowerPC] Implement VDSO timebase access on powerpc*
Implement the remaining pieces needed to allow userland timestamp reading.

Rewritten based on an intial essay into the problem by Justin Hibbits.
(Copyright changed to my own on his request.)

Tested on ppc64 (POWER9 Talos II), powerpcspe (e500v2 RB800), and
powerpc (g4 PowerBook).

Reviewed by:	jhibbits (in irc)
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D26347
2020-09-08 03:00:31 +00:00
Brandon Bergren
a5c869c1f6 [PowerPC] Work around -O miscompile on powerpc 32 bit.
Work around llvm 11 miscompile in 32 bit powerpc that appears to cause ifuncs
to branch to the wrong address by forcing -O2. This worked in previous
versions because -O was mapped to -O2 previously (but is now -O1.)

While here, remove the old temporary workaround from r224882 that does the
opposite thing for powerpc non-DEBUG kernels, bringing it in line with other
platforms that compile at -O2.

This fixes kernel boot on powerpc and powerpcspe after the llvm11 transition.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-08 01:27:03 +00:00
Mark Johnston
aec9e7d8b0 vm_object_split(): Handle orig_object type changes.
orig_object->type can change from OBJT_DEFAULT to OBJT_SWAP while
vm_object_split() is sleeping.  In this case some pages in new_object
may be left unbusied, but vm_object_split() attempts to unbusy all of
them.

Track the beginning of the busied range.  Add an assertion to verify
that pages are not re-added to the source object while sleeping.

Reported by:	Olympios Petrakis <olympios.petrakis@netapp.com>
Reviewed by:	alc, kib
Tested by:	pho
MFC after:	1 week
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D26223
2020-09-07 23:28:33 +00:00
Konstantin Belousov
7de1bc13e2 imgact_elf.c: unify check for phdr fitting into the first page.
Similar to the userspace rtld check.

Reviewed by:	dim, emaste (previous versions)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D26339
2020-09-07 21:37:16 +00:00
Brandon Bergren
3d4217bc0f [PowerPC] Initialize ELFv1 as a secondary sysvec to ELFv2.
In order to enable VDSO timekeeping, it is necessary that there be exactly
one primary FreeBSD sysvec for each of the host and (optionally) compat32.

So, switch ELFv1 to being a secondary sysvec of ELFv2, so it does not get
double-allocated in the shared page.

Since secondary sysvecs use the same sigcode allocation as the primary,
define both to use the main sigcode64, and adjust the sv_sigcode_base on
ELFv2 after initialization to point to the correct offset.

This has the desirable side effect of avoiding having a separate copy of
the signal trampoline in the shared page. Our sigcode64 was already written
to take advantage of trampoline sharing, it was just not being allocated
that way until now.

Submitted by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
2020-09-07 20:25:54 +00:00
Brandon Bergren
9464e1ef97 Fix vdso compat32 timekeeping on !=x86.
Since x86 is the only 32-bit arch that has a 32-bit time_t, adjust the
private bintime32 struct in vdso to only use a 32 bit sec on amd64.

This matches the existing behavior in the compat code.

Noticed while implementing vdso timekeeping on powerpc.

This should also theoretically fix vdso timekeeping for arm binaries on
aarch64.

See tools attached to https://reviews.freebsd.org/D26347 for testing.

Reviewed by:	kib (in irc)
Sponsored by:	Tag1 Consulting, Inc.
2020-09-07 20:05:18 +00:00
Bjoern A. Zeeb
c6167b4bf5 WiFi: fix ieee80211_media_change() callers
In r178354 with the introduction of multi-bss ("vap") support factoring
out started and with r193340 ieee80211_media_change() no longer returned
ENETRESET but only 0 or error.
As ieee80211(9) tells the ieee80211_media_change() function should not
be called directly but is registered with ieee80211_vap_attach() instead.

Some drivers have not been fully converted.  After fixing the return
checking some of these functions were simply wrappers between
ieee80211_vap_attach() and ieee80211_media_change(), so remove the extra
function, where possible as well.

PR:		248955
Submitted by:	Tong Zhang (ztong0001 gmail.com) (original)
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2020-09-07 15:35:40 +00:00
Alexander V. Chernikov
05aca418f4 Consistently use the same gateway when adding/deleting interface routes.
Use the same link-level gateway when adding or deleting interface routes.
This helps nexthop checking in the upcoming multipath changes.

Differential Revision:	https://reviews.freebsd.org/D26317
2020-09-07 10:13:54 +00:00
Andriy Gapon
1668d773a4 musb/allwinner: add support for configuring phy as well as device mode
At least on Orange Pi PC Plus even the host mode does not work without
enabling the phy and setting it to the host mode.

The driver will now parse dr_mode property and will try to configure
itself and the phy accordingly.
OTG mode is not supported yet, so it is treated as the device / peripheral
mode.

The phy is enabled -- powered on -- only for the host mode.

The device mode requires support from a phy driver, e.g., aw_usbphy on
Allwinner platform.
aw_usbphy does not support the device mode, so it cannnot work yet.

MFC after:	6 weeks
2020-09-07 06:53:29 +00:00
Andriy Gapon
f206695209 musb/allwinner: add H3 support
MFC after:	6 weeks
2020-09-07 06:49:07 +00:00
Andriy Gapon
d7abf6e73c musb/allwinner: apply register filter in awusbdrd_bs_r_2() as well
Otherwise, I get this panic:
panic: awusbdrd_reg: Invalid register 0x342

It looks that musb code both writes and reads at least MUSB2_REG_TXDBDIS.

MFC after:	5 weeks
X-MFC after:	r365399
2020-09-07 06:48:08 +00:00
Andriy Gapon
029e367dd1 fixup r365398: add a missed file with all the new Allwinner musb_otg code
Obtained from:	andrew
MFC after:	5 weeks
X-MFC with:	r365398
2020-09-07 06:44:24 +00:00
Andriy Gapon
d9a65ba85b Allwinner USB DRD support (musb_otg)
Allwinner USB DRD is based on the Mentor USB OTG controller, with a
different register layout and a few missing registers.

The code is by Andrew Turner (andrew).

Reviewed by:	hselasky, manu
Obtained from:	andrew
MFC after:	5 weeks
Differential Revision: https://reviews.freebsd.org/D5881
2020-09-07 06:39:00 +00:00
Andriy Gapon
6305020526 twsi: some variants clear interrupt flag by writing 0, others by writing 1
Make that distinction more explicit and regular in the code.
The difference in behavior is documented in the respective datasheets.

Previously, the code handled the distinction by writing the control
register multiple times where at least one write was zero and another
was one.

This can be considered a follow-up to r363021.

Reviewed by:	manu
MFC after:	4 weeks
Differential Revision: https://reviews.freebsd.org/D26308
2020-09-07 06:32:03 +00:00
Andriy Gapon
e21a4ccfd1 twsi: use tsleep instead of pause for better responsiveness
wakeup() does not have any effect on pause(), so if a transfer was
not finished by the time of the first check, then the thread
would sleep full 30 ms.

To do: protect the transfer and interrupt code with the mutex,
switch from tsleep from msleep

Reviewed by:	manu
MFC after:	3 weeks
Differential Revision: https://reviews.freebsd.org/D26309
2020-09-07 06:29:41 +00:00
Andriy Gapon
c3a7328be8 aw_clk_nm: fix incorrect use of abs()
abs() takes a (signed) int as input.
Instead, it was used with unsigned 64-bit integers.

So, add and use a new helper function to calculate a difference between
two uint64_t-s.

Reviewed by:	manu
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D26307
2020-09-07 06:27:18 +00:00
Alan Somers
dbc973ca7a padlock(4): fix instapanics with geli authentication
cryptodev_process implementations are supposed to return 0

PR:		247986
Submitted by:	jhb
MFC after:	1 week
2020-09-06 19:25:31 +00:00
Ed Maste
4fa9815a3d rtsock.c: remove extraneous space
Submitted by:	Neel Chauhan <neel AT neelc DOT org>
Differential Revision:	https://reviews.freebsd.org/D26249
2020-09-05 16:13:36 +00:00
Rick Macklem
22f085c43b Fix a potential memory leak in the NFS over TLS handling code.
For the TLS case where there is a "user@domain" name specified in the
X.509 v3 certificate presented by the client in the otherName component
of subjectAltName, a gid list is allocated via mem_alloc().
This needs to be free'd. Otherwise xp_gidp == NULL and free() handles that.
(The size argument to mem_free() is not used by FreeBSD, so it can be 0.)

This leak would not have occurred for any other case than NFS over TLS
with the "user@domain" in the client's certificate.
2020-09-05 00:50:52 +00:00
Chuck Silvers
a0a36d4886 vfs: avoid exposing partially constructed vnodes
If multiple threads race calling vfs_hash_insert() while creating vnodes
with the same identity, all of the vnodes which lose the race must be
destroyed before any other thread can see them. Previously this was
accomplished by the vput() in vfs_hash_insert() resulting in the vnode's
VOP_INACTIVE() method calling vgone() before the vnode lock was unlocked,
but at some point changes to the the vnode refcount/inactive logic have caused
that to no longer work, leading to crashes, so instead vfs_hash_insert()
must call vgone() itself before calling vput() on vnodes which lose the race.

Reviewed by:	mjg, kib
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D26291
2020-09-05 00:26:03 +00:00
Bjoern A. Zeeb
67d224ef43 bbr: remove unused static function
bbr_log_type_hrdwtso() is a file local static unused function.
Remove it to avoid warnings on kernel compiles.

Reviewed by:	gallatin
Differential Revision:	https://reviews.freebsd.org/D26331
2020-09-05 00:20:32 +00:00
Bjoern A. Zeeb
d29a3de296 uipc_ktls: remove unused static function
m_segments() was added with r363464 but never used. Remove it to
avoid warnings when compiling kernels.

Reported by:	rmacklem (also says jhb)
Reviewed by:	gallatin, jhb
Differential Revision:	https://reviews.freebsd.org/D26330
2020-09-05 00:19:40 +00:00
Matt Macy
eac7052fde ZFS: MFV 2.0-rc1-gfd20a8
- fixes jail delegation
- fixes raw kstat unsupported complaints
- exposes dbgmsg, dbuf, and checksum benchmark stats
- restore rename -u support
2020-09-04 22:25:14 +00:00
Brooks Davis
46b974a9db Round TF_SIZE up to the stack alignment (16-bytes).
The kernel adjusts the stack by TF_SIZE and the RISC-V ABI requires
that it remain 16-byte aligned.

Reported by:	CHERI, jrtc27
Reviewed by:	mhorne
Obtained from:	CheriBSD
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D26328
2020-09-04 21:55:22 +00:00