]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
2 years agoloader: add knob to build with user malloc
Toomas Soome [Sat, 28 Mar 2020 21:47:44 +0000 (21:47 +0000)]
loader: add knob to build with user malloc

This option is intended to aid development, to allow building with user
malloc. The use case would be to build userboot & test with libc (or
other) malloc and use extra malloc debug features.

(cherry picked from commit c907ec9e16745e3dacd15982f71dea21a06de53c)

2 years agoloader: remove libsa/crc32.c and use version from zlib
Toomas Soome [Thu, 19 Mar 2020 21:05:11 +0000 (21:05 +0000)]
loader: remove libsa/crc32.c and use version from zlib

we have crc32(const void *, size_t) in libsa. Unfortunately zlib has
crc32(long, const unigned char *, unsigned) and we have conflict.

Since we do build libsa with zlib, we can use zlib version instead.

(cherry picked from commit 27bae6150a9fd352796b5ff775eb464a2cf6dac9)

2 years agoloader: replace zfs_alloc/zfs_free with malloc/free
Toomas Soome [Wed, 26 Feb 2020 18:12:12 +0000 (18:12 +0000)]
loader: replace zfs_alloc/zfs_free with malloc/free

Use common memory management.

(cherry picked from commit c1c4c81fd75a7d0c14011ea1cf6113ecdd80e16a)

2 years agoMove smbios.c to libsa.
Warner Losh [Thu, 20 Feb 2020 00:46:22 +0000 (00:46 +0000)]
Move smbios.c to libsa.

smbios used to be an i386 only kinda weird quirk to the x86
architecture. But UEFI picked it up, dusted it off and now it's many
other locations. Make it base technology by moving it to libsa and
fixing up the compliation. The code has issues with unaligned access
still, but that will be addressed in a followup commit.

(cherry picked from commit a64f0b83e5ee1c9f7ac5782a3d3f9f1c7b368e41)

2 years agoCreate ptov() function.
Warner Losh [Thu, 20 Feb 2020 00:46:16 +0000 (00:46 +0000)]
Create ptov() function.

Create a ptov() function. It's basically the same as the btx PTOV
macro, but works everywhere. smbios needs this to translate addresses,
but the translation differs between BIOS booting and EFI booting. Make
it a function so one smbios.o can be used everywhere. Provide
definitions for it in the two loaders affected.

(cherry picked from commit ed2a65769a5d04fcfc2acff3fa11d6b69394fd88)

2 years agofollowup on r357497: clean obsolete comment and use shift instead of multiplication
Toomas Soome [Wed, 5 Feb 2020 13:08:24 +0000 (13:08 +0000)]
followup on r357497: clean obsolete comment and use shift instead of multiplication

Based on illumos review feedback: leftover comment, but also
have consistent block size calculation and add missing else leg to if
statement.

(cherry picked from commit 380977d55797c67c052759a9789a4120bd12f792)

2 years agozfsboot: vdev_read_pad2 does allocate buffer with wrong size
Toomas Soome [Wed, 5 Feb 2020 11:02:00 +0000 (11:02 +0000)]
zfsboot: vdev_read_pad2 does allocate buffer with wrong size

vdev_read_pad2() does read VDEV_PAD_SIZE of data, and will copy size bytes
of it, hence, we need buffer of VDEV_PAD_SIZE bytes.

Issue introduced in r357497.

(cherry picked from commit 7503958e4cd57bcfc2b611594906b56c6645e5f4)

2 years agovdev_read_pad2: freeing wrong pointer
Toomas Soome [Wed, 5 Feb 2020 05:42:42 +0000 (05:42 +0000)]
vdev_read_pad2: freeing wrong pointer

Shoud free previously allocated tmp buffer instead. Issue introduced in
r357497.

(cherry picked from commit a1746b25837c2df4367eed7e8c3665e26e0dc6bb)

2 years agoloader: rewrite zfs reader zap code to use malloc
Toomas Soome [Tue, 4 Feb 2020 07:37:55 +0000 (07:37 +0000)]
loader: rewrite zfs reader zap code to use malloc

First step on removing zfs_alloc.

(cherry picked from commit 4d297e7035a4c3e367fd995767ceabaa75bec1ca)

2 years agoRemove comment. We're just going to the next node here.
Warner Losh [Thu, 28 Nov 2019 05:40:10 +0000 (05:40 +0000)]
Remove comment. We're just going to the next node here.

(cherry picked from commit 79cb1bf26f78a580a3cb639f3e45dcd8171be14d)

2 years agocstyle cleanup for i386_copy.c
Toomas Soome [Fri, 8 Nov 2019 12:19:03 +0000 (12:19 +0000)]
cstyle cleanup for i386_copy.c

No functional changes are intended.

(cherry picked from commit 1113c41fef7b1b0ff02d816908f553f4699d9bd1)

2 years agouserboot/test should use PRIx64 as one would expect from prefix 0x
Toomas Soome [Thu, 24 Oct 2019 07:49:33 +0000 (07:49 +0000)]
userboot/test should use PRIx64 as one would expect from prefix 0x

Test is printing decimal value after prefix 0x.

(cherry picked from commit 96b2f9c996c82941b58eceaafe55eb696e8a5a4d)

2 years agoRemove whole-disk vdev support from zfsboot
Patrick Kelsey [Sun, 17 Feb 2019 03:52:44 +0000 (03:52 +0000)]
Remove whole-disk vdev support from zfsboot

This is consistent with the removal of whole-disk vdev support from
libsa/zfs/zfs.c in r342151, and is part way to having the LBAs read
during probe be fully constrained by partition tables when present.

(cherry picked from commit 861729a32e1a723ecfd2c5ba009d108879aa661b)

2 years agoWait a maximum of 300 seconds for network send/recv in libsa
Rebecca Cran [Thu, 20 Dec 2018 19:27:46 +0000 (19:27 +0000)]
Wait a maximum of 300 seconds for network send/recv in libsa

The reason for this change is that currently, a send/recv
takes many hours to time out.
This is suboptimal in the bootloader because it means for example
that NFS will take hours to fail before allowing subsequent access
methods such as gzip to be tried.

Setting MAXWAIT to 300 seconds (5 minutes) still allows slow
connections of 1Mb to be used to download a 30MB kernel file.

(cherry picked from commit d5cee48f3e65662051e15c85e4fc1841d72977fe)

2 years agoNuke out buffer overflow safety marker code.
Maxim Sobolev [Fri, 23 Nov 2018 22:36:56 +0000 (22:36 +0000)]
Nuke out buffer overflow safety marker code.

It duplicates similar code in the malloc()/free() as well as having
potential of softening the handling in case error is detected down to a
mere warning as compared to hard panic in free().

(cherry picked from commit 6c81fe160cb922d35cc740e2fa8be1a9467d139f)

2 years agoloader: zfsimpl.c cstyle cleanup
Toomas Soome [Sun, 15 Dec 2019 14:09:49 +0000 (14:09 +0000)]
loader: zfsimpl.c cstyle cleanup

No functional changes intended.

(cherry picked from commit 2e6bb6553b04d80cf85c9728df6aa4dc66dc020a)

2 years agoReverted: loader: allow booting from pool with log device
Toomas Soome [Sun, 3 Nov 2019 21:36:29 +0000 (21:36 +0000)]
Reverted: loader: allow booting from pool with log device

Apparently people are using log with boot pool, so we can not just
error out there. Still we will need to investigate how to handle
log properly.

(cherry picked from commit f331eb7d346b5e6b33b7e180fc876bfd853ba6ef)
(cherry picked from commit ae3f74e7638b91bdc778fbaee9caeab917190a82)

2 years agoReverted: loader: use struct initializer in vdev_probe().
Toomas Soome [Sun, 10 Nov 2019 15:07:36 +0000 (15:07 +0000)]
Reverted: loader: use struct initializer in vdev_probe().

(cherry picked from commit e5d9d0794881cb6cef879304c35b6d00b499b444)
(cherry picked from commit c082b391b0e24ce69b33482cf77ff13bd1fefe29)

2 years agoReverted: Split out the loader efifb setup to a new function
Andrew Turner [Fri, 26 Feb 2021 11:47:34 +0000 (11:47 +0000)]
Reverted: Split out the loader efifb setup to a new function

(cherry picked from commit c8db60c0673d4bb7a3a3e2c043804e1ed1108c2f)
(cherry picked from commit 773fc43fb060149f8e59c183e5da79feaf118c8c)

2 years agoloader: tftp client should use server address from rootip
Toomas Soome [Mon, 2 Aug 2021 12:27:38 +0000 (15:27 +0300)]
loader: tftp client should use server address from rootip

servip is set from bootp bp_siaddr (if present) and rootip is
set immediately from servip in tha sane bootp code.

However, the common/dev_net.c does only set rootip (based on
url processing etc). Therefore, we should also use rootip in tftp
reader.

Fixes hung tftp based boot when bp_siaddr is not provided.

(cherry picked from commit 1b1bb6f178802a4522824e0268634a99cdbda098)

2 years agoloader: Don't reserve space for symbols twice.
Warner Losh [Mon, 12 Jul 2021 21:17:05 +0000 (15:17 -0600)]
loader: Don't reserve space for symbols twice.

The current code bumps lastaddr twice for the symbol table
location. However, the first bump is bogus and results in wasted
space. Remove it.

PR: 110995

(cherry picked from commit 297e9f364b5aa243572ee52b1faef9b3542c1c9e)

2 years agoloader: Fix dtb loading
Emmanuel Vadot [Mon, 5 Jul 2021 13:50:39 +0000 (15:50 +0200)]
loader: Fix dtb loading

When calling file_findfile with only a type it returns
the first file matching the type. But in fdt_apply_overlays we
then iterate on the next files and try loading them as dtb overlays.
Fix this by checking the type one more time.

Reported by: Mark Millard <marklmi@yahoo.com>

(cherry picked from commit b464c459eaf4e63a3abaaa1ecf51c9d6e9f7521e)

2 years agoUpdate the EFI timer to be called once a second
Andrew Turner [Wed, 12 May 2021 08:59:04 +0000 (08:59 +0000)]
Update the EFI timer to be called once a second

There is no need to call it evert 10ms when we need 1s granularity.
Update to update the time every second.

(cherry picked from commit 93f7be080f3ad0bd71190d87aa2043d714270206)

2 years agoLoader: support booting OS from memory disk (MD)
Yongbo Yao [Wed, 7 Apr 2021 18:33:22 +0000 (13:33 -0500)]
Loader: support booting OS from memory disk (MD)

Until now, the boot image can be embedded into the loader with
/sys/tools/embed_mfs.sh, and memory disk (MD) is already supported
in loader source. But due to memory disk (MD) driver isn't registered
to the loader yet, the boot image can't be boot from embedded memory
disk.

(cherry picked from commit 5984246f9626fbc3d356ee2d3b3cd159f6d0a7c2)

2 years agoReuse the amd64 loader relocation code on arm64
Andrew Turner [Sun, 17 Jan 2021 18:11:11 +0000 (18:11 +0000)]
Reuse the amd64 loader relocation code on arm64

There is no need to keep multiple copies of the relocation code. The
amd64 code works on arm64 with a few small changes to relocation types.

(cherry picked from commit f6f0b849fb2683feebf2416a793964be0bd05cc5)

2 years agoloader: Partial revert of 987eabdc2ae1
Emmanuel Vadot [Sun, 17 Jan 2021 16:41:25 +0000 (17:41 +0100)]
loader: Partial revert of 987eabdc2ae1

The arm relocation code doesn't not work and make loader not loading
dependancies.

Reported by: Dr. Rolf Jansen <freebsd-rj@obsigna.com>

(cherry picked from commit 0f2434ea000e02e6b1f7f40f489c346c64445242)

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

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

