Skip to contentSkip to conversation

MIPS: KVM: Fix trace event to save PC directly

PATCH Applied James Hogan 3 participants 3 messages Feb 24, 2015 – Mar 2, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: KVM: Fix trace event to save PC directly

Currently the guest exit trace event saves the VCPU pointer to the structure, and the guest PC is retrieved by dereferencing it when the event is printed rather than directly from the trace record. This isn't safe as the printing may occur long afterwards, after the PC has changed and potentially after the VCPU has been freed. Usually this results in the same (wrong) PC being printed for multiple trace events. It also isn't portable as userland has no way to access the VCPU data structure when interpreting the trace record itself.

Lets save the actual PC in the structure so that the correct value is accessible later.

Fixes 669e846e6c4e ("KVM/MIPS32: MIPS arch specific APIs for KVM")
Cc Paolo Bonzini <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Marcelo Tosatti <[email protected]>
Cc Gleb Natapov <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc <[email protected]> # v3.10+
---
 arch/mips/kvm/trace.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/mips/kvm/trace.h +3 -3
index c1388d40663b..bd6437f67dc0 100644
@@ -24,18 +24,18 @@ TRACE_EVENT(kvm_exit,
 	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int reason),
 	    TP_ARGS(vcpu, reason),
 	    TP_STRUCT__entry(
-			__field(struct kvm_vcpu *, vcpu)
+			__field(unsigned long, pc)
 			__field(unsigned int, reason)
 	    ),
 
 	    TP_fast_assign(
-			__entry->vcpu = vcpu;
+			__entry->pc = vcpu->arch.pc;
 			__entry->reason = reason;
 	    ),
 
 	    TP_printk("[%s]PC: 0x%08lx",
 		      kvm_mips_exit_types_str[__entry->reason],
-		      __entry->vcpu->arch.pc)
+		      __entry->pc)
 );
 
 #endif /* _TRACE_KVM_H */
Signature · 1 line
2.0.5
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · On Tue, 24 Feb 2015 11:46:20 +0000 James Hogan <[email protected]> wrote:

Lets save the actual PC in the structure so that the correct value is accessible later.

Fixes 669e846e6c4e ("KVM/MIPS32: MIPS arch specific APIs for KVM")
Cc Paolo Bonzini <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Marcelo Tosatti <[email protected]>
Cc Gleb Natapov <[email protected]>
Cc Steven Rostedt <[email protected]>

-- Steve

Quoted 9 lines
---
 arch/mips/kvm/trace.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
#2 lore raw
In reply to James Hogan
Quoted 11 lines · James Hogan

Currently the guest exit trace event saves the VCPU pointer to the structure, and the guest PC is retrieved by dereferencing it when the event is printed rather than directly from the trace record. This isn't safe as the printing may occur long afterwards, after the PC has changed and potentially after the VCPU has been freed. Usually this results in the same (wrong) PC being printed for multiple trace events. It also isn't portable as userland has no way to access the VCPU data structure when interpreting the trace record itself.

Lets save the actual PC in the structure so that the correct value is accessible later.

Applied, thanks.