From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH 3/5] x86/hvm: fix handling of accesses to partial r/o MMIO pages
Date: Mon, 14 Apr 2025 18:13:25 +0200 [thread overview]
Message-ID: <Z_00JReo7Ji7RwkD@macbook.lan> (raw)
In-Reply-To: <c92d5665-0940-40b5-8cbb-81889adf40c5@suse.com>
On Mon, Apr 14, 2025 at 05:24:32PM +0200, Jan Beulich wrote:
> On 14.04.2025 15:53, Roger Pau Monné wrote:
> > On Mon, Apr 14, 2025 at 08:33:44AM +0200, Jan Beulich wrote:
> >> On 11.04.2025 12:54, Roger Pau Monne wrote:
> >>> @@ -1981,7 +2056,9 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,
> >>> */
> >>> if ( (p2mt == p2m_mmio_dm) ||
> >>> (npfec.write_access &&
> >>> - (p2m_is_discard_write(p2mt) || (p2mt == p2m_ioreq_server))) )
> >>> + (p2m_is_discard_write(p2mt) || (p2mt == p2m_ioreq_server) ||
> >>> + /* MMIO entries can be r/o if the target mfn is in mmio_ro_ranges. */
> >>> + (p2mt == p2m_mmio_direct))) )
> >>> {
> >>> if ( !handle_mmio_with_translation(gla, gfn, npfec) )
> >>> hvm_inject_hw_exception(X86_EXC_GP, 0);
> >>
> >> Aren't we handing too many things to handle_mmio_with_translation() this
> >> way? At the very least you're losing ...
> >>
> >>> @@ -2033,14 +2110,6 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,
> >>> goto out_put_gfn;
> >>> }
> >>>
> >>> - if ( (p2mt == p2m_mmio_direct) && npfec.write_access && npfec.present &&
> >>
> >> ... the .present check.
> >
> > Isn't the p2mt == p2m_mmio_direct check already ensuring the entry is
> > present? Otherwise it's type would be p2m_invalid or p2m_mmio_dm?
>
> Yes (to the 1st question), it kind of is.
>
> > It did seem to me the other checks in this function already assume
> > that by having a valid type the entry is present.
>
> Except for the code above, where we decided to play safe. AT the very least
> if you drop such a check, please say a justifying word in the description.
I've added:
"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 page
present check is dropped as type p2m_mmio_direct must have the
present bit set in the PTE."
Let me know if you think that's enough.
> >> I'm also concerned of e.g. VT-x'es APIC access MFN, which is
> >> p2m_mmio_direct.
> >
> > But that won't go into hvm_hap_nested_page_fault() when using
> > cpu_has_vmx_virtualize_apic_accesses (and thus having an APIC page
> > mapped as p2m_mmio_direct)?
> >
> > It would instead be an EXIT_REASON_APIC_ACCESS vmexit which is handled
> > differently?
>
> All true as long as things work as expected (potentially including the guest
> also behaving as expected). Also this was explicitly only an example I could
> readily think of. I'm simply wary of handle_mmio_with_translation() now
> getting things to handle it's not meant to ever see.
How was access to MMIO r/o regions supposed to be handled before
33c19df9a5a0 (~2015)? I see that setting r/o MMIO p2m entries was
added way before to p2m_type_to_flags() and ept_p2m_type_to_flags()
(~2010), yet I can't figure out how writes would be handled back then
that didn't result in a p2m fault and crashing of the domain.
I'm happy to look at other ways to handling this, but given there's
current logic for handling accesses to read-only regions in
hvm_hap_nested_page_fault() I think re-using that was the best way to
also handle accesses to MMIO read-only regions.
Arguably it would already be the case that for other reasons Xen would
need to emulate an instruction that accesses a read-only MMIO region?
Thanks, Roger.
next prev parent reply other threads:[~2025-04-14 16:13 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-11 10:54 [PATCH 0/5] xen/x86: fix implementation of subpage r/o MMIO Roger Pau Monne
2025-04-11 10:54 ` [PATCH 1/5] x86/mm: account for the offset when performing subpage r/o MMIO access Roger Pau Monne
2025-04-11 12:00 ` Andrew Cooper
2025-04-11 10:54 ` [PATCH 2/5] xen/io: provide helpers for multi size MMIO accesses Roger Pau Monne
2025-04-11 18:44 ` Denis Mukhin
2025-04-14 6:07 ` Jan Beulich
2025-04-14 7:49 ` Julien Grall
2025-04-14 8:52 ` Jan Beulich
2025-04-11 10:54 ` [PATCH 3/5] x86/hvm: fix handling of accesses to partial r/o MMIO pages Roger Pau Monne
2025-04-14 6:33 ` Jan Beulich
2025-04-14 13:53 ` Roger Pau Monné
2025-04-14 15:24 ` Jan Beulich
2025-04-14 16:13 ` Roger Pau Monné [this message]
2025-04-15 7:32 ` Jan Beulich
2025-04-15 8:34 ` Roger Pau Monné
2025-04-15 9:41 ` Jan Beulich
2025-04-15 10:04 ` Roger Pau Monné
2025-04-15 10:18 ` Jan Beulich
2025-04-15 10:40 ` Marek Marczykowski
2025-04-15 10:50 ` Jan Beulich
2025-04-15 12:47 ` Roger Pau Monné
2025-04-15 12:53 ` Jan Beulich
2025-04-11 10:54 ` [PATCH 4/5] x86/hvm: only register the r/o subpage ops when needed Roger Pau Monne
2025-04-14 6:36 ` Jan Beulich
2025-04-11 10:54 ` [PATCH 5/5] x86/mm: move mmio_ro_emulated_write() to PV only file Roger Pau Monne
2025-04-14 6:37 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z_00JReo7Ji7RwkD@macbook.lan \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.