linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers/virt/fsl_hypervisor: Correcting error handling path
@ 2020-05-13 20:23 Souptick Joarder
  2020-05-22 11:50 ` Souptick Joarder
  2020-05-22 12:53 ` Dan Carpenter
  0 siblings, 2 replies; 4+ messages in thread
From: Souptick Joarder @ 2020-05-13 20:23 UTC (permalink / raw)
  To: akpm, dan.carpenter, jgg, dsterba, arnd, ira.weiny
  Cc: linux-kernel, Souptick Joarder

First, when memory allocation for sg_list_unaligned failed, there
is no point of calling put_pages() as we haven't pinned any pages.

Second, if get_user_pages_fast() failed we should unpinned num_pinned
pages, no point of checking till num_pages.

This will address both.

Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
---
 drivers/virt/fsl_hypervisor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/virt/fsl_hypervisor.c b/drivers/virt/fsl_hypervisor.c
index 1b0b11b..ea344d7 100644
--- a/drivers/virt/fsl_hypervisor.c
+++ b/drivers/virt/fsl_hypervisor.c
@@ -157,7 +157,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)
 
 	unsigned int i;
 	long ret = 0;
-	int num_pinned; /* return value from get_user_pages() */
+	int num_pinned = 0; /* return value from get_user_pages() */
 	phys_addr_t remote_paddr; /* The next address in the remote buffer */
 	uint32_t count; /* The number of bytes left to copy */
 
@@ -293,7 +293,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)
 
 exit:
 	if (pages) {
-		for (i = 0; i < num_pages; i++)
+		for (i = 0; i < num_pinned; i++)
 			if (pages[i])
 				put_page(pages[i]);
 	}
-- 
1.9.1


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

* Re: [PATCH] drivers/virt/fsl_hypervisor: Correcting error handling path
  2020-05-13 20:23 [PATCH] drivers/virt/fsl_hypervisor: Correcting error handling path Souptick Joarder
@ 2020-05-22 11:50 ` Souptick Joarder
  2020-05-22 12:53 ` Dan Carpenter
  1 sibling, 0 replies; 4+ messages in thread
From: Souptick Joarder @ 2020-05-22 11:50 UTC (permalink / raw)
  To: Andrew Morton, Dan Carpenter, Jason Gunthorpe, dsterba,
	Arnd Bergmann, Ira Weiny
  Cc: linux-kernel

On Thu, May 14, 2020 at 1:45 AM Souptick Joarder <jrdr.linux@gmail.com> wrote:
>
> First, when memory allocation for sg_list_unaligned failed, there
> is no point of calling put_pages() as we haven't pinned any pages.
>
> Second, if get_user_pages_fast() failed we should unpinned num_pinned
> pages, no point of checking till num_pages.
>
> This will address both.

Any comment on this patch ?

>
> Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
> ---
>  drivers/virt/fsl_hypervisor.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/virt/fsl_hypervisor.c b/drivers/virt/fsl_hypervisor.c
> index 1b0b11b..ea344d7 100644
> --- a/drivers/virt/fsl_hypervisor.c
> +++ b/drivers/virt/fsl_hypervisor.c
> @@ -157,7 +157,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)
>
>         unsigned int i;
>         long ret = 0;
> -       int num_pinned; /* return value from get_user_pages() */
> +       int num_pinned = 0; /* return value from get_user_pages() */
>         phys_addr_t remote_paddr; /* The next address in the remote buffer */
>         uint32_t count; /* The number of bytes left to copy */
>
> @@ -293,7 +293,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)
>
>  exit:
>         if (pages) {
> -               for (i = 0; i < num_pages; i++)
> +               for (i = 0; i < num_pinned; i++)
>                         if (pages[i])
>                                 put_page(pages[i]);
>         }
> --
> 1.9.1
>

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

* Re: [PATCH] drivers/virt/fsl_hypervisor: Correcting error handling path
  2020-05-13 20:23 [PATCH] drivers/virt/fsl_hypervisor: Correcting error handling path Souptick Joarder
  2020-05-22 11:50 ` Souptick Joarder
@ 2020-05-22 12:53 ` Dan Carpenter
  2020-05-26  5:13   ` Souptick Joarder
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2020-05-22 12:53 UTC (permalink / raw)
  To: Souptick Joarder, Dan Williams
  Cc: akpm, jgg, dsterba, arnd, ira.weiny, linux-kernel

On Thu, May 14, 2020 at 01:53:16AM +0530, Souptick Joarder wrote:
> First, when memory allocation for sg_list_unaligned failed, there
> is no point of calling put_pages() as we haven't pinned any pages.
> 
> Second, if get_user_pages_fast() failed we should unpinned num_pinned
> pages, no point of checking till num_pages.
> 
> This will address both.
> 
> Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>

If gup_flags were | FOLL_LONGTERM then this patch would fix a double
free because of the put_page() in __gup_longterm_locked().

mm/gup.c
  1786                  if (check_dax_vmas(vmas_tmp, rc)) {
  1787                          for (i = 0; i < rc; i++)
  1788                                  put_page(pages[i]);
                                        ^^^^^^^^^^^^^^^^^^^
put_page() here and also in the caller.

  1789                          rc = -EOPNOTSUPP;
  1790                          goto out;
  1791                  }

But since this isn't FOLL_LONGTERM the patch is a nice cleanup which
doesn't affect run time.

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter


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

* Re: [PATCH] drivers/virt/fsl_hypervisor: Correcting error handling path
  2020-05-22 12:53 ` Dan Carpenter
@ 2020-05-26  5:13   ` Souptick Joarder
  0 siblings, 0 replies; 4+ messages in thread
From: Souptick Joarder @ 2020-05-26  5:13 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Dan Williams, Andrew Morton, Jason Gunthorpe, dsterba,
	Arnd Bergmann, Ira Weiny, linux-kernel

On Fri, May 22, 2020 at 6:24 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> On Thu, May 14, 2020 at 01:53:16AM +0530, Souptick Joarder wrote:
> > First, when memory allocation for sg_list_unaligned failed, there
> > is no point of calling put_pages() as we haven't pinned any pages.
> >
> > Second, if get_user_pages_fast() failed we should unpinned num_pinned
> > pages, no point of checking till num_pages.
> >
> > This will address both.
> >
> > Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
>
> If gup_flags were | FOLL_LONGTERM then this patch would fix a double
> free because of the put_page() in __gup_longterm_locked().
>
> mm/gup.c
>   1786                  if (check_dax_vmas(vmas_tmp, rc)) {
>   1787                          for (i = 0; i < rc; i++)
>   1788                                  put_page(pages[i]);
>                                         ^^^^^^^^^^^^^^^^^^^
> put_page() here and also in the caller.
>
>   1789                          rc = -EOPNOTSUPP;
>   1790                          goto out;
>   1791                  }
>
> But since this isn't FOLL_LONGTERM the patch is a nice cleanup which
> doesn't affect run time.
>
> Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

Hi Andrew,
Is it fine to take it through mm tree ?

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

end of thread, other threads:[~2020-05-26  5:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13 20:23 [PATCH] drivers/virt/fsl_hypervisor: Correcting error handling path Souptick Joarder
2020-05-22 11:50 ` Souptick Joarder
2020-05-22 12:53 ` Dan Carpenter
2020-05-26  5:13   ` Souptick Joarder

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).