From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Daniel De Graaf <dgdegra@tycho.nsa.gov>,
anthony.perard@citrix.com,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
Ian Campbell <Ian.Campbell@eu.citrix.com>
Cc: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: Re: [PATCH qemu] Support grant references in mapping
Date: Fri, 25 Feb 2011 10:01:52 -0500 [thread overview]
Message-ID: <20110225150152.GA12918@dumpdata.com> (raw)
In-Reply-To: <4D278F24.5060504@tycho.nsa.gov>
On Fri, Jan 07, 2011 at 05:09:40PM -0500, Daniel De Graaf wrote:
> This is untested in qemu, but is the same patch as was applied to the
> server I have tested. It applies to the ioemu-remote that I am using.
I lost track of this patchset. I think we need to first have somebody
familiar with QEMU review these patches.
CC-ing Stefano, Ian, Anthony
>
> ---
>
> Request and support using grant references in backends for
> the keyboard and framebuffer.
>
> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
>
> ---
>
> diff --git a/hw/xenfb.c b/hw/xenfb.c
> index 97960ba..c8d7a3e 100644
> --- a/hw/xenfb.c
> +++ b/hw/xenfb.c
> @@ -61,6 +61,7 @@ struct common {
> struct XenDevice xendev; /* must be first */
> void *page;
> DisplayState *ds;
> + int uses_gref;
> };
>
> struct XenInput {
> @@ -100,22 +101,27 @@ struct XenFB {
>
> static int common_bind(struct common *c)
> {
> - int mfn;
> + int ref;
>
> - if (xenstore_read_fe_int(&c->xendev, "page-ref", &mfn) == -1)
> - return -1;
> if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1)
> return -1;
>
> - c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
> - XC_PAGE_SIZE,
> - PROT_READ | PROT_WRITE, mfn);
> + if (xenstore_read_fe_int(&c->xendev, "page-gref", &ref) == 0) {
> + c->page = xc_gnttab_map_grant_ref(xen_xc, c->xendev.gnttabdev, c->xendev.dom, ref, PROT_READ | PROT_WRITE);
> + c->uses_gref = 1;
> + } else if (xenstore_read_fe_int(&c->xendev, "page-ref", &ref) == 0) {
> + xen_pfn_t pfn = ref;
> + c->page = xc_map_foreign_pages(xen_xc, c->xendev.dom, PROT_READ | PROT_WRITE, &pfn, 1);
> + c->uses_gref = 0;
> + } else
> + return -1;
> +
> if (c->page == NULL)
> return -1;
>
> xen_be_bind_evtchn(&c->xendev);
> - xen_be_printf(&c->xendev, 1, "ring mfn %d, remote-port %d, local-port %d\n",
> - mfn, c->xendev.remote_port, c->xendev.local_port);
> + xen_be_printf(&c->xendev, 1, "ring ref %d, remote-port %d, local-port %d\n",
> + ref, c->xendev.remote_port, c->xendev.local_port);
>
> return 0;
> }
> @@ -123,10 +129,12 @@ static int common_bind(struct common *c)
> static void common_unbind(struct common *c)
> {
> xen_be_unbind_evtchn(&c->xendev);
> - if (c->page) {
> + if (c->page && c->uses_gref) {
> + xc_gnttab_munmap(xen_xc, c->xendev.gnttabdev, c->page, 1);
> + } else if (c->page) {
> munmap(c->page, XC_PAGE_SIZE);
> - c->page = NULL;
> }
> + c->page = NULL;
> }
>
> /* -------------------------------------------------------------------- */
> @@ -422,8 +430,6 @@ static int xenfb_map_fb(struct XenFB *xenfb)
> struct xenfb_page *page = xenfb->c.page;
> char *protocol = xenfb->c.xendev.protocol;
> int n_fbdirs;
> - unsigned long *pgmfns = NULL;
> - unsigned long *fbmfns = NULL;
> void *map, *pd;
> int mode, ret = -1;
>
> @@ -472,36 +478,72 @@ static int xenfb_map_fb(struct XenFB *xenfb)
> #endif
> }
>
> - if (xenfb->pixels) {
> + if (xenfb->pixels && xenfb->c.uses_gref) {
> + xc_gnttab_munmap(xen_xc, xenfb->c.xendev.gnttabdev, xenfb->pixels, xenfb->fbpages);
> + } else if (xenfb->pixels) {
> munmap(xenfb->pixels, xenfb->fbpages * XC_PAGE_SIZE);
> - xenfb->pixels = NULL;
> }
> + xenfb->pixels = NULL;
>
> xenfb->fbpages = (xenfb->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
> n_fbdirs = xenfb->fbpages * mode / 8;
> n_fbdirs = (n_fbdirs + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
>
> - pgmfns = qemu_mallocz(sizeof(unsigned long) * n_fbdirs);
> - fbmfns = qemu_mallocz(sizeof(unsigned long) * xenfb->fbpages);
> + if (xenfb->c.uses_gref) {
> + uint32_t* domids = qemu_mallocz(sizeof(uint32_t)*n_fbdirs);
> + uint32_t* refs = qemu_mallocz(sizeof(uint32_t)*n_fbdirs);
> + int i;
> + for(i=0; i < n_fbdirs; i++)
> + {
> + domids[i] = xenfb->c.xendev.dom;
> + refs[i] = (mode == 32) ? ((uint32_t*)pd)[i] : ((uint64_t*)pd)[i];
> + }
>
> - xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
> - map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
> - PROT_READ, pgmfns, n_fbdirs);
> - if (map == NULL)
> - goto out;
> - xenfb_copy_mfns(mode, xenfb->fbpages, fbmfns, map);
> - munmap(map, n_fbdirs * XC_PAGE_SIZE);
> + map = xc_gnttab_map_grant_refs(xen_xc, xenfb->c.xendev.gnttabdev,
> + n_fbdirs, domids, refs, PROT_READ);
> + qemu_free(domids);
> + qemu_free(refs);
> +
> + if (map == NULL)
> + goto out;
> +
> + domids = qemu_mallocz(sizeof(uint32_t)*xenfb->fbpages);
> + refs = qemu_mallocz(sizeof(uint32_t)*xenfb->fbpages);
> + for(i=0; i < xenfb->fbpages; i++)
> + {
> + domids[i] = xenfb->c.xendev.dom;
> + refs[i] = (mode == 32) ? ((uint32_t*)map)[i] : ((uint64_t*)map)[i];
> + }
> +
> + xc_gnttab_munmap(xen_xc, xenfb->c.xendev.gnttabdev, map, n_fbdirs);
> + xenfb->pixels = xc_gnttab_map_grant_refs(xen_xc, xenfb->c.xendev.gnttabdev,
> + xenfb->fbpages, domids, refs, PROT_READ);
> + qemu_free(domids);
> + qemu_free(refs);
> + } else {
> + unsigned long *pgmfns = qemu_mallocz(sizeof(unsigned long) * n_fbdirs);
> + xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
> + map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
> + PROT_READ, pgmfns, n_fbdirs);
> + qemu_free(pgmfns);
> +
> + if (map == NULL)
> + goto out;
> +
> + unsigned long *fbmfns = qemu_mallocz(sizeof(unsigned long) * xenfb->fbpages);
> + xenfb_copy_mfns(mode, xenfb->fbpages, fbmfns, map);
> + munmap(map, n_fbdirs * XC_PAGE_SIZE);
> + xenfb->pixels = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
> + PROT_READ | PROT_WRITE, fbmfns, xenfb->fbpages);
> + qemu_free(fbmfns);
> + }
>
> - xenfb->pixels = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
> - PROT_READ | PROT_WRITE, fbmfns, xenfb->fbpages);
> if (xenfb->pixels == NULL)
> goto out;
>
> ret = 0; /* all is fine */
>
> out:
> - qemu_free(pgmfns);
> - qemu_free(fbmfns);
> return ret;
> }
>
> @@ -860,6 +902,8 @@ static int fb_init(struct XenDevice *xendev)
> #ifdef XENFB_TYPE_RESIZE
> xenstore_write_be_int(xendev, "feature-resize", 1);
> #endif
> + xenstore_write_be_int(xendev, "use-grants", 1);
> +
> return 0;
> }
>
> @@ -913,6 +957,13 @@ static void fb_disconnect(struct XenDevice *xendev)
> {
> struct XenFB *fb = container_of(xendev, struct XenFB, c.xendev);
>
> + if (fb->pixels && fb->c.uses_gref) {
> + xc_gnttab_munmap(xen_xc, fb->c.xendev.gnttabdev, fb->pixels, fb->fbpages);
> + } else if (fb->pixels) {
> + // Note: not needed if we are doing the mmap() below
> + // munmap(fb->pixels, fb->fbpages * XC_PAGE_SIZE);
> + }
> +
> /*
> * FIXME: qemu can't un-init gfx display (yet?).
> * Replacing the framebuffer with anonymous shared memory
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
next prev parent reply other threads:[~2011-02-25 15:01 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-07 16:12 [PATCH] Add grant references for fbfront/kbdfront dgdegra
2011-01-07 16:12 ` [PATCH 1/3] xen-fbfront: Read width/height from backend dgdegra
2011-01-07 20:47 ` Ian Campbell
2011-01-07 21:30 ` Daniel De Graaf
2011-01-07 16:12 ` [PATCH 2/3] xen-fbfront: Use grant references when requested dgdegra
2011-01-07 20:44 ` Ian Campbell
2011-01-07 21:02 ` Daniel De Graaf
2011-01-07 21:41 ` Daniel De Graaf
2011-01-07 21:56 ` Ian Campbell
2011-01-07 16:12 ` [PATCH 3/3] xen-kbdfront: Add grant reference for shared page dgdegra
2011-01-07 16:51 ` [PATCH] Add grant references for fbfront/kbdfront Konrad Rzeszutek Wilk
2011-01-07 17:55 ` Daniel De Graaf
2011-01-07 18:28 ` Ian Campbell
2011-01-07 19:36 ` Daniel De Graaf
2011-01-07 20:44 ` Ian Campbell
2011-01-07 21:51 ` Daniel De Graaf
2011-01-07 22:09 ` [PATCH qemu] Support grant references in mapping Daniel De Graaf
2011-01-11 16:19 ` Ian Jackson
2011-02-25 15:01 ` Konrad Rzeszutek Wilk [this message]
2011-02-25 17:38 ` Stefano Stabellini
2011-01-07 19:21 ` [PATCH] Add grant references for fbfront/kbdfront Konrad Rzeszutek Wilk
2011-01-07 19:32 ` Daniel De Graaf
2011-01-07 19:51 ` Konrad Rzeszutek Wilk
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=20110225150152.GA12918@dumpdata.com \
--to=konrad.wilk@oracle.com \
--cc=Ian.Campbell@eu.citrix.com \
--cc=anthony.perard@citrix.com \
--cc=dgdegra@tycho.nsa.gov \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/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).