linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] arm64: introduce run-time detection of aarch32 support
@ 2015-09-01 14:41 Yury Norov
  2015-09-01 14:41 ` [PATCH 1/2] arm64: cpufeature.h: resolve hidden header dependencies Yury Norov
  2015-09-01 14:41 ` [PATCH 2/2] arm64: don't load 32-bit binaries if platform has no aarch32_el0 Yury Norov
  0 siblings, 2 replies; 7+ messages in thread
From: Yury Norov @ 2015-09-01 14:41 UTC (permalink / raw)
  To: linux-arm-kernel

This is needed to avoid loading aarch32 binaries if COMPAT is enabled, but
aarch32 is not supported by specific platform.

First patch fixes hidden header dependencies in arch/arm64/include/asm/cpufeature.h.
It's not related to the issue, but helps to avoid build failure that happens
if one applies second patch only.

Second patch adds run-time detection of aarch32 support, and rejects kernel to
load such binaries, if not supported.

Tested on ThunderX.

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>

Yury Norov (2):
  arm64: cpufeature.h: resolve hidden header dependencies
  arm64: don't load 32-bit binaries if platform has no aarch32_el0

 arch/arm64/include/asm/cpufeature.h | 6 ++++++
 arch/arm64/include/asm/elf.h        | 6 ++++--
 arch/arm64/kernel/cpuinfo.c         | 9 +++++++++
 3 files changed, 19 insertions(+), 2 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] arm64: cpufeature.h: resolve hidden header dependencies
  2015-09-01 14:41 [PATCH 0/2] arm64: introduce run-time detection of aarch32 support Yury Norov
@ 2015-09-01 14:41 ` Yury Norov
  2015-09-01 16:02   ` Mark Rutland
  2015-09-01 14:41 ` [PATCH 2/2] arm64: don't load 32-bit binaries if platform has no aarch32_el0 Yury Norov
  1 sibling, 1 reply; 7+ messages in thread
From: Yury Norov @ 2015-09-01 14:41 UTC (permalink / raw)
  To: linux-arm-kernel

Functions implemented in cpufeature.h depend on some headers, but
cpufeature.h does not include them. This may cause build failure if
cpufeature.h user does not include that headers by itself. (Like it
happens in next patch of this series.)

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
 arch/arm64/include/asm/cpufeature.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
index c104421..20cdc26 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -30,6 +30,11 @@
 
 #ifndef __ASSEMBLY__
 
+#include <linux/bitmap.h>
+#include <linux/log2.h>
+#include <linux/printk.h>
+#include <linux/types.h>
+
 struct arm64_cpu_capabilities {
 	const char *desc;
 	u16 capability;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] arm64: don't load 32-bit binaries if platform has no aarch32_el0
  2015-09-01 14:41 [PATCH 0/2] arm64: introduce run-time detection of aarch32 support Yury Norov
  2015-09-01 14:41 ` [PATCH 1/2] arm64: cpufeature.h: resolve hidden header dependencies Yury Norov
@ 2015-09-01 14:41 ` Yury Norov
  2015-09-01 16:04   ` Mark Rutland
  1 sibling, 1 reply; 7+ messages in thread
From: Yury Norov @ 2015-09-01 14:41 UTC (permalink / raw)
  To: linux-arm-kernel

Kernel option COMPAT defines the ability of executing aarch32 binaries.
Some platforms does not support aarch32 mode, and so cannot execute that
binaries. But we cannot just disable COMPAT for them because the same
kernel binary may be used by multiple platforms.

In this patch, system_supports_aarch32_el0() is introduced to detect
aarch32 support at run-time.

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
 arch/arm64/include/asm/cpufeature.h | 1 +
 arch/arm64/include/asm/elf.h        | 6 ++++--
 arch/arm64/kernel/cpuinfo.c         | 9 +++++++++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
index 20cdc26..d24ea15 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -81,6 +81,7 @@ void check_local_cpu_errata(void);
 void check_local_cpu_features(void);
 bool cpu_supports_mixed_endian_el0(void);
 bool system_supports_mixed_endian_el0(void);
+bool system_supports_aarch32_el0(void);
 
 #endif /* __ASSEMBLY__ */
 
diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index faad6df..461897b 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -21,6 +21,7 @@
 /*
  * ELF register definitions..
  */
+#include <asm/cpufeature.h>
 #include <asm/ptrace.h>
 #include <asm/user.h>
 
@@ -173,8 +174,9 @@ typedef compat_elf_greg_t		compat_elf_gregset_t[COMPAT_ELF_NGREG];
 
 /* AArch32 EABI. */
 #define EF_ARM_EABI_MASK		0xff000000
-#define compat_elf_check_arch(x)	(((x)->e_machine == EM_ARM) && \
-					 ((x)->e_flags & EF_ARM_EABI_MASK))
+#define compat_elf_check_arch(x)	(system_supports_aarch32_el0()	\
+					&& ((x)->e_machine == EM_ARM)	\
+					&& ((x)->e_flags & EF_ARM_EABI_MASK))
 
 #define compat_start_thread		compat_start_thread
 #define COMPAT_SET_PERSONALITY(ex)	set_thread_flag(TIF_32BIT);
diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
index 75d5a86..95d953f 100644
--- a/arch/arm64/kernel/cpuinfo.c
+++ b/arch/arm64/kernel/cpuinfo.c
@@ -79,6 +79,15 @@ bool system_supports_mixed_endian_el0(void)
 	return mixed_endian_el0;
 }
 
+#define AARCH64		1
+#define AARCH32_64	2
+bool system_supports_aarch32_el0(void)
+{
+	struct cpuinfo_arm64 *info = this_cpu_ptr(&cpu_data);
+	u64 arm64_el0 = info->reg_id_aa64pfr0 & 0xf;
+	return arm64_el0 == AARCH32_64;
+}
+
 static void update_mixed_endian_el0_support(struct cpuinfo_arm64 *info)
 {
 	mixed_endian_el0 &= id_aa64mmfr0_mixed_endian_el0(info->reg_id_aa64mmfr0);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 1/2] arm64: cpufeature.h: resolve hidden header dependencies
  2015-09-01 14:41 ` [PATCH 1/2] arm64: cpufeature.h: resolve hidden header dependencies Yury Norov
@ 2015-09-01 16:02   ` Mark Rutland
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Rutland @ 2015-09-01 16:02 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Sep 01, 2015 at 03:41:11PM +0100, Yury Norov wrote:
> Functions implemented in cpufeature.h depend on some headers, but
> cpufeature.h does not include them. This may cause build failure if
> cpufeature.h user does not include that headers by itself. (Like it
> happens in next patch of this series.)
> 
> Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
> ---
>  arch/arm64/include/asm/cpufeature.h | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
> index c104421..20cdc26 100644
> --- a/arch/arm64/include/asm/cpufeature.h
> +++ b/arch/arm64/include/asm/cpufeature.h
> @@ -30,6 +30,11 @@
>  
>  #ifndef __ASSEMBLY__
>  
> +#include <linux/bitmap.h>

We're also missing <linux/compiler.h> for the __attribute_const__ on
cpuid_feature_extract_field.

> +#include <linux/log2.h>

The cpu_feature macro using ilog2 is prior to the __ASSEMBLY__ guard.
Given it cannot be used by assembly, I think it should also be pulled
under the guard, or removed as it doesn't appear to be used anyway
(which would remove the need for this include).

Otherwise this looks good to me.

Thanks,
Mark.

> +#include <linux/printk.h>
> +#include <linux/types.h>
> +
>  struct arm64_cpu_capabilities {
>  	const char *desc;
>  	u16 capability;
> -- 
> 2.1.4
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/2] arm64: don't load 32-bit binaries if platform has no aarch32_el0
  2015-09-01 14:41 ` [PATCH 2/2] arm64: don't load 32-bit binaries if platform has no aarch32_el0 Yury Norov
@ 2015-09-01 16:04   ` Mark Rutland
  2015-09-01 17:41     ` Suzuki K. Poulose
  2015-09-01 17:44     ` Yury
  0 siblings, 2 replies; 7+ messages in thread
