vfio-ccw: Do not read region ret_code after write
PATCH 1/1 vfio-ccw: Do not read region ret_code after write
A pwrite() call returns the number of bytes written (or -1 on error), and vfio-ccw compares this number with the size of the region to determine if an error had occurred or not. If they are equal, the code reads the ret_code field from the region. However, while the kernel sets the ret_code field as necessary, the region and thus this field is not "written back" to the user. So the value can only be what it was initialized to, which is zero.
Not harming anything, but it's a puzzle. Let's avoid the confusion and just set the return code to zero for this case.
--- hw/vfio/ccw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/vfio/ccw.c +3 -3
@@ -106,7 +106,7 @@ again:error_report ("vfio-ccw: write I/O region failed with errno=%d" , errno); ret = -errno; }else { - ret = region->ret_code; + ret =0 ; }switch (ret) {case 0 :
@@ -194,7 +194,7 @@ again:error_report ("vfio-ccw: write cmd region failed with errno=%d" , errno); ret = -errno; }else { - ret = region->ret_code; + ret =0 ; }switch (ret) {case 0 :
@@ -234,7 +234,7 @@ again:error_report ("vfio-ccw: write cmd region failed with errno=%d" , errno); ret = -errno; }else { - ret = region->ret_code; + ret =0 ; }switch (ret) {case 0 :
Signature · 1 line
2.25.1
Quoted 10 lines · On Mon, 1 Mar 2021 20:51:43 +0100 Eric Farman <[email protected]> wrote:
A
pwrite()call returns the number of bytes written (or -1 on error), and vfio-ccw compares this number with the size of the region to determine if an error had occurred or not. If they are equal, the code reads theret_codefield from the region. However, while the kernel sets theret_codefield as necessary, the region and thus this field is not "written back" to the user. So the value can only be what it was initialized to, which is zero.Not harming anything, but it's a puzzle. Let's avoid the confusion and just set the return code to zero for this case.
Yes, ret_code seems to be pretty much useless for us: we don't even look at it when we read the region for interrupt handling. Thankfully, we don't seem to really need it, as we can rely on errno. (Probably worth double checking that this is indeed the case.)
I don't suppose we need to handle a hypothetical broken kernel that returns the wrong size with errno==0?
Quoted 38 lines
Suggested-by Matthew Rosato <[email protected]>Signed-off-by Eric Farman <[email protected]>--- hw/vfio/ccw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)hw/vfio/ccw.c +3
-3@@ -106,7 +106,7 @@ again:error_report ("vfio-ccw: write I/O region failed with errno=%d" , errno); ret = -errno; }else { - ret = region->ret_code; + ret =0 ; }switch (ret) {case 0 :@@ -194,7 +194,7 @@ again:error_report ("vfio-ccw: write cmd region failed with errno=%d" , errno); ret = -errno; }else { - ret = region->ret_code; + ret =0 ; }switch (ret) {case 0 :@@ -234,7 +234,7 @@ again:error_report ("vfio-ccw: write cmd region failed with errno=%d" , errno); ret = -errno; }else { - ret = region->ret_code; + ret =0 ; }switch (ret) {case 0 :
Quoted 11 lines · Cornelia Huck
Quoted 8 lines · On Mon, 1 Mar 2021 20:51:43 +0100 Eric Farman <[email protected]> wrote:
A
pwrite()call returns the number of bytes written (or -1 on error), and vfio-ccw compares this number with the size of the region to determine if an error had occurred or not. If they are equal, the code reads theret_codefield from the region. However, while the kernel sets theret_codefield as necessary, the region and thus this field is not "written back" to the user. So the value can only be what it was initialized to, which is zero.
Quoted 7 lines
Quoted 2 lines
Not harming anything, but it's a puzzle. Let's avoid the confusion and just set the return code to zero for this case.
Yes,
ret_codeseems to be pretty much useless for us: we don't even look at it when we read the region for interrupt handling. Thankfully, we don't seem to really need it, as we can rely on errno. (Probably worth double checking that this is indeed the case.)
I didn't see any scenario on either the kernel or qemu side that made me worried.
Quoted 3 lines
I don't suppose we need to handle a hypothetical broken kernel that returns the wrong size with errno==0?
Well, that would be silly of it. :) But, since I'm in here, sure I can add in some suspenders.
Thanks,
Eric
Quoted 40 lines
Quoted 39 lines
Suggested-by Matthew Rosato <[email protected]>Signed-off-by Eric Farman <[email protected]>--- hw/vfio/ccw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)hw/vfio/ccw.c +3
-3@@ -106,7 +106,7 @@ again:error_report ("vfio-ccw: write I/O region failed with errno=%d" , errno); ret = -errno; }else { - ret = region->ret_code; + ret =0 ; }switch (ret) {case 0 :@@ -194,7 +194,7 @@ again:error_report ("vfio-ccw: write cmd region failed with errno=%d" , errno); ret = -errno; }else { - ret = region->ret_code; + ret =0 ; }switch (ret) {case 0 :@@ -234,7 +234,7 @@ again:error_report ("vfio-ccw: write cmd region failed with errno=%d" , errno); ret = -errno; }else { - ret = region->ret_code; + ret =0 ; }switch (ret) {case 0 :