Commit Graph

300996 Commits

Author SHA1 Message Date
riastradh 40ce89a264 rumpkern: Provide fs_filtops weak alias.
We should introduce a link set for sys_kfilters, but this works
around the problem for now -- librump's dependency on librumpvfs
symbols.
2023-04-22 13:53:29 +00:00
riastradh 3595579765 file(9): New fo_posix_fadvise operation.
XXX kernel revbump -- changes struct fileops API and ABI
2023-04-22 13:53:02 +00:00
riastradh b0e1b1fb8f file(9): New fo_fpathconf operation.
XXX kernel revbump -- struct fileops API and ABI change
2023-04-22 13:52:54 +00:00
riastradh 3747f4429b file(9): New fo_advlock operation.
This moves the vnode-specific logic from sys_descrip.c into
vfs_vnode.c, like we did for fo_seek.

XXX kernel revbump -- struct fileops API and ABI change
2023-04-22 13:52:46 +00:00
riastradh e016f733bf sys/file.h: Sort forward declarations.
No functional change intended.
2023-04-22 13:52:37 +00:00
riastradh 178e3f10b7 dk(4): Convert tests to assertions in various devsw operations.
.d_cancel, .d_strategy, .d_read, .d_write, .d_ioctl, and .d_discard
are only ever used between successful .d_open return and entry to
.d_close.  .d_open doesn't return until sc is nonnull and sc_state is
RUNNING, and dkwedge_detach waits for the last .d_close before
setting sc_state to DEAD.  So there is no possibility for sc to be
null or for sc_state to be anything other than RUNNING or DYING.

There is a small functional change here but only in the event of a
race: in the short window between when dkwedge_detach is entered, and
when .d_close runs, any I/O operations (read, write, ioctl, &c.) may
be issued that would have failed with ENXIO before.

This shouldn't matter for anything: disk I/O operations are supposed
to complete reasonably promptly, and these operations _could_ have
begun milliseconds prior, before dkwedge_detach was entered, so it's
not a significant distinction.

Notes:

- .d_open must still contend with trying to open a nonexistent wedge,
  of course.

- .d_close must also contend with closing a nonexistent wedge, in
  case there were two calls to open in quick succession and the first
  failed while the second hadn't yet determined it would fail.

- .d_size and .d_dump are used from ddb without any open/close.
2023-04-22 13:11:50 +00:00
riastradh 940cc9cc40 dk(4): Fix racy access to sc->sc_dk.dk_openmask in dkwedge_delall1.
Need sc->sc_parent->dk_rawlock for this, as used in dkopen/dkclose.
2023-04-22 12:33:46 +00:00
riastradh 569b1a9933 disk(9): Fix missing unlock in error branch in previous change.
Reported-by: syzbot+870665adaf8911c0d94d@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=a4ae17cf66b5bb999182ae77fd3c7ad9ad18c891
2023-04-22 11:58:01 +00:00
riastradh c64d668143 readdir(2), lseek(2): Fix races in access to struct file::f_offset.
For non-directory vnodes:
- reading f_offset requires a shared or exclusive vnode lock
- writing f_offset requires an exclusive vnode lock

For directory vnodes, access (read or write) requires either:
- a shared vnode lock AND f_lock, or
- an exclusive vnode lock.

This way, two files for the same underlying directory vnode can still
do VOP_READDIR in parallel, but if two readdir(2) or lseek(2) calls
run in parallel on the same file, the load and store of f_offset is
atomic (otherwise, e.g., on 32-bit systems it might be torn and lead
to corrupt offsets).

