Skip to contentSkip to conversation

mem_event: fix regression affecting CR3, CR4 memory events

PATCH In review Steven Maresca 6 participants 11 messages Sep 10, 2012 – Sep 17, 2012

lore
Share & tools
lore
#0 lore raw

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
diff -r a64f4e107951 -r 4d31c1c86418 xen/arch/x86/hvm/hvm.c
@@ -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
#1 lore raw
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_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.

diff -r a64f4e107951 -r 4d31c1c86418 xen/arch/x86/hvm/hvm.c

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 +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

#2 lore raw
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

#3 lore raw
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_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

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

#4 lore raw
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_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

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.

Quoted 7 lines

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.

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

Acked-by
#5 lore raw
Quoted 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_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

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__. )

Quoted 7 lines
Quoted 3 lines

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.

The patch looks ok to me.

Tim.

#6 lore raw
In reply to Steven Maresca
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_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

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.

Quoted 7 lines

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.

Looks good to me.

Cheers,
Aravindh

#7 lore raw
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_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

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.

Quoted 7 lines

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.

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

#8 lore raw
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_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

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.

Quoted 7 lines

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.

Looks good to me.

Quoted 8 lines
Quoted 2 lines

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.

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.

#9 lore raw
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_event calls back in mov_to_cr(), which is where they were before that?

Cheers,

Tim.

#10 lore raw
In reply to Tim Deegan
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_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

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.

Quoted 7 lines

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.

Looks good to me.

Quoted 8 lines
Quoted 2 lines

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.

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_event calls back in mov_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