This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add ifunc memcpy and memmove for aarch64


Hi Steve,

On 19/01/2017 16:22, Steve Ellcey wrote:
> +extern uint64_t __midr attribute_hidden;
> +extern bool __is_thunderx attribute_hidden;
> +
> +#define INIT_ARCH()						\
> +  {								\
> +    if (__midr == 0)						\
> +      {								\
> +	asm volatile ("mrs %0, midr_el1" : "=r"(__midr));	\
> +	__is_thunderx = IS_THUNDERX(__midr);			\
> +      }								\
> +  }

I think to avoid potentially multiple kernel traps at loading or plt resolve time,
a better solution would be issue the mrs instruction once at loader/program startup,
fill in an internal structure with the required information and use it later on
ifunc resolution.  This is similar the cpu-features/cacheinfo strategy for x86.


> diff --git a/sysdeps/unix/sysv/linux/aarch64/configure.ac b/sysdeps/unix/sysv/linux/aarch64/configure.ac
> index 211fa9c..684cb46 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/configure.ac
> +++ b/sysdeps/unix/sysv/linux/aarch64/configure.ac
> @@ -1,6 +1,11 @@
>  GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
>  # Local configure fragment for sysdeps/unix/sysv/linux/aarch64.
>  
> -arch_minimum_kernel=3.7.0
> +# For multi-arch support we need a kernel that emulates the mrs instruction.
> +if test x$multi_arch = xyes; then
> +    arch_minimum_kernel=4.11.0
> +else
> +    arch_minimum_kernel=3.7.0
> +fi

I do not think this is suffice to prevent the multiarch version on system with
old installed kernel headers.  This will only prevents if you explicit use
--enable-multi-arch, however multiarch are enabled by default in configure.ac
(configure.ac:877).  So building on with old kernel headers will broke 
the runtime.

We need to make sure glibc built against older kernel headers (or with
--enable-kernel=x.y.z) do not use mrs instruction and glibc built against
newer kernel that may use mrs fail on loading with DL_SYSDEP_OSCHECK.

>From last patch iteration [1] documentation, kernel provides the HWCAP_CPUID
bit on hwcap to indication it supports the mrs emulation.  So using my previous
suggestion I would recommend:

  1. Remove any configure check or restriction.
  2. Add a cpu_features module similar to x86 that set a global state with
     the cpu information obtained from kernel.  It will first check HWCAP_CPUID
     bit on hwcap and if it is set then issue the mrs instruction.  It will
     then populate the global state with the required cpu information.
  3. Use the cpu information to select the correct ifunc.

It has another advantage of avoid more complexity with different glibc
with different minimum required kernels.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]