mem_event: fix regression affecting CR3, CR4 memory events
PATCH 1/1 mem_event: fix regression affecting CR3, CR4 memory events
This is a patch repairing a regression in code previously functional in 4.1.x. It appears that, during some refactoring work, calls to hvm_memory_event_cr3 and hvm_memory_event_cr4 were lost.
These functions were originally called in mov_to_cr() of vmx.c, but the commit http://xenbits.xen.org/hg/xen-unstable.hg/rev/1276926e3795 abstracted the original code into generic functions up a level in hvm.c, dropping these calls in the process.
xen/arch/x86/hvm/hvm.c +4 -0
@@ -1758,6 +1758,7 @@ int hvm_set_cr3(unsigned long value) {struct vcpu *v = current;struct page_info *page; +unsigned long old;if (hvm_paging_enabled (v) && !paging_mode_hap (v->domain) && (value != v->arch.hvm_vcpu.guest_cr[3 ]) )
@@ -1775,8 +1776,10 @@ int hvm_set_cr3(unsigned long value)HVM_DBG_LOG (DBG_LEVEL_VMMU ,"Update CR3 value = %lx" , value); } + old=v->arch.hvm_vcpu.guest_cr[3 ]; v->arch.hvm_vcpu.guest_cr[3 ] = value;paging_update_cr3 (v); +hvm_memory_event_cr3 (value, old);return X86EMUL_OKAY ; bad_cr3:
@@ -1818,6 +1821,7 @@ int hvm_set_cr4(unsigned long value) v->arch.hvm_vcpu.guest_cr[4 ] = value;hvm_update_guest_cr (v,4 ); +hvm_memory_event_cr4 (value, old_cr);/* * Modifying CR4.{PSE,PAE,PGE,SMEP}, or clearing CR4.PCIDE
Quoted 29 lines · Steven Maresca
This is a patch repairing a regression in code previously functional in 4.1.x. It appears that, during some refactoring work, calls to
hvm_memory_event_cr3andhvm_memory_event_cr4were lost.These functions were originally called in
mov_to_cr()ofvmx.c, but the commit http://xenbits.xen.org/hg/xen-unstable.hg/rev/1276926e3795 abstracted the original code into generic functions up a level inhvm.c, dropping these calls in the process.Signed-off-by Steven Maresca <[email protected]>diff -r
a64f4e107951-r4d31c1c86418xen/arch/x86/hvm/hvm.cxen/arch/x86/hvm/hvm.c Mon Sep 10 16:48:15 2012 -0400 renamed from xen/arch/x86/hvm/hvm.c Fri Sep 07 11:09:46 2012 +0100 +3
-0@@ -1758,6 +1758,7 @@ int hvm_set_cr3(unsigned long value) { struct vcpu *v = current; struct page_info *page; + unsigned long old; if ( hvm_paging_enabled(v) && !paging_mode_hap(v->domain) && (value != v->arch.hvm_vcpu.guest_cr[3]) )@@ -1775,8 +1776,10 @@ int hvm_set_cr3(unsigned long value) HVM_DBG_LOG(DBG_LEVEL_VMMU, "Update CR3 value = %lx", value); } + old=v->arch.hvm_vcpu.guest_cr[3]; v->arch.hvm_vcpu.guest_cr[3] = value; paging_update_cr3(v); + hvm_memory_event_cr3(value, old); return X86EMUL_OKAY; bad_cr3:
xen/arch/x86/hvm/hvm.c Mon Sep 10 16:48:15 2012 -0400 int hvm_set_cr4(unsigned long value) · line 1827
Quoted 7 lines
xen/arch/x86/hvm/hvm.c Mon Sep 10 16:48:15 2012 -0400 renamed from xen/arch/x86/hvm/hvm.c Fri Sep 07 11:09:46 2012 +0100 +1
-0@@ -1818,6 +1821,7 @@ int hvm_set_cr4(unsigned long value) v->arch.hvm_vcpu.guest_cr[4] = value; hvm_update_guest_cr(v, 4); + hvm_memory_event_cr4(value, old_cr); /* * Modifying CR4.{PSE,PAE,PGE,SMEP}, or clearing CR4.PCIDE
Given the refactoring in the commit related to the regression
http://xenbits.xen.org/hg/xen-unstable.hg/rev/1276926e3795, it seemed (to me anyway) that inserting calls as shown in the patch would be cleaner, but I can definitely come up with some drawbacks. However, I wanted to get this fixed for 4.2 if at all possible, so I wanted to send regardless.
In terms of drawbacks, this will require some ifdefs for x86_64, for example.
Any suggestions for the cleanest means of achieving the same in vmx.c?
Steve
Quoted 10 lines · Steven Maresca
Given the refactoring in the commit related to the regression
http://xenbits.xen.org/hg/xen-unstable.hg/rev/1276926e3795, it seemed (to me anyway) that inserting calls as shown in the patch would be cleaner, but I can definitely come up with some drawbacks. However, I wanted to get this fixed for 4.2 if at all possible, so I wanted to send regardless.In terms of drawbacks, this will require some ifdefs for
x86_64, for example.Any suggestions for the cleanest means of achieving the same in
vmx.c?
I don't understand this at all. The original commit moved some CR handling to common HVM code. Your patch adds some mem_event calls into that common HVM code. What would need to be "achieved" in vmx.c? What ifdefs would be required for x86_64?
-- Keir
Quoted 11 lines · Keir Fraser
Quoted 9 lines · Steven Maresca
Given the refactoring in the commit related to the regression
http://xenbits.xen.org/hg/xen-unstable.hg/rev/1276926e3795, it seemed (to me anyway) that inserting calls as shown in the patch would be cleaner, but I can definitely come up with some drawbacks. However, I wanted to get this fixed for 4.2 if at all possible, so I wanted to send regardless.In terms of drawbacks, this will require some ifdefs for
x86_64, for example.
Quoted 10 lines
Quoted 1 line
Any suggestions for the cleanest means of achieving the same in
vmx.c?I don't understand this at all. The original commit moved some CR handling to common HVM code. Your patch adds some
mem_eventcalls into that common HVM code. What would need to be "achieved" invmx.c? What ifdefs would be required forx86_64?-- Keir
Keir,
In the process of moving CR handling to common code, that commit removed calls to hvm_memory_event_cr3() and hvm_memory_event_cr4(). Without some patch restoring the calls to those two functions, current xen-unstable and xen-4.2-testing only reference them as function prototypes and function definitions -- there are no calls whatsoever.
I only mentioned an ifdef relative to x86_64 because of the #ifdef __x86_64__ around the function definitions. ( I know in the hvm.h itself they're just empty inline functions if not __x86_64__. )
Regarding vmx.c: hvm_memory_event_cr0 is called within vmx_cr_access. The patch I sent restoring the calls to hvm_memory_event_cr4 and hvm_memory_event_cr3 could be treated similarly, that's all.
Steve
Andres Lagar-Cavilla
Acked-byQuoted 31 lines · Steven Maresca
Quoted 11 lines · Keir Fraser
Quoted 9 lines · Steven Maresca
Given the refactoring in the commit related to the regression
http://xenbits.xen.org/hg/xen-unstable.hg/rev/1276926e3795, it seemed (to me anyway) that inserting calls as shown in the patch would be cleaner, but I can definitely come up with some drawbacks. However, I wanted to get this fixed for 4.2 if at all possible, so I wanted to send regardless.In terms of drawbacks, this will require some ifdefs for
x86_64, for example.Quoted 10 lines
Quoted 1 line
Any suggestions for the cleanest means of achieving the same in
vmx.c?I don't understand this at all. The original commit moved some CR handling to common HVM code. Your patch adds some
mem_eventcalls into that common HVM code. What would need to be "achieved" invmx.c? What ifdefs would be required forx86_64?-- Keir
Keir,
In the process of moving CR handling to common code, that commit removed calls to
hvm_memory_event_cr3()andhvm_memory_event_cr4(). Without some patch restoring the calls to those two functions, current xen-unstable and xen-4.2-testing only reference them as function prototypes and function definitions -- there are no calls whatsoever.
Quoted 7 lines
I only mentioned an ifdef relative to
x86_64because of the #ifdef__x86_64__around the function definitions. ( I know in thehvm.hitself they're just empty inline functions if not__x86_64__. )Regarding
vmx.c:hvm_memory_event_cr0is called withinvmx_cr_access. The patch I sent restoring the calls tohvm_memory_event_cr4andhvm_memory_event_cr3could be treated similarly, that's all.
The patch looks ok to me.
You don't need to worry about x86_32. Is on its way out. You don't need to push this down into vmx either. Once AMD gains support for mem-event, this will just work for svm as well.
Like Keir says, no need for us. Your patch is good as is. Best to cc Tim Deegan <[email protected]>, the mm maintainer.
Cheers
Andres
Quoted 2 lines
Steve
Tim Deegan
Acked-byQuoted 38 lines · Andres Lagar-Cavilla
Quoted 35 lines · Steven Maresca
Quoted 11 lines · Keir Fraser
Quoted 9 lines · Steven Maresca
Given the refactoring in the commit related to the regression
http://xenbits.xen.org/hg/xen-unstable.hg/rev/1276926e3795, it seemed (to me anyway) that inserting calls as shown in the patch would be cleaner, but I can definitely come up with some drawbacks. However, I wanted to get this fixed for 4.2 if at all possible, so I wanted to send regardless.In terms of drawbacks, this will require some ifdefs for
x86_64, for example.Quoted 10 lines
Quoted 1 line
Any suggestions for the cleanest means of achieving the same in
vmx.c?I don't understand this at all. The original commit moved some CR handling to common HVM code. Your patch adds some
mem_eventcalls into that common HVM code. What would need to be "achieved" invmx.c? What ifdefs would be required forx86_64?-- Keir
Keir,
In the process of moving CR handling to common code, that commit removed calls to
hvm_memory_event_cr3()andhvm_memory_event_cr4(). Without some patch restoring the calls to those two functions, current xen-unstable and xen-4.2-testing only reference them as function prototypes and function definitions -- there are no calls whatsoever.I only mentioned an ifdef relative to
x86_64because of the #ifdef__x86_64__around the function definitions. ( I know in thehvm.hitself they're just empty inline functions if not__x86_64__. )
Quoted 7 lines
Quoted 3 lines
Regarding
vmx.c:hvm_memory_event_cr0is called withinvmx_cr_access. The patch I sent restoring the calls tohvm_memory_event_cr4andhvm_memory_event_cr3could be treated similarly, that's all.The patch looks ok to me.
Tim.
Aravindh Puthiyaparambil
Acked-byQuoted 31 lines · Steven Maresca
Quoted 11 lines · Keir Fraser
Quoted 9 lines · Steven Maresca
Given the refactoring in the commit related to the regression
http://xenbits.xen.org/hg/xen-unstable.hg/rev/1276926e3795, it seemed (to me anyway) that inserting calls as shown in the patch would be cleaner, but I can definitely come up with some drawbacks. However, I wanted to get this fixed for 4.2 if at all possible, so I wanted to send regardless.In terms of drawbacks, this will require some ifdefs for
x86_64, for example.Quoted 10 lines
Quoted 1 line
Any suggestions for the cleanest means of achieving the same in
vmx.c?I don't understand this at all. The original commit moved some CR handling to common HVM code. Your patch adds some
mem_eventcalls into that common HVM code. What would need to be "achieved" invmx.c? What ifdefs would be required forx86_64?-- Keir
Keir,
In the process of moving CR handling to common code, that commit removed calls to
hvm_memory_event_cr3()andhvm_memory_event_cr4(). Without some patch restoring the calls to those two functions, current xen-unstable and xen-4.2-testing only reference them as function prototypes and function definitions -- there are no calls whatsoever.
Quoted 7 lines
I only mentioned an ifdef relative to
x86_64because of the #ifdef__x86_64__around the function definitions. ( I know in thehvm.hitself they're just empty inline functions if not__x86_64__. )Regarding
vmx.c:hvm_memory_event_cr0is called withinvmx_cr_access. The patch I sent restoring the calls tohvm_memory_event_cr4andhvm_memory_event_cr3could be treated similarly, that's all.
Looks good to me.
Cheers,
Aravindh
Quoted 40 lines · Aravindh Puthiyaparambil
Quoted 31 lines · Steven Maresca
Quoted 11 lines · Keir Fraser
Quoted 9 lines · Steven Maresca
Given the refactoring in the commit related to the regression
http://xenbits.xen.org/hg/xen-unstable.hg/rev/1276926e3795, it seemed (to me anyway) that inserting calls as shown in the patch would be cleaner, but I can definitely come up with some drawbacks. However, I wanted to get this fixed for 4.2 if at all possible, so I wanted to send regardless.In terms of drawbacks, this will require some ifdefs for
x86_64, for example.Quoted 10 lines
Quoted 1 line
Any suggestions for the cleanest means of achieving the same in
vmx.c?I don't understand this at all. The original commit moved some CR handling to common HVM code. Your patch adds some
mem_eventcalls into that common HVM code. What would need to be "achieved" invmx.c? What ifdefs would be required forx86_64?-- Keir
Keir,
In the process of moving CR handling to common code, that commit removed calls to
hvm_memory_event_cr3()andhvm_memory_event_cr4(). Without some patch restoring the calls to those two functions, current xen-unstable and xen-4.2-testing only reference them as function prototypes and function definitions -- there are no calls whatsoever.Quoted 7 lines
I only mentioned an ifdef relative to
x86_64because of the #ifdef__x86_64__around the function definitions. ( I know in thehvm.hitself they're just empty inline functions if not__x86_64__. )Regarding
vmx.c:hvm_memory_event_cr0is called withinvmx_cr_access. The patch I sent restoring the calls tohvm_memory_event_cr4andhvm_memory_event_cr3could be treated similarly, that's all.
Quoted 5 lines
Looks good to me.
Cheers,
Aravindh
Adding Tim Deegan as suggested.
Tim, this is a regression fix for CR3/CR4 memory events unintentionally removed during some refactoring of HVM CR handling. If at all possible, for 4.2 inclusion before we officially leave RC. Acks received from Andres and Aravindh. Thanks to all for the quick review.
Take care,
Steve
Quoted 45 lines · Steven Maresca
Quoted 43 lines · Aravindh Puthiyaparambil
Quoted 31 lines · Steven Maresca
Quoted 11 lines · Keir Fraser
Quoted 9 lines · Steven Maresca
Given the refactoring in the commit related to the regression
http://xenbits.xen.org/hg/xen-unstable.hg/rev/1276926e3795, it seemed (to me anyway) that inserting calls as shown in the patch would be cleaner, but I can definitely come up with some drawbacks. However, I wanted to get this fixed for 4.2 if at all possible, so I wanted to send regardless.In terms of drawbacks, this will require some ifdefs for
x86_64, for example.Quoted 10 lines
Quoted 1 line
Any suggestions for the cleanest means of achieving the same in
vmx.c?I don't understand this at all. The original commit moved some CR handling to common HVM code. Your patch adds some
mem_eventcalls into that common HVM code. What would need to be "achieved" invmx.c? What ifdefs would be required forx86_64?-- Keir
Keir,
In the process of moving CR handling to common code, that commit removed calls to
hvm_memory_event_cr3()andhvm_memory_event_cr4(). Without some patch restoring the calls to those two functions, current xen-unstable and xen-4.2-testing only reference them as function prototypes and function definitions -- there are no calls whatsoever.Quoted 7 lines
I only mentioned an ifdef relative to
x86_64because of the #ifdef__x86_64__around the function definitions. ( I know in thehvm.hitself they're just empty inline functions if not__x86_64__. )Regarding
vmx.c:hvm_memory_event_cr0is called withinvmx_cr_access. The patch I sent restoring the calls tohvm_memory_event_cr4andhvm_memory_event_cr3could be treated similarly, that's all.Looks good to me.
Quoted 8 lines
Quoted 2 lines
Cheers,
AravindhAdding Tim Deegan as suggested.
Tim, this is a regression fix for CR3/CR4 memory events unintentionally removed during some refactoring of HVM CR handling. If at all possible, for 4.2 inclusion before we officially leave RC.
I think it's too late to get any more code changes in to 4.2.0, so this will have to wait for 4.2.1. Ian?
The patch looks OK, but why didn't you put the memory_event calls back in mov_to_cr(), which is where they were before that?
Cheers,
Tim.
Quoted 2 lines · Tim Deegan
I think it's too late to get any more code changes in to 4.2.0, so this will have to wait for 4.2.1. Ian?
I'd defer to you h/v guys but IMHO only fixes for super critical issues should be going in for 4.2.0 now.
4.2.1 is not that far away and these fixes will be in 4.2-testing between 4.2.0 and then.
Quoted 7 lines
The patch looks OK, but why didn't you put the
memory_eventcalls back inmov_to_cr(), which is where they were before that?Cheers,
Tim.
Quoted 58 lines · Tim Deegan
Quoted 45 lines · Steven Maresca
Quoted 43 lines · Aravindh Puthiyaparambil
Quoted 31 lines · Steven Maresca
Quoted 11 lines · Keir Fraser
Quoted 9 lines · Steven Maresca
Given the refactoring in the commit related to the regression
http://xenbits.xen.org/hg/xen-unstable.hg/rev/1276926e3795, it seemed (to me anyway) that inserting calls as shown in the patch would be cleaner, but I can definitely come up with some drawbacks. However, I wanted to get this fixed for 4.2 if at all possible, so I wanted to send regardless.In terms of drawbacks, this will require some ifdefs for
x86_64, for example.Quoted 10 lines
Quoted 1 line
Any suggestions for the cleanest means of achieving the same in
vmx.c?I don't understand this at all. The original commit moved some CR handling to common HVM code. Your patch adds some
mem_eventcalls into that common HVM code. What would need to be "achieved" invmx.c? What ifdefs would be required forx86_64?-- Keir
Keir,
In the process of moving CR handling to common code, that commit removed calls to
hvm_memory_event_cr3()andhvm_memory_event_cr4(). Without some patch restoring the calls to those two functions, current xen-unstable and xen-4.2-testing only reference them as function prototypes and function definitions -- there are no calls whatsoever.Quoted 7 lines
I only mentioned an ifdef relative to
x86_64because of the #ifdef__x86_64__around the function definitions. ( I know in thehvm.hitself they're just empty inline functions if not__x86_64__. )Regarding
vmx.c:hvm_memory_event_cr0is called withinvmx_cr_access. The patch I sent restoring the calls tohvm_memory_event_cr4andhvm_memory_event_cr3could be treated similarly, that's all.Looks good to me.
Quoted 8 lines
Quoted 2 lines
Cheers,
AravindhAdding Tim Deegan as suggested.
Tim, this is a regression fix for CR3/CR4 memory events unintentionally removed during some refactoring of HVM CR handling. If at all possible, for 4.2 inclusion before we officially leave RC.
I think it's too late to get any more code changes in to 4.2.0, so this will have to wait for 4.2.1. Ian?
Quoted 6 lines
The patch looks OK, but why didn't you put the
memory_eventcalls back inmov_to_cr(), which is where they were before that?Cheers,
Tim.
Tim,
This bugfix could definitely be placed in hvm_mov_to_cr() - it just seemed more localized if placed in the hvm_set_cr*() functions. I'll happily defer to preference, if you have one.
Thanks,
Steve