diff mbox series

[RFC,3/4] vduse: Add the function for get/free the mapp pages

Message ID 20230628065919.54042-4-lulu@redhat.com (mailing list archive)
State New, archived
Headers show
Series reconnect support in vduse | expand

Commit Message

Cindy Lu June 28, 2023, 6:59 a.m. UTC
From: Your Name <you@example.com>

Add the function for get/free pages, ad this info
will saved in dev->reconnect_info

Signed-off-by: Cindy Lu <lulu@redhat.com>
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 35 ++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

Comments

Jason Wang June 28, 2023, 8:11 a.m. UTC | #1
On Wed, Jun 28, 2023 at 2:59 PM Cindy Lu <lulu@redhat.com> wrote:
>
> From: Your Name <you@example.com>
>
> Add the function for get/free pages, ad this info
> will saved in dev->reconnect_info

I think this should be squashed to patch 2 otherwise it fixes a bug
that is introduced in patch 2?

>
> Signed-off-by: Cindy Lu <lulu@redhat.com>
> ---
>  drivers/vdpa/vdpa_user/vduse_dev.c | 35 ++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>
> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> index 1b833bf0ae37..3df1256eccb4 100644
> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> @@ -1313,6 +1313,35 @@ static struct vduse_dev *vduse_dev_get_from_minor(int minor)
>         return dev;
>  }
>
> +int vduse_get_vq_reconnnect(struct vduse_dev *dev, u16 idx)
> +{
> +       struct vdpa_reconnect_info *area;
> +       void *addr = (void *)get_zeroed_page(GFP_KERNEL);
> +
> +       area = &dev->reconnect_info[idx];
> +
> +       area->addr = virt_to_phys(addr);
> +       area->vaddr = (unsigned long)addr;
> +       area->size = PAGE_SIZE;
> +       area->index = idx;
> +
> +       return 0;
> +}
> +
> +int vduse_free_vq_reconnnect(struct vduse_dev *dev, u16 idx)
> +{
> +       struct vdpa_reconnect_info *area;
> +
> +       area = &dev->reconnect_info[idx];
> +       if ((area->size == PAGE_SIZE) && (area->addr != NULL)) {
> +               free_page(area->vaddr);
> +               area->size = 0;
> +               area->addr = 0;
> +               area->vaddr = 0;
> +       }
> +
> +       return 0;
> +}
>
>  static vm_fault_t vduse_vm_fault(struct vm_fault *vmf)
>  {
> @@ -1446,6 +1475,10 @@ static int vduse_destroy_dev(char *name)
>                 mutex_unlock(&dev->lock);
>                 return -EBUSY;
>         }
> +       for (int i = 0; i < dev->vq_num; i++) {
> +
> +               vduse_free_vq_reconnnect(dev, i);
> +       }
>         dev->connected = true;
>         mutex_unlock(&dev->lock);
>
> @@ -1583,6 +1616,8 @@ static int vduse_create_dev(struct vduse_dev_config *config,
>                 INIT_WORK(&dev->vqs[i].kick, vduse_vq_kick_work);
>                 spin_lock_init(&dev->vqs[i].kick_lock);
>                 spin_lock_init(&dev->vqs[i].irq_lock);
> +
> +               vduse_get_vq_reconnnect(dev, i);

Can we delay the allocated until fault?

Thanks

>         }
>
>         ret = idr_alloc(&vduse_idr, dev, 1, VDUSE_DEV_MAX, GFP_KERNEL);
> --
> 2.34.3
>
Cindy Lu July 1, 2023, 9:16 a.m. UTC | #2
On Wed, Jun 28, 2023 at 4:11 PM Jason Wang <jasowang@redhat.com> wrote:
>
> On Wed, Jun 28, 2023 at 2:59 PM Cindy Lu <lulu@redhat.com> wrote:
> >
> > From: Your Name <you@example.com>
> >
> > Add the function for get/free pages, ad this info
> > will saved in dev->reconnect_info
>
> I think this should be squashed to patch 2 otherwise it fixes a bug
> that is introduced in patch 2?
>
sure will do
> >
> > Signed-off-by: Cindy Lu <lulu@redhat.com>
> > ---
> >  drivers/vdpa/vdpa_user/vduse_dev.c | 35 ++++++++++++++++++++++++++++++
> >  1 file changed, 35 insertions(+)
> >
> > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> > index 1b833bf0ae37..3df1256eccb4 100644
> > --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> > @@ -1313,6 +1313,35 @@ static struct vduse_dev *vduse_dev_get_from_minor(int minor)
> >         return dev;
> >  }
> >
> > +int vduse_get_vq_reconnnect(struct vduse_dev *dev, u16 idx)
> > +{
> > +       struct vdpa_reconnect_info *area;
> > +       void *addr = (void *)get_zeroed_page(GFP_KERNEL);
> > +
> > +       area = &dev->reconnect_info[idx];
> > +
> > +       area->addr = virt_to_phys(addr);
> > +       area->vaddr = (unsigned long)addr;
> > +       area->size = PAGE_SIZE;
> > +       area->index = idx;
> > +
> > +       return 0;
> > +}
> > +
> > +int vduse_free_vq_reconnnect(struct vduse_dev *dev, u16 idx)
> > +{
> > +       struct vdpa_reconnect_info *area;
> > +
> > +       area = &dev->reconnect_info[idx];
> > +       if ((area->size == PAGE_SIZE) && (area->addr != NULL)) {
> > +               free_page(area->vaddr);
> > +               area->size = 0;
> > +               area->addr = 0;
> > +               area->vaddr = 0;
> > +       }
> > +
> > +       return 0;
> > +}
> >
> >  static vm_fault_t vduse_vm_fault(struct vm_fault *vmf)
> >  {
> > @@ -1446,6 +1475,10 @@ static int vduse_destroy_dev(char *name)
> >                 mutex_unlock(&dev->lock);
> >                 return -EBUSY;
> >         }
> > +       for (int i = 0; i < dev->vq_num; i++) {
> > +
> > +               vduse_free_vq_reconnnect(dev, i);
> > +       }
> >         dev->connected = true;
> >         mutex_unlock(&dev->lock);
> >
> > @@ -1583,6 +1616,8 @@ static int vduse_create_dev(struct vduse_dev_config *config,
> >                 INIT_WORK(&dev->vqs[i].kick, vduse_vq_kick_work);
> >                 spin_lock_init(&dev->vqs[i].kick_lock);
> >                 spin_lock_init(&dev->vqs[i].irq_lock);
> > +
> > +               vduse_get_vq_reconnnect(dev, i);
>
> Can we delay the allocated until fault?
>
sure will do
> Thanks
>
> >         }
> >
> >         ret = idr_alloc(&vduse_idr, dev, 1, VDUSE_DEV_MAX, GFP_KERNEL);
> > --
> > 2.34.3
> >
>
diff mbox series

