Add LOG_GUEST_ERROR for reporting guest bugs
v2 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 3-8 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.
Changes v1->v2:
* add patch 2 including qemu-log.h in hw/hw.h
* update 3..8 to not include qemu-log.h directly
Peter Maydell (8):
qemu-log: Add new log category for guest bugs
hw/hw.h: Add include of qemu-log.h
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/hw.h | 1 + hw/pl011.c | 11 +++++++---- hw/pl022.c | 8 +++++--- hw/pl031.c | 16 ++++++++++------ hw/pl041.c | 5 +++-- hw/pl181.c | 18 ++++++++++-------- hw/pl190.c | 6 ++++-- qemu-log.c | 3 +++ qemu-log.h | 1 + 9 files changed, 44 insertions(+), 25 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v2 1/8 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.9.5
PATCH v2 2/8 hw/hw.h: Add include of qemu-log.h
In reply to Peter MaydellAdd an include of qemu-log.h to hw.h, so that device model code has access to these logging functions without the need to directly include qemu-log.h.
--- hw/hw.h | 1 + 1 file changed, 1 insertion(+)
hw/hw.h +1 -0
@@ -12,6 +12,7 @@#include "irq.h" #include "qemu-file.h" #include "vmstate.h" +#include "qemu-log.h" #ifdef NEED_CPU_H #if TARGET_LONG_BITS ==64
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH v2 2/8] hw/hw.h: Add include of qemu-log.h
Quoted 3 lines · On Thu, 18 Oct 2012 14:11:36 +0100 Peter Maydell <[email protected]>…
Add an include of
qemu-log.htohw.h, so that device model code has access to these logging functions without the need to directly includeqemu-log.h.
It would be better to include qemu-log.h to files that have immediate dependency on it, then creating another include all "qemu-common.h." and compile/preprocess it for every hw file.
Quoted 18 lines
Signed-off-by Peter Maydell <[email protected]>--- hw/hw.h | 1 + 1 file changed, 1 insertion(+)hw/hw.h +1
-0@@ -12,6 +12,7 @@#include "irq.h" #include "qemu-file.h" #include "vmstate.h" +#include "qemu-log.h" #ifdef NEED_CPU_H #if TARGET_LONG_BITS ==64
Re: [Qemu-devel] [PATCH v2 2/8] hw/hw.h: Add include of qemu-log.h
Quoted 7 lines · Igor Mammedov
Quoted 3 lines · Peter Maydell
Add an include of
qemu-log.htohw.h, so that device model code has access to these logging functions without the need to directly includeqemu-log.h.It would be better to include
qemu-log.hto files that have immediate dependency on it, then creating another include all "qemu-common.h." and compile/preprocess it for every hw file.
That is what v1 of this patch did; Blue suggested it would be better to put it in a common header, and I agree:
basically every device model will have cases where it will want to diagnose bad guest behaviour, and so we would end up including qemu-log.h in every file in hw/.
-- PMM
PATCH v2 3/8 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 | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
hw/pl181.c +10 -8
@@ -352,7 +352,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 +363,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 +388,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 +428,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.9.5
PATCH v2 4/8 hw/pl041: Use LOG_UNIMP
In reply to Peter MaydellUse the new LOG_UNIMP tracing to report unimplemented features.
--- hw/pl041.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/pl041.c +3 -2
@@ -536,8 +536,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.9.5
PATCH v2 5/8 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/pl190.c +4 -2
@@ -143,7 +143,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 +203,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.9.5
PATCH v2 6/8 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 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
hw/pl011.c +7 -4
@@ -107,7 +107,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 +179,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.9.5
PATCH v2 7/8 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
hw/pl022.c +5 -3
@@ -168,7 +168,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 +212,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.9.5
PATCH v2 8/8 hw/pl031: Use LOG_GUEST_ERROR
In reply to Peter MaydellUse LOG_GUEST_ERROR rather than hw_error or direct fprintf.
--- hw/pl031.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
hw/pl031.c +10 -6
@@ -120,11 +120,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 +169,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.9.5
Blue Swirl
AppliedQuoted 15 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.Patches 3-8 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.
Quoted 3 lines
Changes
v1->v2:
* add patch 2 includingqemu-log.hinhw/hw.h
* update 3..8 to not includeqemu-log.hdirectly
Thanks, applied all.
Quoted 26 lines
Peter Maydell (8):
qemu-log: Add new log category for guest bugs
hw/hw.h: Add include ofqemu-log.h
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/hw.h | 1 + hw/pl011.c | 11 +++++++---- hw/pl022.c | 8 +++++--- hw/pl031.c | 16 ++++++++++------ hw/pl041.c | 5 +++-- hw/pl181.c | 18 ++++++++++-------- hw/pl190.c | 6 ++++-- qemu-log.c | 3 +++ qemu-log.h | 1 + 9 files changed, 44 insertions(+), 25 deletions(-)--
1.7.9.5