Commit Graph

84 Commits

Author SHA1 Message Date
riastradh 9fcc4522cd sequencer.c: Nix trailing whitespace.
No functional change intended.
2023-10-17 09:59:46 +00:00
oster a0226423ba Redo previous by making the DPRINT macro always expand to something. 2023-10-16 13:31:33 +00:00
oster ab39a7d8f1 When building kernel=ALL, make gcc happy by addressing its warning of:
"suggest braces around empty body in an 'if' statement".
2023-10-15 18:13:37 +00:00
riastradh 5d45019599 sequencer(4): Fix lock leak in ioctl(FIOASYNC).
Reported-by: syzbot+0bfe9054ab0e70ab02e6@syzkaller.appspotmail.com
Reported-by: syzbot+f2c5459483e60dd2c877@syzkaller.appspotmail.com
Reported-by: syzbot+d932ddf0ec7e30784ca8@syzkaller.appspotmail.com

Note: The evidence from
https://syzkaller.appspot.com/bug?id=19e1c8779bb0e020188ca80a586e470b59d7525d
suggests in the stack trace that the syscall was 16, which is chown.
This is not accurate; it happens because the x86 syscall logic sets
rax in the trapframe to the return value (in this case, 16 is EBUSY)
_before_ calling userret which does the lockdebug checks, and ddb
uses the trapframe's rax to show what the syscall number was when
printing its stack trace:

[ 104.0605877] Mutex error: lwp_exit,1084: sleep lock held
[ 104.0605877] lock address : 0xffffd9801269e050 type     :     sleep/adaptive
...
[ 104.5005727] syscall() at netbsd:syscall+0x323 sys/arch/x86/x86/syscall.c:92
[ 104.5115909] --- syscall (number 16) ---

XXX Maybe we should record the syscall number elsewhere so this is
not so confusing -- second time in 24h I've been bitten by this, and
in a different way.
2022-07-01 01:04:59 +00:00
pgoyette d2d4d4364b Combine the midi and sequencer modules into a single midi_seq module
to avoid a circular dependency as noted in kern/56772.  Retain minimal
modules of the original names to accomodate auto-loading upon access
to the /dev/xxx nodes.
2022-06-04 03:31:10 +00:00
riastradh 7f28edca24 sequencer(4): VOP_CLOSE requires vnode lock.
Reported-by: syzbot+877c50d819fea9403247@syzkaller.appspotmail.com
2022-04-16 11:13:10 +00:00
riastradh fca0981e2d sequencer(4): Convert some #if DIAGNOSTIC to assertions. 2022-04-16 11:13:01 +00:00
riastradh 0cf07bbb37 sequencer(4): Sprinkle KNF.
- Sort includes.
- Nix trailing whitespace.
- No parens for return.
- Blank line between declarations and statements.
- Note MP bug with unit allocation.

No functional change intended.
2022-04-16 11:12:21 +00:00
pgoyette 97f8debd62 For device modules that provide both auto-config and /dev/xxx
interfaces, make sure that initialization and destruction
follow the proper sequence.  This is triggered by the recent
changes to the devsw stuff; per riastradh@ the required call
sequence is:

	devsw_attach()
	config_init_component() or config_cf*_attach()
	...
	config_fini_component() or config_cf*_detach()
	devsw_detach()

While here, add a few missing calls to some of the detach
routines.

Testing of these changes has been limited to:
	1. compile without build break
	2. no related test failures from atf
	3. modload/modunload work as well as
	   before.

No functional device testing done, since I don't have any
of these devices.  Let me know of any damage I might cause
here!

XXX Some of the modules affected by this commit are already
XXX broken;  see kern/56772.  This commit does not break
any additional modules (as far as I know).
2022-03-31 19:30:15 +00:00
riastradh f1443ed561 sequencer(4): Don't use mutex_spin_exit on an IPL_NONE lock. 2022-03-29 09:19:56 +00:00
thorpej 12ae65d98c Change the kqueue filterops::f_isfd field to filterops::f_flags, and
define a flag FILTEROP_ISFD that has the meaning of the prior f_isfd.
Field and flag name aligned with OpenBSD.

