Skip to content

Commit c4f6681

Browse files
conghuic23acrnsi
authored andcommitted
softirq: disable interrupt when modify timer_list
In current code, the timer_list for per cpu can be accessed both in vmexit and softirq handler. There is a case that, the timer_list is modifying in vmexit, but an interrupt occur, the timer_list is also modified in softirq handler. So the time_list may in unpredictable state. In some platforms, the hv console may hang as its timer handler is not invoked because of the corruption for timer_list. So, to fix the issue, disable the interrupt before modifying the timer_list. Tracked-On: #3512 Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Signed-off-by: Conghui Chen <conghui.chen@intel.com> Reviewed-by: Li, Fei1 <fei1.li@intel.com>
1 parent f49ab66 commit c4f6681

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

hypervisor/arch/x86/timer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ int32_t add_timer(struct hv_timer *timer)
8989
struct per_cpu_timers *cpu_timer;
9090
uint16_t pcpu_id;
9191
int32_t ret = 0;
92+
uint64_t rflags;
9293

9394
if ((timer == NULL) || (timer->func == NULL) || (timer->fire_tsc == 0UL)) {
9495
ret = -EINVAL;
@@ -103,10 +104,12 @@ int32_t add_timer(struct hv_timer *timer)
103104
pcpu_id = get_pcpu_id();
104105
cpu_timer = &per_cpu(cpu_timers, pcpu_id);
105106

107+
CPU_INT_ALL_DISABLE(&rflags);
106108
/* update the physical timer if we're on the timer_list head */
107109
if (local_add_timer(cpu_timer, timer)) {
108110
update_physical_timer(cpu_timer);
109111
}
112+
CPU_INT_ALL_RESTORE(rflags);
110113

111114
TRACE_2L(TRACE_TIMER_ACTION_ADDED, timer->fire_tsc, 0UL);
112115
}
@@ -117,9 +120,13 @@ int32_t add_timer(struct hv_timer *timer)
117120

118121
void del_timer(struct hv_timer *timer)
119122
{
123+
uint64_t rflags;
124+
125+
CPU_INT_ALL_DISABLE(&rflags);
120126
if ((timer != NULL) && !list_empty(&timer->node)) {
121127
list_del_init(&timer->node);
122128
}
129+
CPU_INT_ALL_RESTORE(rflags);
123130
}
124131

125132
static void init_percpu_timer(uint16_t pcpu_id)

0 commit comments

Comments
 (0)