From: Ian Campbell <ian.campbell@citrix.com>
To: Jan Beulich <JBeulich@suse.com>,
xen-devel <xen-devel@lists.xenproject.org>
Cc: Kevin Tian <kevin.tian@intel.com>, Wei Liu <wei.liu2@citrix.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
George Dunlap <George.Dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
Jun Nakajima <jun.nakajima@intel.com>, Keir Fraser <keir@xen.org>
Subject: Re: [PATCH v4] x86/p2m: use large pages for MMIO mappings
Date: Mon, 25 Jan 2016 12:16:47 +0000 [thread overview]
Message-ID: <1453724207.4320.137.camel@citrix.com> (raw)
In-Reply-To: <56A25C0602000078000CA367@prv-mh.provo.novell.com>
On Fri, 2016-01-22 at 08:42 -0700, Jan Beulich wrote:
> When mapping large BARs (e.g. the frame buffer of a graphics card) the
> overhead of establishing such mappings using only 4k pages has,
> particularly after the XSA-125 fix, become unacceptable. Alter the
> XEN_DOMCTL_memory_mapping semantics once again, so that there's no
> longer a fixed amount of guest frames that represents the upper limit
> of what a single invocation can map. Instead bound execution time by
> limiting the number of iterations (regardless of page size).
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> Open issues (perhaps for subsequent changes):
> - ARM side unimplemented (and hence libxc for now made cope with both
> models), the main issue (besides my inability to test any change
> there) being the many internal uses of map_mmio_regions())
> - iommu_{,un}map_page() interfaces don't support "order" (hence
> mmio_order() for now returns zero when !iommu_hap_pt_share, which in
> particular means the AMD side isn't being taken care of just yet, but
> note that this also has the intended effect of suppressing non-zero
> order mappings in the shadow mode case)
> ---
> v4: Move cleanup duty entirely to the caller of the hypercall. Move
> return value description to from commit message to domctl.h.
> v3: Re-base on top of "x86/hvm: fold opt_hap_{2mb,1gb} into
> hap_capabilities". Extend description to spell out new return value
> meaning. Add a couple of code comments. Use PAGE_ORDER_4K instead
> of literal 0. Take into consideration r/o MMIO pages.
> v2: Produce valid entries for large p2m_mmio_direct mappings in
> p2m_pt_set_entry(). Don't open code iommu_use_hap_pt() in
> mmio_order(). Update function comment of set_typed_p2m_entry() and
> clear_mmio_p2m_entry(). Use PRI_mfn. Add ASSERT()s to
> {,un}map_mmio_regions() to detect otherwise endless loops.
>
> --- a/tools/libxc/xc_domain.c
> +++ b/tools/libxc/xc_domain.c
> @@ -2174,7 +2174,7 @@ int xc_domain_memory_mapping(
> {
> DECLARE_DOMCTL;
> xc_dominfo_t info;
> - int ret = 0, err;
> + int ret = 0, rc;
> unsigned long done = 0, nr, max_batch_sz;
>
> if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 ||
> @@ -2199,19 +2199,24 @@ int xc_domain_memory_mapping(
> domctl.u.memory_mapping.nr_mfns = nr;
> domctl.u.memory_mapping.first_gfn = first_gfn + done;
> domctl.u.memory_mapping.first_mfn = first_mfn + done;
> - err = do_domctl(xch, &domctl);
> - if ( err && errno == E2BIG )
> + rc = do_domctl(xch, &domctl);
> + if ( rc < 0 && errno == E2BIG )
> {
> if ( max_batch_sz <= 1 )
> break;
> max_batch_sz >>= 1;
> continue;
> }
> + if ( rc > 0 )
> + {
> + done += rc;
> + continue;
> + }
> /* Save the first error... */
> if ( !ret )
> - ret = err;
> + ret = rc;
> /* .. and ignore the rest of them when removing. */
> - if ( err && add_mapping != DPCI_REMOVE_MAPPING )
> + if ( rc && add_mapping != DPCI_REMOVE_MAPPING )
> break;
This all looks good to me, assuming I've interpreted the interface comment
correctly.
> +
> +#define MAP_MMIO_MAX_ITER 64 /* pretty arbitrary */
> +
I suppose no existing in-tree code exceeds that (or there'd be more patch
here).
64 seems like as good a number as anything (corresponds to 256K for 4K
mappings, which doesn't seem too low).
> done += nr;
> --- a/xen/include/public/domctl.h
> +++ b/xen/include/public/domctl.h
> @@ -542,8 +542,14 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_bind_
>
>
> /* Bind machine I/O address range -> HVM address range. */
> -/* If this returns -E2BIG lower nr_mfns value. */
> /* XEN_DOMCTL_memory_mapping */
> +/* Returns
> + - zero (success, everything done)
> + - -E2BIG (passed in nr_mfns value too large for the implementation)
> + - positive (partial success, this many [less than nr_mfns] done,
Is the successful region contiguous, i.e. 0..return val, or does the caller
need to figure it somehow? (I think based on libxc changes the former, but
it should be spelt out here I think).
> + requiring re-invocation by the caller with updated inputs)
> + - negative (error)
This is a more general case of -E2BIG, you might fix that by saying "other
error" or by moving -E2BIG to be a subclause.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-01-25 12:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-22 15:42 [PATCH v4] x86/p2m: use large pages for MMIO mappings Jan Beulich
2016-01-25 12:16 ` Ian Campbell [this message]
2016-01-25 13:54 ` Jan Beulich
2016-01-25 14:05 ` Ian Campbell
2016-01-25 14:16 ` Jan Beulich
2016-01-25 14:21 ` Ian Campbell
2016-01-25 16:18 ` [PATCH v5] " Jan Beulich
2016-01-25 17:18 ` Ian Campbell
2016-01-26 22:35 ` Tian, Kevin
2016-01-27 10:22 ` Jan Beulich
2016-01-27 10:28 ` Andrew Cooper
2016-01-27 12:32 ` Andrew Cooper
2016-01-27 13:37 ` Jan Beulich
2016-01-27 14:28 ` Andrew Cooper
2016-01-27 14:40 ` Jan Beulich
2016-01-27 14:51 ` Andrew Cooper
2016-01-27 15:20 ` 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=1453724207.4320.137.camel@citrix.com \
--to=ian.campbell@citrix.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=jun.nakajima@intel.com \
--cc=keir@xen.org \
--cc=kevin.tian@intel.com \
--cc=stefano.stabellini@eu.citrix.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.