public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] i386: remove IOPL check on task switch
@ 2006-11-03  6:27 Chuck Ebbert
  2006-11-03 18:06 ` Zachary Amsden
  0 siblings, 1 reply; 10+ messages in thread
From: Chuck Ebbert @ 2006-11-03  6:27 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, Andrew Morton, Zachary Amsden, Andi Kleen

IOPL is implicitly saved and restored on task switch,
so explicit check is no longer needed.

Signed-off-by: Chuck Ebbert <76306.1226@compuserve.com>

--- 2.6.19-rc4-32smp.orig/arch/i386/kernel/process.c
+++ 2.6.19-rc4-32smp/arch/i386/kernel/process.c
@@ -681,12 +681,6 @@ struct task_struct fastcall * __switch_t
 		loadsegment(gs, next->gs);
 
 	/*
-	 * Restore IOPL if needed.
-	 */
-	if (unlikely(prev->iopl != next->iopl))
-		set_iopl_mask(next->iopl);
-
-	/*
 	 * Now maybe handle debug registers and/or IO bitmaps
 	 */
 	if (unlikely((task_thread_info(next_p)->flags & _TIF_WORK_CTXSW)
-- 
Chuck
"Even supernovas have their duller moments."

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

* Re: [patch] i386: remove IOPL check on task switch
  2006-11-03  6:27 Chuck Ebbert
@ 2006-11-03 18:06 ` Zachary Amsden
  2006-11-03 18:41   ` Andi Kleen
  0 siblings, 1 reply; 10+ messages in thread
From: Zachary Amsden @ 2006-11-03 18:06 UTC (permalink / raw)
  To: Chuck Ebbert; +Cc: linux-kernel, Linus Torvalds, Andrew Morton, Andi Kleen

Chuck Ebbert wrote:
> IOPL is implicitly saved and restored on task switch,
> so explicit check is no longer needed.
>
> Signed-off-by: Chuck Ebbert <76306.1226@compuserve.com>
>
> --- 2.6.19-rc4-32smp.orig/arch/i386/kernel/process.c
> +++ 2.6.19-rc4-32smp/arch/i386/kernel/process.c
> @@ -681,12 +681,6 @@ struct task_struct fastcall * __switch_t
>  		loadsegment(gs, next->gs);
>  
>  	/*
> -	 * Restore IOPL if needed.
> -	 */
> -	if (unlikely(prev->iopl != next->iopl))
> -		set_iopl_mask(next->iopl);
> -
> -	/*
>  	 * Now maybe handle debug registers and/or IO bitmaps
>  	 */
>  	if (unlikely((task_thread_info(next_p)->flags & _TIF_WORK_CTXSW)
>   

Nack.  This is used for paravirt-ops kernels that use IOPL'd userspace.  
Fixing it would require a fairly heavy penalty on the iret path, since 
every single instruction there contributes to a critical region which 
must have custom fixup code, or some other technique to provide 
protection against interrupt re-entrancy.

At least, let's discuss other potential solutions first - for now it is 
harmless.

Zach

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

* Re: [patch] i386: remove IOPL check on task switch
  2006-11-03 18:06 ` Zachary Amsden
@ 2006-11-03 18:41   ` Andi Kleen
  0 siblings, 0 replies; 10+ messages in thread
From: Andi Kleen @ 2006-11-03 18:41 UTC (permalink / raw)
  To: Zachary Amsden; +Cc: Chuck Ebbert, linux-kernel, Linus Torvalds, Andrew Morton

 
> Nack.  This is used for paravirt-ops kernels that use IOPL'd userspace.  
> Fixing it would require a fairly heavy penalty on the iret path, since 
> every single instruction there contributes to a critical region which 
> must have custom fixup code, or some other technique to provide 
> protection against interrupt re-entrancy.
> 
> At least, let's discuss other potential solutions first - for now it is 
> harmless.

Ok I will drop the patch again

-Andi

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

* Re: [patch] i386: remove IOPL check on task switch
@ 2006-11-03 23:57 Chuck Ebbert
  2006-11-04 19:19 ` Zachary Amsden
  0 siblings, 1 reply; 10+ messages in thread
From: Chuck Ebbert @ 2006-11-03 23:57 UTC (permalink / raw)
  To: Zachary Amsden; +Cc: Andi Kleen, Andrew Morton, Linus Torvalds, linux-kernel

In-Reply-To: <454B850C.3050402@vmware.com>

On Fri, 03 Nov 2006 10:06:04 -0800, Zachary Amsden wrote:

> Chuck Ebbert wrote:
> > IOPL is implicitly saved and restored on task switch,
> > so explicit check is no longer needed.
> 
> Nack.  This is used for paravirt-ops kernels that use IOPL'd userspace.  

How does that work?  In the stock kernel, anything done by
the call to set_iopl_mask() (that was removed by the patch)
will be nullified by the 'popfl' at the end of the switch_to()
macro.

-- 
Chuck
"Even supernovas have their duller moments."

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

* Re: [patch] i386: remove IOPL check on task switch
@ 2006-11-04  0:00 Chuck Ebbert
  0 siblings, 0 replies; 10+ messages in thread
From: Chuck Ebbert @ 2006-11-04  0:00 UTC (permalink / raw)
  To: Zachary Amsden; +Cc: Andi Kleen, Andrew Morton, Linus Torvalds, linux-kernel

In-Reply-To: <454B850C.3050402@vmware.com>

On Fri, 03 Nov 2006 10:06:04 -0800, Zachary Amsden wrote:

> Chuck Ebbert wrote:
> > IOPL is implicitly saved and restored on task switch,
> > so explicit check is no longer needed.
> 
> Nack.  This is used for paravirt-ops kernels that use IOPL'd userspace.  

How does that work?  In the stock kernel, anything done by
the call to set_iopl_mask() (that was removed by the patch)
will be nullified by the 'popfl' at the end of the switch_to()
macro.

-- 
Chuck
"Even supernovas have their duller moments."

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

* Re: [patch] i386: remove IOPL check on task switch
  2006-11-03 23:57 [patch] i386: remove IOPL check on task switch Chuck Ebbert
@ 2006-11-04 19:19 ` Zachary Amsden
  2006-11-04 19:39   ` Zachary Amsden
  0 siblings, 1 reply; 10+ messages in thread
From: Zachary Amsden @ 2006-11-04 19:19 UTC (permalink / raw)
  To: Chuck Ebbert; +Cc: Andi Kleen, Andrew Morton, Linus Torvalds, linux-kernel

Chuck Ebbert wrote:
> In-Reply-To: <454B850C.3050402@vmware.com>
>
> On Fri, 03 Nov 2006 10:06:04 -0800, Zachary Amsden wrote:
>
>   
>> Chuck Ebbert wrote:
>>     
>>> IOPL is implicitly saved and restored on task switch,
>>> so explicit check is no longer needed.
>>>       
>> Nack.  This is used for paravirt-ops kernels that use IOPL'd userspace.  
>>     
>
> How does that work?  In the stock kernel, anything done by
> the call to set_iopl_mask() (that was removed by the patch)
> will be nullified by the 'popfl' at the end of the switch_to()
> macro.
>   

Who put a popfl back in switch_to?  I took it out some time ago.  It 
should not be there.  The only reason for it was to stop IOPL leaking 
from one process to another from a sleep during a sysenter based system 
call.

Zach

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

* Re: [patch] i386: remove IOPL check on task switch
  2006-11-04 19:19 ` Zachary Amsden
@ 2006-11-04 19:39   ` Zachary Amsden
  2006-11-04 19:52     ` Linus Torvalds
  2006-11-04 20:02     ` Andi Kleen
  0 siblings, 2 replies; 10+ messages in thread
From: Zachary Amsden @ 2006-11-04 19:39 UTC (permalink / raw)
  To: Zachary Amsden
  Cc: Chuck Ebbert, Andi Kleen, Andrew Morton, Linus Torvalds,
	linux-kernel

Zachary Amsden wrote:
> Chuck Ebbert wrote:
>> In-Reply-To: <454B850C.3050402@vmware.com>
>>
>> On Fri, 03 Nov 2006 10:06:04 -0800, Zachary Amsden wrote:
>>
>>  
>>> Chuck Ebbert wrote:
>>>    
>>>> IOPL is implicitly saved and restored on task switch,
>>>> so explicit check is no longer needed.
>>>>       
>>> Nack.  This is used for paravirt-ops kernels that use IOPL'd 
>>> userspace.      
>>
>> How does that work?  In the stock kernel, anything done by
>> the call to set_iopl_mask() (that was removed by the patch)
>> will be nullified by the 'popfl' at the end of the switch_to()
>> macro.
>>   
>
> Who put a popfl back in switch_to?  I took it out some time ago.  It 
> should not be there.  The only reason for it was to stop IOPL leaking 
> from one process to another from a sleep during a sysenter based 
> system call.

Ok, checking shows Linus put it back to stop NT leakage.  This is 
correct, but unlikely.  Would be nice to avoid it unless absolutely 
necessary.  Perhaps xor eflags old and new and only set_system_eflags() 
if non-ALU bits have changed.

Zach

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

* Re: [patch] i386: remove IOPL check on task switch
  2006-11-04 19:39   ` Zachary Amsden
@ 2006-11-04 19:52     ` Linus Torvalds
  2006-11-04 20:09       ` Zachary Amsden
  2006-11-04 20:02     ` Andi Kleen
  1 sibling, 1 reply; 10+ messages in thread
From: Linus Torvalds @ 2006-11-04 19:52 UTC (permalink / raw)
  To: Zachary Amsden; +Cc: Chuck Ebbert, Andi Kleen, Andrew Morton, linux-kernel



On Sat, 4 Nov 2006, Zachary Amsden wrote:
>
> Ok, checking shows Linus put it back to stop NT leakage.  This is correct, but
> unlikely.  Would be nice to avoid it unless absolutely necessary.  Perhaps xor
> eflags old and new and only set_system_eflags() if non-ALU bits have changed.

Not just NT. AC also leaked, and caused crashes in other programs (Wine) 
that didn't expect AC to be set and did unaligned accesses.

		Linus

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

* Re: [patch] i386: remove IOPL check on task switch
  2006-11-04 19:39   ` Zachary Amsden
  2006-11-04 19:52     ` Linus Torvalds
@ 2006-11-04 20:02     ` Andi Kleen
  1 sibling, 0 replies; 10+ messages in thread
From: Andi Kleen @ 2006-11-04 20:02 UTC (permalink / raw)
  To: Zachary Amsden; +Cc: Chuck Ebbert, Andrew Morton, Linus Torvalds, linux-kernel

 
> Ok, checking shows Linus put it back to stop NT leakage. 

It is also needed to stop AC leakage

> This is  
> correct, but unlikely.  Would be nice to avoid it unless absolutely 
> necessary.  Perhaps xor eflags old and new and only set_system_eflags() 
> if non-ALU bits have changed.

If it's worth it...

If it's worth for the context switch i think it would make 
more sense to do it for the normal restore_flags() etc. which are much
more common (and could be actually handled in most cases with test + jump + sti)

-Andi

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

* Re: [patch] i386: remove IOPL check on task switch
  2006-11-04 19:52     ` Linus Torvalds
@ 2006-11-04 20:09       ` Zachary Amsden
  0 siblings, 0 replies; 10+ messages in thread
From: Zachary Amsden @ 2006-11-04 20:09 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Chuck Ebbert, Andi Kleen, Andrew Morton, linux-kernel

Linus Torvalds wrote:
> On Sat, 4 Nov 2006, Zachary Amsden wrote:
>   
>> Ok, checking shows Linus put it back to stop NT leakage.  This is correct, but
>> unlikely.  Would be nice to avoid it unless absolutely necessary.  Perhaps xor
>> eflags old and new and only set_system_eflags() if non-ALU bits have changed.
>>     
>
> Not just NT. AC also leaked, and caused crashes in other programs (Wine) 
> that didn't expect AC to be set and did unaligned accesses.

Yes, AC, NT, IOPL, ID are bad to leak.  DF / TF / RF are impossible to 
leak by privilege contract.  SF, ZF, PF, OF, CF can be clobbered.

VM / VIF / VIP are dealt with in separate switch paths (although I have 
witnessed a VIF leak once from a userspace process that managed to get 
VIF set).  These can't even be set with popf, and require iret to fix.

But 99% of the time, only SF / ZF / PF / OF / CF will be different, so 
you can avoid the popf.

Zach

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

end of thread, other threads:[~2006-11-04 20:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-03 23:57 [patch] i386: remove IOPL check on task switch Chuck Ebbert
2006-11-04 19:19 ` Zachary Amsden
2006-11-04 19:39   ` Zachary Amsden
2006-11-04 19:52     ` Linus Torvalds
2006-11-04 20:09       ` Zachary Amsden
2006-11-04 20:02     ` Andi Kleen
  -- strict thread matches above, loose matches on Subject: below --
2006-11-04  0:00 Chuck Ebbert
2006-11-03  6:27 Chuck Ebbert
2006-11-03 18:06 ` Zachary Amsden
2006-11-03 18:41   ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox