|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH 2/2] x86/pv: Provide better SYSCALL backwards compatibility in FRED mode
On 25.03.2026 18:02, Andrew Cooper wrote: > In FRED mode, the SYSCALL instruction does not modify %rcx/%r11. Software > using SYSCALL spills %rcx/%r11 around the invocation, which is why FRED not > doing this goes largely unnoticed. > > However, consider the following migration scenario: > > * VM suspends. Hypercall, so SYSCALL, %rcx/%r11 left unmodified > * VM moves to a non-FRED system > * Xen resumes the VM with a real SYSRET instruction > > Instead of resuming at the instruction following the SYSCALL instruction, the > VM is resumed at whatever dead value was in %rcx. Would it? In restore_all_guest we load %r11 and %rcx from the stack frame's EFLAGS and RIP fields. If we didn't, various other things wouldn't work either. > --- a/xen/arch/x86/traps.c > +++ b/xen/arch/x86/traps.c > @@ -2405,6 +2405,8 @@ void asmlinkage entry_from_pv(struct cpu_user_regs > *regs) > > regs->ssx = l ? FLAT_KERNEL_SS : FLAT_USER_SS32; > regs->csx = l ? FLAT_KERNEL_CS64 : FLAT_USER_CS32; > + regs->rcx = regs->rip; > + regs->r11 = regs->rflags; Don't you also need to set TRAP_syscall here, for the new code in eretu_exit_to_guest to actually make a difference? (There actually is a paragraph about this in the comment out of context above, which then may also want adjusting.) Further a question as to limiting overhead: Doing this on every SYSCALL entry ... > @@ -26,7 +27,16 @@ FUNC(entry_FRED_R3, 4096) > END(entry_FRED_R3) > > FUNC(eretu_exit_to_guest) > - POP_GPRS > + /* > + * PV guests aren't aware of FRED. If Xen in IDT mode would have > used > + * a SYSRET instruction, preserve the legacy behaviour for %rcx/%r11 > + */ > + testb $TRAP_syscall >> 8, UREGS_entry_vector + 1(%rsp) > + > + POP_GPRS /* Preserves flags */ > + > + cmovnz EFRAME_rip(%rsp), %rcx > + cmovnz EFRAME_eflags(%rsp), %r11 ... and every exit-to-guest isn't very nice when concern is about just the specific case of migrating FRED -> non-FRED. Couldn't we instead make the adjustment when generating the save record for the register state of the vCPU? Jan
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |