hw/display/xlnx_dp: Fix memory region size, improve logging
cover hw/display/xlnx_dp: Fix memory region size, improve logging
A collection of cleanup patches written while fuzzing the Xilinx Display Port device.
Philippe Mathieu-Daudé (4):
hw/misc/auxbus: Use qemu_log_mask(UNIMP) instead of debug printf hw/display/dpcd: Fix memory region size hw/display/dpcd: Convert debug printf()s to trace events hw/display/xlnx_dp: Replace disabled DPRINTF() by error_report()
hw/display/dpcd.c | 20 +++++--------------- hw/display/xlnx_dp.c | 14 ++++++++------ hw/misc/auxbus.c | 2 +- hw/display/trace-events | 4 ++++ 4 files changed, 18 insertions(+), 22 deletions(-)
Signature · 1 line
2.21.3
PATCH 1/4 hw/misc/auxbus: Use qemu_log_mask(UNIMP) instead of debug printf
Convert the deprecated DPRINTF() call by qemu_log_mask(LOG_UNIMP).
--- hw/misc/auxbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/auxbus.c +1 -1
@@ -196,7 +196,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address, }break ;default : -DPRINTF ("Not implemented!\n" ); +qemu_log_mask (LOG_UNIMP ,"AUX cmd=%u not implemented\n" , cmd);return AUX_NACK ; }
Signature · 1 line
2.21.3
Re: [PATCH 1/4] hw/misc/auxbus: Use qemu_log_mask(UNIMP) instead of debug printf
Quoted 4 lines · Philippe Mathieu-Daudé
Convert the deprecated
DPRINTF()call byqemu_log_mask(LOG_UNIMP).Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 21 lines
--- hw/misc/auxbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/misc/auxbus.c +1
-2@@ -196,7 +196,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address, }break ;default : -DPRINTF ("Not implemented!\n" ); +qemu_log_mask (LOG_UNIMP ,"AUX cmd=%u not implemented\n" , cmd);return AUX_NACK ; } --2.21.3
PATCH 2/4 hw/display/dpcd: Fix memory region size
In reply to Philippe Mathieu-DaudéThe memory region size is 512K.
--- hw/display/dpcd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/display/dpcd.c +2 -2
@@ -1,5 +1,5 @@/* -* dpcd.c +* Xilinx Display Port Control Data * * Copyright (C) 2015 : GreenSocs Ltd * http://www.greensocs.com/ , email: [email protected]
@@ -137,7 +137,7 @@ static void dpcd_init(Object *obj) {DPCDState *s =DPCD (obj); -memory_region_init_io (&s->iomem, obj, &aux_ops, s,TYPE_DPCD ,0x7FFFF ); +memory_region_init_io (&s->iomem, obj, &aux_ops, s,TYPE_DPCD ,0x80000 );aux_init_mmio (AUX_SLAVE (obj), &s->iomem); }
Signature · 1 line
2.21.3
Re: [PATCH 2/4] hw/display/dpcd: Fix memory region size
Quoted 4 lines · Philippe Mathieu-Daudé
The memory region size is 512K.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 28 lines
--- hw/display/dpcd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/display/dpcd.c +2
-3@@ -1,5 +1,5 @@/* -* dpcd.c +* Xilinx Display Port Control Data * * Copyright (C) 2015 : GreenSocs Ltd * http://www.greensocs.com/ , email: [email protected] @@ -137,7 +137,7 @@ static void dpcd_init(Object *obj) {DPCDState *s =DPCD (obj); -memory_region_init_io (&s->iomem, obj, &aux_ops, s,TYPE_DPCD ,0x7FFFF ); +memory_region_init_io (&s->iomem, obj, &aux_ops, s,TYPE_DPCD ,0x80000 );aux_init_mmio (AUX_SLAVE (obj), &s->iomem); } --2.21.3
PATCH 3/4 hw/display/dpcd: Convert debug printf()s to trace events
In reply to Philippe Mathieu-DaudéConvert DPRINTF() to trace events and remove ifdef'ry.
--- hw/display/dpcd.c | 16 +++------------- hw/display/trace-events | 4 ++++ 2 files changed, 7 insertions(+), 13 deletions(-)
hw/display/dpcd.c +3 -13
@@ -32,16 +32,7 @@#include "hw/misc/auxbus.h" #include "migration/vmstate.h" #include "hw/display/dpcd.h" - -#ifndef DEBUG_DPCD -#define DEBUG_DPCD 0 -#endif - -#define DPRINTF (fmt, ...) do { \ - if (DEBUG_DPCD) { \ - qemu_log("dpcd: " fmt, ## __VA_ARGS__); \ - } \ -} while (0) +#include "trace.h" #define DPCD_READABLE_AREA 0x600
@@ -70,8 +61,8 @@ static uint64_t dpcd_read(void *opaque, hwaddr offset, unsigned size) offset); ret =0 ; } +trace_dpcd_read (offset, ret); -DPRINTF ("read 0x%" PRIX8 " @0x%" HWADDR_PRIX "\n" , ret, offset);return ret; }
@@ -80,8 +71,7 @@ static void dpcd_write(void *opaque, hwaddr offset, uint64_t value, {DPCDState *e =DPCD (opaque); -DPRINTF ("write 0x%" PRIX8 " @0x%" HWADDR_PRIX "\n" , (uint8_t )value, offset); - +trace_dpcd_write (offset, value);if (offset <DPCD_READABLE_AREA ) { e->dpcd_info[offset] = value; }else {
hw/display/trace-events +4 -0
@@ -151,3 +151,7 @@ artist_vram_write(unsigned int size, uint64_t addr, uint64_t val) "%u 0x%"PRIx64 artist_fill_window(unsigned int start_x, unsigned int start_y, unsigned int width, unsigned int height, uint32_t op, uint32_t ctlpln) "start=%ux%u length=%ux%u op=0x%08x ctlpln=0x%08x" artist_block_move(unsigned int start_x, unsigned int start_y, unsigned int dest_x, unsigned int dest_y, unsigned int width, unsigned int height) "source %ux%u -> dest %ux%u size %ux%u" artist_draw_line(unsigned int start_x, unsigned int start_y, unsigned int end_x, unsigned int end_y) "%ux%u %ux%u" + +# dpcd.c +dpcd_read(uint32_t addr, uint8_t val) "read addr:0x%"PRIx32" val:0x%02x" +dpcd_write(uint32_t addr, uint8_t val) "write addr:0x%"PRIx32" val:0x%02x"
Signature · 1 line
2.21.3
Re: [PATCH 3/4] hw/display/dpcd: Convert debug printf()s to trace events
Quoted 4 lines · Philippe Mathieu-Daudé
Convert
DPRINTF()to trace events and remove ifdef'ry.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 63 lines
--- hw/display/dpcd.c | 16 +++------------- hw/display/trace-events | 4 ++++ 2 files changed, 7 insertions(+), 13 deletions(-)hw/display/dpcd.c +3
-13@@ -32,16 +32,7 @@#include "hw/misc/auxbus.h" #include "migration/vmstate.h" #include "hw/display/dpcd.h" - -#ifndef DEBUG_DPCD -#define DEBUG_DPCD 0 -#endif - -#define DPRINTF (fmt, ...) do { \ - if (DEBUG_DPCD) { \ - qemu_log("dpcd: " fmt, ## __VA_ARGS__); \ - } \ -} while (0) +#include "trace.h" #define DPCD_READABLE_AREA 0x600@@ -70,8 +61,8 @@ static uint64_t dpcd_read(void *opaque, hwaddr offset, unsigned size) offset); ret =0 ; } +trace_dpcd_read (offset, ret); -DPRINTF ("read 0x%" PRIX8 " @0x%" HWADDR_PRIX "\n" , ret, offset);return ret; }@@ -80,8 +71,7 @@ static void dpcd_write(void *opaque, hwaddr offset, uint64_t value, {DPCDState *e =DPCD (opaque); -DPRINTF ("write 0x%" PRIX8 " @0x%" HWADDR_PRIX "\n" , (uint8_t )value, offset); - +trace_dpcd_write (offset, value);if (offset <DPCD_READABLE_AREA ) { e->dpcd_info[offset] = value; }else {hw/display/trace-events +4
-1@@ -151,3 +151,7 @@ artist_vram_write(unsigned int size, uint64_t addr, uint64_t val) "%u 0x%"PRIx64 artist_fill_window(unsigned int start_x, unsigned int start_y, unsigned int width, unsigned int height, uint32_t op, uint32_t ctlpln) "start=%ux%u length=%ux%u op=0x%08x ctlpln=0x%08x" artist_block_move(unsigned int start_x, unsigned int start_y, unsigned int dest_x, unsigned int dest_y, unsigned int width, unsigned int height) "source %ux%u -> dest %ux%u size %ux%u" artist_draw_line(unsigned int start_x, unsigned int start_y, unsigned int end_x, unsigned int end_y) "%ux%u %ux%u" + +# dpcd.c +dpcd_read(uint32_t addr, uint8_t val) "read addr:0x%"PRIx32" val:0x%02x" +dpcd_write(uint32_t addr, uint8_t val) "write addr:0x%"PRIx32" val:0x%02x" --2.21.3
PATCH 4/4 hw/display/xlnx_dp: Replace disabled DPRINTF() by error_report()
In reply to Philippe Mathieu-DaudéDPRINTF() calls are disabled by default, so when unexpected data is used, the whole process abort without information.
Display a bit of information with error_report() before crashing.
--- hw/display/xlnx_dp.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
hw/display/xlnx_dp.c +8 -6
@@ -1,5 +1,5 @@/* -* xlnx_dp.c +* Xilinx Display Port * * Copyright (C) 2015 : GreenSocs Ltd * http://www.greensocs.com/ , email: [email protected]
@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "qemu/error-report.h" #include "qemu/log.h" #include "qemu/module.h" #include "hw/display/xlnx_dp.h"
@@ -465,7 +466,7 @@ static uint8_t xlnx_dp_aux_pop_tx_fifo(XlnxDPState *s)uint8_t ret;if (fifo8_is_empty (&s->tx_fifo)) { -DPRINTF ("tx_fifo underflow..\n" ); +error_report ("%s: TX_FIFO underflow" , __func__);abort (); } ret =fifo8_pop (&s->tx_fifo);
@@ -525,6 +526,7 @@ static void xlnx_dp_aux_set_command(XlnxDPState *s, uint32_t value)qemu_log_mask (LOG_UNIMP ,"xlnx_dp: Write i2c status not implemented\n" );break ;default : +error_report ("%s: invalid command: %u" , __func__, cmd);abort (); }
@@ -631,8 +633,8 @@ static void xlnx_dp_change_graphic_fmt(XlnxDPState *s) s->g_plane.format = PIXMAN_b8g8r8;break ;default : -DPRINTF ("error: unsupported graphic format %u.\n" , - s->avbufm_registers[AV_BUF_FORMAT ] &DP_GRAPHIC_MASK ); +error_report ("%s: unsupported graphic format %u" , __func__, + s->avbufm_registers[AV_BUF_FORMAT ] &DP_GRAPHIC_MASK );abort (); }
@@ -647,8 +649,8 @@ static void xlnx_dp_change_graphic_fmt(XlnxDPState *s) s->v_plane.format = PIXMAN_x8b8g8r8;break ;default : -DPRINTF ("error: unsupported video format %u.\n" , - s->avbufm_registers[AV_BUF_FORMAT ] &DP_NL_VID_FMT_MASK ); +error_report ("%s: unsupported video format %u" , __func__, + s->avbufm_registers[AV_BUF_FORMAT ] &DP_NL_VID_FMT_MASK );abort (); }
Signature · 1 line
2.21.3
Re: [PATCH 4/4] hw/display/xlnx_dp: Replace disabled DPRINTF() by error_report()
Quoted 7 lines · Philippe Mathieu-Daudé
DPRINTF()calls are disabled by default, so when unexpected data is used, the whole process abort without information.Display a bit of information with
error_report()before crashing.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 66 lines
--- hw/display/xlnx_dp.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)hw/display/xlnx_dp.c +8
-7@@ -1,5 +1,5 @@/* -* xlnx_dp.c +* Xilinx Display Port * * Copyright (C) 2015 : GreenSocs Ltd * http://www.greensocs.com/ , email: [email protected] @@ -24,6 +24,7 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "qemu/error-report.h" #include "qemu/log.h" #include "qemu/module.h" #include "hw/display/xlnx_dp.h" @@ -465,7 +466,7 @@ static uint8_t xlnx_dp_aux_pop_tx_fifo(XlnxDPState *s)uint8_t ret;if (fifo8_is_empty (&s->tx_fifo)) { -DPRINTF ("tx_fifo underflow..\n" ); +error_report ("%s: TX_FIFO underflow" , __func__);abort (); } ret =fifo8_pop (&s->tx_fifo);@@ -525,6 +526,7 @@ static void xlnx_dp_aux_set_command(XlnxDPState *s, uint32_t value)qemu_log_mask (LOG_UNIMP ,"xlnx_dp: Write i2c status not implemented\n" );break ;default : +error_report ("%s: invalid command: %u" , __func__, cmd);abort (); }@@ -631,8 +633,8 @@ static void xlnx_dp_change_graphic_fmt(XlnxDPState *s) s->g_plane.format = PIXMAN_b8g8r8;break ;default : -DPRINTF ("error: unsupported graphic format %u.\n" , - s->avbufm_registers[AV_BUF_FORMAT ] &DP_GRAPHIC_MASK ); +error_report ("%s: unsupported graphic format %u" , __func__, + s->avbufm_registers[AV_BUF_FORMAT ] &DP_GRAPHIC_MASK );abort (); }@@ -647,8 +649,8 @@ static void xlnx_dp_change_graphic_fmt(XlnxDPState *s) s->v_plane.format = PIXMAN_x8b8g8r8;break ;default : -DPRINTF ("error: unsupported video format %u.\n" , - s->avbufm_registers[AV_BUF_FORMAT ] &DP_NL_VID_FMT_MASK ); +error_report ("%s: unsupported video format %u" , __func__, + s->avbufm_registers[AV_BUF_FORMAT ] &DP_NL_VID_FMT_MASK );abort (); } --2.21.3