Skip to contentSkip to conversation

ehci: fix "int" overflow for calculation ehci->last_run_ns

Qemu-devel 李林 2 participants 2 messages May 10, 2017 – May 12, 2017

lore
Share & tools
lore

李林

author
#0 lore raw

If we experience large delays between echi timer callbacks (i.e. because other periodic handlers have taken a lot of time to complete) we get a lot of skipped frames which then delay ehci timer callback.
Then we will calculation ehci->last_run_ns,but skipped_uframes is int,so "UFRAME_TIMER_NS * skipped_uframes" will be int,and if skipped_uframes is big enough ,it can overflow ,and this can not calculation the right number,then it can raise large amountsinterrupts;
Observable behaviour is qemu consuming 100% host CPU time while guest is unresponsive. This misbehavior could happen for a while and QEMU does not get out from this state automatically without the patch in Branch-master repository.

hw/usb/hcd-ehci.c +1 -1
index 50ef817f93..8df2f08783 100644
@@ -2238,7 +2238,7 @@ static void ehci_frame_timer(void *opaque)
     int need_timer = 0;
     int64_t expire_time, t_now;
     uint64_t ns_elapsed;
-    int uframes, skipped_uframes;
+    uint64 uframes, skipped_uframes;
     int i;
 
 
     t_now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
#1 lore raw
Quoted 18 lines · 李林

If we experience large delays between echi timer callbacks (i.e. because other periodic handlers have taken a lot of time to complete) we get a lot of skipped frames which then delay ehci timer callback.
Then we will calculation ehci->last_run_ns,but skipped_uframes is int,so "UFRAME_TIMER_NS * skipped_uframes" will be int,and if skipped_uframes is big enough ,it can overflow ,and this can not calculation the right number,then it can raise large amountsinterrupts;
Observable behaviour is qemu consuming 100% host CPU time while guest is unresponsive. This misbehavior could happen for a while and QEMU does not get out from this state automatically without the patch in Branch-master repository.

hw/usb/hcd-ehci.c +1 -1
index 50ef817f93..8df2f08783 100644
@@ -2238,7 +2238,7 @@ static void ehci_frame_timer(void *opaque)
     int need_timer = 0;
     int64_t expire_time, t_now;
     uint64_t ns_elapsed;
-    int uframes, skipped_uframes;
+    uint64 uframes, skipped_uframes;
     int i;
 
 
Quoted 2 lines
     t_now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);

Adding Gerd as USB maintainer to CC.

ATB,

Mark.