]> xenbits.xensource.com Git - xen.git/commit
x86/hvm: fix handling of accesses to partial r/o MMIO pages
authorRoger Pau Monne <roger.pau@citrix.com>
Wed, 9 Apr 2025 16:53:00 +0000 (18:53 +0200)
committerRoger Pau Monne <roger.pau@citrix.com>
Tue, 29 Apr 2025 12:49:54 +0000 (14:49 +0200)
commit8f36bde2b2a1ded193ce450c13b213ab9443f2ec
tree93ea757b655111034235d7e26b04c1dff7df79a7
parenteb627dd6ea58344351e8b31d32866ae5cb127055
x86/hvm: fix handling of accesses to partial r/o MMIO pages

The current logic to handle accesses to MMIO pages partially read-only is
based on the (now removed) logic used to handle accesses to the r/o MMCFG
region(s) for PVH v1 dom0.  However that has issues when running on AMD
hardware, as in that case the guest linear address that triggered the fault
is not provided as part of the VM exit.  This caused
mmio_ro_emulated_write() to always fail before calling
subpage_mmio_write_emulate() when running on AMD and called from an HVM
context.

Take a different approach and convert the handling of partial read-only
MMIO page accesses into an HVM MMIO ops handler, as that's the more natural
way to handle this kind of emulation for HVM domains.

This allows getting rid of hvm_emulate_one_mmio() and it's single call site
in hvm_hap_nested_page_fault().  As part of the fix r/o MMIO accesses are
now handled by handle_mmio_with_translation(), re-using the same logic that
was used for other read-only types part of p2m_is_discard_write().  The
usage of emulation for faulting p2m_mmio_direct types is limited to
addresses in the r/o MMIO range. The page present check is dropped as type
p2m_mmio_direct must have the present bit set in the PTE.

Note a small adjustment is needed to the `pf-fixup` dom0 PVH logic: avoid
attempting to fixup faults resulting from write accesses to read-only MMIO
regions, as handling of those accesses is now done by handle_mmio().

Fixes: 33c19df9a5a0 ('x86/PCI: intercept accesses to RO MMIO from dom0s in HVM containers')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/hvm/Makefile
xen/arch/x86/hvm/emulate.c
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/mmio.c [new file with mode: 0644]
xen/arch/x86/include/asm/hvm/emulate.h
xen/arch/x86/include/asm/hvm/io.h
xen/arch/x86/include/asm/mm.h
xen/arch/x86/mm.c