From: "Huang\, Ying" <ying.huang@intel.com>
To: Omar Sandoval <osandov@osandov.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
kernel-team@fb.com
Subject: Re: [PATCH] mm: fix nr_rotate_swap leak in swapon() error case
Date: Thu, 17 May 2018 09:40:03 +0800 [thread overview]
Message-ID: <87h8n7xdos.fsf@yhuang-dev.intel.com> (raw)
In-Reply-To: <b6fe6b879f17fa68eee6cbd876f459f6e5e33495.1526491581.git.osandov@fb.com> (Omar Sandoval's message of "Wed, 16 May 2018 10:56:22 -0700")
Omar Sandoval <osandov@osandov.com> writes:
> From: Omar Sandoval <osandov@fb.com>
>
> If swapon() fails after incrementing nr_rotate_swap, we don't decrement
> it and thus effectively leak it. Make sure we decrement it if we
> incremented it.
>
> Fixes: 81a0298bdfab ("mm, swap: don't use VMA based swap readahead if HDD is used as swap")
> Signed-off-by: Omar Sandoval <osandov@fb.com>
Good catch! Thanks!
Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
Best Regards,
Huang, Ying
> ---
> Based on v4.17-rc5.
>
> mm/swapfile.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index cc2cf04d9018..78a015fcec3b 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -3112,6 +3112,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
> unsigned long *frontswap_map = NULL;
> struct page *page = NULL;
> struct inode *inode = NULL;
> + bool inced_nr_rotate_swap = false;
>
> if (swap_flags & ~SWAP_FLAGS_VALID)
> return -EINVAL;
> @@ -3215,8 +3216,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
> cluster = per_cpu_ptr(p->percpu_cluster, cpu);
> cluster_set_null(&cluster->index);
> }
> - } else
> + } else {
> atomic_inc(&nr_rotate_swap);
> + inced_nr_rotate_swap = true;
> + }
>
> error = swap_cgroup_swapon(p->type, maxpages);
> if (error)
> @@ -3307,6 +3310,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
> vfree(swap_map);
> kvfree(cluster_info);
> kvfree(frontswap_map);
> + if (inced_nr_rotate_swap)
> + atomic_dec(&nr_rotate_swap);
> if (swap_file) {
> if (inode && S_ISREG(inode->i_mode)) {
> inode_unlock(inode);
prev parent reply other threads:[~2018-05-17 1:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-16 17:56 [PATCH] mm: fix nr_rotate_swap leak in swapon() error case Omar Sandoval
2018-05-16 18:51 ` Rik van Riel
2018-05-17 1:40 ` Huang, Ying [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h8n7xdos.fsf@yhuang-dev.intel.com \
--to=ying.huang@intel.com \
--cc=akpm@linux-foundation.org \
--cc=kernel-team@fb.com \
--cc=linux-mm@kvack.org \
--cc=osandov@osandov.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.