(cherry picked from commit 987eabdc2ae1c0beba77e4d3b538155e81c7a7d5)

2 years agostand/efihttp: Work around a bug in edk2 http instance reconfiguration
D Scott Phillips [Wed, 9 Sep 2020 16:35:51 +0000 (16:35 +0000)]
stand/efihttp: Work around a bug in edk2 http instance reconfiguration

A bug in the EFI HTTP driver of TianoCore EDK2 causes memory
corruption when an http instance that uses tls is reconfigured,
leading to a crash.

Work around this by forcing a new http instance for each request
instead of reconfiguring the existing one.

The upstream bug report is https://bugzilla.tianocore.org/show_bug.cgi?id=1917

(cherry picked from commit d455cd5ac36f4c1ac76f04e2c2bb4bfb00fe8bcd)

2 years agoZFS: remove duplicate "com.datto:encryption" from loader
Matt Macy [Thu, 27 Aug 2020 21:37:35 +0000 (21:37 +0000)]
ZFS: remove duplicate "com.datto:encryption" from loader

(cherry picked from commit 962619075c531f333b51161b4ec011e1e987ad5a)

2 years agoFix stand/newvers.sh with zsh in sh mode
Alex Richardson [Wed, 12 Aug 2020 15:49:10 +0000 (15:49 +0000)]
Fix stand/newvers.sh with zsh in sh mode

When building on macOS with sh==zsh, newvers.sh was producing an
unterminated string literal due to \\n being turned as a newline. Fix this
by using a here document instead.

(cherry picked from commit cad2917baf6e8d90720f5bfb2463dfa7be35f568)

2 years agoFix compilation error for install.c in loader
Stephen J. Kiernan [Fri, 31 Jul 2020 16:08:25 +0000 (16:08 +0000)]
Fix compilation error for install.c in loader

Fix typo in interp_include() invocation (missing 'p')
Remove setting tftpip, as servip is used by the tftp code in libsa. There
is no separate tftpip global variable any more.

(cherry picked from commit fafe230db0cd8d96ac5f3f74643e0c71e949d623)

2 years agoloader: geli_dev_ioctl does return huge mediasize
Toomas Soome [Tue, 7 Jul 2020 12:24:40 +0000 (12:24 +0000)]
loader: geli_dev_ioctl does return huge mediasize

The DIOCGMEDIASIZE is calculated md->md_sectorsize * md->md_provsize, and
for boot disk, the md_sectorsize is 4k. However, the md_provsize is already
in units of bytes.

(cherry picked from commit 0d1a62068123df267e20530c86d2fc7a4e1aaa2e)

2 years agoAs with r352446 align blocks in boot1.efi
Andrew Turner [Tue, 5 May 2020 09:42:26 +0000 (09:42 +0000)]
As with r352446 align blocks in boot1.efi

We need to ensure the buffers are aligned before passing them to ReadBlocks.
Assume 512 bytes is enough for now.

(cherry picked from commit 3d5e12ebce94791aa0d6df3e81e7a8ac48ee4b51)

2 years agoBuild the arm64 loader with -ffixed-x18
Andrew Turner [Fri, 24 Apr 2020 10:03:11 +0000 (10:03 +0000)]
Build the arm64 loader with -ffixed-x18

This stops the compiler from using the x18 register. Some UEFI
implementations assume this will be preserved when calling the Boot
Services.

(cherry picked from commit a2e2311a40696e39eb24ff4a4d4c0968bba42c8c)

2 years agoloader: misaligned access of dos_partition structure
Toomas Soome [Thu, 19 Mar 2020 17:27:08 +0000 (17:27 +0000)]
loader: misaligned access of dos_partition structure

armv7 crash due to misligned access of dos_partition dp_start field.

Allocate and make copy of dos_partition array to make sure the data
is aligned.

(cherry picked from commit 87d8d5ea3dd0a8ad2c0468660805017d6d45d937)

2 years agoloader: alloc_pread() should set errno if malloc fails
Toomas Soome [Sun, 23 Feb 2020 15:21:15 +0000 (15:21 +0000)]
loader: alloc_pread() should set errno if malloc fails

We may want to find out why alloc_pread() failed.

(cherry picked from commit 91e697162c272aa81f375d3294e43cea97e8c4cd)

2 years agoefi_register_handles() is missing NULL pointer check
Toomas Soome [Thu, 20 Feb 2020 09:02:59 +0000 (09:02 +0000)]
efi_register_handles() is missing NULL pointer check

Add missing check of malloc() result.

(cherry picked from commit 4a82db5fe718a6b4abaf4de7f5d82563dc2f98df)

2 years agoinsert_zfs() is missing NULL pointer check
Toomas Soome [Thu, 20 Feb 2020 09:00:20 +0000 (09:00 +0000)]
insert_zfs() is missing NULL pointer check

Add missing check of malloc() result.

(cherry picked from commit 7afa0d95e212a612b2990c975082757c44c3b50f)

2 years agoefipart_inithandles() is missing NULL pointer check
Toomas Soome [Thu, 20 Feb 2020 08:56:56 +0000 (08:56 +0000)]
efipart_inithandles() is missing NULL pointer check

Add missing check of malloc() result.

(cherry picked from commit 79cbcdcf3ececdb45f02c528d00e53e9600a4f48)

2 years agoconnect_controllers() is missing NULL pointer check
Toomas Soome [Thu, 20 Feb 2020 08:55:18 +0000 (08:55 +0000)]
connect_controllers() is missing NULL pointer check

Add missing check of malloc() result.

(cherry picked from commit ef91a071ac534ed1293f624e4e205916da8f30a4)

2 years agoefihttp_fs_seek() is missing NULL pointer check
Toomas Soome [Thu, 20 Feb 2020 08:53:04 +0000 (08:53 +0000)]
efihttp_fs_seek() is missing NULL pointer check

Add missing check of malloc() result.

(cherry picked from commit 8abc11f65c828a58263e4b4a8eac70fdf7082792)

