Re: [PATCH 3/4] x86/sgx: Fine grained SGX MCA behavior for virtualization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2022/5/12 07:33, Kai Huang wrote:
>> +			ret = force_sig_mceerr(BUS_MCEERR_AR, (void __user *)owner->vaddr,
>> +					PAGE_SHIFT);
> If I understand correctly, this sends signal to the userspace hypervisor, i.e.
> Qemu?  Can you elaborate how is KVM supposed to inject the #MC to guest, instead
> of Qemu process (the VM) being killed?
> 

Yes, here we use the facility that Qemu already has.
The basic call path as below:

sigbus_handler
  kvm_on_sigbus
    kvm_arch_on_sigbus_vcpu
      qemu_ram_addr_from_host
      kvm_physical_memory_addr_from_host
      kvm_hwpoison_page_add
      kvm_mce_inject
        cpu_x86_inject_mce

1. At first when Qemu init, it will register sigbus_handler() as its SIGBUS handler
   at qemu_init_sigbus().
2. At sigbus_handler() it will filter-out the signal which siginfo->si_code is not
   BUS_MCEERR_AO or BUS_MCEERR_AR, and then re-raise SIGBUS signal.
   If the si_code is BUS_MCEERR_AO or BUS_MCEERR_AR, it will invoke
   kvm_on_sigbus(siginfo->si_code, siginfo->si_addr), go on handling the signal.
3. kvm_on_sigbus() is a simple generic wrap which will call arch specific
   kvm_arch_on_sigbus_vcpu()
4. kvm_arch_on_sigbus_vcpu() is x86 specific implementation, it will do following
   1) Convert HVA (addr) to HPA (ram_addr)
      ram_addr = qemu_ram_addr_from_host(addr)
   2) Retrieve the GPA (paddr) as per HVA (addr)
      kvm_physical_memory_addr_from_host(c->kvm_state, addr, &paddr)
   3) Add the page including HWPoison HPA to its hwpoison_page_list
      kvm_hwpoison_page_add(ram_addr)
   4) Inject the #MC to guest with GPA and si_code
      kvm_mce_inject(cpu, paddr, code)
        cpu_x86_inject_mce()

The rest is guest kernel uses the existed MCA to handle the #MC. According to the
physical address (in fact, GPA) find the applications and send kill signal if the
#MC is SRAR.

So the intention of this patchset is to enrich the information when sending
SIGBUS, so that VMM can use already existed facility to take a proper behavior.

Best Regards,
Zhiquan

> 
> -- Thanks, -Kai



[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux