From: Wei Liu <wei.liu2@citrix.com>
To: xen-devel@lists.xen.org
Cc: Wei Liu <wei.liu2@citrix.com>,
ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com,
david.vrabel@citrix.com, boris.ostrovsky@oracle.com
Subject: [PATCH RFC 07/10] xen/balloon: factor out some helper functions
Date: Wed, 15 Oct 2014 16:54:16 +0100 [thread overview]
Message-ID: <1413388459-4663-8-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1413388459-4663-1-git-send-email-wei.liu2@citrix.com>
They will be used in the page migration routine.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
drivers/xen/balloon.c | 121 +++++++++++++++++++++++++++----------------------
1 file changed, 68 insertions(+), 53 deletions(-)
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 24efdf6..815e1d5 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -312,6 +312,67 @@ static inline void __reinsert_balloon_pages(struct list_head *head)
spin_unlock_irqrestore(&xen_balloon.xb_dev_info->pages_lock, flags);
}
+static int __memory_op_hypercall(int cmd, xen_pfn_t *list, xen_ulong_t nr)
+{
+ int rc;
+ struct xen_memory_reservation reservation = {
+ .address_bits = 0,
+ .extent_order = 0,
+ .domid = DOMID_SELF
+ };
+
+ set_xen_guest_handle(reservation.extent_start, list);
+ reservation.nr_extents = nr;
+ rc = HYPERVISOR_memory_op(cmd, &reservation);
+
+ return rc;
+}
+
+static void __link_back_to_pagetable(struct page *page, xen_ulong_t mfn,
+ pte_t pte)
+{
+#ifdef CONFIG_XEN_HAVE_PVMMU
+ unsigned long pfn = page_to_pfn(page);
+
+ if (!xen_feature(XENFEAT_auto_translated_physmap)) {
+ set_phys_to_machine(pfn, mfn);
+
+ /* 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),
+ pte, 0);
+ BUG_ON(ret);
+ }
+ }
+#endif
+}
+
+static void __replace_mapping_with_scratch_page(struct page *page)
+{
+#ifdef CONFIG_XEN_HAVE_PVMMU
+ /*
+ * Ballooned out frames are effectively replaced with
+ * a scratch frame. Ensure direct mappings and the
+ * p2m are consistent.
+ */
+ if (!xen_feature(XENFEAT_auto_translated_physmap)) {
+ unsigned long p, smfn;
+ struct page *scratch_page = get_balloon_scratch_page();
+
+ p = page_to_pfn(scratch_page);
+ smfn = pfn_to_mfn(p);
+
+ __link_back_to_pagetable(page, smfn,
+ mfn_pte(smfn, PAGE_KERNEL_RO));
+
+ put_balloon_scratch_page();
+ }
+#endif
+}
+
+
/* This function will always try to fill in pages managed by Xen
* balloon driver, then pages managed by generic balloon driver.
*/
@@ -322,11 +383,6 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
struct page *page;
LIST_HEAD(queue);
bool xen_pages;
- struct xen_memory_reservation reservation = {
- .address_bits = 0,
- .extent_order = 0,
- .domid = DOMID_SELF
- };
#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG
if (!xen_balloon.balloon_stats.balloon_low &&
@@ -365,9 +421,8 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
}
/* Second step: issue hypercall */
- set_xen_guest_handle(reservation.extent_start, frame_list);
- reservation.nr_extents = nr_pages;
- rc = HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation);
+ rc = __memory_op_hypercall(XENMEM_populate_physmap, frame_list,
+ nr_pages);
if (rc <= 0) {
rc = BP_EAGAIN;
goto move_pages_back;
@@ -382,21 +437,8 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
list_del(&page->lru);
pfn = page_to_pfn(page);
-#ifdef CONFIG_XEN_HAVE_PVMMU
- 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);
- }
- }
-#endif
+ __link_back_to_pagetable(page, frame_list[i],
+ mfn_pte(frame_list[i], PAGE_KERNEL));
/* Relinquish the page back to the allocator. */
if (xen_pages)
@@ -439,11 +481,6 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp,
unsigned long pfn, i;
struct page *page;
int ret;
- struct xen_memory_reservation reservation = {
- .address_bits = 0,
- .extent_order = 0,
- .domid = DOMID_SELF
- };
#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG
if (xen_balloon.balloon_stats.hotplug_pages) {
@@ -489,36 +526,14 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp,
frame_list[i] = pfn_to_mfn(pfn);
page = pfn_to_page(pfn);
-#ifdef CONFIG_XEN_HAVE_PVMMU
- /*
- * Ballooned out frames are effectively replaced with
- * a scratch frame. Ensure direct mappings and the
- * p2m are consistent.
- */
- if (!xen_feature(XENFEAT_auto_translated_physmap)) {
- if (!PageHighMem(page)) {
- struct page *scratch_page = get_balloon_scratch_page();
-
- ret = HYPERVISOR_update_va_mapping(
- (unsigned long)__va(pfn << PAGE_SHIFT),
- pfn_pte(page_to_pfn(scratch_page),
- PAGE_KERNEL_RO), 0);
- BUG_ON(ret);
-
- put_balloon_scratch_page();
- }
- __set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
- }
-#endif
-
+ __replace_mapping_with_scratch_page(page);
balloon_append(page, core_driver);
}
flush_tlb_all();
- set_xen_guest_handle(reservation.extent_start, frame_list);
- reservation.nr_extents = nr_pages;
- ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
+ ret = __memory_op_hypercall(XENMEM_decrease_reservation, frame_list,
+ nr_pages);
BUG_ON(ret != nr_pages);
xen_balloon.balloon_stats.current_pages -= nr_pages;
--
1.7.10.4
next prev parent reply other threads:[~2014-10-15 15:54 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-15 15:54 [PATCH RFC 00/10] Xen balloon page compaction support Wei Liu
2014-10-15 15:54 ` [PATCH RFC 01/10] balloon_compaction: don't BUG() when it is not necessary Wei Liu
2014-10-15 15:54 ` [PATCH RFC 02/10] xen/balloon: fix code comment for free_xenballooned_pages Wei Liu
2014-10-15 15:54 ` [PATCH RFC 03/10] xen/balloon: consolidate data structures Wei Liu
2014-10-15 15:54 ` [PATCH RFC 04/10] xen/balloon: factor out function to update balloon stats Wei Liu
2014-10-15 15:54 ` [PATCH RFC 05/10] xen/balloon: rework increase_reservation Wei Liu
2014-10-15 15:54 ` [PATCH RFC 06/10] xen/balloon: make use of generic balloon driver Wei Liu
2014-10-15 15:54 ` Wei Liu [this message]
2014-10-15 15:54 ` [PATCH RFC 08/10] xen/balloon: implement migratepage Wei Liu
2014-10-15 16:16 ` David Vrabel
2014-10-16 9:28 ` Ian Campbell
2014-10-15 15:54 ` [PATCH RFC 09/10] balloon: BALLOON_COMPACTION now depends on XEN_BALLOON Wei Liu
2014-10-15 15:54 ` [PATCH RFC 10/10] XXX: balloon bitmap and sysrq key to dump bitmap Wei Liu
2014-10-15 16:25 ` [PATCH RFC 00/10] Xen balloon page compaction support David Vrabel
2014-10-15 16:30 ` Wei Liu
2014-10-16 9:31 ` David Vrabel
2014-10-15 16:54 ` Andrew Cooper
2014-10-15 17:00 ` Wei Liu
2014-10-15 17:14 ` Andrew Cooper
2014-10-16 9:12 ` Wei Liu
2014-10-16 9:26 ` Ian Campbell
2014-10-17 12:35 ` Andrew Cooper
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=1413388459-4663-8-git-send-email-wei.liu2@citrix.com \
--to=wei.liu2@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=david.vrabel@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.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).