I think I've finally got my head round using HYPERVISOR_stack_switch. It seems to replace all my stack magic, and at least it's not crashing now.
However, I now have a different problem. I am running my context switch off of a single shot timer. When the timer fires Xen transfers control to my PV guest via the hypercall_callback.
The hypercall_callback handler stores the current CPU register file, however the stored rsp always points to the hypercall stack, not the stack that was active in my PV at the moment the timer event fired.
I need to store the PV stack pointer so I can recover it later when my scheduler activates it. I have looked back up the stack and I don't really see where my active stack pointer is. Any idea where I can get it?
Regards.