Date: Wed, 15 May 2019 17:58:09 +0000 (UTC) From: Ian Lepore <ian@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r347627 - stable/11/sys/dev/dcons Message-ID: <201905151758.x4FHw9Rl053148@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ian Date: Wed May 15 17:58:08 2019 New Revision: 347627 URL: https://svnweb.freebsd.org/changeset/base/347627 Log: MFC r347422: Allow dcons(4) to be unloaded when loaded as a module. When the module is unloaded, the tty devices are destroyed. That requires implementing the tsw_free callback to avoid a panic. This driver requires no particular cleanup to be done from the callback, but the module itself must remain in memory until the deferred tsw_free callbacks are invoked. These changes implement that by incrementing a reference count variable in the detach routine, and decrementing it in the tsw_free callback. The MOD_UNLOAD event handler doesn't return until the count drops to zero. PR: 237758 Modified: stable/11/sys/dev/dcons/dcons_os.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/dcons/dcons_os.c ============================================================================== --- stable/11/sys/dev/dcons/dcons_os.c Wed May 15 17:57:06 2019 (r347626) +++ stable/11/sys/dev/dcons/dcons_os.c Wed May 15 17:58:08 2019 (r347627) @@ -50,6 +50,7 @@ #include <sys/proc.h> #include <sys/ucred.h> +#include <machine/atomic.h> #include <machine/bus.h> #include <dev/dcons/dcons.h> @@ -133,12 +134,16 @@ extern struct gdb_dbgport *gdb_cur; #endif static tsw_outwakeup_t dcons_outwakeup; +static tsw_free_t dcons_free; static struct ttydevsw dcons_ttydevsw = { .tsw_flags = TF_NOPREFIX, .tsw_outwakeup = dcons_outwakeup, + .tsw_free = dcons_free, }; +static int dcons_close_refs; + #if (defined(GDB) || defined(DDB)) static int dcons_check_break(struct dcons_softc *dc, int c) @@ -196,6 +201,14 @@ dcons_os_putc(struct dcons_softc *dc, int c) } static void +dcons_free(void *xsc __unused) +{ + + /* Our deferred free has arrived, now we're waiting for one fewer. */ + atomic_subtract_rel_int(&dcons_close_refs, 1); +} + +static void dcons_outwakeup(struct tty *tp) { struct dcons_softc *dc; @@ -389,6 +402,8 @@ dcons_detach(int port) dc = &sc[port]; tp = dc->tty; + /* tty_rel_gone() schedules a deferred free callback, count it. */ + atomic_add_int(&dcons_close_refs, 1); tty_lock(tp); tty_rel_gone(tp); @@ -423,6 +438,9 @@ dcons_modevent(module_t mode, int type, void *data) contigfree(dg.buf, DCONS_BUF_SIZE, M_DEVBUF); } + /* Wait for tty deferred free callbacks to complete. */ + while (atomic_load_acq_int(&dcons_close_refs) > 0) + pause_sbt("dcunld", mstosbt(50), mstosbt(10), 0); break; case MOD_SHUTDOWN: #if 0 /* Keep connection after halt */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201905151758.x4FHw9Rl053148>