Skip to contentSkip to conversation

Rework FIXMEs and fprintfs in hcd-xhci.c

PATCH Superseded Thomas Huth 3 participants 10 messages Jul 13

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Rework FIXMEs and fprintfs in hcd-xhci.c

Replace the local FIXME macro and fprintf statement with qemu_log_mask() and g_assert_not_reached().

Thomas Huth (3):
hw/usb/hcd-xhci: Turn guest-triggerable abort() into qemu_log_mask() hw/usb/hcd-xhci: Remove the FIXME macro
hw/usb/hcd-xhci: Use qemu_log_mask() instead of fprintf() statement

 hw/usb/hcd-xhci.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH v3 1/3 hw/usb/hcd-xhci: Turn guest-triggerable abort() into qemu_log_mask()

From: Thomas Huth <[email protected]>

The FIXME macros in xhci_alloc_device_streams() can be triggered by a (malicious) guest. Since the macro also contains an abort() statement, this terminates QEMU. Turn the FIXME statements into a qemu_log_mask() instead to avoid that a guest can shoot itself this way.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3784

---
 hw/usb/hcd-xhci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/usb/hcd-xhci.c +4 -2
index 2cdab3ba0e4..f5bb7d25600 100644
@@ -965,11 +965,13 @@ static TRBCCode xhci_alloc_device_streams(XHCIState *xhci, unsigned int slotid,
          * together and make an usb_device_alloc_streams call per group.
          */
         if (epctxs[i]->nr_pstreams != req_nr_streams) {
-            FIXME("guest streams config not identical for all eps");
+            qemu_log_mask(LOG_UNIMP,
+                          "guest streams config not identical for all eps\n");
             return CC_RESOURCE_ERROR;
         }
         if (eps[i]->max_streams != dev_max_streams) {
-            FIXME("device streams config not identical for all eps");
+            qemu_log_mask(LOG_UNIMP,
+                          "device streams config not identical for all eps\n");
             return CC_RESOURCE_ERROR;
         }
     }
Signature · 1 line
2.55.0
Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] hw/usb/hcd-xhci: Turn guest-triggerable abort() into qemu_log_mask()

Quoted 27 lines · Thomas Huth

From: Thomas Huth <[email protected]>

The FIXME macros in xhci_alloc_device_streams() can be triggered by a (malicious) guest. Since the macro also contains an abort() statement, this terminates QEMU. Turn the FIXME statements into a qemu_log_mask() instead to avoid that a guest can shoot itself this way.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3784

---
 hw/usb/hcd-xhci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/usb/hcd-xhci.c +1 -1
index 2cdab3ba0e4..f5bb7d25600 100644
@@ -965,11 +965,13 @@ static TRBCCode xhci_alloc_device_streams(XHCIState *xhci, unsigned int slotid,
          * together and make an usb_device_alloc_streams call per group.
          */
         if (epctxs[i]->nr_pstreams != req_nr_streams) {
-            FIXME("guest streams config not identical for all eps");
+            qemu_log_mask(LOG_UNIMP,

hw/usb/hcd-xhci.c static TRBCCode xhci_alloc_device_streams(XHCIState *xhci, unsigned int slotid, · line 977

Quoted 10 lines
hw/usb/hcd-xhci.c +3 -1
+                          "guest streams config not identical for all eps\n");
             return CC_RESOURCE_ERROR;
         }
         if (eps[i]->max_streams != dev_max_streams) {
-            FIXME("device streams config not identical for all eps");
+            qemu_log_mask(LOG_UNIMP,
+                          "device streams config not identical for all eps\n");
             return CC_RESOURCE_ERROR;
         }
     }

thanks
-- PMM

#3 lore raw

PATCH v3 2/3 hw/usb/hcd-xhci: Remove the FIXME macro

In reply to Thomas Huth

From: Thomas Huth <[email protected]>

The FIXME macro is only used in one case, which should hopefully never trigger: The containing function handles all the USB_RET_* values except for USB_RET_ADD_TO_QUEUE and USB_RET_REMOVE_FROM_QUEUE, which are both internal return values for when an async packet needs to be queued or dequeued, and which shouldn't still be the status by the time we get to this function. Thus let's simplify this spot and use a g_assert_not_reached() instead.

---
 hw/usb/hcd-xhci.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/usb/hcd-xhci.c +1 -3
index f5bb7d25600..ee913d5c4d5 100644
@@ -39,8 +39,6 @@
 #else
 #define DPRINTF(...) do {} while (0)
 #endif
-#define FIXME(_msg) do { fprintf(stderr, "FIXME %s:%d %s\n", \
-                                 __func__, __LINE__, _msg); abort(); } while (0)
 
 #define TRB_LINK_LIMIT  32
 #define COMMAND_LIMIT   256