There is still a potential problem: the _whole transaction_ of
readdir(2) may not be atomic.  For example, if thread A and thread B
read n bytes of directory content, thread A might get bytes [0,n) and
thread B might get bytes [n,2n) but f_offset might end up at n
instead of 2n once both operations complete.  (However, f_offset
wouldn't be some corrupt garbled number like n & 0xffffffff00000000.)
Fixing this would require either:
(a) using an exclusive vnode lock in vn_readdir,
(b) introducing a new lock that serializes vn_readdir on the same
    file (but ont necessarily the same vnode), or
(c) proving it is safe to hold f_lock across VOP_READDIR, VOP_SEEK,
    and VOP_GETATTR.
2023-04-22 11:22:36 +00:00
skrll 1144d080df KASSERT(kpreempt_disabled()) before accessing curcpu() 2023-04-22 10:22:43 +00:00
tsutsui d6e282afba Remove ancient /*ARGSUSED*/ comments. 2023-04-22 10:09:12 +00:00
skrll 1674da94a1 G/C pte_index 2023-04-22 10:03:53 +00:00
tsutsui f9df6ee016 Remove ancient /*ARGSUSED*/ comments. 2023-04-22 10:00:24 +00:00
skrll 7fc70db482 Move fdt_update_stdout_path from evbarm code to MI code 2023-04-22 09:53:45 +00:00
rillig 8e1084f184 lint: fix typos in comments 2023-04-22 09:39:14 +00:00
tsutsui 521fe5f3f1 Remove ancient /* ARGSUSED */ lint comments. 2023-04-21 23:01:59 +00:00
tsutsui 6d7bfad47a Remove ancient /* ARGSUSED */ lint comments. 2023-04-21 22:44:27 +00:00
tsutsui 97076c53d9 Avoid an extern declaration in .c file. Just declare it as static.
Suggested on tech-userlevel@.
2023-04-21 22:43:11 +00:00
gutteridge 04d453bc9d Add new test t_open_pr_57260
New test case that reflects the fix in PR kern/57260. The majority of
work for this case itself was by riastradh@, who'd supplied the basis
for it in the ticket, and provided further guidance.
2023-04-21 21:50:04 +00:00
abs 384f6a9e2e Fix incorrect test for FUSE_USE_VERSION 34
(Thanks to Mark Davies for report)
2023-04-21 19:29:31 +00:00
riastradh 58e3e0ea57 dk(4): Narrow the scope of the device numbering lookup on detach.
Just need it for vdevgone, order relative to other things in detach
doesn't matter.

No functional change intended.
2023-04-21 18:54:09 +00:00
riastradh a3597aeef1 dk(4): dkdump: Simplify. No functional change intended. 2023-04-21 18:45:13 +00:00
riastradh 9c2d6869ce dk(4): Omit needless locking in dksize, dkdump.
All the members these use are stable after initialization, except for
the wedge size, which dkwedge_size safely reads a snapshot of without
locking in the caller.
2023-04-21 18:44:58 +00:00
riastradh a5eec8cb2f dk(4): Take a read-lock on dkwedges_lock if we're only reading.
- dkwedge_find_by_name
- dkwedge_find_by_parent
- dkwedge_print_wnames
2023-04-21 18:44:18 +00:00
riastradh 5f51c927dc dk(4): Set .d_cfdriver and .d_devtounit to plug open/detach race.
This way, opening dkN or rdkN will wait if attach or detach is still
in progress, and vdevgone will wake up such pending opens and make
them fail.  So it is no longer possible for a wedge to be detached
after dkopen has already started using it.

For now, we use a custom .d_devtounit function that looks up the
autoconf unit number via the dkwedges array, which conceivably may
use an independent unit numbering system -- nothing guarantees they
match up.  (In practice they will mostly match up, but concurrent
wedge creation could lead to different numbering.)  Eventually this
should be changed so the two numbering systems match, which would let
us delete the new dkunit function and just use dev_minor_unit like
many other drivers can.
2023-04-21 18:31:00 +00:00
riastradh 932706d0fa dk(4): Use disk_begindetach and rely on vdevgone to close instances.
The first step is to decide whether we can detach (if forced, yes; if
not forced, only if not already open), and prevent new opens if so.
There's no need to start closing open instances at this point --
we're just making a decision to detach, and preventing new opens by
transitioning state that dkopen will respect[*].

The second step is to force all open instances to close.  This is
done by vdevgone.  By the time vdevgone returns, there can be no open
instances, so if there _were_ any, closing them via vdevgone will
have passed through dklastclose.

After that point, there can be no opens and no I/O operations, so
dk_openmask must already be zero and the bufq must be empty.

Thus, there's no need to have an explicit call to dklastclose (via
dkwedge_cleanup_parent) before or after making the decision to
detach.

[*] Currently access to this state is racy: nothing serializes
    dkwedge_detach's state transition with dkopen's test.  TBD in a
    separate commit shortly.
2023-04-21 18:30:52 +00:00
riastradh 385414544c dk(4): Fix callout detach race.
1. Set a flag sc_iostop under the lock sc_iolock so dkwedge_detach
   and dkstart don't race over it.

2. Decline to schedule the callout if sc_iostop is set.  The callout
   is already only ever scheduled while the lock is held.

3. Use callout_halt to wait for any concurrent callout to complete.
   At this point, it can't reschedule itself.

Without this change, the callout could be concurrently rescheduling
itself as we issue callout_stop, leading to use-after-free later.
2023-04-21 18:30:32 +00:00
riastradh 30a457d3c8 dk(4): Add null d_cancel routine to devsw.
This way, dkclose is guaranteed that dkopen, dkread, dkwrite,
dkioctl, &c., have all returned before it runs.  For block opens,
setting d_cancel also guarantees that any buffered writes are flushed
with vinvalbuf before dkclose is called.
2023-04-21 18:30:21 +00:00
riastradh 22cd13ae33 disk(9): Fix use-after-free race with concurrent disk_set_info.
This can happen with dk(4), which allows wedges to have their size
increased without destroying and recreating the device instance.

Drivers which allow concurrent disk_set_info and disk_ioctl must
serialize disk_set_info with dk_openlock.
2023-04-21 18:30:04 +00:00
riastradh c882a32047 dk(4): Require dk_openlock in dk_set_geometry.
Not strictly necessary but this makes reasoning easier and documents
with an assertion how disk_set_info is serialized.
2023-04-21 18:29:43 +00:00
riastradh a1b9c8917b dk(4): Assert dkwedges[unit] is the sc we're about to free. 2023-04-21 18:29:33 +00:00
riastradh 5f20b99ff2 dk(4): Assert parent vp is nonnull before we stash it away.
Let's enable early attribution if this goes wrong.

