Commit Graph

297455 Commits

Author SHA1 Message Date
skrll 6543c3db91 bge: Mirror the bus_dma RX buffer changes in the OpenBSD driver
This change reduces the amount of work done in the interrupt handler.
2022-08-14 09:03:05 +00:00
skrll 742af3975a Make bge(4) MP safe
This started out as a fix so that LOCKDEBUG wouldn't explode with kernel
lock spinout.  LOCKDEBUG is too aggressive now and really should be
relaxed.
2022-08-14 09:01:25 +00:00
lukem 546bd46b3f build.sh: improve help versus usage
Rework help / usage semantics:
- send help to stdout, exit 0.
- send usage to stderr, exit 1.
2022-08-14 08:51:41 +00:00
uwe 57e570e974 make(1): Fix some obviously wrong uses of .Va 2022-08-14 08:49:00 +00:00
skrll a087b0e4be Whitespace 2022-08-14 08:45:56 +00:00
skrll bfa88ac24d bge: Fix bge_ring_map bus_dmamap_sync POST{READ,WRITE} operations.
When the range of ring entries wraps around sync from the start of the
ring to the last entry.
2022-08-14 08:42:33 +00:00
mlelstv 1ce359b723 Split TSC calibtration into many small steps and disable interrupts
for each step. Also add debug messages.
2022-08-14 07:49:33 +00:00
rillig 338356f54b make.1: clean up formatting and grammar, be more accurate 2022-08-14 04:17:09 +00:00
rillig abbcae44b8 make.1: not every '-' is a flag 2022-08-14 04:12:29 +00:00
jmcneill 40939db178 pciconf: Skip callbacks for reserved ranges if resource allocation fails.
In the event that a BAR write is ignored, no need to notify the callback
of any changes.
2022-08-13 21:51:33 +00:00
jmcneill 9ebe52630b Add "nopcimsi" boot option to force legacy INTx only mode. 2022-08-13 20:08:36 +00:00
jmcneill 9c4bb73692 arm: acpi: Improve legacy INTx support.
For devices on a bus with no direct _PRT, use the raw intr pin with the
parent bridge's slot number to derive a pin number that can be used to
lookup the pin -> irq mapping in the parent bus's _PRT.
2022-08-13 20:07:13 +00:00
hannken e14a6c8694 When run from py-anita/amd64 this test fails with:
cgdconfig: getfsspecname failed: no match for `wd0e'

as the virtual machine has root on dk0, dk0 at wd0 and trying to
open wd0e fails.

This tests runs without a rump kernel and therefore should not
even try to open configured devices on the host.  Replace the
disks "wd0e" and "ld1e" with non-existant disks "dska" and "dskb".
2022-08-13 17:46:26 +00:00
riastradh f9d4cd6b9b viocon(4): Omit unused sc_dmamap. 2022-08-13 17:31:32 +00:00
riastradh e35330b91a viocon(4): Fix bus_dmamap_sync after tx: POSTWRITE, not POSTREAD. 2022-08-13 17:31:21 +00:00
wiz 68024510e8 Remove Li without effect. 2022-08-13 17:06:55 +00:00
wiz 20da36831f New sentence, new line. 2022-08-13 17:06:38 +00:00
riastradh 0abc1f6384 viocon(4): Fix $NetBSD$ rcsid. 2022-08-13 17:02:53 +00:00
wiz 08b052832f Fix Dd argument. 2022-08-13 17:02:10 +00:00
jmcneill 648048f537 aarch64: Add tpm driver to GENERIC64 kernel. 2022-08-13 16:55:10 +00:00
riastradh a8a1e86030 viocon(4): Fix tty device number. 2022-08-13 16:52:29 +00:00
jmcneill cf79ebbbb2 acpipchb: Add a kernel cmdline option to skip PCI resource assignment.
Passing "nopciconf" to the kernel will force acpipchb to skip PCI
resource assignment.
2022-08-13 16:44:11 +00:00
jmcneill 7063e10b11 Process "ranges" property even when linux,pci-probe-only is set.
When the linux,pci-probe-only flag is set, we still need to process the
ranges property to determine whether or not to set PCI_FLAGS_IO_OKAY and
PCI_FLAGS_MEM_OKAY flags on the bus.
2022-08-13 16:01:34 +00:00
jandberg c017fe63d1 Update comment about X11 support 2022-08-13 10:53:38 +00:00
martin 1149feacd2 Do not try to create a fake MBR disklabel from the PMBR of a GPT disk. 2022-08-13 09:34:47 +00:00
isaki aa3450bc70 audiotest: Add two tests for AUDIO_SETINFO after mmap.
These tests affect only standalone test, not atf.
2022-08-13 07:22:40 +00:00
isaki 248c923741 audiotest: Fix typo in comments. 2022-08-13 07:19:15 +00:00
isaki 00cd774dfc audiotest: Separate mmap_len test by parameters.
This change affects only standalone test, not atf.
2022-08-13 07:14:40 +00:00
skrll 66dead3da9 Fix an inverted KASSERTMSG test from the #ifdef DIAGNOSTIC panic -> KASSERT
conversion.
2022-08-13 06:59:56 +00:00
isaki de41ebe0c0 audio: Rework about usrbuf allocation.
- Allocate the usrbuf from kmem(9) instead of uvm(9).  The usrbuf has used
  uvm(9), in case mmap(2) might be issued later.  However, despite the most
  apps don't use mmap(2), allocating (and reallocating) uvm(9) every time
  would be expensive.  In addition, uvm(9) for recording usrbuf was totally
  pointless now.
- For playback, the usrbuf memory will be allocated in pages.  Because the
  usrbuf for playback is mostly near 64KB for backward compatibility.
  This will reduce reallocation especially from the initial ulaw to the most
  commonly used format like slinear16/2ch/48kHz.
- When mmap(2) is called, it will replace the playback usrbuf from kmem(9) to
  uvm(9).
- Prohibit changing playback format once mmap(2) is called.
  It follows netbsd-7.
- For recording, the usrbuf memory will be allocated in the requested size
  every time as before.  Because the usrbuf for recording is only one block
  and is enough small to the page in the most case.
Inspired by PR kern/56947.
2022-08-13 06:47:41 +00:00
riastradh 2ab9954344 specfs: Refuse to open a closing-in-progress block device.
We could wait for close to complete, but if this happened ever so
slightly earlier it would lead to EBUSY anyway, so there's no point
in adding logic for that -- either way the caller neglected to wait
for the last close to finish before trying to open it the device
again.

https://mail-index.netbsd.org/current-users/2022/08/09/msg042800.html

Reported-by: syzbot+4388f20706ec8a4c8db0@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=47c67ab6d3a87514d0707882a9ad6671beaa8642

Reported-by: syzbot+0f1756652dce4cb341ed@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=a632ce762d64241fc82a9bc57230b7b7c7095d1a
2022-08-12 21:25:39 +00:00
riastradh 3259e3c923 rum(4): Avoid uninitialized garbage in failed register read.
Reported-by: syzbot+f2cba71b1b1bc91029b3@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=7a01863d0fe34a4946516388c436991ba2beaa63
2022-08-12 19:13:36 +00:00
riastradh a5fdd92957 specfs: Assert !closing on successful open.
- If there's a prior concurrent close, it must have interrupted this
  open.

- If there's a new concurrent close, it must wait until this open has
  released device_lock before it can revoke.
2022-08-12 17:06:01 +00:00
riastradh 938c8ecc70 specfs: Assert opencnt>0 on successful open. 2022-08-12 17:05:49 +00:00
riastradh 8769a2203d thinkpad(4): Don't detach on shutdown.
There's no important state that needs to be recorded, or resources
that need to be relinquished, so detach-on-shutdown isn't necessary.

At the moment, detach-on-shutdown is actually harmful here: if
shutdown is triggered by a sysmon power switch event, then
config_detach will be called from the sysmon taskqueue, but
thinkpad_detach has to wait for ACPI notifiers to finish running
which means waiting for the sysmon taskqueue -> deadlock or crash.

We should maybe arrange to do config_detach from a thread other than
the sysmon taskqueue thread to avoid this class of problems -- but
for now, thinkpad(4) has no reason to detach on shutdown anyway, so
let's take the easy path.

Note: There are many drivers that set DVF_DETACH_SHUTDOWN which
probably shouldn't; the flag means the kernel _will_ detach on
shutdown, not that it _may_.  Even those that do need to record state
or relinquish resources might be better served by pmf shutdown hooks
which can skip freeing software resources for faster shutdown.
2022-08-12 16:21:41 +00:00
riastradh 1536c4bfa3 autoconf(9): Provide diagnostics for config_detach_* misuse. 2022-08-12 16:16:12 +00:00
riastradh 7ce51081c7 module(9), sysctl(7): Document kern.module.autounload_unsafe. 2022-08-12 15:43:38 +00:00
riastradh 4fd6c3fe81 usbnet(9): Tidy up language about init/rx/tx/stop in man page. 2022-08-12 15:30:41 +00:00
riastradh c4bc985609 module(9): Don't autounload unaudited modules by default.
Modules that have not been audited for autounload safety don't
recognize the command MODULE_CMD_AUTOUNLOAD and return ENOTTY.  These
modules are not safe to autounload, so don't autounload them.  Since
unload is risky business (if not careful, can lead to use-after-free,
kernel memory corruption, &c.), it needs to be opt-in by default, not
opt-out.

Modules that have been audited can return 0 or EBUSY to explicitly
allow or deny autounload.  Users who want to live on the edge to try
to exercise module autounload even for unaudited modules -- and are
willing to accept the consequences, and maybe contribute to auditing!
-- can set the new sysctl knob kern.module.autounload_unsafe=1.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2022/08/08/msg028282.html
2022-08-12 15:17:10 +00:00
riastradh bec343a700 x86/bus_dma: #ifdef DIAGNOSTIC panic -> KASSERT
While here, use some better types and avoid integer overflow in the
diagnostic tests.

No functional change intended except in the case of bugs anyway.
2022-08-12 15:01:26 +00:00
riastradh 86933b7331 x86: Adjust fences issued in bus_dmamap_sync after bouncing.
And expand the comment on the lfence for POSTREAD before bouncing.

Net change:

op                      before bounce       after bounce
                                        old             new
PREREAD                 nop             lfence          sfence
PREWRITE                nop             mfence          sfence
PREREAD|PREWRITE        nop             mfence          sfence
POSTREAD                lfence          lfence          nop[*]
POSTWRITE               nop             mfence          nop
POSTREAD|POSTWRITE      lfence          mfence          nop[*]

The case of PREREAD is as follows:

1. loads and stores before DMA buffer may be allocated for the purpose
2. bus_dmamap_sync(BUS_DMASYNC_PREREAD)
3. store to register or DMA descriptor to trigger DMA

The register or DMA descriptor may be in any type of memory (or I/O).

lfence at (2) is _not enough_ to ensure stores at (1) have completed
before the store in (3) in case the register or DMA descriptor lives
in wc/wc+ memory, or the store to it is non-temporal: in that case,
it may executed early before all the stores in (1) have completed.

On the other hand, lfence at (2) is _not needed_ to ensure loads in
(1) have completed before the store in (3), because x86 never
reorders load;store to store;load.  So we may need to enforce
store/store ordering, but not any other ordering, hence sfence.

The case of PREWRITE is as follows:

1. stores to DMA buffer (and loads from it, before allocated)
2. bus_dmamap_sync(BUS_DMASYNC_PREWRITE)
3. store to register or DMA descriptor to trigger DMA

Ensuring prior loads have completed is not necessary because x86
never reorders load;store to store;load (and in any case, the device
isn't changing the DMA buffer, so it's safe to read over and over
again).  But we must ensure the stores in (1) have completed before
the store in (3).  So we need sfence, in case either the DMA buffer
or the register or the DMA descriptor is in wc/wc+ memory or either
store is non-temporal.  But we don't need mfence.

The case of POSTREAD is as follows:

1. load from register or DMA descriptor notifying DMA completion
2. bus_dmamap_sync(BUS_DMASYNC_POSTREAD)
   (a) lfence [*]
   (b) if bouncing, memcpy(userbuf, bouncebuf, ...)
   (c) ???
3. loads from DMA buffer to use data, and stores to reuse buffer

This certainly needs an lfence to prevent the loads at (3) from being
executed early -- but bus_dmamap_sync already issues lfence in that
case at 2(a), before it conditionally loads from the bounce buffer
into the user's buffer.  So we don't need any _additional_ fence
_after_ bouncing at 2(c).

The case of POSTWRITE is as follows:

1. load from register or DMA descriptor notifying DMA completion
2. bus_dmamap_sync(BUS_DMASYNC_POSTWRITE)
3. loads and stores to reuse buffer

Stores at (3) will never be executed early because x86 never reorders
load;store to store;load for any memory types.  Loads at (3) are
harmless because the device isn't changing the buffer -- it's
supposed to be fixed from the time of PREWRITE to the time of
POSTWRITE as far as the CPU can witness.

Proposed on port-amd64 last month:

https://mail-index.netbsd.org/port-amd64/2022/07/16/msg003593.html

Reference:

AMD64 Architecture Programmer's Manual, Volume 2: System Programming,
24593--Rev. 3.38--November 2021, Sec. 7.4.2 Memory Barrier Interaction
with Memory Types, Table 7-3, p. 196.
https://www.amd.com/system/files/TechDocs/24593.pdf
2022-08-12 13:44:12 +00:00
riastradh b377a6075b bus_space(9): Update barrier semantics to match reality and sense.
As proposed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2022/07/16/msg028249.html

tl;dr:
- bus_space_barrier is needed only with prefetchable/cacheable.
- BUS_SPACE_BARRIER_READ is like membar_acquire.
- BUS_SPACE_BARRIER_WRITE is like membar_release.
- READ|WRITE is like membar_sync.
2022-08-12 13:24:37 +00:00
riastradh 85774ea613 usbnet(9): Fix mbuf alignment and narrow bounds check.
In usbnet.c rev. 1.16, usbnet_newbuf was first passed a buffer length
to verify it fits within MCLBYTES.  It also changed m_adj to go
before, not after, setting m_len and m_pkthdr.len -- which had the
effect of making the m_adj a no-op, because after MGETHDR the mbuf
has zero length and m_adj stops at the length of the mbuf, so nothing
was aligned as intended.

To make this aligned as intended, we require the buffer length to be
_below_ MCLBYTES, by ETHER_ALIGN, so there's room for the ethernet
header in a maximum-length payload.  Once we do that, it is safe to
initialize m_len = m_pkthdr.len = ETHER_ALIGN + buflen, which is
below the actual size of the mbuf (MHLEN or MCLBYTES, depending), and
_then_ do m_adj to align the pointer.
2022-08-12 11:25:45 +00:00
riastradh fdfb7cab0e membar(3): Fix t_spinlock for machines with hash-locked atomics.
Regular stores don't participate in the hash-locking scheme, so use
atomic_swap instead of a regular store here.
2022-08-12 11:21:44 +00:00
riastradh cc725e3507 viocon(4): New virtio tty driver imported from OpenBSD.
viocon* at virtio?

/dev/ttyVI??

Tested under qemu with:

qemu-system-aarch64 ... \
  -device virtio-serial \
  -chardev socket,path=/tmp/ttyVI00,server=on,wait=off,id=ttyVI00 \
  -device virtconsole,chardev=ttyVI00,name=org.NetBSD.dev.ttyVI00 \
  ...

I updated MAKEDEV.conf to create /dev/ttyVI?? on all ports where it
looks likely to work based on:
(a) having pci or a non-pci virtio attachment,
(b) `qemu-system-$ARCH -M ?' mentioned something resembling the port,
    and