2 years agoefinet_dev_init() is missing NULL pointer check
Toomas Soome [Thu, 20 Feb 2020 08:48:34 +0000 (08:48 +0000)]
efinet_dev_init() is missing NULL pointer check

Add missing check of malloc() result.

(cherry picked from commit 860545e20b8f09881973b828863f55141fb2250e)

2 years agoIn gptboot, don't assume a partition number is a single digit, 1-9. GPT
Ian Lepore [Sun, 22 Dec 2019 22:33:22 +0000 (22:33 +0000)]
In gptboot, don't assume a partition number is a single digit, 1-9.  GPT
partitions can have 128 partitions, so parse contiguous digits and then
validate that the number is between 1-128 inclusive.

I'm not sure 128 is a hard limit in the GPT standard, but it's the common
number in use, and it's a better upper limit than 9.

(cherry picked from commit 42e08952bb84aa86dfdcc7b80c95b58e515bdce7)

2 years agoUse symbolic names for int13 calls
Warner Losh [Mon, 16 Dec 2019 21:52:12 +0000 (21:52 +0000)]
Use symbolic names for int13 calls

For all the INT13 calls, use symbolic names instead of magic numbers. This makes
it easier to understand what the code is doing w/o a trip to google to find what
these numbers mean.

(cherry picked from commit 7f5499972e115cafc861ec438cd7237422cd9b7c)

2 years agoloader.efi: print ImageBase so we know where we are
Toomas Soome [Fri, 6 Dec 2019 09:50:29 +0000 (09:50 +0000)]
loader.efi: print ImageBase so we know where we are

Output a bit of debugging aid.

(cherry picked from commit fed13eb3e8d6091dcfae45e7652835d519306abe)

2 years agoloader.efi: Default to serial if we don't have a ConOut variable
Emmanuel Vadot [Fri, 8 Nov 2019 20:08:44 +0000 (20:08 +0000)]
loader.efi: Default to serial if we don't have a ConOut variable

In the EFI implementation in U-Boot no ConOut efi variable is created,
this cause loader to fallback to TERM_EMU implementation which is very
very very slow (and uses the ConOut device in the system table anyway).
The UEFI spec aren't clear as if this variable needs to exists or not.

(cherry picked from commit 14fb9485a4dc9c8212bfae6c2049cb4930f4b8e5)

2 years agoloader: show APFS partition type name
Toomas Soome [Mon, 4 Nov 2019 12:20:19 +0000 (12:20 +0000)]
loader: show APFS partition type name

Add small visual aid in lsdev output.

(cherry picked from commit 124003d5870a2da22648cfd8d9a71fda4f0d64a7)

2 years agoloader: zfs.c is missing malloc checks, fix it
Toomas Soome [Sun, 3 Nov 2019 14:36:16 +0000 (14:36 +0000)]
loader: zfs.c is missing malloc checks, fix it

malloc() can return NULL, we need to check the return value.

(cherry picked from commit 21da9f14f6144429874a286bfe21a16cbb0dbabd)

2 years agoloader: should check malloc in zfs_dev_open
Toomas Soome [Sun, 3 Nov 2019 13:03:47 +0000 (13:03 +0000)]
loader: should check malloc in zfs_dev_open

malloc can return NULL.

(cherry picked from commit f4ed0045735d88aa681b4933072ff35a890a86a0)

2 years agoloader: userboot/test should accept more than one disk
Toomas Soome [Sun, 3 Nov 2019 09:14:29 +0000 (09:14 +0000)]
loader: userboot/test should accept more than one disk

allow to specify multiple -d options, test -d disk1 -d disk2 ..

(cherry picked from commit bcbb1e60a1c181310a7ce36af2c202fa789d03e5)

2 years agopthread_mutexattr(3): document each pthread_mutexattr_set/get* function
Konstantin Belousov [Fri, 1 Oct 2021 01:39:39 +0000 (04:39 +0300)]
pthread_mutexattr(3): document each pthread_mutexattr_set/get* function

(cherry picked from commit be6116fdfc4d292b77b3df7d4dda029d26a73d65)

2 years agolibthr(3): explain some internals of the locks implementation
Konstantin Belousov [Fri, 1 Oct 2021 01:17:02 +0000 (04:17 +0300)]
libthr(3): explain some internals of the locks implementation

(cherry picked from commit f5b9747075a9b489226e2a911f8a1597f4b9d072)

2 years agopthread_mutexattr(3): install pthread_mutexattr_get/setpshared links
Konstantin Belousov [Fri, 1 Oct 2021 00:53:44 +0000 (03:53 +0300)]
pthread_mutexattr(3): install pthread_mutexattr_get/setpshared links

(cherry picked from commit 6bda192013fc8e6c994098fe262f2a74f424cb57)

2 years agopthread_mutexattr(3): document pthread_mutexattr_set/getpshared
Konstantin Belousov [Fri, 1 Oct 2021 00:46:16 +0000 (03:46 +0300)]
pthread_mutexattr(3): document pthread_mutexattr_set/getpshared

(cherry picked from commit 0a6e5fc29b43778bd004f7754c730e41a9ce2675)

2 years agopthread_mutexattr(3): use .Fo/.Fc to avoid too long lines
Konstantin Belousov [Fri, 1 Oct 2021 00:40:19 +0000 (03:40 +0300)]
pthread_mutexattr(3): use .Fo/.Fc to avoid too long lines

(cherry picked from commit 9f3b6cdbe87cf92d4099f3f5ff8eff3030a8076b)

2 years agofusefs: don't panic if FUSE_GETATTR fails durint VOP_GETPAGES
Konstantin Belousov [Thu, 16 Sep 2021 23:53:58 +0000 (02:53 +0300)]
fusefs: don't panic if FUSE_GETATTR fails durint VOP_GETPAGES

During VOP_GETPAGES, fusefs needs to determine the file's length, which
could require a FUSE_GETATTR operation.  If that fails, it's better to
SIGBUS than panic.

Sponsored by: Axcient
Reviewed by:  markj, kib
Differential Revision: https://reviews.freebsd.org/D31994

(cherry picked from commit 4f917847c9037d9b76de188c03e13b81224431b2)

buffer pager: allow get_blksize method to return error

Reported and reviewed by: asomers
Sponsored by: The FreeBSD Foundation
Differential revision: https://reviews.freebsd.org/D31998

(cherry picked from commit 197a4f29f39e6ae6215a6dbd28ef449d305e6d49)

2 years agoses: Guard the elm_type_names declaration by _KERNEL
Alan Somers [Mon, 30 Aug 2021 20:45:13 +0000 (14:45 -0600)]
ses: Guard the elm_type_names declaration by _KERNEL

Sponsored by: Axcient

(cherry picked from commit cc2d08d3880c2e726849ab2aa23b3d15f8aa3938)

2 years agoses: Correct spelling of "Temperature Sensor"
Alan Somers [Mon, 30 Aug 2021 19:59:32 +0000 (13:59 -0600)]
ses: Correct spelling of "Temperature Sensor"

According to SES 4 revision 2 table 71, it should be singular.

Sponsored by: Axcient

(cherry picked from commit 1fb52e4373e7f645d71059a6a403469f059044c8)

2 years agoperiodic: by default, skip 221.backup-gpart in jails
Alan Somers [Fri, 18 Jun 2021 14:33:08 +0000 (08:33 -0600)]
periodic: by default, skip 221.backup-gpart in jails

It can still be enabled as usual in /etc/periodic.conf

PR: 256253
Reported by: delphij
Submitted by: Miroslav Lachman <000.fbsd@quip.cz>

(cherry picked from commit fcf2227a557552e45646bbcf2422a98baab5c8a8)

2 years agovinvalbuf: do not panic if we were unable to flush dirty buffers
Konstantin Belousov [Sun, 30 May 2021 16:52:42 +0000 (19:52 +0300)]
vinvalbuf: do not panic if we were unable to flush dirty buffers

Return EBUSY instead and let caller to handle the issue.

For vgone()/vnode reclamation, caller first does vinvalbuf(V_SAVE),
which return EBUSY in case dirty buffers where not flushed. Then caller
calls vinvalbuf(0) due to non-zero return, which gets rid of all dirty
buffers without dependencies.

PR: 238565
Reviewed by: asomers, mckusick
Sponsored by: The FreeBSD Foundation
Differential revision: https://reviews.freebsd.org/D30555

(cherry picked from commit 27006229f7a40a18a61a0e8fd270bc583326b690)

fusefs: reenable the WriteCluster.cluster_write_err test

The underlying panic was just fixed by
revision 27006229f7a40a18a61a0e8fd270bc583326b690

PR: 238565
(cherry picked from commit 425bbe9e64f7af6bdb30a099bd90a32885de1ab8)

2 years agogmultipath: make physpath distinct from the underlying providers'
Alan Somers [Thu, 22 Apr 2021 21:09:03 +0000 (15:09 -0600)]
gmultipath: make physpath distinct from the underlying providers'

zfsd uses a device's physical path attribute to automatically replace a
missing ZFS disk when a blank disk is inserted into the same physical
slot.  Currently gmultipath passes through its underlying providers'
physical path attribute.  That may cause zfsd to replace a missing
gmultipath provider with a newly arrived, single-path disk.  That would
be bad.

This commit fixes that problem by simply appending "/mp" to the
underlying providers' physical path, in a manner similar to what geli
already does.

Sponsored by: Axcient
Differential Revision: https://reviews.freebsd.org/D29941

(cherry picked from commit 420dbe763f15b076751443edfeeb4f676deb3c44)

2 years agodaemon: add some basic tests
Alan Somers [Wed, 17 Mar 2021 16:35:00 +0000 (10:35 -0600)]
daemon: add some basic tests

Sponsored by: Axcient
Differential Revision: https://reviews.freebsd.org/D29316

(cherry picked from commit 3b57d80c7aa924ed0fad565591f5292c2ac88da5)

2 years agoICMP checksum test: Fix for big endian
Charlie Root [Tue, 12 Jan 2021 01:56:12 +0000 (18:56 -0700)]
ICMP checksum test: Fix for big endian

The in_cksum tests originally tried to simulate a BE environment by
swapping the byte order of the input.  But that's overcomplicated, and
didn't actually work on real BE hardware.  The correct testing strategy
is just to test on the native endianness, and run the tests in both BE
and LE environments.

Submitted by: Renato Riolino <renato.riolino@eldorado.org.br>
Reviewed By: asomers
Differential Revision: https://reviews.freebsd.org/D23193

(cherry picked from commit 292808246db702b9194deb8938e40fd06914aea9)

2 years agoMFC uipc_shm: Fix kern.ipc.posix_shm_list for jails
Jamie Gritton [Wed, 29 Sep 2021 17:20:36 +0000 (10:20 -0700)]
MFC uipc_shm: Fix kern.ipc.posix_shm_list for jails

Fix error return of kern.ipc.posix_shm_list, which caused it (and thus
"posixshmcontrol ls") to fail for all jails that didn't happen to own
the last shm object in the list.

(cherry picked from commit 747a47261eee59b6e9c437cd2c1b3979df5c32ac)

2 years agoBackout 356693. The libsa malloc does provide necessary alignment and
Toomas Soome [Mon, 13 Jan 2020 20:02:27 +0000 (20:02 +0000)]
Backout 356693. The libsa malloc does provide necessary alignment and
memalign by 4 will reduce alignment for some platforms. Thanks for Ian for
pointing this out.

(cherry picked from commit aaeffe5b7064536dc7f4ea75a58125ec69d2706b)

2 years agoloader: allocate properly aligned buffer for network packet
Toomas Soome [Mon, 13 Jan 2020 18:22:54 +0000 (18:22 +0000)]
loader: allocate properly aligned buffer for network packet

Use memalign(4, size) to ensure we have properly aligned buffer.

