Skip to contentSkip to conversation

MSR access API uses in KVM x86

DISCUSSION Xin Li 3 participants 4 messages Apr 21, 2025 – Apr 23, 2025 KVM

lore
Share & tools
lore

Xin Li

author
#0 lore raw

It looks to me that MSR access API uses in KVM x86 are NOT consistent; sometimes {wr,rd}msrl() are used and sometimes native_{wr,rd}msrl() are used.

Was there a reason that how a generic or native MSR API was chosen?

In my opinion KVM should use the native MSR APIs, which can streamline operations and potentially improve performance by avoiding the overhead associated with generic MSR API indirect calls when CONFIG_XEN_PV=y.

No?

Thanks!
Xin

#1 lore raw
Quoted 5 lines · Xin Li

It looks to me that MSR access API uses in KVM x86 are NOT consistent; sometimes {wr,rd}msrl() are used and sometimes native_{wr,rd}msrl() are used.

Was there a reason that how a generic or native MSR API was chosen?

I doubt anyone knows for sure; that'd likely require a time travelling device and/or telepathic abilities :-)

Quoted 3 lines

In my opinion KVM should use the native MSR APIs, which can streamline operations and potentially improve performance by avoiding the overhead associated with generic MSR API indirect calls when CONFIG_XEN_PV=y.

As Jürgen pointed out, they aren't indirect calls. Though IIUC, there is still a direct CALL and thus a RET when PARAVIRT_XXL=Y.

I agree that using PV APIs in KVM doesn't make much sense, as running KVM in a XEN PV guest doesn't seem like something we should optimize for, if it's even supported. So if we end up churning all of the rdmsr/wrmsr macros, I have no objection to switching to native variants.

Though if we do that, it would be nice if there's a way to avoid the "native_" prefix everywhere, for the sake of readability.

#2 lore raw
Quoted 14 lines · Sean Christopherson
Quoted 5 lines · Xin Li

It looks to me that MSR access API uses in KVM x86 are NOT consistent; sometimes {wr,rd}msrl() are used and sometimes native_{wr,rd}msrl() are used.

Was there a reason that how a generic or native MSR API was chosen?

I doubt anyone knows for sure; that'd likely require a time travelling device and/or telepathic abilities :-)

Quoted 3 lines

In my opinion KVM should use the native MSR APIs, which can streamline operations and potentially improve performance by avoiding the overhead associated with generic MSR API indirect calls when CONFIG_XEN_PV=y.

Quoted 6 lines

As Jürgen pointed out, they aren't indirect calls. Though IIUC, there is still a direct CALL and thus a RET when PARAVIRT_XXL=Y.

I agree that using PV APIs in KVM doesn't make much sense, as running KVM in a XEN PV guest doesn't seem like something we should optimize for, if it's even supported.

Shudder. :-D

No, definitely not supported.

Juergen

author
#3 lore raw
In reply to Sean Christopherson
Quoted 7 lines · Sean Christopherson
Quoted 5 lines · Xin Li

It looks to me that MSR access API uses in KVM x86 are NOT consistent; sometimes {wr,rd}msrl() are used and sometimes native_{wr,rd}msrl() are used.

Was there a reason that how a generic or native MSR API was chosen?

Quoted 8 lines

I doubt anyone knows for sure; that'd likely require a time travelling device and/or telepathic abilities :-)

Quoted 3 lines

In my opinion KVM should use the native MSR APIs, which can streamline operations and potentially improve performance by avoiding the overhead associated with generic MSR API indirect calls when CONFIG_XEN_PV=y.

As Jürgen pointed out, they aren't indirect calls. Though IIUC, there is still

Right, I didn't notice such an optimization went in.

Quoted 1 line

a direct CALL and thus a RET when PARAVIRT_XXL=Y.

Correct.

Quoted 5 lines

I agree that using PV APIs in KVM doesn't make much sense, as running KVM in a XEN PV guest doesn't seem like something we should optimize for, if it's even supported. So if we end up churning all of the rdmsr/wrmsr macros, I have no objection to switching to native variants.

Thanks for the confirmation.

Quoted 4 lines

Though if we do that, it would be nice if there's a way to avoid the "native_" prefix everywhere, for the sake of readability.

Yeah, I will think about better naming them.