(c) `qemu-system-$ARCH -device virtio-serial' launched without
    complaining about the virtio-serial device.

(Criterion (c) excluded sparc and sparc64.)
2022-08-12 11:15:40 +00:00
riastradh 2f5368b82e wm(4): Remove the non-MP-safe scaffolding.
- Where we had #ifndef WM_MPSAFE splnet(), we also had WM_CORE_LOCK,
  which implies splnet, so just remove the conditional splnet.

- Make the core lock unconditional and remove macro indirections.

- Pass CALLOUT_MPSAFE, SOFTINT_MPSAFE, and WQ_MPSAFE directly without
  macro indirections.
2022-08-12 10:59:42 +00:00
riastradh 9b55231166 wm(4): Audit sc->phy.acquire and sc->nvm.acquire.
The return value must be used, because some of the acquire/release
pairs hold a mutex from acquire to release, and failing to call
release, or calling release twice, leads to an inconsistent state.
2022-08-12 10:58:45 +00:00
riastradh 0b717e9120 wm: use a workqueue to reset the interface when wm_watchdog determines it needs a reset.
Author: Nick Hudson <skrll@netbsd.org>
Committer: Taylor R Campbell <riastradh@NetBSD.org>
2022-08-12 10:58:21 +00:00
riastradh 5d68158ac4 wm(4): if_flags and IFNET_LOCK audit
Don't touch if_flags without IFNET_LOCK:

- If only core lock is held, use sc_if_flags.
- If only txq lock is held, use txq_stopping.
  => Verified all paths guarantee !txq_stopping, so assert.
- Make sure sc_if_flags is updated on stop.
- Make wm_init fail once we enter wm_detach.
- Sprinkle assertions.


Author: Taylor R Campbell <riastradh@NetBSD.org>
2022-08-12 10:57:06 +00:00
riastradh 77bae3ca91 wm(4): Revert previous -- mistakenly committed unsquashed change part. 2022-08-12 10:55:01 +00:00