Rework FIXMEs and fprintfs in hcd-xhci.c
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
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
@@ -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
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 anabort()statement, this terminates QEMU. Turn the FIXME statements into aqemu_log_mask()instead to avoid that a guest can shoot itself this way.Reported-by Feifan Qian <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3784
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Thomas Huth <[email protected]>--- hw/usb/hcd-xhci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/usb/hcd-xhci.c +1
-1@@ -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
PATCH v3 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.
--- hw/usb/hcd-xhci.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/usb/hcd-xhci.c +1 -3
@@ -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
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_QUEUEandUSB_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 ag_assert_not_reached()instead.
Quoted 5 lines
Suggested-by Peter Maydell <[email protected]>Signed-off-by Thomas Huth <[email protected]>--- 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
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_QUEUEandUSB_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 ag_assert_not_reached()instead.Quoted 5 lines
Suggested-by Peter Maydell <[email protected]>Signed-off-by Thomas Huth <[email protected]>--- hw/usb/hcd-xhci.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Quoted 4 lines
Reviewed-by Peter Maydell <[email protected]>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
Philippe Mathieu-Daudé
Reviewed-byRe: [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_QUEUEandUSB_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 ag_assert_not_reached()instead.Suggested-by Peter Maydell <[email protected]>Signed-off-by Thomas Huth <[email protected]>---
hw/usb/hcd-xhci.c| 4 +---1 file changed, 1 insertion(+), 3 deletions(-)
Quoted 5 lines
Quoted 4 lines
Reviewed-by Peter Maydell <[email protected]>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().
PATCH v3 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" ); *cc_error =CC_INVALID_STREAM_TYPE_ERROR ;return NULL ; }
Signature · 1 line
2.55.0
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 thefprintf()here now.Suggested-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(-)hw/usb/hcd-xhci.c +0
-0
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
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 thefprintf()here now.Suggested-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(-)hw/usb/hcd-xhci.c +0
-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" );
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
Reviewed-by Peter Maydell <[email protected]>
Thanks!
Thomas