WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

RE: [Xen-devel] [PATCH] Arch-neutral balloon driver

To: "Magenheimer, Dan \(HP Labs Fort Collins\)" <dan.magenheimer@xxxxxx>, "Xen Mailing List" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: RE: [Xen-devel] [PATCH] Arch-neutral balloon driver
From: "Tian, Kevin" <kevin.tian@xxxxxxxxx>
Date: Wed, 7 Dec 2005 11:35:40 +0800
Delivery-date: Wed, 07 Dec 2005 03:36:17 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcX6w2vm0h6bE0ptSRmJJKr6vn/gsQAGmOig
Thread-topic: [Xen-devel] [PATCH] Arch-neutral balloon driver
>From: Magenheimer, Dan
>(HP Labs Fort Collins)
>Sent: 2005年12月7日 8:16
>
>Attached patch makes the balloon driver arch-neutral
>(compiles on ia64... look ma, no #ifdef's!).  Please apply
>to xen-unstable.

One comment is to add a get_phys_to_machine, just like set_phys_to_machine, 
which may save your time in other similar cases where that translation array is 
missing on arch like ia64.

>
>One change should be eyeballed, line 257 in balloon.c, because
>phys_to_machine_mapping[pfn] is not identical to pfn_to_mfn
>(different by sign bit, should be OK?)

If all previous foreign mapped pages are correctly handled at destruction, they 
will go into balloon pool directly instead of buddy system. So Ideally new 
allocated pages from buddy pool shouldn't have foreign flag set, and then two 
access ways should be identical. You may add an ASSERT upon this flag there for 
sanity.

Thanks,
Kevins
>
>Signed-off by: Dan Magenheimer <dan.magenheimer@xxxxxx>
>
>diff -r 0255f48b757f linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c
>--- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c       Sun Dec
>4 19:12:00 2005
>+++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c       Tue Dec
>6 16:25:53 2005
>@@ -192,8 +192,8 @@
>               page = balloon_retrieve();
>               BUG_ON(page == NULL);
>
>-              pfn = page - mem_map;
>-              BUG_ON(phys_to_machine_mapping[pfn] !=
>INVALID_P2M_ENTRY);
>+              pfn = page_to_pfn(page);
>+              BUG_ON(phys_to_machine_mapping_valid(pfn));
>
>               /* Update P->M and M->P tables. */
>               set_phys_to_machine(pfn, mfn_list[i]);
>@@ -253,8 +253,8 @@
>                       break;
>               }
>
>-              pfn = page - mem_map;
>-              mfn_list[i] = phys_to_machine_mapping[pfn];
>+              pfn = page_to_pfn(page);
>+              mfn_list[i] = pfn_to_mfn(pfn);
>
>               if (!PageHighMem(page)) {
>                       v = phys_to_virt(pfn << PAGE_SHIFT);
>@@ -444,6 +444,9 @@
>
>       IPRINTK("Initialising balloon driver.\n");
>
>+      if (xen_init() < 0)
>+              return -1;
>+
>       current_pages = min(xen_start_info->nr_pages, max_pfn);
>       target_pages  = current_pages;
>       balloon_low   = 0;
>@@ -465,7 +468,7 @@
>
>       /* Initialise the balloon with excess memory space. */
>       for (pfn = xen_start_info->nr_pages; pfn < max_pfn; pfn++) {
>-              page = &mem_map[pfn];
>+              page = pfn_to_page(pfn);
>               if (!PageReserved(page))
>                       balloon_append(page);
>       }
>diff -r 0255f48b757f
>linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h
>--- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h     Sun Dec
>4 19:12:00 2005
>+++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h     Tue Dec
>6 16:25:53 2005
>@@ -65,6 +65,8 @@
> extern unsigned long *phys_to_machine_mapping;
> #define pfn_to_mfn(pfn)       \
> (phys_to_machine_mapping[(unsigned int)(pfn)] & ~(1UL<<31))
>+#define       phys_to_machine_mapping_valid(pfn) \
>+      (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY)
> static inline unsigned long mfn_to_pfn(unsigned long mfn)
> {
>       unsigned long pfn;
>diff -r 0255f48b757f
>linux-2.6-xen-sparse/include/asm-xen/asm-ia64/hypercall.h
>--- a/linux-2.6-xen-sparse/include/asm-xen/asm-ia64/hypercall.h        Sun Dec
>4 19:12:00 2005
>+++ b/linux-2.6-xen-sparse/include/asm-xen/asm-ia64/hypercall.h        Tue Dec
>6 16:25:53 2005
>@@ -355,34 +355,27 @@
> #endif
>     return 1;
> }
>+#endif
>
> static inline int
> HYPERVISOR_update_va_mapping(
>     unsigned long va, pte_t new_val, unsigned long flags)
> {
>-#if 0
>-    int ret;
>-    unsigned long ign1, ign2, ign3;
>-
>-    __asm__ __volatile__ (
>-        TRAP_INSTR
>-        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
>-      : "0" (__HYPERVISOR_update_va_mapping),
>-          "1" (va), "2" ((new_val).pte_low), "3" (flags)
>-      : "memory" );
>-
>-    if ( unlikely(ret < 0) )
>-    {
>-        printk(KERN_ALERT "Failed update VA mapping: %08lx, %08lx,
>%08lx\n",
>-               va, (new_val).pte_low, flags);
>-        BUG();
>-    }
>-
>-    return ret;
>-#endif
>-    return 1;
>-}
>-#endif
>+    /* no-op */
>+    return 1;
>+}
>+
>+static inline int
>+HYPERVISOR_memory_op(
>+    unsigned int cmd, void *arg)
>+{
>+    int ret;
>+    __asm__ __volatile__ ( ";; mov r14=%2 ; mov r15=%3 ; mov r2=%1 ;
>break 0x1000 ;; mov %0=r8 ;;"
>+        : "=r" (ret)
>+        : "i" (__HYPERVISOR_console_io), "r"(cmd), "r"(arg)
>+        : "r14","r15","r2","r8","memory" );
>+    return ret;
>+}
>
> static inline int
> HYPERVISOR_event_channel_op(
>diff -r 0255f48b757f
>linux-2.6-xen-sparse/include/asm-xen/asm-ia64/hypervisor.h
>--- a/linux-2.6-xen-sparse/include/asm-xen/asm-ia64/hypervisor.h
>Sun Dec  4 19:12:00 2005
>+++ b/linux-2.6-xen-sparse/include/asm-xen/asm-ia64/hypervisor.h
>Tue Dec  6 16:25:53 2005
>@@ -52,4 +52,19 @@
> #define       mfn_to_pfn(x)   (x)
> #define machine_to_phys_mapping 0
>
>+// for drivers/xen/balloon/balloon.c
>+#ifdef CONFIG_XEN_SCRUB_PAGES
>+#define scrub_pages(_p,_n) memset((void *)(_p), 0, (_n) << PAGE_SHIFT)
>+#else
>+#define scrub_pages(_p,_n) ((void)0)
>+#endif
>+#define       pte_mfn(_x)     pte_pfn(_x)
>+#define INVALID_P2M_ENTRY     (~0UL)
>+#define __pte_ma(_x)  ((pte_t) {(_x)})
>+#define phys_to_machine_mapping_valid(_x)     (1)
>+#define       kmap_flush_unused()     do {} while (0)
>+#define set_phys_to_machine(_x,_y)    do {} while (0)
>+#define xen_machphys_update(_x,_y)    do {} while (0)
>+#define pfn_pte_ma(_x,_y)     __pte_ma(0)
>+
> #endif /* __HYPERVISOR_H__ */
>diff -r 0255f48b757f
>linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h
>--- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h   Sun Dec
>4 19:12:00 2005
>+++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h   Tue Dec
>6 16:25:53 2005
>@@ -67,6 +67,8 @@
> extern unsigned long *phys_to_machine_mapping;
> #define pfn_to_mfn(pfn)       \
> (phys_to_machine_mapping[(unsigned int)(pfn)] & ~(1UL << 63))
>+#define       phys_to_machine_mapping_valid(pfn) \
>+      (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY)
> static inline unsigned long mfn_to_pfn(unsigned long mfn)
> {
>       unsigned long pfn;
>
>_______________________________________________
>Xen-devel mailing list
>Xen-devel@xxxxxxxxxxxxxxxxxxx
>http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>