@@ -1675,7 +1673,7 @@ static int xhci_try_complete_packet(XHCITransfer *xfer)
     default:
         DPRINTF("%s: FIXME: status = %d\n", __func__,
                 xfer->packet.status);
-        FIXME("unhandled USB_RET_*");
+        g_assert_not_reached();
     }
     return 0;
 }
Signature · 1 line
2.55.0
Reviewed-by on v3 2/3
#4 lore raw

Re: [PATCH v3 2/3] hw/usb/hcd-xhci: Remove the FIXME macro

Quoted 11 lines · Thomas Huth

From: Thomas Huth <[email protected]>

The FIXME macro is only used in one case, which should hopefully never trigger: The containing function handles all the USB_RET_* values except for USB_RET_ADD_TO_QUEUE and USB_RET_REMOVE_FROM_QUEUE, which are both internal return values for when an async packet needs to be queued or dequeued, and which shouldn't still be the status by the time we get to this function. Thus let's simplify this spot and use a g_assert_not_reached() instead.

Quoted 5 lines
---
 hw/usb/hcd-xhci.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Not sure if some compilers/analyzers would complain about the DPRINTF followed by g_assert_not_reached().

thanks
-- PMM

#5 lore raw

Re: [PATCH v3 2/3] hw/usb/hcd-xhci: Remove the FIXME macro

Quoted 18 lines · Peter Maydell
Quoted 11 lines · Thomas Huth

From: Thomas Huth <[email protected]>

The FIXME macro is only used in one case, which should hopefully never trigger: The containing function handles all the USB_RET_* values except for USB_RET_ADD_TO_QUEUE and USB_RET_REMOVE_FROM_QUEUE, which are both internal return values for when an async packet needs to be queued or dequeued, and which shouldn't still be the status by the time we get to this function. Thus let's simplify this spot and use a g_assert_not_reached() instead.

Quoted 5 lines
---
  hw/usb/hcd-xhci.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
Quoted 4 lines

Not sure if some compilers/analyzers would complain about the DPRINTF followed by g_assert_not_reached().

I hope they don't complain since the macro is disabled by default...? Or shall we play save and remove the DPRINTF here, too?

Thomas

#6 lore raw

Re: [PATCH v3 2/3] hw/usb/hcd-xhci: Remove the FIXME macro

Quoted 19 lines · Thomas Huth
Quoted 18 lines · Peter Maydell
Quoted 16 lines · Thomas Huth

From: Thomas Huth <[email protected]>

The FIXME macro is only used in one case, which should hopefully never trigger: The containing function handles all the USB_RET_* values except for USB_RET_ADD_TO_QUEUE and USB_RET_REMOVE_FROM_QUEUE, which are both internal return values for when an async packet needs to be queued or dequeued, and which shouldn't still be the status by the time we get to this function. Thus let's simplify this spot and use a g_assert_not_reached() instead.

---
  hw/usb/hcd-xhci.c | 4 +---

  1 file changed, 1 insertion(+), 3 deletions(-)
Quoted 5 lines
Quoted 4 lines

Not sure if some compilers/analyzers would complain about the DPRINTF followed by g_assert_not_reached().

I hope they don't complain since the macro is disabled by default...? Or shall we play save and remove the DPRINTF here, too?

