KVM: s390: Fix KVM_S390_GET_CMMA_BITS ioctl definition
PATCH 1/1 KVM: s390: Fix KVM_S390_GET_CMMA_BITS ioctl definition
This ioctl actually writes to parameter too.
--- include/uapi/linux/kvm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/kvm.h +1 -1
@@ -1351,7 +1351,7 @@ struct kvm_s390_ucas_mapping {/* Available with KVM_CAP_X86_SMM */ #define KVM_SMI _IO(KVMIO, 0xb7)/* Available with KVM_CAP_S390_CMMA_MIGRATION */ -#define KVM_S390_GET_CMMA_BITS _IOW(KVMIO, 0xb8, struct kvm_s390_cmma_log) +#define KVM_S390_GET_CMMA_BITS _IOWR(KVMIO, 0xb8, struct kvm_s390_cmma_log)#define KVM_S390_SET_CMMA_BITS _IOW(KVMIO, 0xb9, struct kvm_s390_cmma_log)#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
Signature · 1 line
glebfm
Quoted 1 line · Gleb Fotengauer-Malinovskiy
This ioctl actually writes to parameter too.
Maybe rephrase that to:
The kernel does not only read struct kvm_s390_cmma_log for KVM_S390_GET_CMMA_BITS, it also writes back a return value making this _IOWR instead of _IOW.
Quoted 2 lines
Fixes 4036e387 ("KVM: s390: ioctls to get and set guest storage attributes")Signed-off-by Gleb Fotengauer-Malinovskiy <[email protected]>
Out of curiosity, how did you notice that?
Quoted 18 lines
--- include/uapi/linux/kvm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/uapi/linux/kvm.h +1
-1@@ -1351,7 +1351,7 @@ struct kvm_s390_ucas_mapping {/* Available with KVM_CAP_X86_SMM */ #define KVM_SMI _IO(KVMIO, 0xb7)/* Available with KVM_CAP_S390_CMMA_MIGRATION */ -#define KVM_S390_GET_CMMA_BITS _IOW(KVMIO, 0xb8, struct kvm_s390_cmma_log) +#define KVM_S390_GET_CMMA_BITS _IOWR(KVMIO, 0xb8, struct kvm_s390_cmma_log)#define KVM_S390_SET_CMMA_BITS _IOW(KVMIO, 0xb9, struct kvm_s390_cmma_log)#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
PATCH v2 1/1 KVM: s390: Fix KVM_S390_GET_CMMA_BITS ioctl definition
In case of KVM_S390_GET_CMMA_BITS, the kernel does not only read struct kvm_s390_cmma_log passed from userspace (which constitutes _IOC_WRITE), it also writes back a return value (which constitutes _IOC_READ) making this an _IOWR ioctl instead of _IOW.
--- include/uapi/linux/kvm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/kvm.h +1 -1
@@ -1351,7 +1351,7 @@ struct kvm_s390_ucas_mapping {/* Available with KVM_CAP_X86_SMM */ #define KVM_SMI _IO(KVMIO, 0xb7)/* Available with KVM_CAP_S390_CMMA_MIGRATION */ -#define KVM_S390_GET_CMMA_BITS _IOW(KVMIO, 0xb8, struct kvm_s390_cmma_log) +#define KVM_S390_GET_CMMA_BITS _IOWR(KVMIO, 0xb8, struct kvm_s390_cmma_log)#define KVM_S390_SET_CMMA_BITS _IOW(KVMIO, 0xb9, struct kvm_s390_cmma_log)#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
Signature · 1 line
glebfm
Quoted 6 lines · Christian Borntraeger
Quoted 1 line · Gleb Fotengauer-Malinovskiy
This ioctl actually writes to parameter too.
Maybe rephrase that to:
The kernel does not only read structkvm_s390_cmma_logforKVM_S390_GET_CMMA_BITS, it also writes back a return value making this_IOWRinstead of_IOW.
Ok, see v2.
Quoted 6 lines
Quoted 2 lines
Fixes 4036e387 ("KVM: s390: ioctls to get and set guest storage attributes")Signed-off-by Gleb Fotengauer-Malinovskiy <[email protected]>Out of curiosity, how did you notice that?
I regenerated strace's ioctl lists. It was obvious from the diff that *GET* and *SET* could not be both _IOC_WRITE.
Signature · 1 line
glebfm
Quoted 12 lines · Gleb Fotengauer-Malinovskiy
Quoted 6 lines · Christian Borntraeger
Quoted 1 line · Gleb Fotengauer-Malinovskiy
This ioctl actually writes to parameter too.
Maybe rephrase that to:
The kernel does not only read structkvm_s390_cmma_logforKVM_S390_GET_CMMA_BITS, it also writes back a return value making this_IOWRinstead of_IOW.Ok, see v2.
Quoted 2 lines
Quoted 2 lines
Fixes 4036e387 ("KVM: s390: ioctls to get and set guest storage attributes")Signed-off-by Gleb Fotengauer-Malinovskiy <[email protected]>
Quoted 8 lines
Quoted 4 lines
Out of curiosity, how did you notice that?
I regenerated strace's ioctl lists. It was obvious from the diff that *GET* and *SET* could not be both
_IOC_WRITE.
In fact we do have multiple GET/SET ioctls in KVM, where both provide a control block that is _IOC_WRITE only. That control block then has an address that will be read/written to depending on get/set.
E.g. look at
#define KVM_SET_DEVICE_ATTR _IOW(KVMIO, 0xe1, struct kvm_device_attr) #define KVM_GET_DEVICE_ATTR _IOW(KVMIO, 0xe2, struct kvm_device_attr)
but as far as I understand, the direction hints only qualify the referenced struct and not the side effects. So for KVM_*_DEVICE_ATTR it is correct to have IOW for both cases.
But for GET_CMMA we do indeed write back data.
Paolo, Radim,
if we want to fix the direction hint, it would be good to merge this in as soon as possible. The new interface was added during this merge window.
2017-07-11 10:21+0200, Christian Borntraeger:
Quoted 33 lines · Gleb Fotengauer-Malinovskiy
Quoted 12 lines · Christian Borntraeger
Quoted 6 lines · Gleb Fotengauer-Malinovskiy
Quoted 1 line
This ioctl actually writes to parameter too.
Maybe rephrase that to:
The kernel does not only read structkvm_s390_cmma_logforKVM_S390_GET_CMMA_BITS, it also writes back a return value making this_IOWRinstead of_IOW.Ok, see v2.
Quoted 2 lines
Quoted 2 lines
Fixes 4036e387 ("KVM: s390: ioctls to get and set guest storage attributes")Signed-off-by Gleb Fotengauer-Malinovskiy <[email protected]>Quoted 8 lines
Quoted 4 lines
Out of curiosity, how did you notice that?
I regenerated strace's ioctl lists. It was obvious from the diff that *GET* and *SET* could not be both
_IOC_WRITE.In fact we do have multiple GET/SET ioctls in KVM, where both provide a control block that is
_IOC_WRITEonly. That control block then has an address that will be read/written to depending on get/set.
E.g. look at#define KVM_SET_DEVICE_ATTR _IOW(KVMIO, 0xe1, struct kvm_device_attr) #define KVM_GET_DEVICE_ATTR _IOW(KVMIO, 0xe2, struct kvm_device_attr)but as far as I understand, the direction hints only qualify the referenced struct and not the side effects. So for KVM_*_DEVICE_ATTR it is correct to have IOW for both cases.
Quoted 6 lines
But for
GET_CMMAwe do indeed write back data.Paolo, Radim,
if we want to fix the direction hint, it would be good to merge this in as soon as possible. The new interface was added during this merge window.
Having correct hints would allow us to have one common copy_from_user/copy_to_user and I think it's not too late to rename it with the real behavior. Applied for the second merge-window pull request,
thanks.