Re: [PATCH v2 6/6] kvm: return -EFAULT for writes to !VM_WRITE IO mappings
Sean Christopherson <[email protected]> Tue, 4 Aug 2026 14:08:55 -0700
| Newsgroups | gmane.linux.kernel,gmane.comp.emulators.kvm.devel,gmane.comp.video.dri.devel,gmane.linux.kernel.mm |
|---|---|
| Message-ID | <[email protected]> |
I strongly prefer "KVM:" for the scope, and it's waaay more common.
$ git log --pretty=oneline --after 2015.01.01 | grep "kvm:" | wc -l
1298
$ git log --pretty=oneline --after 2015.01.01 | grep "KVM:" | wc -l
16249
On Tue, Aug 04, 2026, Paolo Bonzini wrote:
> KVM's behavior when the guest writes to a non-writable VMA is inconsistent.
> For regular, page-backed mappings it returns KVM_PFN_ERR_FAULT and thus
> returns -EFAULT to userspace (which is ABI, and relied upon by tests);
> for VM_IO/VM_PFNMAP mappings instead it returns KVM_PFN_ERR_RO_FAULT
> and thus exits to userspace with KVM_EXIT_MMIO.
>
> This behavior for VM_{IO,PFNMAP} was added by commit bd2fae8da794 ("KVM:
> do not assume PTE is writable after follow_pfn"), and even if it has been
> in place for five years it is unlikely that it is relied upon by userspace,
> since it is inconsistent with KVM itself. Change hva_to_pfn() to return
> KVM_PFN_ERR_FAULT for all non-writable VMAs, and restrict KVM_EXIT_MMIO
> to the case of an explicitly read-only memslot.
>
> Suggested-by: Sean Christopherson <[email protected]>
> Signed-off-by: Paolo Bonzini <[email protected]>
> ---
Shortlog nit aside,
Reviewed-by: Sean Christopherson <[email protected]>