how to add a hypercall in xen 4.13.0

会有一股神秘感。 提交于 2021-01-29 21:40:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!