Commit Graph

300759 Commits

Author SHA1 Message Date
riastradh 86535c9941 specfs: KNF. No functional change intended. 2023-04-22 15:32:49 +00:00
rillig 83d27b7d33 lint: do not warn about parenthesized assignment in controlling expr
Same as for GCC and Clang.
2023-04-22 15:14:37 +00:00
hannken af21e07e29 Remove unused mount member mnt_transinfo.
Ride 10.99.4
2023-04-22 14:30:54 +00:00
hannken 149aa6be82 Remove unused specdev member sd_rdev.
Ride 10.99.4
2023-04-22 14:30:16 +00:00
riastradh e6c797dcea fcntl(2), flock(2): Assert FHASLOCK is clear if no fo_advlock. 2023-04-22 14:23:59 +00:00
riastradh 0755170836 fcntl(2), flock(2): Unify error branches.
Let's make this a bit less error-prone by having everything converge
in the same place instead of multiple returns in different contexts.
2023-04-22 14:23:50 +00:00
riastradh cf7aea2993 fcntl(2), flock(2): Fix missing fd_putfile in error branch.
Oops!
2023-04-22 14:23:32 +00:00
riastradh c7eadb645d Welcome to 10.99.4, courtesy of struct fileops additions! 2023-04-22 14:05:36 +00:00
riastradh b50bf5fb41 rump: Move vnode_if.c from rumpkern to rumpvfs.
This has become increasingly less of a `fully dynamic interface', and
the need for it in the rest of sys/kern/ has been obviated, so let's
put it where it belongs in rumpvfs.
2023-04-22 13:54:59 +00:00
riastradh 7d219861d7 secmodel_extensions: Split vfs part into separate .c file.
This way we can provide weak rumpkern stubs that don't require
rumpvfs for things that are relevant to vfs, but if you do link
rumpvfs then you get the same logic in secmodel extensions.
2023-04-22 13:54:19 +00:00
riastradh 7d23e04198 rump: Move ubc_uiomove, ubc_zerorange from rumpvfs to rumpkern.
Needed by kern_ksyms.c.  We could split kern_ksyms.c up into kernel-
internal interfaces and the user/kernel /dev/ksyms interface, but
there's nothing vfs-specific about ubc_uiomove and ubc_zerorange
anyway, so let's just define them in rumpkern.
2023-04-22 13:53:53 +00:00
riastradh 01ab3089c8 rumpkern: Provide stub pnbuf_cache weak alias.
Needed only by sys_module.c handle_modctl_load, which won't work if
there's no rumpvfs linked in anyway.
2023-04-22 13:53:44 +00:00
riastradh f8ae240ea8 rumpkern: Provide stub uvm_vnodeops weak alias.
Needed for UVM_OBJ_IS_VNODE, but not for anything else in rumpkern
without rumpvfs.
2023-04-22 13:53:37 +00:00
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