@@ -1495,18 +1495,18 @@ EXPORT_SYMBOL_GPL(kvm_lapic_hv_timer_in_use);
1495
1495
1496
1496
static void cancel_hv_timer (struct kvm_lapic * apic )
1497
1497
{
1498
+ WARN_ON (preemptible ());
1498
1499
WARN_ON (!apic -> lapic_timer .hv_timer_in_use );
1499
- preempt_disable ();
1500
1500
kvm_x86_ops -> cancel_hv_timer (apic -> vcpu );
1501
1501
apic -> lapic_timer .hv_timer_in_use = false;
1502
- preempt_enable ();
1503
1502
}
1504
1503
1505
1504
static bool start_hv_timer (struct kvm_lapic * apic )
1506
1505
{
1507
1506
struct kvm_timer * ktimer = & apic -> lapic_timer ;
1508
1507
int r ;
1509
1508
1509
+ WARN_ON (preemptible ());
1510
1510
if (!kvm_x86_ops -> set_hv_timer )
1511
1511
return false;
1512
1512
@@ -1538,6 +1538,8 @@ static bool start_hv_timer(struct kvm_lapic *apic)
1538
1538
static void start_sw_timer (struct kvm_lapic * apic )
1539
1539
{
1540
1540
struct kvm_timer * ktimer = & apic -> lapic_timer ;
1541
+
1542
+ WARN_ON (preemptible ());
1541
1543
if (apic -> lapic_timer .hv_timer_in_use )
1542
1544
cancel_hv_timer (apic );
1543
1545
if (!apic_lvtt_period (apic ) && atomic_read (& ktimer -> pending ))
@@ -1552,15 +1554,20 @@ static void start_sw_timer(struct kvm_lapic *apic)
1552
1554
1553
1555
static void restart_apic_timer (struct kvm_lapic * apic )
1554
1556
{
1557
+ preempt_disable ();
1555
1558
if (!start_hv_timer (apic ))
1556
1559
start_sw_timer (apic );
1560
+ preempt_enable ();
1557
1561
}
1558
1562
1559
1563
void kvm_lapic_expired_hv_timer (struct kvm_vcpu * vcpu )
1560
1564
{
1561
1565
struct kvm_lapic * apic = vcpu -> arch .apic ;
1562
1566
1563
- WARN_ON (!apic -> lapic_timer .hv_timer_in_use );
1567
+ preempt_disable ();
1568
+ /* If the preempt notifier has already run, it also called apic_timer_expired */
1569
+ if (!apic -> lapic_timer .hv_timer_in_use )
1570
+ goto out ;
1564
1571
WARN_ON (swait_active (& vcpu -> wq ));
1565
1572
cancel_hv_timer (apic );
1566
1573
apic_timer_expired (apic );
@@ -1569,6 +1576,8 @@ void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu)
1569
1576
advance_periodic_target_expiration (apic );
1570
1577
restart_apic_timer (apic );
1571
1578
}
1579
+ out :
1580
+ preempt_enable ();
1572
1581
}
1573
1582
EXPORT_SYMBOL_GPL (kvm_lapic_expired_hv_timer );
1574
1583
@@ -1582,9 +1591,11 @@ void kvm_lapic_switch_to_sw_timer(struct kvm_vcpu *vcpu)
1582
1591
{
1583
1592
struct kvm_lapic * apic = vcpu -> arch .apic ;
1584
1593
1594
+ preempt_disable ();
1585
1595
/* Possibly the TSC deadline timer is not enabled yet */
1586
1596
if (apic -> lapic_timer .hv_timer_in_use )
1587
1597
start_sw_timer (apic );
1598
+ preempt_enable ();
1588
1599
}
1589
1600
EXPORT_SYMBOL_GPL (kvm_lapic_switch_to_sw_timer );
1590
1601
0 commit comments