Commit Graph

295205 Commits

Author SHA1 Message Date
riastradh 89d7388021 disk(9): New function disklabel_dev_unit.
Maps a dev_t like wd3e to an autoconf instance number like 3, with no
partition.  Same as DISKUNIT macro, but is a symbol whose pointer can
be taken.  Meant for use with struct bdevsw, cdevsw::d_devtounit.
2022-03-28 12:33:59 +00:00
riastradh fc76cc25dd driver(9): New devsw members d_cfdriver, d_devtounit.
If set, then bdev_open/cdev_open will use d_devtounit to map the
dev_t to an autoconf instance (e.g., /dev/wd0a -> wd0) and hold a
reference with device_lookup_acquire across the call to d_open.

This guarantees that the autoconf instance cannot be detached while
the devsw's d_open function is trying to open it (and also that the
autoconf instance has finished *_attach before anyone can open it).

Of course, if the underlying hardware has gone away, there will be
I/O errors, but this avoids software synchronization bugs between
open and detach for drivers that opt into it.  It's up to the driver
and bus to figure out how to deal with I/O errors from operations on
hardware that has gone away while the software hasn't finished
notifying everything that it's gone yet.

XXX kernel ABI change to struct bdevsw/cdevsw requires bump
2022-03-28 12:33:50 +00:00
riastradh c0aac3ae3a autoconf(9): New localcount-based device instance references.
device_lookup_acquire looks up an autoconf device instance, if found,
and acquires a reference the caller must release with device_release.
If attach or detach is still in progress, device_lookup_acquire waits
until it completes.  While references are held, the device's softc
will not be freed or reused until the last reference is released.

The reference is meant to be held while opening a device in the short
term, and then to be passed off to a longer-term reference that can
be broken explicitly by detach -- usually a device special vnode,
which is broken by vdevgone in the driver's *_detach function.

Sleeping while holding a reference is allowed, e.g. waiting to open a
tty.  A driver must arrange that its *_detach function will interrupt
any threads sleeping while holding references and cause them to back
out so that detach can complete promptly.

Subsequent changes to subr_devsw.c will make bdev_open and cdev_open
automatically take a reference to an autoconf instance for drivers
that opt into this, so there will be no logic changes needed in most
drivers other than to connect the autoconf cfdriver to the
bdevsw/cdevsw I/O operation tables.  The effect will be that *_detach
may run while d_open is in progress, but no new d_open can begin
until *_detach has backed out from or committed to detaching.

