diff options
| author | riastradh <riastradh@NetBSD.org> | 2022-10-04 05:20:01 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2022-10-04 05:20:01 +0000 |
| commit | 80c830524f897618c387e832f2f46a7dde51e032 (patch) | |
| tree | e3531bb389d11552afb0335cd0e45dabe6dafa41 /sys/dev | |
| parent | e763119a2adf6d11a36133c9e45450e550203001 (diff) | |
Revert "constty(4): Make MP-safe."
Something appears to be wrong with this.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/cons.c | 103 |
1 files changed, 29 insertions, 74 deletions
diff --git a/sys/dev/cons.c b/sys/dev/cons.c index 66a37a0c637..8c239e2e16b 100644 --- a/sys/dev/cons.c +++ b/sys/dev/cons.c @@ -1,4 +1,4 @@ -/* $NetBSD: cons.c,v 1.85 2022/10/04 05:19:30 riastradh Exp $ */ +/* $NetBSD: cons.c,v 1.86 2022/10/04 05:20:01 riastradh Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -39,7 +39,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.85 2022/10/04 05:19:30 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.86 2022/10/04 05:20:01 riastradh Exp $"); #include <sys/param.h> #include <sys/proc.h> @@ -54,8 +54,6 @@ __KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.85 2022/10/04 05:19:30 riastradh Exp $"); #include <sys/kauth.h> #include <sys/mutex.h> #include <sys/module.h> -#include <sys/atomic.h> -#include <sys/pserialize.h> #include <dev/cons.h> @@ -69,8 +67,7 @@ dev_type_ioctl(cnioctl); dev_type_poll(cnpoll); dev_type_kqfilter(cnkqfilter); -static bool cn_redirect(dev_t *, int, int *, struct tty **); -static void cn_release(struct tty *); +static bool cn_redirect(dev_t *, int, int *); const struct cdevsw cons_cdevsw = { .d_open = cnopen, @@ -89,7 +86,7 @@ const struct cdevsw cons_cdevsw = { static struct kmutex cn_lock; -struct tty *volatile constty; /* virtual console output device */ +struct tty *constty = NULL; /* virtual console output device */ struct consdev *cn_tab; /* physical console device info */ struct vnode *cn_devvp[2]; /* vnode for underlying device. */ @@ -202,7 +199,6 @@ out: mutex_exit(&cn_lock); int cnread(dev_t dev, struct uio *uio, int flag) { - struct tty *ctp = NULL; int error; /* @@ -212,31 +208,25 @@ cnread(dev_t dev, struct uio *uio, int flag) * input (except a shell in single-user mode, but then, * one wouldn't TIOCCONS then). */ - if (!cn_redirect(&dev, 1, &error, &ctp)) + if (!cn_redirect(&dev, 1, &error)) return error; - error = cdev_read(dev, uio, flag); - cn_release(ctp); - return error; + return cdev_read(dev, uio, flag); } int cnwrite(dev_t dev, struct uio *uio, int flag) { - struct tty *ctp = NULL; int error; /* Redirect output, if that's appropriate. */ - if (!cn_redirect(&dev, 0, &error, &ctp)) + if (!cn_redirect(&dev, 0, &error)) return error; - error = cdev_write(dev, uio, flag); - cn_release(ctp); - return error; + return cdev_write(dev, uio, flag); } int cnioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) { - struct tty *ctp = NULL; int error; error = 0; @@ -245,41 +235,29 @@ cnioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) * Superuser can always use this to wrest control of console * output from the "virtual" console. */ - if (cmd == TIOCCONS) { - struct tty *tp; - - mutex_enter(&constty_lock); - tp = atomic_load_relaxed(&constty); - if (tp == NULL) { - mutex_exit(&constty_lock); - goto passthrough; /* XXX ??? */ - } + if (cmd == TIOCCONS && constty != NULL) { error = kauth_authorize_device_tty(l->l_cred, - KAUTH_DEVICE_TTY_VIRTUAL, tp); + KAUTH_DEVICE_TTY_VIRTUAL, constty); if (!error) - atomic_store_relaxed(&constty, NULL); - mutex_exit(&constty_lock); - return error; + constty = NULL; + return (error); } -passthrough: + /* * Redirect the ioctl, if that's appropriate. * Note that strange things can happen, if a program does * ioctls on /dev/console, then the console is redirected * out from under it. */ - if (!cn_redirect(&dev, 0, &error, &ctp)) + if (!cn_redirect(&dev, 0, &error)) return error; - error = cdev_ioctl(dev, cmd, data, flag, l); - cn_release(ctp); - return error; + return cdev_ioctl(dev, cmd, data, flag, l); } /*ARGSUSED*/ int cnpoll(dev_t dev, int events, struct lwp *l) { - struct tty *ctp = NULL; int error; /* @@ -287,18 +265,15 @@ cnpoll(dev_t dev, int events, struct lwp *l) * I don't want to think of the possible side effects * of console redirection here. */ - if (!cn_redirect(&dev, 0, &error, &ctp)) + if (!cn_redirect(&dev, 0, &error)) return POLLHUP; - error = cdev_poll(dev, events, l); - cn_release(ctp); - return error; + return cdev_poll(dev, events, l); } /*ARGSUSED*/ int cnkqfilter(dev_t dev, struct knote *kn) { - struct tty *ctp = NULL; int error; /* @@ -306,11 +281,9 @@ cnkqfilter(dev_t dev, struct knote *kn) * I don't want to think of the possible side effects * of console redirection here. */ - if (!cn_redirect(&dev, 0, &error, &ctp)) + if (!cn_redirect(&dev, 0, &error)) return error; - error = cdev_kqfilter(dev, kn); - cn_release(ctp); - return error; + return cdev_kqfilter(dev, kn); } int @@ -456,46 +429,28 @@ cnhalt(void) /* * Redirect output, if that's appropriate. If there's no real console, * return ENXIO. + * + * Call with tty_mutex held. */ static bool -cn_redirect(dev_t *devp, int is_read, int *error, struct tty **ctpp) +cn_redirect(dev_t *devp, int is_read, int *error) { dev_t dev = *devp; - struct tty *ctp; - int s; - bool ok; *error = ENXIO; - *ctpp = NULL; - s = pserialize_read_enter(); - if ((ctp = atomic_load_consume(&constty)) != NULL && minor(dev) == 0 && + if (constty != NULL && minor(dev) == 0 && (cn_tab == NULL || (cn_tab->cn_pri != CN_REMOTE))) { if (is_read) { *error = 0; - ok = false; - goto out; + return false; } - tty_acquire(ctp); - *ctpp = ctp; - dev = ctp->t_dev; - } else if (cn_tab == NULL) { - ok = false; - goto out; - } else { + dev = constty->t_dev; + } else if (cn_tab == NULL) + return false; + else dev = cn_tab->cn_dev; - } *devp = dev; -out: pserialize_read_exit(s); - return ok; -} - -static void -cn_release(struct tty *ctp) -{ - - if (ctp == NULL) - return; - tty_release(ctp); + return true; } MODULE(MODULE_CLASS_DRIVER, cons, NULL); |
