linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: mawupeng <mawupeng1@huawei.com>
To: <rppt@linux.vnet.ibm.com>, <hughd@google.com>,
	<aarcange@redhat.com>, <hannes@cmpxchg.org>
Cc: <mawupeng1@huawei.com>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>, <wangkefeng.wang@huawei.com>,
	<willy@infradead.org>, <gregkh@linuxfoundation.org>
Subject: Re: [PATCH stable 4.14,4.19 1/1] mm: Fix page counter mismatch in shmem_mfill_atomic_pte
Date: Tue, 16 Aug 2022 11:27:08 +0800	[thread overview]
Message-ID: <09129cd3-7363-3079-bd57-dde9c73684f1@huawei.com> (raw)
In-Reply-To: <20220802013251.3022141-1-mawupeng1@huawei.com>

Cc Greg

On 2022/8/2 9:32, Wupeng Ma wrote:
> From: Ma Wupeng <mawupeng1@huawei.com>
> 
> shmem_mfill_atomic_pte() wrongly called mem_cgroup_cancel_charge() in "success"
> path, it should mem_cgroup_uncharge() to dec memory counter instead.
> mem_cgroup_cancel_charge() should only be used if this transaction is
> unsuccessful and mem_cgroup_uncharge() is used to do this if this transaction
> succeed.
> 
> This will lead to page->memcg not null and will uncharge one more in put_page().
> The page counter will underflow to maximum value and trigger oom to kill all
> process include sshd and leave system unaccessible.
> 
> page->memcg is set in the following path:
> mem_cgroup_commit_charge
> 	commit_charge
> 		page->mem_cgroup = memcg;
> 
> extra uncharge will be done in the following path:
> put_page
> 	__put_page
> 		__put_single_page
> 			mem_cgroup_uncharge
> 				if (!page->mem_cgroup) <-- should return here
> 					return
> 				uncharge_page
> 				uncharge_batch
> 
> To fix this, call mem_cgroup_commit_charge() at the end of this transaction to
> make sure this transaction is really finished.
> 
> Fixes: 4c27fe4c4c84 ("userfaultfd: shmem: add shmem_mcopy_atomic_pte for userfaultfd support")
> Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
> ---
>  mm/shmem.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 0788616696dc..0b06724c189e 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -2339,8 +2339,6 @@ static int shmem_mfill_atomic_pte(struct mm_struct *dst_mm,
>  	if (ret)
>  		goto out_release_uncharge;
>  
> -	mem_cgroup_commit_charge(page, memcg, false, false);
> -
>  	_dst_pte = mk_pte(page, dst_vma->vm_page_prot);
>  	if (dst_vma->vm_flags & VM_WRITE)
>  		_dst_pte = pte_mkwrite(pte_mkdirty(_dst_pte));
> @@ -2366,6 +2364,8 @@ static int shmem_mfill_atomic_pte(struct mm_struct *dst_mm,
>  	if (!pte_none(*dst_pte))
>  		goto out_release_uncharge_unlock;
>  
> +	mem_cgroup_commit_charge(page, memcg, false, false);
> +
>  	lru_cache_add_anon(page);
>  
>  	spin_lock_irq(&info->lock);


  reply	other threads:[~2022-08-16  3:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-02  1:32 Wupeng Ma
2022-08-16  3:27 ` mawupeng [this message]
2022-08-16  5:31   ` Greg KH
2022-08-16  7:04     ` mawupeng
2022-08-16  7:15       ` Greg KH

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=09129cd3-7363-3079-bd57-dde9c73684f1@huawei.com \
    --to=mawupeng1@huawei.com \
    --cc=aarcange@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@linux.vnet.ibm.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=willy@infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox