2019-06-13 16:39:01

by Anisse Astier

[permalink] [raw]
Subject: [PATCH] arm64/sve: <uapi/asm/ptrace.h> should not depend on <uapi/linux/prctl.h>

Otherwise this will create userspace build issues for any program
(strace, qemu) that includes both <sys/prctl.h> (with musl libc) and
<linux/ptrace.h> (which then includes <asm/ptrace.h>), like this:

error: redefinition of 'struct prctl_mm_map'
struct prctl_mm_map {

See https://github.com/foundriesio/meta-lmp/commit/6d4a106e191b5d79c41b9ac78fd321316d3013c0
for a public example of people working around this issue.

This fixes an UAPI regression introduced in commit 43d4da2c45b2
("arm64/sve: ptrace and ELF coredump support").

Cc: [email protected]
Signed-off-by: Anisse Astier <[email protected]>
---
arch/arm64/include/uapi/asm/ptrace.h | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h
index d78623acb649..03b6d6f029fc 100644
--- a/arch/arm64/include/uapi/asm/ptrace.h
+++ b/arch/arm64/include/uapi/asm/ptrace.h
@@ -65,8 +65,6 @@

#ifndef __ASSEMBLY__

-#include <linux/prctl.h>
-
/*
* User structures for general purpose, floating point and debug registers.
*/
@@ -113,10 +111,10 @@ struct user_sve_header {

/*
* Common SVE_PT_* flags:
- * These must be kept in sync with prctl interface in <linux/ptrace.h>
+ * These must be kept in sync with prctl interface in <linux/prctl.h>
*/
-#define SVE_PT_VL_INHERIT (PR_SVE_VL_INHERIT >> 16)
-#define SVE_PT_VL_ONEXEC (PR_SVE_SET_VL_ONEXEC >> 16)
+#define SVE_PT_VL_INHERIT (1 << 1) /* PR_SVE_VL_INHERIT */
+#define SVE_PT_VL_ONEXEC (1 << 2) /* PR_SVE_SET_VL_ONEXEC */


/*
--
2.19.1


2019-06-13 17:16:47

by Dave Martin

[permalink] [raw]
Subject: Re: [PATCH] arm64/sve: <uapi/asm/ptrace.h> should not depend on <uapi/linux/prctl.h>

On Thu, Jun 13, 2019 at 06:38:01PM +0200, Anisse Astier wrote:
> Otherwise this will create userspace build issues for any program
> (strace, qemu) that includes both <sys/prctl.h> (with musl libc) and
> <linux/ptrace.h> (which then includes <asm/ptrace.h>), like this:
>
> error: redefinition of 'struct prctl_mm_map'
> struct prctl_mm_map {
>
> See https://github.com/foundriesio/meta-lmp/commit/6d4a106e191b5d79c41b9ac78fd321316d3013c0
> for a public example of people working around this issue.
>
> This fixes an UAPI regression introduced in commit 43d4da2c45b2
> ("arm64/sve: ptrace and ELF coredump support").
>
> Cc: [email protected]

Consider adding a Fixes: tag.

> Signed-off-by: Anisse Astier <[email protected]>
> ---
> arch/arm64/include/uapi/asm/ptrace.h | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h
> index d78623acb649..03b6d6f029fc 100644
> --- a/arch/arm64/include/uapi/asm/ptrace.h
> +++ b/arch/arm64/include/uapi/asm/ptrace.h
> @@ -65,8 +65,6 @@
>
> #ifndef __ASSEMBLY__
>
> -#include <linux/prctl.h>
> -
> /*
> * User structures for general purpose, floating point and debug registers.
> */
> @@ -113,10 +111,10 @@ struct user_sve_header {
>
> /*
> * Common SVE_PT_* flags:
> - * These must be kept in sync with prctl interface in <linux/ptrace.h>
> + * These must be kept in sync with prctl interface in <linux/prctl.h>

Ack

> */
> -#define SVE_PT_VL_INHERIT (PR_SVE_VL_INHERIT >> 16)
> -#define SVE_PT_VL_ONEXEC (PR_SVE_SET_VL_ONEXEC >> 16)
> +#define SVE_PT_VL_INHERIT (1 << 1) /* PR_SVE_VL_INHERIT */
> +#define SVE_PT_VL_ONEXEC (1 << 2) /* PR_SVE_SET_VL_ONEXEC */

Makes sense, but...

Since sve_context.h was already introduced to solve a closely related
problem, I wonder whether we can provide shadow definitions there,
similarly to way the arm64/include/uapi/asm/ptrace.h definitions are
derived. Although it's a slight abuse of that header, I think that
would be my preferred approach.

Otherwise, at least make the required relationship between ptrace.h and
prctl.h constants a bit more obvious, say,

#define SVE_PT_VL_INHERIT ((1 << 17) /* PR_SVE_SET_VL_INHERIT */ >> 16)

etc.

Cheers
---Dave

2019-06-14 10:25:59

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH] arm64/sve: <uapi/asm/ptrace.h> should not depend on <uapi/linux/prctl.h>

On Thu, Jun 13, 2019 at 06:14:44PM +0100, Dave Martin wrote:
> On Thu, Jun 13, 2019 at 06:38:01PM +0200, Anisse Astier wrote:
> > */
> > -#define SVE_PT_VL_INHERIT (PR_SVE_VL_INHERIT >> 16)
> > -#define SVE_PT_VL_ONEXEC (PR_SVE_SET_VL_ONEXEC >> 16)
> > +#define SVE_PT_VL_INHERIT (1 << 1) /* PR_SVE_VL_INHERIT */
> > +#define SVE_PT_VL_ONEXEC (1 << 2) /* PR_SVE_SET_VL_ONEXEC */
>
> Makes sense, but...
>
> Since sve_context.h was already introduced to solve a closely related
> problem, I wonder whether we can provide shadow definitions there,
> similarly to way the arm64/include/uapi/asm/ptrace.h definitions are
> derived. Although it's a slight abuse of that header, I think that
> would be my preferred approach.

Yes, that sounds better to me as well. Please send a v2!

Will

2019-06-14 11:23:51

by Anisse Astier

[permalink] [raw]
Subject: Re: [PATCH] arm64/sve: <uapi/asm/ptrace.h> should not depend on <uapi/linux/prctl.h>

Hi Dave,

Thanks for taking the time to review this patch,

On Thu, Jun 13, 2019 at 06:14:44PM +0100, Dave Martin wrote:
> On Thu, Jun 13, 2019 at 06:38:01PM +0200, Anisse Astier wrote:
> > Otherwise this will create userspace build issues for any program
> > (strace, qemu) that includes both <sys/prctl.h> (with musl libc) and
> > <linux/ptrace.h> (which then includes <asm/ptrace.h>), like this:
> >
> > error: redefinition of 'struct prctl_mm_map'
> > struct prctl_mm_map {
> >
> > See https://github.com/foundriesio/meta-lmp/commit/6d4a106e191b5d79c41b9ac78fd321316d3013c0
> > for a public example of people working around this issue.
> >
> > This fixes an UAPI regression introduced in commit 43d4da2c45b2
> > ("arm64/sve: ptrace and ELF coredump support").
> >
> > Cc: [email protected]
>
> Consider adding a Fixes: tag.

Will do in v2.

>
> > Signed-off-by: Anisse Astier <[email protected]>
> > ---
> > arch/arm64/include/uapi/asm/ptrace.h | 8 +++-----
> > 1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h
> > index d78623acb649..03b6d6f029fc 100644
> > --- a/arch/arm64/include/uapi/asm/ptrace.h
> > +++ b/arch/arm64/include/uapi/asm/ptrace.h
> > @@ -65,8 +65,6 @@
> >
> > #ifndef __ASSEMBLY__
> >
> > -#include <linux/prctl.h>
> > -
> > /*
> > * User structures for general purpose, floating point and debug registers.
> > */
> > @@ -113,10 +111,10 @@ struct user_sve_header {
> >
> > /*
> > * Common SVE_PT_* flags:
> > - * These must be kept in sync with prctl interface in <linux/ptrace.h>
> > + * These must be kept in sync with prctl interface in <linux/prctl.h>
>
> Ack
>
> > */
> > -#define SVE_PT_VL_INHERIT (PR_SVE_VL_INHERIT >> 16)
> > -#define SVE_PT_VL_ONEXEC (PR_SVE_SET_VL_ONEXEC >> 16)
> > +#define SVE_PT_VL_INHERIT (1 << 1) /* PR_SVE_VL_INHERIT */
> > +#define SVE_PT_VL_ONEXEC (1 << 2) /* PR_SVE_SET_VL_ONEXEC */
>
> Makes sense, but...
>
> Since sve_context.h was already introduced to solve a closely related
> problem, I wonder whether we can provide shadow definitions there,
> similarly to way the arm64/include/uapi/asm/ptrace.h definitions are
> derived. Although it's a slight abuse of that header, I think that
> would be my preferred approach.


Yes I saw this, and I considered doing something similar. But, those
defines are in uapi/linux/prctl.h, which does not include any asm/*.h
header. This would have then required adding a full infrastructure for
asm/prctl.h (that could then include sve_context.h for example), which
does not exist yet, instead of copying these two values.

Since this is part of the kernel-userspace ABI, I don't see this values
changing anytime soon, which is why I thought copying them shouldn't be
a big issue.

A simple solution would be to to include sve_context.h or a third
header, maybe linux/prctl_arm64_sve.h (with only these two/five
defines), in linux/prctl.h, and reuse it in uapi/asm/ptrace.h; but this
would break the self-contained nature of linux/prctl.h.

>
> Otherwise, at least make the required relationship between ptrace.h and
> prctl.h constants a bit more obvious, say,
>
> #define SVE_PT_VL_INHERIT ((1 << 17) /* PR_SVE_SET_VL_INHERIT */ >> 16)

This one is much simpler and closer to what I had in mind with this
patch.

Will, what do you think of this second approach Dave proposed ?

Regards,

Anisse

2019-06-14 14:24:54

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH] arm64/sve: <uapi/asm/ptrace.h> should not depend on <uapi/linux/prctl.h>

Hi Anisse, Dave,

On Fri, Jun 14, 2019 at 01:22:22PM +0200, Anisse Astier wrote:
> On Thu, Jun 13, 2019 at 06:14:44PM +0100, Dave Martin wrote:
> > On Thu, Jun 13, 2019 at 06:38:01PM +0200, Anisse Astier wrote:
> > > -#define SVE_PT_VL_INHERIT (PR_SVE_VL_INHERIT >> 16)
> > > -#define SVE_PT_VL_ONEXEC (PR_SVE_SET_VL_ONEXEC >> 16)
> > > +#define SVE_PT_VL_INHERIT (1 << 1) /* PR_SVE_VL_INHERIT */
> > > +#define SVE_PT_VL_ONEXEC (1 << 2) /* PR_SVE_SET_VL_ONEXEC */
> >
> > Makes sense, but...
> >
> > Since sve_context.h was already introduced to solve a closely related
> > problem, I wonder whether we can provide shadow definitions there,
> > similarly to way the arm64/include/uapi/asm/ptrace.h definitions are
> > derived. Although it's a slight abuse of that header, I think that
> > would be my preferred approach.
>
> Yes I saw this, and I considered doing something similar. But, those
> defines are in uapi/linux/prctl.h, which does not include any asm/*.h
> header. This would have then required adding a full infrastructure for
> asm/prctl.h (that could then include sve_context.h for example), which
> does not exist yet, instead of copying these two values.

x86 appears to have an asm/prctl.h implementation, but it's not included
by anybody so I guess that doesn't really help us here.

> Since this is part of the kernel-userspace ABI, I don't see this values
> changing anytime soon, which is why I thought copying them shouldn't be
> a big issue.

Certainly not a big issue, just that the harder we make this to change
the better.

> A simple solution would be to to include sve_context.h or a third
> header, maybe linux/prctl_arm64_sve.h (with only these two/five
> defines), in linux/prctl.h, and reuse it in uapi/asm/ptrace.h; but this
> would break the self-contained nature of linux/prctl.h.
> >
> > Otherwise, at least make the required relationship between ptrace.h and
> > prctl.h constants a bit more obvious, say,
> >
> > #define SVE_PT_VL_INHERIT ((1 << 17) /* PR_SVE_SET_VL_INHERIT */ >> 16)
>
> This one is much simpler and closer to what I had in mind with this
> patch.
>
> Will, what do you think of this second approach Dave proposed ?

Duplication is grotty, but it does the job so I'm ok with it. I don't have
any better ideas.

Thanks,

Will

2019-06-14 16:48:27

by Anisse Astier

[permalink] [raw]
Subject: [PATCH v2] arm64/sve: <uapi/asm/ptrace.h> should not depend on <uapi/linux/prctl.h>

Otherwise this will create userspace build issues for any program
(strace, qemu) that includes both <sys/prctl.h> (with musl libc) and
<linux/ptrace.h> (which then includes <asm/ptrace.h>), like this:

error: redefinition of 'struct prctl_mm_map'
struct prctl_mm_map {

See https://github.com/foundriesio/meta-lmp/commit/6d4a106e191b5d79c41b9ac78fd321316d3013c0
for a public example of people working around this issue.

Copying the defines is a bit imperfect here, but better than creating a
whole other header for just two defines that would never change, as part
of the kernel ABI.

Fixes: 43d4da2c45b2 ("arm64/sve: ptrace and ELF coredump support")
Cc: [email protected]
Signed-off-by: Anisse Astier <[email protected]>
---
Changes since v1:
- made a bit more explicit that we copied defined symbols, in commit
and code.
- Use Fixes: tag in commit message

Thanks to Dave Martin and Will Deacon for the review.

---
arch/arm64/include/uapi/asm/ptrace.h | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h
index d78623acb649..438759e7e8a7 100644
--- a/arch/arm64/include/uapi/asm/ptrace.h
+++ b/arch/arm64/include/uapi/asm/ptrace.h
@@ -65,8 +65,6 @@

#ifndef __ASSEMBLY__

-#include <linux/prctl.h>
-
/*
* User structures for general purpose, floating point and debug registers.
*/
@@ -113,10 +111,10 @@ struct user_sve_header {

/*
* Common SVE_PT_* flags:
- * These must be kept in sync with prctl interface in <linux/ptrace.h>
+ * These must be kept in sync with prctl interface in <linux/prctl.h>
*/
-#define SVE_PT_VL_INHERIT (PR_SVE_VL_INHERIT >> 16)
-#define SVE_PT_VL_ONEXEC (PR_SVE_SET_VL_ONEXEC >> 16)
+#define SVE_PT_VL_INHERIT ((1 << 17) /* PR_SVE_VL_INHERIT */ >> 16)
+#define SVE_PT_VL_ONEXEC ((1 << 18) /* PR_SVE_SET_VL_ONEXEC */ >> 16)


/*
--
2.19.1

2019-06-18 13:41:05

by Dave Martin

[permalink] [raw]
Subject: Re: [PATCH v2] arm64/sve: <uapi/asm/ptrace.h> should not depend on <uapi/linux/prctl.h>

On Fri, Jun 14, 2019 at 06:46:00PM +0200, Anisse Astier wrote:
> Otherwise this will create userspace build issues for any program
> (strace, qemu) that includes both <sys/prctl.h> (with musl libc) and
> <linux/ptrace.h> (which then includes <asm/ptrace.h>), like this:
>
> error: redefinition of 'struct prctl_mm_map'
> struct prctl_mm_map {
>
> See https://github.com/foundriesio/meta-lmp/commit/6d4a106e191b5d79c41b9ac78fd321316d3013c0
> for a public example of people working around this issue.
>
> Copying the defines is a bit imperfect here, but better than creating a
> whole other header for just two defines that would never change, as part
> of the kernel ABI.
>
> Fixes: 43d4da2c45b2 ("arm64/sve: ptrace and ELF coredump support")
> Cc: [email protected]
> Signed-off-by: Anisse Astier <[email protected]>
> ---
> Changes since v1:
> - made a bit more explicit that we copied defined symbols, in commit
> and code.
> - Use Fixes: tag in commit message
>
> Thanks to Dave Martin and Will Deacon for the review.
>
> ---
> arch/arm64/include/uapi/asm/ptrace.h | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h
> index d78623acb649..438759e7e8a7 100644
> --- a/arch/arm64/include/uapi/asm/ptrace.h
> +++ b/arch/arm64/include/uapi/asm/ptrace.h
> @@ -65,8 +65,6 @@
>
> #ifndef __ASSEMBLY__
>
> -#include <linux/prctl.h>
> -
> /*
> * User structures for general purpose, floating point and debug registers.
> */
> @@ -113,10 +111,10 @@ struct user_sve_header {
>
> /*
> * Common SVE_PT_* flags:
> - * These must be kept in sync with prctl interface in <linux/ptrace.h>
> + * These must be kept in sync with prctl interface in <linux/prctl.h>
> */
> -#define SVE_PT_VL_INHERIT (PR_SVE_VL_INHERIT >> 16)
> -#define SVE_PT_VL_ONEXEC (PR_SVE_SET_VL_ONEXEC >> 16)
> +#define SVE_PT_VL_INHERIT ((1 << 17) /* PR_SVE_VL_INHERIT */ >> 16)
> +#define SVE_PT_VL_ONEXEC ((1 << 18) /* PR_SVE_SET_VL_ONEXEC */ >> 16)

FWIW,
Acked-by: Dave Martin <[email protected]>

Ideally we would create a common <uapi/asm/prctl.h> that arm64 could
specialise as appropriate, but since x86 already has a similar header
shadowing this, it may be more trouble than it's worth to generalise it.

Cheers
---Dave