Re: [PATCH v2 06/13] KVM: x86: Refactor emulate tracepoint to explicitly take context

From: Paolo Bonzini
Date: Tue Mar 03 2020 - 12:44:21 EST


On 03/03/20 18:42, Sean Christopherson wrote:
>> As long as we have one use of vcpu, I'd rather skip this patch and
>> adjust patch 8 to use "->". Even the other "explicitly take context"
>> parts are kinda debatable since you still have to do emul_to_vcpu.
>> Throwing a handful of
>>
>> - struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt;
>> + struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt;
>>
>> into patch 8 is not bad at all and limits the churn.
> Hmm, I'd prefer to explicitly pass @ctxt, even for the tracepoint. I get
> that it's technically unnecessary churn, but explicitly passing @ctxt means
> that every funcition that grabs arch.emulate_ctxt (all three of 'em) checks
> for a NULL ctxt. That makes it trivial to visually audit that there's no
> risk of a bad pointer dereference, and IMO having @ctxt in the prototype
> is helpful to see "oh, this helper is called from within the emulator".
>

That's a good rationale, but I believe this refactoring belongs more in
the "disable emulator" part than this one.

Paolo