Magenheimer, Dan (HP Labs Fort Collins)
2005-Dec-07 00:16 UTC
[Xen-devel] [PATCH] Arch-neutral balloon driver
Attached patch makes the balloon driver arch-neutral (compiles on ia64... look ma, no #ifdef''s!). Please apply to xen-unstable. 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?) Signed-off by: Dan Magenheimer <dan.magenheimer@hp.com> 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@lists.xensource.com http://lists.xensource.com/xen-devel
>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@hp.com> > >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@lists.xensource.com >http://lists.xensource.com/xen-devel_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Hollis Blanchard
2005-Dec-07 21:13 UTC
Re: [Xen-devel] [PATCH] Arch-neutral balloon driver
On Dec 6, 2005, at 6:16 PM, Magenheimer, Dan (HP Labs Fort Collins) wrote:> Attached patch makes the balloon driver arch-neutral > (compiles on ia64... look ma, no #ifdef''s!). Please apply > to xen-unstable.> 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 > @@ -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;I had some suggestions to obviate this "xen_init()" stuff; you can read them again at http://lists.xensource.com/archives/html/xen-devel/2005-09/ msg00881.html . I see that xen_init() was introduced anyways, but I would not like to see it spread. Instead let''s correct the problem it''s working around.> 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.cC++ comment Other than that this looks ok to me. I think your mailer line-wrapped the patch though. -- Hollis Blanchard IBM Linux Technology Center _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Magenheimer, Dan (HP Labs Fort Collins)
2005-Dec-07 23:05 UTC
RE: [Xen-devel] [PATCH] Arch-neutral balloon driver
> > + if (xen_init() < 0) > > + return -1; > > + > > I had some suggestions to obviate this "xen_init()" stuff; > you can read them again at > http://lists.xensource.com/archives/html/xen-devel/2005-09/ > msg00881.html . I see that xen_init() was introduced anyways, but I > would not like to see it spread. Instead let''s correct the > problem it''s working around.While I''m sympathetic to your argument, I''d prefer for xen_init to be replaced at some point in the future when more major surgery is done on the drivers. In the meantime, it has the advantage that: 1) It has zero impact on Xen/x86. 2) It serves two purposes on Xen/ia64: a) ensures that certain xen driver init routines execute before other xen driver init routines b) returns a no-impact failure if called on a kernel that is not running on Xen (is running on bare metal) It could be argued that we are now "post-3.0", but these are really just minor cleanups on (pre-)3.0 drivers to get networking working on Xen/ia64, preferably on 3.0.x. So I''ll be submitting a patch to add it to netback also.> > +// for drivers/xen/balloon/balloon.c > > C++ commentGood point.> Other than that this looks ok to me. I think your mailer > line-wrapped > the patch though.Stupid Outlook. :-( Keir, should I resend as an attachment? Thanks, Dan _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On 7 Dec 2005, at 23:05, Magenheimer, Dan (HP Labs Fort Collins) wrote:>> Other than that this looks ok to me. I think your mailer >> line-wrapped >> the patch though. > > Stupid Outlook. :-( Keir, should I resend as an attachment?Yes please. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Magenheimer, Dan (HP Labs Fort Collins)
2005-Dec-08 14:23 UTC
RE: [Xen-devel] [PATCH] Arch-neutral balloon driver
Resending as an attachment...> >> Other than that this looks ok to me. I think your mailer > >> line-wrapped > >> the patch though. > > > > Stupid Outlook. :-( Keir, should I resend as an attachment? > > Yes please. > > -- Keir_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel