[CRIU] [PATCH 1/2] criu: Dump and restore pdeath_sig value

Serge Hallyn serge.hallyn at ubuntu.com
Fri Jun 27 10:06:56 PDT 2014


Quoting Pavel Emelyanov (xemul at parallels.com):
> The implementation is pretty straightforward. When dumping per-thread
> misc data with parasite, collect one, then write in thread_core_info.
> 
> On restore wait for creds restore and put the value back (some creds
> changes drop it to zero).
> 
> Signed-off-by: Pavel Emelyanov <xemul at parallels.com>

Thanks - simple containers actually probably won't need this (because
the deathsig is used between the lxc monitor and init, not inside the
container) but eventually for nested containers it will.

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  cr-dump.c           |  4 ++++
>  cr-restore.c        |  5 +++++
>  include/parasite.h  |  1 +
>  include/restorer.h  |  1 +
>  pie/parasite.c      | 14 ++++++++++++--
>  pie/restorer.c      | 20 ++++++++++++++++++++
>  protobuf/core.proto |  1 +
>  7 files changed, 44 insertions(+), 2 deletions(-)
> 
> diff --git a/cr-dump.c b/cr-dump.c
> index c4c9777..45f1f5f 100644
> --- a/cr-dump.c
> +++ b/cr-dump.c
> @@ -689,6 +689,10 @@ int dump_thread_core(int pid, CoreEntry *core, const struct parasite_dump_thread
>  		CORE_THREAD_ARCH_INFO(core)->clear_tid_addr = encode_pointer(ti->tid_addr);
>  		BUG_ON(!tc->sas);
>  		copy_sas(tc->sas, &ti->sas);
> +		if (ti->pdeath_sig) {
> +			tc->has_pdeath_sig = true;
> +			tc->pdeath_sig = ti->pdeath_sig;
> +		}
>  	}
>  
>  	return ret;
> diff --git a/cr-restore.c b/cr-restore.c
> index 573b989..270d1d1 100644
> --- a/cr-restore.c
> +++ b/cr-restore.c
> @@ -2557,6 +2557,11 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
>  			thread_args[i].has_futex	= true;
>  			thread_args[i].futex_rla	= tcore->thread_core->futex_rla;
>  			thread_args[i].futex_rla_len	= tcore->thread_core->futex_rla_len;
> +			thread_args[i].pdeath_sig	= tcore->thread_core->pdeath_sig;
> +			if (tcore->thread_core->pdeath_sig > _KNSIG) {
> +				pr_err("Pdeath signal is too big\n");
> +				goto err;
> +			}
>  
>  			ret = prep_sched_info(&thread_args[i].sp, tcore->thread_core);
>  			if (ret)
> diff --git a/include/parasite.h b/include/parasite.h
> index ddfe975..eaabc01 100644
> --- a/include/parasite.h
> +++ b/include/parasite.h
> @@ -141,6 +141,7 @@ struct parasite_dump_thread {
>  	pid_t			tid;
>  	tls_t			tls;
>  	stack_t			sas;
> +	int			pdeath_sig;
>  };
>  
>  /*
> diff --git a/include/restorer.h b/include/restorer.h
> index bdb2adc..842cc32 100644
> --- a/include/restorer.h
> +++ b/include/restorer.h
> @@ -90,6 +90,7 @@ struct thread_restore_args {
>  
>  	siginfo_t			*siginfo;
>  	unsigned int			siginfo_nr;
> +	int				pdeath_sig;
>  } __aligned(64);
>  
>  struct task_restore_args {
> diff --git a/pie/parasite.c b/pie/parasite.c
> index be46bfc..92e7708 100644
> --- a/pie/parasite.c
> +++ b/pie/parasite.c
> @@ -35,6 +35,10 @@ static struct parasite_dump_pages_args *mprotect_args = NULL;
>  #define SPLICE_F_GIFT	0x08
>  #endif
>  
> +#ifndef PR_GET_PDEATHSIG
> +#define PR_GET_PDEATHSIG  2
> +#endif
> +
>  static int mprotect_vmas(struct parasite_dump_pages_args *args)
>  {
>  	struct parasite_vma_entry *vmas, *vma;
> @@ -145,9 +149,15 @@ static int dump_thread_common(struct parasite_dump_thread *ti)
>  
>  	arch_get_tls(&ti->tls);
>  	ret = sys_prctl(PR_GET_TID_ADDRESS, (unsigned long) &ti->tid_addr, 0, 0, 0);
> -	if (ret == 0)
> -		ret = sys_sigaltstack(NULL, &ti->sas);
> +	if (ret)
> +		goto out;
>  
> +	ret = sys_sigaltstack(NULL, &ti->sas);
> +	if (ret)
> +		goto out;
> +
> +	ret = sys_prctl(PR_GET_PDEATHSIG, (unsigned long)&ti->pdeath_sig, 0, 0, 0);
> +out:
>  	return ret;
>  }
>  
> diff --git a/pie/restorer.c b/pie/restorer.c
> index 27e6929..1ba14e7 100644
> --- a/pie/restorer.c
> +++ b/pie/restorer.c
> @@ -35,6 +35,10 @@
>  
>  #include "asm/restorer.h"
>  
> +#ifndef PR_SET_PDEATHSIG
> +#define PR_SET_PDEATHSIG 1
> +#endif
> +
>  #define sys_prctl_safe(opcode, val1, val2, val3)			\
>  	({								\
>  		long __ret = sys_prctl(opcode, val1, val2, val3, 0);	\
> @@ -189,6 +193,20 @@ static int restore_creds(CredsEntry *ce)
>  	return 0;
>  }
>  
> +/*
> + * This should be done after creds restore, as
> + * some creds changes might drop the value back
> + * to zero.
> + */
> +
> +static inline int restore_pdeath_sig(struct thread_restore_args *ta)
> +{
> +	if (ta->pdeath_sig)
> +		return sys_prctl(PR_SET_PDEATHSIG, ta->pdeath_sig, 0, 0, 0);
> +	else
> +		return 0;
> +}
> +
>  static int restore_dumpable_flag(MmEntry *mme)
>  {
>  	int current_dumpable;
> @@ -349,6 +367,7 @@ long __export_restore_thread(struct thread_restore_args *args)
>  		goto core_restore_end;
>  
>  	restore_finish_stage(CR_STATE_RESTORE_SIGCHLD);
> +	restore_pdeath_sig(args);
>  	restore_finish_stage(CR_STATE_RESTORE_CREDS);
>  	futex_dec_and_wake(&thread_inprogress);
>  
> @@ -1004,6 +1023,7 @@ long __export_restore_task(struct task_restore_args *args)
>  
>  	ret = restore_creds(&args->creds);
>  	ret = ret || restore_dumpable_flag(&args->mm);
> +	ret = ret || restore_pdeath_sig(args->t);
>  
>  	futex_set_and_wake(&thread_inprogress, args->nr_threads);
>  
> diff --git a/protobuf/core.proto b/protobuf/core.proto
> index 21218ec..d850e2e 100644
> --- a/protobuf/core.proto
> +++ b/protobuf/core.proto
> @@ -48,6 +48,7 @@ message thread_core_entry {
>  	optional uint32			sched_prio	= 5;
>  	optional uint64			blk_sigset	= 6;
>  	optional thread_sas_entry	sas		= 7;
> +	optional uint32			pdeath_sig	= 8;
>  }
>  
>  message task_rlimits_entry {
> -- 
> 1.8.4.2
> 
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list