问题
I tried to follow tutorials to add a new hypercall for xen, however all of them cannot work because there is no ENTRY(hypercall_table) in entry.S, how to add a new hypercall in recent version of xen?
回答1:
The easy way to create a custom hypercall is to watch how a simple one is declared and try to mimic the behavior. I did this and was able to successfully write one.
The following steps were reproduced in Xen 4.13
Let's assume that I want to create an attack
hypercall that will mimic some malicious behaviors inside Xen.
1 - Define the HC entry
xen/include/public/xen.h
#define __HYPERVISOR_arch_6 54
#define __HYPERVISOR_arch_7 55
/* Attack Emulation hypercall */
#define __HYPERVISOR_attack 56
2- Define its signature
/xen/include/xen/hypercall.h
extern long
do_attack(
int cmd,
XEN_GUEST_HANDLE_PARAM(void) arg);
3- Declare its page in the assembly source
/xen/arch/x86/guest/hypercall_page.S
DECLARE_HYPERCALL(attack)
4- Declare it for the HVM mode
/xen/arch/x86/hvm/hypercall.c
HYPERCALL(arch_1),
HYPERCALL(attack)
};
5- Declare the number of parameters that it would have
xen/arch/x86/hypercall.c
ARGS(arch_1, 1),
ARGS(attack, 2),
};
6- Declare its body:
/xen/common/kernel.c
DO(attack)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)`
{
printk("Entering Attack Hypercall:\t%d\n", cmd);
return 0;
}
来源:https://stackoverflow.com/questions/60564160/how-to-add-a-hypercall-in-xen-4-13-0