From: Piotr Figiel <hidden> Date: 2021-02-26 13:53:12
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 <redacted>
Reviewed-by: Michal Miroslaw <redacted>
---
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(+)
----- On Feb 26, 2021, at 8:51 AM, Piotr Figiel figiel@google.com wrote:
[...]
---
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
I think what Florian was after would be:
struct ptrace_rseq_configuration {
__u32 size; /* size of struct ptrace_rseq_configuration */
__u32 flags;
__u64 rseq_abi_pointer;
__u32 signature;
__u32 pad;
};
where:
.size = sizeof(struct ptrace_rseq_configuration),
This way, the configuration structure can be expanded in the future. The
rseq ABI structure is by definition fixed-size, so there is no point in
having its size here.
Florian, did I understand your request correctly, or am I missing your point ?
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
From: Michał Mirosław <hidden> Date: 2021-02-26 16:05:50
On Fri, 26 Feb 2021 at 16:32, Mathieu Desnoyers
[off-list ref] wrote:
----- On Feb 26, 2021, at 8:51 AM, Piotr Figiel figiel@google.com wrote:
[...]
quoted
---
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
I think what Florian was after would be:
struct ptrace_rseq_configuration {
__u32 size; /* size of struct ptrace_rseq_configuration */
__u32 flags;
__u64 rseq_abi_pointer;
__u32 signature;
__u32 pad;
};
where:
.size = sizeof(struct ptrace_rseq_configuration),
This way, the configuration structure can be expanded in the future. The
rseq ABI structure is by definition fixed-size, so there is no point in
having its size here.
Florian, did I understand your request correctly, or am I missing your point ?
In this case returning sizeof(conf) would serve the same purpose, wouldn't it?
Best Regards
Michał Mirosław
[Resent because of HTML mail misfeature...]
I think what Florian was after would be:
struct ptrace_rseq_configuration {
__u32 size; /* size of struct ptrace_rseq_configuration */
__u32 flags;
__u64 rseq_abi_pointer;
__u32 signature;
__u32 pad;
};
where:
.size = sizeof(struct ptrace_rseq_configuration),
This way, the configuration structure can be expanded in the future. The
rseq ABI structure is by definition fixed-size, so there is no point in
having its size here.
Still rseq syscall accepts the rseq ABI structure size as a paremeter.
I think this way the information returned from ptrace is consistent with
the userspace view of the rseq state and allows expansion in case the
ABI structure would have to be extended (in spite of it's current
definition).
The configuration structure still can be expanded as its size is
reported to userspace as return value from the request (in line with
Dmitry's comments).
Best regards, Piotr.
----- On Feb 26, 2021, at 11:04 AM, emmir emmir@google.com wrote:
On Fri, 26 Feb 2021 at 16:32, Mathieu Desnoyers
[off-list ref] wrote:
quoted
----- On Feb 26, 2021, at 8:51 AM, Piotr Figiel figiel@google.com wrote:
[...]
quoted
---
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
I think what Florian was after would be:
struct ptrace_rseq_configuration {
__u32 size; /* size of struct ptrace_rseq_configuration */
__u32 flags;
__u64 rseq_abi_pointer;
__u32 signature;
__u32 pad;
};
where:
.size = sizeof(struct ptrace_rseq_configuration),
This way, the configuration structure can be expanded in the future. The
rseq ABI structure is by definition fixed-size, so there is no point in
having its size here.
Florian, did I understand your request correctly, or am I missing your point ?
In this case returning sizeof(conf) would serve the same purpose, wouldn't it?
If the size is received as input from user-space as well, this can be used to
make sure the kernel detects what size is expected by user-space and act accordingly.
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
I think what Florian was after would be:
struct ptrace_rseq_configuration {
__u32 size; /* size of struct ptrace_rseq_configuration */
__u32 flags;
__u64 rseq_abi_pointer;
__u32 signature;
__u32 pad;
};
where:
.size = sizeof(struct ptrace_rseq_configuration),
This way, the configuration structure can be expanded in the future. The
rseq ABI structure is by definition fixed-size, so there is no point in
having its size here.
Still rseq syscall accepts the rseq ABI structure size as a paremeter.
I think this way the information returned from ptrace is consistent with
the userspace view of the rseq state and allows expansion in case the
ABI structure would have to be extended (in spite of it's current
definition).
The configuration structure still can be expanded as its size is
reported to userspace as return value from the request (in line with
Dmitry's comments).
Fair enough. And now with the reply from Florian I see that I misunderstood his
point.
Thanks,
Mathieu
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:
quoted hunk
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 <redacted>
Reviewed-by: Michal Miroslaw <redacted>
---
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(+)
----- On Feb 26, 2021, at 8:51 AM, Piotr Figiel figiel@google.com 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 <redacted>
Reviewed-by: Michal Miroslaw <redacted>
---
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(+)
From: Peter Zijlstra <peterz@infradead.org> Date: 2021-03-11 16:53:03
On Thu, Mar 11, 2021 at 09:51:56AM -0500, Mathieu Desnoyers wrote:
----- On Feb 26, 2021, at 8:51 AM, Piotr Figiel figiel@google.com wrote:
quoted
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 <redacted>
Reviewed-by: Michal Miroslaw <redacted>
----- On Mar 11, 2021, at 11:51 AM, Peter Zijlstra peterz@infradead.org wrote:
On Thu, Mar 11, 2021 at 09:51:56AM -0500, Mathieu Desnoyers wrote:
quoted
----- On Feb 26, 2021, at 8:51 AM, Piotr Figiel figiel@google.com wrote:
quoted
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 <redacted>
Reviewed-by: Michal Miroslaw <redacted>