xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Oleksandr Tyshchenko <olekstysh@gmail.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Oleksandr Andrushchenko <andr2000@gmail.com>,
	al1img <al1img@gmail.com>,
	Andrii Anisov <andrii.anisov@gmail.com>,
	Volodymyr Babchuk <vlad.babchuk@gmail.com>,
	Julien Grall <julien.grall@arm.com>,
	xen-devel@lists.xenproject.org,
	Artem Mygaiev <joculator@gmail.com>
Subject: Re: [RFC PATCH 2/9] iommu: Add ability to map/unmap the number of pages
Date: Fri, 28 Apr 2017 13:16:32 +0300	[thread overview]
Message-ID: <CAPD2p-nPLt_+wBGuH2D1t6UMtK7_Uk2OoneC8_8L8LdaqNULMg@mail.gmail.com> (raw)
In-Reply-To: <5902FBF20200007800154FD9@prv-mh.provo.novell.com>

Hi, Jan.

Thank you for your reply.

On Fri, Apr 28, 2017 at 9:23 AM, Jan Beulich <JBeulich@suse.com> wrote:
>
> >>> On 27.04.17 at 18:56, <olekstysh@gmail.com> wrote:
> > Now I am trying to replace single-page stuff with the multi-page one.
> > Currently, with the single-page API, if map fails we always try to unmap
> > already mapped pages.
> >
> > This is an example of generic code I am speaking about:
> > ...
> > for ( i = 0; i < (1 << order); i++ )
> > {
> >     rc = iommu_map_page(d, gfn + i, mfn_x(mfn) + i, iommu_flags);
> >     if ( unlikely(rc) )
> >     {
> >         while ( i-- )
> >             /* If statement to satisfy __must_check. */
> >             if ( iommu_unmap_page(p2m->domain, gfn + i) )
> >                 continue;
> >
> >         break;
> >     }
> > }
> > ...
> >
> > After modification the generic code will look like:
> > ...
> > rc = iommu_map_pages(d, gfn, mfn_x(mfn), 1 << order, iommu_flags);
> > ...
> > In case of an error we won't know how many pages have been already mapped
> > and
> > as the result we won't be able to unmap them in order to restore the
> > initial state.
> > Therefore I will move the rollback logic to the IOMMU drivers code. So, the
> > IOMMU drivers code
> > will take care of rollback mapping if something goes wrong. Am I right?
>
> Yes, it should be iommu_map_pages() (or its descendants) to clean
> up after itself upon error.
>
> > If all described above make sense, then there are several places I am
> > trying to optimize, but I am not familiar with)
> >
> > 1. xen/arch/x86/x86_64/mm.c:1443:
> > ...
> > if ( iommu_enabled && !iommu_passthrough && !need_iommu(hardware_domain) )
> > {
> >     for ( i = spfn; i < epfn; i++ )
> >         if ( iommu_map_page(hardware_domain, i, i,
> > IOMMUF_readable|IOMMUF_writable)
> > )
> >             break;
> >     if ( i != epfn )
> >     {
> >         while (i-- > old_max) // <--- [1]
> >             /* If statement to satisfy __must_check. */
> >             if ( iommu_unmap_page(hardware_domain, i) )
> >                 continue;
> >
> >         goto destroy_m2p;
> >     }
> > }
> > ...
> >
> > [1] Shouldn't we unmap already mapped pages only?  I mean to use "while
> > (i-- > spfn)" instead.
>
> Both should have the same effect, considering what old_max
> represents, at least as long as there's no MMIO in between. But
> yes, generally it would be more logical to unmap using spfn.
>
> > And if the use of "old_max" here has a special meaning, I think, that this
> > place of code won't be optimized
> > by passing the whole memory block (epfn - spfn) to the IOMMU. Just keep it
> > as is (handle one page at time).
>
> Right, that would have been my general advice: If in doubt, keep
> the code as is rather than trying to optimize it.
OK

>
>
> > 2. xen/drivers/passthrough/vtd/x86/vtd.c:143:
> > ...
> > tmp = 1 << (PAGE_SHIFT - PAGE_SHIFT_4K);
> > for ( j = 0; j < tmp; j++ )
> > {
> >     int ret = iommu_map_page(d, pfn * tmp + j, pfn * tmp + j,
> >                              IOMMUF_readable|IOMMUF_writable);
> >
> >     if ( !rc )
> >        rc = ret;
> > }
> > ...
> >
> > Here we don't try to rollback mapping at all. Was the idea to do so? Or was
> > this place simply missed?
>
> Did you consider both the context this is in (establishing hwdom
> mappings) and the code's history? Both would tell you that yes,
> this is a best effort mapping attempt deliberately continuing
> despite errors (but reporting the first one). This behavior will
> need to be retained. Plus I'm sure you've noticed that this
> effectively is a single page mapping only anyway (due to
> PAGE_SHIFT == PAGE_SHIFT_4K); I have no idea why this
> "clever" code was used.
So, if I understand what your meant I don't even need to try to
optimize this code.
Despite the fact that this code would become much more simple:
...
rc = iommu_map_pages(d, pfn, pfn, 1,
                  IOMMUF_readable|IOMMUF_writable);
...
Right?

>
> And as a side note - the way you quote code (by line number and
> without naming the function it's in) makes it somewhat more
> complicated to answer your questions. In both cases, had I known
> the function the code is in, I wouldn't have had a need at all to go
> look up the context.
Sorry for that. Next time I will provide more detailed snippet.

>
> > P.S. As for using "order" parameter instead of page_count.
> > There are *few* places where "order" doesn't fit.
>
> Well, I'd prefer the "few places" to then break up their requests to
> fit the "order" parameter. Especially for the purpose of possibly
> using large pages, an order input is quite a bit more sensible.
OK

>
> > I can introduce something like this:
> >
> > #define __iommu_map_pages(d,gfn,mfn,order,flags)
> > (iommu_map_pages(d,gfn,mfn,1U << (order),flags))
>
> I'd prefer if you didn't. In no case should this be an identifier
> starting with an underscore.
I got it. I proposed because I had seen analogy with
__map_domain_page/map_domain_page.

>
> Jan

-- 
Regards,

Oleksandr Tyshchenko

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

  reply	other threads:[~2017-04-28 10:16 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-15 20:05 [RFC PATCH 0/9] "Non-shared" IOMMU support on ARM Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 1/9] xen/device-tree: Add dt_count_phandle_with_args helper Oleksandr Tyshchenko
2017-03-16 15:39   ` Julien Grall
2017-03-17 11:24     ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 2/9] iommu: Add ability to map/unmap the number of pages Oleksandr Tyshchenko
2017-03-22 15:44   ` Jan Beulich
2017-03-22 18:01     ` Oleksandr Tyshchenko
2017-03-23  9:07       ` Jan Beulich
2017-03-23 12:47         ` Oleksandr Tyshchenko
2017-04-27 16:56           ` Oleksandr Tyshchenko
2017-04-28  6:23             ` Jan Beulich
2017-04-28 10:16               ` Oleksandr Tyshchenko [this message]
2017-04-28 10:29                 ` Jan Beulich
2017-04-28 10:44                   ` Oleksandr Tyshchenko
2017-04-19 17:31   ` Julien Grall
2017-04-21 11:46     ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 3/9] xen/arm: p2m: Add helper to convert p2m type to IOMMU flags Oleksandr Tyshchenko
2017-04-19 17:28   ` Julien Grall
2017-04-21 11:47     ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 4/9] xen/arm: p2m: Update IOMMU mapping whenever possible if page table is not shared Oleksandr Tyshchenko
2017-04-19 17:46   ` Julien Grall
2017-04-21 14:18     ` Oleksandr Tyshchenko
2017-04-21 16:27       ` Julien Grall
2017-04-21 18:44         ` Oleksandr Tyshchenko
2017-04-24 11:41           ` Julien Grall
2017-04-24 16:08             ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 5/9] iommu/arm: Re-define iommu_use_hap_pt(d) as iommu_hap_pt_share Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 6/9] iommu: Pass additional use_iommu argument to iommu_domain_init() Oleksandr Tyshchenko
2017-03-22 15:48   ` Jan Beulich
2017-03-23 12:50     ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 7/9] iommu/arm: Add alloc_page_table platform callback Oleksandr Tyshchenko
2017-03-22 15:49   ` Jan Beulich
2017-03-23 12:57     ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 8/9] iommu: Split iommu_hwdom_init() into arch specific parts Oleksandr Tyshchenko
2017-03-22 15:54   ` Jan Beulich
2017-03-22 18:40     ` Oleksandr Tyshchenko
2017-03-23  9:08       ` Jan Beulich
2017-03-23 12:40         ` Oleksandr Tyshchenko
2017-03-23 13:28           ` Jan Beulich
2017-04-19 18:09           ` Julien Grall
2017-04-21 12:18             ` Oleksandr Tyshchenko
2017-03-15 20:05 ` [RFC PATCH 9/9] xen: Add use_iommu flag to createdomain domctl Oleksandr Tyshchenko
2017-03-22 15:56   ` Jan Beulich
2017-03-23 16:36     ` Oleksandr Tyshchenko
2017-03-23 17:05       ` Jan Beulich
2017-03-24 11:19         ` Oleksandr Tyshchenko
2017-03-24 11:38           ` Jan Beulich
2017-03-24 13:05             ` Oleksandr Tyshchenko
2017-04-19 18:26   ` Julien Grall
2017-04-21 14:41     ` Oleksandr Tyshchenko
2017-04-25 15:23     ` Wei Liu
2017-04-25 16:07       ` Oleksandr Tyshchenko
2017-04-26 10:05         ` Ian Jackson
2017-04-27 10:41           ` Oleksandr Tyshchenko
2017-03-16 15:31 ` [RFC PATCH 0/9] "Non-shared" IOMMU support on ARM Julien Grall
2017-03-17 11:24   ` Oleksandr Tyshchenko

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=CAPD2p-nPLt_+wBGuH2D1t6UMtK7_Uk2OoneC8_8L8LdaqNULMg@mail.gmail.com \
    --to=olekstysh@gmail.com \
    --cc=JBeulich@suse.com \
    --cc=al1img@gmail.com \
    --cc=andr2000@gmail.com \
    --cc=andrii.anisov@gmail.com \
    --cc=joculator@gmail.com \
    --cc=julien.grall@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=vlad.babchuk@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).