On 02/09/2024 14:25, Matias Ezequiel Vara Larsen wrote: > Hello Steven, > > On Wed, Aug 21, 2024 at 04:38:22PM +0100, Steven Price wrote: ... >> +static int private_memslot_fault(struct kvm_vcpu *vcpu, >> + phys_addr_t fault_ipa, >> + struct kvm_memory_slot *memslot) >> +{ >> + struct kvm *kvm = vcpu->kvm; >> + gpa_t gpa_stolen_mask = kvm_gpa_stolen_bits(kvm); >> + gfn_t gfn = (fault_ipa & ~gpa_stolen_mask) >> PAGE_SHIFT; >> + bool is_priv_gfn = !((fault_ipa & gpa_stolen_mask) == gpa_stolen_mask); >> + bool priv_exists = kvm_mem_is_private(kvm, gfn); >> + struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache; >> + kvm_pfn_t pfn; >> + int ret; >> + >> + if (priv_exists != is_priv_gfn) { >> + kvm_prepare_memory_fault_exit(vcpu, >> + fault_ipa & ~gpa_stolen_mask, >> + PAGE_SIZE, >> + kvm_is_write_fault(vcpu), >> + false, is_priv_gfn); >> + >> + return 0; >> + } > > If I understand correctly, `kvm_prepare_memory_fault_exit()` ends up > returning to the VMM with the KVM_EXIT_MEMORY_FAULT exit reason. The > documentation says (https://docs.kernel.org/virt/kvm/api.html#kvm-run): > > "Note! KVM_EXIT_MEMORY_FAULT is unique among all KVM exit reasons in that > it accompanies a return code of ‘-1’, not ‘0’! errno will always be set > to EFAULT or EHWPOISON when KVM exits with KVM_EXIT_MEMORY_FAULT, > userspace should assume kvm_run.exit_reason is stale/undefined for all > other error numbers." > > Shall the return code be different for KVM_EXIT_MEMORY_FAULT? > > Thanks, Matias. Ah, good spot - I've no idea why KVM_EXIT_MEMORY_FAULT is special in this regard, but yes I guess we should be returning -EFAULT here. Thanks, Steve