drivers/vhost : Removes unnecessary 'else' in vhost_copy_from_user
Subsystems (5)
PATCH 1/1 drivers/vhost : Removes unnecessary 'else' in vhost_copy_from_user
There is no need for this else statement, given that if block will return. This change is not supposed to change the output binary.
It reduces identation level on most lines in this function, and also fixes an split string on vq_err().
--- drivers/vhost/vhost.c | 50 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 26 deletions(-)
drivers/vhost/vhost.c +24 -26
@@ -824,34 +824,32 @@ static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to,if (!vq->iotlb)return __copy_from_user (to, from, size); -else { -/* This function should be called after iotlb -* prefetch, which means we're sure that vq -* could be access through iotlb. So -EAGAIN should -* not happen in this case. -*/ -void __user *uaddr =vhost_vq_meta_fetch (vq, - (u64 )(uintptr_t )from, size, -VHOST_ADDR_DESC ); -struct iov_iter f; -if (uaddr) -return __copy_from_user (to, uaddr, size); +/* This function should be called after iotlb +* prefetch, which means we're sure that vq +* could be access through iotlb. So -EAGAIN should +* not happen in this case. +*/ +void __user *uaddr =vhost_vq_meta_fetch (vq, + (u64 )(uintptr_t )from, size, +VHOST_ADDR_DESC ); +struct iov_iter f; - ret =translate_desc (vq, (u64 )(uintptr_t )from, size, vq->iotlb_iov, -ARRAY_SIZE (vq->iotlb_iov), -VHOST_ACCESS_RO ); -if (ret <0 ) { -vq_err (vq,"IOTLB translation failure: uaddr " -"%p size 0x%llx\n" , from, - (unsigned long long ) size); - goto out; - } -iov_iter_init (&f,READ , vq->iotlb_iov, ret, size); - ret =copy_from_iter (to, size, &f); -if (ret == size) - ret =0 ; - } +if (uaddr) +return __copy_from_user (to, uaddr, size); + + ret =translate_desc (vq, (u64 )(uintptr_t )from, size, vq->iotlb_iov, +ARRAY_SIZE (vq->iotlb_iov), +VHOST_ACCESS_RO ); +if (ret <0 ) { +vq_err (vq,"IOTLB translation failure: uaddr %p size 0x%llx\n" , + from, (unsigned long long )size); + goto out; + } +iov_iter_init (&f,READ , vq->iotlb_iov, ret, size); + ret =copy_from_iter (to, size, &f); +if (ret == size) + ret =0 ; out:return ret;
Signature · 1 line
2.23.0
Quoted 31 lines · Leonardo Bras
There is no need for this else statement, given that if block will return. This change is not supposed to change the output binary.
It reduces identation level on most lines in this function, and also fixes an split string on
vq_err().Signed-off-by Leonardo Bras <[email protected]>--- drivers/vhost/vhost.c | 50 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 26 deletions(-)drivers/vhost/vhost.c +0
-11@@ -824,34 +824,32 @@ static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to,if (!vq->iotlb)return __copy_from_user (to, from, size); -else { -/* This function should be called after iotlb -* prefetch, which means we're sure that vq -* could be access through iotlb. So -EAGAIN should -* not happen in this case. -*/ -void __user *uaddr =vhost_vq_meta_fetch (vq, - (u64 )(uintptr_t )from, size, -VHOST_ADDR_DESC ); -struct iov_iter f; -if (uaddr)
drivers/vhost/vhost.c static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to, · line 836
Quoted 10 lines
drivers/vhost/vhost.c +9
-1-return __copy_from_user (to, uaddr, size); +/* This function should be called after iotlb +* prefetch, which means we're sure that vq +* could be access through iotlb. So -EAGAIN should +* not happen in this case. +*/ +void __user *uaddr =vhost_vq_meta_fetch (vq, + (u64 )(uintptr_t )from, size, +VHOST_ADDR_DESC ); +struct iov_iter f;
I think this will lead at least warnings from compiler.
Generally, I would not bother to make changes like this especially consider it will bring troubles when trying to backporting fixes to downstream in the future.
There're some more interesting things: e.g current metadata IOTLB performance is bad for dynamic mapping since it will be reset each time a new updating is coming.
We can optimize this by only reset the metadata IOTLB when the updating is for metdata.
Want to try this?
Thanks
Quoted 23 lines
drivers/vhost/vhost.c +8
-14- ret =translate_desc (vq, (u64 )(uintptr_t )from, size, vq->iotlb_iov, -ARRAY_SIZE (vq->iotlb_iov), -VHOST_ACCESS_RO ); -if (ret <0 ) { -vq_err (vq,"IOTLB translation failure: uaddr " -"%p size 0x%llx\n" , from, - (unsigned long long ) size); - goto out; - } -iov_iter_init (&f,READ , vq->iotlb_iov, ret, size); - ret =copy_from_iter (to, size, &f); -if (ret == size) - ret =0 ; - } +if (uaddr) +return __copy_from_user (to, uaddr, size); + + ret =translate_desc (vq, (u64 )(uintptr_t )from, size, vq->iotlb_iov, +ARRAY_SIZE (vq->iotlb_iov), +VHOST_ACCESS_RO ); +if (ret <0 ) { + vq_err(vq, "IOTLB translation failure: uaddr %p size 0x%llx\n",
drivers/vhost/vhost.c static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to, · line 855
Quoted 10 lines
drivers/vhost/vhost.c +7
-0+ from, (unsigned long long)size); + goto out; + } +iov_iter_init (&f,READ , vq->iotlb_iov, ret, size); + ret =copy_from_iter (to, size, &f); +if (ret == size) + ret =0 ; out:return ret;
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 31 lines · Leonardo Bras
There is no need for this else statement, given that if block will return. This change is not supposed to change the output binary.
It reduces identation level on most lines in this function, and also fixes an split string on
vq_err().Signed-off-by Leonardo Bras <[email protected]>--- drivers/vhost/vhost.c | 50 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 26 deletions(-)drivers/vhost/vhost.c +0
-11@@ -824,34 +824,32 @@ static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to,if (!vq->iotlb)return __copy_from_user (to, from, size); -else { -/* This function should be called after iotlb -* prefetch, which means we're sure that vq -* could be access through iotlb. So -EAGAIN should -* not happen in this case. -*/ -void __user *uaddr =vhost_vq_meta_fetch (vq, - (u64 )(uintptr_t )from, size, -VHOST_ADDR_DESC ); -struct iov_iter f; -if (uaddr)
drivers/vhost/vhost.c static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to, · line 836
Quoted 10 lines
drivers/vhost/vhost.c +9
-1-return __copy_from_user (to, uaddr, size); +/* This function should be called after iotlb +* prefetch, which means we're sure that vq +* could be access through iotlb. So -EAGAIN should +* not happen in this case. +*/ +void __user *uaddr =vhost_vq_meta_fetch (vq, + (u64 )(uintptr_t )from, size, +VHOST_ADDR_DESC ); +struct iov_iter f;
I think this will lead at least warnings from compiler.
Generally, I would not bother to make changes like this especially consider it will bring troubles when trying to backporting fixes to downstream in the future.
There're some more interesting things: e.g current metadata IOTLB performance is bad for dynamic mapping since it will be reset each time a new updating is coming.
We can optimize this by only reset the metadata IOTLB when the updating is for metdata.
Want to try this?
Thanks
Quoted 33 lines
drivers/vhost/vhost.c +15
-14- ret =translate_desc (vq, (u64 )(uintptr_t )from, size, vq->iotlb_iov, -ARRAY_SIZE (vq->iotlb_iov), -VHOST_ACCESS_RO ); -if (ret <0 ) { -vq_err (vq,"IOTLB translation failure: uaddr " -"%p size 0x%llx\n" , from, - (unsigned long long ) size); - goto out; - } -iov_iter_init (&f,READ , vq->iotlb_iov, ret, size); - ret =copy_from_iter (to, size, &f); -if (ret == size) - ret =0 ; - } +if (uaddr) +return __copy_from_user (to, uaddr, size); + + ret =translate_desc (vq, (u64 )(uintptr_t )from, size, vq->iotlb_iov, +ARRAY_SIZE (vq->iotlb_iov), +VHOST_ACCESS_RO ); +if (ret <0 ) { +vq_err (vq,"IOTLB translation failure: uaddr %p size 0x%llx\n" , + from, (unsigned long long )size); + goto out; + } +iov_iter_init (&f,READ , vq->iotlb_iov, ret, size); + ret =copy_from_iter (to, size, &f); +if (ret == size) + ret =0 ; out:return ret;