Skip to contentSkip to conversation

usb-ehci: Ensure frindex writes leave a valid frindex value

PATCH In review Hans de Goede 2 participants 3 messages Apr 3, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb-ehci: Ensure frindex writes leave a valid frindex value

frindex is a 14 bits counter, so bits 31-14 should always be 0, and after the commit titled "usb-ehci: frindex always is a 14 bits counter" we rely on frindex always being a multiple of 8. I've not seen this in practice, but theoretically a guest can write a value >= 0x4000 or a value which is not a multiple of 8 value to frindex, this patch ensures that things will still work when that happens.

---
 hw/usb/hcd-ehci.c |    4 ++++
 1 file changed, 4 insertions(+)
hw/usb/hcd-ehci.c +4 -0
index 64b58e3..8865b4e 100644
@@ -1102,6 +1102,10 @@ static void ehci_mem_writel(void *ptr, target_phys_addr_t addr, uint32_t val)
         val &= USBINTR_MASK;
         break;
 
+    case FRINDEX:
+        val &= 0x00003ff8; /* frindex is 14bits and always a multiple of 8 */
+        break;
+
     case CONFIGFLAG:
         val &= 0x1;
         if (val) {
Signature · 1 line
1.7.9.3
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Hans de Goede

frindex is a 14 bits counter, so bits 31-14 should always be 0, and after the commit titled "usb-ehci: frindex always is a 14 bits counter" we rely on frindex always being a multiple of 8. I've not seen this in practice, but theoretically a guest can write a value >= 0x4000 or a value which is not a multiple of 8 value to frindex, this patch ensures that things will still work when that happens.

Quoted 25 lines
---
 hw/usb/hcd-ehci.c |    4 ++++
 1 file changed, 4 insertions(+)
hw/usb/hcd-ehci.c +4 -0
index 64b58e3..8865b4e 100644
@@ -1102,6 +1102,10 @@ static void ehci_mem_writel(void *ptr, target_phys_addr_t addr, uint32_t val)
         val &= USBINTR_MASK;
         break;
 
+    case FRINDEX:
+        val &= 0x00003ff8; /* frindex is 14bits and always a multiple of 8 */
+        break;
+
     case CONFIGFLAG:
         val &= 0x1;
         if (val) {
Signature · 1 line
1.7.9.3
Reviewed-by
#2 lore raw
Quoted 9 lines · Alon Levy
Quoted 6 lines · Hans de Goede

frindex is a 14 bits counter, so bits 31-14 should always be 0, and after the commit titled "usb-ehci: frindex always is a 14 bits counter" we rely on frindex always being a multiple of 8. I've not seen this in practice, but theoretically a guest can write a value >= 0x4000 or a value which is not a multiple of 8 value to frindex, this patch ensures that things will still work when that happens.

I meant:

Quoted 27 lines
Quoted 26 lines
---
 hw/usb/hcd-ehci.c |    4 ++++
 1 file changed, 4 insertions(+)
hw/usb/hcd-ehci.c +4 -0
index 64b58e3..8865b4e 100644
@@ -1102,6 +1102,10 @@ static void ehci_mem_writel(void *ptr, target_phys_addr_t addr, uint32_t val)
         val &= USBINTR_MASK;
         break;
 
+    case FRINDEX:
+        val &= 0x00003ff8; /* frindex is 14bits and always a multiple of 8 */
+        break;
+
     case CONFIGFLAG:
         val &= 0x1;
         if (val) {
Signature · 1 line
1.7.9.3