mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-04 04:06:26 +00:00
KVM: x86: Unpack msr_data structure prior to calling kvm_apic_set_base()
Pass in the new value and "host initiated" as separate parameters to kvm_apic_set_base(), as forcing the KVM_SET_SREGS path to declare and fill an msr_data structure is awkward and kludgy, e.g. __set_sregs_common() doesn't even bother to set the proper MSR index. No functional change intended. Suggested-by: Kai Huang <kai.huang@intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://lore.kernel.org/r/20241101183555.1794700-9-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
ff6ce56e1d
commit
c9155eb012
@ -2628,23 +2628,23 @@ static void __kvm_apic_set_base(struct kvm_vcpu *vcpu, u64 value)
|
||||
}
|
||||
}
|
||||
|
||||
int kvm_apic_set_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
|
||||
int kvm_apic_set_base(struct kvm_vcpu *vcpu, u64 value, bool host_initiated)
|
||||
{
|
||||
enum lapic_mode old_mode = kvm_get_apic_mode(vcpu);
|
||||
enum lapic_mode new_mode = kvm_apic_mode(msr_info->data);
|
||||
enum lapic_mode new_mode = kvm_apic_mode(value);
|
||||
u64 reserved_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu) | 0x2ff |
|
||||
(guest_cpuid_has(vcpu, X86_FEATURE_X2APIC) ? 0 : X2APIC_ENABLE);
|
||||
|
||||
if ((msr_info->data & reserved_bits) != 0 || new_mode == LAPIC_MODE_INVALID)
|
||||
if ((value & reserved_bits) != 0 || new_mode == LAPIC_MODE_INVALID)
|
||||
return 1;
|
||||
if (!msr_info->host_initiated) {
|
||||
if (!host_initiated) {
|
||||
if (old_mode == LAPIC_MODE_X2APIC && new_mode == LAPIC_MODE_XAPIC)
|
||||
return 1;
|
||||
if (old_mode == LAPIC_MODE_DISABLED && new_mode == LAPIC_MODE_X2APIC)
|
||||
return 1;
|
||||
}
|
||||
|
||||
__kvm_apic_set_base(vcpu, msr_info->data);
|
||||
__kvm_apic_set_base(vcpu, value);
|
||||
kvm_recalculate_apic_map(vcpu->kvm);
|
||||
return 0;
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
|
||||
struct kvm_lapic_irq *irq, int *r, struct dest_map *dest_map);
|
||||
void kvm_apic_send_ipi(struct kvm_lapic *apic, u32 icr_low, u32 icr_high);
|
||||
|
||||
int kvm_apic_set_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info);
|
||||
int kvm_apic_set_base(struct kvm_vcpu *vcpu, u64 value, bool host_initiated);
|
||||
int kvm_apic_get_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s);
|
||||
int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s);
|
||||
int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu);
|
||||
|
@ -3863,7 +3863,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
|
||||
case MSR_MTRRdefType:
|
||||
return kvm_mtrr_set_msr(vcpu, msr, data);
|
||||
case MSR_IA32_APICBASE:
|
||||
return kvm_apic_set_base(vcpu, msr_info);
|
||||
return kvm_apic_set_base(vcpu, data, msr_info->host_initiated);
|
||||
case APIC_BASE_MSR ... APIC_BASE_MSR + 0xff:
|
||||
return kvm_x2apic_msr_write(vcpu, msr, data);
|
||||
case MSR_IA32_TSC_DEADLINE:
|
||||
@ -11870,16 +11870,13 @@ static bool kvm_is_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
|
||||
static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs,
|
||||
int *mmu_reset_needed, bool update_pdptrs)
|
||||
{
|
||||
struct msr_data apic_base_msr;
|
||||
int idx;
|
||||
struct desc_ptr dt;
|
||||
|
||||
if (!kvm_is_valid_sregs(vcpu, sregs))
|
||||
return -EINVAL;
|
||||
|
||||
apic_base_msr.data = sregs->apic_base;
|
||||
apic_base_msr.host_initiated = true;
|
||||
if (kvm_apic_set_base(vcpu, &apic_base_msr))
|
||||
if (kvm_apic_set_base(vcpu, sregs->apic_base, true))
|
||||
return -EINVAL;
|
||||
|
||||
if (vcpu->arch.guest_state_protected)
|
||||
|
Loading…
Reference in New Issue
Block a user