From: Mark Rutland @ 2015-09-01 16:04 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Sep 01, 2015 at 03:41:12PM +0100, Yury Norov wrote:
> Kernel option COMPAT defines the ability of executing aarch32 binaries.
> Some platforms does not support aarch32 mode, and so cannot execute that
> binaries. But we cannot just disable COMPAT for them because the same
> kernel binary may be used by multiple platforms.
> 
> In this patch, system_supports_aarch32_el0() is introduced to detect
> aarch32 support at run-time.
> 
> Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
> ---
>  arch/arm64/include/asm/cpufeature.h | 1 +
>  arch/arm64/include/asm/elf.h        | 6 ++++--
>  arch/arm64/kernel/cpuinfo.c         | 9 +++++++++
>  3 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
> index 20cdc26..d24ea15 100644
> --- a/arch/arm64/include/asm/cpufeature.h
> +++ b/arch/arm64/include/asm/cpufeature.h
> @@ -81,6 +81,7 @@ void check_local_cpu_errata(void);
>  void check_local_cpu_features(void);
>  bool cpu_supports_mixed_endian_el0(void);
>  bool system_supports_mixed_endian_el0(void);
> +bool system_supports_aarch32_el0(void);
>  
>  #endif /* __ASSEMBLY__ */
>  
> diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
> index faad6df..461897b 100644
> --- a/arch/arm64/include/asm/elf.h
> +++ b/arch/arm64/include/asm/elf.h
> @@ -21,6 +21,7 @@
>  /*
>   * ELF register definitions..
>   */
> +#include <asm/cpufeature.h>
>  #include <asm/ptrace.h>
>  #include <asm/user.h>
>  
> @@ -173,8 +174,9 @@ typedef compat_elf_greg_t		compat_elf_gregset_t[COMPAT_ELF_NGREG];
>  
>  /* AArch32 EABI. */
>  #define EF_ARM_EABI_MASK		0xff000000
> -#define compat_elf_check_arch(x)	(((x)->e_machine == EM_ARM) && \
> -					 ((x)->e_flags & EF_ARM_EABI_MASK))
> +#define compat_elf_check_arch(x)	(system_supports_aarch32_el0()	\
> +					&& ((x)->e_machine == EM_ARM)	\
> +					&& ((x)->e_flags & EF_ARM_EABI_MASK))
>  
>  #define compat_start_thread		compat_start_thread
>  #define COMPAT_SET_PERSONALITY(ex)	set_thread_flag(TIF_32BIT);
> diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
> index 75d5a86..95d953f 100644
> --- a/arch/arm64/kernel/cpuinfo.c
> +++ b/arch/arm64/kernel/cpuinfo.c
> @@ -79,6 +79,15 @@ bool system_supports_mixed_endian_el0(void)
>  	return mixed_endian_el0;
>  }
>  
> +#define AARCH64		1
> +#define AARCH32_64	2

These should be better namespaced. Perhaps ID_AA64PFR0_EL1_EL0_64 and
ID_AA64PFR0_EL1_EL0_6432 ?

> +bool system_supports_aarch32_el0(void)
> +{
> +	struct cpuinfo_arm64 *info = this_cpu_ptr(&cpu_data);
> +	u64 arm64_el0 = info->reg_id_aa64pfr0 & 0xf;
> +	return arm64_el0 == AARCH32_64;
> +}

We should handle this the same way as we do for endianness support and
check that all CPUs support AArch32, and set a global flag, rather than
assuming that all CPUs are symmetric. Likewise for any other feature we
have to dynamically detect.

