[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v3 1/2] x86/mm: add API for marking only part of a MMIO page read only
On 22.05.2024 12:36, Marek Marczykowski-Górecki wrote: > On Wed, May 22, 2024 at 09:52:44AM +0200, Jan Beulich wrote: >> On 21.05.2024 04:54, Marek Marczykowski-Górecki wrote: >>> --- a/xen/arch/x86/hvm/hvm.c >>> +++ b/xen/arch/x86/hvm/hvm.c >>> @@ -2009,6 +2009,14 @@ 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 >>> && >>> + subpage_mmio_write_accept(mfn, gla) && >> >> Afaics subpage_mmio_write_accept() is unreachable then when CONFIG_HVM=n? > > Right, the PV path hits mmio_ro_emulated_write() without my changes > already. > Do you suggest to make subpage_mmio_write_accept() under #ifdef > CONFIG_HVM? That's not just me, but also Misra. >>> + (hvm_emulate_one_mmio(mfn_x(mfn), gla) == X86EMUL_OKAY) ) >>> + { >>> + rc = 1; >>> + goto out_put_gfn; >>> + } >> >> Overall this new if() is pretty similar to the immediate preceding one. >> So similar that I wonder whether the two shouldn't be folded. > > I can do that if you prefer. > >> In fact >> it looks as if the new one is needed only for the case where you'd pass >> through (to a DomU) a device partially used by Xen. That could certainly >> do with mentioning explicitly. > > Well, the change in mmio_ro_emulated_write() is relevant to both dom0 > and domU. It simply wasn't reachable (in this case) for HVM domU before > (but was for PV already). The remark was about the code here only. Of course that other change you talk about is needed for both, and I wasn't meaning to suggest Dom0 had worked (in this regard) prior to your change. >>> +static void __iomem *subpage_mmio_get_page(struct subpage_ro_range *entry) >>> +{ >>> + void __iomem *mapped_page; >>> + >>> + if ( entry->mapped ) >>> + return entry->mapped; >>> + >>> + mapped_page = ioremap(mfn_x(entry->mfn) << PAGE_SHIFT, PAGE_SIZE); >>> + >>> + spin_lock(&subpage_ro_lock); >>> + /* Re-check under the lock */ >>> + if ( entry->mapped ) >>> + { >>> + spin_unlock(&subpage_ro_lock); >>> + iounmap(mapped_page); >> >> The only unmap is on an error path here and on another error path elsewhere. >> IOW it looks as if devices with such marked pages are meant to never be hot >> unplugged. I can see that being intentional for the XHCI console, but imo >> such a restriction also needs prominently calling out in a comment next to >> e.g. the function declaration. > > The v1 included subpage_mmio_ro_remove() function (which would need to > be used in case of hot-unplug of such device, if desirable), but since > this series doesn't introduce any use of it (as you say, it isn't > desirable for XHCI console specifically), you asked me to remove it... > > Should I add an explicit comment about the limitation, instead of having > it implicit by not having subpage_mmio_ro_remove() there? That's what I was asking for in my earlier comment, yes. >>> --- a/xen/arch/x86/pv/ro-page-fault.c >>> +++ b/xen/arch/x86/pv/ro-page-fault.c >>> @@ -330,6 +330,7 @@ static int mmio_ro_do_page_fault(struct >>> x86_emulate_ctxt *ctxt, >>> return X86EMUL_UNHANDLEABLE; >>> } >>> >>> + mmio_ro_ctxt.mfn = mfn; >>> ctxt->data = &mmio_ro_ctxt; >>> if ( pci_ro_mmcfg_decode(mfn_x(mfn), &mmio_ro_ctxt.seg, >>> &mmio_ro_ctxt.bdf) ) >>> return x86_emulate(ctxt, &mmcfg_intercept_ops); >> >> Wouldn't you better set .mfn only on the "else" path, just out of context? >> Suggesting that the new field in the struct could actually overlay the >> (seg,bdf) tuple (being of relevance only to MMCFG intercept handling). >> This would be more for documentation purposes than to actually save space. >> (If so, perhaps the "else" itself would also better be dropped while making >> the adjustment.) > > I can do that if you prefer. But personally, I find such such use of an > union risky (without some means for a compiler to actually enforce their > proper use) - while for correct code it may save some space, it makes > the impact of a type confusion bug potentially worse - now that the > unexpected value would be potentially attacker controlled. > For a documentation purpose I can simply add a comment. Well, I'm not going to insist on using a union. But I am pretty firm on expecting the setting of .mfn to move down. Not using a union will then mean static analysis tools may point out that .mfn is left uninitialized for the above visible 1st invocation of x86_emulate(). Jan
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |