From: Julien Grall <julien.grall@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: x86@kernel.org, ian.campbell@citrix.com,
stefano.stabellini@eu.citrix.com, linux-kernel@vger.kernel.org,
Julien Grall <julien.grall@citrix.com>,
Ingo Molnar <mingo@redhat.com>,
David Vrabel <david.vrabel@citrix.com>,
"H. Peter Anvin" <hpa@zytor.com>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
Thomas Gleixner <tglx@linutronix.de>,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 04/20] xen/grant: Introduce helpers to split a page into grant
Date: Fri, 7 Aug 2015 17:46:43 +0100 [thread overview]
Message-ID: <1438966019-19322-5-git-send-email-julien.grall@citrix.com> (raw)
In-Reply-To: <1438966019-19322-1-git-send-email-julien.grall@citrix.com>
Currently, a grant is always based on the Xen page granularity (i.e
4KB). When Linux is using a different page granularity, a single page
will be split between multiple grants.
The new helpers will be in charge to split the Linux page into grants and
call a function given by the caller on each grant.
Also provide an helper to count the number of grants within a given
contiguous region.
Note that the x86/include/asm/xen/page.h is now including
xen/interface/grant_table.h rather than xen/grant_table.h. It's
necessary because xen/grant_table.h depends on asm/xen/page.h and will
break the compilation. Furthermore, only definition in
interface/grant_table.h was required.
Signed-off-by: Julien Grall <julien.grall@citrix.com>
---
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Changes in v3:
- Fix error reported by checkpatch.pl
- Typoes
- s/pfn/xen_pfn/ in gnttab_foreach_grant
- Drop the possibility to use less data. The complexity is moved
in netback which is the only user
- Rename gnttab_foreach_grant into gnttab_foreach_grant_in_range
- s/offset/start/ in gnttab_count_grant and update the
description of the parameter
- s/mfn/gfn base on the new terminologies
- Add EXPORT_SYMBOL_GPL for gnttab_foreach_grant_in_range
- Use xen_offset_in_page and XEN_PFN_DOWN whenever it's possible
- Fix compilation on x86.
Changes in v2:
- Patch added
---
arch/x86/include/asm/xen/page.h | 2 +-
drivers/xen/grant-table.c | 26 +++++++++++++++++++++++++
include/xen/grant_table.h | 42 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index 0b762f6..501479e 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -12,7 +12,7 @@
#include <asm/pgtable.h>
#include <xen/interface/xen.h>
-#include <xen/grant_table.h>
+#include <xen/interface/grant_table.h>
#include <xen/features.h>
/* Xen machine address */
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 62f591f..94ae0fd 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -776,6 +776,32 @@ void gnttab_batch_copy(struct gnttab_copy *batch, unsigned count)
}
EXPORT_SYMBOL_GPL(gnttab_batch_copy);
+void gnttab_foreach_grant_in_range(struct page *page,
+ unsigned int offset,
+ unsigned int len,
+ xen_grant_fn_t fn,
+ void *data)
+{
+ unsigned int goffset;
+ unsigned int glen;
+ unsigned long xen_pfn;
+
+ len = min_t(unsigned int, PAGE_SIZE - offset, len);
+ goffset = xen_offset_in_page(offset);
+
+ xen_pfn = xen_page_to_pfn(page) + XEN_PFN_DOWN(offset);
+
+ while (len) {
+ glen = min_t(unsigned int, XEN_PAGE_SIZE - goffset, len);
+ fn(pfn_to_gfn(xen_pfn), goffset, glen, data);
+
+ goffset = 0;
+ xen_pfn++;
+ len -= glen;
+ }
+}
+EXPORT_SYMBOL_GPL(gnttab_foreach_grant_in_range);
+
int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
struct gnttab_map_grant_ref *kmap_ops,
struct page **pages, unsigned int count)
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index 4478f4b..2a8ebe8 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -45,8 +45,10 @@
#include <asm/xen/hypervisor.h>
#include <xen/features.h>
+#include <xen/page.h>
#include <linux/mm_types.h>
#include <linux/page-flags.h>
+#include <linux/kernel.h>
#define GNTTAB_RESERVED_XENSTORE 1
@@ -224,4 +226,44 @@ static inline struct xen_page_foreign *xen_page_foreign(struct page *page)
#endif
}
+/* Split Linux page in chunk of the size of the grant and call fn
+ *
+ * Parameters of fn:
+ * gfn: guest frame number
+ * offset: offset in the grant
+ * len: length of the data in the grant.
+ * data: internal information
+ */
+typedef void (*xen_grant_fn_t)(unsigned long gfn, unsigned int offset,
+ unsigned int len, void *data);
+
+void gnttab_foreach_grant_in_range(struct page *page,
+ unsigned int offset,
+ unsigned int len,
+ xen_grant_fn_t fn,
+ void *data);
+
+/* Helper to get to call fn only on the first "grant chunk" */
+static inline void gnttab_one_grant(struct page *page, unsigned int offset,
+ unsigned len, xen_grant_fn_t fn,
+ void *data)
+{
+ /* The first request is limited to the size of one grant */
+ len = min_t(unsigned int, XEN_PAGE_SIZE - (offset & ~XEN_PAGE_MASK),
+ len);
+
+ gnttab_foreach_grant_in_range(page, offset, len, fn, data);
+}
+
+/* Get the number of grant in a specified region
+ *
+ * start: Offset from the beginning of the first page
+ * len: total length of data (can cross multiple page)
+ */
+static inline unsigned int gnttab_count_grant(unsigned int start,
+ unsigned int len)
+{
+ return XEN_PFN_UP(xen_offset_in_page(start) + len);
+}
+
#endif /* __ASM_GNTTAB_H__ */
--
2.1.4
next prev parent reply other threads:[~2015-08-07 16:48 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-07 16:46 [PATCH v3 00/20] xen/arm64: Add support for 64KB page Julien Grall
2015-08-07 16:46 ` [PATCH v3 01/20] net/xen-netback: xenvif_gop_frag_copy: move GSO check out of the loop Julien Grall
2015-08-08 13:59 ` Wei Liu
2015-08-07 16:46 ` [PATCH v3 02/20] arm/xen: Drop pte_mfn and mfn_pte Julien Grall
2015-08-07 16:46 ` [PATCH v3 03/20] xen: Add Xen specific page definition Julien Grall
2015-08-10 10:46 ` Stefano Stabellini
2015-08-20 9:49 ` David Vrabel
2015-08-07 16:46 ` Julien Grall [this message]
2015-08-10 10:44 ` [PATCH v3 04/20] xen/grant: Introduce helpers to split a page into grant Stefano Stabellini
2015-08-20 9:51 ` David Vrabel
[not found] ` <55D5A337.7090704@citrix.com>
2015-08-28 14:29 ` Julien Grall
2015-08-07 16:46 ` [PATCH v3 05/20] xen/grant: Add helper gnttab_page_grant_foreign_access_ref_one Julien Grall
2015-08-07 16:46 ` [PATCH v3 06/20] block/xen-blkfront: Split blkif_queue_request in 2 Julien Grall
2015-08-07 16:46 ` [PATCH v3 07/20] block/xen-blkfront: Store a page rather a pfn in the grant structure Julien Grall
2015-08-07 16:46 ` [PATCH v3 08/20] block/xen-blkfront: split get_grant in 2 Julien Grall
2015-08-07 16:46 ` [PATCH v3 09/20] xen/biomerge: Don't allow biovec to be merge when Linux is not using 4KB page Julien Grall
2015-08-07 16:46 ` [PATCH v3 10/20] xen/xenbus: Use Xen page definition Julien Grall
2015-08-07 16:46 ` [PATCH v3 11/20] tty/hvc: xen: Use xen " Julien Grall
2015-08-07 16:46 ` [PATCH v3 12/20] xen/balloon: Don't rely on the page granularity is the same for Xen and Linux Julien Grall
2015-08-07 16:46 ` [PATCH v3 13/20] xen/events: fifo: Make it running on 64KB granularity Julien Grall
2015-08-07 16:46 ` [PATCH v3 14/20] xen/grant-table: " Julien Grall
2015-08-07 16:46 ` [PATCH v3 15/20] block/xen-blkfront: Make it running on 64KB page granularity Julien Grall
2015-08-07 16:46 ` [PATCH v3 16/20] block/xen-blkback: " Julien Grall
2015-08-07 16:46 ` [PATCH v3 17/20] net/xen-netfront: " Julien Grall
2015-08-20 10:03 ` David Vrabel
2015-08-07 16:46 ` [PATCH v3 18/20] net/xen-netback: " Julien Grall
2015-08-07 16:46 ` [PATCH v3 19/20] xen/privcmd: Add support for Linux " Julien Grall
2015-08-07 16:46 ` [PATCH v3 20/20] arm/xen: Add support for " Julien Grall
2015-08-10 12:52 ` Stefano Stabellini
2015-08-07 17:11 ` [PATCH v3 00/20] xen/arm64: Add support for 64KB page Julien Grall
[not found] ` <1438966019-19322-19-git-send-email-julien.grall@citrix.com>
2015-08-08 14:55 ` [PATCH v3 18/20] net/xen-netback: Make it running on 64KB page granularity Wei Liu
[not found] ` <20150808145534.GB14214@zion.uk.xensource.com>
2015-08-10 9:57 ` Julien Grall
[not found] ` <55C8759C.3010507@citrix.com>
2015-08-10 11:39 ` Wei Liu
[not found] ` <20150810113907.GH8857@zion.uk.xensource.com>
2015-08-10 12:00 ` Julien Grall
[not found] ` <1438966019-19322-3-git-send-email-julien.grall@citrix.com>
2015-08-10 10:10 ` [PATCH v3 02/20] arm/xen: Drop pte_mfn and mfn_pte Stefano Stabellini
[not found] ` <1438966019-19322-10-git-send-email-julien.grall@citrix.com>
2015-08-10 10:50 ` [PATCH v3 09/20] xen/biomerge: Don't allow biovec to be merge when Linux is not using 4KB page Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1508101149070.11337@kaball.uk.xensource.com>
2015-08-10 11:24 ` Julien Grall
[not found] ` <55C889E4.8050307@citrix.com>
2015-08-10 11:25 ` Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1508101224220.11337@kaball.uk.xensource.com>
2015-08-10 11:32 ` Julien Grall
[not found] ` <55C88BD8.7040807@citrix.com>
2015-08-10 12:41 ` David Vrabel
[not found] ` <1438966019-19322-13-git-send-email-julien.grall@citrix.com>
2015-08-10 11:18 ` [PATCH v3 12/20] xen/balloon: Don't rely on the page granularity is the same for Xen and Linux Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1508101207071.11337@kaball.uk.xensource.com>
2015-08-10 11:31 ` Julien Grall
[not found] ` <55C88B77.8030700@citrix.com>
2015-08-10 12:55 ` Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1508101352370.11337@kaball.uk.xensource.com>
2015-08-10 13:36 ` Julien Grall
2015-08-20 9:59 ` David Vrabel
[not found] ` <55D5A51D.2060106@citrix.com>
2015-08-28 15:10 ` Julien Grall
[not found] ` <1438966019-19322-20-git-send-email-julien.grall@citrix.com>
2015-08-10 12:03 ` [PATCH v3 19/20] xen/privcmd: Add support for Linux 64KB page granularity Stefano Stabellini
2015-08-20 10:08 ` David Vrabel
[not found] ` <alpine.DEB.2.02.1508101230260.11337@kaball.uk.xensource.com>
2015-08-10 12:14 ` David Vrabel
[not found] ` <55C895A8.9020004@citrix.com>
2015-08-10 12:57 ` Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1508101356200.11337@kaball.uk.xensource.com>
2015-08-10 13:25 ` Julien Grall
2015-09-01 17:10 ` Julien Grall
2015-08-20 0:40 ` [PATCH v3 00/20] xen/arm64: Add support for 64KB page Julien Grall
[not found] ` <1438966019-19322-9-git-send-email-julien.grall@citrix.com>
2015-08-20 7:33 ` [PATCH v3 08/20] block/xen-blkfront: split get_grant in 2 Roger Pau Monné
[not found] ` <1438966019-19322-16-git-send-email-julien.grall@citrix.com>
2015-08-20 8:10 ` [PATCH v3 15/20] block/xen-blkfront: Make it running on 64KB page granularity Roger Pau Monné
[not found] ` <55D58B6F.8010904@citrix.com>
2015-08-28 15:33 ` Julien Grall
[not found] ` <1438966019-19322-17-git-send-email-julien.grall@citrix.com>
2015-08-20 8:14 ` [PATCH v3 16/20] block/xen-blkback: " Roger Pau Monné
[not found] ` <1438966019-19322-12-git-send-email-julien.grall@citrix.com>
2015-08-20 9:55 ` [PATCH v3 11/20] tty/hvc: xen: Use xen page definition David Vrabel
[not found] ` <55D5A42E.7070800@citrix.com>
2015-08-28 15:03 ` Julien Grall
[not found] ` <55D521F2.5080504@citrix.com>
2015-08-20 8:15 ` [PATCH v3 00/20] xen/arm64: Add support for 64KB page Roger Pau Monné
2015-08-20 10:11 ` David Vrabel
[not found] ` <55D5A7CB.3070207@citrix.com>
2015-08-20 15:03 ` Julien Grall
[not found] ` <55D5EC45.5010306@citrix.com>
2015-08-20 15:15 ` 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=1438966019-19322-5-git-send-email-julien.grall@citrix.com \
--to=julien.grall@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=david.vrabel@citrix.com \
--cc=hpa@zytor.com \
--cc=ian.campbell@citrix.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--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).