From: Julien Grall <julien.grall@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Wei Liu <wei.liu2@citrix.com>,
ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com,
linux-kernel@vger.kernel.org,
Julien Grall <julien.grall@citrix.com>,
David Vrabel <david.vrabel@citrix.com>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 12/20] xen/balloon: Don't rely on the page granularity is the same for Xen and Linux
Date: Thu, 9 Jul 2015 21:42:24 +0100 [thread overview]
Message-ID: <1436474552-31789-13-git-send-email-julien.grall@citrix.com> (raw)
In-Reply-To: <1436474552-31789-1-git-send-email-julien.grall@citrix.com>
For ARM64 guests, Linux is able to support either 64K or 4K page
granularity. Although, the hypercall interface is always based on 4K
page granularity.
With 64K page granuliarty, a single page will be spread over multiple
Xen frame.
When a driver request/free a balloon page, the balloon driver will have
to split the Linux page in 4K chunk before asking Xen to add/remove the
frame from the guest.
Note that this can work on any page granularity assuming it's a multiple
of 4K.
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: Wei Liu <wei.liu2@citrix.com>
---
Changes in v2:
- Use xen_apply_to_page to split a page in 4K chunk
- It's not necessary to have a smaller frame list. Re-use
PAGE_SIZE
- Convert reserve_additional_memory to use XEN_... macro
---
drivers/xen/balloon.c | 147 +++++++++++++++++++++++++++++++++++---------------
1 file changed, 105 insertions(+), 42 deletions(-)
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index fd93369..19a72b1 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -230,6 +230,7 @@ static enum bp_state reserve_additional_memory(long credit)
nid = memory_add_physaddr_to_nid(hotplug_start_paddr);
#ifdef CONFIG_XEN_HAVE_PVMMU
+ /* TODO */
/*
* add_memory() will build page tables for the new memory so
* the p2m must contain invalid entries so the correct
@@ -242,8 +243,8 @@ static enum bp_state reserve_additional_memory(long credit)
if (!xen_feature(XENFEAT_auto_translated_physmap)) {
unsigned long pfn, i;
- pfn = PFN_DOWN(hotplug_start_paddr);
- for (i = 0; i < balloon_hotplug; i++) {
+ pfn = XEN_PFN_DOWN(hotplug_start_paddr);
+ for (i = 0; i < (balloon_hotplug * XEN_PFN_PER_PAGE); i++) {
if (!set_phys_to_machine(pfn + i, INVALID_P2M_ENTRY)) {
pr_warn("set_phys_to_machine() failed, no memory added\n");
return BP_ECANCELED;
@@ -323,10 +324,72 @@ static enum bp_state reserve_additional_memory(long credit)
}
#endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */
+static int set_frame(struct page *page, unsigned long pfn, void *data)
+{
+ unsigned long *index = data;
+
+ frame_list[(*index)++] = pfn;
+
+ return 0;
+}
+
+#ifdef CONFIG_XEN_HAVE_PVMMU
+static int pvmmu_update_mapping(struct page *page, unsigned long pfn,
+ void *data)
+{
+ unsigned long *index = data;
+ xen_pfn_t frame = frame_list[*index];
+
+ set_phys_to_machine(pfn, frame);
+ /* Link back into the page tables if not highmem. */
+ if (!PageHighMem(page)) {
+ int ret;
+ ret = HYPERVISOR_update_va_mapping(
+ (unsigned long)__va(pfn << XEN_PAGE_SHIFT),
+ mfn_pte(frame, PAGE_KERNEL),
+ 0);
+ BUG_ON(ret);
+ }
+
+ (*index)++;
+
+ return 0;
+}
+#endif
+
+static int balloon_remove_mapping(struct page *page, unsigned long pfn,
+ void *data)
+{
+ unsigned long *index = data;
+
+ /* We expect the frame_list to contain the same pfn */
+ BUG_ON(pfn != frame_list[*index]);
+
+ frame_list[*index] = pfn_to_mfn(pfn);
+
+#ifdef CONFIG_XEN_HAVE_PVMMU
+ if (!xen_feature(XENFEAT_auto_translated_physmap)) {
+ if (!PageHighMem(page)) {
+ int ret;
+
+ ret = HYPERVISOR_update_va_mapping(
+ (unsigned long)__va(pfn << XEN_PAGE_SHIFT),
+ __pte_ma(0), 0);
+ BUG_ON(ret);
+ }
+ __set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
+ }
+#endif
+
+ (*index)++;
+
+ return 0;
+}
+
static enum bp_state increase_reservation(unsigned long nr_pages)
{
int rc;
- unsigned long pfn, i;
+ unsigned long i, frame_idx;
struct page *page;
struct xen_memory_reservation reservation = {
.address_bits = 0,
@@ -343,44 +406,43 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
}
#endif
- if (nr_pages > ARRAY_SIZE(frame_list))
- nr_pages = ARRAY_SIZE(frame_list);
+ if (nr_pages > (ARRAY_SIZE(frame_list) / XEN_PFN_PER_PAGE))
+ nr_pages = ARRAY_SIZE(frame_list) / XEN_PFN_PER_PAGE;
+ frame_idx = 0;
page = list_first_entry_or_null(&ballooned_pages, struct page, lru);
for (i = 0; i < nr_pages; i++) {
if (!page) {
nr_pages = i;
break;
}
- frame_list[i] = page_to_pfn(page);
+
+ rc = xen_apply_to_page(page, set_frame, &frame_idx);
+
page = balloon_next_page(page);
}
set_xen_guest_handle(reservation.extent_start, frame_list);
- reservation.nr_extents = nr_pages;
+ reservation.nr_extents = nr_pages * XEN_PFN_PER_PAGE;
rc = HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation);
if (rc <= 0)
return BP_EAGAIN;
- for (i = 0; i < rc; i++) {
+ /* rc is equal to the number of Xen page populated */
+ nr_pages = rc / XEN_PFN_PER_PAGE;
+
+ for (i = 0; i < nr_pages; i++) {
page = balloon_retrieve(false);
BUG_ON(page == NULL);
- pfn = page_to_pfn(page);
-
#ifdef CONFIG_XEN_HAVE_PVMMU
+ frame_idx = 0;
if (!xen_feature(XENFEAT_auto_translated_physmap)) {
- set_phys_to_machine(pfn, frame_list[i]);
-
- /* Link back into the page tables if not highmem. */
- if (!PageHighMem(page)) {
- int ret;
- ret = HYPERVISOR_update_va_mapping(
- (unsigned long)__va(pfn << PAGE_SHIFT),
- mfn_pte(frame_list[i], PAGE_KERNEL),
- 0);
- BUG_ON(ret);
- }
+ int ret;
+
+ ret = xen_apply_to_page(page, pvmmu_update_mapping,
+ &frame_idx);
+ BUG_ON(ret);
}
#endif
@@ -388,7 +450,7 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
__free_reserved_page(page);
}
- balloon_stats.current_pages += rc;
+ balloon_stats.current_pages += nr_pages;
return BP_DONE;
}
@@ -396,7 +458,7 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
{
enum bp_state state = BP_DONE;
- unsigned long pfn, i;
+ unsigned long pfn, i, frame_idx, nr_frames;
struct page *page;
int ret;
struct xen_memory_reservation reservation = {
@@ -414,9 +476,10 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
}
#endif
- if (nr_pages > ARRAY_SIZE(frame_list))
- nr_pages = ARRAY_SIZE(frame_list);
+ if (nr_pages > (ARRAY_SIZE(frame_list) / XEN_PFN_PER_PAGE))
+ nr_pages = ARRAY_SIZE(frame_list) / XEN_PFN_PER_PAGE;
+ frame_idx = 0;
for (i = 0; i < nr_pages; i++) {
page = alloc_page(gfp);
if (page == NULL) {
@@ -426,9 +489,12 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
}
scrub_page(page);
- frame_list[i] = page_to_pfn(page);
+ ret = xen_apply_to_page(page, set_frame, &frame_idx);
+ BUG_ON(ret);
}
+ nr_frames = nr_pages * XEN_PFN_PER_PAGE;
+
/*
* Ensure that ballooned highmem pages don't have kmaps.
*
@@ -439,22 +505,19 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
kmap_flush_unused();
/* Update direct mapping, invalidate P2M, and add to balloon. */
+ frame_idx = 0;
for (i = 0; i < nr_pages; i++) {
- pfn = frame_list[i];
- frame_list[i] = pfn_to_mfn(pfn);
- page = pfn_to_page(pfn);
+ /*
+ * The Xen PFN for a given Linux Page are contiguous in
+ * frame_list
+ */
+ pfn = frame_list[frame_idx];
+ page = xen_pfn_to_page(pfn);
-#ifdef CONFIG_XEN_HAVE_PVMMU
- if (!xen_feature(XENFEAT_auto_translated_physmap)) {
- if (!PageHighMem(page)) {
- ret = HYPERVISOR_update_va_mapping(
- (unsigned long)__va(pfn << PAGE_SHIFT),
- __pte_ma(0), 0);
- BUG_ON(ret);
- }
- __set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
- }
-#endif
+
+ ret = xen_apply_to_page(page, balloon_remove_mapping,
+ &frame_idx);
+ BUG_ON(ret);
balloon_append(page);
}
@@ -462,9 +525,9 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
flush_tlb_all();
set_xen_guest_handle(reservation.extent_start, frame_list);
- reservation.nr_extents = nr_pages;
+ reservation.nr_extents = nr_frames;
ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
- BUG_ON(ret != nr_pages);
+ BUG_ON(ret != nr_frames);
balloon_stats.current_pages -= nr_pages;
--
2.1.4
next prev parent reply other threads:[~2015-07-09 20:46 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1436474552-31789-1-git-send-email-julien.grall@citrix.com>
2015-07-09 20:42 ` [PATCH v2 01/20] xen: Add Xen specific page definition Julien Grall
2015-07-16 14:19 ` Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1507161515420.17378@kaball.uk.xensource.com>
2015-07-16 14:52 ` Julien Grall
2015-07-24 9:28 ` David Vrabel
[not found] ` <55B20540.3020000@citrix.com>
2015-07-24 9:39 ` Julien Grall
[not found] ` <55B207C6.4020300@citrix.com>
2015-07-24 9:48 ` David Vrabel
[not found] ` <55B209D9.1080602@citrix.com>
2015-07-24 9:51 ` Julien Grall
[not found] ` <55B20ABE.7000609@citrix.com>
2015-07-24 10:34 ` David Vrabel
[not found] ` <55B214C5.3020501@citrix.com>
2015-07-24 10:43 ` Ian Campbell
2015-07-24 13:03 ` Julien Grall
2015-07-09 20:42 ` [PATCH v2 02/20] xen: Introduce a function to split a Linux page into Xen page Julien Grall
2015-07-16 14:23 ` Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1507161520330.17378@kaball.uk.xensource.com>
2015-07-16 14:54 ` Julien Grall
[not found] ` <55A7C5A1.7060006@citrix.com>
2015-07-16 15:19 ` Andrew Cooper
2015-07-16 16:09 ` Julien Grall
2015-07-16 16:13 ` Andrew Cooper
2015-07-24 9:31 ` David Vrabel
[not found] ` <55B205FB.5080209@citrix.com>
2015-07-24 9:54 ` Julien Grall
[not found] ` <55B20B56.7020605@citrix.com>
2015-07-24 10:10 ` David Vrabel
[not found] ` <55B20F1F.60902@citrix.com>
2015-07-24 10:20 ` Julien Grall
2015-08-05 14:30 ` Julien Grall
[not found] ` <55C21DF3.2090201@citrix.com>
2015-08-05 15:50 ` David Vrabel
[not found] ` <55C230C9.7060506@citrix.com>
2015-08-05 16:06 ` Julien Grall
2015-07-09 20:42 ` [PATCH v2 03/20] xen/grant: Introduce helpers to split a page into grant Julien Grall
2015-07-09 20:42 ` [PATCH v2 04/20] xen/grant: Add helper gnttab_page_grant_foreign_access_ref Julien Grall
2015-07-09 20:42 ` [PATCH v2 05/20] block/xen-blkfront: Split blkif_queue_request in 2 Julien Grall
2015-07-09 20:42 ` [PATCH v2 06/20] block/xen-blkfront: Store a page rather a pfn in the grant structure Julien Grall
2015-07-09 20:42 ` [PATCH v2 07/20] block/xen-blkfront: split get_grant in 2 Julien Grall
2015-07-09 20:42 ` [PATCH v2 08/20] net/xen-netback: xenvif_gop_frag_copy: move GSO check out of the loop Julien Grall
2015-07-09 20:42 ` [PATCH v2 09/20] xen/biomerge: Don't allow biovec to be merge when Linux is not using 4KB page Julien Grall
2015-07-10 19:12 ` Konrad Rzeszutek Wilk
[not found] ` <20150710191245.GA31063@l.oracle.com>
2015-07-15 8:56 ` Julien Grall
2015-07-16 15:33 ` Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1507161627010.17378@kaball.uk.xensource.com>
2015-07-16 16:15 ` Julien Grall
[not found] ` <55A7D8AD.1090102@citrix.com>
2015-07-16 18:30 ` Konrad Rzeszutek Wilk
2015-07-17 13:20 ` Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1507171418260.17378@kaball.uk.xensource.com>
2015-07-17 14:44 ` Julien Grall
[not found] ` <55A914D5.7080900@citrix.com>
2015-07-17 14:45 ` Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1507171545170.17378@kaball.uk.xensource.com>
2015-07-17 14:46 ` Julien Grall
2015-07-09 20:42 ` [PATCH v2 10/20] xen/xenbus: Use Xen page definition Julien Grall
2015-07-16 15:35 ` Stefano Stabellini
2015-07-24 9:49 ` David Vrabel
2015-07-09 20:42 ` [PATCH v2 11/20] tty/hvc: xen: Use xen " Julien Grall
2015-07-09 20:42 ` Julien Grall [this message]
2015-07-17 14:03 ` [PATCH v2 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.1507161819200.17378@kaball.uk.xensource.com>
2015-07-17 14:32 ` Julien Grall
2015-07-09 20:42 ` [PATCH v2 13/20] xen/events: fifo: Make it running on 64KB granularity Julien Grall
2015-07-09 20:42 ` [PATCH v2 14/20] xen/grant-table: " Julien Grall
2015-07-09 20:42 ` [PATCH v2 15/20] block/xen-blkfront: Make it running on 64KB page granularity Julien Grall
2015-07-21 11:06 ` Roger Pau Monné
[not found] ` <55AE27C2.8090803@citrix.com>
2015-07-21 13:07 ` Julien Grall
2015-07-09 20:42 ` [PATCH v2 16/20] block/xen-blkback: " Julien Grall
2015-07-09 20:42 ` [PATCH v2 17/20] net/xen-netfront: " Julien Grall
2015-07-09 20:42 ` [PATCH v2 18/20] net/xen-netback: " Julien Grall
2015-07-09 20:42 ` [PATCH v2 19/20] xen/privcmd: Add support for Linux " Julien Grall
2015-07-09 20:42 ` [PATCH v2 20/20] arm/xen: Add support for " Julien Grall
[not found] ` <1436474552-31789-20-git-send-email-julien.grall@citrix.com>
2015-07-13 20:13 ` [PATCH v2 19/20] xen/privcmd: Add support for Linux " Boris Ostrovsky
[not found] ` <55A41BE4.3080104@oracle.com>
2015-07-13 22:05 ` Julien Grall
[not found] ` <55A43638.4030503@citrix.com>
2015-07-14 15:28 ` Boris Ostrovsky
[not found] ` <55A52A9E.2000400@oracle.com>
2015-07-14 15:37 ` Julien Grall
2015-07-16 17:12 ` Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1507161707300.17378@kaball.uk.xensource.com>
2015-07-16 17:16 ` Stefano Stabellini
2015-07-17 12:50 ` Julien Grall
[not found] ` <1436474552-31789-4-git-send-email-julien.grall@citrix.com>
2015-07-16 15:01 ` [PATCH v2 03/20] xen/grant: Introduce helpers to split a page into grant Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1507161526030.17378@kaball.uk.xensource.com>
2015-07-16 16:07 ` Julien Grall
[not found] ` <55A7D6AC.5060004@citrix.com>
2015-07-17 13:10 ` Julien Grall
[not found] ` <1436474552-31789-5-git-send-email-julien.grall@citrix.com>
2015-07-16 15:05 ` [PATCH v2 04/20] xen/grant: Add helper gnttab_page_grant_foreign_access_ref Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1507161603490.17378@kaball.uk.xensource.com>
2015-07-16 16:12 ` Julien Grall
2015-07-24 9:35 ` David Vrabel
[not found] ` <1436474552-31789-15-git-send-email-julien.grall@citrix.com>
2015-07-16 15:47 ` [PATCH v2 14/20] xen/grant-table: Make it running on 64KB granularity Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1507161643380.17378@kaball.uk.xensource.com>
2015-07-16 16:23 ` Julien Grall
[not found] ` <55A7DA8F.2040805@citrix.com>
2015-07-17 13:37 ` Stefano Stabellini
[not found] ` <1436474552-31789-18-git-send-email-julien.grall@citrix.com>
2015-07-20 17:26 ` [PATCH v2 17/20] net/xen-netfront: Make it running on 64KB page granularity Julien Grall
2015-07-20 17:54 ` [PATCH v2 00/20] xen/arm64: Add support for 64KB page Julien Grall
[not found] ` <1436474552-31789-6-git-send-email-julien.grall@citrix.com>
2015-07-21 9:54 ` [PATCH v2 05/20] block/xen-blkfront: Split blkif_queue_request in 2 Roger Pau Monné
[not found] ` <55AE16EC.2020204@citrix.com>
2015-07-21 11:12 ` Julien Grall
[not found] ` <1436474552-31789-7-git-send-email-julien.grall@citrix.com>
2015-07-16 15:11 ` [PATCH v2 06/20] block/xen-blkfront: Store a page rather a pfn in the grant structure Stefano Stabellini
2015-07-21 10:16 ` Roger Pau Monné
[not found] ` <55AE1BE7.5030102@citrix.com>
2015-07-21 11:19 ` Julien Grall
[not found] ` <alpine.DEB.2.02.1507161610570.17378@kaball.uk.xensource.com>
2015-07-23 17:18 ` Julien Grall
[not found] ` <1436474552-31789-8-git-send-email-julien.grall@citrix.com>
2015-07-21 10:30 ` [PATCH v2 07/20] block/xen-blkfront: split get_grant in 2 Roger Pau Monné
[not found] ` <55AE1F2A.6010300@citrix.com>
2015-07-21 13:03 ` Julien Grall
[not found] ` <1436474552-31789-12-git-send-email-julien.grall@citrix.com>
2015-07-16 15:36 ` [PATCH v2 11/20] tty/hvc: xen: Use xen page definition Stefano Stabellini
2015-07-24 9:52 ` David Vrabel
[not found] ` <1436474552-31789-14-git-send-email-julien.grall@citrix.com>
2015-07-16 15:43 ` [PATCH v2 13/20] xen/events: fifo: Make it running on 64KB granularity Stefano Stabellini
[not found] ` <alpine.DEB.2.02.1507161642130.17378@kaball.uk.xensource.com>
2015-07-16 16:18 ` Julien Grall
[not found] ` <55A7D955.5090203@citrix.com>
2015-07-17 13:06 ` Stefano Stabellini
2015-07-24 10:36 ` David Vrabel
[not found] ` <55B21527.4010601@citrix.com>
2015-08-06 15:43 ` Julien Grall
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=1436474552-31789-13-git-send-email-julien.grall@citrix.com \
--to=julien.grall@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=david.vrabel@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stefano.stabellini@eu.citrix.com \
--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).