hw/i386/amd_iommu: Fix IOMMU event log encoding errors
PATCH 1/1 hw/i386/amd_iommu: Fix IOMMU event log encoding errors
Coverity issues several UNINIT warnings against AMD IOMMU device [1]. This patch fixes them by initializing the variables. On top of it, this patch changes the event log size to 16 bytes per IOMMU specification. Also the event encoding function incorrectly defines the format of event log entry, which is also fixed.
[1] CID 1487116/1487200/1487190/1487232/1487115/1487258
--- hw/i386/amd_iommu.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
hw/i386/amd_iommu.c +9 -8
@@ -208,8 +208,8 @@ static void amdvi_encode_event(uint64_t *evt, uint16_t devid, uint64_t addr, uint16_t info) {amdvi_setevent_bits (evt, devid,0 ,16 ); -amdvi_setevent_bits (evt, info,55 ,8 ); -amdvi_setevent_bits (evt, addr,63 ,64 ); +amdvi_setevent_bits (evt, info,48 ,16 ); +amdvi_setevent_bits (evt, addr,64 ,64 ); }/* log an error encountered during a page walk *
@@ -218,7 +218,7 @@ static void amdvi_encode_event(uint64_t *evt, uint16_t devid, uint64_t addr,static void amdvi_page_fault (AMDVIState *s,uint16_t devid,hwaddr addr,uint16_t info) { -uint64_t evt[4 ]; +uint64_t evt[2 ] = {0 }; info |=AMDVI_EVENT_IOPF_I |AMDVI_EVENT_IOPF ;amdvi_encode_event (evt, devid, addr, info);
@@ -234,7 +234,7 @@ static void amdvi_page_fault(AMDVIState *s, uint16_t devid,static void amdvi_log_devtab_error (AMDVIState *s,uint16_t devid,hwaddr devtab,uint16_t info) { -uint64_t evt[4 ]; +uint64_t evt[2 ] = {0 }; info |=AMDVI_EVENT_DEV_TAB_HW_ERROR ;
@@ -248,7 +248,8 @@ static void amdvi_log_devtab_error(AMDVIState *s, uint16_t devid,*/ static void amdvi_log_command_error (AMDVIState *s,hwaddr addr) { -uint64_t evt[4 ], info =AMDVI_EVENT_COMMAND_HW_ERROR ; +uint64_t evt[2 ] = {0 }; +uint16_t info =AMDVI_EVENT_COMMAND_HW_ERROR ;amdvi_encode_event (evt,0 , addr, info);amdvi_log_event (s, evt);
@@ -261,7 +262,7 @@ static void amdvi_log_command_error(AMDVIState *s, hwaddr addr)static void amdvi_log_illegalcom_error (AMDVIState *s,uint16_t info,hwaddr addr) { -uint64_t evt[4 ]; +uint64_t evt[2 ] = {0 }; info |=AMDVI_EVENT_ILLEGAL_COMMAND_ERROR ;amdvi_encode_event (evt,0 , addr, info);
@@ -276,7 +277,7 @@ static void amdvi_log_illegalcom_error(AMDVIState *s, uint16_t info,static void amdvi_log_illegaldevtab_error (AMDVIState *s,uint16_t devid,hwaddr addr,uint16_t info) { -uint64_t evt[4 ]; +uint64_t evt[2 ] = {0 }; info |=AMDVI_EVENT_ILLEGAL_DEVTAB_ENTRY ;amdvi_encode_event (evt, devid, addr, info);
@@ -288,7 +289,7 @@ static void amdvi_log_illegaldevtab_error(AMDVIState *s, uint16_t devid,static void amdvi_log_pagetab_error (AMDVIState *s,uint16_t devid,hwaddr addr,uint16_t info) { -uint64_t evt[4 ]; +uint64_t evt[2 ] = {0 }; info |=AMDVI_EVENT_PAGE_TAB_HW_ERROR ;amdvi_encode_event (evt, devid, addr, info);
Signature · 1 line
2.35.1
Quoted 20 lines · Wei Huang
Coverity issues several UNINIT warnings against AMD IOMMU device [1]. This patch fixes them by initializing the variables. On top of it, this patch changes the event log size to 16 bytes per IOMMU specification. Also the event encoding function incorrectly defines the format of event log entry, which is also fixed.
[1] CID 1487116/1487200/1487190/1487232/1487115/1487258
Reported-by Peter Maydell <[email protected]>Signed-off-by Wei Huang <[email protected]>--- hw/i386/amd_iommu.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)hw/i386/amd_iommu.c +0
-0
hw/i386/amd_iommu.c static void amdvi_encode_event(uint64_t *evt, uint16_t devid, uint64_t addr, · line 212
Quoted 7 lines
hw/i386/amd_iommu.c +2
-2@@ -208,8 +208,8 @@ static void amdvi_encode_event(uint64_t *evt, uint16_t devid, uint64_t addr, uint16_t info) {amdvi_setevent_bits (evt, devid,0 ,16 ); -amdvi_setevent_bits (evt, info,55 ,8 ); -amdvi_setevent_bits (evt, addr,63 ,64 ); +amdvi_setevent_bits (evt, info,48 ,16 ); +amdvi_setevent_bits (evt, addr,64 ,64 );
There's a comment just above this function which also needs updating.
Would it be better to have this function start with
evt[0] = 0;
evt[1] = 0;
rather than requiring every caller to zero-initialize the buffer?
thanks
-- PMM
Quoted 16 lines · Peter Maydell
Quoted 15 lines · Wei Huang
Coverity issues several UNINIT warnings against AMD IOMMU device [1]. This patch fixes them by initializing the variables. On top of it, this patch changes the event log size to 16 bytes per IOMMU specification. Also the event encoding function incorrectly defines the format of event log entry, which is also fixed.
[1] CID 1487116/1487200/1487190/1487232/1487115/1487258
Reported-by Peter Maydell <[email protected]>Signed-off-by Wei Huang <[email protected]>--- hw/i386/amd_iommu.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
Quoted 14 lines
hw/i386/amd_iommu.c static void amdvi_encode_event(uint64_t *evt, uint16_t devid, uint64_t addr, · line 212
Quoted 12 lines
hw/i386/amd_iommu.c +2
-2@@ -208,8 +208,8 @@ static void amdvi_encode_event(uint64_t *evt, uint16_t devid, uint64_t addr, uint16_t info) {amdvi_setevent_bits (evt, devid,0 ,16 ); -amdvi_setevent_bits (evt, info,55 ,8 ); -amdvi_setevent_bits (evt, addr,63 ,64 ); +amdvi_setevent_bits (evt, info,48 ,16 ); +amdvi_setevent_bits (evt, addr,64 ,64 );There's a comment just above this function which also needs updating.
Will do.
Quoted 6 lines
Would it be better to have this function start with
evt[0] = 0; evt[1] = 0;rather than requiring every caller to zero-initialize the buffer?
Assuming that Coverity is smart enough to poke one function further for checking UNINIT, I will fix it in the next spin. I will send another rev later today.
Quoted 3 lines
thanks
-- PMM