Rework FIXMEs and fprintfs in hcd-xhci.c
v4 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().
v4:
- Remove the DPRINTF in the second patch
- Add the missing \n in the third patch
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 | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
Signature · 1 line
2.55.0
PATCH v4 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
@@ -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
PATCH v4 2/3 hw/usb/hcd-xhci: Remove the FIXME macro
In reply to Thomas HuthFrom: 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 (and remove the DPRINT() in front of it to avoid that code analyzers trip over unreachable code here).
--- hw/usb/hcd-xhci.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
hw/usb/hcd-xhci.c +1 -5
@@ -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
@@ -1673,9 +1671,7 @@ static int xhci_try_complete_packet(XHCITransfer *xfer)xhci_stall_ep (xfer);break ;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
PATCH v4 3/3 hw/usb/hcd-xhci: Use qemu_log_mask() instead of fprintf() statement
In reply to Thomas HuthFrom: 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
@@ -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\n" ); *cc_error =CC_INVALID_STREAM_TYPE_ERROR ;return NULL ; }
Signature · 1 line
2.55.0
Re: [PATCH v4 3/3] hw/usb/hcd-xhci: Use qemu_log_mask() instead of fprintf() statement
Quoted 11 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 thefprintf()here now.Suggested-by Peter Maydell <[email protected]>Reviewed-by Peter Maydell <[email protected]>Signed-off-by Thomas Huth <[email protected]>--- hw/usb/hcd-xhci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 4 lines · Thomas Huth
Thomas Huth (3):
hw/usb/hcd-xhci: Turn guest-triggerableabort()intoqemu_log_mask()hw/usb/hcd-xhci: Remove the FIXME macro
hw/usb/hcd-xhci: Useqemu_log_mask()instead offprintf()statement
Series queued, thanks.