XXX kernel ABI change to struct device requires bump -- later change
will make struct device opaque to ABI, but we're not there yet
2022-03-28 12:33:41 +00:00
riastradh 154bf9f0b2 driver(9): Fix synchronization of devsw_attach/lookup/detach.
(`dev' means either `bdev' or `cdev' for brevity here, e.g. in
`devsw_lookup' (bdevsw_lookup, cdevsw_lookup), `dev_open' (bdev_open,
cdev_open), `maxdevsws', &c., except for `devsw_attach' and
`devsw_detach' which are taken literally.)

- Use atomic_store_release and atomic_load_consume for devsw and
  tables and their entries, which are read unlocked and thus require
  memory barriers to ensure ordering between initialization in
  devsw_attach and use in dev_lookup.

- Use pserialize(9) and localcount(9) to synchronize dev_open and
  devsw_detach.

  => Driver must ensure d_open fails and all open instances have been
     closed by the time it calls devsw_detach.

  => Bonus: dev_open is no longer globally serialized through
     device_lock.

- Use atomic_store_release and atomic_load_acquire for max_devsws,
  which is used in conditionals in the new devsw_lookup_acquire.

  => It is safe to use atomic_load_relaxed in devsw_lookup because
     the caller must guarantee the entry is stable, so any increase
     of max_devsws must have already happened.

  => devsw_lookup and devsw_lookup_acquire assume that max_devsws
     never goes down.  If you change this you must find some way to
     adapt the users, preferably without adding much overhead so that
     devsw operations are cheap.

This change introduces an auxiliary table devswref mapping device
majors to localcounts of opens in progress.  The auxiliary table only
occupies one pointer's worth of memory in a monolithic kernel, and is
allocated on the fly for dynamically loaded modules.  We could ask
the module itself to reserve storage for it, but I don't see much
value in that, and it would require some changes to the ABI and to
config(8).

- Omit needless boolean indirection.
2022-03-28 12:33:32 +00:00
riastradh e7bed28911 driver(9): devsw_detach never fails. Make it return void.
Prune a whole lotta dead branches as a result of this.  (Some logic
calling this is also wrong for other reasons; devsw_detach is final
-- you should never have any reason to decide to roll it back.  To be
cleaned up in subsequent commits...)

XXX kernel ABI change to devsw_detach signature requires bump
2022-03-28 12:33:20 +00:00
mlelstv 24dda235e4 Add helper to detach genfb console. 2022-03-28 11:21:40 +00:00
mlelstv 6a5f419e50 Check INITED state by default for all ioctls but VNDIOCSET. Avoids crashes
with disk_ioctls on default unit, which is not INITED.
Fixes PR 56700.
2022-03-28 11:16:59 +00:00
mlelstv 159a9ce89a Fix sanity check for zero sized buffer. 2022-03-28 11:09:24 +00:00
mlelstv 80ddacac2c Media size is in bytes (off_t), not sectors. 2022-03-28 10:38:00 +00:00
hannken a2e2545403 Make mmap() with "len == 0" an error if not MAP_ANON. We should return
an error for MAP_ANON too but unfortunately our /libexec/ld.elf_so
sometimes creates an empty anon mapping for the bss of a shared library.

At least FreeBSD and Solaris return this error too and according to POSIX
"If len is zero, mmap() shall fail and no mapping shall be established".

Fixes PR pkg/56338 Installing qt5-qtdeclarative leaves a dangling reference

The dangling reference here originates from vn_mmap() taking a vnode
reference for this empty mapping that will never be released.
2022-03-27 20:18:05 +00:00
rillig 3b385e4c9c make: fix spacing, and a typo in a test 2022-03-27 18:39:01 +00:00
christos 71457ba882 dedup the eofs link/symlink methods 2022-03-27 17:10:55 +00:00
christos 4805589d3d Describe the hardlink restrictions. 2022-03-27 16:36:11 +00:00
christos d202eb1bcf Implement restrictions for adding hard links to files 2022-03-27 16:28:35 +00:00
christos 884c22fa28 add a kauth vnode check for adding links 2022-03-27 16:26:26 +00:00
christos 6a3c4a6f4f add a kauth vnode check for creating links 2022-03-27 16:24:57 +00:00
christos 09ac88fa0a Expose groupmember as kauth_cred_groupmember and use it. 2022-03-27 16:23:08 +00:00
christos e5f9cbf53a Widen kauth_action_t so we can add KAUTH_VNODE_ADD_LINK; welcome to 9.99.96. 2022-03-27 16:16:39 +00:00
gutteridge b9dd3a3166 popen.3: revert s/null-/nul-/ change, this is subject to debate 2022-03-27 00:32:15 +00:00
riastradh 3270682c2f mips/cavium: Simplify membars around interrupt establishment.
Previously I used xc_barrier to ensure the initialization of the
struct octeon_intrhand was witnessed on all CPUs before publishing
it, in order to avoid needing any barrier on the usage side to be
issued by the interrupt handler.

But there's no need to avoid atomic_load_consume at time of
interrupt: on MIPS it's the same as atomic_load_relaxed anyway, so
there's no additional memory barrier cost here.
2022-03-26 19:38:00 +00:00
riastradh 7649865387 igpio(4): Use device_xname, not struct device members. 2022-03-26 19:35:56 +00:00
riastradh 81647a79c0 igpio(4): Nix trailing whitespace.
(setq show-trailing-whitespace t), M-x delete-trailing-whitespace
2022-03-26 19:35:35 +00:00
andvar eb1e4b9f84 s/logial/logical/ 2022-03-26 17:15:18 +00:00
christos de5bb3186c grow (for llvm) 2022-03-26 17:11:20 +00:00
christos c7671db9d6 grow 2022-03-26 17:09:53 +00:00
martin 37b043d21a Add sparc* to the list of architectures that need an explicit address
with PT_CONTINUE in this test.
2022-03-26 16:22:50 +00:00
uwe f560b4a780 __makenew: use calloc to get zeroed memory for window contents.
PR lib/56767.
2022-03-26 16:03:02 +00:00
sjg bac1316949 Mention 'make -r' with .POSIX 2022-03-26 15:39:58 +00:00
rillig 2ee28bb4b2 make: avoid trailing whitespace in debug log for variables
Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
2022-03-26 14:34:07 +00:00
rillig 7d32eabdae make: add space after colon in debug logging for variables
These log messages are intended for human interpretation, so don't make
them unnecessarily hard to read.
2022-03-26 14:17:46 +00:00
rillig 302298bffd make: prefer 'long long' over 'long' on 32-bit C99 platforms
When sorting the words of an expression numerically using the modifier
':On' (added on 2021-07-30), use 64-bit numbers even on 32-bit
platforms.  A typical use case is comparing file sizes.

When tracing the execution of jobs, fix an integer overflow after 2038.
32-bit platforms that use a pre-C99 compiler still have this problem.

No change to the test suite since most tests simply skip any potential
differences between 32-bit platforms and 64-bit platforms (see
varmod-order-numeric.mk) or already account for both variants (see
varmod-localtime.mk).
2022-03-26 14:02:40 +00:00
martin bb9cc87442 When reading CIS tuples from a BAR, do not blindly copy 2k of data (or
to the end of the BAR space), but instead follow the tuples and stop
reading once we reach the end of the list.
I have a card

	bwi0 at cardbus0 function 0: Broadcom Wireless
	bwi0: BBP id 0x4306, BBP rev 0x2, BBP pkg 0

where the BAR claims 8k space but seems to only implement 6k (but that
is impossible to report as the spec only allows 2^n sizes) and the CIS
starts at a bit over 4k (so the old code tried reading beyound the 6k
limit and caused pci bus errors).

An alternative would be to avoid reporting bus errors during this access,
but since we are only interested in the CIS chain anyway (and that ends
way earlier) this is a simpler solution.
2022-03-26 13:41:16 +00:00
rillig cab1987a93 make: clean up comments 2022-03-26 13:32:31 +00:00
rillig ae5c0d120f make: fix crash on .undef of an environment variable (since 2020-10-06) 2022-03-26 12:44:57 +00:00
isaki 51bda90154 Add terminology comments. 2022-03-26 06:49:27 +00:00
isaki c72d86dae9 Improve comments. 2022-03-26 06:43:36 +00:00
isaki 62d953fecb Remove a dead code in audio_track_record(). 2022-03-26 06:41:12 +00:00
isaki 21ff22b0c0 Clarify the assertion in audio_rmixer_process().
By previous commit (r1.116), the assersion no longer fires even without
this modification.  But the condition was a bit inaccurate.
There is no need to check the data length must be aligned to blocks here
(though it also should be aligned now).  What we should check here is that
the tail must be aligned.
2022-03-26 06:36:06 +00:00
isaki c7836332a0 Fix conditions that audio_read() calls audio_track_record().
audio_track_record() must be called when usrbuf has at least one free block.

I hope that this will fix the panic reported in PR kern/56644.
When an user process specifies the hardware format as its recording format
(i.e., there is no track conversions), if the user process read(2) a small
amount of data and the rmixer_process then runs, depending on the conditions,
the panic may happen.  I have never reproduced it because it's difficult to
do intentionally.

Thanks Y.Sugahara and riastradh@ for help and comments.
2022-03-26 06:27:32 +00:00
tnn 62c016145f dwhdmi: properly initialize connector atomic helper funcs (PR port-evbarm/56766) 2022-03-25 23:16:04 +00:00
rillig db6c2e72bd tests/make: test .undef for exported global variables 2022-03-25 23:03:47 +00:00
rillig a3654be969 tests/make: suppress -DCLEANUP output in test deptgt-phony 2022-03-25 22:38:39 +00:00
jmcneill 8fa3427196 evbarm: Enable USERCONF option 2022-03-25 21:24:20 +00:00
jmcneill 89ca88e02d fdt: add support for USERCONF option 2022-03-25 21:23:51 +00:00
jmcneill 97eb8c2aa1 efiboot: Add support for 'userconf' command.
Add support for the 'userconf' command at the boot prompt and in boot.cfg,
and for FDT based booting, pass the commands as a string list property
named "netbsd,userconf" on the /chosen node.
2022-03-25 21:23:00 +00:00
sjg 3db3ca139b Include posix.mk when .POSIX: first encountered
Since .POSIX: is required to be the first non-comment line
in a Makefile, including ${MAKE_POSIX_MK} or whatever _PATH_POSIX_MK is
set to at this point is equivalent to an extension of sys.mk

This is a minimal change that can allow a better approximation of
POSIX compliance

Reviewed by: rillig
2022-03-25 21:16:04 +00:00
rillig 8d3736f16d localtime.c: fix theoretical syntax error
If NetBSD were built with -DHAVE_MALLOC_ERRNO=0, the previous code would
have resulted in a compile error due to the extra '}'.  Fix this by
copying the upstream code.

No binary change.
2022-03-25 19:34:04 +00:00
rillig c87b5bf8e3 localtime.c: reduce unnecessary diff to upstream
No binary change.
2022-03-25 19:25:23 +00:00
rillig 3110a48882 localtime.c: take indentation style from upstream
This reduces the diff to upstream.

No binary change.
2022-03-25 19:00:15 +00:00
rillig fdcb92a153 localtime.c: add back storage class 'register'
This reduces the differences to the upstream code.

No binary change.
2022-03-25 18:35:50 +00:00