Use __syscall_ulong_t for __cpu_mask

Message ID 1448909195-12575-1-git-send-email-hjl.tools@gmail.com
State New, archived
Headers

Commit Message

H.J. Lu Nov. 30, 2015, 6:46 p.m. UTC
  Since x86-64 and x32 use the same set of sched_XXX system call
interface:

[hjl@gnu-6 linux-stable]$ grep sched_
arch/x86/entry/syscalls/syscall_64.tbl
24	common	sched_yield		sys_sched_yield
142	common	sched_setparam		sys_sched_setparam
143	common	sched_getparam		sys_sched_getparam
144	common	sched_setscheduler	sys_sched_setscheduler
145	common	sched_getscheduler	sys_sched_getscheduler
146	common	sched_get_priority_max	sys_sched_get_priority_max
147	common	sched_get_priority_min	sys_sched_get_priority_min
148	common	sched_rr_get_interval	sys_sched_rr_get_interval
203	common	sched_setaffinity	sys_sched_setaffinity
204	common	sched_getaffinity	sys_sched_getaffinity
314	common	sched_setattr		sys_sched_setattr
315	common	sched_getattr		sys_sched_getattr
[hjl@gnu-6 linux-stable]$

__cpu_mask should be __syscall_ulong_t.

	[BZ #19313]
	* sysdeps/unix/sysv/linux/bits/sched.h (__cpu_mask): Replace
	unsigned long int with __syscall_ulong_t.
---
 sysdeps/unix/sysv/linux/bits/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Carlos O'Donell Dec. 1, 2015, 4:07 p.m. UTC | #1
On 11/30/2015 01:46 PM, H.J. Lu wrote:
> Since x86-64 and x32 use the same set of sched_XXX system call
> interface:
> 
> [hjl@gnu-6 linux-stable]$ grep sched_
> arch/x86/entry/syscalls/syscall_64.tbl
> 24	common	sched_yield		sys_sched_yield
> 142	common	sched_setparam		sys_sched_setparam
> 143	common	sched_getparam		sys_sched_getparam
> 144	common	sched_setscheduler	sys_sched_setscheduler
> 145	common	sched_getscheduler	sys_sched_getscheduler
> 146	common	sched_get_priority_max	sys_sched_get_priority_max
> 147	common	sched_get_priority_min	sys_sched_get_priority_min
> 148	common	sched_rr_get_interval	sys_sched_rr_get_interval
> 203	common	sched_setaffinity	sys_sched_setaffinity
> 204	common	sched_getaffinity	sys_sched_getaffinity
> 314	common	sched_setattr		sys_sched_setattr
> 315	common	sched_getattr		sys_sched_getattr
> [hjl@gnu-6 linux-stable]$
> 
> __cpu_mask should be __syscall_ulong_t.
> 
> 	[BZ #19313]
> 	* sysdeps/unix/sysv/linux/bits/sched.h (__cpu_mask): Replace
> 	unsigned long int with __syscall_ulong_t.

How did you test this?

> ---
>  sysdeps/unix/sysv/linux/bits/sched.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/bits/sched.h b/sysdeps/unix/sysv/linux/bits/sched.h
> index ae089df..27d87c4 100644
> --- a/sysdeps/unix/sysv/linux/bits/sched.h
> +++ b/sysdeps/unix/sysv/linux/bits/sched.h
> @@ -115,7 +115,7 @@ struct __sched_param
>  # define __NCPUBITS	(8 * sizeof (__cpu_mask))
>  
>  /* Type for array elements in 'cpu_set_t'.  */
> -typedef unsigned long int __cpu_mask;
> +typedef __syscall_ulong_t __cpu_mask;
>  
>  /* Basic access functions.  */
>  # define __CPUELT(cpu)	((cpu) / __NCPUBITS)
>
  
H.J. Lu Dec. 1, 2015, 4:10 p.m. UTC | #2
On Tue, Dec 1, 2015 at 8:07 AM, Carlos O'Donell <carlos@redhat.com> wrote:
> On 11/30/2015 01:46 PM, H.J. Lu wrote:
>> Since x86-64 and x32 use the same set of sched_XXX system call
>> interface:
>>
>> [hjl@gnu-6 linux-stable]$ grep sched_
>> arch/x86/entry/syscalls/syscall_64.tbl
>> 24    common  sched_yield             sys_sched_yield
>> 142   common  sched_setparam          sys_sched_setparam
>> 143   common  sched_getparam          sys_sched_getparam
>> 144   common  sched_setscheduler      sys_sched_setscheduler
>> 145   common  sched_getscheduler      sys_sched_getscheduler
>> 146   common  sched_get_priority_max  sys_sched_get_priority_max
>> 147   common  sched_get_priority_min  sys_sched_get_priority_min
>> 148   common  sched_rr_get_interval   sys_sched_rr_get_interval
>> 203   common  sched_setaffinity       sys_sched_setaffinity
>> 204   common  sched_getaffinity       sys_sched_getaffinity
>> 314   common  sched_setattr           sys_sched_setattr
>> 315   common  sched_getattr           sys_sched_getattr
>> [hjl@gnu-6 linux-stable]$
>>
>> __cpu_mask should be __syscall_ulong_t.
>>
>>       [BZ #19313]
>>       * sysdeps/unix/sysv/linux/bits/sched.h (__cpu_mask): Replace
>>       unsigned long int with __syscall_ulong_t.
>
> How did you test this?

I tested it on x32, i686 and x86-64.  Maybe we should add
__CPU_MASK_TYPE to bits/typesizes.h so that each
architecture can define it own type for __cpu_mask.

>> ---
>>  sysdeps/unix/sysv/linux/bits/sched.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/sysdeps/unix/sysv/linux/bits/sched.h b/sysdeps/unix/sysv/linux/bits/sched.h
>> index ae089df..27d87c4 100644
>> --- a/sysdeps/unix/sysv/linux/bits/sched.h
>> +++ b/sysdeps/unix/sysv/linux/bits/sched.h
>> @@ -115,7 +115,7 @@ struct __sched_param
>>  # define __NCPUBITS  (8 * sizeof (__cpu_mask))
>>
>>  /* Type for array elements in 'cpu_set_t'.  */
>> -typedef unsigned long int __cpu_mask;
>> +typedef __syscall_ulong_t __cpu_mask;
>>
>>  /* Basic access functions.  */
>>  # define __CPUELT(cpu)       ((cpu) / __NCPUBITS)
>>
>
  
Carlos O'Donell Dec. 1, 2015, 4:51 p.m. UTC | #3
On 12/01/2015 11:10 AM, H.J. Lu wrote:
> On Tue, Dec 1, 2015 at 8:07 AM, Carlos O'Donell <carlos@redhat.com> wrote:
>> On 11/30/2015 01:46 PM, H.J. Lu wrote:
>>> Since x86-64 and x32 use the same set of sched_XXX system call
>>> interface:
>>>
>>> [hjl@gnu-6 linux-stable]$ grep sched_
>>> arch/x86/entry/syscalls/syscall_64.tbl
>>> 24    common  sched_yield             sys_sched_yield
>>> 142   common  sched_setparam          sys_sched_setparam
>>> 143   common  sched_getparam          sys_sched_getparam
>>> 144   common  sched_setscheduler      sys_sched_setscheduler
>>> 145   common  sched_getscheduler      sys_sched_getscheduler
>>> 146   common  sched_get_priority_max  sys_sched_get_priority_max
>>> 147   common  sched_get_priority_min  sys_sched_get_priority_min
>>> 148   common  sched_rr_get_interval   sys_sched_rr_get_interval
>>> 203   common  sched_setaffinity       sys_sched_setaffinity
>>> 204   common  sched_getaffinity       sys_sched_getaffinity
>>> 314   common  sched_setattr           sys_sched_setattr
>>> 315   common  sched_getattr           sys_sched_getattr
>>> [hjl@gnu-6 linux-stable]$
>>>
>>> __cpu_mask should be __syscall_ulong_t.
>>>
>>>       [BZ #19313]
>>>       * sysdeps/unix/sysv/linux/bits/sched.h (__cpu_mask): Replace
>>>       unsigned long int with __syscall_ulong_t.
>>
>> How did you test this?
> 
> I tested it on x32, i686 and x86-64.  Maybe we should add
> __CPU_MASK_TYPE to bits/typesizes.h so that each
> architecture can define it own type for __cpu_mask.

The definition of __syscall_ulong_t, AFAICT, is always
`unsigned long int`, which means the change does nothing?
Aren't both of these types the same size on x86_64 and
x32?

What exactly was the failure mode you saw in bug 19313?

Cheers,
Carlos.
  
H.J. Lu Dec. 1, 2015, 5:01 p.m. UTC | #4
On Tue, Dec 1, 2015 at 8:51 AM, Carlos O'Donell <carlos@redhat.com> wrote:
> On 12/01/2015 11:10 AM, H.J. Lu wrote:
>> On Tue, Dec 1, 2015 at 8:07 AM, Carlos O'Donell <carlos@redhat.com> wrote:
>>> On 11/30/2015 01:46 PM, H.J. Lu wrote:
>>>> Since x86-64 and x32 use the same set of sched_XXX system call
>>>> interface:
>>>>
>>>> [hjl@gnu-6 linux-stable]$ grep sched_
>>>> arch/x86/entry/syscalls/syscall_64.tbl
>>>> 24    common  sched_yield             sys_sched_yield
>>>> 142   common  sched_setparam          sys_sched_setparam
>>>> 143   common  sched_getparam          sys_sched_getparam
>>>> 144   common  sched_setscheduler      sys_sched_setscheduler
>>>> 145   common  sched_getscheduler      sys_sched_getscheduler
>>>> 146   common  sched_get_priority_max  sys_sched_get_priority_max
>>>> 147   common  sched_get_priority_min  sys_sched_get_priority_min
>>>> 148   common  sched_rr_get_interval   sys_sched_rr_get_interval
>>>> 203   common  sched_setaffinity       sys_sched_setaffinity
>>>> 204   common  sched_getaffinity       sys_sched_getaffinity
>>>> 314   common  sched_setattr           sys_sched_setattr
>>>> 315   common  sched_getattr           sys_sched_getattr
>>>> [hjl@gnu-6 linux-stable]$
>>>>
>>>> __cpu_mask should be __syscall_ulong_t.
>>>>
>>>>       [BZ #19313]
>>>>       * sysdeps/unix/sysv/linux/bits/sched.h (__cpu_mask): Replace
>>>>       unsigned long int with __syscall_ulong_t.
>>>
>>> How did you test this?
>>
>> I tested it on x32, i686 and x86-64.  Maybe we should add
>> __CPU_MASK_TYPE to bits/typesizes.h so that each
>> architecture can define it own type for __cpu_mask.
>
> The definition of __syscall_ulong_t, AFAICT, is always
> `unsigned long int`, which means the change does nothing?

That isn't true.  sysdeps/unix/sysv/linux/x86/bits/typesizes.h has

/* X32 kernel interface is 64-bit.  */
#if defined __x86_64__ && defined __ILP32__
# define __SYSCALL_SLONG_TYPE __SQUAD_TYPE
# define __SYSCALL_ULONG_TYPE __UQUAD_TYPE
#else
# define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
# define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
#endif


> Aren't both of these types the same size on x86_64 and
> x32?

That is correct.  But long long != long on x32.

> What exactly was the failure mode you saw in bug 19313?
>

I got

FAIL: nptl/tst-thread-affinity-pthread
FAIL: nptl/tst-thread-affinity-pthread2
FAIL: nptl/tst-thread-affinity-sched
FAIL: posix/tst-affinity
FAIL: posix/tst-affinity-pid

since size 12, which isn't multiple of 8, is passed to sched_getaffinity
syscall. We got 12 since __cpu_mask is unsigned long, instead of
unsigned long long.
  

Patch

diff --git a/sysdeps/unix/sysv/linux/bits/sched.h b/sysdeps/unix/sysv/linux/bits/sched.h
index ae089df..27d87c4 100644
--- a/sysdeps/unix/sysv/linux/bits/sched.h
+++ b/sysdeps/unix/sysv/linux/bits/sched.h
@@ -115,7 +115,7 @@  struct __sched_param
 # define __NCPUBITS	(8 * sizeof (__cpu_mask))
 
 /* Type for array elements in 'cpu_set_t'.  */
-typedef unsigned long int __cpu_mask;
+typedef __syscall_ulong_t __cpu_mask;
 
 /* Basic access functions.  */
 # define __CPUELT(cpu)	((cpu) / __NCPUBITS)