Commit graph

273305 commits

Author SHA1 Message Date
Warner Losh 1dd126163b byteswap.h: Add a glibc/linux compatible byteswap.h
For endian.h to work instead of sys/endian.h, some software needs
byteswap.h available. It must define {__,}byteswap_{16,32,64}.
Included sys/_endian.h to get an appropriate __byteswap16, etc
and defines the new macros in terms of them. Enhance _endian.h
to allow it to be included from here too.

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

(cherry picked from commit 1761b09bf4)
2023-01-24 16:26:28 -07:00
Warner Losh 1004da283d linux: For better compatibility, provide compatible endian.h
Add endian.h. This includes sys/endian.h and then adds extra defines
that glibc defines with double underscores for our
_{BIG,BYTE,LITTLE,PDP}_ENDIAN macros. We also define __FLOAT_WORD_ORDER
to be the same as _BYTE_ENDIAN since FreeBSD doesn't currently define
this, and the default with glibc is exactly this for our platforms.
Move common parts of endian.h and sys/endian.h into sys/_endian.h
to limit namespace pollution from endian.h

All this gives us good compatibility with Linux. There may be one or two
upstreams that haven't integrated the patches I tried to send up.

There are some minor differences:
	o The extra glibc macros are not defined. These are all
	  controlled with either __ at the start, or only defined
	  when glibc is being built. We also don't define macros
	  that are used internally in glibc that would pollute
	  the namespace.
	o For complete compatibility, this change must also be
	  paired with providing a glibc-compatible byteswap.h.

Sponsored by:		Netflix
Reviewed by:		mhorne, markj, jhb
Differential Revision:	https://reviews.freebsd.org/D31962

(cherry picked from commit 30e0d2a510)
2023-01-24 16:26:28 -07:00
Warner Losh 6f3e6234f8 endian.h: Use the __bswap* versions
Make it possible to have all these macros work without bswap* being
defined. bswap* is part of the application namespace and applications
are free to redefine those functions.

Reviewed by:		emaste,jhb,markj
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D31964

(cherry picked from commit 44fb3c695f)
2023-01-24 16:26:27 -07:00
Brooks Davis c91bf3cb34 epoch: replace hand coded assertion
The assertion is equivalent to kstack_contains() so use that rather
than spelling it out.

Suggested by:	jhb
Reviewed by:	jhb
MFC after:	1 week
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D38107

(cherry picked from commit fa1d803c0f)
2023-01-24 22:46:31 +00:00
Brooks Davis a25797c114 riscv: Fix thread0.td_kstack_pages init
Commit 0ef3ca7ae3 initialized
thread0.td_kstack_pages to KSTACK_PAGES.  Due to the lack of an
include of opt_kstack_pages.h it used the fallback value of 4 from
machine/param.h.  This meant that increasing KSTACK_PAGES in the kernel
config resulted in a panic in _epoch_enter_preempt as the following
assertion was false during network stack setup:

	MPASS((vm_offset_t)et >= td->td_kstack &&
	    (vm_offset_t)et + sizeof(struct epoch_tracker) <=
	    td->td_kstack + td->td_kstack_pages * PAGE_SIZE);

Switch to initializing with kstack_pages following other architectures.

Reviewed by:	imp, markj
Sponsored by:   DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D38049

(cherry picked from commit b75062f234)
2023-01-24 22:46:07 +00:00
Brooks Davis e3e6f08472 arm64: Fix thread0.td_kstack_pages init
Commit 86a994d653 initialized
thread0.td_kstack_pages to KSTACK_PAGES.  Due to the lack of an
include of opt_kstack_pages.h it used the fallback value of 4 from
machine/param.h.  This meant that increasing KSTACK_PAGES in the kernel
config resulted in a panic in _epoch_enter_preempt as the following
assertion was false during network stack setup:

        MPASS((vm_offset_t)et >= td->td_kstack &&
	    (vm_offset_t)et + sizeof(struct epoch_tracker) <=
	    td->td_kstack + td->td_kstack_pages * PAGE_SIZE);

Switch to initializing with kstack_pages following other architectures.

Reviewed by:	imp, markj
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D38048

(cherry picked from commit e1b610f76c)
2023-01-24 22:45:35 +00:00
Warner Losh 3ececb0f35 stand: dev can't be NULL in default_prasedev
We pass in the address of a variable to store this value always in the
only place that calls this function, so there is no need to test for NULL.

