All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: George Dunlap <george.dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	boris.ostrovsky@oracle.com, xen-devel@lists.xenproject.org
Subject: Re: [PATCH v3.1 08/15] x86/vtd: fix mapping of RMRR regions
Date: Fri, 4 Nov 2016 13:25:17 +0100	[thread overview]
Message-ID: <20161104122517.nwvyg4nbktpc55tv@mac> (raw)
In-Reply-To: <581C7262020000780011C3AB@prv-mh.provo.novell.com>

On Fri, Nov 04, 2016 at 04:34:58AM -0600, Jan Beulich wrote:
> >>> On 04.11.16 at 10:45, <roger.pau@citrix.com> wrote:
> > On Fri, Nov 04, 2016 at 03:16:47AM -0600, Jan Beulich wrote:
> >> >>> On 29.10.16 at 10:59, <roger.pau@citrix.com> wrote:
> >> > --- a/xen/arch/x86/mm/p2m.c
> >> > +++ b/xen/arch/x86/mm/p2m.c
> >> > @@ -1049,22 +1049,29 @@ int set_identity_p2m_entry(struct domain *d, unsigned long gfn,
> >> >  
> >> >      mfn = p2m->get_entry(p2m, gfn, &p2mt, &a, 0, NULL, NULL);
> >> >  
> >> > -    if ( p2mt == p2m_invalid || p2mt == p2m_mmio_dm )
> >> > +    switch ( p2mt )
> >> > +    {
> >> > +    case p2m_invalid:
> >> > +    case p2m_mmio_dm:
> >> >          ret = p2m_set_entry(p2m, gfn, _mfn(gfn), PAGE_ORDER_4K,
> >> >                              p2m_mmio_direct, p2ma);
> >> > -    else if ( mfn_x(mfn) == gfn && p2mt == p2m_mmio_direct && a == p2ma )
> >> > -    {
> >> > -        ret = 0;
> >> > -        /*
> >> > -         * PVH fixme: during Dom0 PVH construction, p2m entries are being set
> >> > -         * but iomem regions are not mapped with IOMMU. This makes sure that
> >> > -         * RMRRs are correctly mapped with IOMMU.
> >> > -         */
> >> > -        if ( is_hardware_domain(d) && !iommu_use_hap_pt(d) )
> >> > +        if ( ret )
> >> > +            break;
> >> > +        /* fallthrough */
> >> > +    case p2m_mmio_direct:
> >> > +        if ( p2mt == p2m_mmio_direct && a != p2ma )
> >> 
> >> I don't understand the removal of the MFN == GFN check, and it
> >> also isn't being explained in the commit message.
> > 
> > Maybe I'm not understanding the logic of this function correctly, but it 
> > seems extremely bogus, and behaves quite differently depending on whether 
> > gfn == mfn and whether the domain is the hardware domain.
> 
> I can't exclude there's something wrong here, but you're removing
> a safety belt. Before touching this, did you go back in history to
> find out why things are the way they are? I remember it having
> taken quite a bit of discussion to reach a mostly acceptable flow
> here.

As said, I agree that the gfn == mfn check should be kept.

I've looked at 0e9e09 and 5ae039, but I cannot really understand how 5ae039 
was supposed to work in the first place, and to create the proper IOMMU 
mappings for RMRR regions. It replaced a call to intel_iommu_map_page with a 
call to set_identity_p2m_entry, and this newly introduced function 
(set_identity_p2m_entry) will only setup the p2m mappings for the required 
page, but it will completely ignore to setup any IOMMU mappings if the pt is 
not shared between HAP and the IOMMU.

Then 0e9e09 is a fixup for PVH guests, which really require RMRR regions 
properly mapped in the IOMMU in order to run. Since on PVH guests holes and 
reserved regions are identity mapped in the p2m, RMRR regions should already 
be mapped in the p2m, so 0e9e09 just added the IOMMU mappings if the pt was 
not shared.

But yet I think that 0e9e09 is wrong, and that it fixed RMRR mappings for 
hardware that shares the pt between HAP and the IOMMU while breaking it for 
hardware that doesn't share the pt between HAP and the IOMMU.
 
> > If gfn == mfn (so the page is already mapped in the p2m) and the domain is 
> > the hardware domain, an IOMMU mapping would be established. If gfn is not 
> > set, we will just set the p2m entry, but the IOMMU is not going to be 
> > properly configured, unless it shares the pt with p2m.
> 
> Well, that's why the comment says "PVH fixme". The issue is not
> the code here, but the code which established the mapping we
> found here. That code fails to also do the IOMMU mapping when
> needed. The only correct course of action, afaict, would be to
> fix that other code (wherever that is) and remove the comment
> together with the bogus code here (which would lead to just
> "ret = 0" remaining.

On classic PVH all holes or reserved regions in the memory map are identity 
mapped into the p2m, this is why RMRR regions where expected to be already 
mapped in the p2m. This is no longer true for PVHv2 domains, and holes or 
reserved regions are no longer mapped by default into the p2m.

> > This patch fixes the behavior of the function so it's consistent, and we 
> > can guarantee that after calling it a proper mapping in the p2m and the IOMMU 
> > will exist, and that it's going to be gfn == mfn, or else an error will be returned.
> > 
> > I agree with you that the mfn == gfn check should be kept, so the condition 
> > above should be:
> > 
> > 	if ( p2mt == p2m_mmio_direct && (a != p2ma || gfn != mfn) )
> > 
> > But please see below.
> > 
> >> And then following a case label with a comparison of the respective
> >> switch expression against the very value from the case label is
> >> certainly odd. I'm pretty sure a better structure of the code could be
> >> found.
> > 
> > Hm, the comparison is there because of the fallthrough in the above case. I 
> > could remove it by also setting the IOMMU entry in the above case, if that's 
> > better, so it would look like:
> > 
> > case p2m_invalid:
> > case p2m_mmio_dm:
> >     ret = p2m_set_entry(p2m, gfn, _mfn(gfn), PAGE_ORDER_4K,
> >                         p2m_mmio_direct, p2ma);
> >     if ( ret )
> >         break;
> >     if ( !iommu_use_hap_pt(d) )
> >         ret = iommu_map_page(d, gfn, gfn, IOMMUF_readable|IOMMUF_writable);
> >     break;
> > case p2m_mmio_direct:
> >     if ( a != p2ma || gfn != mfn )
> >     {
> >         printk(XENLOG_G_WARNING
> >                "Cannot setup identity map d%d:%lx, already mapped with "
> >                "different access type or mfn\n", d->domain_id, gfn);
> >         ret = (flag & XEN_DOMCTL_DEV_RDM_RELAXED) ? 0 : -EBUSY;
> >         break;
> >     }
> >     if ( !iommu_use_hap_pt(d) )
> >         ret = iommu_map_page(d, gfn, gfn, IOMMUF_readable|IOMMUF_writable);
> 
> Well, since according to what I've said above this code should
> really not be here, I think the code structuring question is moot
> now. The conditional call to iommu_map_page() really just needs
> adding alongside the p2m_set_entry() call.

OK, so if the gfn is already mapped into the p2m we don't care whether it 
has a valid IOMMU mapping or not?

Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2016-11-04 12:25 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-29  8:59 [PATCH v3.1 00/15] Initial PVHv2 Dom0 support Roger Pau Monne
2016-10-29  8:59 ` [PATCH v3.1 01/15] xen/x86: remove XENFEAT_hvm_pirqs for PVHv2 guests Roger Pau Monne
2016-10-31 16:32   ` Jan Beulich
2016-11-03 12:35     ` Roger Pau Monne
2016-11-03 12:52       ` Jan Beulich
2016-11-03 14:25         ` Konrad Rzeszutek Wilk
2016-11-03 15:05         ` Roger Pau Monne
2016-11-03 14:22       ` Konrad Rzeszutek Wilk
2016-11-03 15:01         ` Roger Pau Monne
2016-11-03 15:43         ` Roger Pau Monne
2016-10-29  8:59 ` [PATCH v3.1 02/15] xen/x86: fix return value of *_set_allocation functions Roger Pau Monne
2016-10-29 22:11   ` Tim Deegan
2016-10-29  8:59 ` [PATCH v3.1 03/15] xen/x86: allow calling {sh/hap}_set_allocation with the idle domain Roger Pau Monne
2016-10-31 16:34   ` Jan Beulich
2016-11-01 10:45     ` Tim Deegan
2016-11-02 17:14       ` Roger Pau Monne
2016-11-03 10:20         ` Roger Pau Monne
2016-11-03 10:33           ` Tim Deegan
2016-11-03 11:31           ` Jan Beulich
2016-10-29  8:59 ` [PATCH v3.1 04/15] xen/x86: assert that local_events_need_delivery is not called by " Roger Pau Monne
2016-10-31 16:37   ` Jan Beulich
2016-10-29  8:59 ` [PATCH v3.1 05/15] x86/paging: introduce paging_set_allocation Roger Pau Monne
2016-10-31 16:42   ` Jan Beulich
2016-11-01 10:29     ` Tim Deegan
2016-10-29  8:59 ` [PATCH v3.1 06/15] xen/x86: split the setup of Dom0 permissions to a function Roger Pau Monne
2016-10-31 16:44   ` Jan Beulich
2016-10-29  8:59 ` [PATCH v3.1 07/15] xen/x86: do the PCI scan unconditionally Roger Pau Monne
2016-10-31 16:47   ` Jan Beulich
2016-11-03 10:58     ` Roger Pau Monne
2016-11-03 11:35       ` Jan Beulich
2016-11-03 11:54         ` Boris Ostrovsky
2016-11-29 12:33           ` Roger Pau Monne
2016-11-29 12:47             ` Jan Beulich
2016-11-29 12:57               ` Roger Pau Monne
2016-11-30  5:53                 ` Tian, Kevin
2016-11-30  9:02                   ` Jan Beulich
2016-10-29  8:59 ` [PATCH v3.1 08/15] x86/vtd: fix mapping of RMRR regions Roger Pau Monne
2016-11-04  9:16   ` Jan Beulich
2016-11-04  9:45     ` Roger Pau Monne
2016-11-04 10:34       ` Jan Beulich
2016-11-04 12:25         ` Roger Pau Monne [this message]
2016-11-04 12:53           ` Jan Beulich
2016-11-04 13:03             ` Roger Pau Monne
2016-11-04 13:16               ` Jan Beulich
2016-11-04 15:33                 ` Roger Pau Monne
2016-11-04 16:13                   ` Jan Beulich
2016-11-04 16:19                     ` Roger Pau Monne
2016-11-04 17:08                       ` Jan Beulich
2016-11-04 17:25                         ` Roger Pau Monne
2016-11-07  8:36                           ` Jan Beulich
2016-10-29  8:59 ` [PATCH v3.1 09/15] xen/x86: allow the emulated APICs to be enabled for the hardware domain Roger Pau Monne
2016-11-04  9:19   ` Jan Beulich
2016-11-04  9:47     ` Roger Pau Monne
2016-11-04 10:21       ` Jan Beulich
2016-11-04 12:09         ` Roger Pau Monne
2016-11-04 12:50           ` Jan Beulich
2016-11-04 13:06             ` Roger Pau Monne
2016-10-29  8:59 ` [PATCH v3.1 10/15] xen/x86: split Dom0 build into PV and PVHv2 Roger Pau Monne
2016-11-11 16:53   ` Jan Beulich
2016-11-16 18:02     ` Roger Pau Monne
2016-11-17 10:49       ` Jan Beulich
2016-11-28 17:49         ` Roger Pau Monne
2016-11-29  9:34           ` Jan Beulich
2016-10-29  8:59 ` [PATCH v3.1 11/15] xen/mm: introduce a function to map large chunks of MMIO Roger Pau Monne
2016-11-11 16:58   ` Jan Beulich
2016-11-29 12:41     ` Roger Pau Monne
2016-11-29 13:00       ` Jan Beulich
2016-11-29 15:32         ` Roger Pau Monne
2016-11-11 20:17   ` Konrad Rzeszutek Wilk
2016-10-29  8:59 ` [PATCH v3.1 12/15] xen/x86: populate PVHv2 Dom0 physical memory map Roger Pau Monne
2016-11-11 17:16   ` Jan Beulich
2016-11-28 11:26     ` Roger Pau Monne
2016-11-28 11:41       ` Jan Beulich
2016-11-28 13:30         ` Roger Pau Monne
2016-11-28 13:49           ` Jan Beulich
2016-11-28 16:02             ` Roger Pau Monne
2016-10-29  8:59 ` [PATCH v3.1 13/15] xen/x86: parse Dom0 kernel for PVHv2 Roger Pau Monne
2016-11-11 20:30   ` Konrad Rzeszutek Wilk
2016-11-28 12:14     ` Roger Pau Monne
2016-10-29  9:00 ` [PATCH v3.1 14/15] xen/x86: hack to setup PVHv2 Dom0 CPUs Roger Pau Monne
2016-10-29  9:00 ` [PATCH v3.1 15/15] xen/x86: setup PVHv2 Dom0 ACPI tables Roger Pau Monne
2016-11-14 16:15   ` Jan Beulich
2016-11-30 12:40     ` Roger Pau Monne
2016-11-30 14:09       ` Jan Beulich
2016-11-30 14:23         ` Roger Pau Monne
2016-11-30 16:38           ` Jan Beulich
2016-10-31 14:35 ` [PATCH v3.1 00/15] Initial PVHv2 Dom0 support Boris Ostrovsky
2016-10-31 14:43   ` Andrew Cooper
2016-10-31 16:35     ` Roger Pau Monne

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=20161104122517.nwvyg4nbktpc55tv@mac \
    --to=roger.pau@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=george.dunlap@eu.citrix.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.