hw/m68k/mcf52xx: Replace hw_error() by qemu_log_mask()
PATCH 1/1 hw/m68k/mcf52xx: Replace hw_error() by qemu_log_mask()
hw_error() calls exit(). This a bit overkill when we can log the accesses as unimplemented or guest error.
When fuzzing the devices, we don't want the whole process to exit. Replace some hw_error() calls by qemu_log_mask().
--- hw/m68k/mcf5206.c | 7 +++++-- hw/m68k/mcf5208.c | 14 +++++++++----- hw/m68k/mcf_intc.c | 4 +++- hw/net/mcf_fec.c | 8 +++++--- 4 files changed, 22 insertions(+), 11 deletions(-)
hw/m68k/mcf5206.c +5 -2
@@ -8,6 +8,7 @@#include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/log.h" #include "cpu.h" #include "hw/hw.h" #include "hw/irq.h"
@@ -306,7 +307,8 @@ static uint64_t m5206_mbar_read(m5206_mbar_state *s,case 0x170 :return s->uivr[0 ];case 0x1b0 :return s->uivr[1 ]; } -hw_error ("Bad MBAR read offset 0x%x" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad MBAR offset 0x%" HWADDR_PRIX "\n" , + __func__, offset);return 0 ; }
@@ -360,7 +362,8 @@ static void m5206_mbar_write(m5206_mbar_state *s, uint32_t offset, s->uivr[1 ] = value;break ;default : -hw_error ("Bad MBAR write offset 0x%x" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad MBAR offset 0x%x\n" , + __func__, offset);break ; } }
hw/m68k/mcf5208.c +9 -5
@@ -9,10 +9,10 @@#include "qemu/osdep.h" #include "qemu/units.h" #include "qemu/error-report.h" +#include "qemu/log.h" #include "qapi/error.h" #include "qemu-common.h" #include "cpu.h" -#include "hw/hw.h" #include "hw/irq.h" #include "hw/m68k/mcf.h" #include "hw/m68k/mcf_fec.h"
@@ -111,7 +111,8 @@ static void m5208_timer_write(void *opaque, hwaddr offset,case 4 :break ;default : -hw_error ("m5208_timer_write: Bad offset 0x%x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, offset);break ; }m5208_timer_update (s);
@@ -136,7 +137,8 @@ static uint64_t m5208_timer_read(void *opaque, hwaddr addr,case 4 :return ptimer_get_count (s->timer);default : -hw_error ("m5208_timer_read: Bad offset 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr);return 0 ; } }
@@ -164,7 +166,8 @@ static uint64_t m5208_sys_read(void *opaque, hwaddr addr,return 0 ;default : -hw_error ("m5208_sys_read: Bad offset 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr);return 0 ; } }
@@ -172,7 +175,8 @@ static uint64_t m5208_sys_read(void *opaque, hwaddr addr,static void m5208_sys_write (void *opaque,hwaddr addr,uint64_t value,unsigned size) { -hw_error ("m5208_sys_write: Bad offset 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr); }static const MemoryRegionOps m5208_sys_ops = {
hw/m68k/mcf_intc.c +3 -1
@@ -8,6 +8,7 @@#include "qemu/osdep.h" #include "qemu/module.h" +#include "qemu/log.h" #include "cpu.h" #include "hw/hw.h" #include "hw/irq.h"
@@ -127,7 +128,8 @@ static void mcf_intc_write(void *opaque, hwaddr addr, }break ;default : -hw_error ("mcf_intc_write: Bad write offset %d\n" , offset); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%02x\n" , + __func__, offset);break ; }mcf_intc_update (s);
hw/net/mcf_fec.c +5 -3
@@ -7,7 +7,7 @@*/ #include "qemu/osdep.h" -#include "hw/hw.h" +#include "qemu/log.h" #include "hw/irq.h" #include "net/net.h" #include "qemu/module.h"
@@ -392,7 +392,8 @@ static uint64_t mcf_fec_read(void *opaque, hwaddr addr,case 0x188 :return s->emrbr; case 0x200 ... 0x2e0: return s->mib[(addr & 0x1ff) / 4];default : -hw_error ("mcf_fec_read: Bad address 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad address 0x%" HWADDR_PRIX "\n" , + __func__, addr);return 0 ; } }
@@ -492,7 +493,8 @@ static void mcf_fec_write(void *opaque, hwaddr addr, s->mib[(addr &0x1ff ) /4 ] = value;break ;default : -hw_error ("mcf_fec_write Bad address 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad address 0x%" HWADDR_PRIX "\n" , + __func__, addr); }mcf_fec_update (s); }
Signature · 1 line
2.21.3
Quoted 2 lines · Philippe Mathieu-Daudé
hw_error()callsexit(). This a bit overkill when we can log the accesses as unimplemented or guest error.
Good idea. hw_error() is also mainly for CPU errors, it really should not be used for non-CPU devices.
Quoted 24 lines
When fuzzing the devices, we don't want the whole process to exit. Replace some
hw_error()calls byqemu_log_mask().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/m68k/mcf5206.c | 7 +++++-- hw/m68k/mcf5208.c | 14 +++++++++----- hw/m68k/mcf_intc.c | 4 +++- hw/net/mcf_fec.c | 8 +++++--- 4 files changed, 22 insertions(+), 11 deletions(-)hw/m68k/mcf5206.c +1
-0@@ -8,6 +8,7 @@#include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/log.h" #include "cpu.h" #include "hw/hw.h" #include "hw/irq.h"
hw/m68k/mcf5206.c static uint64_t m5206_mbar_read(m5206_mbar_state *s, · line 310
Quoted 5 lines
hw/m68k/mcf5206.c +1
-1@@ -306,7 +307,8 @@ static uint64_t m5206_mbar_read(m5206_mbar_state *s,case 0x170 :return s->uivr[0 ];case 0x1b0 :return s->uivr[1 ]; } -hw_error ("Bad MBAR read offset 0x%x" , (int )offset); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad MBAR offset 0x%" HWADDR_PRIX "\n",
offset seems to be uint64_t in this function, so I think this should rather use PRIx64 instead of HWADDR_PRIX ? Or maybe check whether we can change the offset to uint32_t ?
hw/m68k/mcf5206.c static void m5206_mbar_write(m5206_mbar_state *s, uint32_t offset, · line 366
Quoted 11 lines
hw/m68k/mcf5206.c +3
-1+ __func__, offset);return 0 ; }@@ -360,7 +362,8 @@ static void m5206_mbar_write(m5206_mbar_state *s, uint32_t offset, s->uivr[1 ] = value;break ;default : -hw_error ("Bad MBAR write offset 0x%x" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad MBAR offset 0x%x\n" , + __func__, offset);
Here offset seems to be uint32_t ... so I guess it should be fine for the _read function, too.
Quoted 20 lines
hw/m68k/mcf5206.c +0
-0break ; } }hw/m68k/mcf5208.c +1
-1@@ -9,10 +9,10 @@#include "qemu/osdep.h" #include "qemu/units.h" #include "qemu/error-report.h" +#include "qemu/log.h" #include "qapi/error.h" #include "qemu-common.h" #include "cpu.h" -#include "hw/hw.h" #include "hw/irq.h" #include "hw/m68k/mcf.h" #include "hw/m68k/mcf_fec.h"
hw/m68k/mcf5208.c static void m5208_timer_write(void *opaque, hwaddr offset, · line 116
Quoted 7 lines
hw/m68k/mcf5208.c +2
-1@@ -111,7 +111,8 @@ static void m5208_timer_write(void *opaque, hwaddr offset,case 4 :break ;default : -hw_error ("m5208_timer_write: Bad offset 0x%x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, offset);break ;
Should the "break" be replaced by a "return" now?
Quoted 45 lines
hw/m68k/mcf5208.c +6
-3}m5208_timer_update (s);@@ -136,7 +137,8 @@ static uint64_t m5208_timer_read(void *opaque, hwaddr addr,case 4 :return ptimer_get_count (s->timer);default : -hw_error ("m5208_timer_read: Bad offset 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr);return 0 ; } }@@ -164,7 +166,8 @@ static uint64_t m5208_sys_read(void *opaque, hwaddr addr,return 0 ;default : -hw_error ("m5208_sys_read: Bad offset 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr);return 0 ; } }@@ -172,7 +175,8 @@ static uint64_t m5208_sys_read(void *opaque, hwaddr addr,static void m5208_sys_write (void *opaque,hwaddr addr,uint64_t value,unsigned size) { -hw_error ("m5208_sys_write: Bad offset 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr); }static const MemoryRegionOps m5208_sys_ops = {hw/m68k/mcf_intc.c +1
-0@@ -8,6 +8,7 @@#include "qemu/osdep.h" #include "qemu/module.h" +#include "qemu/log.h" #include "cpu.h" #include "hw/hw.h" #include "hw/irq.h"
hw/m68k/mcf_intc.c static void mcf_intc_write(void *opaque, hwaddr addr, · line 133
Quoted 7 lines
hw/m68k/mcf_intc.c +2
-1@@ -127,7 +128,8 @@ static void mcf_intc_write(void *opaque, hwaddr addr, }break ;default : -hw_error ("mcf_intc_write: Bad write offset %d\n" , offset); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%02x\n" , + __func__, offset);break ;
"return" instead of "break" ?
Quoted 26 lines
hw/m68k/mcf_intc.c +0
-0}mcf_intc_update (s);hw/net/mcf_fec.c +3
-2@@ -7,7 +7,7 @@*/ #include "qemu/osdep.h" -#include "hw/hw.h" +#include "qemu/log.h" #include "hw/irq.h" #include "net/net.h" #include "qemu/module.h" @@ -392,7 +392,8 @@ static uint64_t mcf_fec_read(void *opaque, hwaddr addr,case 0x188 :return s->emrbr; case 0x200 ... 0x2e0: return s->mib[(addr & 0x1ff) / 4];default : -hw_error ("mcf_fec_read: Bad address 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad address 0x%" HWADDR_PRIX "\n" , + __func__, addr);return 0 ; } }
hw/net/mcf_fec.c static void mcf_fec_write(void *opaque, hwaddr addr, · line 497
Quoted 6 lines
hw/net/mcf_fec.c +2
-1@@ -492,7 +493,8 @@ static void mcf_fec_write(void *opaque, hwaddr addr, s->mib[(addr &0x1ff ) /4 ] = value;break ;default : -hw_error ("mcf_fec_write Bad address 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad address 0x%" HWADDR_PRIX "\n" , + __func__, addr);
return here?
hw/net/mcf_fec.c static void mcf_fec_write(void *opaque, hwaddr addr, · line 500
Quoted 4 lines
hw/net/mcf_fec.c +0
-0}mcf_fec_update (s); }
Thomas
Quoted 24 lines · Thomas Huth
Quoted 2 lines · Philippe Mathieu-Daudé
hw_error()callsexit(). This a bit overkill when we can log the accesses as unimplemented or guest error.Good idea.
hw_error()is also mainly for CPU errors, it really should not be used for non-CPU devices.Quoted 17 lines
When fuzzing the devices, we don't want the whole process to exit. Replace some
hw_error()calls byqemu_log_mask().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/m68k/mcf5206.c | 7 +++++-- hw/m68k/mcf5208.c | 14 +++++++++----- hw/m68k/mcf_intc.c | 4 +++- hw/net/mcf_fec.c | 8 +++++--- 4 files changed, 22 insertions(+), 11 deletions(-)hw/m68k/mcf5206.c +0
-0@@ -8,6 +8,7 @@
Quoted 16 lines
hw/m68k/mcf5206.c static uint64_t m5206_mbar_read(m5206_mbar_state *s, · line 310
Quoted 12 lines
hw/m68k/mcf5206.c +2
-1#include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/log.h" #include "cpu.h" #include "hw/hw.h" #include "hw/irq.h" @@ -306,7 +307,8 @@ static uint64_t m5206_mbar_read(m5206_mbar_state *s,case 0x170 :return s->uivr[0 ];case 0x1b0 :return s->uivr[1 ]; } -hw_error ("Bad MBAR read offset 0x%x" , (int )offset); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad MBAR offset 0x%" HWADDR_PRIX "\n",offset seems to be
uint64_tin this function, so I think this should rather use PRIx64 instead ofHWADDR_PRIX? Or maybe check whether we can change the offset touint32_t?
Too many copy/pasting, sorry.
Quoted 37 lines
hw/m68k/mcf5206.c static void m5206_mbar_write(m5206_mbar_state *s, uint32_t offset, · line 366
Quoted 12 lines
hw/m68k/mcf5206.c +3
-1+ __func__, offset);return 0 ; }@@ -360,7 +362,8 @@ static void m5206_mbar_write(m5206_mbar_state *s, uint32_t offset, s->uivr[1 ] = value;break ;default : -hw_error ("Bad MBAR write offset 0x%x" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad MBAR offset 0x%x\n" , + __func__, offset);Here offset seems to be
uint32_t... so I guess it should be fine for the_readfunction, too.Quoted 21 lines
hw/m68k/mcf5206.c +0
-0break ; } }hw/m68k/mcf5208.c +1
-1@@ -9,10 +9,10 @@#include "qemu/osdep.h" #include "qemu/units.h" #include "qemu/error-report.h" +#include "qemu/log.h" #include "qapi/error.h" #include "qemu-common.h" #include "cpu.h" -#include "hw/hw.h" #include "hw/irq.h" #include "hw/m68k/mcf.h" #include "hw/m68k/mcf_fec.h" @@ -111,7 +111,8 @@ static void m5208_timer_write(void *opaque, hwaddr offset,case 4 :
Quoted 8 lines
hw/m68k/mcf5208.c static void m5208_timer_write(void *opaque, hwaddr offset, · line 116
Quoted 6 lines
hw/m68k/mcf5208.c +2
-1break ;default : -hw_error ("m5208_timer_write: Bad offset 0x%x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, offset);break ;Should the "break" be replaced by a "return" now?
I was not sure, OK.
Quoted 99 lines
Quoted 46 lines
hw/m68k/mcf5208.c +6
-3}m5208_timer_update (s);@@ -136,7 +137,8 @@ static uint64_t m5208_timer_read(void *opaque, hwaddr addr,case 4 :return ptimer_get_count (s->timer);default : -hw_error ("m5208_timer_read: Bad offset 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr);return 0 ; } }@@ -164,7 +166,8 @@ static uint64_t m5208_sys_read(void *opaque, hwaddr addr,return 0 ;default : -hw_error ("m5208_sys_read: Bad offset 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr);return 0 ; } }@@ -172,7 +175,8 @@ static uint64_t m5208_sys_read(void *opaque, hwaddr addr,static void m5208_sys_write (void *opaque,hwaddr addr,uint64_t value,unsigned size) { -hw_error ("m5208_sys_write: Bad offset 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr); }static const MemoryRegionOps m5208_sys_ops = {hw/m68k/mcf_intc.c +1
-0@@ -8,6 +8,7 @@#include "qemu/osdep.h" #include "qemu/module.h" +#include "qemu/log.h" #include "cpu.h" #include "hw/hw.h" #include "hw/irq.h" hw/m68k/mcf_intc.c static void mcf_intc_write(void *opaque, hwaddr addr, · line 133
Quoted 7 lines
hw/m68k/mcf_intc.c +2
-1@@ -127,7 +128,8 @@ static void mcf_intc_write(void *opaque, hwaddr addr, }break ;default : -hw_error ("mcf_intc_write: Bad write offset %d\n" , offset); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%02x\n" , + __func__, offset);break ;"return" instead of "break" ?
Quoted 26 lines
hw/m68k/mcf_intc.c +0
-0}mcf_intc_update (s);hw/net/mcf_fec.c +3
-2@@ -7,7 +7,7 @@*/ #include "qemu/osdep.h" -#include "hw/hw.h" +#include "qemu/log.h" #include "hw/irq.h" #include "net/net.h" #include "qemu/module.h" @@ -392,7 +392,8 @@ static uint64_t mcf_fec_read(void *opaque, hwaddr addr,case 0x188 :return s->emrbr; case 0x200 ... 0x2e0: return s->mib[(addr & 0x1ff) / 4];default : -hw_error ("mcf_fec_read: Bad address 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad address 0x%" HWADDR_PRIX "\n" , + __func__, addr);return 0 ; } }hw/net/mcf_fec.c static void mcf_fec_write(void *opaque, hwaddr addr, · line 497
Quoted 6 lines
hw/net/mcf_fec.c +2
-1@@ -492,7 +493,8 @@ static void mcf_fec_write(void *opaque, hwaddr addr, s->mib[(addr &0x1ff ) /4 ] = value;break ;default : -hw_error ("mcf_fec_write Bad address 0x%x\n" , (int )addr); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad address 0x%" HWADDR_PRIX "\n" , + __func__, addr);return here?
hw/net/mcf_fec.c static void mcf_fec_write(void *opaque, hwaddr addr, · line 500
Quoted 4 lines
hw/net/mcf_fec.c +0
-0}mcf_fec_update (s); }Thomas
Quoted 6 lines · Thomas Huth
Quoted 2 lines · Philippe Mathieu-Daudé
hw_error()callsexit(). This a bit overkill when we can log the accesses as unimplemented or guest error.Good idea.
hw_error()is also mainly for CPU errors, it really should not be used for non-CPU devices.
Are you sure?
$ git grep hw_error target | wc -l 5 $ git grep hw_error hw | wc -l 137
[...]
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Thomas Huth
Quoted 2 lines · Philippe Mathieu-Daudé
hw_error()callsexit(). This a bit overkill when we can log the accesses as unimplemented or guest error.Good idea.
hw_error()is also mainly for CPU errors, it really should not be used for non-CPU devices.
Quoted 6 lines
Are you sure?
$ git grep hw_error target | wc -l 5 $ git grep hw_error hw | wc -l 137
Well, the function is defined in cpus.c and it's dumping the state of each CPU ... I think it's used in a lot of places during development of new code to quickly get some information on where things went wrong in the guest, but technically, it really sounds wrong to me that a non-CPU device creates CPU dumps in mature code.
Thomas
Quoted 16 lines · Thomas Huth
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Thomas Huth
Quoted 2 lines · Philippe Mathieu-Daudé
hw_error()callsexit(). This a bit overkill when we can log the accesses as unimplemented or guest error.Good idea.
hw_error()is also mainly for CPU errors, it really should not be used for non-CPU devices.Quoted 6 lines
Are you sure?
$ git grep hw_error target | wc -l 5 $ git grep hw_error hw | wc -l 137
Quoted 5 lines
Well, the function is defined in
cpus.cand it's dumping the state of each CPU ... I think it's used in a lot of places during development of new code to quickly get some information on where things went wrong in the guest, but technically, it really sounds wrong to me that a non-CPU device creates CPU dumps in mature code.
OK got it now, thanks.