I'd remove this pointless DPRINTF().

#7 lore raw

PATCH v3 3/3 hw/usb/hcd-xhci: Use qemu_log_mask() instead of fprintf() statement

In reply to Thomas Huth

From: Thomas Huth <[email protected]>

We've got a proper way for logging unimplemented hardware features, so use qemu_log_mask() instead of the fprintf() here now.

---
 hw/usb/hcd-xhci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/usb/hcd-xhci.c +2 -1
index ee913d5c4d5..527910d92d2 100644
@@ -1017,7 +1017,8 @@ static XHCIStreamContext *xhci_find_stream(XHCIEPContext *epctx,
         }
         sctx = epctx->pstreams + streamid;
     } else {
-        fprintf(stderr, "xhci: FIXME: secondary streams not implemented yet");
+        qemu_log_mask(LOG_UNIMP,
+                      "xhci: secondary streams not implemented yet");
         *cc_error = CC_INVALID_STREAM_TYPE_ERROR;
         return NULL;
     }
Signature · 1 line
2.55.0
Reviewed-by on v3 3/3
#8 lore raw

Re: [PATCH v3 3/3] hw/usb/hcd-xhci: Use qemu_log_mask() instead of fprintf() statement

Quoted 17 lines · Thomas Huth

From: Thomas Huth <[email protected]>

We've got a proper way for logging unimplemented hardware features, so use qemu_log_mask() instead of the fprintf() here now.

---
 hw/usb/hcd-xhci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/usb/hcd-xhci.c +0 -0
index ee913d5c4d5..527910d92d2 100644

hw/usb/hcd-xhci.c static XHCIStreamContext *xhci_find_stream(XHCIEPContext *epctx, · line 1024

Quoted 9 lines
hw/usb/hcd-xhci.c +2 -1
@@ -1017,7 +1017,8 @@ static XHCIStreamContext *xhci_find_stream(XHCIEPContext *epctx,
         }
         sctx = epctx->pstreams + streamid;
     } else {
-        fprintf(stderr, "xhci: FIXME: secondary streams not implemented yet");
+        qemu_log_mask(LOG_UNIMP,
+                      "xhci: secondary streams not implemented yet");
         *cc_error = CC_INVALID_STREAM_TYPE_ERROR;
         return NULL;
     }

qemu_log_mask() strings need a trailing "\n" (as of course does printing messages to stderr :-)).

Otherwise

thanks
-- PMM

#9 lore raw

Re: [PATCH v3 3/3] hw/usb/hcd-xhci: Use qemu_log_mask() instead of fprintf() statement

Quoted 22 lines · Peter Maydell
Quoted 21 lines · Thomas Huth

From: Thomas Huth <[email protected]>

We've got a proper way for logging unimplemented hardware features, so use qemu_log_mask() instead of the fprintf() here now.

---
  hw/usb/hcd-xhci.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/usb/hcd-xhci.c +0 -1
index ee913d5c4d5..527910d92d2 100644
@@ -1017,7 +1017,8 @@ static XHCIStreamContext *xhci_find_stream(XHCIEPContext *epctx,
          }
          sctx = epctx->pstreams + streamid;
      } else {
-        fprintf(stderr, "xhci: FIXME: secondary streams not implemented yet");
Quoted 8 lines

hw/usb/hcd-xhci.c static XHCIStreamContext *xhci_find_stream(XHCIEPContext *epctx, · line 1024

Quoted 5 lines
hw/usb/hcd-xhci.c +2 -0
+        qemu_log_mask(LOG_UNIMP,
+                      "xhci: secondary streams not implemented yet");
          *cc_error = CC_INVALID_STREAM_TYPE_ERROR;
          return NULL;
      }

qemu_log_mask() strings need a trailing "\n" (as of course does printing messages to stderr :-)).

D'oh, I forgot it again! Thanks for spotting it! I'll send an updated version...

Quoted 2 lines

Otherwise

Thanks!

Thomas