mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Vrabel <david.vrabel@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	linux-kernel@vger.kernel.org,
	"Andrew Morton" <akpm@linux-foundation.org>,
	David Vrabel <david.vrabel@citrix.com>
Subject: [PATCH 1/6] xen: add functions for mapping foreign pages over pages
Date: Thu, 15 Sep 2011 13:40:06 +0100	[thread overview]
Message-ID: <1316090411-22608-2-git-send-email-david.vrabel@citrix.com> (raw)
In-Reply-To: <1316090411-22608-1-git-send-email-david.vrabel@citrix.com>

From: David Vrabel <david.vrabel@citrix.com>

Add xenbus_map_ring_page() and xenbus_unmap_ring_page() which map and
unmap foreign pages over a page instead of mapping them into vmalloc
address space.  This avoids having to do an expensive
vmalloc_sync_all().

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
---
 drivers/xen/xenbus/xenbus_client.c |   68 ++++++++++++++++++++++++++++++++++++
 include/xen/xenbus.h               |    3 ++
 2 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
index cdacf92..504325b 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -32,6 +32,7 @@
 
 #include <linux/slab.h>
 #include <linux/types.h>
+#include <linux/mm.h>
 #include <linux/vmalloc.h>
 #include <asm/xen/hypervisor.h>
 #include <xen/interface/xen.h>
@@ -39,6 +40,7 @@
 #include <xen/events.h>
 #include <xen/grant_table.h>
 #include <xen/xenbus.h>
+#include <xen/page.h>
 
 const char *xenbus_strstate(enum xenbus_state state)
 {
@@ -509,6 +511,44 @@ EXPORT_SYMBOL_GPL(xenbus_map_ring);
 
 
 /**
+ * xenbus_map_ring_page - map a foreign page into a kernel page
+ * @dev: xenbus device
+ * @gnt_ref: grant reference
+ * @page: return the page the foreign page has been mapped to
+ *
+ * Map a foreign page from another domain's grant table into a newly
+ * allocated page in this domain.  The page must be unmapped with
+ * xenbus_unmap_ring_page().
+ *
+ * Returns 0 on success, and -ENOMEM or GNTST_* (see
+ * include/xen/interface/grant_table.h) on error.
+ */
+int xenbus_map_ring_page(struct xenbus_device *dev, int gnt_ref,
+			 struct page **page)
+{
+	struct page *new_page;
+	grant_ref_t handle;
+	int ret;
+
+	new_page = alloc_page(GFP_KERNEL);
+	if (!new_page)
+		return -ENOMEM;
+
+	ret = xenbus_map_ring(dev, gnt_ref, &handle, page_address(new_page));
+	if (ret < 0)
+		goto err;
+
+	new_page->private = handle;
+	*page = new_page;
+	return 0;
+
+err:
+	__free_page(new_page);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(xenbus_map_ring_page);
+
+/**
  * xenbus_unmap_ring_vfree
  * @dev: xenbus device
  * @vaddr: addr to unmap
@@ -593,6 +633,34 @@ int xenbus_unmap_ring(struct xenbus_device *dev,
 }
 EXPORT_SYMBOL_GPL(xenbus_unmap_ring);
 
+/**
+ * xenbus_unmap_ring_page - unmap an foreign page from a kernel page
+ * @dev: xenbus device
+ * @page: page the foreign page was mapped to
+ *
+ * Unmap a foreign page previously mapped with xenbus_map_ring_page().
+ * The page is freed.
+ */
+void xenbus_unmap_ring_page(struct xenbus_device *dev, struct page *page)
+{
+	int ret;
+
+	ret = xenbus_unmap_ring(dev, page->private, page_address(page));
+	if (ret < 0)
+		return;
+
+	/*
+	 * Restore the original PTE of this page before freeing it.
+	 */
+	ret = HYPERVISOR_update_va_mapping(
+		(unsigned long)page_address(page),
+		mfn_pte(get_phys_to_machine(page_to_pfn(page)), PAGE_KERNEL),
+		0);
+	BUG_ON(ret);
+
+	__free_page(page);
+}
+EXPORT_SYMBOL_GPL(xenbus_unmap_ring_page);
 
 /**
  * xenbus_read_driver_state
diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h
index aceeca7..ebde2fd 100644
--- a/include/xen/xenbus.h
+++ b/include/xen/xenbus.h
@@ -212,10 +212,13 @@ int xenbus_map_ring_valloc(struct xenbus_device *dev,
 			   int gnt_ref, void **vaddr);
 int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
 			   grant_handle_t *handle, void *vaddr);
+int xenbus_map_ring_page(struct xenbus_device *dev, int gnt_ref,
+			 struct page **page);
 
 int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr);
 int xenbus_unmap_ring(struct xenbus_device *dev,
 		      grant_handle_t handle, void *vaddr);
+void xenbus_unmap_ring_page(struct xenbus_device *dev, struct page *page);
 
 int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port);
 int xenbus_bind_evtchn(struct xenbus_device *dev, int remote_port, int *port);
-- 
1.7.2.5


  reply	other threads:[~2011-09-15 12:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-15 12:40 [PATCH 0/6] xen: don't call vmalloc_sync_all() when mapping foreign pages David Vrabel
2011-09-15 12:40 ` David Vrabel [this message]
2011-09-15 12:40 ` [PATCH 2/6] block: xen-blkback: use API provided by xenbus module to map rings David Vrabel
2011-09-15 12:40 ` [PATCH 3/6] net: xen-netback: " David Vrabel
2011-09-15 12:40 ` [PATCH 4/6] xen: xen-pciback: use xenbus_map_ring_page() " David Vrabel
2011-09-15 12:40 ` [PATCH 5/6] xen: xenbus: remove xenbus_map_ring_valloc() and xenbus_map_ring_vfree() David Vrabel
2011-09-15 12:40 ` [PATCH 6/6] mm: remove vmalloc_sync_all() from alloc_vm_area() David Vrabel
2011-09-15 21:37 ` [PATCH 0/6] xen: don't call vmalloc_sync_all() when mapping foreign pages Jeremy Fitzhardinge
2011-09-21 10:42   ` Stefano Stabellini
2011-09-21 18:57     ` [Xen-devel] " Jeremy Fitzhardinge
2011-09-22 11:06       ` Stefano Stabellini
2011-09-22 21:19         ` Jeremy Fitzhardinge
2011-09-23 10:53           ` Stefano Stabellini
2011-09-23 11:18           ` David Vrabel
2011-09-21 14:44   ` David Vrabel
2011-09-23 15:11     ` David Vrabel

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=1316090411-22608-2-git-send-email-david.vrabel@citrix.com \
    --to=david.vrabel@citrix.com \
    --cc=akpm@linux-foundation.org \
    --cc=konrad.wilk@oracle.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

Powered by JetHome