[Mesa-dev] [PATCH 6/7] intel: decoder: don't read qword outside the limit of the instruction/struct

Lionel Landwerlin lionel.g.landwerlin at intel.com
Thu Aug 3 14:37:44 UTC 2017


We used to print invalid data when the last field what clamped to
32bits due to Dword Length of the whole instruction :

0x000ce0b4:  0x10000002:  MI_STORE_DATA_IMM
0x000ce0b4:  0x10000002 : Dword 0
    DWord Length: 2
    Store Qword: 0
    Use Global GTT: false
0x000ce0b8:  0x00045010 : Dword 1
    Core Mode Enable: 0
    Address: 0x00045010
0x000ce0bc:  0x00000000 : Dword 2
0x000ce0c0:  0x00000000 : Dword 3
    Immediate Data: 8791026489807077376

With this change we have the proper value :

0x000ce0b4:  0x10000002:  MI_STORE_DATA_IMM (4 Dwords)
0x000ce0b4:  0x10000002 : Dword 0
    DWord Length: 2
    Store Qword: 0
    Use Global GTT: false
0x000ce0b8:  0x00045010 : Dword 1
    Core Mode Enable: 0
    Address: 0x00045010
0x000ce0bc:  0x00000000 : Dword 2
0x000ce0c0:  0x00000000 : Dword 3
    Immediate Data: 0

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
 src/intel/common/gen_decoder.c | 11 ++++++++---
 src/intel/common/gen_decoder.h |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/intel/common/gen_decoder.c b/src/intel/common/gen_decoder.c
index 61ecf2eb392..ee05afb1051 100644
--- a/src/intel/common/gen_decoder.c
+++ b/src/intel/common/gen_decoder.c
@@ -855,9 +855,13 @@ gen_field_decode(struct gen_field_iterator *iter)
    else
       memset(iter->name, 0, sizeof(iter->name));
 
-   if ((iter->field->end - iter->field->start) > 32)
-      v.qw = ((uint64_t) iter->p[iter->dword+1] << 32) | iter->p[iter->dword];
-   else
+   memset(&v, 0, sizeof(v));
+
+   if ((iter->field->end - iter->field->start) > 32) {
+      if (&iter->p[iter->dword + 1] < iter->end)
+         v.qw = ((uint64_t) iter->p[iter->dword+1] << 32);
+      v.qw |= iter->p[iter->dword];
+   } else
       v.qw = iter->p[iter->dword];
 
    const char *enum_name = NULL;
@@ -946,6 +950,7 @@ gen_field_iterator_init(struct gen_field_iterator *iter,
    else
       iter->field = group->next->fields;
    iter->p = p;
+   iter->end = &p[gen_group_get_length(iter->group, iter->p)];
    iter->print_colors = print_colors;
 
    gen_field_decode(iter);
diff --git a/src/intel/common/gen_decoder.h b/src/intel/common/gen_decoder.h
index 2f05104178e..7bf8d433bc1 100644
--- a/src/intel/common/gen_decoder.h
+++ b/src/intel/common/gen_decoder.h
@@ -57,6 +57,7 @@ struct gen_field_iterator {
    char value[128];
    struct gen_group *struct_desc;
    const uint32_t *p;
+   const uint32_t *end;
    int dword; /**< current field starts at &p[dword] */
 
    int group_iter;
-- 
2.13.3



More information about the mesa-dev mailing list