2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 13:58:34 +00:00

tty: Move tty layer shared init into tty_init_restore

Instead of using tty_mutex value in atomic context
(which is wrong, since it is not atomic) better move
tty_mutex allocation into cr_restore_tasks where our
all initializers live. Otherwise weird race effect
might be observed.

Reported-by: Deng Guangxing <dengguangxing@huawei.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov 2019-06-25 15:16:26 +03:00 committed by Andrei Vagin
parent b30b0dcb14
commit 13b29f8e16
3 changed files with 5 additions and 14 deletions

View File

@ -2353,6 +2353,9 @@ int cr_restore_tasks(void)
if (vdso_init_restore())
goto err;
if (tty_init_restore())
goto err;
if (opts.cpu_cap & CPU_CAP_IMAGE) {
if (cpu_validate_cpuinfo())
goto err;

View File

@ -32,6 +32,7 @@ struct mount_info;
extern int devpts_restore(struct mount_info *pm);
extern int tty_prep_fds(void);
extern int tty_init_restore(void);
extern int devpts_check_bindmount(struct mount_info *m);

View File

@ -349,11 +349,8 @@ static mutex_t *tty_mutex;
static bool tty_is_master(struct tty_info *info);
static int init_tty_mutex(void)
int tty_init_restore(void)
{
if (tty_mutex)
return 0;
tty_mutex = shmalloc(sizeof(*tty_mutex));
if (!tty_mutex) {
pr_err("Can't create ptmx index mutex\n");
@ -600,9 +597,6 @@ static int __pty_open_ptmx_index(int index, int flags,
memset(fds, 0xff, sizeof(fds));
if (init_tty_mutex())
return -1;
mutex_lock(tty_mutex);
for (i = 0; i < ARRAY_SIZE(fds); i++) {
@ -1792,13 +1786,6 @@ static int tty_info_setup(struct tty_info *info)
add_post_prepare_cb_once(&prep_tty_restore);
/*
* Call it explicitly. Post-callbacks will be called after
* namespaces preparation, while the latter needs this mutex.
*/
if (init_tty_mutex())
return -1;
info->fdstore_id = -1;
return file_desc_add(&info->d, info->tfe->id, &tty_desc_ops);
}