All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory
@ 2017-08-31 23:35 Darrick J. Wong
  2017-08-31 23:41 ` taskboxtester
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Darrick J. Wong @ 2017-08-31 23:35 UTC (permalink / raw)
  To: akpm, ying.huang; +Cc: linux-mm, linux-kernel

If initializing a small swap file fails because the swap file has a
problem (holes, etc.) then we need to free the cluster info as part of
cleanup.  Unfortunately a previous patch changed the code to use
kvzalloc but did not change all the vfree calls to use kvfree.

Found by running generic/357 from xfstests.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 mm/swapfile.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 6ba4aab..c1deb01 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3052,7 +3052,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 	p->flags = 0;
 	spin_unlock(&swap_lock);
 	vfree(swap_map);
-	vfree(cluster_info);
+	kvfree(cluster_info);
 	if (swap_file) {
 		if (inode && S_ISREG(inode->i_mode)) {
 			inode_unlock(inode);

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

* [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory
@ 2017-08-31 23:35 Darrick J. Wong
  2017-08-31 23:41 ` taskboxtester
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Darrick J. Wong @ 2017-08-31 23:35 UTC (permalink / raw)
  To: akpm, ying.huang; +Cc: linux-mm, linux-kernel

If initializing a small swap file fails because the swap file has a
problem (holes, etc.) then we need to free the cluster info as part of
cleanup.  Unfortunately a previous patch changed the code to use
kvzalloc but did not change all the vfree calls to use kvfree.

Found by running generic/357 from xfstests.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 mm/swapfile.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 6ba4aab..c1deb01 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3052,7 +3052,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 	p->flags = 0;
 	spin_unlock(&swap_lock);
 	vfree(swap_map);
