mirror of
https://github.com/torvalds/linux.git
synced 2026-06-03 12:03:54 +02:00
KVM: x86: Add kvm_msr_{read,write}() helpers
Wrap __kvm_{get,set}_msr() into two new helpers for KVM usage and use the
helpers to replace existing usage of the raw functions.
kvm_msr_{read,write}() are KVM-internal helpers, i.e. used when KVM needs
to get/set a MSR value for emulating CPU behavior, i.e., host_initiated ==
%true in the helpers.
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Tested-by: Mathias Krause <minipli@grsecurity.net>
Tested-by: John Allen <john.allen@amd.com>
Signed-off-by: Chao Gao <chao.gao@intel.com>
Tested-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Link: https://lore.kernel.org/r/20250812025606.74625-4-chao.gao@intel.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
db07f3d0eb
commit
c2aa58b226
|
|
@ -2156,9 +2156,10 @@ void kvm_enable_efer_bits(u64);
|
|||
bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
|
||||
int kvm_emulate_msr_read(struct kvm_vcpu *vcpu, u32 index, u64 *data);
|
||||
int kvm_emulate_msr_write(struct kvm_vcpu *vcpu, u32 index, u64 data);
|
||||
int __kvm_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data, bool host_initiated);
|
||||
int __kvm_emulate_msr_read(struct kvm_vcpu *vcpu, u32 index, u64 *data);
|
||||
int __kvm_emulate_msr_write(struct kvm_vcpu *vcpu, u32 index, u64 data);
|
||||
int kvm_msr_read(struct kvm_vcpu *vcpu, u32 index, u64 *data);
|
||||
int kvm_msr_write(struct kvm_vcpu *vcpu, u32 index, u64 data);
|
||||
int kvm_emulate_rdmsr(struct kvm_vcpu *vcpu);
|
||||
int kvm_emulate_rdmsr_imm(struct kvm_vcpu *vcpu, u32 msr, int reg);
|
||||
int kvm_emulate_wrmsr(struct kvm_vcpu *vcpu);
|
||||
|
|
|
|||
|
|
@ -2006,7 +2006,7 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
|
|||
if (function == 7 && index == 0) {
|
||||
u64 data;
|
||||
if ((*ebx & (feature_bit(RTM) | feature_bit(HLE))) &&
|
||||
!__kvm_get_msr(vcpu, MSR_IA32_TSX_CTRL, &data, true) &&
|
||||
!kvm_msr_read(vcpu, MSR_IA32_TSX_CTRL, &data) &&
|
||||
(data & TSX_CTRL_CPUID_CLEAR))
|
||||
*ebx &= ~(feature_bit(RTM) | feature_bit(HLE));
|
||||
} else if (function == 0x80000007) {
|
||||
|
|
|
|||
|
|
@ -1899,8 +1899,8 @@ static int kvm_set_msr_ignored_check(struct kvm_vcpu *vcpu,
|
|||
* Returns 0 on success, non-0 otherwise.
|
||||
* Assumes vcpu_load() was already called.
|
||||
*/
|
||||
int __kvm_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data,
|
||||
bool host_initiated)
|
||||
static int __kvm_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data,
|
||||
bool host_initiated)
|
||||
{
|
||||
struct msr_data msr;
|
||||
int ret;
|
||||
|
|
@ -1926,6 +1926,16 @@ int __kvm_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data,
|
|||
return ret;
|
||||
}
|
||||
|
||||
int kvm_msr_write(struct kvm_vcpu *vcpu, u32 index, u64 data)
|
||||
{
|
||||
return __kvm_set_msr(vcpu, index, data, true);
|
||||
}
|
||||
|
||||
int kvm_msr_read(struct kvm_vcpu *vcpu, u32 index, u64 *data)
|
||||
{
|
||||
return __kvm_get_msr(vcpu, index, data, true);
|
||||
}
|
||||
|
||||
static int kvm_get_msr_ignored_check(struct kvm_vcpu *vcpu,
|
||||
u32 index, u64 *data, bool host_initiated)
|
||||
{
|
||||
|
|
@ -12472,7 +12482,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
|
|||
MSR_IA32_MISC_ENABLE_BTS_UNAVAIL;
|
||||
|
||||
__kvm_set_xcr(vcpu, 0, XFEATURE_MASK_FP);
|
||||
__kvm_set_msr(vcpu, MSR_IA32_XSS, 0, true);
|
||||
kvm_msr_write(vcpu, MSR_IA32_XSS, 0);
|
||||
}
|
||||
|
||||
/* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user