Re: [patch] Re: [2.1.117] GPF in APM while using WINE

Linus Torvalds (torvalds@transmeta.com)
Mon, 24 Aug 1998 10:32:51 -0700 (PDT)


On Mon, 24 Aug 1998, MOLNAR Ingo wrote:
>
> hm, the problem is that the APM bottom half runs during context switching.
> When the bh is executed at a point where we have already switched the LDT,
> but have not yet saved the segments, it can cause a crash by
> saving/restoring illegal segment registers.

Oh, Gods. Ugh.

Yes, the reason this didn't show up before was that we had interrupts
effectively disabled for the whole context switch (simply because we did
it with a single instruction and thus the CPU wouldn't accept interrupts
until it was all done..)

> - make the switch_to() code safe wrt segment saves without
> disabling IRQs, by zeroing out segment registers. (zeroing
> segment registers takes exactly 1 cycle on my PII)

This looks like a reasonable solution, especially as we only need to do
this when we reload the LDT. However...

> is there any other place in the kernel where segment registers might hold
> invalid contents?

There are cases where a user can force a bad segment into %fs and %gs by
loading a new LDT - the kernel won't care. It has the logic to cleanly
reload zero segments in the normal paths.

I would suggest that instead of your patch to __switch_to(), the APM code
should probably re-load %fs and %gs with

loadsegment(fs, value);
loadsegment(gs, value);

which correctly takes the GP trap and loads a zero if the value was bad
using the normal exception mechanism (ie no overhead at all except for the
case where it actually traps).

That will work correctly for both the case where a interrupt happened
while the segments hadn't yet been updated, AND for the case (which can be
synchronous) where a user had invalidated the segment pointed to by
%fs/%gs.

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html