From: Oleg Nesterov <oleg@redhat.com>
To: Piotr Figiel <figiel@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
mathieu.desnoyers@efficios.com, peterz@infradead.org,
paulmck@kernel.org, boqun.feng@gmail.com, ldv@altlinux.org,
fweimer@redhat.com, Alexey Dobriyan <adobriyan@gmail.com>,
Andrei Vagin <avagin@gmail.com>,
linux-kernel@vger.kernel.org, posk@google.com,
kyurtsever@google.com, ckennelly@google.com, pjt@google.com,
emmir@google.com, linux-man@vger.kernel.org,
linux-api@vger.kernel.org
Subject: Re: [PATCH v2] ptrace: add PTRACE_GET_RSEQ_CONFIGURATION request
Date: Wed, 10 Mar 2021 19:50:02 +0100 [thread overview]
Message-ID: <20210310185001.GD8973@redhat.com> (raw)
In-Reply-To: <20210226135156.1081606-1-figiel@google.com>
I don't think I can review this patch, I don't understand the problem space
well enough. But just in case, I see nothing wrong in this simple patch.
Feel free to add
Acked-by: Oleg Nesterov <oleg@redhat.com>
On 02/26, Piotr Figiel wrote:
>
> For userspace checkpoint and restore (C/R) a way of getting process state
> containing RSEQ configuration is needed.
>
> There are two ways this information is going to be used:
> - to re-enable RSEQ for threads which had it enabled before C/R
> - to detect if a thread was in a critical section during C/R
>
> Since C/R preserves TLS memory and addresses RSEQ ABI will be restored
> using the address registered before C/R.
>
> Detection whether the thread is in a critical section during C/R is needed
> to enforce behavior of RSEQ abort during C/R. Attaching with ptrace()
> before registers are dumped itself doesn't cause RSEQ abort.
> Restoring the instruction pointer within the critical section is
> problematic because rseq_cs may get cleared before the control is passed
> to the migrated application code leading to RSEQ invariants not being
> preserved. C/R code will use RSEQ ABI address to find the abort handler
> to which the instruction pointer needs to be set.
>
> To achieve above goals expose the RSEQ ABI address and the signature value
> with the new ptrace request PTRACE_GET_RSEQ_CONFIGURATION.
>
> This new ptrace request can also be used by debuggers so they are aware
> of stops within restartable sequences in progress.
>
> Signed-off-by: Piotr Figiel <figiel@google.com>
> Reviewed-by: Michal Miroslaw <emmir@google.com>
>
> ---
> v2:
> Applied review comments:
> - changed return value from the ptrace request to the size of the
> configuration structure
> - expanded configuration structure with the flags field and
> the rseq abi structure size
>
> v1:
> https://lore.kernel.org/lkml/20210222100443.4155938-1-figiel@google.com/
>
> ---
> include/uapi/linux/ptrace.h | 10 ++++++++++
> kernel/ptrace.c | 25 +++++++++++++++++++++++++
> 2 files changed, 35 insertions(+)
>
> diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h
> index 83ee45fa634b..3747bf816f9a 100644
> --- a/include/uapi/linux/ptrace.h
> +++ b/include/uapi/linux/ptrace.h
> @@ -102,6 +102,16 @@ struct ptrace_syscall_info {
> };
> };
>
> +#define PTRACE_GET_RSEQ_CONFIGURATION 0x420f
> +
> +struct ptrace_rseq_configuration {
> + __u64 rseq_abi_pointer;
> + __u32 rseq_abi_size;
> + __u32 signature;
> + __u32 flags;
> + __u32 pad;
> +};
> +
> /*
> * These values are stored in task->ptrace_message
> * by tracehook_report_syscall_* to describe the current syscall-stop.
> diff --git a/kernel/ptrace.c b/kernel/ptrace.c
> index 61db50f7ca86..76f09456ec4b 100644
> --- a/kernel/ptrace.c
> +++ b/kernel/ptrace.c
> @@ -31,6 +31,7 @@
> #include <linux/cn_proc.h>
> #include <linux/compat.h>
> #include <linux/sched/signal.h>
> +#include <linux/minmax.h>
>
> #include <asm/syscall.h> /* for syscall_get_* */
>
> @@ -779,6 +780,24 @@ static int ptrace_peek_siginfo(struct task_struct *child,
> return ret;
> }
>
> +#ifdef CONFIG_RSEQ
> +static long ptrace_get_rseq_configuration(struct task_struct *task,
> + unsigned long size, void __user *data)
> +{
> + struct ptrace_rseq_configuration conf = {
> + .rseq_abi_pointer = (u64)(uintptr_t)task->rseq,
> + .rseq_abi_size = sizeof(*task->rseq),
> + .signature = task->rseq_sig,
> + .flags = 0,
> + };
> +
> + size = min_t(unsigned long, size, sizeof(conf));
> + if (copy_to_user(data, &conf, size))
> + return -EFAULT;
> + return sizeof(conf);
> +}
> +#endif
> +
> #ifdef PTRACE_SINGLESTEP
> #define is_singlestep(request) ((request) == PTRACE_SINGLESTEP)
> #else
> @@ -1222,6 +1241,12 @@ int ptrace_request(struct task_struct *child, long request,
> ret = seccomp_get_metadata(child, addr, datavp);
> break;
>
> +#ifdef CONFIG_RSEQ
> + case PTRACE_GET_RSEQ_CONFIGURATION:
> + ret = ptrace_get_rseq_configuration(child, addr, datavp);
> + break;
> +#endif
> +
> default:
> break;
> }
> --
> 2.30.1.766.gb4fecdf3b7-goog
>
next prev parent reply other threads:[~2021-03-10 18:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-26 13:51 [PATCH v2] ptrace: add PTRACE_GET_RSEQ_CONFIGURATION request Piotr Figiel
2021-02-26 15:32 ` Mathieu Desnoyers
2021-02-26 16:04 ` Michał Mirosław
2021-02-26 16:41 ` Mathieu Desnoyers
2021-02-26 16:06 ` Piotr Figiel
2021-03-03 18:55 ` Mathieu Desnoyers
2021-03-03 17:10 ` Florian Weimer
2021-03-10 18:50 ` Oleg Nesterov [this message]
2021-03-11 14:51 ` Mathieu Desnoyers
2021-03-11 16:51 ` Peter Zijlstra
2021-03-11 17:24 ` Mathieu Desnoyers
2021-03-17 13:13 ` [tip: sched/core] rseq, ptrace: Add " tip-bot2 for Piotr Figiel
2021-03-17 15:19 ` tip-bot2 for Piotr Figiel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210310185001.GD8973@redhat.com \
--to=oleg@redhat.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=avagin@gmail.com \
--cc=boqun.feng@gmail.com \
--cc=ckennelly@google.com \
--cc=emmir@google.com \
--cc=figiel@google.com \
--cc=fweimer@redhat.com \
--cc=kyurtsever@google.com \
--cc=ldv@altlinux.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-man@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=pjt@google.com \
--cc=posk@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.