Skip to contentSkip to conversation

KVM: SVM: Add tracepoint for cr_interception

PATCH In review Haiwei Li 3 participants 5 messages Sep 4, 2020 – Sep 24, 2020

Subsystems (3)
lore
Share & tools
lore

Haiwei Li

author
#0 lore raw

PATCH 1/1 KVM: SVM: Add tracepoint for cr_interception

From: Haiwei Li <[email protected]>

Add trace_kvm_cr_write and trace_kvm_cr_read for svm.

---
 arch/x86/kvm/svm/svm.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kvm/svm/svm.c +2 -0
index 03dd7bac8034..2c6dea48ba62 100644
@@ -2261,6 +2261,7 @@ static int cr_interception(struct vcpu_svm *svm)
 	if (cr >= 16) { /* mov to cr */
 		cr -= 16;
 		val = kvm_register_read(&svm->vcpu, reg);
+		trace_kvm_cr_write(cr, val);
 		switch (cr) {
 		case 0:
 			if (!check_selective_cr0_intercepted(svm, val))
@@ -2306,6 +2307,7 @@ static int cr_interception(struct vcpu_svm *svm)
 			return 1;
 		}
 		kvm_register_write(&svm->vcpu, reg, val);
+		trace_kvm_cr_read(cr, val);
 	}
 	return kvm_complete_insn_gp(&svm->vcpu, err);
 }

--
2.18.4

Reviewed-by on v1 1/1
#1 lore raw

arch/x86/kvm/svm/svm.c static int cr_interception(struct vcpu_svm *svm)

Quoted 14 lines · Haiwei Li

From: Haiwei Li <[email protected]>

Add trace_kvm_cr_write and trace_kvm_cr_read for svm.

---
  arch/x86/kvm/svm/svm.c | 2 ++
  1 file changed, 2 insertions(+)
arch/x86/kvm/svm/svm.c +0 -0
index 03dd7bac8034..2c6dea48ba62 100644
@@ -2261,6 +2261,7 @@ static int cr_interception(struct vcpu_svm *svm)

There are two special cases when we go to emulate_on_interception() and these won't be logged but I don't think this is a must.

arch/x86/kvm/svm/svm.c static int cr_interception(struct vcpu_svm *svm) · line 2310

Quoted 12 lines
arch/x86/kvm/svm/svm.c +2 -0
  	if (cr >= 16) { /* mov to cr */
  		cr -= 16;
  		val = kvm_register_read(&svm->vcpu, reg);
+		trace_kvm_cr_write(cr, val);
  		switch (cr) {
  		case 0:
  			if (!check_selective_cr0_intercepted(svm, val))
@@ -2306,6 +2307,7 @@ static int cr_interception(struct vcpu_svm *svm)
  			return 1;
  		}
  		kvm_register_write(&svm->vcpu, reg, val);
+		trace_kvm_cr_read(cr, val);

The 'default:' case above does 'return 1;' so we won't get the trace but I understand you put trace_kvm_cr_read() here so you can log the returned 'val', #UD should be clearly visible.

Quoted 6 lines
arch/x86/kvm/svm/svm.c +0 -1
  	}
  	return kvm_complete_insn_gp(&svm->vcpu, err);
  }
--

2.18.4

Signature · 1 line
Vitaly
author
#2 lore raw
Quoted 37 lines · Vitaly Kuznetsov

arch/x86/kvm/svm/svm.c static int cr_interception(struct vcpu_svm *svm)

Quoted 14 lines · Haiwei Li

From: Haiwei Li <[email protected]>

Add trace_kvm_cr_write and trace_kvm_cr_read for svm.

---
   arch/x86/kvm/svm/svm.c | 2 ++
   1 file changed, 2 insertions(+)
arch/x86/kvm/svm/svm.c +0 -0
index 03dd7bac8034..2c6dea48ba62 100644
@@ -2261,6 +2261,7 @@ static int cr_interception(struct vcpu_svm *svm)

There are two special cases when we go to emulate_on_interception() and these won't be logged but I don't think this is a must.

arch/x86/kvm/svm/svm.c static int cr_interception(struct vcpu_svm *svm) · line 2310

Quoted 12 lines
arch/x86/kvm/svm/svm.c +2 -0
   	if (cr >= 16) { /* mov to cr */
   		cr -= 16;
   		val = kvm_register_read(&svm->vcpu, reg);
+		trace_kvm_cr_write(cr, val);
   		switch (cr) {
   		case 0:
   			if (!check_selective_cr0_intercepted(svm, val))
@@ -2306,6 +2307,7 @@ static int cr_interception(struct vcpu_svm *svm)
   			return 1;
   		}
   		kvm_register_write(&svm->vcpu, reg, val);
+		trace_kvm_cr_read(cr, val);

The 'default:' case above does 'return 1;' so we won't get the trace but I understand you put trace_kvm_cr_read() here so you can log the returned 'val', #UD should be clearly visible.

Quoted 8 lines
Quoted 6 lines
arch/x86/kvm/svm/svm.c +0 -1
   	}
   	return kvm_complete_insn_gp(&svm->vcpu, err);
   }
--

2.18.4

Thanks a lot.

Quoted 1 line
author
#3 lore raw
In reply to Haiwei Li

Kindly ping. :)

Quoted 31 lines · Haiwei Li

From: Haiwei Li <[email protected]>

Add trace_kvm_cr_write and trace_kvm_cr_read for svm.

---
  arch/x86/kvm/svm/svm.c | 2 ++
  1 file changed, 2 insertions(+)
arch/x86/kvm/svm/svm.c +2 -0
index 03dd7bac8034..2c6dea48ba62 100644
@@ -2261,6 +2261,7 @@ static int cr_interception(struct vcpu_svm *svm)
      if (cr >= 16) { /* mov to cr */
          cr -= 16;
          val = kvm_register_read(&svm->vcpu, reg);
+        trace_kvm_cr_write(cr, val);
          switch (cr) {
          case 0:
              if (!check_selective_cr0_intercepted(svm, val))
@@ -2306,6 +2307,7 @@ static int cr_interception(struct vcpu_svm *svm)
              return 1;
          }
          kvm_register_write(&svm->vcpu, reg, val);
+        trace_kvm_cr_read(cr, val);
      }
      return kvm_complete_insn_gp(&svm->vcpu, err);
  }
Signature · 1 line
2.18.4