kvm compat patch
PATCH 1/1 kvm compat patch
This patch fixes the mutex, page and kzalloc problems with older kernels.
--
Markus Rechberger
Operating System Research Center
AMD Saxony LLC & Co. KG
mmu.c +18 -18
@@ -298,18 +298,18 @@if (!is_rmap_pte (*spte))return ; page =pfn_to_page ((*spte &PT64_BASE_ADDR_MASK ) >>PAGE_SHIFT ); -if (!page->private) { +if (!page_private (page)) {rmap_printk ("rmap_add: %p %llx 0->1\n" , spte, *spte); - page->private = (unsigned long )spte; - }else if (!(page->private &1 )) { +set_page_private (page,(unsigned long )spte); + }else if (!(page_private (page) &1 )) {rmap_printk ("rmap_add: %p %llx 1->many\n" , spte, *spte); desc =mmu_alloc_rmap_desc (vcpu); - desc->shadow_ptes[0 ] = (u64 *)page->private; + desc->shadow_ptes[0 ] = (u64 *)page_private (page); desc->shadow_ptes[1 ] = spte; - page->private = (unsigned long )desc |1 ; +set_page_private (page,(unsigned long )desc |1 ); }else {rmap_printk ("rmap_add: %p %llx many->many\n" , spte, *spte); - desc = (struct kvm_rmap_desc *)(page->private & ~1ul ); + desc = (struct kvm_rmap_desc *)(page_private (page) & ~1ul );while (desc->shadow_ptes[RMAP_EXT -1 ] && desc->more) desc = desc->more;if (desc->shadow_ptes[RMAP_EXT -1 ]) {
@@ -337,12 +337,12 @@if (j !=0 )return ;if (!prev_desc && !desc->more) - page->private = (unsigned long )desc->shadow_ptes[0 ]; +set_page_private (page,(unsigned long )desc->shadow_ptes[0 ]);else if (prev_desc) prev_desc->more = desc->more;else - page->private = (unsigned long )desc->more |1 ; +set_page_private (page,(unsigned long )desc->more |1 );mmu_free_rmap_desc (vcpu, desc); }
@@ -356,20 +356,20 @@if (!is_rmap_pte (*spte))return ; page =pfn_to_page ((*spte &PT64_BASE_ADDR_MASK ) >>PAGE_SHIFT ); -if (!page->private) { +if (!page_private (page)) {printk (KERN_ERR "rmap_remove: %p %llx 0->BUG\n" , spte, *spte);BUG (); - }else if (!(page->private &1 )) { + }else if (!(page_private (page) &1 )) {rmap_printk ("rmap_remove: %p %llx 1->0\n" , spte, *spte); -if ((u64 *)page->private != spte) { +if ((u64 *)page_private (page) != spte) {printk (KERN_ERR "rmap_remove: %p %llx 1->BUG\n" , spte, *spte);BUG (); } - page->private =0 ; +set_page_private (page,0 ); }else {rmap_printk ("rmap_remove: %p %llx many->many\n" , spte, *spte); - desc = (struct kvm_rmap_desc *)(page->private & ~1ul ); + desc = (struct kvm_rmap_desc *)(page_private (page) & ~1ul ); prev_desc =NULL ;while (desc) {for (i =0 ; i <RMAP_EXT && desc->shadow_ptes[i]; ++i)
@@ -398,11 +398,11 @@BUG_ON (!slot); page =gfn_to_page (slot, gfn); -while (page->private) { -if (!(page->private &1 )) - spte = (u64 *)page->private; +while (page_private (page)) { +if (!(page_private (page) &1 )) + spte = (u64 *)page_private (page);else { - desc = (struct kvm_rmap_desc *)(page->private & ~1ul ); + desc = (struct kvm_rmap_desc *)(page_private (page) & ~1ul ); spte = desc->shadow_ptes[0 ]; }BUG_ON (!spte);
@@ -1218,7 +1218,7 @@INIT_LIST_HEAD (&page_header->link);if ((page =alloc_page (GFP_KERNEL )) ==NULL ) goto error_1; - page->private = (unsigned long )page_header; +set_page_private (page, (unsigned long )page_header); page_header->page_hpa = (hpa_t )page_to_pfn (page) <<PAGE_SHIFT ;memset (__va (page_header->page_hpa),0 ,PAGE_SIZE );list_add (&page_header->link, &vcpu->free_pages);
kvm_main.c +1 -1
@@ -674,7 +674,7 @@ | __GFP_ZERO);if (!new.phys_mem[i]) goto out_free; - new.phys_mem[i]->private =0 ; +set_page_private (new.phys_mem[i],0 ); } }
kvm.h +10 -1
@@ -8,7 +8,9 @@#include <linux/types.h> #include <linux/list.h> +#if LINUX_VERSION_CODE >KERNEL_VERSION (2 ,6 ,15 )#include <linux/mutex.h> +#endif #include <linux/spinlock.h> #include <linux/mm.h>
@@ -225,7 +227,11 @@struct vmcs *vmcs;struct vcpu_svm *svm; }; +#if LINUX_VERSION_CODE >KERNEL_VERSION (2 ,6 ,15 )struct mutex mutex; +#else +struct semaphore mutex; +#endif int cpu;int launched;int interrupt_window_open;
@@ -531,7 +537,10 @@ {struct page *page =pfn_to_page (shadow_page >>PAGE_SHIFT ); -return (struct kvm_mmu_page *)page->private; +return (struct kvm_mmu_page *)page_private (page); +#if 0 + page->private; +#endif }static inline u16 read_fs (void )
external-module-compat.h +21 -0
@@ -72,6 +72,27 @@* The cpu hotplug stubs are broken if !CONFIG_CPU_HOTPLUG */ +#if LINUX_VERSION_CODE <=KERNEL_VERSION (2 ,6 ,15 ) +#define DEFINE_MUTEX (a) DECLARE_MUTEX(a) +#define mutex_lock_interruptible (a) down_interruptible(a) +#define mutex_unlock (a) up(a) +#define mutex_lock (a) down(a) +#define mutex_init (a) init_MUTEX(a) +#define mutex_trylock (a) down_trylock(a) +#endif + +#if LINUX_VERSION_CODE <KERNEL_VERSION (2 ,6 ,14 ) +#ifndef kzalloc +#define kzalloc (size,flags) \ +({ \ + void *__ret = kmalloc(size, flags); \ + if (__ret) +memset (__ret,0 , size); + __ret; +}) +#endif +#endif +#if LINUX_VERSION_CODE <KERNEL_VERSION (2 ,6 ,21 )#ifndef CONFIG_HOTPLUG_CPU
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
Quoted 5 lines · Markus Rechberger
This patch fixes the mutex, page and kzalloc problems with older kernels.
Signed-off-by Markus Rechberger <[email protected]>
The page_private() and kzalloc() stuff looks good, I can apply it. But:
kvm.h line 14
Quoted 12 lines
Index:
kvm.h
===================================================================kvm.h +2
-0@@ -8,7 +8,9 @@#include <linux/types.h> #include <linux/list.h> +#if LINUX_VERSION_CODE >KERNEL_VERSION (2 ,6 ,15 )#include <linux/mutex.h> +#endif
Checks on kernel version are (usually) not accepted in mainline. I think I can cook up some Makefile magic to work around the #include though.
kvm.h line 235
Quoted 13 lines
kvm.h +4
-0#include <linux/spinlock.h> #include <linux/mm.h> @@ -225,7 +227,11 @@struct vmcs *vmcs;struct vcpu_svm *svm; }; +#if LINUX_VERSION_CODE >KERNEL_VERSION (2 ,6 ,15 )struct mutex mutex; +#else +struct semaphore mutex; +#endif
'#define mutex semaphore' in external-module-comapt.h, please.
kvm.h line 543
Quoted 4 lines
kvm.h +3
-0+#if 0 + page->private; +#endif
Please delete.
Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Quoted 15 lines · Avi Kivity
Quoted 5 lines · Markus Rechberger
This patch fixes the mutex, page and kzalloc problems with older kernels.
Signed-off-by Markus Rechberger <[email protected]>The
page_private()andkzalloc()stuff looks good, I can apply it. But:Quoted 6 lines
Index:
kvm.h
===================================================================kvm.h +0
-0@@ -8,7 +8,9 @@
Quoted 10 lines
kvm.h line 16
Quoted 6 lines
kvm.h +2
-0#include <linux/types.h> #include <linux/list.h> +#if LINUX_VERSION_CODE >KERNEL_VERSION (2 ,6 ,15 )#include <linux/mutex.h> +#endif Checks on kernel version are (usually) not accepted in mainline. I think I can cook up some
Makefilemagic to work around the #include though.
They're never accepted. They might slip through the cracks if no one reviews the patch thoroughly enough.
Cheers,
Muli
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Quoted 10 lines · Muli Ben-Yehuda
Quoted 5 lines
Checks on kernel version are (usually) not accepted in mainline. I think I can cook up some
Makefilemagic to work around the #include though.They're never accepted. They might slip through the cracks if no one reviews the patch thoroughly enough.
[avi@firebolt linux-2.6]$ find drivers/ -type f -name '*.[ch]' | xargs cat | grep -c LINUX_VERSION_CODE
98
I've no intention of pursuing that path though.
Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Quoted 11 lines · Avi Kivity
Quoted 10 lines · Muli Ben-Yehuda
Quoted 5 lines
Checks on kernel version are (usually) not accepted in mainline. I think I can cook up some
Makefilemagic to work around the #include though.They're never accepted. They might slip through the cracks if no one reviews the patch thoroughly enough.
Quoted 6 lines
[avi@firebolt linux-2.6]$ find
drivers/-type f -name '*.[ch]' | xargs cat | grep -cLINUX_VERSION_CODE
98I've no intention of pursuing that path though.
We simply parse such things out of the sources in the video4linux project before submitting the code to the upstream kernel Attached another patch, I haven't touched the LINUX_VERSION_CODE include check in kvm.h
Signature · 3 lines
Markus Rechberger Operating System Research Center AMD Saxony LLC & Co. KG
mmu.c +18 -18
@@ -298,18 +298,18 @@if (!is_rmap_pte (*spte))return ; page =pfn_to_page ((*spte &PT64_BASE_ADDR_MASK ) >>PAGE_SHIFT ); -if (!page->private) { +if (!page_private (page)) {rmap_printk ("rmap_add: %p %llx 0->1\n" , spte, *spte); - page->private = (unsigned long )spte; - }else if (!(page->private &1 )) { +set_page_private (page,(unsigned long )spte); + }else if (!(page_private (page) &1 )) {rmap_printk ("rmap_add: %p %llx 1->many\n" , spte, *spte); desc =mmu_alloc_rmap_desc (vcpu); - desc->shadow_ptes[0 ] = (u64 *)page->private; + desc->shadow_ptes[0 ] = (u64 *)page_private (page); desc->shadow_ptes[1 ] = spte; - page->private = (unsigned long )desc |1 ; +set_page_private (page,(unsigned long )desc |1 ); }else {rmap_printk ("rmap_add: %p %llx many->many\n" , spte, *spte); - desc = (struct kvm_rmap_desc *)(page->private & ~1ul ); + desc = (struct kvm_rmap_desc *)(page_private (page) & ~1ul );while (desc->shadow_ptes[RMAP_EXT -1 ] && desc->more) desc = desc->more;if (desc->shadow_ptes[RMAP_EXT -1 ]) {
@@ -337,12 +337,12 @@if (j !=0 )return ;if (!prev_desc && !desc->more) - page->private = (unsigned long )desc->shadow_ptes[0 ]; +set_page_private (page,(unsigned long )desc->shadow_ptes[0 ]);else if (prev_desc) prev_desc->more = desc->more;else - page->private = (unsigned long )desc->more |1 ; +set_page_private (page,(unsigned long )desc->more |1 );mmu_free_rmap_desc (vcpu, desc); }
@@ -356,20 +356,20 @@if (!is_rmap_pte (*spte))return ; page =pfn_to_page ((*spte &PT64_BASE_ADDR_MASK ) >>PAGE_SHIFT ); -if (!page->private) { +if (!page_private (page)) {printk (KERN_ERR "rmap_remove: %p %llx 0->BUG\n" , spte, *spte);BUG (); - }else if (!(page->private &1 )) { + }else if (!(page_private (page) &1 )) {rmap_printk ("rmap_remove: %p %llx 1->0\n" , spte, *spte); -if ((u64 *)page->private != spte) { +if ((u64 *)page_private (page) != spte) {printk (KERN_ERR "rmap_remove: %p %llx 1->BUG\n" , spte, *spte);BUG (); } - page->private =0 ; +set_page_private (page,0 ); }else {rmap_printk ("rmap_remove: %p %llx many->many\n" , spte, *spte); - desc = (struct kvm_rmap_desc *)(page->private & ~1ul ); + desc = (struct kvm_rmap_desc *)(page_private (page) & ~1ul ); prev_desc =NULL ;while (desc) {for (i =0 ; i <RMAP_EXT && desc->shadow_ptes[i]; ++i)
@@ -398,11 +398,11 @@BUG_ON (!slot); page =gfn_to_page (slot, gfn); -while (page->private) { -if (!(page->private &1 )) - spte = (u64 *)page->private; +while (page_private (page)) { +if (!(page_private (page) &1 )) + spte = (u64 *)page_private (page);else { - desc = (struct kvm_rmap_desc *)(page->private & ~1ul ); + desc = (struct kvm_rmap_desc *)(page_private (page) & ~1ul ); spte = desc->shadow_ptes[0 ]; }BUG_ON (!spte);
@@ -1218,7 +1218,7 @@INIT_LIST_HEAD (&page_header->link);if ((page =alloc_page (GFP_KERNEL )) ==NULL ) goto error_1; - page->private = (unsigned long )page_header; +set_page_private (page, (unsigned long )page_header); page_header->page_hpa = (hpa_t )page_to_pfn (page) <<PAGE_SHIFT ;memset (__va (page_header->page_hpa),0 ,PAGE_SIZE );list_add (&page_header->link, &vcpu->free_pages);
kvm_main.c +1 -1
@@ -674,7 +674,7 @@ | __GFP_ZERO);if (!new.phys_mem[i]) goto out_free; - new.phys_mem[i]->private =0 ; +set_page_private (new.phys_mem[i],0 ); } }
kvm.h +3 -1
@@ -8,7 +8,9 @@#include <linux/types.h> #include <linux/list.h> +#if LINUX_VERSION_CODE >KERNEL_VERSION (2 ,6 ,15 )#include <linux/mutex.h> +#endif #include <linux/spinlock.h> #include <linux/mm.h>
@@ -531,7 +533,7 @@ {struct page *page =pfn_to_page (shadow_page >>PAGE_SHIFT ); -return (struct kvm_mmu_page *)page->private; +return (struct kvm_mmu_page *)page_private (page); }static inline u16 read_fs (void )
external-module-compat.h +25 -0
@@ -72,6 +72,31 @@* The cpu hotplug stubs are broken if !CONFIG_CPU_HOTPLUG */ +#if LINUX_VERSION_CODE <=KERNEL_VERSION (2 ,6 ,15 ) +#define DEFINE_MUTEX (a) DECLARE_MUTEX(a) +#define mutex_lock_interruptible (a) down_interruptible(a) +#define mutex_unlock (a) up(a) +#define mutex_lock (a) down(a) +#define mutex_init (a) init_MUTEX(a) +#define mutex_trylock (a) down_trylock(a) +#endif + +#if LINUX_VERSION_CODE <KERNEL_VERSION (2 ,6 ,14 ) +#ifndef kzalloc +#define kzalloc (size,flags) \ +({ \ + void *__ret = kmalloc(size, flags); \ + if (__ret) +memset (__ret,0 , size); + __ret; +}) +#endif +#endif + +#if LINUX_VERSION_CODE <=KERNEL_VERSION (2 ,6 ,15 ) +#define mutex semaphore +#endif +#if LINUX_VERSION_CODE <KERNEL_VERSION (2 ,6 ,21 )#ifndef CONFIG_HOTPLUG_CPU
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
Avi Kivity
AppliedQuoted 5 lines · Markus Rechberger
Attached another patch, I haven't touched the
LINUX_VERSION_CODEinclude check inkvm.hSigned-off-by Markus Rechberger <[email protected]>
Applied, thanks. Adding an empty include/linux/mutex.h is enough to get rid of the #ifdef.
Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642