Sponsored by:		Netflix
Notied by:		tsoome in D38041

(cherry picked from commit 4883f347f6)
2023-01-24 14:49:47 -07:00
Warner Losh f9ab67f200 kboot: Use standard set_currdev
Use the standard set_currdev instead of the (now very old) copy of
setting currdev and loaddev directly. We do this only when we don't go
find the ZFS pool to boot from.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38012

(cherry picked from commit eb1795782c)
2023-01-24 14:49:47 -07:00
Warner Losh 0b569fe671 kboot: Add hostdisk override
When hostdisk_override is set, all the /dev devices are hidden, and only
the files in that directory are used. This will allow filesystem testing
on FreeBSD without root, for example. Adjust the parse routine to not
require devices start with /dev (plus fix a leak for an error
condition). Add a match routine to allow the device name to be something
like "/home/user/testing/zfsfoo:" instead of strictly in /dev. Note:
since we need to look at all the devices in the system to probe for ZFS
zpools, you can't generally use a full path to get a 'virtual disk' at
this time.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38011

(cherry picked from commit b7ecfa195f)
2023-01-24 14:49:47 -07:00
Warner Losh eaed7ff9d0 kboot: Fetch hostfs_root and bootdev from the environment
Fetch bootdev from the environment variable (so it should be set on the
command line). Default to 'zfs:' which will in the future look for the
first zpool that we can boot from. Prior versions of kboot would set
this from the second argument on the command line.

Fetch hostfs_root from the environment (defaulting to '/'). Prior
versions of kboot would set this from the first arg on the command line.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38010

(cherry picked from commit 4f3be6b8d9)
2023-01-24 14:49:47 -07:00
Warner Losh d11df0599d kboot: Add ZFS support build glue
Now that all the pieces are in place, allow kboot to be built with ZFS
support.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38009

(cherry picked from commit 42e37d8caf)
2023-01-24 14:49:47 -07:00
Warner Losh f168e96dfb kboot: Add support for ZFS volumes
Add the zfs device and filesystem to config and write the hook we need
to probe zfs since there's not a generic mechanism in place to do that
when ZFS is configured.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38008

(cherry picked from commit f20ecce33a)
2023-01-24 14:49:47 -07:00
Warner Losh 85ab3bb989 kboot: Add ZFS support to hostdisk
Add helper function to walk through the disk drives we've found to look
for zpools. main.c will still need to call this because the loader
hasn't implemented a good way to 'taste' drives for zpools and/or GELI
partitions (mostly because there's no generic list of candidate
devices).

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38007

(cherry picked from commit cc82c650a7)
2023-01-24 14:49:46 -07:00
Warner Losh 85ce7697ca kboot: Rework hostdisk.c to allow easier ZFS support.
Keep a list of disks and partitions that we have. Keep track of the
sizes of the media and sector and use that to implement DIOCGMEDIASIZE
and DIOCGSECTORSIZE. Proivde a way to lookup disks by name.

Sponsored by:		Netflix
Reviewed by:		kevans (prior version)
Differential Revision:	https://reviews.freebsd.org/D38013

(cherry picked from commit 1a13008e98)
2023-01-24 14:49:46 -07:00
Warner Losh 379f5668e2 stand/zfs: Fix memory leaking on error cases
Now that we return an allocated zfs_devdesc, we have to free it. These
frees were missing from the error cases. In addition, simplify the code
a bit for the out of memory case.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38006

(cherry picked from commit 5385c7e13b)
2023-01-24 14:49:46 -07:00
Warner Losh 0cd6d49acf stand/uboot: Explain why we test for NULL here
Most parsedev routines assume that idev is non-null and can always be
set. Since we break from this pattern in uboot, explain why in a
comment. devparse was invented to put a lot of common code in one place
and to simplify the archsw.arch_getdev code and any dv_parsedev code
called. However, uboot couldn't use devparse at the time because its
device naming scheme slightly different parsing. So, we still use
uboot_parsedev directly from uboot_getdev where dev could be NULL. Add a
comment to this effect.

The match functionality added for ofw likely could be used to clean up
the multiple kludges that are here for uboot's device naming differences
with the normal boot loader. This work will wait for the future.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38042

(cherry picked from commit 5740057b43)
2023-01-24 14:49:46 -07:00
Warner Losh 2f7b00be10 stand/ofw: dev can't be NULL here
dev can't be NULL here. ofw_common_parsedev is always called via
devparse (indirectly through dv_parsedev() calls there which call it
with the args unchanged). In the past, ofw_getdev could call us with
NULL pointer for the parse-only case, but that's now all handled inside
of devparse for simplicity.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38041

(cherry picked from commit d38d8a4c4e)
2023-01-24 14:49:46 -07:00
Warner Losh 10b9e348e4 stand: Separate base and cli parts of nvstore
zfs lives in libsa. However, it depends on nvstore (and other things)
that are in common. Fix part of this layering violation by splitting
nvstore into a libsa piece (which is the base implementation) and
keeping a much smaller common piece (to implement the nvstore
command). This just leaves zfs' knowledge of device names that's
specific to common and its calling platform specific init code to
resolve. Add a nvstore.h file for these two parts to communicate private
things and move the public nvstore api from bootstrap.h to stand.h.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D38043

(cherry picked from commit d1ea501714)
2023-01-24 14:49:46 -07:00
Warner Losh 7956ceec92 stand: create common set_currdev
Pull together the nearly identical copies of set_currdev in i386,
userboot and efi. Other boot loaders have variances that might be fine
to use the common routine, or not. Since they are harder to test for me,
and ofw and uboot do handle these setting differently, leave them be for
now.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38005

(cherry picked from commit ad70f2e22e)
2023-01-24 14:49:46 -07:00
Warner Losh 6c918e0bfa stand: Move dev_cleanup into libsa
Since dev_cleanup() walks through all the devsw devices with dv_cleanup
rotuines, move it into libsa rather than having it in
'common'. Logically, it operates only on things that are in libsa, and
would never be different for different loaders: either people would call
it as is, or they'd do the loop themselves with 'special' things inline
between calls to cleanup (not that I think that will ever be needed
though).

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38004

(cherry picked from commit bf020787d5)
2023-01-24 14:49:46 -07:00
Warner Losh ab377e0e51 stand: Create common gen_setcurrdev and replace code
Replace 4 identical copies of *_setcurrdev with gen_setcurrdev to avoid
having to create a 5th copy. uboot_setcurrdev is actually different and
needs to remain separate (even though it's quite similar).

Sponsored by:		Netflix
Reviewed by:		fuz@fuz.su, kevans
Differential Revision:	https://reviews.freebsd.org/D38003

(cherry picked from commit 1c1783d66b)
2023-01-24 14:49:45 -07:00
Warner Losh 6ebdd83cae stand/efi: Better variable name
sanity_check_currdev returns true if it found a kernel or a sane loader
config file. A better name for this would be 'bootable' rather than 'rv'
which connotes in other places an errno value or similar.

Sponsored by:		Netflix

(cherry picked from commit 23ed2a38c2)
2023-01-24 14:49:45 -07:00
Warner Losh 903ffbe57d stand/zfs: Add a third argument to zfs_probe_dev: part_too
Pass in 'true' if you'd like to search this device's partitions or
'false' if you should just search the device. EFI and (in the future)
kboot have discrete partitions that aren't accessed via the full disk
device. Weird things happen if you try to search in these cases.

Sponsored by:		Netflix

(cherry picked from commit 71bbe6fb70)
2023-01-24 14:49:45 -07:00
Warner Losh e474c38577 kboot: use 128MB for the heap area, ZFS needs a lot of memory
ZFS uses a lot of memory. The old minimal allocations won't work when
ZFS support is added. Most environments this will be used (or will
liekly be used) have >> 256MB, 128MB should be safe everywhere and allow
examination of a fair number of ZFS pools to boot from.

Sponsored by:		Netflix

(cherry picked from commit 4dd3e76881)
2023-01-24 14:49:45 -07:00
Warner Losh dd0f00db08 kboot: Sort kexec_load alphabetically
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37968

(cherry picked from commit a0e4d18091)
2023-01-24 14:49:45 -07:00
Warner Losh 3141164b2a stand: Add macros for file types from stat
Add the familiar macros for file types for stat's st_mode
member. Prepend HOST_ to the start of these. Make sure all the values
match the linux nolibc and uapi headers. These values are the same as
native values since they appear to be required by POSIX. Define anyway
to allow the reader of the code to know that they are in the 'host (eg
Linux)' namespace rather than the 'loader' namespace.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37967

