If userspace blindly copies CPUID, but doesn't
enable the capability, the guest will think the hypercall is supported. The
guest hopefully won't freak out too much on the resulting -KVM_ENOSYS, but it
does make the CPUID flag rather useless.
The
guest hopefully won't freak out too much on the resulting -KVM_ENOSYS, but it
does make the CPUID flag rather useless.
We can make it work with:
u64 gpa = a0, npages = a1, enc = a2;
if (!guest_pv_has(vcpu, KVM_FEATURE_HC_PAGE_ENC_STATUS))
break;
if (!PAGE_ALIGNED(gpa) || !npages ||
gpa_to_gfn(gpa) + npages <= gpa_to_gfn(gpa)) {
ret = -EINVAL;
break;
}
if (!vcpu->kvm->arch.hypercall_exit_enabled) {
ret = 0;
break;
}
[...]
(BTW, it's better to return a bitmask of hypercalls that will exit to
userspace from KVM_CHECK_EXTENSION. Userspace can still reject with -ENOSYS
those that it doesn't know, but it's important that it knows in general how
to handle KVM_EXIT_HYPERCALL).
Speaking of bitmasks, what about also accepting a bitmask for enabling the
capability? (not sure if the above implies that). E.g.