* [PATCH 0/2] vhost: fix ranges when call vhost_iotlb_itree_first()
@ 2022-11-08 10:34 Stefano Garzarella
2022-11-08 10:34 ` [PATCH 1/2] vringh: fix range used in iotlb_translate() Stefano Garzarella
2022-11-08 10:34 ` [PATCH 2/2] vhost: fix range used in translate_desc() Stefano Garzarella
0 siblings, 2 replies; 7+ messages in thread
From: Stefano Garzarella @ 2022-11-08 10:34 UTC (permalink / raw)
To: virtualization; +Cc: kvm, Michael S. Tsirkin, netdev, linux-kernel
While I was working on vringh to support VA in vringh_*_iotlb()
I saw that the range we use in iotlb_translate() when we call
vhost_iotlb_itree_first() was not correct IIUC.
So I looked at all the calls and found that in vhost.c as well.
I didn't observe a failure and I don't have a reproducer because
I noticed the problem by looking at the code.
Maybe we didn't have a problem, because a shorter range was being
returned anyway and the loop stopped taking into account the total
amount of bytes translated, but I think it's better to fix.
Thanks,
Stefano
Stefano Garzarella (2):
vringh: fix range used in iotlb_translate()
vhost: fix range used in translate_desc()
drivers/vhost/vhost.c | 4 ++--
drivers/vhost/vringh.c | 5 ++---
2 files changed, 4 insertions(+), 5 deletions(-)
--
2.38.1
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] vringh: fix range used in iotlb_translate()
2022-11-08 10:34 [PATCH 0/2] vhost: fix ranges when call vhost_iotlb_itree_first() Stefano Garzarella
@ 2022-11-08 10:34 ` Stefano Garzarella
2022-11-09 3:24 ` Jason Wang
2022-11-08 10:34 ` [PATCH 2/2] vhost: fix range used in translate_desc() Stefano Garzarella
1 sibling, 1 reply; 7+ messages in thread
From: Stefano Garzarella @ 2022-11-08 10:34 UTC (permalink / raw)
To: virtualization; +Cc: kvm, Michael S. Tsirkin, netdev, linux-kernel
vhost_iotlb_itree_first() requires `start` and `last` parameters
to search for a mapping that overlaps the range.
In iotlb_translate() we cyclically call vhost_iotlb_itree_first(),
incrementing `addr` by the amount already translated, so rightly
we move the `start` parameter passed to vhost_iotlb_itree_first(),
but we should hold the `last` parameter constant.
Let's fix it by saving the `last` parameter value before incrementing
`addr` in the loop.
Fixes: 9ad9c49cfe97 ("vringh: IOTLB support")
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
drivers/vhost/vringh.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
index 11f59dd06a74..828c29306565 100644
--- a/drivers/vhost/vringh.c
+++ b/drivers/vhost/vringh.c
@@ -1102,7 +1102,7 @@ static int iotlb_translate(const struct vringh *vrh,
struct vhost_iotlb_map *map;
struct vhost_iotlb *iotlb = vrh->iotlb;
int ret = 0;
- u64 s = 0;
+ u64 s = 0, last = addr + len - 1;
spin_lock(vrh->iotlb_lock);
@@ -1114,8 +1114,7 @@ static int iotlb_translate(const struct vringh *vrh,
break;
}
- map = vhost_iotlb_itree_first(iotlb, addr,
- addr + len - 1);
+ map = vhost_iotlb_itree_first(iotlb, addr, last);
if (!map || map->start > addr) {
ret = -EINVAL;
break;
--
2.38.1
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] vhost: fix range used in translate_desc()
2022-11-08 10:34 [PATCH 0/2] vhost: fix ranges when call vhost_iotlb_itree_first() Stefano Garzarella
2022-11-08 10:34 ` [PATCH 1/2] vringh: fix range used in iotlb_translate() Stefano Garzarella
@ 2022-11-08 10:34 ` Stefano Garzarella
2022-11-09 3:28 ` Jason Wang
1 sibling, 1 reply; 7+ messages in thread
From: Stefano Garzarella @ 2022-11-08 10:34 UTC (permalink / raw)
To: virtualization; +Cc: kvm, Michael S. Tsirkin, netdev, linux-kernel
vhost_iotlb_itree_first() requires `start` and `last` parameters
to search for a mapping that overlaps the range.
In translate_desc() we cyclically call vhost_iotlb_itree_first(),
incrementing `addr` by the amount already translated, so rightly
we move the `start` parameter passed to vhost_iotlb_itree_first(),
but we should hold the `last` parameter constant.
Let's fix it by saving the `last` parameter value before incrementing
`addr` in the loop.
Fixes: 0bbe30668d89 ("vhost: factor out IOTLB")
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
I'm not sure about the fixes tag. On the one I used this patch should
apply cleanly, but looking at the latest stable (4.9), maybe we should
use
Fixes: a9709d6874d5 ("vhost: convert pre sorted vhost memory array to interval tree")
Suggestions?
---
drivers/vhost/vhost.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 40097826cff0..3c2359570df9 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -2053,7 +2053,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
struct vhost_dev *dev = vq->dev;
struct vhost_iotlb *umem = dev->iotlb ? dev->iotlb : dev->umem;
struct iovec *_iov;
- u64 s = 0;
+ u64 s = 0, last = addr + len - 1;
int ret = 0;
while ((u64)len > s) {
@@ -2063,7 +2063,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
break;
}
- map = vhost_iotlb_itree_first(umem, addr, addr + len - 1);
+ map = vhost_iotlb_itree_first(umem, addr, last);
if (map == NULL || map->start > addr) {
if (umem != dev->iotlb) {
ret = -EFAULT;
--
2.38.1
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] vringh: fix range used in iotlb_translate()
2022-11-08 10:34 ` [PATCH 1/2] vringh: fix range used in iotlb_translate() Stefano Garzarella
@ 2022-11-09 3:24 ` Jason Wang
0 siblings, 0 replies; 7+ messages in thread
From: Jason Wang @ 2022-11-09 3:24 UTC (permalink / raw)
To: Stefano Garzarella
Cc: netdev, Michael S. Tsirkin, linux-kernel, kvm, virtualization
On Tue, Nov 8, 2022 at 6:34 PM Stefano Garzarella <sgarzare@redhat.com> wrote:
>
> vhost_iotlb_itree_first() requires `start` and `last` parameters
> to search for a mapping that overlaps the range.
>
> In iotlb_translate() we cyclically call vhost_iotlb_itree_first(),
> incrementing `addr` by the amount already translated, so rightly
> we move the `start` parameter passed to vhost_iotlb_itree_first(),
> but we should hold the `last` parameter constant.
>
> Let's fix it by saving the `last` parameter value before incrementing
> `addr` in the loop.
>
> Fixes: 9ad9c49cfe97 ("vringh: IOTLB support")
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
> ---
> drivers/vhost/vringh.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
> index 11f59dd06a74..828c29306565 100644
> --- a/drivers/vhost/vringh.c
> +++ b/drivers/vhost/vringh.c
> @@ -1102,7 +1102,7 @@ static int iotlb_translate(const struct vringh *vrh,
> struct vhost_iotlb_map *map;
> struct vhost_iotlb *iotlb = vrh->iotlb;
> int ret = 0;
> - u64 s = 0;
> + u64 s = 0, last = addr + len - 1;
>
> spin_lock(vrh->iotlb_lock);
>
> @@ -1114,8 +1114,7 @@ static int iotlb_translate(const struct vringh *vrh,
> break;
> }
>
> - map = vhost_iotlb_itree_first(iotlb, addr,
> - addr + len - 1);
> + map = vhost_iotlb_itree_first(iotlb, addr, last);
> if (!map || map->start > addr) {
> ret = -EINVAL;
> break;
> --
> 2.38.1
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] vhost: fix range used in translate_desc()
2022-11-08 10:34 ` [PATCH 2/2] vhost: fix range used in translate_desc() Stefano Garzarella
@ 2022-11-09 3:28 ` Jason Wang
2022-11-09 8:18 ` Stefano Garzarella
0 siblings, 1 reply; 7+ messages in thread
From: Jason Wang @ 2022-11-09 3:28 UTC (permalink / raw)
To: Stefano Garzarella
Cc: netdev, Michael S. Tsirkin, linux-kernel, kvm, virtualization
On Tue, Nov 8, 2022 at 6:34 PM Stefano Garzarella <sgarzare@redhat.com> wrote:
>
> vhost_iotlb_itree_first() requires `start` and `last` parameters
> to search for a mapping that overlaps the range.
>
> In translate_desc() we cyclically call vhost_iotlb_itree_first(),
> incrementing `addr` by the amount already translated, so rightly
> we move the `start` parameter passed to vhost_iotlb_itree_first(),
> but we should hold the `last` parameter constant.
>
> Let's fix it by saving the `last` parameter value before incrementing
> `addr` in the loop.
>
> Fixes: 0bbe30668d89 ("vhost: factor out IOTLB")
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> ---
>
> I'm not sure about the fixes tag. On the one I used this patch should
> apply cleanly, but looking at the latest stable (4.9), maybe we should
> use
>
> Fixes: a9709d6874d5 ("vhost: convert pre sorted vhost memory array to interval tree")
I think this should be the right commit to fix.
Other than this
Acked-by: Jason Wang <jasowang@redhat.com>
Thanks
>
> Suggestions?
> ---
> drivers/vhost/vhost.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 40097826cff0..3c2359570df9 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -2053,7 +2053,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
> struct vhost_dev *dev = vq->dev;
> struct vhost_iotlb *umem = dev->iotlb ? dev->iotlb : dev->umem;
> struct iovec *_iov;
> - u64 s = 0;
> + u64 s = 0, last = addr + len - 1;
> int ret = 0;
>
> while ((u64)len > s) {
> @@ -2063,7 +2063,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
> break;
> }
>
> - map = vhost_iotlb_itree_first(umem, addr, addr + len - 1);
> + map = vhost_iotlb_itree_first(umem, addr, last);
> if (map == NULL || map->start > addr) {
> if (umem != dev->iotlb) {
> ret = -EFAULT;
> --
> 2.38.1
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] vhost: fix range used in translate_desc()
2022-11-09 3:28 ` Jason Wang
@ 2022-11-09 8:18 ` Stefano Garzarella
2022-11-09 10:10 ` Michael S. Tsirkin
0 siblings, 1 reply; 7+ messages in thread
From: Stefano Garzarella @ 2022-11-09 8:18 UTC (permalink / raw)
To: Jason Wang; +Cc: netdev, Michael S. Tsirkin, linux-kernel, kvm, virtualization
On Wed, Nov 09, 2022 at 11:28:41AM +0800, Jason Wang wrote:
>On Tue, Nov 8, 2022 at 6:34 PM Stefano Garzarella <sgarzare@redhat.com> wrote:
>>
>> vhost_iotlb_itree_first() requires `start` and `last` parameters
>> to search for a mapping that overlaps the range.
>>
>> In translate_desc() we cyclically call vhost_iotlb_itree_first(),
>> incrementing `addr` by the amount already translated, so rightly
>> we move the `start` parameter passed to vhost_iotlb_itree_first(),
>> but we should hold the `last` parameter constant.
>>
>> Let's fix it by saving the `last` parameter value before incrementing
>> `addr` in the loop.
>>
>> Fixes: 0bbe30668d89 ("vhost: factor out IOTLB")
>> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
>> ---
>>
>> I'm not sure about the fixes tag. On the one I used this patch should
>> apply cleanly, but looking at the latest stable (4.9), maybe we should
>> use
>>
>> Fixes: a9709d6874d5 ("vhost: convert pre sorted vhost memory array to interval tree")
>
>I think this should be the right commit to fix.
Yeah, @Michael should I send a v2 with that tag?
>
>Other than this
>
>Acked-by: Jason Wang <jasowang@redhat.com>
>
Thanks for the review,
Stefano
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] vhost: fix range used in translate_desc()
2022-11-09 8:18 ` Stefano Garzarella
@ 2022-11-09 10:10 ` Michael S. Tsirkin
0 siblings, 0 replies; 7+ messages in thread
From: Michael S. Tsirkin @ 2022-11-09 10:10 UTC (permalink / raw)
To: Stefano Garzarella; +Cc: netdev, linux-kernel, kvm, virtualization
On Wed, Nov 09, 2022 at 09:18:23AM +0100, Stefano Garzarella wrote:
> On Wed, Nov 09, 2022 at 11:28:41AM +0800, Jason Wang wrote:
> > On Tue, Nov 8, 2022 at 6:34 PM Stefano Garzarella <sgarzare@redhat.com> wrote:
> > >
> > > vhost_iotlb_itree_first() requires `start` and `last` parameters
> > > to search for a mapping that overlaps the range.
> > >
> > > In translate_desc() we cyclically call vhost_iotlb_itree_first(),
> > > incrementing `addr` by the amount already translated, so rightly
> > > we move the `start` parameter passed to vhost_iotlb_itree_first(),
> > > but we should hold the `last` parameter constant.
> > >
> > > Let's fix it by saving the `last` parameter value before incrementing
> > > `addr` in the loop.
> > >
> > > Fixes: 0bbe30668d89 ("vhost: factor out IOTLB")
> > > Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> > > ---
> > >
> > > I'm not sure about the fixes tag. On the one I used this patch should
> > > apply cleanly, but looking at the latest stable (4.9), maybe we should
> > > use
> > >
> > > Fixes: a9709d6874d5 ("vhost: convert pre sorted vhost memory array to interval tree")
> >
> > I think this should be the right commit to fix.
>
> Yeah, @Michael should I send a v2 with that tag?
Pls do.
> >
> > Other than this
> >
> > Acked-by: Jason Wang <jasowang@redhat.com>
> >
>
> Thanks for the review,
> Stefano
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-11-09 10:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-08 10:34 [PATCH 0/2] vhost: fix ranges when call vhost_iotlb_itree_first() Stefano Garzarella
2022-11-08 10:34 ` [PATCH 1/2] vringh: fix range used in iotlb_translate() Stefano Garzarella
2022-11-09 3:24 ` Jason Wang
2022-11-08 10:34 ` [PATCH 2/2] vhost: fix range used in translate_desc() Stefano Garzarella
2022-11-09 3:28 ` Jason Wang
2022-11-09 8:18 ` Stefano Garzarella
2022-11-09 10:10 ` Michael S. Tsirkin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).