Date: Fri, 17 Apr 2020 18:34:49 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360051 - in head/sys: dev/altera/jtag_uart dev/bvm dev/cfe dev/ofw dev/rp dev/xen/console kern netgraph sys Message-ID: <202004171834.03HIYnjX036326@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Fri Apr 17 18:34:49 2020 New Revision: 360051 URL: https://svnweb.freebsd.org/changeset/base/360051 Log: tty: convert tty_lock_assert to tty_assert_locked to hide lock type A later change, currently being iterated on in D24459, will in-fact change the lock type to an sx so that TTY drivers can sleep on it if they need to. Committing this ahead of time to make the review in question a little more palatable. tty_lock_assert() is unfortunately still needed for now in two places to make sure that the tty lock has not been recursed upon, for those scenarios where it's supplied by the TTY driver and possibly a mutex that is allowed to recurse. Suggested by: markj Modified: head/sys/dev/altera/jtag_uart/altera_jtag_uart_tty.c head/sys/dev/bvm/bvm_console.c head/sys/dev/cfe/cfe_console.c head/sys/dev/ofw/ofw_console.c head/sys/dev/rp/rp.c head/sys/dev/xen/console/xen_console.c head/sys/kern/tty.c head/sys/kern/tty_info.c head/sys/kern/tty_ttydisc.c head/sys/netgraph/ng_tty.c head/sys/sys/tty.h head/sys/sys/ttydevsw.h head/sys/sys/ttydisc.h head/sys/sys/ttyhook.h Modified: head/sys/dev/altera/jtag_uart/altera_jtag_uart_tty.c ============================================================================== --- head/sys/dev/altera/jtag_uart/altera_jtag_uart_tty.c Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/dev/altera/jtag_uart/altera_jtag_uart_tty.c Fri Apr 17 18:34:49 2020 (r360051) @@ -266,7 +266,7 @@ aju_handle_input(struct altera_jtag_uart_softc *sc, st { int c; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); AJU_LOCK_ASSERT(sc); while (aju_readable(sc)) { @@ -298,7 +298,7 @@ aju_handle_output(struct altera_jtag_uart_softc *sc, s uint32_t v; uint8_t ch; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); AJU_LOCK_ASSERT(sc); AJU_UNLOCK(sc); @@ -364,7 +364,7 @@ aju_outwakeup(struct tty *tp) { struct altera_jtag_uart_softc *sc = tty_softc(tp); - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); AJU_LOCK(sc); aju_handle_output(sc, tp); Modified: head/sys/dev/bvm/bvm_console.c ============================================================================== --- head/sys/dev/bvm/bvm_console.c Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/dev/bvm/bvm_console.c Fri Apr 17 18:34:49 2020 (r360051) @@ -130,7 +130,7 @@ static void bvm_tty_close(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); callout_stop(&bvm_timer); } @@ -159,7 +159,7 @@ bvm_timeout(void *v) tp = (struct tty *)v; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); while ((c = bvm_cngetc(NULL)) != -1) ttydisc_rint(tp, c, 0); ttydisc_rint_done(tp); Modified: head/sys/dev/cfe/cfe_console.c ============================================================================== --- head/sys/dev/cfe/cfe_console.c Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/dev/cfe/cfe_console.c Fri Apr 17 18:34:49 2020 (r360051) @@ -142,7 +142,7 @@ cfe_timeout(void *v) tp = (struct tty *)v; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); while ((c = cfe_cngetc(NULL)) != -1) ttydisc_rint(tp, c, 0); ttydisc_rint_done(tp); Modified: head/sys/dev/ofw/ofw_console.c ============================================================================== --- head/sys/dev/ofw/ofw_console.c Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/dev/ofw/ofw_console.c Fri Apr 17 18:34:49 2020 (r360051) @@ -152,7 +152,7 @@ ofw_timeout(void *v) tp = (struct tty *)v; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); while ((c = ofw_cngetc(NULL)) != -1) ttydisc_rint(tp, c, 0); ttydisc_rint_done(tp); Modified: head/sys/dev/rp/rp.c ============================================================================== --- head/sys/dev/rp/rp.c Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/dev/rp/rp.c Fri Apr 17 18:34:49 2020 (r360051) @@ -674,7 +674,7 @@ static void rp_do_poll(void *arg) rp = arg; tp = rp->rp_tty; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); ctl = rp->rp_ctlp; CtlMask = ctl->ctlmask(ctl); if (CtlMask & (1 << rp->rp_aiop)) { Modified: head/sys/dev/xen/console/xen_console.c ============================================================================== --- head/sys/dev/xen/console/xen_console.c Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/dev/xen/console/xen_console.c Fri Apr 17 18:34:49 2020 (r360051) @@ -515,7 +515,7 @@ xencons_tx(struct tty *tp) cons = tty_softc(tp); - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); /* * Don't transmit any character if the buffer is full. Otherwise, Modified: head/sys/kern/tty.c ============================================================================== --- head/sys/kern/tty.c Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/kern/tty.c Fri Apr 17 18:34:49 2020 (r360051) @@ -228,7 +228,7 @@ static void ttydev_leave(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (tty_opened(tp) || tp->t_flags & TF_OPENCLOSE) { /* Device is still opened somewhere. */ @@ -413,7 +413,7 @@ static __inline int tty_is_ctty(struct tty *tp, struct proc *p) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); return (p->p_session == tp->t_session && p->p_flag & P_CONTROLT); } @@ -427,7 +427,7 @@ tty_wait_background(struct tty *tp, struct thread *td, int error; MPASS(sig == SIGTTIN || sig == SIGTTOU); - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); for (;;) { PROC_LOCK(p); @@ -697,7 +697,7 @@ tty_kqops_read_event(struct knote *kn, long hint __unu { struct tty *tp = kn->kn_hook; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (tty_gone(tp) || tp->t_flags & TF_ZOMBIE) { kn->kn_flags |= EV_EOF; @@ -721,7 +721,7 @@ tty_kqops_write_event(struct knote *kn, long hint __un { struct tty *tp = kn->kn_hook; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (tty_gone(tp)) { kn->kn_flags |= EV_EOF; @@ -1122,7 +1122,7 @@ tty_rel_free(struct tty *tp) { struct cdev *dev; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); #define TF_ACTIVITY (TF_GONE|TF_OPENED|TF_HOOK|TF_OPENCLOSE) if (tp->t_sessioncnt != 0 || (tp->t_flags & TF_ACTIVITY) != TF_GONE) { @@ -1153,7 +1153,7 @@ tty_rel_pgrp(struct tty *tp, struct pgrp *pg) { MPASS(tp->t_sessioncnt > 0); - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (tp->t_pgrp == pg) tp->t_pgrp = NULL; @@ -1180,7 +1180,7 @@ void tty_rel_gone(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); /* Simulate carrier removal. */ @@ -1268,7 +1268,7 @@ static void tty_to_xtty(struct tty *tp, struct xtty *xt) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); xt->xt_size = sizeof(struct xtty); xt->xt_insize = ttyinq_getsize(&tp->t_inq); @@ -1460,7 +1460,7 @@ tty_signal_sessleader(struct tty *tp, int sig) { struct proc *p; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(sig >= 1 && sig < NSIG); /* Make signals start output again. */ @@ -1479,7 +1479,7 @@ tty_signal_pgrp(struct tty *tp, int sig) { ksiginfo_t ksi; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(sig >= 1 && sig < NSIG); /* Make signals start output again. */ @@ -1957,7 +1957,7 @@ tty_ioctl(struct tty *tp, u_long cmd, void *data, int { int error; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (tty_gone(tp)) return (ENXIO); @@ -2124,7 +2124,7 @@ void ttyhook_unregister(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(tp->t_flags & TF_HOOK); /* Disconnect the hook. */ Modified: head/sys/kern/tty_info.c ============================================================================== --- head/sys/kern/tty_info.c Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/kern/tty_info.c Fri Apr 17 18:34:49 2020 (r360051) @@ -266,7 +266,7 @@ tty_info(struct tty *tp) char comm[MAXCOMLEN + 1]; struct rusage ru; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (tty_checkoutq(tp) == 0) return; Modified: head/sys/kern/tty_ttydisc.c ============================================================================== --- head/sys/kern/tty_ttydisc.c Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/kern/tty_ttydisc.c Fri Apr 17 18:34:49 2020 (r360051) @@ -326,7 +326,7 @@ ttydisc_read(struct tty *tp, struct uio *uio, int iofl { int error; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (uio->uio_resid == 0) return (0); @@ -458,7 +458,7 @@ ttydisc_write(struct tty *tp, struct uio *uio, int iof int error = 0; unsigned int oblen = 0; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (tp->t_flags & TF_ZOMBIE) return (EIO); @@ -573,7 +573,7 @@ done: void ttydisc_optimize(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (ttyhook_hashook(tp, rint_bypass)) { tp->t_flags |= TF_BYPASS; @@ -594,7 +594,7 @@ void ttydisc_modem(struct tty *tp, int open) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (open) cv_broadcast(&tp->t_dcdwait); @@ -842,7 +842,7 @@ ttydisc_rint(struct tty *tp, char c, int flags) char ob[3] = { 0xff, 0x00 }; size_t ol; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); atomic_add_long(&tty_nin, 1); @@ -1085,7 +1085,7 @@ ttydisc_rint_bypass(struct tty *tp, const void *buf, s { size_t ret; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(tp->t_flags & TF_BYPASS); @@ -1106,7 +1106,7 @@ void ttydisc_rint_done(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (ttyhook_hashook(tp, rint_done)) ttyhook_rint_done(tp); @@ -1122,7 +1122,7 @@ ttydisc_rint_poll(struct tty *tp) { size_t l; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (ttyhook_hashook(tp, rint_poll)) return ttyhook_rint_poll(tp); @@ -1165,7 +1165,7 @@ size_t ttydisc_getc(struct tty *tp, void *buf, size_t len) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (tp->t_flags & TF_STOPPED) return (0); @@ -1192,7 +1192,7 @@ ttydisc_getc_uio(struct tty *tp, struct uio *uio) size_t len; char buf[TTY_STACKBUF]; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (tp->t_flags & TF_STOPPED) return (0); @@ -1233,7 +1233,7 @@ size_t ttydisc_getc_poll(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (tp->t_flags & TF_STOPPED) return (0); @@ -1255,7 +1255,7 @@ tty_putstrn(struct tty *tp, const char *p, size_t n) { size_t i; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (tty_gone(tp)) return (-1); Modified: head/sys/netgraph/ng_tty.c ============================================================================== --- head/sys/netgraph/ng_tty.c Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/netgraph/ng_tty.c Fri Apr 17 18:34:49 2020 (r360051) @@ -412,7 +412,7 @@ ngt_rint_bypass(struct tty *tp, const void *buf, size_ size_t total = 0; int error = 0, length; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (sc->hook == NULL) return (0); @@ -459,7 +459,7 @@ ngt_rint(struct tty *tp, char c, int flags) struct mbuf *m; int error = 0; - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); if (sc->hook == NULL) return (0); Modified: head/sys/sys/tty.h ============================================================================== --- head/sys/sys/tty.h Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/sys/tty.h Fri Apr 17 18:34:49 2020 (r360051) @@ -173,8 +173,11 @@ void tty_rel_gone(struct tty *tp); #define tty_lock(tp) mtx_lock((tp)->t_mtx) #define tty_unlock(tp) mtx_unlock((tp)->t_mtx) #define tty_lock_owned(tp) mtx_owned((tp)->t_mtx) -#define tty_lock_assert(tp,ma) mtx_assert((tp)->t_mtx, (ma)) +#define tty_assert_locked(tp) mtx_assert((tp)->t_mtx, MA_OWNED) #define tty_getlock(tp) ((tp)->t_mtx) + +/* XXX Should migrate users to tty_assert_locked! */ +#define tty_lock_assert(tp, ma) mtx_assert((tp)->t_mtx, (ma)) /* Device node creation. */ int tty_makedevf(struct tty *tp, struct ucred *cred, int flags, Modified: head/sys/sys/ttydevsw.h ============================================================================== --- head/sys/sys/ttydevsw.h Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/sys/ttydevsw.h Fri Apr 17 18:34:49 2020 (r360051) @@ -86,7 +86,7 @@ static __inline int ttydevsw_open(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); return (tp->t_devsw->tsw_open(tp)); @@ -96,7 +96,7 @@ static __inline void ttydevsw_close(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); tp->t_devsw->tsw_close(tp); @@ -106,7 +106,7 @@ static __inline void ttydevsw_outwakeup(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); /* Prevent spurious wakeups. */ @@ -120,7 +120,7 @@ static __inline void ttydevsw_inwakeup(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); /* Prevent spurious wakeups. */ @@ -134,7 +134,7 @@ static __inline int ttydevsw_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); return (tp->t_devsw->tsw_ioctl(tp, cmd, data, td)); @@ -145,7 +145,7 @@ ttydevsw_cioctl(struct tty *tp, int unit, u_long cmd, struct thread *td) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); return (tp->t_devsw->tsw_cioctl(tp, unit, cmd, data, td)); @@ -183,7 +183,7 @@ static __inline void ttydevsw_pktnotify(struct tty *tp, char event) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); tp->t_devsw->tsw_pktnotify(tp, event); @@ -202,7 +202,7 @@ static __inline bool ttydevsw_busy(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); return (tp->t_devsw->tsw_busy(tp)); Modified: head/sys/sys/ttydisc.h ============================================================================== --- head/sys/sys/ttydisc.h Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/sys/ttydisc.h Fri Apr 17 18:34:49 2020 (r360051) @@ -72,7 +72,7 @@ static __inline size_t ttydisc_read_poll(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); return ttyinq_bytescanonicalized(&tp->t_inq); } @@ -81,7 +81,7 @@ static __inline size_t ttydisc_write_poll(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); return ttyoutq_bytesleft(&tp->t_outq); } Modified: head/sys/sys/ttyhook.h ============================================================================== --- head/sys/sys/ttyhook.h Fri Apr 17 18:24:47 2020 (r360050) +++ head/sys/sys/ttyhook.h Fri Apr 17 18:34:49 2020 (r360051) @@ -78,7 +78,7 @@ void ttyhook_unregister(struct tty *); static __inline int ttyhook_rint(struct tty *tp, char c, int flags) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); return tp->t_hook->th_rint(tp, c, flags); @@ -87,7 +87,7 @@ ttyhook_rint(struct tty *tp, char c, int flags) static __inline size_t ttyhook_rint_bypass(struct tty *tp, const void *buf, size_t len) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); return tp->t_hook->th_rint_bypass(tp, buf, len); @@ -96,7 +96,7 @@ ttyhook_rint_bypass(struct tty *tp, const void *buf, s static __inline void ttyhook_rint_done(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); tp->t_hook->th_rint_done(tp); @@ -105,7 +105,7 @@ ttyhook_rint_done(struct tty *tp) static __inline size_t ttyhook_rint_poll(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); return tp->t_hook->th_rint_poll(tp); @@ -114,7 +114,7 @@ ttyhook_rint_poll(struct tty *tp) static __inline size_t ttyhook_getc_inject(struct tty *tp, void *buf, size_t len) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); return tp->t_hook->th_getc_inject(tp, buf, len); @@ -123,7 +123,7 @@ ttyhook_getc_inject(struct tty *tp, void *buf, size_t static __inline void ttyhook_getc_capture(struct tty *tp, const void *buf, size_t len) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); tp->t_hook->th_getc_capture(tp, buf, len); @@ -132,7 +132,7 @@ ttyhook_getc_capture(struct tty *tp, const void *buf, static __inline size_t ttyhook_getc_poll(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); MPASS(!tty_gone(tp)); return tp->t_hook->th_getc_poll(tp); @@ -141,7 +141,7 @@ ttyhook_getc_poll(struct tty *tp) static __inline void ttyhook_close(struct tty *tp) { - tty_lock_assert(tp, MA_OWNED); + tty_assert_locked(tp); tp->t_hook->th_close(tp); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202004171834.03HIYnjX036326>