云计算 作业3

Homework 3


Q1:Write a hypercall in KVM

A hypercall is a way for a guest OS to make a call to the hypervisor, in some ways similar to how a system call allows an applicaon to make a call to the OS. We are asking you to write a hypercall to become familiar with how they work and the codebase for KVM. For this part of the assignment, you will also set up your VM so you can use it for your hypercall development.
The hypercall you write should take one argument and output the informaon about virtual CPU in KVM. Modern architectures provide special support for virtualizaon and add a privileged instrucon for hypercalls, which you will use in this part of the assignment. Rather than using the default kernel that comes with Ubuntu 14.04.5, you should download and build a more recent version of the Linux kernel, kernel version 4.10, and install that in your VM. It will be this updated version of the kernel/KVM source that you will modify to implement your hypercall.

Q2: Test your new hypercall

To test your new hypercall, you will install your modificaons in the guest kernel running in your nested VM for tesng. As menoned earlier, the instrucon that iniates a hypercall is a privileged instrucon and cannot be executed in user mode. To test the hypercall from user space, you need to add a new system call in your guest kernel which in turn calls to the vcpu_info. The prototype of the system call can be defined as the following.

int sys_vcpu_info(void);

Answer:

  1. Download the Linux v4.10 mainline kernel source
$ git clone https://github.com/torvalds/linux.git -b v4.10
  1. In the Linux source directory, copy the ubuntu config to kernel source
$ cp /boot/config-#YOUR_UBUNTU_VERSION .config
$ yes "" | make oldconfig
  1. Install proper packages for the kernel compile.
$ sudo apt-get install libssl-dev bc libncurses-dev
  1. Run the following command to configure kernel.
$ make menuconfig

To enable race in your KVM host, go to Kernel Hacking and select Tracers . Then enter Tracers , select both Kernel Function Tracer and Kernel Function Graph Tracer . Finally, save the config and exit.

  1. Add system call.

    Add int sys_vcpu_info(void) into sys.c :

    asmlinkage int sys_vcpu_info(void){
       char id[30];
       unsigned   long   s1,s2,s3,s4;
       char   sel;         
       asm volatile         
       ( "movl $0x01 , %%eax ; \n\t"      
       "xorl %%edx , %%edx ;\n\t"      
       "cpuid ;\n\t"       
       "movl %%edx ,%0 ;\n\t"      
       "movl %%eax ,%1 ; \n\t"      
       :"=m"(s1),"=m"(s2)      );            
       //printf("%08X-%08X-",s1,s2);      
       asm volatile         
       ("movl $0x03,%%eax ;\n\t"      
       "xorl %%ecx,%%ecx ;\n\t"      
       "xorl %%edx,%%edx ;\n\t"   
       "cpuid ;\n\t"      
       "movl %%edx,%0 ;\n\t"      
       "movl %%ecx,%1 ;\n\t"      
       :"=m"(s3),"=m"(s4)      );         
       vcpu_info(id);    
       return id;     
     }
    

    Add declaraon in syscalls.h .
    Add ID for system calling:
    In guest kernel source code, add the system call that calls the hypercall and Implement the syscall to call the hypercall. Then in host kernel source code, define the hypercall number (include/uapi/linux/kvm_para.h) and print “Hello World” as the hypercall code (arch/x86/kvm/x86.c)

  2. Aer you add your hypercall to your Linux/KVM source, use the following command to compile the kernel.

$ make -j8
  1. Finally, use the following command to install the new kernel to your system. The new kernel will be loaded in the next boot.
$ make modules_install
$ make install
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值