-	vfree(cluster_info);
+	kvfree(cluster_info);
 	if (swap_file) {
 		if (inode && S_ISREG(inode->i_mode)) {
 			inode_unlock(inode);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory
  2017-08-31 23:35 [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory Darrick J. Wong
@ 2017-08-31 23:41 ` taskboxtester
  2017-09-01  1:33 ` Huang, Ying
  2017-09-01  8:33 ` David Rientjes
  2 siblings, 0 replies; 9+ messages in thread
From: taskboxtester @ 2017-08-31 23:41 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-mm, linux-kernel, akpm, ying.huang

[-- Attachment #1: Type: text/plain, Size: 980 bytes --]

taskboxtester@gmail.com liked your message with Boxer for Android.


On Aug 31, 2017 7:36 PM, "Darrick J. Wong" <darrick.wong@oracle.com> wrote:

If initializing a small swap file fails because the swap file has a
problem (holes, etc.) then we need to free the cluster info as part of
cleanup.  Unfortunately a previous patch changed the code to use
kvzalloc but did not change all the vfree calls to use kvfree.

Found by running generic/357 from xfstests.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
mm/swapfile.c |    2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 6ba4aab..c1deb01 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3052,7 +3052,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
p->flags = 0;
spin_unlock(&swap_lock);
vfree(swap_map);
-vfree(cluster_info);
+kvfree(cluster_info);
if (swap_file) {
if (inode && S_ISREG(inode->i_mode)) {
inode_unlock(inode);


[-- Attachment #2: Type: text/html, Size: 1556 bytes --]

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

* Re: [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory
  2017-08-31 23:35 [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory Darrick J. Wong
  2017-08-31 23:41 ` taskboxtester
@ 2017-09-01  1:33 ` Huang, Ying
  2017-09-01  8:33 ` David Rientjes
  2 siblings, 0 replies; 9+ messages in thread
From: Huang, Ying @ 2017-09-01  1:33 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: akpm, ying.huang, linux-mm, linux-kernel

"Darrick J. Wong" <darrick.wong@oracle.com> writes:

> If initializing a small swap file fails because the swap file has a
> problem (holes, etc.) then we need to free the cluster info as part of
> cleanup.  Unfortunately a previous patch changed the code to use
> kvzalloc but did not change all the vfree calls to use kvfree.
>
> Found by running generic/357 from xfstests.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Thanks for fixing!

Reviewed-by: "Huang, Ying" <ying.huang@intel.com>

Best Regards,
Huang, Ying

> ---
>  mm/swapfile.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 6ba4aab..c1deb01 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -3052,7 +3052,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
>  	p->flags = 0;
>  	spin_unlock(&swap_lock);
>  	vfree(swap_map);
> -	vfree(cluster_info);
> +	kvfree(cluster_info);
>  	if (swap_file) {
>  		if (inode && S_ISREG(inode->i_mode)) {
>  			inode_unlock(inode);

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

* Re: [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory
@ 2017-09-01  1:33 ` Huang, Ying
  0 siblings, 0 replies; 9+ messages in thread
From: Huang, Ying @ 2017-09-01  1:33 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: akpm, ying.huang, linux-mm, linux-kernel

"Darrick J. Wong" <darrick.wong@oracle.com> writes:

> If initializing a small swap file fails because the swap file has a
> problem (holes, etc.) then we need to free the cluster info as part of
> cleanup.  Unfortunately a previous patch changed the code to use
> kvzalloc but did not change all the vfree calls to use kvfree.
>
> Found by running generic/357 from xfstests.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Thanks for fixing!

Reviewed-by: "Huang, Ying" <ying.huang@intel.com>

Best Regards,
Huang, Ying

> ---
>  mm/swapfile.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 6ba4aab..c1deb01 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -3052,7 +3052,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
>  	p->flags = 0;
>  	spin_unlock(&swap_lock);
>  	vfree(swap_map);
> -	vfree(cluster_info);
> +	kvfree(cluster_info);
>  	if (swap_file) {
>  		if (inode && S_ISREG(inode->i_mode)) {
>  			inode_unlock(inode);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory
  2017-08-31 23:35 [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory Darrick J. Wong
  2017-08-31 23:41 ` taskboxtester
  2017-09-01  1:33 ` Huang, Ying
@ 2017-09-01  8:33 ` David Rientjes
  2017-09-04  0:58   ` Huang, Ying
  2 siblings, 1 reply; 9+ messages in thread
From: David Rientjes @ 2017-09-01  8:33 UTC (permalink / raw)
  To: Andrew Morton, Darrick J. Wong; +Cc: ying.huang, linux-mm, linux-kernel

On Thu, 31 Aug 2017, Darrick J. Wong wrote:

> If initializing a small swap file fails because the swap file has a
> problem (holes, etc.) then we need to free the cluster info as part of
> cleanup.  Unfortunately a previous patch changed the code to use
> kvzalloc but did not change all the vfree calls to use kvfree.
> 

Hopefully this can make it into 4.13.

Fixes: 54f180d3c181 ("mm, swap: use kvzalloc to allocate some swap data structures")
Cc: stable@vger.kernel.org [4.12]

> Found by running generic/357 from xfstests.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Acked-by: David Rientjes <rientjes@google.com>

But I think there's also a memory leak and we need this on top of your 
fix:


mm, swapfile: fix swapon frontswap_map memory leak on error 

Free frontswap_map if an error is encountered before enable_swap_info().

Signed-off-by: David Rientjes <rientjes@google.com>
---
 mm/swapfile.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/swapfile.c b/mm/swapfile.c
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3053,6 +3053,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 	spin_unlock(&swap_lock);
 	vfree(swap_map);
 	kvfree(cluster_info);
+	kvfree(frontswap_map);
 	if (swap_file) {
 		if (inode && S_ISREG(inode->i_mode)) {
 			inode_unlock(inode);

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

* Re: [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory
@ 2017-09-01  8:33 ` David Rientjes
  2017-09-04  0:58   ` Huang, Ying
  0 siblings, 1 reply; 9+ messages in thread
From: David Rientjes @ 2017-09-01  8:33 UTC (permalink / raw)
  To: Andrew Morton, Darrick J. Wong; +Cc: ying.huang, linux-mm, linux-kernel

On Thu, 31 Aug 2017, Darrick J. Wong wrote:

> If initializing a small swap file fails because the swap file has a
> problem (holes, etc.) then we need to free the cluster info as part of
> cleanup.  Unfortunately a previous patch changed the code to use
> kvzalloc but did not change all the vfree calls to use kvfree.
> 

Hopefully this can make it into 4.13.

Fixes: 54f180d3c181 ("mm, swap: use kvzalloc to allocate some swap data structures")
Cc: stable@vger.kernel.org [4.12]

> Found by running generic/357 from xfstests.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Acked-by: David Rientjes <rientjes@google.com>

But I think there's also a memory leak and we need this on top of your 
fix:


mm, swapfile: fix swapon frontswap_map memory leak on error 

Free frontswap_map if an error is encountered before enable_swap_info().

Signed-off-by: David Rientjes <rientjes@google.com>
---
 mm/swapfile.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/swapfile.c b/mm/swapfile.c
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3053,6 +3053,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 	spin_unlock(&swap_lock);
 	vfree(swap_map);
 	kvfree(cluster_info);
+	kvfree(frontswap_map);
 	if (swap_file) {
 		if (inode && S_ISREG(inode->i_mode)) {
 			inode_unlock(inode);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory
  2017-09-01  8:33 ` David Rientjes
@ 2017-09-04  0:58   ` Huang, Ying
  0 siblings, 0 replies; 9+ messages in thread
From: Huang, Ying @ 2017-09-04  0:58 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Darrick J. Wong, ying.huang, linux-mm, linux-kernel

David Rientjes <rientjes@google.com> writes:

> On Thu, 31 Aug 2017, Darrick J. Wong wrote:
>
>> If initializing a small swap file fails because the swap file has a
>> problem (holes, etc.) then we need to free the cluster info as part of
>> cleanup.  Unfortunately a previous patch changed the code to use
>> kvzalloc but did not change all the vfree calls to use kvfree.
>> 
>
> Hopefully this can make it into 4.13.
>
> Fixes: 54f180d3c181 ("mm, swap: use kvzalloc to allocate some swap data structures")
> Cc: stable@vger.kernel.org [4.12]
>
>> Found by running generic/357 from xfstests.
>> 
>> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
>
> Acked-by: David Rientjes <rientjes@google.com>
>
> But I think there's also a memory leak and we need this on top of your 
> fix:
>
>
> mm, swapfile: fix swapon frontswap_map memory leak on error 
>
> Free frontswap_map if an error is encountered before enable_swap_info().
>
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
>  mm/swapfile.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -3053,6 +3053,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
>  	spin_unlock(&swap_lock);
>  	vfree(swap_map);
>  	kvfree(cluster_info);
> +	kvfree(frontswap_map);
>  	if (swap_file) {
>  		if (inode && S_ISREG(inode->i_mode)) {
>  			inode_unlock(inode);

Yes.  There is a memory leak.

Reviewed-by: "Huang, Ying" <ying.huang@intel.com>

Best Regards,
Huang, Ying

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

* Re: [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory
@ 2017-09-04  0:58   ` Huang, Ying
  0 siblings, 0 replies; 9+ messages in thread
From: Huang, Ying @ 2017-09-04  0:58 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Darrick J. Wong, ying.huang, linux-mm, linux-kernel

David Rientjes <rientjes@google.com> writes:

> On Thu, 31 Aug 2017, Darrick J. Wong wrote:
>
>> If initializing a small swap file fails because the swap file has a
>> problem (holes, etc.) then we need to free the cluster info as part of
>> cleanup.  Unfortunately a previous patch changed the code to use
>> kvzalloc but did not change all the vfree calls to use kvfree.
>> 
>
> Hopefully this can make it into 4.13.
>
> Fixes: 54f180d3c181 ("mm, swap: use kvzalloc to allocate some swap data structures")
> Cc: stable@vger.kernel.org [4.12]
>
>> Found by running generic/357 from xfstests.
>> 
>> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
>
> Acked-by: David Rientjes <rientjes@google.com>
>
> But I think there's also a memory leak and we need this on top of your 
> fix:
>
>
> mm, swapfile: fix swapon frontswap_map memory leak on error 
>
> Free frontswap_map if an error is encountered before enable_swap_info().
>
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
>  mm/swapfile.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -3053,6 +3053,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
>  	spin_unlock(&swap_lock);
>  	vfree(swap_map);
>  	kvfree(cluster_info);
> +	kvfree(frontswap_map);
>  	if (swap_file) {
>  		if (inode && S_ISREG(inode->i_mode)) {
>  			inode_unlock(inode);

Yes.  There is a memory leak.

Reviewed-by: "Huang, Ying" <ying.huang@intel.com>

Best Regards,
Huang, Ying

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2017-09-04  0:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-31 23:35 [PATCH] mm: kvfree the swap cluster info if the swap file is unsatisfactory Darrick J. Wong
2017-08-31 23:41 ` taskboxtester
2017-09-01  1:33 ` Huang, Ying
2017-09-01  8:33 ` David Rientjes
2017-09-04  0:58   ` Huang, Ying

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.