hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
kernel/arch/x86/kvm/vmx/vmx.c
....@@ -752,14 +752,15 @@
752752 static int vmx_set_guest_uret_msr(struct vcpu_vmx *vmx,
753753 struct vmx_uret_msr *msr, u64 data)
754754 {
755
+ unsigned long flags;
755756 int ret = 0;
756757
757758 u64 old_msr_data = msr->data;
758759 msr->data = data;
759760 if (msr - vmx->guest_uret_msrs < vmx->nr_active_uret_msrs) {
760
- preempt_disable();
761
+ flags = hard_preempt_disable();
761762 ret = kvm_set_user_return_msr(msr->slot, msr->data, msr->mask);
762
- preempt_enable();
763
+ hard_preempt_enable(flags);
763764 if (ret)
764765 msr->data = old_msr_data;
765766 }
....@@ -1383,19 +1384,23 @@
13831384 #ifdef CONFIG_X86_64
13841385 static u64 vmx_read_guest_kernel_gs_base(struct vcpu_vmx *vmx)
13851386 {
1386
- preempt_disable();
1387
+ unsigned long flags;
1388
+
1389
+ flags = hard_preempt_disable();
13871390 if (vmx->guest_state_loaded)
13881391 rdmsrl(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base);
1389
- preempt_enable();
1392
+ hard_preempt_enable(flags);
13901393 return vmx->msr_guest_kernel_gs_base;
13911394 }
13921395
13931396 static void vmx_write_guest_kernel_gs_base(struct vcpu_vmx *vmx, u64 data)
13941397 {
1395
- preempt_disable();
1398
+ unsigned long flags;
1399
+
1400
+ flags = hard_preempt_disable();
13961401 if (vmx->guest_state_loaded)
13971402 wrmsrl(MSR_KERNEL_GS_BASE, data);
1398
- preempt_enable();
1403
+ hard_preempt_enable(flags);
13991404 vmx->msr_guest_kernel_gs_base = data;
14001405 }
14011406 #endif
....@@ -1795,6 +1800,7 @@
17951800 */
17961801 static void setup_msrs(struct vcpu_vmx *vmx)
17971802 {
1803
+ hard_cond_local_irq_disable();
17981804 vmx->guest_uret_msrs_loaded = false;
17991805 vmx->nr_active_uret_msrs = 0;
18001806 #ifdef CONFIG_X86_64
....@@ -1815,6 +1821,7 @@
18151821 vmx_setup_uret_msr(vmx, MSR_TSC_AUX);
18161822
18171823 vmx_setup_uret_msr(vmx, MSR_IA32_TSX_CTRL);
1824
+ hard_cond_local_irq_enable();
18181825
18191826 if (cpu_has_vmx_msr_bitmap())
18201827 vmx_update_msr_bitmap(&vmx->vcpu);
....@@ -2050,6 +2057,7 @@
20502057 u32 msr_index = msr_info->index;
20512058 u64 data = msr_info->data;
20522059 u32 index;
2060
+ unsigned long flags;
20532061
20542062 switch (msr_index) {
20552063 case MSR_EFER:
....@@ -2289,11 +2297,22 @@
22892297
22902298 default:
22912299 find_uret_msr:
2300
+ /*
2301
+ * Guest MSRs may be activated independently from
2302
+ * vcpu_run(): rely on the notifier for restoring them
2303
+ * upon preemption by the companion core, right before
2304
+ * the current CPU switches to out-of-band scheduling
2305
+ * (see dovetail_context_switch()).
2306
+ */
22922307 msr = vmx_find_uret_msr(vmx, msr_index);
2293
- if (msr)
2308
+ if (msr) {
2309
+ flags = hard_cond_local_irq_save();
2310
+ inband_enter_guest(vcpu);
22942311 ret = vmx_set_guest_uret_msr(vmx, msr, data);
2295
- else
2312
+ hard_cond_local_irq_restore(flags);
2313
+ } else {
22962314 ret = kvm_set_msr_common(vcpu, msr_info);
2315
+ }
22972316 }
22982317
22992318 /* FB_CLEAR may have changed, also update the FB_CLEAR_DIS behavior */
....@@ -7056,7 +7075,9 @@
70567075 vmx_vcpu_load(vcpu, cpu);
70577076 vcpu->cpu = cpu;
70587077 init_vmcs(vmx);
7078
+ hard_cond_local_irq_disable();
70597079 vmx_vcpu_put(vcpu);
7080
+ hard_cond_local_irq_enable();
70607081 put_cpu();
70617082 if (cpu_need_virtualize_apic_accesses(vcpu)) {
70627083 err = alloc_apic_access_page(vcpu->kvm);