Skip to contentSkip to conversation

Is it safe to assume that v == current in hvm_do_resume()?

DISCUSSION Razvan Cojocaru 2 participants 3 messages Oct 22, 2014

lore
Share & tools
lore
#0 lore raw

Hello,

As far as I've understood the code, and based on several tests, it would appear that in xen/arch/x86/hvm/hvm.c, the struct vcpu *v parameter to hvm_do_resume() is always equal to current.

Is that a reasonable assumption to make? I could have missed some use cases for the function.

Thanks,
Razvan

#1 lore raw
Quoted 8 lines · Razvan Cojocaru

Hello,

As far as I've understood the code, and based on several tests, it would appear that in xen/arch/x86/hvm/hvm.c, the struct vcpu *v parameter to hvm_do_resume() is always equal to current.

Is that a reasonable assumption to make? I could have missed some use cases for the function.

The calls look like this:

{vmx,svm}_do_resume is the schedule_tail function pointer, which is a no-return function and called on the way out of a context switch.

They call hvm_do_resume() followed by a reset_stack_and_jump() to {vmx,svm}_asm_do_vmentry.

So yes - you can be guaranteed that the v in hvm_do_resume() is current.

If you do come to explicitly rely on this behaviour, and it is in any way unclear, it might be worth introducing an ASSERT(v == current) near to the expectation.

~Andrew

#2 lore raw
Quoted 15 lines · Andrew Cooper
Quoted 8 lines · Razvan Cojocaru

Hello,

As far as I've understood the code, and based on several tests, it would appear that in xen/arch/x86/hvm/hvm.c, the struct vcpu *v parameter to hvm_do_resume() is always equal to current.

Is that a reasonable assumption to make? I could have missed some use cases for the function.

The calls look like this:

{vmx,svm}_do_resume is the schedule_tail function pointer, which is a no-return function and called on the way out of a context switch.

Quoted 8 lines

They call hvm_do_resume() followed by a reset_stack_and_jump() to {vmx,svm}_asm_do_vmentry.

So yes - you can be guaranteed that the v in hvm_do_resume() is current.

If you do come to explicitly rely on this behaviour, and it is in any way unclear, it might be worth introducing an ASSERT(v == current) near to the expectation.

Thanks for the confirmation!

Indeed, I had placed an ASSERT() before the code that needs v == current.

Thanks,
Razvan