From: Paul Durrant <Paul.Durrant@citrix.com>
To: Roger Pau Monne <roger.pau@citrix.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Wei Liu <wei.liu2@citrix.com>,
Andrew Cooper <Andrew.Cooper3@citrix.com>,
"Tim (Xen.org)" <tim@xen.org>, Jan Beulich <jbeulich@suse.com>,
Ian Jackson <Ian.Jackson@citrix.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH v3 12/12] x86/hvm/ioreq: add a new mappable resource type...
Date: Mon, 4 Sep 2017 15:04:18 +0000 [thread overview]
Message-ID: <701192c6c3b44ba18a39c47f9d27bff0@AMSPEX02CL03.citrite.net> (raw)
In-Reply-To: <20170904150218.in6cujyxat6i4aem@MacBook-Pro-de-Roger.local>
> -----Original Message-----
> From: Roger Pau Monne
> Sent: 04 September 2017 16:02
> To: Paul Durrant <Paul.Durrant@citrix.com>
> Cc: xen-devel@lists.xenproject.org; Stefano Stabellini
> <sstabellini@kernel.org>; Wei Liu <wei.liu2@citrix.com>; Andrew Cooper
> <Andrew.Cooper3@citrix.com>; Ian Jackson <Ian.Jackson@citrix.com>; Tim
> (Xen.org) <tim@xen.org>; Jan Beulich <jbeulich@suse.com>
> Subject: Re: [Xen-devel] [PATCH v3 12/12] x86/hvm/ioreq: add a new
> mappable resource type...
>
> On Thu, Aug 31, 2017 at 10:36:05AM +0100, Paul Durrant wrote:
> > ... XENMEM_resource_ioreq_server
> >
> > This patch adds support for a new resource type that can be mapped using
> > the XENMEM_acquire_resource memory op.
> >
> > If an emulator makes use of this resource type then, instead of mapping
> > gfns, the IOREQ server will allocate pages from the heap. These pages
> > will never be present in the P2M of the guest at any point and so are
> > not vulnerable to any direct attack by the guest. They are only ever
> > accessible by Xen and any domain that has mapping privilege over the
> > guest (which may or may not be limited to the domain running the
> emulator).
> >
> > NOTE: Use of the new resource type is not compatible with use of
> > XEN_DMOP_get_ioreq_server_info unless the XEN_DMOP_no_gfns
> flag is
> > set.
> >
> > Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
> > Acked-by: George Dunlap <George.Dunlap@eu.citrix.com>
> > ---
> > Cc: Jan Beulich <jbeulich@suse.com>
> > Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> > Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> > Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> > Cc: Stefano Stabellini <sstabellini@kernel.org>
> > Cc: Tim Deegan <tim@xen.org>
> > Cc: Wei Liu <wei.liu2@citrix.com>
> > ---
> > xen/arch/x86/hvm/ioreq.c | 126
> +++++++++++++++++++++++++++++++++++++++-
> > xen/arch/x86/mm.c | 27 +++++++++
> > xen/include/asm-x86/hvm/ioreq.h | 2 +
> > xen/include/public/hvm/dm_op.h | 4 ++
> > xen/include/public/memory.h | 3 +
> > 5 files changed, 161 insertions(+), 1 deletion(-)
> >
> > diff --git a/xen/arch/x86/hvm/ioreq.c b/xen/arch/x86/hvm/ioreq.c
> > index 2d98b43849..5d406bc1fb 100644
> > --- a/xen/arch/x86/hvm/ioreq.c
> > +++ b/xen/arch/x86/hvm/ioreq.c
> > @@ -241,6 +241,15 @@ static int hvm_map_ioreq_gfn(struct
> hvm_ioreq_server *s, bool buf)
> > struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
> > int rc;
> >
> > + if ( iorp->page )
> > + {
> > + /* Make sure the page has not been allocated */
> > + if ( gfn_eq(iorp->gfn, INVALID_GFN) )
> > + return -EPERM;
> > +
> > + return 0;
> > + }
> > +
> > if ( d->is_dying )
> > return -EINVAL;
> >
> > @@ -263,6 +272,60 @@ static int hvm_map_ioreq_gfn(struct
> hvm_ioreq_server *s, bool buf)
> > return rc;
> > }
> >
> > +static int hvm_alloc_ioreq_mfn(struct hvm_ioreq_server *s, bool buf)
> > +{
> > + struct domain *currd = current->domain;
> > + struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
> > +
> > + if ( iorp->page )
> > + {
> > + /* Make sure the page has not been mapped */
> > + if ( !gfn_eq(iorp->gfn, INVALID_GFN) )
> > + return -EPERM;
> > +
> > + return 0;
> > + }
> > +
> > + /*
> > + * Allocated IOREQ server pages are assigned to the emulating
> > + * domain, not the target domain. This is because the emulator is
> > + * likely to be destroyed after the target domain has been torn
> > + * down, and we must use MEMF_no_refcount otherwise page
> allocation
> > + * could fail if the emulating domain has already reached its
> > + * maximum allocation.
> > + */
> > + iorp->page = alloc_domheap_page(currd, MEMF_no_refcount);
>
> So AFAICT (correct me if I'm wrong), the number of pages that can be
> allocated here is limited by MAX_NR_IOREQ_SERVERS, each ioreq server
> can only have at most one page.
>
Each server can have at most 2 pages (one for synchronous ioreqs and one for buffered).
> > + if ( !iorp->page )
> > + return -ENOMEM;
> > +
> > + get_page(iorp->page, currd);
>
> Hm, didn't we agree that this get_page was not needed? AFAICT you need
> this if you use MEMF_no_owner, because the page is not added to
> d->page_list.
>
Oh, good catch. I completely forgot to ditch that.
Paul
> Thanks, Roger.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
prev parent reply other threads:[~2017-09-04 15:04 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-31 9:35 [PATCH v3 00/12] x86: guest resource mapping Paul Durrant
2017-08-31 9:35 ` [PATCH v3 01/12] x86/mm: allow a privileged PV domain to map guest mfns Paul Durrant
2017-08-31 9:35 ` [PATCH v3 02/12] x86/mm: add HYPERVISOR_memory_op to acquire guest resources Paul Durrant
2017-08-31 9:35 ` [PATCH v3 03/12] tools/libxenforeignmemory: add support for resource mapping Paul Durrant
2017-09-04 10:43 ` Roger Pau Monné
2017-09-04 15:38 ` Paul Durrant
2017-08-31 9:35 ` [PATCH v3 04/12] tools/libxenforeignmemory: reduce xenforeignmemory_restrict code footprint Paul Durrant
2017-09-04 10:47 ` Roger Pau Monné
2017-09-05 8:39 ` Paul Durrant
2017-08-31 9:35 ` [PATCH v3 05/12] tools/libxenctrl: use new xenforeignmemory API to seed grant table Paul Durrant
2017-09-04 11:05 ` Roger Pau Monné
2017-08-31 9:35 ` [PATCH v3 06/12] x86/hvm/ioreq: rename .*pfn and .*gmfn to .*gfn Paul Durrant
2017-08-31 9:36 ` [PATCH v3 07/12] x86/hvm/ioreq: use bool rather than bool_t Paul Durrant
2017-08-31 9:36 ` [PATCH v3 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a list Paul Durrant
2017-09-04 13:40 ` Roger Pau Monné
2017-09-04 14:39 ` Jan Beulich
2017-09-05 9:06 ` Paul Durrant
2017-08-31 9:36 ` [PATCH v3 09/12] x86/hvm/ioreq: simplify code and use consistent naming Paul Durrant
2017-09-04 14:08 ` Roger Pau Monné
2017-08-31 9:36 ` [PATCH v3 10/12] x86/hvm/ioreq: use gfn_t in struct hvm_ioreq_page Paul Durrant
2017-08-31 9:36 ` [PATCH v3 11/12] x86/hvm/ioreq: defer mapping gfns until they are actually requsted Paul Durrant
2017-09-04 14:31 ` Roger Pau Monné
2017-08-31 9:36 ` [PATCH v3 12/12] x86/hvm/ioreq: add a new mappable resource type Paul Durrant
2017-09-04 15:02 ` Roger Pau Monné
2017-09-04 15:04 ` Paul Durrant [this message]
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=701192c6c3b44ba18a39c47f9d27bff0@AMSPEX02CL03.citrite.net \
--to=paul.durrant@citrix.com \
--cc=Andrew.Cooper3@citrix.com \
--cc=Ian.Jackson@citrix.com \
--cc=jbeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--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 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).