This does not constitute a functional or ABI change, as the field location
and size, and the value placed in that field, are the same as the previous
code, but we're bumping __NetBSD_Version__ so 3rd-party module source code
can adapt, as needed.

NetBSD 9.99.89
2021-09-26 01:16:07 +00:00
thorpej 2682e5ac8e Use sel{record,remove}_knote(). 2020-12-19 01:18:58 +00:00
ad 0eaaa024ea Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.
2020-05-23 23:42:41 +00:00
maxv 282ced251b Fix the size passed to memcpy, we only want 8 bytes. Found by KASAN. 2019-08-25 07:10:30 +00:00
riastradh e33bbc1b18 Provisionally return to declaring midi_cd unconditionally.
Apparently this breaks compiling some kernels, although how they ever
managed to link if midi_cd is not declared in ioconf.h, and therefore
presumably not defined in ioconf.c, is beyond me.

Maybe someone who knows how sequencer is supposed to work, and/or
someone who knows how arm kernels are linked, can figure this out...
2017-10-29 17:57:21 +00:00
riastradh af7f88ad32 Back out extern struct cfdriver -> ioconf.h change to sequencer.c.
This broke the module build, because it needs midi_cd which is defined
in another module and not declared by the ioconf.h generated from
sequencer.ioconf.

But...  It also needs sequencer_cd, which is _also_ not declared by
the ioconf.h generated from sequencer.ioconf, nor defined in the
ioconf.c generated from sequencer.ioconf.  Did this ever work???
2017-10-28 04:16:04 +00:00
riastradh 1f73c3c78a Kill some more extern cfdriver xyz_cd in favour of #include "ioconf.h". 2017-10-28 03:47:24 +00:00
maya 18b796d442 Use C99 initializer for filterops
Mostly done with spatch with touchups for indentation

