From: Mike Rapoport <rppt@linux.vnet.ibm.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: guoxuenan <guoxuenan@huawei.com>,
akpm@linux-foundation.org, minchan@kernel.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
yi.zhang@huawei.com, miaoxie@huawei.com, shli@fb.com,
aarcange@redhat.com, mgorman@techsingularity.net,
kirill.shutemov@linux.intel.com, rientjes@google.com,
khandual@linux.vnet.ibm.com, riel@redhat.com
Subject: Re: [PATCH] mm,madvise: bugfix of madvise systemcall infinite loop under special circumstances.
Date: Mon, 27 Nov 2017 14:42:49 +0200 [thread overview]
Message-ID: <20171127124248.GA10946@rapoport-lnx> (raw)
In-Reply-To: <20171127115847.7b65btmfl762552d@dhcp22.suse.cz>
On Mon, Nov 27, 2017 at 12:58:47PM +0100, Michal Hocko wrote:
> On Mon 27-11-17 19:53:18, guoxuenan wrote:
> > From: chenjie <chenjie6@huawei.com>
> >
> > The madvise() system call supported a set of "conventional" advice values,
> > the MADV_WILLNEED parameter has possibility of triggering an infinite loop under
> > direct access mode(DAX).
> >
> > Infinite loop situation:
> > 1a??initial state [ start = vam->vm_start < vam->vm_end < end ].
> > 2a??madvise_vma() using MADV_WILLNEED parameter;
> > madvise_vma() -> madvise_willneed() -> return 0 && the value of [prev] is not updated.
> >
> > In function SYSCALL_DEFINE3(madvise,...)
> > When [start = vam->vm_start] the program enters "for" loop,
> > find_vma_prev() will set the pointer vma and the pointer prev(prev = vam->vm_prev).
> > Normally ,madvise_vma() will always move the pointer prev ,but when use DAX mode,
> > it will never update the value of [prev].
> >
> > =======================================================================
> > SYSCALL_DEFINE3(madvise,...)
> > {
> > [...]
> > //start = vam->start => prev=vma->prev
> > vma = find_vma_prev(current->mm, start, &prev);
> > [...]
> > for(;;)
> > {
> > update [start = vma->vm_start]
> >
> > con0: if (start >= end) //false always;
> > goto out;
> > tmp = vma->vm_end;
> >
> > //do not update [prev] and always return 0;
> > error = madvise_willneed();
> >
> > con1: if (error) //false always;
> > goto out;
> >
> > //[ vam->vm_start < start = vam->vm_end <end ]
> > update [start = tmp ]
> >
> > con2: if (start >= end) //false always ;
> > goto out;
> >
> > //because of pointer [prev] did not change,[vma] keep as it was;
> > update [ vma = prev->vm_next ]
> > }
> > [...]
> > }
> > =======================================================================
> > After the first cycle ;it will always keep
> > vam->vm_start < start = vam->vm_end < end && vma = prev->vm_next;
> > since Circulation exit conditions (con{0,1,2}) will never meet ,the
> > program stuck in infinite loop.
>
> I find your changelog a bit hard to parse. What would you think about
> the following:
> "
> MADVISE_WILLNEED has always been a noop for DAX (formerly XIP) mappings.
> Unfortunatelly madvise_willneed doesn't communicate this information
> properly to the generic madvise syscall implementation. The calling
> converion is quite subtle there. madvise_vma is supposed to either
spelling: "The calling convention"
> return an error or update &prev otherwise the main loop will never
> advance to the next vma and it will keep looping for ever without a way
> to get out of the kernel.
>
> It seems this has been broken since introduced. Nobody has noticed
> because nobody seems to be using MADVISE_WILLNEED on these DAX mappings.
>
> Fixes: fe77ba6f4f97 ("[PATCH] xip: madvice/fadvice: execute in place")
> Cc: stable
> "
>
> > Signed-off-by: chenjie <chenjie6@huawei.com>
> > Signed-off-by: guoxuenan <guoxuenan@huawei.com>
>
> Other than that
> Acked-by: Michal Hocko <mhocko@suse.com>
>
> > ---
> > mm/madvise.c | 4 +---
> > 1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/mm/madvise.c b/mm/madvise.c
> > index 375cf32..751e97a 100644
> > --- a/mm/madvise.c
> > +++ b/mm/madvise.c
> > @@ -276,15 +276,14 @@ static long madvise_willneed(struct vm_area_struct *vma,
> > {
> > struct file *file = vma->vm_file;
> >
> > + *prev = vma;
> > #ifdef CONFIG_SWAP
> > if (!file) {
> > - *prev = vma;
> > force_swapin_readahead(vma, start, end);
> > return 0;
> > }
> >
> > if (shmem_mapping(file->f_mapping)) {
> > - *prev = vma;
> > force_shm_swapin_readahead(vma, start, end,
> > file->f_mapping);
> > return 0;
> > @@ -299,7 +298,6 @@ static long madvise_willneed(struct vm_area_struct *vma,
> > return 0;
> > }
> >
> > - *prev = vma;
> > start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
> > if (end > vma->vm_end)
> > end = vma->vm_end;
> > --
> > 2.9.5
> >
>
> --
> Michal Hocko
> SUSE Labs
>
--
Sincerely yours,
Mike.
--
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>
next prev parent reply other threads:[~2017-11-27 12:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-27 11:53 guoxuenan
2017-11-27 11:58 ` Michal Hocko
2017-11-27 12:28 ` guoxuenan
2017-11-27 12:42 ` Mike Rapoport [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-11-24 2:27 guoxuenan
2017-11-24 8:05 ` Michal Hocko
[not found] ` <829af987-4d65-382c-dbd4-0c81222ebb51@huawei.com>
[not found] ` <20171124130803.hafb3zbhy7gdqkvi@dhcp22.suse.cz>
2017-11-25 1:52 ` 郭雪楠
2017-11-27 2:54 ` 郭雪楠
2017-11-27 7:59 ` Michal Hocko
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=20171127124248.GA10946@rapoport-lnx \
--to=rppt@linux.vnet.ibm.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=guoxuenan@huawei.com \
--cc=khandual@linux.vnet.ibm.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@kernel.org \
--cc=miaoxie@huawei.com \
--cc=minchan@kernel.org \
--cc=riel@redhat.com \
--cc=rientjes@google.com \
--cc=shli@fb.com \
--cc=yi.zhang@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox