trap bounce flags
With the severe stability issues we are having with SLE10sp1 on x86-64, things start pointing pretty closely at the int80 direct trap patch we imported from -unstable. While I just now realized that there's been a fix for these problems for quite a while (don't know how this slipped my attention), I still have a few notes:
- even compat_restore_all_guest now asserts interrupts are disabled, despite 32-bit restore_all_guest not doing so (and the iret path not generally needing this)
- int80_direct_trap checks for non-zero TRAPBOUNCE_flags, yet {,compat_}create_bounce_frame clear the low byte of these flags (i.e. including TBF_exception, which is in this lower byte); it appears to be only a lucky coincidence that this still works as the cmp (again!) is suffix-less and hence gets sized as a 32-bit compare, accidentally covering TRAPBOUNCE_cs
- from the above, why is it that only the lower byte (if anything) needs clearing?
Jan
Quoted 3 lines · Jan Beulich
- even
compat_restore_all_guestnow asserts interrupts are disabled, despite 32-bitrestore_all_guestnot doing so (and the iret path not generally needing this)
The 32-bit restore_all_guest ought to have the assertion added. I must have forgotten about it. Interrupts need to be disabled during return to guest so that the tests for softirq work and event-notification to the guest do not race against new interrupts. Of course this issue is much less fatal than the restore-rsp;sysret bug!
Quoted 5 lines
-
int80_direct_trapchecks for non-zeroTRAPBOUNCE_flags, yet {,compat_}create_bounce_frame clear the low byte of these flags (i.e. includingTBF_exception, which is in this lower byte); it appears to be only a lucky coincidence that this still works as the cmp (again!) is suffix-less and hence gets sized as a 32-bit compare, accidentallycoveringTRAPBOUNCE_cs
Ooo, good catch. It's a tiny bit gross but the best fix is probably just to restore the flags field after the call to create_bounce_frame. And of course change the cmp to a cmpb. Agree?
Quoted 2 lines
- from the above, why is it that only the lower byte (if anything) needs clearing?
Really it's a one-byte field: it's consistently treated that way in asm code. The upper byte is always zero. We should probably make the field explicitly uint8_t. Agree?
-- Keir
Quoted 6 lines · Keir Fraser
Quoted 2 lines
- from the above, why is it that only the lower byte (if anything) needs clearing?
Really it's a one-byte field: it's consistently treated that way in asm code. The upper byte is always zero. We should probably make the field explicitly
uint8_t. Agree?
FYI, we need to clear that field usually because the contents are one-shot but the structure itself is permanent and checked on every return to guest. A non-zero flags field is what we use to indicate whether the structure is 'primed' or not. So the passing in of a different, non-one-shot, structure on the direct-int80 path is a bit abusive of the interface. But I think we can live with it if we reset the flags field manually and include a comment. :-)
-- Keir
Quoted 9 lines
Quoted 5 lines
-
int80_direct_trapchecks for non-zeroTRAPBOUNCE_flags, yet {,compat_}create_bounce_frame clear the low byte of these flags (i.e. includingTBF_exception, which is in this lower byte); it appears to be only a lucky coincidence that this still works as the cmp (again!) is suffix-less and hence gets sized as a 32-bit compare, accidentallycoveringTRAPBOUNCE_csOoo, good catch. It's a tiny bit gross but the best fix is probably just to restore the flags field after the call to
create_bounce_frame. And of course change the cmp to a cmpb. Agree?
That's the alternative solution I considered. The preferable one is to do the compat/native distinction before the null check, and then be consistent with the rest of the code and check cs for 32-bit guest and eip for 64-bit ones. That's how I'm preparing a patch right now.
Quoted 6 lines
Quoted 2 lines
- from the above, why is it that only the lower byte (if anything) needs clearing?
Really it's a one-byte field: it's consistently treated that way in asm code. The upper byte is always zero. We should probably make the field explicitly
uint8_t. Agree?
Making it a uint8_t is fine. It is, however, far from being consistently handled in assembly code:x86_32/entry.S: 4 word refs and 3 byte refsx86_64/entry.S: 6 word refs, 3 byte refs, and one size-less ref x86_64/compat/entry.S: 4 word refs and 3 byte refs
Jan
Quoted 4 lines · Jan Beulich
That's the alternative solution I considered. The preferable one is to do the compat/native distinction before the null check, and then be consistent with the rest of the code and check cs for 32-bit guest and eip for 64-bit ones. That's how I'm preparing a patch right now.
Attached is my own proposed patch which I think cleans up all the issues. Checking just flags in asm and keeping the null-bounce check in init_int80_direct_trap() seems fine to me.
-- Keir
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
- from the above, why is it that only the lower byte (if anything) needs clearing?
Really it's a one-byte field: it's consistently treated that way in asm code. The upper byte is always zero. We should probably make the field explicitly
uint8_t. Agree?
Quoted 6 lines
Making it a
uint8_tis fine. It is, however, far from being consistently handled
in assembly code:x86_32/entry.S: 4 word refs and 3 byte refsx86_64/entry.S: 6 word refs, 3 byte refs, and one size-less refx86_64/compat/entry.S: 4 word refs and 3 byte refs
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 3 lines · Keir Fraser
Attached is my own proposed patch which I think cleans up all the issues. Checking just flags in asm and keeping the null-bounce check in
init_int80_direct_trap()seems fine to me.
The change of a movw $0 to a movb $TBF_EXCEPTION in that patch is wrong, by the way. Should be movb $0.
-- Keir
Quoted 9 lines
Quoted 1 line
Quoted 1 line
Keir Fraser <[email protected]> 25.04.07 12:56 >>>
Quoted 3 lines · Keir Fraser
Attached is my own proposed patch which I think cleans up all the issues. Checking just flags in asm and keeping the null-bounce check in
init_int80_direct_trap()seems fine to me.The change of a movw $0 to a movb $TBF_EXCEPTION in that patch is wrong, by the way. Should be movb $0.
Which means there's not really a dependency on this being non-zero...
The patch looks otherwise okay to me, though I think there's one more issue here: There's another suffix-less instruction (updating UREGS_rip in int80_slow_path) - this must be a subq, and it must imply that no 32-bit guest places an int $0x80 at 0xfffffffe.
And my patch has a not directly related adjustment removing the
movl $TRAP_syscall,UREGS_entry_vector+8(%rsp)
close to the end of compat_create_bounce_frame, as this is meaningless here.
Jan
Quoted 1 line · Jan Beulich
Which means there's not really a dependency on this being non-zero...
Yeah, I limited that dependency just to the handle_exception path. It now zeroes the flags field itself which. It might be even cleaner to host the zero of the flags field to before the indirect call to the exception-specific C handler (that's the only thing that might set up the bounce structure).
Quoted 4 lines
The patch looks otherwise okay to me, though I think there's one more issue here: There's another suffix-less instruction (updating
UREGS_ripinint80_slow_path) - this must be a subq, and it must imply that no 32-bit guest places an int $0x80 at0xfffffffe.
Yep.
Quoted 6 lines
And my patch has a not directly related adjustment removing the
movl $TRAP_syscall,UREGS_entry_vector+8(%rsp)
close to the end of
compat_create_bounce_frame, as this is meaningless here.
Should we also remove it from compat_hypercall?
-- Keir
Quoted 8 lines
Quoted 6 lines
And my patch has a not directly related adjustment removing the
movl $TRAP_syscall,UREGS_entry_vector+8(%rsp)
close to the end of
compat_create_bounce_frame, as this is meaningless here.Should we also remove it from
compat_hypercall?
Probably not, to be able to identify the frame properly in case something crashes in the process of handling the hypercall.
Jan