Commit Graph

301107 Commits

Author SHA1 Message Date
riastradh 007aafd79d efi(4): Implement MI parts of EFIIOC_GET_TABLE.
Intended to be compatible with FreeBSD.

Not yet supported on any architectures.

PR kern/57076

XXX pullup-10
2023-05-22 16:27:58 +00:00
riastradh 300b116152 efi(4): Move error macros to efi.h.
PR kern/57076

XXX pullup-10
2023-05-22 16:27:48 +00:00
riastradh 7ac3dc849f efi(4): Parenthesize EFIERR argument out of paranoia.
PR kern/57076

XXX pullup-10
2023-05-22 16:27:39 +00:00
riastradh 68e2407866 dtrace_fbt: Read and write instructions appropriately-endian on arm.
arm is a little more complicated because it has three cases:
- big-endian data, big-endian instructions
- big-endian data, little-endian instructions
- little-endian data, little-endian instructions
2023-05-22 15:12:54 +00:00
riastradh 2e4b9f2ad5 dk(4): Add locking notes. 2023-05-22 15:00:17 +00:00
riastradh f135754f8b dk(4): Explain why no need for device reference in dksize, dkdump. 2023-05-22 15:00:06 +00:00
riastradh f4b9deb83c dk(4): Strengthen preconditions of various devsw operations.
These can only happen between dkopen and dkclose, so there's no need
to test -- we can assert instead that the wedge exists and is fully
initialized.
2023-05-22 14:59:58 +00:00
riastradh 76134fbec7 dk(4): Strengthen dkclose preconditions.
Like dkopen, except it is possible for this to be called after the
wedge has transitioned to dying.

XXX sc_state read here races with sc_state write in dkwedge_detach.
Could change this to atomic_load/store.
2023-05-22 14:59:50 +00:00
riastradh 63ec6eb7b5 dk(4): Strengthen dkopen preconditions.
This cannot be called before dkwedge_attach for the same unit
returns, so sc->sc_dev is guaranteed to be set to a nonnull device_t
and the state is guaranteed not to be larval.