Thanks,
Mark.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/2] arm64: don't load 32-bit binaries if platform has no aarch32_el0
  2015-09-01 16:04   ` Mark Rutland
@ 2015-09-01 17:41     ` Suzuki K. Poulose
  2015-09-01 17:44     ` Yury
  1 sibling, 0 replies; 7+ messages in thread
From: Suzuki K. Poulose @ 2015-09-01 17:41 UTC (permalink / raw)
  To: linux-arm-kernel

On 01/09/15 17:04, Mark Rutland wrote:
> On Tue, Sep 01, 2015 at 03:41:12PM +0100, Yury Norov wrote:
>> Kernel option COMPAT defines the ability of executing aarch32 binaries.
>> Some platforms does not support aarch32 mode, and so cannot execute that
>> binaries. But we cannot just disable COMPAT for them because the same
>> kernel binary may be used by multiple platforms.
>>
>> In this patch, system_supports_aarch32_el0() is introduced to detect
>> aarch32 support at run-time.
>>
>> Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
>> ---
>>   arch/arm64/include/asm/cpufeature.h | 1 +
>>   arch/arm64/include/asm/elf.h        | 6 ++++--
>>   arch/arm64/kernel/cpuinfo.c         | 9 +++++++++
>>   3 files changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
>> index 20cdc26..d24ea15 100644
>> --- a/arch/arm64/include/asm/cpufeature.h
>> +++ b/arch/arm64/include/asm/cpufeature.h
>> @@ -81,6 +81,7 @@ void check_local_cpu_errata(void);
>>   void check_local_cpu_features(void);
>>   bool cpu_supports_mixed_endian_el0(void);
>>   bool system_supports_mixed_endian_el0(void);
>> +bool system_supports_aarch32_el0(void);
>>
>>   #endif /* __ASSEMBLY__ */
>>
>> diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
>> index faad6df..461897b 100644
>> --- a/arch/arm64/include/asm/elf.h
>> +++ b/arch/arm64/include/asm/elf.h
>> @@ -21,6 +21,7 @@
>>   /*
>>    * ELF register definitions..
>>    */
>> +#include <asm/cpufeature.h>
>>   #include <asm/ptrace.h>
>>   #include <asm/user.h>
>>
>> @@ -173,8 +174,9 @@ typedef compat_elf_greg_t		compat_elf_gregset_t[COMPAT_ELF_NGREG];
>>
>>   /* AArch32 EABI. */
>>   #define EF_ARM_EABI_MASK		0xff000000
>> -#define compat_elf_check_arch(x)	(((x)->e_machine == EM_ARM) && \
>> -					 ((x)->e_flags & EF_ARM_EABI_MASK))
>> +#define compat_elf_check_arch(x)	(system_supports_aarch32_el0()	\
>> +					&& ((x)->e_machine == EM_ARM)	\
>> +					&& ((x)->e_flags & EF_ARM_EABI_MASK))
>>
>>   #define compat_start_thread		compat_start_thread
>>   #define COMPAT_SET_PERSONALITY(ex)	set_thread_flag(TIF_32BIT);
>> diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
>> index 75d5a86..95d953f 100644
>> --- a/arch/arm64/kernel/cpuinfo.c
>> +++ b/arch/arm64/kernel/cpuinfo.c
>> @@ -79,6 +79,15 @@ bool system_supports_mixed_endian_el0(void)
>>   	return mixed_endian_el0;
>>   }
>>
>> +#define AARCH64		1
>> +#define AARCH32_64	2
>
> These should be better namespaced. Perhaps ID_AA64PFR0_EL1_EL0_64 and
> ID_AA64PFR0_EL1_EL0_6432 ?
>
>> +bool system_supports_aarch32_el0(void)
>> +{
>> +	struct cpuinfo_arm64 *info = this_cpu_ptr(&cpu_data);
>> +	u64 arm64_el0 = info->reg_id_aa64pfr0 & 0xf;
>> +	return arm64_el0 == AARCH32_64;
>> +}
>
> We should handle this the same way as we do for endianness support and
> check that all CPUs support AArch32, and set a global flag, rather than
> assuming that all CPUs are symmetric. Likewise for any other feature we
> have to dynamically detect.

Correct. With my series, which I will post after the merge window, we should be able to
define this as a CPU capability and check that bit instead, which would give us a system
wide value.

Suzuki


>
> Thanks,
> Mark.
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/2] arm64: don't load 32-bit binaries if platform has no aarch32_el0
  2015-09-01 16:04   ` Mark Rutland
  2015-09-01 17:41     ` Suzuki K. Poulose
@ 2015-09-01 17:44     ` Yury
  1 sibling, 0 replies; 7+ messages in thread