Patch

diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index 1b833bf0ae37..3df1256eccb4 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -1313,6 +1313,35 @@  static struct vduse_dev *vduse_dev_get_from_minor(int minor)
 	return dev;
 }
 
+int vduse_get_vq_reconnnect(struct vduse_dev *dev, u16 idx)
+{
+	struct vdpa_reconnect_info *area;
+	void *addr = (void *)get_zeroed_page(GFP_KERNEL);
+
+	area = &dev->reconnect_info[idx];
+
+	area->addr = virt_to_phys(addr);
+	area->vaddr = (unsigned long)addr;
+	area->size = PAGE_SIZE;
+	area->index = idx;
+
+	return 0;
+}
+
+int vduse_free_vq_reconnnect(struct vduse_dev *dev, u16 idx)
+{
+	struct vdpa_reconnect_info *area;
+
+	area = &dev->reconnect_info[idx];
+	if ((area->size == PAGE_SIZE) && (area->addr != NULL)) {
+		free_page(area->vaddr);
+		area->size = 0;
+		area->addr = 0;
+		area->vaddr = 0;
+	}
+
+	return 0;
+}
 
 static vm_fault_t vduse_vm_fault(struct vm_fault *vmf)
 {
@@ -1446,6 +1475,10 @@  static int vduse_destroy_dev(char *name)
 		mutex_unlock(&dev->lock);
 		return -EBUSY;
 	}
+	for (int i = 0; i < dev->vq_num; i++) {
+
+		vduse_free_vq_reconnnect(dev, i);
+	}
 	dev->connected = true;
 	mutex_unlock(&dev->lock);
 
@@ -1583,6 +1616,8 @@  static int vduse_create_dev(struct vduse_dev_config *config,
 		INIT_WORK(&dev->vqs[i].kick, vduse_vq_kick_work);
 		spin_lock_init(&dev->vqs[i].kick_lock);
 		spin_lock_init(&dev->vqs[i].irq_lock);
+
+		vduse_get_vq_reconnnect(dev, i);
 	}
 
 	ret = idr_alloc(&vduse_idr, dev, 1, VDUSE_DEV_MAX, GFP_KERNEL);