If it's not the parent's first open, also assert the parent vp is
already nonnull.
2023-04-21 18:29:26 +00:00
riastradh 95a8f72e29 dk(4): Don't touch dkwedges or ndkwedges outside dkwedges_lock. 2023-04-21 18:29:18 +00:00
riastradh 693156e9b4 dk(4): Move CFDRIVER_DECL and CFATTACH_DECL3_NEW earlier in file.
Follows the pattern of most drivers, and will be necessary for
referencing dk_cd in dk_bdevsw and dk_cdevsw soon, to prevent
open/detach races.

No functional change intended.
2023-04-21 18:26:35 +00:00
riastradh bbf9e378e1 dk(4): Prevent races in access to struct dkwedge_softc::sc_size.
Rules:

1. Only ever increases, never decreases.

   (Decreases require removing and readding the wedge.)

2. Increases are serialized by dk_openlock.

3. Reads can happen unlocked in any context where the softc is valid.

Access is gathered into dkwedge_size* subroutines -- don't touch
sc_size outside these.  For now, we use rwlock(9) to keep the
reasoning simple.  This should be done with atomics on 64-bit
platforms and a seqlock on 32-bit platforms to avoid contention.
However, we can do that in a later change.
2023-04-21 18:25:49 +00:00
riastradh 2232f80f28 dk(4): <sys/rwlock.h> for rwlock(9). 2023-04-21 18:25:30 +00:00
riastradh 797500ada3 dk(4): KNF: Sort includes.
No functional change intended.
2023-04-21 18:25:22 +00:00
riastradh 783e976b26 dk(4): ENXIO, not ENODEV, means no such device.
ENXIO is `device not configured', meaning there is no such device.

ENODEV is `operation not supported by device', meaning the device is
there but refuses the operation, like writing to a read-only medium.

Exception: For undefined ioctl commands, it's not ENODEV _or_ ENXIO,
but rather ENOTTY, because why make any of this obvious when you
could make it obscure Unix lore?
2023-04-21 18:25:09 +00:00
riastradh 7f62a7fc94 dk(4): Fix typo in comment: dkstrategy, not dkstragegy.
No functional change intended.
2023-04-21 18:24:56 +00:00
riastradh 600b5399ed dk(4): Omit needless void * cast.
No functional change intended.
2023-04-21 18:24:47 +00:00
riastradh 30efe94ac2 dk(4): KNF: Whitespace.
No functional change intended.
2023-04-21 18:24:39 +00:00
riastradh 9fa4440b53 dk(4): KNF: return (v) -> return v.
No functional change intended.
2023-04-21 18:24:31 +00:00
riastradh b9b7baff4e dk(4): Avoid holding dkwedges_lock while allocating array.
This is not great -- we shouldn't be choosing the unit number here
anyway; we should just let autoconf do it for us -- but it's better
than potentially blocking any dk_openlock or dk_rawlock (which are
sometimes held when waiting for dkwedges_lock) for memory allocation.
2023-04-21 18:24:19 +00:00
riastradh b134e0f792 dk(4): Restore assertions in dklastclose.
We only enter dklastclose if the wedge is open (sc->sc_dk.dk_openmask
!= 0), which can happen only if dkfirstopen has succeeded, in which
case we hold a dk_rawopens reference to the parent that prevents
anyone else from closing it.  Hence sc->sc_parent->dk_rawopens > 0.

On open, sc->sc_parent->dk_rawvp is set to nonnull, and it is only
reset to null on close.  Hence if the parent is still open, as it
must be here, sc->sc_parent->dk_rawvp must be nonnull.
2023-04-21 18:09:38 +00:00
nikita 160c9084ef lua: fix formating diff to upstream in ldo.h 2023-04-21 17:48:06 +00:00
riastradh 019d618210 autoconf(9): Add a comment where we risk arithmetic overflow. 2023-04-21 17:35:43 +00:00
nikita 4fd395ecb3 lua: fix ftb in lvm.c 2023-04-21 17:31:33 +00:00
roy 1f7e02ab78 Note update to dhcpcd-10.0.1 2023-04-21 17:00:05 +00:00
roy 74820ea053 Merge changes 2023-04-21 16:54:26 +00:00
roy 794dfa7744 Update to dhcpcd-10.0.1 with the following changes:
* privsep: keep resources open rather than open/close
 * dhcp6: OPTION_NTP_SERVER is now preferred over OPTION_SNTP_SERVER
 * Misc bug fixes mainly around privsep for many platforms.
 * Fix for reading the some BSD routing table entries.
 * Fix reading authtokens from config.

Big new release, mainly around better privsep process management
which allows us to detect when they exit unexpectedly.
2023-04-21 16:52:28 +00:00