All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Paul Durrant <paul.durrant@citrix.com>
Cc: Kevin Tian <kevin.tian@intel.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Tim Deegan <tim@xen.org>,
	george.dunlap@citrix.com, Julien Grall <julien.grall@arm.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	xen-devel <xen-devel@lists.xenproject.org>,
	IanJackson <Ian.Jackson@citrix.com>,
	Brian Woods <brian.woods@amd.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [PATCH v2 3/4] iommu: elide flushing for higher order map/unmap operations
Date: Tue, 04 Dec 2018 09:01:42 -0700	[thread overview]
Message-ID: <5C06A4E60200007800202C98@prv1-mh.provo.novell.com> (raw)
In-Reply-To: <0d6a78307bb5438582dd7e8e55a449db@AMSPEX02CL03.citrite.net>

>>> On 04.12.18 at 16:36, <Paul.Durrant@citrix.com> wrote:
>> From: Jan Beulich [mailto:JBeulich@suse.com]
>> Sent: 04 December 2018 15:17
>> 
>> >>> On 03.12.18 at 18:40, <paul.durrant@citrix.com> wrote:
>> > --- a/xen/arch/arm/p2m.c
>> > +++ b/xen/arch/arm/p2m.c
>> > @@ -971,8 +971,17 @@ static int __p2m_set_entry(struct p2m_domain *p2m,
>> >
>> >      if ( need_iommu_pt_sync(p2m->domain) &&
>> >           (lpae_is_valid(orig_pte) || lpae_is_valid(*entry)) )
>> > +    {
>> > +        unsigned int flush_flags = 0;
>> > +
>> > +        if ( lpae_is_valid(orig_pte) )
>> > +            flush_flags |= IOMMU_FLUSHF_modified;
>> > +        if ( lpae_is_valid(*entry) )
>> > +            flush_flags |= IOMMU_FLUSHF_added;
>> 
>> Shouldn't this be "else if" with the meaning assigned to both
>> types? From an abstract perspective I'd also expect that for
>> a single mapping no more than one of the flags can come
>> back set (through the iommu_ops interface).
> 
> That's not how I see it. My rationale is:
> 
> - present PTE made non-present, or modified -> IOMMU_FLUSHF_modified
> - new PTE value is present -> IOMMU_FLUSHF_added
> 
> So, a single op can set any combination of bits and thus the above code does 
> not use 'else if'.

I can't fit this with the code comments:

enum
{
    _IOMMU_FLUSHF_added, /* no modified entries, just additional entries */
    _IOMMU_FLUSHF_modified, /* modified entries */
};

..., in particular the "no modified entries" part.

>> > @@ -84,7 +86,7 @@ static bool set_iommu_pde_present(uint32_t *pde,
>> unsigned long next_mfn,
>> >
>> >          if ( maddr_old != maddr_next || iw != old_w || ir != old_r ||
>> >               old_level != next_level )
>> > -            need_flush = true;
>> > +            flush_flags = IOMMU_FLUSHF_modified;
>> 
>> Why uniformly "modified"?
> 
> Because the AMD IOMMU does require flushing for a non-present -> present 
> transition AFAICT. The old code certainly implies this.

It is one thing what the flush function does with the value, but
another whether the modifying function "lies". I'm not opposed
to simplification, but then a comment needs to explain this.

>> > @@ -235,6 +236,9 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
>> >                  process_pending_softirqs();
>> >          }
>> >
>> > +        while ( !flush_flags && iommu_flush_all(d) )
>> > +            break;
>> 
>> Is there a comment missing here explaining the seemingly odd
>> loop?
> 
> I'm merely using the construct you suggested, but I can add a comment.

And I'm fine with the construct, but in the other place (for which
we did discuss this for the earlier version) there is a comment.

>> > --- a/xen/drivers/passthrough/vtd/iommu.c
>> > +++ b/xen/drivers/passthrough/vtd/iommu.c
>> > @@ -633,11 +633,14 @@ static int __must_check iommu_flush_iotlb(struct
>> domain *d, dfn_t dfn,
>> >
>> >  static int __must_check iommu_flush_iotlb_pages(struct domain *d,
>> >                                                  dfn_t dfn,
>> > -                                                unsigned int
>> page_count)
>> > +                                                unsigned int
>> page_count,
>> > +                                                unsigned int
>> flush_flags)
>> >  {
>> >      ASSERT(page_count && !dfn_eq(dfn, INVALID_DFN));
>> > +    ASSERT(flush_flags);
>> >
>> > -    return iommu_flush_iotlb(d, dfn, 1, page_count);
>> > +    return iommu_flush_iotlb(d, dfn, flush_flags &
>> IOMMU_FLUSHF_modified,
>> > +                             page_count);
>> 
>> Why the restriction to "modified"?
> 
> The parameter is a bool which should be true if an existing PTE was modified 
> or false otherwise. I can make this !!(flush_flags & IOMMU_FLUSHF_modified) is 
> you prefer.

No, that wasn't my point. The question is why this isn't just
"flush_flags", without any masking. Iirc there are precautions
in the VT-d code to deal with hardware which may cache
non-present entries. In that case "added" requires flushing too.

Jan


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

  reply	other threads:[~2018-12-04 16:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-03 17:40 [PATCH v2 0/4] iommu improvements Paul Durrant
2018-12-03 17:40 ` [PATCH v2 1/4] amd-iommu: add flush iommu_ops Paul Durrant
2018-12-04 14:24   ` Jan Beulich
2018-12-04 14:56     ` Paul Durrant
2018-12-03 17:40 ` [PATCH v2 2/4] iommu: rename wrapper functions Paul Durrant
2018-12-04 14:51   ` Jan Beulich
2018-12-04 15:00     ` Paul Durrant
2018-12-03 17:40 ` [PATCH v2 3/4] iommu: elide flushing for higher order map/unmap operations Paul Durrant
2018-12-04 15:16   ` Jan Beulich
2018-12-04 15:36     ` Paul Durrant
2018-12-04 16:01       ` Jan Beulich [this message]
2018-12-04 16:53         ` Paul Durrant
2018-12-04 17:20           ` Jan Beulich
2018-12-03 17:40 ` [PATCH v2 4/4] x86/mm/p2m: stop checking for IOMMU shared page tables in mmio_order() Paul Durrant
2018-12-04 15:20   ` Jan Beulich
2018-12-04 15:22     ` Paul Durrant
2018-12-04 15:36       ` Jan Beulich
2018-12-04 15:51   ` 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=5C06A4E60200007800202C98@prv1-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=Ian.Jackson@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=brian.woods@amd.com \
    --cc=george.dunlap@citrix.com \
    --cc=julien.grall@arm.com \
    --cc=kevin.tian@intel.com \
    --cc=konrad.wilk@oracle.com \
    --cc=paul.durrant@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=tim@xen.org \
    --cc=wei.liu2@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.