And this cannot be called concurrently with dkwedge_detach, or after
dkwedge_detach does vdevgone until another wedge with the same number
is attached (which can't happen until dkwedge_detach completes), so
the state is guaranteed not to be dying or dead.

Hence sc->sc_dev != NULL and sc->sc_state == DKW_STATE_RUNNING.
2023-05-22 14:59:42 +00:00
riastradh 83a2b59bb8 dk(4): Prevent race between dkwedge_get_parent_name and wedge detach.
Still races with parent detach but maybe this is better.

XXX Maybe we should ditch dkwedge_get_parent_name -- it's used only
by rf_containsboot, which kinda suggests it shouldn't exist.
2023-05-22 14:59:34 +00:00
riastradh cf2c621940 dk(4): Split unsafe lookups into safe subroutines and unsafe wrappers.
No functional change intended.

Eventually we should adjust the callers to use the safe subroutines
instead and device_release when done.
2023-05-22 14:59:25 +00:00
riastradh a2f20f9f51 dk(4): Don't hold lock around uiomove in dkwedge_list.
Instead, hold a device reference.  dkwedge_detach will not run until
the device reference is released.
2023-05-22 14:59:16 +00:00
riastradh 6d451267ef dk(4): Skip larval wedges in various lookup routines.
These have not yet finished a concurent dkwedge_attach, so there's
nothing we can safely do with them.  Just pretend they don't exist --
as if we had arrived at the lookup a moment earlier.
2023-05-22 14:59:07 +00:00
riastradh 491f52c66d dk(4): Simplify dkwedge_delall by detaching directly.
No need for O(n^2) algorithm and potentially racy lookups -- not that
n is large enough for n^2 to matter, but the mechanism is simpler
this way.
2023-05-22 14:58:59 +00:00
riastradh 1a796f2016 dk(4): Use device_lookup_private for dkwedge_lookup.
No longer necessary to go through the dkwedges array.

Currently device_lookup_private still involves touching other global
locks, but that will change eventually to a lockless pserialized fast
path.
2023-05-22 14:58:50 +00:00
riastradh 766ff58e57 dk(4): dkunit is no longer needed; nix it.
dkwedges array indexing now coincides with autoconf device numbering.
2023-05-22 14:58:41 +00:00
riastradh 12be938315 dk(4): Use config_attach_pseudo_acquire to create wedges.
This way, indexing of the dkwedges array coincides with numbering of
autoconf dk(4) instances.

As a side effect, this plugs a race in dkwedge_add with concurrent
drvctl -r.  There are a lot of such races in dk(4) left -- to be
addressed with more device references.
2023-05-22 14:58:32 +00:00
riastradh d14ddd60fe autoconf(9): New functions for referenced attach/detach.
New functions:

- config_found_acquire(dev, aux, print, cfargs)
- config_attach_acquire(parent, cf, aux, print, cfargs)
- config_attach_pseudo_acquire(cf, aux)
- config_detach_release(dev, flags)
- device_acquire(dev)

The config_*_acquire functions are like the non-acquire versions, but
they return a referenced device_t, which is guaranteed to be safe to
use until released.  The device's detach function may run while it is
referenced, but the device_t will not be freed and the parent's
.ca_childdetached routine will not be called.

=> config_attach_pseudo_acquire additionally lets you pass an aux
   argument to the device's .ca_attach routine, unlike
   config_attach_pseudo which always passes NULL.

=> Eventually, config_found, config_attach, and config_attach_pseudo
   should be made to return void, because use of the device_t they
   return is unsafe without the kernel lock and difficult to use
   safely even with the kernel lock or in a UP system.  For now,
   they require the caller to hold the kernel lock, while
   config_*_acquire do not.

config_detach_release is like device_release and then config_detach,
but avoids the race inherent with that sequence.

=> Eventually, config_detach should be eliminated, because getting at
   the device_t it needs is unsafe without the kernel lock and
   difficult to use safely even with the kernel lock or in a UP
   system.  For now, it requires the caller to hold the kernel lock,
   while config_detach_release does not.

device_acquire acquires a reference to a device.  It never fails and
can be used in thread context (but not interrupt context, hard or
soft).  Caller is responsible for ensuring that the device_t cannot
be freed; in other words, the device_t must be made unavailable to
any device_acquire callers before the .ca_detach function returns.
Typically device_acquire will be used in a read section (mutex,
rwlock, pserialize, &c.) in a data structure lookup, with
corresponding logic in the .ca_detach function to remove the device
from the data structure and wait for all read sections to complete.

Proposed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/05/10/msg028889.html
2023-05-22 14:58:22 +00:00
riastradh a7a3e2ad8d tty(9): Make ttwrite update uio with only how much it has consumed.
As is, it leaves uio in an inconsistent state.  Good enough for the
write(2) return value to be correct for a userland caller to restart
write(2) where it left off, but not good enough for a loop in the
kernel to reuse the same uio.

Reported-by: syzbot+e0f56178d0add0d8be20@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=6290eb02b8fe73361dc15c7bc44e1208601e6af8

Reported-by: syzbot+7caa189e8fccd926357e@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=c0a3b77b4831dfa81fc855857bde81755d246bd3

Reported-by: syzbot+4a1eff91eb4e7c1970b6@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=10523a633a4ad9749f57dc7cf03f9447d518c5b8

Reported-by: syzbot+1d3c280f59099dc82e17@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=8e02ebb0da76a8e286461f33502117a1d30275c6

Reported-by: syzbot+080d51214d0634472b12@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=1f617747db8087e5554d3df1b79a545dee26a650

Reported-by: syzbot+dd50b448e49e5020131a@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=f71c8cef4110b7eeac6eca67b6a4d1f4a8b3e96f

Reported-by: syzbot+26b675ecf0cc9dfd8586@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=57b1901f5b3e090a964d08dd0d729f9909f203be

Reported-by: syzbot+87f0df2c9056313a5c4b@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=67994a3da32d075144e25d1ac314be1d9694ae6e

Reported-by: syzbot+e5bc98e18aa42f0cb25d@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=6374bd286532423c63f2b331748280729134224c

Reported-by: syzbot+7e587f4c5aaaf80e84b3@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=976210ed438d48ac275d77d7ebf4a086e43b5fcb
2023-05-22 14:07:37 +00:00
riastradh 819a01cff3 uiomove(9): Add uiopeek/uioskip operations.
This allows a caller to grab some data, consume part of it, and
atomically update the uio with only the amount it consumed.  This
way, the caller can use a buffer of a size that doesn't depend on how
much it will actually consume, which it may not know in advance --
e.g., because it depends on how much an underlying hardware tty
device will accept before it decides it has had too much.

Proposed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/05/09/msg028883.html

(Opinions were divided between `uioadvance' and `uioskip'.  I stuck
with `uioskip' because that was less work for me.)
2023-05-22 14:07:24 +00:00
lukem bfb7ad4003 man0: support objdirs, tools, parallel builds
man0 creates files, so write to the the OBJDIR instead of the
source directory.

Use TOOL_ appropriately.
Add MAKEVERBOSE support.

Add separate rules to generate:
- all.files: the list of all man files to process (based on mkman)
- manNpages.files: per-section files from all.files. (based on mkman)
- manNpages.ps: per-section .ps from manNpages.files, with
  per-file MAKEVERBOSE messages to stderr (as before, just prettier).
- manNpages.pdf: per-section .pdf from manNpages.ps.

Remove the now-obsolete mkman script.

Add TOOL_GROPS and _MKSHMSG_FORMAT to <bsd.own.mk>
2023-05-22 12:55:44 +00:00
rillig f14ab694cd lint: rename constant NOTSPEC to NO_TSPEC
It was too easy to misread the old name as NOT_SPEC instead of the
intended NO_TSPEC.
2023-05-22 12:55:04 +00:00
lukem 35586877ba man0: add bind/dist/bin/tests to noman 2023-05-22 12:34:48 +00:00
rillig 9379c1663f tests/lint: demonstrate wrong emitted array length in initialization
Seen in usr.bin/indent/debug.c, in the various 'name' arrays.
2023-05-22 11:51:46 +00:00
rillig b95ee04d96 indent: implement suppressing optional blank lines 2023-05-22 10:28:59 +00:00
skrll 5b6b6999b3 Fix a comment 2023-05-22 06:50:52 +00:00
rillig 0df62e5bf6 tests/indent: skip creating an intermediate file in tests 2023-05-22 06:35:56 +00:00
msaitoh e1c80d2dbf Fix a bug when a media is changed to IFM_AUTO.
Fix a bug that ifconfig ifN media auto doesn't change the setting when
the previous media setting used autonego. When the mii_phy_setmedia()
function is called to change the media to IFM_AUTO, the BMCR_AUTOEN bit was
used to check if the previous setting was IFM_AUTO. It's not correct.
IFM_1000_T also uses autonego. So if a previous setting is IFM_1000_T and
the next setting is IFM_AUTO, mii_phy_auto() is not called if neither
MIIF_FORCEANEG nor MIIF_DOPAUSE are set. As a result, after changing
IFM_AUTO, neither 10Mbps nor 100Mbps are not advertised.

Note that almost all drivers uses MIIF_DOPAUSE flags.

TODO: cleanup ciphy.c and rgephy.c. Those have #ifdef foo.
2023-05-22 02:12:13 +00:00
andvar e7745f3aff s/thar/that/ in comments. 2023-05-21 18:01:38 +00:00
mlelstv dc30f1e972 iscsictl uses authentication types (n)one, (c)hap and mutual (C)hap. 2023-05-21 12:02:43 +00:00
rillig c99fb69e72 tests/indent: fix outdated or wrong comments 2023-05-21 10:18:44 +00:00
rillig 243cf9019e indent: don't read out-of-bounds memory in preprocessing lines
(Since a few minutes.)

If a line '#if 0' was followed by an unlikely line '#', the second line
was interpreted as '#if' as well.

To detect this bug automatically, a dynamic analysis tool would need to
know that only the memory between lab.mem and lab.mem + lab.len has
defined content.  This constraint, in turn, would throw up at the bottom
of copy_comment_wrap, which for a brief moment intentionally violates
this constraint.
2023-05-21 10:05:20 +00:00
rillig 4779b6fb88 indent: don't error out on unrecognized preprocessor directives
This allows indent to be used on the GCC preprocessor output.
2023-05-21 09:48:22 +00:00
nisimura 9c45fecdea small fixes, code shuffle for ease of understanding. 2023-05-21 00:35:38 +00:00
rillig 89b72942a5 tests/indent: prevent 'indent end' with arguments 2023-05-20 22:08:07 +00:00
rillig a9183f83be tests/indent: migrate test driver from AWK to Lua
Lua reports more details when os.execute fails, which is useful when
running old versions of indent for comparison.  The new test driver also
supports multiple test files in the same run.
2023-05-20 21:32:05 +00:00
rillig 04185e831b tests/indent: clean up test driver
No functional change.
2023-05-20 17:31:53 +00:00
rillig 687b1dc030 indent: remove redundant checks in processing of '}'
No functional change.
2023-05-20 16:31:31 +00:00
christos f49971e7bf remove old files that cause conflicts on case insensitive filesystems. Reported
by lukem@
2023-05-20 14:44:29 +00:00
rillig fe2fb3c8db indent: don't insert blank line between two closing lines 2023-05-20 12:05:01 +00:00
rillig 4fb425a29f indent: extract the output state from the parser state
The parser state depends on the preprocessing lines, the output state
shouldn't.
2023-05-20 11:53:53 +00:00
rillig 5a9a628018 indent: implement blank line above block comment 2023-05-20 11:19:17 +00:00
rillig 1764a17f2c indent: implement blank line after function body 2023-05-20 10:46:21 +00:00
rillig c7613eff0b indent: ensure that no blank lines are inserted in INDENT OFF mode
No blank lines were inserted previously, but the code looked
suspicious as if that were possible.
2023-05-20 10:25:47 +00:00
rillig 4d19140d48 indent: implement blank lines around conditional compilation 2023-05-20 10:09:02 +00:00
pgoyette 29d8ffc91f ALso fix chgrp Synopsis to include -d option 2023-05-20 09:41:34 +00:00
rillig e174834cff indent: add debug logging for brace indentation
No functional change outside debug mode, as the initialization of
di_stack[0] was redundant.
2023-05-20 02:47:35 +00:00
rillig 86c76bf510 indent: clean up lexing of word tokens
No functional change.
2023-05-20 01:28:14 +00:00
pgoyette b1c9211c1b dd -d to the Synopsis 2023-05-20 00:54:15 +00:00
rillig 182fed1007 indent: separate detection of function definitions from lexing '*'
No functional change.
2023-05-20 00:17:56 +00:00