(cherry picked from commit 659bf32dfc595b6cd6aeda7f05cb57872c64d2d1)

2 years agoFix build for mips.XLP64 kernel, by re-ordering headers
Ravi Pokala [Tue, 31 Mar 2020 20:09:20 +0000 (20:09 +0000)]
Fix build for mips.XLP64 kernel, by re-ordering headers

The log for the failure contained errors like this:

| In file included from ${SRCTOP}/sys/mips/nlm/dev/net/xlpge.c:34:
| In file included from ${SRCTOP}/sys/sys/systm.h:44:
| In file included from ./machine/atomic.h:849:
| ${SRCTOP}/sys/sys/_atomic_subword.h:222:37: error: unknown type name 'u_long'; did you mean 'long'?
| atomic_testandset_acq_long(volatile u_long *p, u_int v)
|                                     ^~~~~~
|                                     long

And similar "unknown type name" errors for u_int, not recognizing bool as a type, etc.

This was caused by including <sys/param.h> too far down; move it up where it belongs.

While here, add a blank line after '__FBSDID()', in keeping with convention.

(cherry picked from commit 144af011b4ee87ed3eba4f2c9f6780f4543ba554)

2 years ago[PowerPC] Fix atomic_cmpset_masked().
Brandon Bergren [Tue, 26 May 2020 19:03:45 +0000 (19:03 +0000)]
[PowerPC] Fix atomic_cmpset_masked().

A recent kernel change caused the previously unused atomic_cmpset_masked() to
be used.

It had a typo in it.

Instead of reading the old value from an uninitialized variable, read it
from the passed-in pointer as intended.

This fixes crashes on 64 bit Book-E.

Obtained from: jhibbits

(cherry picked from commit 9941cb0657d63b4b1570dcf384196bb599bf9024)

2 years agoatomic: Add atomic_cmpset_masked to powerpc and use it
Justin Hibbits [Fri, 15 Nov 2019 04:33:07 +0000 (04:33 +0000)]
atomic: Add atomic_cmpset_masked to powerpc and use it

Summary:
This is a more optimal way of doing atomic_compset_masked() than the
fallback in sys/_atomic_subword.h.  There's also an override for
_atomic_fcmpset_masked_word(), which may or may not be necessary, and is
unused for powerpc.

(cherry picked from commit d0bdb11139424b9dcfe3b73cd5a003055382de03)

2 years agopowerpc/atomic: Fix atomic_cmpset_rel()
Justin Hibbits [Tue, 15 Oct 2019 03:37:21 +0000 (03:37 +0000)]
powerpc/atomic: Fix atomic_cmpset_rel()

Need a release barrier, not an acquire barrier, else bad things happen.

(cherry picked from commit 9551397f51a7041dd0060bae1433d0e802373e35)

2 years agopowerpc: Implement atomic_(f)cmpset_ for short and char
Justin Hibbits [Tue, 8 Oct 2019 01:36:34 +0000 (01:36 +0000)]
powerpc: Implement atomic_(f)cmpset_ for short and char

This adds two implementations for each atomic_fcmpset_ and atomic_cmpset_
short and char functions, selectable at compile time for the target
architecture.  By default, it uses a generic shift-and-mask to perform atomic
updates to sub-components of 32-bit words from <sys/_atomic_subword.h>.
However, if ISA_206_ATOMICS is defined it uses the ll/sc instructions for
halfword and bytes, introduced in PowerISA 2.06.  These instructions are
supported by all IBM processors from POWER7 on, as well as the Freescale/NXP
e6500 core.  Although the e5500 and e500mc both implement PowerISA 2.06 they
do not implement these instructions.

As part of this, clean up the atomic_(f)cmpset_acq and _rel wrappers, by
using macros to reduce code duplication.

ISA_206_ATOMICS requires clang or newer binutils (2.20 or later).

(cherry picked from commit 84046d16eba76392ece41452b6ca3bd5808a1d19)

2 years agomips: use generic sub-word atomic *cmpset
Kyle Evans [Wed, 2 Oct 2019 17:07:59 +0000 (17:07 +0000)]
mips: use generic sub-word atomic *cmpset

Most of this diff is refactoring to reduce duplication between the different
acq_ and rel_ variants.

(cherry picked from commit 281ec62c977aba21b4aa60ed0f532d6a20b669e0)

2 years agoProvide generic sub-word atomic *cmpset
Kyle Evans [Wed, 2 Oct 2019 17:06:28 +0000 (17:06 +0000)]
Provide generic sub-word atomic *cmpset

Provide *cmpset_{8,16} as wrappers around atomic_fcmpset_32. Initial users
will be mips and sparc64, and perhaps parts of powerpc.

This are not for general consumption; machine/atomic.h should include this
header as needed to provide atomic_{,f}cmpset_{8,16} and machine/atomic.h
should provide acq_ and rel_ variants.

(cherry picked from commit b6c5d1ef76cdcfe2103fd2ed8ef8f97e1c740edc)

2 years agosys/dev/cfi: include sys/types.h as well
Kyle Evans [Thu, 2 Jan 2020 22:52:31 +0000 (22:52 +0000)]
sys/dev/cfi: include sys/types.h as well

This will soon be a dependency for machine/atomic.h on mips with the
introduction of 64-bit atomics; the scope here is pretty narrow, so throw it
here in the header just before systm.h, which includes machine/atomic.h

(cherry picked from commit 85ccd84cb3ce35f830cd4c07154152daf41181ef)

2 years agosyslogd: undo regression after r326573
Eugene Grosbein [Mon, 27 Sep 2021 07:25:21 +0000 (14:25 +0700)]
syslogd: undo regression after r326573

Restore ability for our syslogd to collect pre-RFC3164 formatted
messages from remote hosts that was broken with r326573.

Note that parsing of RFC5424 format not changed.

(cherry picked from commit 3b4cc56e524ac947ba0e6571e2c455139c2839ec)

