Skip to contentSkip to conversation

Initialize ioreq_t in hvmemul_do_io()

PATCH In review Paul Durrant 3 participants 7 messages May 22, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Initialize ioreq_t in hvmemul_do_io()

All relevant fields of the ioreq_t are properly initialized but coverity complains about vp_eport being uninitialized (ID 1215178) because it is the subject of a struct copy in hvm_send_assist_req().

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/emulate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/emulate.c +1 -1
index 904c71a..e516194 100644
@@ -57,7 +57,7 @@ static int hvmemul_do_io(
     int value_is_ptr = (p_data == NULL);
     struct vcpu *curr = current;
     struct hvm_vcpu_io *vio;
-    ioreq_t p;
+    ioreq_t p = { 0 };
     unsigned long ram_gfn = paddr_to_pfn(ram_gpa);
     p2m_type_t p2mt;
     struct page_info *ram_page;
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 22.05.14 at 14:48, <[email protected]> wrote:

All relevant fields of the ioreq_t are properly initialized but coverity complains about vp_eport being uninitialized (ID 1215178) because it is the subject of a struct copy in hvm_send_assist_req().

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/emulate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/emulate.c +0 -0
index 904c71a..e516194 100644

xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 60

Quoted 5 lines
xen/arch/x86/hvm/emulate.c +1 -1
@@ -57,7 +57,7 @@ static int hvmemul_do_io(
     int value_is_ptr = (p_data == NULL);
     struct vcpu *curr = current;
     struct hvm_vcpu_io *vio;
-    ioreq_t p;
+    ioreq_t p = { 0 };

To be honest, I dislike fixes like this to address tool shortcomings. It's not like this is giaramteed to be just a single instruction that gets added (maybe the compiler can figure this, but I would want to rely on it.

If it's known to just be one member, can't that (with a suitable but brief comment) be added to the set of field initializations further down in the function? That would still be code there just to please Coverity, but it would be guaranteed to be a single instruction.

Btw., Andrew, can one identify at build time that a build is done just for Coverity's inspection? If so, rather than a comment a suitable preprocessor conditional might be enough documentation in cases like this.

Jan

#2 lore raw
Quoted 20 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 22 May 2014 14:14
To: Andrew Cooper; Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: Re: [PATCH] Initialize ioreq_t in hvmemul_do_io()

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 22.05.14 at 14:48, <[email protected]> wrote:

All relevant fields of the ioreq_t are properly initialized but coverity complains about vp_eport being uninitialized (ID 1215178) because it is the subject of a struct copy in hvm_send_assist_req().

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/emulate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 60

Quoted 10 lines
xen/arch/x86/hvm/emulate.c +1 -1
index 904c71a..e516194 100644
@@ -57,7 +57,7 @@ static int hvmemul_do_io(
     int value_is_ptr = (p_data == NULL);
     struct vcpu *curr = current;
     struct hvm_vcpu_io *vio;
-    ioreq_t p;
+    ioreq_t p = { 0 };

To be honest, I dislike fixes like this to address tool shortcomings. It's not like this is giaramteed to be just a single instruction that gets added (maybe the compiler can figure this, but I would want to rely on it.

I could always change hvm_send_assist_req() to only copy the relevant fields from the proto structure, as it used to in earlier versions of my patch.

Paul

Quoted 11 lines

If it's known to just be one member, can't that (with a suitable but brief comment) be added to the set of field initializations further down in the function? That would still be code there just to please Coverity, but it would be guaranteed to be a single instruction.

Btw., Andrew, can one identify at build time that a build is done just for Coverity's inspection? If so, rather than a comment a suitable preprocessor conditional might be enough documentation in cases like this.

Jan

#3 lore raw
Quoted 38 lines
Quoted 21 lines
Quoted 1 line · On 22.05.14 at 15:20, <[email protected]> wrote:

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 22 May 2014 14:14
To: Andrew Cooper; Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: Re: [PATCH] Initialize ioreq_t in hvmemul_do_io()

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 22.05.14 at 14:48, <[email protected]> wrote:

All relevant fields of the ioreq_t are properly initialized but coverity complains about vp_eport being uninitialized (ID 1215178) because it is the subject of a struct copy in hvm_send_assist_req().

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/emulate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 60

Quoted 10 lines
xen/arch/x86/hvm/emulate.c +1 -1
index 904c71a..e516194 100644
@@ -57,7 +57,7 @@ static int hvmemul_do_io(
     int value_is_ptr = (p_data == NULL);
     struct vcpu *curr = current;
     struct hvm_vcpu_io *vio;
-    ioreq_t p;
+    ioreq_t p = { 0 };

To be honest, I dislike fixes like this to address tool shortcomings. It's not like this is giaramteed to be just a single instruction that gets added (maybe the compiler can figure this, but I would want to rely on it.

Quoted 2 lines

I could always change hvm_send_assist_req() to only copy the relevant fields from the proto structure, as it used to in earlier versions of my patch.

But the structure copy is certainly more efficient than the piece-wise copying.

Jan

#4 lore raw
Quoted 36 lines · Jan Beulich
Quoted 36 lines
Quoted 36 lines
Quoted 1 line · On 22.05.14 at 15:20, <[email protected]> wrote:

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 22 May 2014 14:14
To: Andrew Cooper; Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: Re: [PATCH] Initialize ioreq_t in hvmemul_do_io()

Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 22.05.14 at 14:48, <[email protected]> wrote:

All relevant fields of the ioreq_t are properly initialized but coverity complains about vp_eport being uninitialized (ID 1215178) because it is the subject of a struct copy in hvm_send_assist_req().

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/emulate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/emulate.c +0 -0
index 904c71a..e516194 100644

xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 60

Quoted 5 lines
xen/arch/x86/hvm/emulate.c +1 -1
@@ -57,7 +57,7 @@ static int hvmemul_do_io(
     int value_is_ptr = (p_data == NULL);
     struct vcpu *curr = current;
     struct hvm_vcpu_io *vio;
-    ioreq_t p;
+    ioreq_t p = { 0 };

To be honest, I dislike fixes like this to address tool shortcomings. It's not like this is giaramteed to be just a single instruction that gets added (maybe the compiler can figure this, but I would want to rely on it.

Quoted 7 lines
Quoted 2 lines

I could always change hvm_send_assist_req() to only copy the relevant fields from the proto structure, as it used to in earlier versions of my patch.

But the structure copy is certainly more efficient than the piece-wise copying.

Jan

When interpreting the coverity results, I accidentally missed the second occurrence of this issue.

It is possible to "goto finished_access" and have p.addr and p.dir uninitialised when tracing the IO.

By far the safest option is just initialise the entire structure to 0.

~Andrew

#5 lore raw
Quoted 51 lines

-----Original Message-----
From: Andrew Cooper
Sent: 22 May 2014 14:47
To: Jan Beulich
Cc: Paul Durrant; [email protected]; Keir (Xen.org)
Subject: Re: [PATCH] Initialize ioreq_t in hvmemul_do_io()

Quoted 21 lines · Jan Beulich
Quoted 21 lines
Quoted 21 lines
Quoted 1 line · On 22.05.14 at 15:20, <[email protected]> wrote:

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 22 May 2014 14:14
To: Andrew Cooper; Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: Re: [PATCH] Initialize ioreq_t in hvmemul_do_io()

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 22.05.14 at 14:48, <[email protected]> wrote:

All relevant fields of the ioreq_t are properly initialized but coverity complains about vp_eport being uninitialized (ID 1215178) because it is the subject of a struct copy in hvm_send_assist_req().

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/emulate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 1 line
Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/xen/arch/x86/hvm/emulate.c

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 60

Quoted 9 lines

index 904c71a..e516194 100644

xen/arch/x86/hvm/emulate.c +1 -1
@@ -57,7 +57,7 @@ static int hvmemul_do_io(
     int value_is_ptr = (p_data == NULL);
     struct vcpu *curr = current;
     struct hvm_vcpu_io *vio;
-    ioreq_t p;
+    ioreq_t p = { 0 };

To be honest, I dislike fixes like this to address tool shortcomings. It's not like this is giaramteed to be just a single instruction that gets added (maybe the compiler can figure this, but I would want to rely on it.

Quoted 1 line
Quoted 1 line

I could always change hvm_send_assist_req() to only copy the relevant

fields

Quoted 4 lines
Quoted 1 line

from the proto structure, as it used to in earlier versions of my patch.

But the structure copy is certainly more efficient than the piece-wise copying.

Quoted 9 lines
Quoted 2 lines

Jan

When interpreting the coverity results, I accidentally missed the second occurrence of this issue.

It is possible to "goto finished_access" and have p.addr and p.dir uninitialised when tracing the IO.

Unfortunately the ioreq passed to hvmtrace_io_assist() is just bogus in this case. I need to fix that too.

Paul

Quoted 3 lines

By far the safest option is just initialise the entire structure to 0.

~Andrew

#6 lore raw
In reply to Andrew Cooper
Quoted 43 lines
Quoted 1 line
Quoted 1 line · On 22.05.14 at 15:47, <[email protected]> wrote:
Quoted 36 lines · Jan Beulich
Quoted 36 lines
Quoted 36 lines
Quoted 1 line · On 22.05.14 at 15:20, <[email protected]> wrote:

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 22 May 2014 14:14
To: Andrew Cooper; Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: Re: [PATCH] Initialize ioreq_t in hvmemul_do_io()

Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 22.05.14 at 14:48, <[email protected]> wrote:

All relevant fields of the ioreq_t are properly initialized but coverity complains about vp_eport being uninitialized (ID 1215178) because it is the subject of a struct copy in hvm_send_assist_req().

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/emulate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/emulate.c +0 -0
index 904c71a..e516194 100644

xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 60

Quoted 5 lines
xen/arch/x86/hvm/emulate.c +1 -1
@@ -57,7 +57,7 @@ static int hvmemul_do_io(
     int value_is_ptr = (p_data == NULL);
     struct vcpu *curr = current;
     struct hvm_vcpu_io *vio;
-    ioreq_t p;
+    ioreq_t p = { 0 };

To be honest, I dislike fixes like this to address tool shortcomings. It's not like this is giaramteed to be just a single instruction that gets added (maybe the compiler can figure this, but I would want to rely on it.

Quoted 4 lines
Quoted 2 lines

I could always change hvm_send_assist_req() to only copy the relevant fields from the proto structure, as it used to in earlier versions of my patch.

But the structure copy is certainly more efficient than the piece-wise copying.

Quoted 7 lines

When interpreting the coverity results, I accidentally missed the second occurrence of this issue.

It is possible to "goto finished_access" and have p.addr and p.dir uninitialised when tracing the IO.

By far the safest option is just initialise the entire structure to 0.

Then the better choice imo is to move as much as possible of the initialization into the initializer. That might even allow cleaning up variables - for example value_is_ptr could clearly be replaced by p.data_is_ptr - and it would reduce the life range of e.g. df.

Jan