[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 7/8] vfio-ccw: Do not read region ret_code after write
From: |
Cornelia Huck |
Subject: |
[PULL 7/8] vfio-ccw: Do not read region ret_code after write |
Date: |
Fri, 5 Mar 2021 16:55:16 +0100 |
From: Eric Farman <farman@linux.ibm.com>
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 not equal, this is a failure and the errno is used to
determine exactly how things failed. An errno of zero is possible
(though unlikely) in this situation and would be translated to a
successful operation.
If they ARE equal, the ret_code field is read from the region to
determine how to proceed. 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.
So, let's convert an unexpected length with errno of zero to a
return code of -EFAULT, and explicitly set an expected length to
a return code of zero. This will be a little safer and clearer.
Suggested-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Eric Farman <farman@linux.ibm.com>
Message-Id: <20210303160739.2179378-1-farman@linux.ibm.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
---
hw/vfio/ccw.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index bc78a0ad7638..b2df708e4b01 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -104,9 +104,9 @@ again:
goto again;
}
error_report("vfio-ccw: write I/O region failed with errno=%d", errno);
- ret = -errno;
+ ret = errno ? -errno : -EFAULT;
} else {
- ret = region->ret_code;
+ ret = 0;
}
switch (ret) {
case 0:
@@ -192,9 +192,9 @@ again:
goto again;
}
error_report("vfio-ccw: write cmd region failed with errno=%d", errno);
- ret = -errno;
+ ret = errno ? -errno : -EFAULT;
} else {
- ret = region->ret_code;
+ ret = 0;
}
switch (ret) {
case 0:
@@ -232,9 +232,9 @@ again:
goto again;
}
error_report("vfio-ccw: write cmd region failed with errno=%d", errno);
- ret = -errno;
+ ret = errno ? -errno : -EFAULT;
} else {
- ret = region->ret_code;
+ ret = 0;
}
switch (ret) {
case 0:
--
2.26.2
- [PULL 0/8] s390x update, Cornelia Huck, 2021/03/05
- [PULL 1/8] s390x/cpu_model: disallow unpack for --only-migratable, Cornelia Huck, 2021/03/05
- [PULL 3/8] hw/s390x: fix build for virtio-9p-ccw, Cornelia Huck, 2021/03/05
- [PULL 2/8] target/s390x/arch_dump: Fix warning for the name field in the PT_NOTE section, Cornelia Huck, 2021/03/05
- [PULL 4/8] s390x/pci: restore missing Query PCI Function CLP data, Cornelia Huck, 2021/03/05
- [PULL 5/8] virtio-ccw: commands on revision-less devices, Cornelia Huck, 2021/03/05
- [PULL 7/8] vfio-ccw: Do not read region ret_code after write,
Cornelia Huck <=
- [PULL 8/8] target/s390x/kvm: Simplify debug code, Cornelia Huck, 2021/03/05
- [PULL 6/8] css: SCHIB measurement block origin must be aligned, Cornelia Huck, 2021/03/05
- Re: [PULL 0/8] s390x update, Peter Maydell, 2021/03/05