2 years ago12.3: update stable/12 to -PRERELEASE to start the release cycle
Glen Barber [Thu, 7 Oct 2021 00:07:19 +0000 (20:07 -0400)]
12.3: update stable/12 to -PRERELEASE to start the release cycle

Approved by: re (implicit)

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

2 years agomips: fcmpset: do not spin on sc failure
Kyle Evans [Wed, 2 Oct 2019 15:13:40 +0000 (15:13 +0000)]
mips: fcmpset: do not spin on sc failure

For ll/sc architectures, atomic(9) allows failure modes where *old == val
due to write failure and callers should compensate for this. Do not retry on
failure, just leave 0 in ret and fail the operation if we couldn't sc it.
This lets the caller determine if it should retry or not.

(cherry picked from commit 22c2c971a614a72875787e0fd0001906451ee245)

2 years agoatomic_cmpset return value is also an int.
Warner Losh [Fri, 14 Dec 2018 19:48:42 +0000 (19:48 +0000)]
atomic_cmpset return value is also an int.

(cherry picked from commit 3d060215a5013c72b968aa5163833fa31fc92913)

2 years agoatomic_fcmpset* return int, not the type of *.
Warner Losh [Fri, 14 Dec 2018 19:14:51 +0000 (19:14 +0000)]
atomic_fcmpset* return int, not the type of *.

fcmpset returns true/false as a int, so make the return types and
variables match the int to be consistent with other arch.

(cherry picked from commit 2fb9d3808a3a0a8939502600cde69b04550d1e7d)

2 years agoTwo minor issues:
Warner Losh [Tue, 17 Dec 2019 03:20:37 +0000 (03:20 +0000)]
Two minor issues:
(1) Don't define load/store 64 atomics for o32. They aren't atomic
there.
(2) Add comment about why we need 64 atomic define on n32 only.

(cherry picked from commit fa9b4635f0874eedc3d908f2cd21746680c8c2ed)

2 years agoemulated atomic64: disable interrupts as the lock mechanism on !SMP
Kyle Evans [Fri, 3 Jan 2020 18:29:20 +0000 (18:29 +0000)]
emulated atomic64: disable interrupts as the lock mechanism on !SMP

Reviewed by: jhibbits, bdragon
Differential Revision: https://reviews.freebsd.org/D23015

(cherry picked from commit 3a22f09cbff13aed11206af6c839c4e1a5a08bff)

2 years ago[PowerPC] [MIPS] Implement 32-bit kernel emulation of atomic64 operations
Brandon Bergren [Thu, 2 Jan 2020 23:20:37 +0000 (23:20 +0000)]
[PowerPC] [MIPS] Implement 32-bit kernel emulation of atomic64 operations

This is a lock-based emulation of 64-bit atomics for kernel use, split off
from an earlier patch by jhibbits.

This is needed to unblock future improvements that reduce the need for
locking on 64-bit platforms by using atomic updates.

The implementation allows for future integration with userland atomic64,
but as that implies going through sysarch for every use, the current
status quo of userland doing its own locking may be for the best.

Submitted by: jhibbits (original patch), kevans (mips bits)
Reviewed by: jhibbits, jeff, kevans
Differential Revision: https://reviews.freebsd.org/D22976

(cherry picked from commit 9aafc7c0523456c8b5ee8919c97f75277cf4d70b)

2 years agoFix busdma resource leak on usb device detach.
Ian Lepore [Tue, 28 Sep 2021 19:29:10 +0000 (13:29 -0600)]
Fix busdma resource leak on usb device detach.

When a usb device is detached, usb_pc_dmamap_destroy() called
bus_dmamap_destroy() while the map was still loaded. That's harmless on x86
architectures, but on all other platforms it causes bus_dmamap_destroy() to
return EBUSY and leak away any memory resources (including bounce buffers)
associated with the mapping, as well as any allocated map structure itself.

This change introduces a new is_loaded flag to the usb_page_cache struct to
track whether a map is loaded or not. If the map is loaded,
bus_dmamap_unload() is called before bus_dmamap_destroy() to avoid leaking
away resources.

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

(cherry picked from commit dc91a9715f8fda4b3633388830a28a99f73cbe59)

2 years agotests: kqueue: CLOCK_BOOTTIME is an alias of CLOCK_UPTIME
Kyle Evans [Wed, 6 Oct 2021 14:50:32 +0000 (09:50 -0500)]
tests: kqueue: CLOCK_BOOTTIME is an alias of CLOCK_UPTIME

