Skip to content

Commit 1b3618b

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fixes from Paolo Bonzini: "Except for the preempt notifiers fix, these are all small bugfixes that could have been waited for -rc2. Sending them now since I was taking care of Peter's patch anyway" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: kvm: add hyper-v crash msrs values KVM: x86: remove data variable from kvm_get_msr_common KVM: s390: virtio-ccw: don't overwrite config space values KVM: x86: keep track of LVT0 changes under APICv KVM: x86: properly restore LVT0 KVM: x86: make vapics_in_nmi_mode atomic sched, preempt_notifier: separate notifier registration from static_key inc/dec
2 parents 14a6f19 + a88464a commit 1b3618b

File tree

10 files changed

+54
-16
lines changed

10 files changed

+54
-16
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ struct kvm_arch {
607607
struct kvm_pic *vpic;
608608
struct kvm_ioapic *vioapic;
609609
struct kvm_pit *vpit;
610-
int vapics_in_nmi_mode;
610+
atomic_t vapics_in_nmi_mode;
611611
struct mutex apic_map_lock;
612612
struct kvm_apic_map *apic_map;
613613

arch/x86/include/uapi/asm/hyperv.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@
199199
#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6
200200
#define HV_X64_MSR_STIMER3_COUNT 0x400000B7
201201

202+
/* Hyper-V guest crash notification MSR's */
203+
#define HV_X64_MSR_CRASH_P0 0x40000100
204+
#define HV_X64_MSR_CRASH_P1 0x40000101
205+
#define HV_X64_MSR_CRASH_P2 0x40000102
206+
#define HV_X64_MSR_CRASH_P3 0x40000103
207+
#define HV_X64_MSR_CRASH_P4 0x40000104
208+
#define HV_X64_MSR_CRASH_CTL 0x40000105
209+
#define HV_X64_MSR_CRASH_CTL_NOTIFY (1ULL << 63)
210+
#define HV_X64_MSR_CRASH_PARAMS \
211+
(1 + (HV_X64_MSR_CRASH_P4 - HV_X64_MSR_CRASH_P0))
212+
202213
#define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001
203214
#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12
204215
#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK \

arch/x86/kvm/i8254.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static void pit_do_work(struct kthread_work *work)
305305
* LVT0 to NMI delivery. Other PIC interrupts are just sent to
306306
* VCPU0, and only if its LVT0 is in EXTINT mode.
307307
*/
308-
if (kvm->arch.vapics_in_nmi_mode > 0)
308+
if (atomic_read(&kvm->arch.vapics_in_nmi_mode) > 0)
309309
kvm_for_each_vcpu(i, vcpu, kvm)
310310
kvm_apic_nmi_wd_deliver(vcpu);
311311
}

arch/x86/kvm/lapic.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,16 +1257,17 @@ static void start_apic_timer(struct kvm_lapic *apic)
12571257

12581258
static void apic_manage_nmi_watchdog(struct kvm_lapic *apic, u32 lvt0_val)
12591259
{
1260-
int nmi_wd_enabled = apic_lvt_nmi_mode(kvm_apic_get_reg(apic, APIC_LVT0));
1260+
bool lvt0_in_nmi_mode = apic_lvt_nmi_mode(lvt0_val);
12611261

1262-
if (apic_lvt_nmi_mode(lvt0_val)) {
1263-
if (!nmi_wd_enabled) {
1262+
if (apic->lvt0_in_nmi_mode != lvt0_in_nmi_mode) {
1263+
apic->lvt0_in_nmi_mode = lvt0_in_nmi_mode;
1264+
if (lvt0_in_nmi_mode) {
12641265
apic_debug("Receive NMI setting on APIC_LVT0 "
12651266
"for cpu %d\n", apic->vcpu->vcpu_id);
1266-
apic->vcpu->kvm->arch.vapics_in_nmi_mode++;
1267-
}
1268-
} else if (nmi_wd_enabled)
1269-
apic->vcpu->kvm->arch.vapics_in_nmi_mode--;
1267+
atomic_inc(&apic->vcpu->kvm->arch.vapics_in_nmi_mode);
1268+
} else
1269+
atomic_dec(&apic->vcpu->kvm->arch.vapics_in_nmi_mode);
1270+
}
12701271
}
12711272

12721273
static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
@@ -1597,6 +1598,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event)
15971598
if (!(vcpu->kvm->arch.disabled_quirks & KVM_QUIRK_LINT0_REENABLED))
15981599
apic_set_reg(apic, APIC_LVT0,
15991600
SET_APIC_DELIVERY_MODE(0, APIC_MODE_EXTINT));
1601+
apic_manage_nmi_watchdog(apic, kvm_apic_get_reg(apic, APIC_LVT0));
16001602

16011603
apic_set_reg(apic, APIC_DFR, 0xffffffffU);
16021604
apic_set_spiv(apic, 0xff);
@@ -1822,6 +1824,7 @@ void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu,
18221824
apic_update_ppr(apic);
18231825
hrtimer_cancel(&apic->lapic_timer.timer);
18241826
apic_update_lvtt(apic);
1827+
apic_manage_nmi_watchdog(apic, kvm_apic_get_reg(apic, APIC_LVT0));
18251828
update_divide_count(apic);
18261829
start_apic_timer(apic);
18271830
apic->irr_pending = true;

