[2/6] tunables: Add LD_HWCAP_MASK to tunables

Message ID 1496347928-19432-3-git-send-email-siddhesh@sourceware.org
State New, archived
Headers

Commit Message

Siddhesh Poyarekar June 1, 2017, 8:12 p.m. UTC
  Add LD_HWCAP_MASK to tunables in preparation of it being removed from
rtld.c.  This allows us to read LD_HWCAP_MASK much earlier so that it
can influence IFUNC resolution in aarch64.

This patch does not actually do anything other than read the
LD_HWCAP_MASK variable and add the tunables way to set the
LD_HWCAP_MASK, i.e. via the glibc.tune.hwcap_mask tunable.  In a
follow-up patch, the _dl_hwcap_mask will be replaced with
glibc.tune.hwcap_mask to complete the transition.

	* elf/dl-tunables.list: Add glibc.tune.hwcap_mask.
	* scripts/gen-tunables.awk: Include dl-procinfo.h.
	* manual/tunables.texi: Document glibc.tune.hwcap_mask.
---
 elf/dl-tunables.list     |  7 +++++++
 manual/tunables.texi     | 23 +++++++++++++++++++++++
 scripts/gen-tunables.awk |  1 +
 3 files changed, 31 insertions(+)
  

Comments

Adhemerval Zanella June 6, 2017, 5:57 p.m. UTC | #1
On 01/06/2017 17:12, Siddhesh Poyarekar wrote:
> Add LD_HWCAP_MASK to tunables in preparation of it being removed from
> rtld.c.  This allows us to read LD_HWCAP_MASK much earlier so that it
> can influence IFUNC resolution in aarch64.
> 
> This patch does not actually do anything other than read the
> LD_HWCAP_MASK variable and add the tunables way to set the
> LD_HWCAP_MASK, i.e. via the glibc.tune.hwcap_mask tunable.  In a
> follow-up patch, the _dl_hwcap_mask will be replaced with
> glibc.tune.hwcap_mask to complete the transition.
> 
> 	* elf/dl-tunables.list: Add glibc.tune.hwcap_mask.
> 	* scripts/gen-tunables.awk: Include dl-procinfo.h.
> 	* manual/tunables.texi: Document glibc.tune.hwcap_mask.

LGTM with a remark below.

> ---
>  elf/dl-tunables.list     |  7 +++++++
>  manual/tunables.texi     | 23 +++++++++++++++++++++++
>  scripts/gen-tunables.awk |  1 +
>  3 files changed, 31 insertions(+)
> 
> diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list
> index b9f1488..41ce9af 100644
> --- a/elf/dl-tunables.list
> +++ b/elf/dl-tunables.list
> @@ -77,4 +77,11 @@ glibc {
>        security_level: SXID_IGNORE
>      }
>    }
> +  tune {
> +    hwcap_mask {
> +      type: UINT_64
> +      env_alias: LD_HWCAP_MASK
> +      default: HWCAP_IMPORTANT
> +    }
> +  }

LD_HWCAP_MASK is on UNSECURE_ENVVARS at sysdeps/generic/unsecvars.h, so I think
we should add a security_level: SXID_IGNORE for hwcap_mask as well.
  
Adhemerval Zanella June 6, 2017, 6:16 p.m. UTC | #2
On 06/06/2017 14:57, Adhemerval Zanella wrote:
> 
> 
> On 01/06/2017 17:12, Siddhesh Poyarekar wrote:
>> Add LD_HWCAP_MASK to tunables in preparation of it being removed from
>> rtld.c.  This allows us to read LD_HWCAP_MASK much earlier so that it
>> can influence IFUNC resolution in aarch64.
>>
>> This patch does not actually do anything other than read the
>> LD_HWCAP_MASK variable and add the tunables way to set the
>> LD_HWCAP_MASK, i.e. via the glibc.tune.hwcap_mask tunable.  In a
>> follow-up patch, the _dl_hwcap_mask will be replaced with
>> glibc.tune.hwcap_mask to complete the transition.
>>
>> 	* elf/dl-tunables.list: Add glibc.tune.hwcap_mask.
>> 	* scripts/gen-tunables.awk: Include dl-procinfo.h.
>> 	* manual/tunables.texi: Document glibc.tune.hwcap_mask.
> 
> LGTM with a remark below.
> 
>> ---
>>  elf/dl-tunables.list     |  7 +++++++
>>  manual/tunables.texi     | 23 +++++++++++++++++++++++
>>  scripts/gen-tunables.awk |  1 +
>>  3 files changed, 31 insertions(+)
>>
>> diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list
>> index b9f1488..41ce9af 100644
>> --- a/elf/dl-tunables.list
>> +++ b/elf/dl-tunables.list
>> @@ -77,4 +77,11 @@ glibc {
>>        security_level: SXID_IGNORE
>>      }
>>    }
>> +  tune {
>> +    hwcap_mask {
>> +      type: UINT_64
>> +      env_alias: LD_HWCAP_MASK
>> +      default: HWCAP_IMPORTANT
>> +    }
>> +  }
> 
> LD_HWCAP_MASK is on UNSECURE_ENVVARS at sysdeps/generic/unsecvars.h, so I think
> we should add a security_level: SXID_IGNORE for hwcap_mask as well.
> 

