Add LOG_GUEST_ERROR for reporting guest bugs
cover Add LOG_GUEST_ERROR for reporting guest bugs
This patch series introduces a new logging category to qemu_log_mask(), for reporting situations which the device model can cope with but which indicate bugs in the guest. The most common cause of these is "guest tried to access a register which doesn't exist". At the moment device models use an inconsistent mix of "silently ignore", "hw_error(), killing qemu" and "direct print to stderr" for reporting this kind of event.
Patches 2-7 are a random selection of ARM devices which I've switched to using the new LOG_GUEST_ERROR (or the existing LOG_UNIMP where that is more appropriate). There are obviously more conversions that could be made; this is just a sample to demonstrate the utility of the log category.
One question that comes to mind -- should we include qemu-log.h in qemu-common.h (or some other common header?) rather than having to include qemu-log.h directly in lots of device model source files?
Peter Maydell (7):
qemu-log: Add new log category for guest bugs
hw/pl181: Use LOG_UNIMP and LOG_GUEST_ERROR
hw/pl041: Use LOG_UNIMP
hw/pl190: Use LOG_GUEST_ERROR
hw/pl011: Use LOG_UNIMP and LOG_GUEST_ERROR
hw/pl022: Use LOG_UNIMP and LOG_GUEST_ERROR
hw/pl031: Use LOG_GUEST_ERROR
hw/pl011.c | 12 ++++++++---- hw/pl022.c | 9 ++++++--- hw/pl031.c | 17 +++++++++++------ hw/pl041.c | 6 ++++-- hw/pl181.c | 19 +++++++++++-------- hw/pl190.c | 7 +++++-- qemu-log.c | 3 +++ qemu-log.h | 1 + 8 files changed, 49 insertions(+), 25 deletions(-)
Signature · 1 line
1.7.11.4
PATCH 1/7 qemu-log: Add new log category for guest bugs
Add a new category for device models to log guest behaviour which is likely to be a guest bug of some kind (accessing nonexistent registers, reading 32 bit wide registers with a byte access, etc). Making this its own log category allows those who care (mostly guest OS authors) to see the complaints without bothering most users.
--- qemu-log.c | 3 +++ qemu-log.h | 1 + 2 files changed, 4 insertions(+)
qemu-log.c +3 -0
@@ -116,6 +116,9 @@ const CPULogItem cpu_log_items[] = { "show all i/o ports accesses" }, {LOG_UNIMP ,"unimp" , "log unimplemented functionality" }, + { LOG_GUEST_ERROR, "guest_errors", +"log when the guest OS does something invalid (eg accessing a\n" + "non-existent register)" }, { 0, NULL, NULL }, };
qemu-log.h +1 -0
@@ -35,6 +35,7 @@ static inline bool qemu_log_enabled(void)#define CPU_LOG_TB_CPU (1 << 8)#define CPU_LOG_RESET (1 << 9)#define LOG_UNIMP (1 << 10) +#define LOG_GUEST_ERROR (1 << 11)/* Returns true if a bit is set in the current loglevel mask */
Signature · 1 line
1.7.11.4
PATCH 2/7 hw/pl181: Use LOG_UNIMP and LOG_GUEST_ERROR
In reply to Peter MaydellRather than a mix of direct printing to stderr and aborting via hw_error(), use LOG_UNIMP and LOG_GUEST_ERROR.
--- hw/pl181.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
hw/pl181.c +11 -8
@@ -10,6 +10,7 @@#include "blockdev.h" #include "sysbus.h" #include "sd.h" +#include "qemu-log.h" //#define DEBUG_PL181 1
@@ -352,7 +353,7 @@ static uint64_t pl181_read(void *opaque, target_phys_addr_t offset,case 0xa0 :case 0xa4 :case 0xa8 :case 0xac :case 0xb0 :case 0xb4 :case 0xb8 :case 0xbc :if (s->fifo_len ==0 ) { -fprintf (stderr,"pl181: Unexpected FIFO read\n" ); +qemu_log_mask (LOG_GUEST_ERROR ,"pl181: Unexpected FIFO read\n" );return 0 ; }else {uint32_t value;
@@ -363,7 +364,8 @@ static uint64_t pl181_read(void *opaque, target_phys_addr_t offset,return value; }default : -hw_error ("pl181_read: Bad offset %x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"pl181_read: Bad offset %x\n" , (int )offset);return 0 ; } }
@@ -387,11 +389,11 @@ static void pl181_write(void *opaque, target_phys_addr_t offset, s->cmd = value;if (s->cmd &PL181_CMD_ENABLE ) {if (s->cmd &PL181_CMD_INTERRUPT ) { -fprintf (stderr,"pl181: Interrupt mode not implemented\n" ); -abort (); +qemu_log_mask (LOG_UNIMP , +"pl181: Interrupt mode not implemented\n" ); }if (s->cmd &PL181_CMD_PENDING ) { -fprintf (stderr,"pl181: Pending commands not implemented\n" ); -abort (); +qemu_log_mask (LOG_UNIMP , +"pl181: Pending commands not implemented\n" ); }else {pl181_send_command (s);pl181_fifo_run (s);
@@ -427,14 +429,15 @@ static void pl181_write(void *opaque, target_phys_addr_t offset,case 0xa0 :case 0xa4 :case 0xa8 :case 0xac :case 0xb0 :case 0xb4 :case 0xb8 :case 0xbc :if (s->datacnt ==0 ) { -fprintf (stderr,"pl181: Unexpected FIFO write\n" ); +qemu_log_mask (LOG_GUEST_ERROR ,"pl181: Unexpected FIFO write\n" ); }else {pl181_fifo_push (s, value);pl181_fifo_run (s); }break ;default : -hw_error ("pl181_write: Bad offset %x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"pl181_write: Bad offset %x\n" , (int )offset); }pl181_update (s); }
Signature · 1 line
1.7.11.4
PATCH 3/7 hw/pl041: Use LOG_UNIMP
In reply to Peter MaydellUse the new LOG_UNIMP tracing to report unimplemented features.
--- hw/pl041.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/pl041.c +4 -2
@@ -21,6 +21,7 @@*/ #include "sysbus.h" +#include "qemu-log.h" #include "pl041.h" #include "lm4549.h"
@@ -536,8 +537,9 @@ static int pl041_init(SysBusDevice *dev)default :/* NC FIFO depth of 16 is not allowed because its id bits in AACIPERIPHID3 overlap with the id for the default NC FIFO depth */ -fprintf (stderr,"pl041: unsupported non-compact fifo depth [%i]\n" , - s->fifo_depth); +qemu_log_mask (LOG_UNIMP , +"pl041: unsupported non-compact fifo depth [%i]\n" , + s->fifo_depth);return -1 ; }
Signature · 1 line
1.7.11.4
PATCH 4/7 hw/pl190: Use LOG_GUEST_ERROR
In reply to Peter MaydellIf the guest attempts an offset to a nonexistent register, just log this via LOG_GUEST_ERROR rather than killing QEMU with a hw_error.
--- hw/pl190.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
hw/pl190.c +5 -2
@@ -8,6 +8,7 @@*/ #include "sysbus.h" +#include "qemu-log.h" /* The number of virtual priority levels. 16 user vectors plus the unvectored IRQ. Chained interrupts would require an additional level
@@ -143,7 +144,8 @@ static uint64_t pl190_read(void *opaque, target_phys_addr_t offset,case 13 :/* DEFVECTADDR */ return s->vect_addr[16 ];default : -hw_error ("pl190_read: Bad offset %x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"pl190_read: Bad offset %x\n" , (int )offset);return 0 ; } }
@@ -202,7 +204,8 @@ static void pl190_write(void *opaque, target_phys_addr_t offset, }break ;default : -hw_error ("pl190_write: Bad offset %x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"pl190_write: Bad offset %x\n" , (int )offset);return ; }pl190_update (s);
Signature · 1 line
1.7.11.4
PATCH 5/7 hw/pl011: Use LOG_UNIMP and LOG_GUEST_ERROR
In reply to Peter MaydellUse the new LOG_UNIMP and LOG_GUEST_ERROR logging types rather than hw_error().
--- hw/pl011.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
hw/pl011.c +8 -4
@@ -9,6 +9,7 @@#include "sysbus.h" #include "qemu-char.h" +#include "qemu-log.h" typedef struct { SysBusDevice busdev;
@@ -107,7 +108,8 @@ static uint64_t pl011_read(void *opaque, target_phys_addr_t offset,case 18 :/* UARTDMACR */ return s->dmacr;default : -hw_error ("pl011_read: Bad offset %x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"pl011_read: Bad offset %x\n" , (int )offset);return 0 ; } }
@@ -178,11 +180,13 @@ static void pl011_write(void *opaque, target_phys_addr_t offset,break ;case 18 :/* UARTDMACR */ s->dmacr = value; -if (value &3 ) -hw_error ("PL011: DMA not implemented\n" ); +if (value &3 ) { +qemu_log_mask (LOG_UNIMP ,"pl011: DMA not implemented\n" ); + }break ;default : -hw_error ("pl011_write: Bad offset %x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"pl011_write: Bad offset %x\n" , (int )offset); } }
Signature · 1 line
1.7.11.4
PATCH 6/7 hw/pl022: Use LOG_UNIMP and LOG_GUEST_ERROR
In reply to Peter MaydellUse LOG_UNIMP and LOG_GUEST_ERROR where appropriate rather than hw_error().
--- hw/pl022.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
hw/pl022.c +6 -3
@@ -9,6 +9,7 @@#include "sysbus.h" #include "ssi.h" +#include "qemu-log.h" //#define DEBUG_PL022 1
@@ -168,7 +169,8 @@ static uint64_t pl022_read(void *opaque, target_phys_addr_t offset,/* Not implemented. */ return 0 ;default : -hw_error ("pl022_read: Bad offset %x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"pl022_read: Bad offset %x\n" , (int )offset);return 0 ; } }
@@ -211,11 +213,12 @@ static void pl022_write(void *opaque, target_phys_addr_t offset,break ;case 0x20 :/* DMACR */ if (value) { -hw_error ("pl022: DMA not implemented\n" ); +qemu_log_mask (LOG_UNIMP ,"pl022: DMA not implemented\n" ); }break ;default : -hw_error ("pl022_write: Bad offset %x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"pl022_write: Bad offset %x\n" , (int )offset); } }
Signature · 1 line
1.7.11.4
PATCH 7/7 hw/pl031: Use LOG_GUEST_ERROR
In reply to Peter MaydellUse LOG_GUEST_ERROR rather than hw_error or direct fprintf.
--- hw/pl031.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
hw/pl031.c +11 -6
@@ -14,6 +14,7 @@#include "sysbus.h" #include "qemu-timer.h" #include "sysemu.h" +#include "qemu-log.h" //#define DEBUG_PL031
@@ -120,11 +121,13 @@ static uint64_t pl031_read(void *opaque, target_phys_addr_t offset,case RTC_MIS :return s->is & s->im;case RTC_ICR : -fprintf (stderr,"qemu: pl031_read: Unexpected offset 0x%x\n" , - (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"pl031: read of write-only register at offset 0x%x\n" , + (int )offset);break ;default : -hw_error ("pl031_read: Bad offset 0x%x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"pl031_read: Bad offset 0x%x\n" , (int )offset);break ; }
@@ -167,12 +170,14 @@ static void pl031_write(void * opaque, target_phys_addr_t offset,case RTC_DR :case RTC_MIS :case RTC_RIS : -fprintf (stderr,"qemu: pl031_write: Unexpected offset 0x%x\n" , - (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"pl031: write to read-only register at offset 0x%x\n" , + (int )offset);break ;default : -hw_error ("pl031_write: Bad offset 0x%x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"pl031_write: Bad offset 0x%x\n" , (int )offset);break ; } }
Signature · 1 line
1.7.11.4
Quoted 9 lines · Peter Maydell
This patch series introduces a new logging category to
qemu_log_mask(), for reporting situations which the device model can cope with but which indicate bugs in the guest. The most common cause of these is "guest tried to access a register which doesn't exist". At the moment device models use an inconsistent mix of "silently ignore", "hw_error(), killing qemu" and "direct print to stderr" for reporting this kind of event.
Quoted 5 lines
Patches 2-7 are a random selection of ARM devices which I've switched to using the new
LOG_GUEST_ERROR(or the existingLOG_UNIMPwhere that is more appropriate). There are obviously more conversions that could be made; this is just a sample to demonstrate the utility of the log category.
The conversion is not entirely trivial, since hw_error() does not return but qemu_log_mask() does. Your changes look OK.
Quoted 5 lines
One question that comes to mind -- should we include
qemu-log.hinqemu-common.h(or some other common header?) rather than having to includeqemu-log.hdirectly in lots of device model source files?
Yes.
Quoted 23 lines
Peter Maydell (7):
qemu-log: Add new log category for guest bugs
hw/pl181: UseLOG_UNIMPandLOG_GUEST_ERROR
hw/pl041: UseLOG_UNIMP
hw/pl190: UseLOG_GUEST_ERROR
hw/pl011: UseLOG_UNIMPandLOG_GUEST_ERROR
hw/pl022: UseLOG_UNIMPandLOG_GUEST_ERROR
hw/pl031: UseLOG_GUEST_ERRORhw/pl011.c | 12 ++++++++---- hw/pl022.c | 9 ++++++--- hw/pl031.c | 17 +++++++++++------ hw/pl041.c | 6 ++++-- hw/pl181.c | 19 +++++++++++-------- hw/pl190.c | 7 +++++-- qemu-log.c | 3 +++ qemu-log.h | 1 + 8 files changed, 49 insertions(+), 25 deletions(-)--
1.7.11.4
Quoted 7 lines · Blue Swirl
Quoted 4 lines · Peter Maydell
One question that comes to mind -- should we include
qemu-log.hinqemu-common.h(or some other common header?) rather than having to includeqemu-log.hdirectly in lots of device model source files?Yes.
This turns out not to be quite as trivial as I'd thought, since qemu-log.h requires (if NEED_CPU_H is defined) definitions of types like target_ulong. So we can't include it from qemu-common.h unless we change all the target-*/cpu.h to include cpu-defs.h before qemu-common.h. Alternatively we could split the NEED_CPU_H bits of qemu-log.h out into a qemu-cpu-log.h which would be manually included by the bits of qemu that needed it.
The other option would be to include qemu-log.h from hw/hw.h. This just works without requiring any complicated workarounds, and all the device code includes hw.h already...
-- PMM
Quoted 17 lines · Peter Maydell
Quoted 7 lines · Blue Swirl
Quoted 4 lines · Peter Maydell
One question that comes to mind -- should we include
qemu-log.hinqemu-common.h(or some other common header?) rather than having to includeqemu-log.hdirectly in lots of device model source files?Yes.
This turns out not to be quite as trivial as I'd thought, since
qemu-log.hrequires (ifNEED_CPU_His defined) definitions of types liketarget_ulong. So we can't include it fromqemu-common.hunless we change all thetarget-*/cpu.hto includecpu-defs.hbeforeqemu-common.h. Alternatively we could split theNEED_CPU_Hbits ofqemu-log.hout into aqemu-cpu-log.hwhich would be manually included by the bits of qemu that needed it.
Quoted 3 lines
The other option would be to include
qemu-log.hfromhw/hw.h. This just works without requiring any complicated workarounds, and all the device code includeshw.halready...
I was also thinking about that but then I thought that it would be nice to use qemu-log.h elsewhere too. But hw/hw.h sounds much easier for now.
Quoted 2 lines
-- PMM