arch/x86/kvm/lapic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct kvm_lapic {
2626
struct kvm_vcpu *vcpu;
2727
bool sw_enabled;
2828
bool irr_pending;
29+
bool lvt0_in_nmi_mode;
2930
/* Number of bits set in ISR. */
3031
s16 isr_count;
3132
/* The highest vector set in ISR; if -1 - invalid, must scan ISR. */

arch/x86/kvm/x86.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,8 +2379,6 @@ static int get_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
23792379

23802380
int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
23812381
{
2382-
u64 data;
2383-
23842382
switch (msr_info->index) {
23852383
case MSR_IA32_PLATFORM_ID:
23862384
case MSR_IA32_EBL_CR_POWERON:
@@ -2453,7 +2451,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
24532451
/* TSC increment by tick */
24542452
msr_info->data = 1000ULL;
24552453
/* CPU multiplier */
2456-
data |= (((uint64_t)4ULL) << 40);
2454+
msr_info->data |= (((uint64_t)4ULL) << 40);
24572455
break;
24582456
case MSR_EFER:
24592457
msr_info->data = vcpu->arch.efer;

drivers/s390/kvm/virtio_ccw.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct virtio_ccw_device {
6565
bool is_thinint;
6666
bool going_away;
6767
bool device_lost;
68+
unsigned int config_ready;
6869
void *airq_info;
6970
};
7071

@@ -833,8 +834,11 @@ static void virtio_ccw_get_config(struct virtio_device *vdev,
833834
if (ret)
834835
goto out_free;
835836

836-
memcpy(vcdev->config, config_area, sizeof(vcdev->config));
837-
memcpy(buf, &vcdev->config[offset], len);
837+
memcpy(vcdev->config, config_area, offset + len);
838+
if (buf)
839+
memcpy(buf, &vcdev->config[offset], len);
840+
if (vcdev->config_ready < offset + len)
841+
vcdev->config_ready = offset + len;
838842

839843
out_free:
840844
kfree(config_area);
@@ -857,6 +861,9 @@ static void virtio_ccw_set_config(struct virtio_device *vdev,
857861
if (!config_area)
858862
goto out_free;
859863

864+
/* Make sure we don't overwrite fields. */
865+
if (vcdev->config_ready < offset)
866+
virtio_ccw_get_config(vdev, 0, NULL, offset);
860867
memcpy(&vcdev->config[offset], buf, len);
861868
/* Write the config area to the host. */
862869
memcpy(config_area, vcdev->config, sizeof(vcdev->config));

include/linux/preempt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ struct preempt_notifier {
293293
struct preempt_ops *ops;
294294
};
295295

296+
void preempt_notifier_inc(void);
297+
void preempt_notifier_dec(void);
296298
void preempt_notifier_register(struct preempt_notifier *notifier);
297299
void preempt_notifier_unregister(struct preempt_notifier *notifier);
298300

kernel/sched/core.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,13 +2320,27 @@ void wake_up_new_task(struct task_struct *p)
23202320

23212321
static struct static_key preempt_notifier_key = STATIC_KEY_INIT_FALSE;
23222322

2323+
void preempt_notifier_inc(void)
2324+
{
2325+
static_key_slow_inc(&preempt_notifier_key);
2326+
}
2327+
EXPORT_SYMBOL_GPL(preempt_notifier_inc);
2328+
2329+
void preempt_notifier_dec(void)
2330+
{
2331+
static_key_slow_dec(&preempt_notifier_key);
2332+
}
2333+
EXPORT_SYMBOL_GPL(preempt_notifier_dec);
2334+
23232335
/**
23242336
* preempt_notifier_register - tell me when current is being preempted & rescheduled
23252337
* @notifier: notifier struct to register
23262338
*/
23272339
void preempt_notifier_register(struct preempt_notifier *notifier)
23282340
{
2329-
static_key_slow_inc(&preempt_notifier_key);
2341+
if (!static_key_false(&preempt_notifier_key))
2342+
WARN(1, "registering preempt_notifier while notifiers disabled\n");
2343+
23302344
hlist_add_head(&notifier->link, &current->preempt_notifiers);
23312345
}
23322346
EXPORT_SYMBOL_GPL(preempt_notifier_register);
@@ -2340,7 +2354,6 @@ EXPORT_SYMBOL_GPL(preempt_notifier_register);
23402354
void preempt_notifier_unregister(struct preempt_notifier *notifier)
23412355
{
23422356
hlist_del(&notifier->link);
2343-
static_key_slow_dec(&preempt_notifier_key);
23442357
}
23452358
EXPORT_SYMBOL_GPL(preempt_notifier_unregister);
23462359

virt/kvm/kvm_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ static struct kvm *kvm_create_vm(unsigned long type)
553553
list_add(&kvm->vm_list, &vm_list);
554554
spin_unlock(&kvm_lock);
555555

556+
preempt_notifier_inc();
557+
556558
return kvm;
557559

558560
out_err:
@@ -620,6 +622,7 @@ static void kvm_destroy_vm(struct kvm *kvm)
620622
cleanup_srcu_struct(&kvm->irq_srcu);
621623
cleanup_srcu_struct(&kvm->srcu);
622624
kvm_arch_free_vm(kvm);
625+
preempt_notifier_dec();
623626
hardware_disable_all();
624627
mmdrop(mm);
625628
}

0 commit comments

Comments
 (0)