On 05/04/2018 02:04, Wanpeng Li wrote: >>> emulate_instruction(vcpu, 0) can handle invalid instruction. >> But David's observation is still better because your code doesn't handle usermode exits. > My code handles it, return emulate_instruction(vcpu, 0) == > EMULATE_DONE, it will return 0 since EMULATE_USER_EXIT == EMULATE_DONE > fails. > >> I've fixed this up. > Thanks. The codes similar to my v3 but more beauty. :) I change to > this view since Radim's comments to v3 > https://www.spinics.net/lists/kvm/msg166999.html And after I actually woke up I think I disagree with Radim. Tests can trap the #UD to test emulation at CPL0 and skip or fail the test for instructions unknown to the emulator. It's much better than sending an emulation failure to userspace, which would abort the guest. Paolo