* [Xenomai] [PATCH] x86/ipipe: get FPU backup area allocated for all threads
@ 2013-09-30 19:21 Gilles Chanteperdrix
2013-10-04 8:33 ` Jan Kiszka
0 siblings, 1 reply; 8+ messages in thread
From: Gilles Chanteperdrix @ 2013-09-30 19:21 UTC (permalink / raw)
To: xenomai
In order to be able to handle FPU faults in the Xenomai domain without
switching to the root domain, the FPU backup area must be systematically
allocated for all Linux tasks. Currently, the backup area is systematically
allocated in arch_dup_task_struct(), but gets freed upon exec by
flush_thread(). Stop freeing it in flush_thread(), there does not seem
to be any risk of leaking information, as the "used_math" flag is cleared
by drop_init_fpui() so that upon next fault, the context is reinitialized.
---
arch/x86/kernel/process.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index a00bed1..4716eb2 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -73,14 +73,6 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
if (ret)
return ret;
fpu_copy(dst, src);
- } else {
-#ifdef CONFIG_IPIPE
- /* unconditionally allocate, RT domain may need it */
- memset(&dst->thread.fpu, 0, sizeof(dst->thread.fpu));
- ret = fpu_alloc(&dst->thread.fpu);
- if (ret)
- return ret;
-#endif
}
return 0;
}
@@ -170,8 +162,8 @@ void flush_thread(void)
* lazily at the first use.
*/
if (!use_eager_fpu())
-#endif
free_thread_xstate(tsk);
+#endif
}
static void hard_disable_TSC(void)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Xenomai] [PATCH] x86/ipipe: get FPU backup area allocated for all threads
2013-09-30 19:21 [Xenomai] [PATCH] x86/ipipe: get FPU backup area allocated for all threads Gilles Chanteperdrix
@ 2013-10-04 8:33 ` Jan Kiszka
2013-10-04 8:50 ` Gilles Chanteperdrix
2013-10-04 8:53 ` Gilles Chanteperdrix
0 siblings, 2 replies; 8+ messages in thread
From: Jan Kiszka @ 2013-10-04 8:33 UTC (permalink / raw)
To: Gilles Chanteperdrix; +Cc: xenomai
On 2013-09-30 21:21, Gilles Chanteperdrix wrote:
> In order to be able to handle FPU faults in the Xenomai domain without
> switching to the root domain, the FPU backup area must be systematically
> allocated for all Linux tasks. Currently, the backup area is systematically
> allocated in arch_dup_task_struct(), but gets freed upon exec by
> flush_thread(). Stop freeing it in flush_thread(), there does not seem
> to be any risk of leaking information, as the "used_math" flag is cleared
> by drop_init_fpui() so that upon next fault, the context is reinitialized.
How to reproduce the scenario? Would be good to document it in order to
check for regressions in future kernels.
> ---
> arch/x86/kernel/process.c | 10 +---------
> 1 file changed, 1 insertion(+), 9 deletions(-)
>
> diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
> index a00bed1..4716eb2 100644
> --- a/arch/x86/kernel/process.c
> +++ b/arch/x86/kernel/process.c
> @@ -73,14 +73,6 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
> if (ret)
> return ret;
> fpu_copy(dst, src);
> - } else {
> -#ifdef CONFIG_IPIPE
> - /* unconditionally allocate, RT domain may need it */
> - memset(&dst->thread.fpu, 0, sizeof(dst->thread.fpu));
> - ret = fpu_alloc(&dst->thread.fpu);
> - if (ret)
> - return ret;
> -#endif
Why removing the systematic allocation? This is not explained above and
seems counterproductive.
> }
> return 0;
> }
> @@ -170,8 +162,8 @@ void flush_thread(void)
> * lazily at the first use.
> */
> if (!use_eager_fpu())
> -#endif
> free_thread_xstate(tsk);
> +#endif
Yes, this makes sense. It was wrong in multiple ways.
> }
>
> static void hard_disable_TSC(void)
>
Jan
--
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Xenomai] [PATCH] x86/ipipe: get FPU backup area allocated for all threads
2013-10-04 8:33 ` Jan Kiszka
@ 2013-10-04 8:50 ` Gilles Chanteperdrix
2013-10-04 8:53 ` Jan Kiszka
2013-10-04 8:53 ` Gilles Chanteperdrix
1 sibling, 1 reply; 8+ messages in thread
From: Gilles Chanteperdrix @ 2013-10-04 8:50 UTC (permalink / raw)
To: Jan Kiszka; +Cc: xenomai
Jan Kiszka wrote:
> On 2013-09-30 21:21, Gilles Chanteperdrix wrote:
>> In order to be able to handle FPU faults in the Xenomai domain without
>> switching to the root domain, the FPU backup area must be systematically
>> allocated for all Linux tasks. Currently, the backup area is
>> systematically
>> allocated in arch_dup_task_struct(), but gets freed upon exec by
>> flush_thread(). Stop freeing it in flush_thread(), there does not seem
>> to be any risk of leaking information, as the "used_math" flag is
>> cleared
>> by drop_init_fpui() so that upon next fault, the context is
>> reinitialized.
>
> How to reproduce the scenario? Would be good to document it in order to
> check for regressions in future kernels.
Simply shadow the main thread, and use FPU in primary mode, without having
first used it in secondary mode. You should get a kernel oops.
We can add a test to switchtest, the problem is that switchtest purposedly
avoided to use FPU in the main thread before creating the other threads
to test threads which are not created with the "used_math" flag. But we can
use FPU after the other threads creation, right before the call to sigwait.
--
Gilles
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Xenomai] [PATCH] x86/ipipe: get FPU backup area allocated for all threads
2013-10-04 8:50 ` Gilles Chanteperdrix
@ 2013-10-04 8:53 ` Jan Kiszka
2013-10-04 8:57 ` Gilles Chanteperdrix
0 siblings, 1 reply; 8+ messages in thread
From: Jan Kiszka @ 2013-10-04 8:53 UTC (permalink / raw)
To: Gilles Chanteperdrix; +Cc: xenomai
On 2013-10-04 10:50, Gilles Chanteperdrix wrote:
>
> Jan Kiszka wrote:
>> On 2013-09-30 21:21, Gilles Chanteperdrix wrote:
>>> In order to be able to handle FPU faults in the Xenomai domain without
>>> switching to the root domain, the FPU backup area must be systematically
>>> allocated for all Linux tasks. Currently, the backup area is
>>> systematically
>>> allocated in arch_dup_task_struct(), but gets freed upon exec by
>>> flush_thread(). Stop freeing it in flush_thread(), there does not seem
>>> to be any risk of leaking information, as the "used_math" flag is
>>> cleared
>>> by drop_init_fpui() so that upon next fault, the context is
>>> reinitialized.
>>
>> How to reproduce the scenario? Would be good to document it in order to
>> check for regressions in future kernels.
>
> Simply shadow the main thread, and use FPU in primary mode, without having
> first used it in secondary mode. You should get a kernel oops.
>
> We can add a test to switchtest, the problem is that switchtest purposedly
> avoided to use FPU in the main thread before creating the other threads
> to test threads which are not created with the "used_math" flag. But we can
> use FPU after the other threads creation, right before the call to sigwait.
Yes, having an explicit test case would be great. Also important is to
avoid using a modern CPU with XSAVE support. Most of our target have
this feature now.
Jan
--
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Xenomai] [PATCH] x86/ipipe: get FPU backup area allocated for all threads
2013-10-04 8:33 ` Jan Kiszka
2013-10-04 8:50 ` Gilles Chanteperdrix
@ 2013-10-04 8:53 ` Gilles Chanteperdrix
2013-10-04 9:01 ` Jan Kiszka
1 sibling, 1 reply; 8+ messages in thread
From: Gilles Chanteperdrix @ 2013-10-04 8:53 UTC (permalink / raw)
To: Jan Kiszka; +Cc: xenomai
Jan Kiszka wrote:
>> diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
>> index a00bed1..4716eb2 100644
>> --- a/arch/x86/kernel/process.c
>> +++ b/arch/x86/kernel/process.c
>> @@ -73,14 +73,6 @@ int arch_dup_task_struct(struct task_struct *dst,
>> struct task_struct *src)
>> if (ret)
>> return ret;
>> fpu_copy(dst, src);
>> - } else {
>> -#ifdef CONFIG_IPIPE
>> - /* unconditionally allocate, RT domain may need it */
>> - memset(&dst->thread.fpu, 0, sizeof(dst->thread.fpu));
>> - ret = fpu_alloc(&dst->thread.fpu);
>> - if (ret)
>> - return ret;
>> -#endif
>
> Why removing the systematic allocation? This is not explained above and
> seems counterproductive.
Because when we stop deleting the fpu backup area upon exec, no fork ever
takes place for source thread without an fpu backup area. So, the "else"
clause never happens, and we can remove it entirely.
--
Gilles
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Xenomai] [PATCH] x86/ipipe: get FPU backup area allocated for all threads
2013-10-04 8:53 ` Jan Kiszka
@ 2013-10-04 8:57 ` Gilles Chanteperdrix
0 siblings, 0 replies; 8+ messages in thread
From: Gilles Chanteperdrix @ 2013-10-04 8:57 UTC (permalink / raw)
To: Jan Kiszka; +Cc: xenomai
Jan Kiszka wrote:
> On 2013-10-04 10:50, Gilles Chanteperdrix wrote:
>>
>> Jan Kiszka wrote:
>>> On 2013-09-30 21:21, Gilles Chanteperdrix wrote:
>>>> In order to be able to handle FPU faults in the Xenomai domain without
>>>> switching to the root domain, the FPU backup area must be
>>>> systematically
>>>> allocated for all Linux tasks. Currently, the backup area is
>>>> systematically
>>>> allocated in arch_dup_task_struct(), but gets freed upon exec by
>>>> flush_thread(). Stop freeing it in flush_thread(), there does not seem
>>>> to be any risk of leaking information, as the "used_math" flag is
>>>> cleared
>>>> by drop_init_fpui() so that upon next fault, the context is
>>>> reinitialized.
>>>
>>> How to reproduce the scenario? Would be good to document it in order to
>>> check for regressions in future kernels.
>>
>> Simply shadow the main thread, and use FPU in primary mode, without
>> having
>> first used it in secondary mode. You should get a kernel oops.
>>
>> We can add a test to switchtest, the problem is that switchtest
>> purposedly
>> avoided to use FPU in the main thread before creating the other threads
>> to test threads which are not created with the "used_math" flag. But we
>> can
>> use FPU after the other threads creation, right before the call to
>> sigwait.
>
> Yes, having an explicit test case would be great. Also important is to
> avoid using a modern CPU with XSAVE support. Most of our target have
> this feature now.
My tests machines do not have xsave.
--
Gilles
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Xenomai] [PATCH] x86/ipipe: get FPU backup area allocated for all threads
2013-10-04 8:53 ` Gilles Chanteperdrix
@ 2013-10-04 9:01 ` Jan Kiszka
2013-10-04 20:18 ` Gilles Chanteperdrix
0 siblings, 1 reply; 8+ messages in thread
From: Jan Kiszka @ 2013-10-04 9:01 UTC (permalink / raw)
To: Gilles Chanteperdrix; +Cc: xenomai
On 2013-10-04 10:53, Gilles Chanteperdrix wrote:
>
> Jan Kiszka wrote:
>>> diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
>>> index a00bed1..4716eb2 100644
>>> --- a/arch/x86/kernel/process.c
>>> +++ b/arch/x86/kernel/process.c
>>> @@ -73,14 +73,6 @@ int arch_dup_task_struct(struct task_struct *dst,
>>> struct task_struct *src)
>>> if (ret)
>>> return ret;
>>> fpu_copy(dst, src);
>>> - } else {
>>> -#ifdef CONFIG_IPIPE
>>> - /* unconditionally allocate, RT domain may need it */
>>> - memset(&dst->thread.fpu, 0, sizeof(dst->thread.fpu));
>>> - ret = fpu_alloc(&dst->thread.fpu);
>>> - if (ret)
>>> - return ret;
>>> -#endif
>>
>> Why removing the systematic allocation? This is not explained above and
>> seems counterproductive.
>
> Because when we stop deleting the fpu backup area upon exec, no fork ever
> takes place for source thread without an fpu backup area. So, the "else"
> clause never happens, and we can remove it entirely.
OK, please add this to the commit log.
Jan
--
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Xenomai] [PATCH] x86/ipipe: get FPU backup area allocated for all threads
2013-10-04 9:01 ` Jan Kiszka
@ 2013-10-04 20:18 ` Gilles Chanteperdrix
0 siblings, 0 replies; 8+ messages in thread
From: Gilles Chanteperdrix @ 2013-10-04 20:18 UTC (permalink / raw)
To: xenomai
In order to be able to handle FPU faults in the Xenomai domain without
switching to the root domain, an FPU context must be systematically
allocated for all Linux tasks. Currently, the FPU context is systematically
allocated in arch_dup_task_struct(), but gets freed upon exec by
flush_thread(). Stop freeing it in flush_thread(), there does not seem
to be any risk of leaking information, as the "used_math" flag is cleared
by drop_init_fpu() so that upon next fault, the context is reinitialized.
Also stop creating an FPU context in arch_dup_task_struct() if the source
taks does not have one, as there are no longer any task without an FPU context.
---
arch/x86/kernel/process.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index a00bed1..4716eb2 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -73,14 +73,6 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
if (ret)
return ret;
fpu_copy(dst, src);
- } else {
-#ifdef CONFIG_IPIPE
- /* unconditionally allocate, RT domain may need it */
- memset(&dst->thread.fpu, 0, sizeof(dst->thread.fpu));
- ret = fpu_alloc(&dst->thread.fpu);
- if (ret)
- return ret;
-#endif
}
return 0;
}
@@ -170,8 +162,8 @@ void flush_thread(void)
* lazily at the first use.
*/
if (!use_eager_fpu())
-#endif
free_thread_xstate(tsk);
+#endif
}
static void hard_disable_TSC(void)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-10-04 20:18 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-30 19:21 [Xenomai] [PATCH] x86/ipipe: get FPU backup area allocated for all threads Gilles Chanteperdrix
2013-10-04 8:33 ` Jan Kiszka
2013-10-04 8:50 ` Gilles Chanteperdrix
2013-10-04 8:53 ` Jan Kiszka
2013-10-04 8:57 ` Gilles Chanteperdrix
2013-10-04 8:53 ` Gilles Chanteperdrix
2013-10-04 9:01 ` Jan Kiszka
2013-10-04 20:18 ` Gilles Chanteperdrix
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.