@@
expression a;
identifier b,c,d;
identifier p;
@@
const struct filterops p =
- 	{ a, b, c, d
+ 	{
+ 	.f_isfd = a,
+ 	.f_attach = b,
+ 	.f_detach = c,
+ 	.f_event = d,
};
2017-10-25 08:12:37 +00:00
pgoyette ab66491cc5 Add infrastructure for modularization of audio, midi, and sequencer 2017-06-01 09:44:30 +00:00
chs fd34ea77eb remove checks for failure after memory allocation calls that cannot fail:
kmem_alloc() with KM_SLEEP
  kmem_zalloc() with KM_SLEEP
  percpu_alloc()
  pserialize_create()
  psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
2017-06-01 02:45:05 +00:00
christos e7ae23fd9e include "ioconf.h" to get the 'void <driver>attach(int count);' prototype. 2015-08-20 14:40:16 +00:00
mrg c0b0b4cb23 fix !AUDIO_DEBUG build. 2014-12-30 07:39:15 +00:00
mrg c180abe317 - fix a confusion between midi(4) unit and connected to sequencer
devices.
- minor comment/debug clean ups.

fixes problems attempting to read or write from the right midi(4)
device using the sequencer(4) device when one or more of the
non-final devices fails to open with midiseq_open().
2014-12-30 07:33:44 +00:00
mrg 7c9962e642 use __func__ in some debug messages. 2014-12-23 11:37:40 +00:00
mrg 55e0969cef various clean ups for midi and sequencer:
midi specific:
- add reference counting for midi operations, and ensure that
  detach waits for other threads to complete before tearing
  down the device completely.
- in detach, halt midi callouts before destroying them
- re-check sc->dying after sleeping in midiread()
- in real_writebytes(), make sure we're open and not dying
- make sure we drop the interrupt lock before calling any code
  that may want to check thread locks.  this is now safe due to
  the above changes.

sequencer specific:
- avoid caching the midi softc in the sequencer softc.  instead,
  every time we want to use it, look it up again and make sure
  it still exists.


this fixes various crashes i've seen in the usb midi code when
detaching the umidi while it is active.
2014-12-22 07:02:22 +00:00
dholland f9228f4225 Add d_discard to all struct cdevsw instances I could find.
All have been set to "nodiscard"; some should get a real implementation.
2014-07-25 08:10:31 +00:00
dholland a68f9396b6 Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
2014-03-16 05:20:22 +00:00
christos e794833e32 remove unused variables 2013-10-17 21:19:40 +00:00
christos 1da1754862 allocate dynamically 2013-04-27 22:12:42 +00:00
plunky 1687854c43 Tidy up a little, the way that midi attachment code works
- change midi_attach() to omit the 'parent' arg (there are
  only two callers of this and it is not used)

- change midisyn_attach() to midisyn_init(), so not needing a midi_softc,
  and fix the midi_pcppi driver to set hw_if and hw_hdl directly in
  its midi_softc before calling midi_attach()

- add a device_t to opl_softc structure, change opl drivers to store
  the device 'self' in opl_softc and fix opl_attach() to use this
  opl_softc->dev field directly rather than a field in an otherwise
  unused midi_softc

- remove unnecessary midi_softc from opl and cms drivers (child device
  provides that)

reviewed by mrg
2012-04-09 10:18:16 +00:00
mrg 5dec1d140d call VOP_CLOSE() in the case we're bailing due to missing both read/write.
fixes vrelel() warnings when opening /dev/music on a device that doesn't
support the requested open flags.
2012-02-13 01:47:16 +00:00
jmcneill 8a962f23f2 Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

  Add MP locking to the audio drivers.

  Making the audio drivers MP safe is necessary before efforts
  can be made to make the VM system MP safe.

  The are two locks per device instance, an ISR lock and
  a character device lock. The ISR lock replaces calls to
  splaudio()/splx(), and will be held across calls to device
  methods which were called at splaudio() before (e.g.
  trigger_output). The character device lock is held across
  calls to nearly all of the methods, excluding some only
  used for initialization, e.g. get_locks.

Welcome to 5.99.57.
2011-11-23 23:07:28 +00:00
cegger df7f595ecd Ansify function definitions w/o arguments. Generated with sed. 2009-03-18 10:22:21 +00:00
cegger f8e41c4991 make this compile 2009-01-11 10:40:27 +00:00
christos aa389c698d Use more timespecs internally. From Alexander Shishkin and me.
Welcome to 4.99.70, 30 more to go for 100.
2008-07-15 16:18:08 +00:00
cegger 708f88d69f use device_lookup_private to get softc 2008-06-12 23:06:14 +00:00
martin ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
ad 6d70f903e6 Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
  be sent from a hardware interrupt handler. Signal activity must be
  deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
  and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.
2008-04-24 15:35:27 +00:00
plunky 8b2b4c8612 use devsw_name2chr() to look up the major number of the midi device as
it is a character device
2008-03-21 19:33:24 +00:00
cube 14218c181b Split device_t/softc for midi(4), and other related cosmetic changes. 2008-03-04 21:56:11 +00:00
rmind c6186face4 Welcome to 4.99.55:
- Add a lot of missing selinit() and seldestroy() calls.

- Merge selwakeup() and selnotify() calls into a single selnotify().

- Add an additional 'events' argument to selnotify() call.  It will
  indicate which event (POLL_IN, POLL_OUT, etc) happen.  If unknown,
  zero may be used.

Note: please pass appropriate value of 'events' where possible.
Proposed on: <tech-kern>
2008-03-01 14:16:49 +00:00
pooka 4e38160d4d Do not "return 1" from kqfilter for errors. That value is passed
directly to the userland caller and results in a mysterious EPERM.
Instead, return EINVAL or something else sensible depending on the
case.
2007-12-05 17:19:46 +00:00
ad 46ed8f7d77 Use the softint API. 2007-10-08 16:18:02 +00:00
ad 88ab7da936 Merge some of the less invasive changes from the vmlocking branch:
- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
2007-07-09 20:51:58 +00:00
christos 53524e44ef Kill caddr_t; there will be some MI fallout, but it will be fixed shortly. 2007-03-04 05:59:00 +00:00
ad b07ec3fc38 Merge newlock2 to head. 2007-02-09 21:55:00 +00:00
christos 1665d5e960 fix spelling of accommodate; from Zapher. 2006-11-24 19:46:58 +00:00
christos 168cd830d2 __unused removal on arguments; approved by core. 2006-11-16 01:32:37 +00:00
pooka ce41546de3 make compile for NMIDI == 0 2006-10-22 12:52:46 +00:00
christos 4d595fd7b1 - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
2006-10-12 01:30:41 +00:00