[Devel] [PATCH RHEL8 COMMIT] Revert "ve/tty: vt -- Implement per VE support for console and terminals"
Konstantin Khorenko
khorenko at virtuozzo.com
Wed Jun 9 15:16:04 MSK 2021
The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.37
------>
commit 89007a75bae83a6aa02cd69ed82d495a75abba3a
Author: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
Date: Wed Jun 9 15:16:03 2021 +0300
Revert "ve/tty: vt -- Implement per VE support for console and terminals"
The code that implements per-container tty (vtty driver) should be reverted,
because vzctl does not use it anymore and relies on the fact that vtty
driver is not present.
This reverts commit bc6c9bdf8869b5f7ea3484cee68596c8f1e2d87f.
https://jira.sw.ru/browse/PSBM-83150
Signed-off-by: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
---
drivers/tty/n_tty.c | 6 -
drivers/tty/pty.c | 543 ---------------------------------------------------
drivers/tty/tty_io.c | 28 ---
include/linux/tty.h | 1 -
include/linux/ve.h | 13 --
kernel/ve/vecalls.c | 3 -
6 files changed, 594 deletions(-)
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 2f042b65a101..3ad460219fd6 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -49,7 +49,6 @@
#include <linux/module.h>
#include <linux/ratelimit.h>
#include <linux/vmalloc.h>
-#include <linux/ve.h>
/* number of characters left in xmit buffer before select has we have room */
@@ -2323,12 +2322,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
retval = -ERESTARTSYS;
break;
}
-#ifdef CONFIG_VE
- if (tty_hung_up_p(file) ||
- (tty->link && !tty->link->count && !vtty_is_master(tty->link))) {
-#else
if (tty_hung_up_p(file) || (tty->link && !tty->link->count)) {
-#endif
retval = -EIO;
break;
}
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 75633be9e412..b0e2c4847a5d 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -949,553 +949,10 @@ static void __init unix98_pty_init(void)
static inline void unix98_pty_init(void) { }
#endif
-#if defined(CONFIG_VE)
-
-/*
- * VTTY architecture overview.
- *
- * With VTTY we make /dev/console and /dev/tty[X] virtualized
- * per container (note the real names may vary because the
- * kernel itself uses major:minor numbers to distinguish
- * devices and doesn't care how they are named inside /dev.
- * /dev/console stands for TTYAUX_MAJOR:1 while /dev/tty[X]
- * stands for TTY_MAJOR:[0:12]. That said from inside of
- * VTTY /dev/console is the same as /dev/tty0.
- *
- * For every container here is a tty map represented by
- * vtty_map_t. It carries @veid of VE and associated slave
- * tty peers.
- *
- * map
- * veid -> CTID
- * vttys -> [ 0 ]
- * `- @slave -> link -> @master
- * [ 1 ]
- * `- @slave -> link -> @master
- */
-
-#include <linux/ve.h>
-#include <linux/file.h>
-#include <linux/anon_inodes.h>
-
-static struct tty_driver *vttym_driver;
-static struct tty_driver *vttys_driver;
-static DEFINE_IDR(vtty_idr);
-
-static struct file_operations vtty_fops;
-
-#define vtty_match_index(idx) ((idx) >= 0 && (idx) < MAX_NR_VTTY_CONSOLES)
-
-bool vtty_is_master(struct tty_struct *tty)
-{
- return tty->driver == vttym_driver;
-}
-
-typedef struct {
- envid_t veid;
- struct tty_struct *vttys[MAX_NR_VTTY_CONSOLES];
-} vtty_map_t;
-
-static vtty_map_t *vtty_map_lookup(envid_t veid)
-{
- lockdep_assert_held(&tty_mutex);
- return idr_find(&vtty_idr, veid);
-}
-
-static void vtty_map_set(vtty_map_t *map, struct tty_struct *tty)
-{
- lockdep_assert_held(&tty_mutex);
- WARN_ON(map->vttys[tty->index]);
-
- tty->driver_data = tty->link->driver_data = map;
- map->vttys[tty->index] = tty;
-}
-
-static void vtty_map_free(vtty_map_t *map)
-{
- lockdep_assert_held(&tty_mutex);
- idr_remove(&vtty_idr, map->veid);
- kfree(map);
-}
-
-static void vtty_map_clear(struct tty_struct *tty)
-{
- vtty_map_t *map = tty->driver_data;
-
- lockdep_assert_held(&tty_mutex);
- if (map) {
- struct tty_struct *p = map->vttys[tty->index];
- int i;
-
- WARN_ON(p != (tty->driver == vttys_driver ? tty : tty->link));
- map->vttys[tty->index] = NULL;
- tty->driver_data = tty->link->driver_data = NULL;
-
- for (i = 0; i < MAX_NR_VTTY_CONSOLES; i++) {
- if (map->vttys[i])
- break;
- }
-
- if (i >= MAX_NR_VTTY_CONSOLES)
- vtty_map_free(map);
- }
-}
-
-static vtty_map_t *vtty_map_alloc(envid_t veid)
-{
- vtty_map_t *map = kzalloc(sizeof(*map), GFP_KERNEL);
-
- lockdep_assert_held(&tty_mutex);
- if (map) {
- map->veid = veid;
- veid = idr_alloc(&vtty_idr, map, veid, veid + 1, GFP_KERNEL);
- if (veid < 0) {
- kfree(map);
- return ERR_PTR(veid);
- }
- } else
- map = ERR_PTR(-ENOMEM);
- return map;
-}
-
-/*
- * vttys are never supposed to be opened from inside
- * of VE0 except special ioctl call, so treat zero as
- * "unused" sign.
- */
-static envid_t vtty_context_veid;
-
-static void vtty_set_context(envid_t veid)
-{
- lockdep_assert_held(&tty_mutex);
- WARN_ON(!veid);
- vtty_context_veid = veid;
-}
-
-static void vtty_drop_context(void)
-{
- lockdep_assert_held(&tty_mutex);
- vtty_context_veid = 0;
-}
-
-static envid_t vtty_get_context(void)
-{
- lockdep_assert_held(&tty_mutex);
- return vtty_context_veid ?: get_exec_env()->veid;
-}
-
-static struct tty_struct *vtty_lookup(struct tty_driver *driver,
- struct file *filp, int idx)
-{
- vtty_map_t *map = vtty_map_lookup(vtty_get_context());
- struct tty_struct *tty;
-
- if (!vtty_match_index(idx))
- return ERR_PTR(-EIO);
-
- /*
- * Nothing ever been opened yet, allocate a new
- * tty map together with both peers from the scratch
- * in install procedure.
- */
- if (!map)
- return NULL;
-
- tty = map->vttys[idx];
- if (tty) {
- if (driver == vttym_driver)
- tty = tty->link;
- WARN_ON(!tty);
- }
- return tty;
-}
-
-static void vtty_standard_install(struct tty_driver *driver,
- struct tty_struct *tty)
-{
- tty_init_termios(tty);
- tty_driver_kref_get(driver);
- tty_port_init(tty->port);
- tty->port->itty = tty;
-}
-
-static struct tty_struct *vtty_install_peer(struct tty_driver *driver,
- struct tty_port *port, int index)
-{
- struct tty_struct *tty;
-
- tty = alloc_tty_struct(driver, index);
- if (!tty)
- return ERR_PTR(-ENOMEM);
-
- tty->port = port;
- vtty_standard_install(driver, tty);
- return tty;
-}
-
-static int vtty_install(struct tty_driver *driver, struct tty_struct *tty)
-{
- envid_t veid = vtty_get_context();
- struct tty_port *peer_port;
- struct tty_struct *peer;
- vtty_map_t *map;
- int ret;
-
- WARN_ON_ONCE(driver != vttys_driver);
-
- map = vtty_map_lookup(veid);
- if (!map) {
- map = vtty_map_alloc(veid);
- if (IS_ERR(map))
- return PTR_ERR(map);
- }
-
- tty->port = kzalloc(sizeof(*tty->port), GFP_KERNEL);
- peer_port = kzalloc(sizeof(*peer_port), GFP_KERNEL);
- if (!tty->port || !peer_port) {
- ret = -ENOMEM;
- goto err_free;
- }
-
- peer = vtty_install_peer(vttym_driver, peer_port, tty->index);
- if (IS_ERR(peer)) {
- ret = PTR_ERR(peer);
- goto err_free;
- }
-
- vtty_standard_install(vttys_driver, tty);
- tty->count++;
-
- tty->link = peer;
- peer->link = tty;
-
- vtty_map_set(map, tty);
- return 0;
-
-err_free:
- kfree(tty->port);
- kfree(peer_port);
- return ret;
-}
-
-static int vtty_open(struct tty_struct *tty, struct file *filp)
-{
- set_bit(TTY_THROTTLED, &tty->flags);
- return 0;
-}
-
-static void vtty_close(struct tty_struct *tty, struct file *filp)
-{
- if (tty->count <= (tty->driver == vttys_driver) ? 2 : 1) {
- wake_up_interruptible(&tty->read_wait);
- wake_up_interruptible(&tty->write_wait);
-
- wake_up_interruptible(&tty->link->read_wait);
- wake_up_interruptible(&tty->link->write_wait);
- }
-}
-
-static void vtty_shutdown(struct tty_struct *tty)
-{
- vtty_map_clear(tty);
-}
-
-static int vtty_write(struct tty_struct *tty,
- const unsigned char *buf, int count)
-{
- struct tty_struct *peer = tty->link;
-
- if (tty->stopped)
- return 0;
-
- if (count > 0) {
- count = tty_insert_flip_string(peer->port, buf, count);
- if (count) {
- tty_flip_buffer_push(peer->port);
- tty_wakeup(tty);
- } else {
- /*
- * Flush the slave reader if noone
- * is actually hooked on. Otherwise
- * wait until reader fetch all data.
- */
- if (peer->count <
- (tty->driver == vttym_driver) ? 2 : 1)
- tty_perform_flush(peer, TCIFLUSH);
- }
- }
-
- return count;
-}
-
-static int vtty_write_room(struct tty_struct *tty)
-{
- struct tty_struct *peer = tty->link;
-
- if (tty->stopped)
- return 0;
-
- if (peer->count <
- (tty->driver == vttym_driver) ? 2 : 1)
- return 2048;
-
- tty_buffer_space_avail(peer->port);
-}
-
-static void vtty_remove(struct tty_driver *driver, struct tty_struct *tty)
-{
-}
-
-static int vtty_resize(struct tty_struct *tty, struct winsize *ws)
-{
- if (tty->driver == vttym_driver)
- return pty_resize(tty, ws);
- return tty_do_resize(tty, ws);
-}
-
-static const struct tty_operations vtty_ops = {
- .lookup = vtty_lookup,
- .install = vtty_install,
- .open = vtty_open,
- .close = vtty_close,
- .shutdown = vtty_shutdown,
- .cleanup = pty_cleanup,
- .write = vtty_write,
- .write_room = vtty_write_room,
- .chars_in_buffer= pty_chars_in_buffer,
- .set_termios = pty_set_termios,
- .unthrottle = pty_unthrottle,
- .flush_buffer = pty_flush_buffer,
- .remove = vtty_remove,
- .resize = vtty_resize,
-};
-
-struct tty_driver *vtty_console_driver(int *index)
-{
- *index = 0;
- return vttys_driver;
-}
-
-struct tty_driver *vtty_driver(dev_t dev, int *index)
-{
- if (MAJOR(dev) == TTY_MAJOR &&
- MINOR(dev) <= MAX_NR_VTTY_CONSOLES) {
- if (MINOR(dev))
- *index = MINOR(dev) - 1;
- else
- *index = 0;
- return vttys_driver;
- }
- return NULL;
-}
-
-void vtty_release_init(struct tty_struct *tty, struct tty_struct *o_tty)
-{
- int pty_master, tty_closing, o_tty_closing;
-
- if (tty->driver != vttym_driver &&
- tty->driver != vttys_driver)
- return;
-
- set_bit(TTY_VTTY_BUSY, &tty->flags);
- clear_bit(TTY_VTTY_BUSY, &tty->flags);
-
- pty_master = (tty->driver == vttym_driver);
-
- tty_closing = tty->count <= 1;
- o_tty_closing = o_tty && (o_tty->count <= (pty_master ? 1 : 0));
-
- /*
- * Do not close master while slave is active.
- */
- if (!o_tty_closing && pty_master) {
- set_bit(TTY_VTTY_BUSY, &tty->flags);
- tty->count++;
- }
-
- /*
- * Do not close master if we've closing
- * not the last slave even if there is no
- * readers on the master.
- */
- if (o_tty_closing && !tty_closing && !pty_master) {
- set_bit(TTY_VTTY_BUSY, &o_tty->flags);
- o_tty->count++;
- }
-}
-
-void vtty_release_fini(struct tty_struct *tty, struct tty_struct *o_tty)
-{
- if (test_bit(TTY_VTTY_BUSY, &tty->flags)) {
- clear_bit(TTY_VTTY_BUSY, &tty->flags);
- tty->count--;
- }
-
- if (o_tty && test_bit(TTY_VTTY_BUSY, &o_tty->flags)) {
- clear_bit(TTY_VTTY_BUSY, &o_tty->flags);
- o_tty->count--;
- }
-}
-
-static int __init vtty_init(void)
-{
-#define VTTY_DRIVER_ALLOC_FLAGS \
- (TTY_DRIVER_REAL_RAW | \
- TTY_DRIVER_RESET_TERMIOS | \
- TTY_DRIVER_DYNAMIC_DEV | \
- TTY_DRIVER_INSTALLED | \
- TTY_DRIVER_DEVPTS_MEM)
-
- vttym_driver = tty_alloc_driver(MAX_NR_VTTY_CONSOLES,
- VTTY_DRIVER_ALLOC_FLAGS);
- if (IS_ERR(vttym_driver))
- panic(pr_fmt("Can't allocate master vtty driver\n"));
-
- vttys_driver = tty_alloc_driver(MAX_NR_VTTY_CONSOLES,
- VTTY_DRIVER_ALLOC_FLAGS);
- if (IS_ERR(vttys_driver))
- panic(pr_fmt("Can't allocate slave vtty driver\n"));
-
- vttym_driver->driver_name = "vtty_master";
- vttym_driver->name = "vttym";
- vttym_driver->name_base = 0;
- vttym_driver->major = 0;
- vttym_driver->minor_start = 0;
- vttym_driver->type = TTY_DRIVER_TYPE_PTY;
- vttym_driver->subtype = PTY_TYPE_MASTER;
- vttym_driver->init_termios = tty_std_termios;
- vttym_driver->init_termios.c_iflag = 0;
- vttym_driver->init_termios.c_oflag = 0;
-
- /* 38400 boud rate, 8 bit char size, enable receiver */
- vttym_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
- vttym_driver->init_termios.c_lflag = 0;
- tty_set_operations(vttym_driver, &vtty_ops);
-
- vttys_driver->driver_name = "vtty_slave";
- vttys_driver->name = "vttys";
- vttys_driver->name_base = 0;
- vttys_driver->major = 0;
- vttys_driver->minor_start = 0;
- vttys_driver->type = TTY_DRIVER_TYPE_PTY;
- vttys_driver->subtype = PTY_TYPE_SLAVE;
- vttys_driver->init_termios = tty_std_termios;
- vttys_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
- tty_set_operations(vttys_driver, &vtty_ops);
-
- if (tty_register_driver(vttym_driver))
- panic(pr_fmt("Can't register master vtty driver\n"));
-
- if (tty_register_driver(vttys_driver))
- panic(pr_fmt("Can't register slave vtty driver\n"));
-
- tty_default_fops(&vtty_fops);
- return 0;
-}
-
-int vtty_open_master(envid_t veid, int idx)
-{
- struct tty_struct *tty;
- struct file *file;
- char devname[64];
- int fd, ret;
-
- if (!vtty_match_index(idx))
- return -EIO;
-
- fd = get_unused_fd_flags(0);
- if (fd < 0)
- return fd;
-
- snprintf(devname, sizeof(devname), "v%utty%d", veid, idx);
- file = anon_inode_getfile(devname, &vtty_fops, NULL, O_RDWR);
- if (IS_ERR(file)) {
- ret = PTR_ERR(file);
- goto err_put_unused_fd;
- }
- nonseekable_open(NULL, file);
-
- ret = tty_alloc_file(file);
- if (ret)
- goto err_fput;
-
- /*
- * Opening comes from ve0 context so
- * setup VE's context until master fetched.
- * This is done under @tty_mutex so noone
- * else would access it while we're holding
- * the lock.
- */
- mutex_lock(&tty_mutex);
- vtty_set_context(veid);
-
- tty = vtty_lookup(vttym_driver, NULL, idx);
- if (!tty ||
- (test_bit(TTY_OTHER_CLOSED, &tty->flags) ||
- test_bit(TTY_OTHER_CLOSED, &tty->link->flags))) {
- /*
- * The previous connection is about to
- * be closed so drop it from the map and
- * allocate a new one.
- */
- if (tty)
- vtty_map_clear(tty);
- tty = tty_init_dev(vttys_driver, idx);
- if (IS_ERR(tty))
- goto err_install;
- tty->count--;
- tty_unlock(tty);
- tty = tty->link;
- }
-
- /* One master at a time */
- if (tty->count >= 1) {
- ret = -EBUSY;
- goto err_install;
- }
-
- vtty_drop_context();
-
- /* FIXME: code will be dropped anyway
- * WARN_ON(!test_bit(TTY_LDISC, &tty->flags));
- */
-
- /*
- * We're the master peer so increment
- * slave counter as well.
- */
- tty_add_file(tty, file);
- tty->count++;
- tty->link->count++;
- fd_install(fd, file);
- vtty_open(tty, file);
-
- mutex_unlock(&tty_mutex);
- ret = fd;
-out:
- return ret;
-
-err_install:
- vtty_drop_context();
- mutex_unlock(&tty_mutex);
- tty_free_file(file);
-err_fput:
- file->f_op = NULL;
- fput(file);
-err_put_unused_fd:
- put_unused_fd(fd);
- goto out;
-}
-EXPORT_SYMBOL(vtty_open_master);
-#else
-static void vtty_init(void) { };
-#endif /* CONFIG_VE */
-
static int __init pty_init(void)
{
legacy_pty_init();
unix98_pty_init();
- vtty_init();
return 0;
}
device_initcall(pty_init);
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 1bd5a9d4e416..d003244ca1eb 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -106,7 +106,6 @@
#include <linux/kmod.h>
#include <linux/nsproxy.h>
-#include <linux/ve.h>
#undef TTY_DEBUG_HANGUP
#ifdef TTY_DEBUG_HANGUP
@@ -1675,8 +1674,6 @@ int tty_release(struct inode *inode, struct file *filp)
/* If tty is pty master, lock the slave pty (stable lock order) */
tty_lock_slave(o_tty);
- vtty_release_init(tty, o_tty);
-
/*
* Sanity check: if tty->count is going to zero, there shouldn't be
* any waiters on tty->read_wait or tty->write_wait. We test the
@@ -1767,7 +1764,6 @@ int tty_release(struct inode *inode, struct file *filp)
/* check whether both sides are closing ... */
final = !tty->count && !(o_tty && o_tty->count);
- vtty_release_fini(tty, o_tty);
tty_unlock_slave(o_tty);
tty_unlock(tty);
@@ -1836,19 +1832,6 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
{
struct tty_driver *driver;
-#ifdef CONFIG_VE
- struct ve_struct *ve = get_exec_env();
-
- if (!ve_is_super(ve)) {
- driver = vtty_driver(device, index);
- if (driver) {
- if (MINOR(device) == 0)
- filp->f_flags |= O_NOCTTY;
- return tty_driver_kref_get(driver);
- }
- }
-#endif
-
switch (device) {
#ifdef CONFIG_VT
case MKDEV(TTY_MAJOR, 0): {
@@ -1860,17 +1843,6 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
#endif
case MKDEV(TTYAUX_MAJOR, 1): {
struct tty_driver *console_driver = console_device(index);
- #ifdef CONFIG_VE
- if (!ve_is_super(ve)) {
- console_driver = vtty_console_driver(index);
- /*
- * Reset fops, sometimes there might be
- * console_fops picked from inode->i_cdev
- * in chrdev_open()
- */
- filp->f_op = &tty_fops;
- }
- #endif
if (console_driver) {
driver = tty_driver_kref_get(console_driver);
if (driver && filp) {
diff --git a/include/linux/tty.h b/include/linux/tty.h
index e24cc899f1ec..808fbfe86f85 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -367,7 +367,6 @@ struct tty_file_private {
#define TTY_HUPPED 18 /* Post driver->hangup() */
#define TTY_HUPPING 19 /* Hangup in progress */
#define TTY_LDISC_HALTED 22 /* Line discipline is halted */
-#define TTY_VTTY_BUSY 23 /* Mark tty as busy for VE sake */
/* Values for tty->flow_change */
#define TTY_THROTTLE_SAFE 1
diff --git a/include/linux/ve.h b/include/linux/ve.h
index 42883b4b898a..7d6837fef8c6 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -21,9 +21,6 @@ struct nsproxy;
struct veip_struct;
struct user_namespace;
struct super_block;
-struct tty_driver;
-struct tty_struct;
-struct cn_private;
struct ve_struct {
struct cgroup_subsys_state css;
@@ -165,16 +162,6 @@ void ve_exit_ns(struct pid_namespace *ns);
bool ve_check_trusted_exec(struct file *file, struct filename *name);
bool ve_check_trusted_mmap(struct file *file);
-#ifdef CONFIG_TTY
-#define MAX_NR_VTTY_CONSOLES (12)
-extern struct tty_driver *vtty_driver(dev_t dev, int *index);
-extern struct tty_driver *vtty_console_driver(int *index);
-extern int vtty_open_master(envid_t veid, int idx);
-extern void vtty_release_init(struct tty_struct *tty, struct tty_struct *o_tty);
-extern void vtty_release_fini(struct tty_struct *tty, struct tty_struct *o_tty);
-extern bool vtty_is_master(struct tty_struct *tty);
-#endif /* CONFIG_TTY */
-
static inline struct ve_struct *css_to_ve(struct cgroup_subsys_state *css)
{
return css ? container_of(css, struct ve_struct, css) : NULL;
diff --git a/kernel/ve/vecalls.c b/kernel/ve/vecalls.c
index f1cc04ee82da..dcda8c0753c8 100644
--- a/kernel/ve/vecalls.c
+++ b/kernel/ve/vecalls.c
@@ -367,9 +367,6 @@ static int ve_configure(envid_t veid, unsigned int key,
struct ve_struct *ve;
int err = -ENOKEY;
- if (key == VE_CONFIGURE_OPEN_TTY)
- return vtty_open_master(veid, val);
-
ve = get_ve_by_id(veid);
if (!ve)
return -EINVAL;
More information about the Devel
mailing list