Build-test should be done a buildenv from a newer branch. =-( We don't
have this alias in stable/12, so just provide it locally in a way that
won't break should 155f15118a77 find its way here.

Reported by: Jenkins, naddy
Fixes: f9765c9c1acb ("kqueue: don't arbitrarily restrict ...")

2 years agopf tests: Basic adaptive mode syncookie test
Kristof Provost [Sat, 25 Sep 2021 13:05:02 +0000 (15:05 +0200)]
pf tests: Basic adaptive mode syncookie test

MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D32139

(cherry picked from commit 2f20d80692ceb584842a7642562fc9f610a5b661)

2 years agopf tests: Basic syncookie test
Kristof Provost [Sat, 10 Jul 2021 11:20:44 +0000 (13:20 +0200)]
pf tests: Basic syncookie test

MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D32138

(cherry picked from commit dc0636636bb1937283d4f218732ac2357f4ec4f1)

2 years agopf.conf: document syncookies
Kristof Provost [Sat, 14 Aug 2021 08:42:03 +0000 (10:42 +0200)]
pf.conf: document syncookies

Reviewed by: bcr
Obtained from: OpenBSD
MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D32137

(cherry picked from commit 20f015f08d66d0d953e49245cb95c81c118b9ee9)

2 years agopfctl: userspace adaptive syncookies configration
Kristof Provost [Fri, 13 Aug 2021 11:42:59 +0000 (13:42 +0200)]
pfctl: userspace adaptive syncookies configration

Hook up the userspace bits to configure syncookies in adaptive mode.

MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D32136

(cherry picked from commit 5062afff9de7e67da96e3f0dcb9d8bbd5a4e1c5b)

2 years agopf: hook up adaptive mode configuration
Kristof Provost [Sat, 24 Jul 2021 12:23:59 +0000 (14:23 +0200)]
pf: hook up adaptive mode configuration

The kernel side of pf syncookie adaptive mode configuration.

MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D32135

(cherry picked from commit 955460d41e99031906841870e02063ffdf227f09)

2 years agopf: implement adaptive mode
Kristof Provost [Sat, 24 Jul 2021 11:59:34 +0000 (13:59 +0200)]
pf: implement adaptive mode

Use atomic counters to ensure that we correctly track the number of half
open states and syncookie responses in-flight.
This determines if we activate or deactivate syncookies in adaptive
mode.

MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D32134

(cherry picked from commit bf8637181a2bb81206ff8c685f1632d07b8feb13)

2 years agotcp_wrappers: get rid of duplicate fgets declarations
Kyle Evans [Thu, 30 Sep 2021 04:21:24 +0000 (23:21 -0500)]
tcp_wrappers: get rid of duplicate fgets declarations

This is declared in stdio.h, no need for this one.

(cherry picked from commit 4dbd8c72d3030b8f111fdac86ba45ff596595497)

2 years agolibc: ssp: sprinkle around some __dead2
Kyle Evans [Wed, 29 Sep 2021 21:48:20 +0000 (16:48 -0500)]
libc: ssp: sprinkle around some __dead2

This is consistent with, e.g., NetBSD's implementation, which declares
these as noreturn in ssp/ssp.h.

(cherry picked from commit 5487294d79f9ebe72a847d0855adb4df85e0d66e)

2 years agobootp: remove the USE_BFUNCS knob
Kyle Evans [Thu, 30 Sep 2021 03:01:34 +0000 (22:01 -0500)]
bootp: remove the USE_BFUNCS knob

We'd likely be better served by converting these to the equivalent mem*
calls, but just kill the knob for now. The b* macros being defined get
in the way of _FORTIFY_SOURCE.

(cherry picked from commit cfb9be506285cd65120f9686d532130a3757ce56)

2 years agokqueue: document how timers with low/past timeouts are handled
Kyle Evans [Thu, 30 Sep 2021 18:19:05 +0000 (13:19 -0500)]
kqueue: document how timers with low/past timeouts are handled

(cherry picked from commit 4b5554cebb66020f59dc869b835aebbd66e4bb8c)

2 years agokqueue: don't arbitrarily restrict long-past values for NOTE_ABSTIME
Kyle Evans [Wed, 29 Sep 2021 19:55:59 +0000 (14:55 -0500)]
kqueue: don't arbitrarily restrict long-past values for NOTE_ABSTIME

NOTE_ABSTIME values are converted to values relative to boottime in
filt_timervalidate(), and negative values are currently rejected.  We
don't reject times in the past in general, so clamp this up to 0 as
needed such that the timer fires immediately rather than imposing what
looks like an arbitrary restriction.

Another possible scenario is that the system clock had to be adjusted
by ~minutes or ~hours and we have less than that in terms of uptime,
making a reasonable short-timeout suddenly invalid. Firing it is still
a valid choice in this scenario so that applications can at least
expect a consistent behavior.

(cherry picked from commit 9c999a259f00b35f0467acd351fea9157ed7e1e4)
(cherry picked from commit 2f4dbe279f6b5eb87ec493d96f6943ffdb603ba0)

2 years agocam: Fix a typo in a comment
Gordon Bergling [Sat, 2 Oct 2021 08:48:43 +0000 (10:48 +0200)]
cam: Fix a typo in a comment

- s/perorming/performing/

(cherry picked from commit 15c5f657a0107c7c1a3c954252a9ac6bb80f2535)

2 years agovnic: Fix a typo in a comment
Gordon Bergling [Sat, 2 Oct 2021 08:47:21 +0000 (10:47 +0200)]
vnic: Fix a typo in a comment

- s/setings/settings/

(cherry picked from commit fafb1c574d43b8c3acb510d925f599fee461c039)

2 years agoevdev: Fix a typo in a commit
Gordon Bergling [Sat, 2 Oct 2021 08:43:41 +0000 (10:43 +0200)]
evdev: Fix a typo in a commit

- s/prefered/preferred/

(cherry picked from commit efd8749fe5cccb6c3d6b5f3c3515bf89ad306bcc)

2 years agonetvsc: Fix a typo in a comment
Gordon Bergling [Sat, 2 Oct 2021 08:42:18 +0000 (10:42 +0200)]
netvsc: Fix a typo in a comment

- s/prefered/preferred/

(cherry picked from commit 9ebd651b58502f0572a7832d088f53f7a2ad00a5)

2 years agowpa: Fix EAP/PEAP MSCHAPv2 authentication SIGSEGV
Cy Schubert [Tue, 5 Oct 2021 22:09:06 +0000 (15:09 -0700)]
wpa: Fix EAP/PEAP MSCHAPv2 authentication SIGSEGV

25ecdc7d52770caf1c9b44b5ec11f468f6b636f3 (MFCed by
5654815fd3604e024eefdcb34904d3a7c883e8c5) introduced a link error
causing a SIGSEGV when using EAP/PEAP MSCHAPv2 authentication. It was
subsequently addressed by c1d255d3ffdbe447de3ab875bf4e7d7accc5bfc5,
discovered by build time link errors not experienced during testing of
25ecdc7d52770caf1c9b44b5ec11f468f6b636f3. This commit MFCs a portion
of c1d255d3ffdbe447de3ab875bf4e7d7accc5bfc5 addressing only the
SIGSEGV. The rest of c1d255d3ffdbe447de3ab875bf4e7d7accc5bfc5 will
be MFCed in November 2021.

This is a direct commit to stable/12.

PR: 258527
Reported by: Marek Zarychta <zarychtam@plan-b.pwste.edu.pl>
Tested by: Marek Zarychta <zarychtam@plan-b.pwste.edu.pl>