I am getting build errors for i686 and s390{x} with --enable-tunables:

In file included from /home/azanella/Projects/glibc/build/i686-linux-gnu/dl-tunable-list.h:6:0,
                 from ./dl-tunables.h:67,
                 from ../elf/dl-sysdep.c:47,
                 from ../sysdeps/unix/sysv/linux/dl-sysdep.c:38:
../sysdeps/unix/sysv/linux/i386/dl-procinfo.h:25:1: error: redefinition of ‘_dl_procinfo’
 _dl_procinfo (unsigned int type, unsigned long int word)
 ^~~~~~~~~~~~
In file included from ../elf/dl-sysdep.c:42:0,
                 from ../sysdeps/unix/sysv/linux/dl-sysdep.c:38:
../sysdeps/unix/sysv/linux/i386/dl-procinfo.h:25:1: note: previous definition of ‘_dl_procinfo’ was here
 _dl_procinfo (unsigned int type, unsigned long int word)
 ^~~~~~~~~~~~

It because both Linux i686 and s390 dl-procinfo.h do not have include guard (as
for the other dl-procinfo.h implementation).  I think you should include them
on this patch.
  
Siddhesh Poyarekar June 7, 2017, 5:33 a.m. UTC | #3
On Tuesday 06 June 2017 11:27 PM, Adhemerval Zanella wrote:
> LD_HWCAP_MASK is on UNSECURE_ENVVARS at sysdeps/generic/unsecvars.h, so I think
> we should add a security_level: SXID_IGNORE for hwcap_mask as well.

It is in UNSECURE_ENVVARS, so it should be SXID_ERASE (the default) and
not SXID_IGNORE since the latter will make the tunable available for
children of setuid processes.

Siddhesh
  
Adhemerval Zanella June 7, 2017, 12:07 p.m. UTC | #4
On 07/06/2017 02:33, Siddhesh Poyarekar wrote:
> On Tuesday 06 June 2017 11:27 PM, Adhemerval Zanella wrote:
>> LD_HWCAP_MASK is on UNSECURE_ENVVARS at sysdeps/generic/unsecvars.h, so I think
>> we should add a security_level: SXID_IGNORE for hwcap_mask as well.
> 
> It is in UNSECURE_ENVVARS, so it should be SXID_ERASE (the default) and
> not SXID_IGNORE since the latter will make the tunable available for
> children of setuid processes.

Right, I wasn't aware SXID_ERASE was the default.  Thanks for the clarification.
  

Patch

diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list
index b9f1488..41ce9af 100644
--- a/elf/dl-tunables.list
+++ b/elf/dl-tunables.list
@@ -77,4 +77,11 @@  glibc {
       security_level: SXID_IGNORE
     }
   }
+  tune {
+    hwcap_mask {
+      type: UINT_64
+      env_alias: LD_HWCAP_MASK
+      default: HWCAP_IMPORTANT
+    }
+  }
 }
diff --git a/manual/tunables.texi b/manual/tunables.texi
index ac8c38f..c9a4cb7 100644
--- a/manual/tunables.texi
+++ b/manual/tunables.texi
@@ -31,6 +31,8 @@  their own namespace.
 @menu
 * Tunable names::  The structure of a tunable name
 * Memory Allocation Tunables::  Tunables in the memory allocation subsystem
+* Hardware Capability Tunables::  Tunables that modify the hardware
+				  capabilities seen by @theglibc{}
 @end menu
 
 @node Tunable names
@@ -190,3 +192,24 @@  number of arenas is determined by the number of CPU cores online.  For 32-bit
 systems the limit is twice the number of cores online and on 64-bit systems, it
 is 8 times the number of cores online.
 @end deftp
+
+@node Hardware Capability Tunables
+@section Hardware Capability Tunables
+@cindex hardware capability tunables
+@cindex hwcap tunables
+@cindex tunables, hwcap
+
+@deftp {Tunable namespace} glibc.tune
+Behavior of @theglibc{} can be tuned to assume specific hardware capabilities
+by setting the following tunables in the @code{tune} namespace:
+@end deftp
+
+@deftp Tunable glibc.tune.hwcap_mask
+This tunable supersedes the @env{LD_HWCAP_MASK} environment variable and is
+identical in features.
+
+The @code{AT_HWCAP} key in the Auxilliary Vector specifies instruction set
+extensions available in the processor at runtime for some architectures.  The
+@code{glibc.tune.hwcap_mask} tunable allows the user to mask out those
+capabilities at runtime, thus disabling use of those extensions.
+@end deftp
diff --git a/scripts/gen-tunables.awk b/scripts/gen-tunables.awk
index b10b00e..93e5aff 100644
--- a/scripts/gen-tunables.awk
+++ b/scripts/gen-tunables.awk
@@ -134,6 +134,7 @@  END {
   print "# error \"Do not include this file directly.\""
   print "# error \"Include tunables.h instead.\""
   print "#endif"
+  print "#include <dl-procinfo.h>\n"
 
   # Now, the enum names
   print "\ntypedef enum"