All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] vdpa_sim: Fix incorrect size passed to alloc_iova()
       [not found] <20210809060257.99-1-xieyongji@bytedance.com>
@ 2021-08-09  9:04 ` Stefano Garzarella
       [not found]   ` <CACycT3s9ZKGhXquuVBiOEmEELCMgqVw1no7JpA8_J3maCKKqxA@mail.gmail.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Stefano Garzarella @ 2021-08-09  9:04 UTC (permalink / raw)
  To: Xie Yongji; +Cc: virtualization, mst

On Mon, Aug 09, 2021 at 02:02:57PM +0800, Xie Yongji wrote:
>The size passed to alloc_iova() should be the size of
>page frames to allocate rather than size in bytes.
>
>Fixes: 4080fc106750 ("vdpa_sim: use iova module to allocate IOVA addresses")
>Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
>---
> drivers/vdpa/vdpa_sim/vdpa_sim.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
>index 14e024de5cbf..1ccf615221fe 100644
>--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
>+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
>@@ -137,7 +137,8 @@ static dma_addr_t vdpasim_map_range(struct vdpasim *vdpasim, phys_addr_t paddr,
> 	int ret;
>
> 	/* We set the limit_pfn to the maximum (ULONG_MAX - 1) */
>-	iova = alloc_iova(&vdpasim->iova, size, ULONG_MAX - 1, true);
>+	iova = alloc_iova(&vdpasim->iova, size >> iova_shift(&vdpasim->iova),
>+			  ULONG_MAX - 1, true);
> 	if (!iova)
> 		return DMA_MAPPING_ERROR;
>
>-- 
>2.11.0
>

We invoked init_iova_domain() with granularity = 1, so it should be 
correct to use the size in bytes.

However, in order to avoid future bugs if we change granularity, I agree 
that it's better to use iova_shift():

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

Thanks,
Stefano

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] vdpa_sim: Fix incorrect size passed to alloc_iova()
       [not found]   ` <CACycT3s9ZKGhXquuVBiOEmEELCMgqVw1no7JpA8_J3maCKKqxA@mail.gmail.com>
@ 2021-08-09  9:35     ` Michael S. Tsirkin
  0 siblings, 0 replies; 2+ messages in thread
From: Michael S. Tsirkin @ 2021-08-09  9:35 UTC (permalink / raw)
  To: Yongji Xie; +Cc: virtualization

On Mon, Aug 09, 2021 at 05:18:13PM +0800, Yongji Xie wrote:
> On Mon, Aug 9, 2021 at 5:04 PM Stefano Garzarella <sgarzare@redhat.com> wrote:
> >
> > On Mon, Aug 09, 2021 at 02:02:57PM +0800, Xie Yongji wrote:
> > >The size passed to alloc_iova() should be the size of
> > >page frames to allocate rather than size in bytes.
> > >
> > >Fixes: 4080fc106750 ("vdpa_sim: use iova module to allocate IOVA addresses")
> > >Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
> > >---
> > > drivers/vdpa/vdpa_sim/vdpa_sim.c | 3 ++-
> > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > >diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
> > >index 14e024de5cbf..1ccf615221fe 100644
> > >--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
> > >+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
> > >@@ -137,7 +137,8 @@ static dma_addr_t vdpasim_map_range(struct vdpasim *vdpasim, phys_addr_t paddr,
> > >       int ret;
> > >
> > >       /* We set the limit_pfn to the maximum (ULONG_MAX - 1) */
> > >-      iova = alloc_iova(&vdpasim->iova, size, ULONG_MAX - 1, true);
> > >+      iova = alloc_iova(&vdpasim->iova, size >> iova_shift(&vdpasim->iova),
> > >+                        ULONG_MAX - 1, true);
> > >       if (!iova)
> > >               return DMA_MAPPING_ERROR;
> > >
> > >--
> > >2.11.0
> > >
> >
> > We invoked init_iova_domain() with granularity = 1, so it should be
> > correct to use the size in bytes.
> >
> 
> Oh, yes. I missed the byte granularity.
> 
> Thanks,
> Yongji

Ok pls post with corrected description and dropped Fixes tag.

-- 
MST

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-09  9:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20210809060257.99-1-xieyongji@bytedance.com>
2021-08-09  9:04 ` [PATCH] vdpa_sim: Fix incorrect size passed to alloc_iova() Stefano Garzarella
     [not found]   ` <CACycT3s9ZKGhXquuVBiOEmEELCMgqVw1no7JpA8_J3maCKKqxA@mail.gmail.com>
2021-08-09  9:35     ` Michael S. Tsirkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.