(cherry picked from commit 2f5f17b80c)
2023-01-24 14:49:45 -07:00
Warner Losh 85d8155e95 kboot: Disks should be at least 16MB
Linux pre-boot environments will often have a number of psuedo disks
that are small, all smaller than a few MB. 16MB is a good cutoff since
it's big enough to filter these devices, yet small enough to allow a
super-minimal partition through (the smallest I've been able to make
that's useful lately is around 20MB).

Sponsored by:		Netflix

(cherry picked from commit 0386255bee)
2023-01-24 14:49:45 -07:00
Warner Losh 2b42c3818a kboot: hostdisk.c update copyright notice
I've rewritten a substantial portion of this file, so add Netflix
copyright.

Sponsored by:		Netflix

(cherry picked from commit 538b73578b)
2023-01-24 14:49:45 -07:00
Warner Losh 5e4f201c7d stand: Allow stand.h to be included in C++ programs
Allow stand.h to be included in C++ programs. This is little more than
using our stylized __BEGIN_DECL / __END_DECL around the entire
file. There's no run-time support for C++, so the C++ that can be used
is quite limited. It is enough for libunwind, though.

Sponsored by:		Netflix
Reviewed by:		jrtc27, kevans
Differential Revision:	https://reviews.freebsd.org/D37946

(cherry picked from commit 5cf20707ba)
2023-01-24 14:49:44 -07:00
Warner Losh 28dc27649b stand: Add inttype.h
libunwind files need inttype.h. It's safe so add it to the safe list.

Sponsored by:		Netflix
Reviewed by:		jrtc27, kevans
Differential Revision:	https://reviews.freebsd.org/D37947

(cherry picked from commit 97e1430606)
2023-01-24 14:49:44 -07:00
Warner Losh 887eddca59 stand: Make ioctl declaration consistent
It typically had two args with an optional third from the userland
declaration in sys/ioccom.h. However, the funciton definition used a
non-optional char * argument. This mismatch is UB behavior (but worked
due to the calling convetions of all our machines).

Instead, add a declaration for ioctl to stand.h, make the third arg
'void *' which is a better match to the ... declaration before. This
prevents the convert int * -> char * errors as well. Make the ioctl
user-space declaration truly user-space specific (omit it in the
stand-alone build).

No functional change intended.

Sponsored by:		Netflix
Reviewed by:		emaste
Differential Revision:	https://reviews.freebsd.org/D37680

(cherry picked from commit 2e1e68cbae)
2023-01-24 14:49:44 -07:00
Warner Losh e68bfa6252 kboot: Use (void) instead of () for functiosn with no args
`int foo();` means 'a function that takes any number of arguments.`
not `a function that takes no arguemnts`, that's spelled `int foo(void);`
Adopt the latter.

Sponsored by:		Netflix

(cherry picked from commit e830a6cbbe)
2023-01-24 14:49:44 -07:00
Warner Losh b5f753c82a kboot: Allow loading fdt from different sources
Linux has /sys/firmware/fdt and /proc/device-tree to publish the dtb for
the system. The former has it all in one file, while the latter breaks
it out. Prefer the former since it's the more modern interface, but
retain both since I don't have a PS3 to test to see if its kernel is new
enough for /sys/firmware or not.

In addition, do the proper fixup.

Sponsored by:		Netflix

(cherry picked from commit 111610316e)
2023-01-24 14:49:44 -07:00
Warner Losh 5cf7162251 kboot: Need to find the ACPI tables
We need to pass the ACPI tables to the laucnhed kernel (at least for x86
and aarch64). Find it using the Linux standard way.

Sponsored by:		Netflix

(cherry picked from commit 1066a70e14)
2023-01-24 14:49:44 -07:00
Warner Losh 4bebad28e6 stand/kboot: Parse the command line args
Do the standard command line parsing... With a small twist to deal with
the quirks of booting via linuxboot to the initrd from the command line
in shell.efi and other observed oddities.

Sponsored by:		Netflix

(cherry picked from commit e1ff7945e1)
2023-01-24 14:49:44 -07:00
Warner Losh 9c621f09dd stand/efi: remove unused local varaibles
Remove some unused local variables. No functional change.

Sponsored by:		Netflix

(cherry picked from commit 667419d553)
2023-01-24 14:49:44 -07:00
Warner Losh e0dcc84789 stand/kboot: Remove unneeded include.
endian.h isn't needed for this file, so remove it.

Sponsored by:		Netflix

(cherry picked from commit 482380c6f8)
2023-01-24 14:49:43 -07:00
Warner Losh c6faa73882 stand/kboot: Initialize all the devices
main() of the boot loader is expected to call devinit() early. We do
this at the same time we do it in the EFI loader (except we don't have a
buffer cache here, we don't need to initialize time and we don't have
special efi partition handles to enumerate). This is just after we probe
for the console.

Sponsored by:		Netflix

(cherry picked from commit 299c64e316)
2023-01-24 14:49:43 -07:00
Warner Losh 093049763b kboot: copy EFI's bootinfo.c and adjust
Copy EFI's bootinfo.c and make minor adjustments for kboot's needs. Do
not connect this to the build just yet until other pieces are in place.

Sponsored by:		Netflix

(cherry picked from commit 288626083b)
2023-01-24 14:49:43 -07:00
Warner Losh 693894521c kboot: Mark the EFI specific parts of bootinfo.c
bootinfo.c is about to be shared with kboot since they create
substantially similar environments / metadata tagging / etc. Tag this
with #ifdef EFI for the moment until the proper abstracting out can
happen.

Sponsored by:		Netflix

(cherry picked from commit b11aebff4d)
2023-01-24 14:49:43 -07:00
Warner Losh 8eed237164 stand/zlib: Document the upstream issue behind NO_DEPRECATED_NON_PROTOTYPE
The zlib project has issue https://github.com/madler/zlib/issues/633 to
document its continued use of old K&R-style function definitions.

Suggested by:		delphij@
Sponsored by:		Netflix

(cherry picked from commit 6b574b3ba9)
2023-01-24 14:49:43 -07:00
Warner Losh d0288b18fb stand: update prototypes for md_load and md_load64
These are declared as extern in a number of files (some with the wrong
return type). Centralize this in modinfo.h and remove a few extra stray
declarations as well that are no longer used. No functional change.

Note: I've not tried to cope with the bi_load() functions which are the
same logical thing. These will be handled separately.

Sponsored by:		Netflix

(cherry picked from commit 335615c4ca)
2023-01-24 14:49:43 -07:00
Warner Losh 0d805f0f6f kboot: Add md_addr to metadata
Save the address of where the metadata is loaded.

Sponsored by:		Netflix

(cherry picked from commit 9f7269677c)
2023-01-24 14:49:43 -07:00
Warner Losh 931e05ffc2 kboot: Use #define for DT_DIR
Sponsored by:		Netflix

(cherry picked from commit 0ea00e71a2)
2023-01-24 14:49:43 -07:00
Warner Losh 31f473ee87 kboot: powerpc64 has no newfstat system call
Powerpc doesn't have a newfstat system call. It does have a fstat call,
which we define properly if SYS_newfstat isn't defined.

Sponsored by:		Netflix

(cherry picked from commit 8483b3add8)
2023-01-24 14:49:42 -07:00
Warner Losh abda8106e2 kboot: Add aarch64 termios
Aarch64 has the generic termios interface, so use termios_gen.h

Sponsored by:		Netflix

(cherry picked from commit 58091659cf)
2023-01-24 14:49:42 -07:00
Warner Losh 3f10d138f3 kboot: Add missing license to termios
I neglected to include the proper license markings on these
files. Remedy that now.

Sponsored by:		Netflix

(cherry picked from commit 1fc8e9b833)
2023-01-24 14:49:42 -07:00
Warner Losh 76cd49c8fe stand: aarch64 has different nlinks than amd64
Some typedefs are system dependent, so move them into stat_arch.h where
they are used.  On amd64, nlinks is a int64_t, while on aarch64 it's an
int (or int32_t).

Sponsored by:		Netflix

(cherry picked from commit 929c6216b1)
2023-01-24 14:49:42 -07:00
Warner Losh 743ee03d72 kboot: powerpc ldscript catchup
Catch up with the latest ldscript for powerpc. Make it match others in
the tree.

Sponsored by:		Netflix

(cherry picked from commit e3b74ec119)
2023-01-24 14:49:42 -07:00
Warner Losh 583dde3da0 stand/efi: Break stlye rules a little for easier sharing
Break the style rules a little to allow easier sharing between efi and
kboot. This will allow the ifdefs to be fewer in number.

Sponsored by:		Netflix

(cherry picked from commit aed1e5d332)
2023-01-24 14:49:42 -07:00