qxl: don't panic on phys2virt
RFC 1/1 qxl: don't panic on phys2virt
Issues a qxl_guest_bug from qxl_phys2virt. Everywhere else will fail. qxl_phys2virt requires an additional argument because all it's possible return values are legit (well, I could use the fact it returns a pointer so it should be word aligned but I don't want to go there, this is totally internal).
--- hw/qxl-logger.c | 38 +++++++++++++++++++---------- hw/qxl-render.c | 14 +++++++++-- hw/qxl.c | 72 +++++++++++++++++++++++++++++++++++++++++++++---------- hw/qxl.h | 3 ++- 4 files changed, 99 insertions(+), 28 deletions(-)
hw/qxl-logger.c +26 -12
@@ -100,12 +100,16 @@ static const char *qxl_v2n(const char *n[], size_t l, int v) }#define qxl_name (_list, _value) qxl_v2n(_list, ARRAY_SIZE(_list), _value) -static void qxl_log_image (PCIQXLDevice *qxl,QXLPHYSICAL addr,int group_id) +static void qxl_log_image (PCIQXLDevice *qxl,QXLPHYSICAL addr,int group_id, +int *error) {QXLImage *image;QXLImageDescriptor *desc; - image =qxl_phys2virt (qxl, addr, group_id); + image =qxl_phys2virt (qxl, addr, group_id, error); +if (*error) { +return ; + } desc = &image->descriptor;fprintf (stderr," (id %" PRIx64" type %d flags %d width %d height %d" , desc->id, desc->type, desc->flags, desc->width, desc->height);
@@ -130,17 +134,19 @@ static void qxl_log_rect(QXLRect *rect) rect->left, rect->top); } -static void qxl_log_cmd_draw_copy (PCIQXLDevice *qxl,QXLCopy *copy,int group_id) +static void qxl_log_cmd_draw_copy (PCIQXLDevice *qxl,QXLCopy *copy, +int group_id,int *error) {fprintf (stderr," src %" PRIx64, copy->src_bitmap); -qxl_log_image (qxl, copy->src_bitmap, group_id); +qxl_log_image (qxl, copy->src_bitmap, group_id, error);fprintf (stderr," area" );qxl_log_rect (©->src_area);fprintf (stderr," rop %d" , copy->rop_descriptor); } -static void qxl_log_cmd_draw (PCIQXLDevice *qxl,QXLDrawable *draw,int group_id) +static void qxl_log_cmd_draw (PCIQXLDevice *qxl,QXLDrawable *draw,int group_id, +int *error) { fprintf(stderr, ": surface_id %d type %s effect %s", draw->surface_id,
@@ -148,13 +154,13 @@ static void qxl_log_cmd_draw(PCIQXLDevice *qxl, QXLDrawable *draw, int group_id) qxl_name(qxl_draw_effect, draw->effect));switch (draw->type) {case QXL_DRAW_COPY : -qxl_log_cmd_draw_copy (qxl, &draw->u.copy, group_id); +qxl_log_cmd_draw_copy (qxl, &draw->u.copy, group_id, error);break ; } }static void qxl_log_cmd_draw_compat (PCIQXLDevice *qxl,QXLCompatDrawable *draw, -int group_id) +int group_id,int *error) { fprintf(stderr, ": type %s effect %s", qxl_name(qxl_draw_type, draw->type),
@@ -166,7 +172,7 @@ static void qxl_log_cmd_draw_compat(PCIQXLDevice *qxl, QXLCompatDrawable *draw, }switch (draw->type) {case QXL_DRAW_COPY : -qxl_log_cmd_draw_copy (qxl, &draw->u.copy, group_id); +qxl_log_cmd_draw_copy (qxl, &draw->u.copy, group_id, error);break ; } }
@@ -192,6 +198,7 @@ static void qxl_log_cmd_surface(PCIQXLDevice *qxl, QXLSurfaceCmd *cmd)void qxl_log_cmd_cursor (PCIQXLDevice *qxl,QXLCursorCmd *cmd,int group_id) {QXLCursor *cursor; +int error;fprintf (stderr,": %s" ,qxl_name (qxl_cursor_cmd, cmd->type));
@@ -202,7 +209,10 @@ void qxl_log_cmd_cursor(PCIQXLDevice *qxl, QXLCursorCmd *cmd, int group_id) cmd->u.set.position.y, cmd->u.set.visible ?"yes" :"no" , cmd->u.set.shape); - cursor =qxl_phys2virt (qxl, cmd->u.set.shape, group_id); + cursor =qxl_phys2virt (qxl, cmd->u.set.shape, group_id, &error); +if (error) { +return ; + } fprintf(stderr, " type %s size %dx%d hot-spot +%d+%d" " unique 0x%" PRIx64 " data-size %d", qxl_name(spice_cursor_type, cursor->header.type),
@@ -220,6 +230,7 @@ void qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext) {bool compat = ext->flags &QXL_COMMAND_FLAG_COMPAT ;void *data; +int error;if (!qxl->cmdlog) {return ;
@@ -230,13 +241,16 @@ void qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext)qxl_name (qxl_type, ext->cmd.type), compat ? "(compat)" : ""); - data =qxl_phys2virt (qxl, ext->cmd.data, ext->group_id); + data =qxl_phys2virt (qxl, ext->cmd.data, ext->group_id, &error); +if (error) { +return ; + }switch (ext->cmd.type) {case QXL_CMD_DRAW :if (!compat) { -qxl_log_cmd_draw (qxl, data, ext->group_id); +qxl_log_cmd_draw (qxl, data, ext->group_id, &error); }else { -qxl_log_cmd_draw_compat (qxl, data, ext->group_id); +qxl_log_cmd_draw_compat (qxl, data, ext->group_id, &error); }break ;case QXL_CMD_SURFACE :
hw/qxl-render.c +12 -2
@@ -229,10 +229,16 @@ fail:/* called from spice server thread context only */ void qxl_render_cursor (PCIQXLDevice *qxl,QXLCommandExt *ext) { -QXLCursorCmd *cmd =qxl_phys2virt (qxl, ext->cmd.data, ext->group_id); +int error; +QXLCursorCmd *cmd =qxl_phys2virt (qxl, ext->cmd.data, ext->group_id, + &error);QXLCursor *cursor;QEMUCursor *c; +if (error) { +return ; + } +if (!qxl->ssd.ds->mouse_set || !qxl->ssd.ds->cursor_define) {return ; }
@@ -244,7 +250,11 @@ void qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext) }switch (cmd->type) {case QXL_CURSOR_SET : - cursor =qxl_phys2virt (qxl, cmd->u.set.shape, ext->group_id); + cursor =qxl_phys2virt (qxl, cmd->u.set.shape, ext->group_id, + &error); +if (error) { +return ; + }if (cursor->chunk.data_size != cursor->data_size) {fprintf (stderr,"%s: multiple chunks\n" , __FUNCTION__);return ;
hw/qxl.c +59 -13
129 lines not on this page · raw message
hw/qxl.h +2 -1
@@ -126,7 +126,8 @@ typedef struct PCIQXLDevice {#define QXL_DEFAULT_REVISION QXL_REVISION_STABLE_V10/* qxl.c */ -void *qxl_phys2virt (PCIQXLDevice *qxl,QXLPHYSICAL phys,int group_id); +void *qxl_phys2virt (PCIQXLDevice *qxl,QXLPHYSICAL phys,int group_id, +int *error);void qxl_guest_bug (PCIQXLDevice *qxl,const char *msg, ...); void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
Signature · 1 line
1.7.9.3
Quoted 1 line · Alon Levy
Issues a
qxl_guest_bugfromqxl_phys2virt. Everywhere else will fail.
Nice start (there are more guest-triggerable asserts to be fixed this way).
Quoted 4 lines
qxl_phys2virtrequires an additional argument because all it's possible return values are legit (well, I could use the fact it returns a pointer so it should be word aligned but I don't want to go there, this is totally internal).
Really? What is bad with returning and checking for NULL? Guest memslots are backed by guest ram and should never ever resolve to a NULL pointer in qemu's process address space.
cheers,
Gerd
Quoted 5 lines · Gerd Hoffmann
Quoted 1 line · Alon Levy
Issues a
qxl_guest_bugfromqxl_phys2virt. Everywhere else will fail.Nice start (there are more guest-triggerable asserts to be fixed this way).
Quoted 8 lines
Quoted 4 lines
qxl_phys2virtrequires an additional argument because all it's possible return values are legit (well, I could use the fact it returns a pointer so it should be word aligned but I don't want to go there, this is totally internal).Really? What is bad with returning and checking for NULL? Guest memslots are backed by guest ram and should never ever resolve to a NULL pointer in qemu's process address space.
phys2virt actually returns an offset, not a real pointer iirc. I'll check it again.
Quoted 3 lines
cheers,
Gerd