From: stefano.stabellini@eu.citrix.com
To: linux-kernel@vger.kernel.org
Cc: xen-devel@lists.xensource.com,
Jeremy Fitzhardinge <Jeremy.Fitzhardinge@citrix.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Subject: [PATCH 10/11] xen gntdev: use gnttab_map_refs and gnttab_unmap_refs
Date: Wed, 15 Dec 2010 13:40:45 +0000 [thread overview]
Message-ID: <1292420446-3348-10-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1012151259510.2390@kaball-desktop>
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Use gnttab_map_refs and gnttab_unmap_refs to map and unmap the grant
ref, so that we can have a corresponding struct page.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
drivers/xen/gntdev.c | 37 ++++++++++++++++++++++++++++++-------
1 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index fc5e420..35de6bb 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -68,6 +68,7 @@ struct grant_map {
struct ioctl_gntdev_grant_ref *grants;
struct gnttab_map_grant_ref *map_ops;
struct gnttab_unmap_grant_ref *unmap_ops;
+ struct page **pages;
};
/* ------------------------------------------------------------------ */
@@ -88,6 +89,7 @@ static void gntdev_print_maps(struct gntdev_priv *priv,
static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count)
{
struct grant_map *add;
+ int i;
add = kzalloc(sizeof(struct grant_map), GFP_KERNEL);
if (NULL == add)
@@ -96,11 +98,19 @@ static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count)
add->grants = kzalloc(sizeof(add->grants[0]) * count, GFP_KERNEL);
add->map_ops = kzalloc(sizeof(add->map_ops[0]) * count, GFP_KERNEL);
add->unmap_ops = kzalloc(sizeof(add->unmap_ops[0]) * count, GFP_KERNEL);
- if (NULL == add->grants ||
- NULL == add->map_ops ||
- NULL == add->unmap_ops)
+ add->pages = kzalloc(sizeof(add->pages[0]) * count, GFP_KERNEL);
+ if (NULL == add->grants ||
+ NULL == add->map_ops ||
+ NULL == add->unmap_ops ||
+ NULL == add->pages)
goto err;
+ for (i = 0; i < count; i++) {
+ add->pages[i] = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
+ if (add->pages[i] == NULL)
+ goto err;
+ }
+
add->index = 0;
add->count = count;
add->priv = priv;
@@ -111,6 +121,12 @@ static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count)
return add;
err:
+ if (add->pages)
+ for (i = 0; i < count; i++) {
+ if (add->pages[i])
+ __free_page(add->pages[i]);
+ }
+ kfree(add->pages);
kfree(add->grants);
kfree(add->map_ops);
kfree(add->unmap_ops);
@@ -186,8 +202,17 @@ static int gntdev_del_map(struct grant_map *map)
static void gntdev_free_map(struct grant_map *map)
{
+ unsigned i;
+
if (!map)
return;
+
+ if (map->pages)
+ for (i = 0; i < map->count; i++) {
+ if (map->pages[i])
+ __free_page(map->pages[i]);
+ }
+ kfree(map->pages);
kfree(map->grants);
kfree(map->map_ops);
kfree(map->unmap_ops);
@@ -221,8 +246,7 @@ static int map_grant_pages(struct grant_map *map)
if (debug)
printk("%s: map %d+%d\n", __FUNCTION__, map->index, map->count);
- err = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref,
- map->map_ops, map->count);
+ err = gnttab_map_refs(map->map_ops, map->pages, map->count);
if (WARN_ON(err))
return err;
@@ -241,8 +265,7 @@ static int unmap_grant_pages(struct grant_map *map, int offset, int pages)
if (debug)
printk("%s: map %d+%d [%d+%d]\n", __FUNCTION__,
map->index, map->count, offset, pages);
- err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
- map->unmap_ops + offset, pages);
+ err = gnttab_unmap_refs(map->unmap_ops + offset, map->pages, pages);
if (WARN_ON(err))
return err;
--
1.5.6.5
next prev parent reply other threads:[~2010-12-15 13:40 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-15 13:39 [PATCH 00/11] xen: allow usermode to map granted pages Stefano Stabellini
2010-12-15 13:40 ` [PATCH 01/11] xen: define gnttab_set_map_op/unmap_op stefano.stabellini
2011-01-05 20:25 ` Konrad Rzeszutek Wilk
2011-01-06 9:16 ` Ian Campbell
2010-12-15 13:40 ` [PATCH 02/11] xen/gntdev: allow usermode to map granted pages stefano.stabellini
2011-01-05 20:25 ` [Xen-devel] " Konrad Rzeszutek Wilk
2011-01-06 9:21 ` [SPAM] " Ian Campbell
2011-01-10 10:33 ` [Xen-devel] " Stefano Stabellini
2010-12-15 13:40 ` [PATCH 03/11] xen/gntdev: add VM_PFNMAP to vma stefano.stabellini
2010-12-15 13:40 ` [PATCH 04/11] xen: move p2m handling to separate file stefano.stabellini
2011-01-05 20:24 ` Konrad Rzeszutek Wilk
2010-12-15 13:40 ` [PATCH 05/11] xen: add m2p override mechanism stefano.stabellini
2010-12-15 13:40 ` [PATCH 06/11] xen: gntdev: move use of GNTMAP_contains_pte next to the map_op stefano.stabellini
2011-01-05 20:24 ` Konrad Rzeszutek Wilk
2011-01-10 10:32 ` Stefano Stabellini
2011-01-10 21:16 ` Konrad Rzeszutek Wilk
2010-12-15 13:40 ` [PATCH 07/11] xen/gntdev: stop using "token" argument stefano.stabellini
2010-12-15 13:40 ` [PATCH 08/11] xen p2m: transparently change the p2m mappings in the m2p override stefano.stabellini
2010-12-15 23:36 ` [Xen-devel] " Jeremy Fitzhardinge
2010-12-16 15:25 ` Stefano Stabellini
2011-01-05 20:24 ` Konrad Rzeszutek Wilk
2010-12-15 13:40 ` [PATCH 09/11] xen: introduce gnttab_map_refs and gnttab_unmap_refs stefano.stabellini
2011-01-05 20:23 ` Konrad Rzeszutek Wilk
2011-01-10 10:32 ` Stefano Stabellini
2010-12-15 13:40 ` stefano.stabellini [this message]
2011-01-05 20:23 ` [PATCH 10/11] xen gntdev: use " Konrad Rzeszutek Wilk
2011-01-10 10:33 ` Stefano Stabellini
2010-12-15 13:40 ` [PATCH 11/11] xen p2m: clear the old pte when adding a page to m2p_override stefano.stabellini
2011-01-05 20:23 ` Konrad Rzeszutek Wilk
2011-01-10 10:32 ` Stefano Stabellini
2010-12-15 13:43 ` [PATCH 00/11] xen: allow usermode to map granted pages Stefano Stabellini
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=1292420446-3348-10-git-send-email-stefano.stabellini@eu.citrix.com \
--to=stefano.stabellini@eu.citrix.com \
--cc=Jeremy.Fitzhardinge@citrix.com \
--cc=linux-kernel@vger.kernel.org \
--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).