From: Yury @ 2015-09-01 17:44 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Sep 01, 2015 at 05:04:26PM +0100, Mark Rutland wrote:
> On Tue, Sep 01, 2015 at 03:41:12PM +0100, Yury Norov wrote:
> > Kernel option COMPAT defines the ability of executing aarch32 binaries.
> > Some platforms does not support aarch32 mode, and so cannot execute that
> > binaries. But we cannot just disable COMPAT for them because the same
> > kernel binary may be used by multiple platforms.
> > 
> > In this patch, system_supports_aarch32_el0() is introduced to detect
> > aarch32 support at run-time.
> > 
> > Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
> > ---
> >  arch/arm64/include/asm/cpufeature.h | 1 +
> >  arch/arm64/include/asm/elf.h        | 6 ++++--
> >  arch/arm64/kernel/cpuinfo.c         | 9 +++++++++
> >  3 files changed, 14 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
> > index 20cdc26..d24ea15 100644
> > --- a/arch/arm64/include/asm/cpufeature.h
> > +++ b/arch/arm64/include/asm/cpufeature.h
> > @@ -81,6 +81,7 @@ void check_local_cpu_errata(void);
> >  void check_local_cpu_features(void);
> >  bool cpu_supports_mixed_endian_el0(void);
> >  bool system_supports_mixed_endian_el0(void);
> > +bool system_supports_aarch32_el0(void);
> >  
> >  #endif /* __ASSEMBLY__ */
> >  
> > diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
> > index faad6df..461897b 100644
> > --- a/arch/arm64/include/asm/elf.h
> > +++ b/arch/arm64/include/asm/elf.h
> > @@ -21,6 +21,7 @@
> >  /*
> >   * ELF register definitions..
> >   */
> > +#include <asm/cpufeature.h>
> >  #include <asm/ptrace.h>
> >  #include <asm/user.h>
> >  
> > @@ -173,8 +174,9 @@ typedef compat_elf_greg_t		compat_elf_gregset_t[COMPAT_ELF_NGREG];
> >  
> >  /* AArch32 EABI. */
> >  #define EF_ARM_EABI_MASK		0xff000000
> > -#define compat_elf_check_arch(x)	(((x)->e_machine == EM_ARM) && \
> > -					 ((x)->e_flags & EF_ARM_EABI_MASK))
> > +#define compat_elf_check_arch(x)	(system_supports_aarch32_el0()	\
> > +					&& ((x)->e_machine == EM_ARM)	\
> > +					&& ((x)->e_flags & EF_ARM_EABI_MASK))
> >  
> >  #define compat_start_thread		compat_start_thread
> >  #define COMPAT_SET_PERSONALITY(ex)	set_thread_flag(TIF_32BIT);
> > diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
> > index 75d5a86..95d953f 100644
> > --- a/arch/arm64/kernel/cpuinfo.c
> > +++ b/arch/arm64/kernel/cpuinfo.c
> > @@ -79,6 +79,15 @@ bool system_supports_mixed_endian_el0(void)
> >  	return mixed_endian_el0;
> >  }
> >  
> > +#define AARCH64		1
> > +#define AARCH32_64	2
> 
> These should be better namespaced. Perhaps ID_AA64PFR0_EL1_EL0_64 and
> ID_AA64PFR0_EL1_EL0_6432 ?
> 
> > +bool system_supports_aarch32_el0(void)
> > +{
> > +	struct cpuinfo_arm64 *info = this_cpu_ptr(&cpu_data);
> > +	u64 arm64_el0 = info->reg_id_aa64pfr0 & 0xf;
> > +	return arm64_el0 == AARCH32_64;
> > +}
> 
> We should handle this the same way as we do for endianness support and
> check that all CPUs support AArch32, and set a global flag, rather than
> assuming that all CPUs are symmetric. Likewise for any other feature we
> have to dynamically detect.
> 

OK. Will do in V2

> Thanks,
> Mark.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-09-01 17:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-01 14:41 [PATCH 0/2] arm64: introduce run-time detection of aarch32 support Yury Norov
2015-09-01 14:41 ` [PATCH 1/2] arm64: cpufeature.h: resolve hidden header dependencies Yury Norov
2015-09-01 16:02   ` Mark Rutland
2015-09-01 14:41 ` [PATCH 2/2] arm64: don't load 32-bit binaries if platform has no aarch32_el0 Yury Norov
2015-09-01 16:04   ` Mark Rutland
2015-09-01 17:41     ` Suzuki K. Poulose
2015-09-01 17:44     ` Yury

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).