From: "Michael S. Tsirkin" <mst@redhat.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
Oleg Nesterov <oleg@redhat.com>,
David Rientjes <rientjes@google.com>,
Vladimir Davydov <vdavydov@parallels.com>
Subject: Re: [PATCH 09/10] vhost, mm: make sure that oom_reaper doesn't reap memory read by vhost
Date: Fri, 29 Jul 2016 16:14:10 +0300 [thread overview]
Message-ID: <20160729161039-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20160729060422.GA5504@dhcp22.suse.cz>
On Fri, Jul 29, 2016 at 08:04:22AM +0200, Michal Hocko wrote:
> On Thu 28-07-16 23:41:53, Michael S. Tsirkin wrote:
> > On Thu, Jul 28, 2016 at 09:42:33PM +0200, Michal Hocko wrote:
> [...]
> > > diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
> > > index 349557825428..a327d5362581 100644
> > > --- a/include/linux/uaccess.h
> > > +++ b/include/linux/uaccess.h
> > > @@ -76,6 +76,28 @@ static inline unsigned long __copy_from_user_nocache(void *to,
> > > #endif /* ARCH_HAS_NOCACHE_UACCESS */
> > >
> > > /*
> > > + * A safe variant of __get_user for for use_mm() users to have a
> >
> > for for -> for?
>
> fixed
>
> >
> > > + * gurantee that the address space wasn't reaped in the background
> > > + */
> > > +#define __get_user_mm(mm, x, ptr) \
> > > +({ \
> > > + int ___gu_err = __get_user(x, ptr); \
> >
> > I suspect you need smp_rmb() here to make sure it test does not
> > bypass the memory read.
> >
> > You will accordingly need smp_wmb() when you set the flag,
> > maybe it's there already - I have not checked.
>
> As the comment for setting the flag explains the memory barriers
> shouldn't be really needed AFAIU. More on that below.
>
> [...]
> > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> > > index ca1cc24ba720..6ccf63fbfc72 100644
> > > --- a/mm/oom_kill.c
> > > +++ b/mm/oom_kill.c
> > > @@ -488,6 +488,14 @@ static bool __oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm)
> > > goto unlock_oom;
> > > }
> > >
> > > + /*
> > > + * Tell all users of get_user_mm/copy_from_user_mm that the content
> > > + * is no longer stable. No barriers really needed because unmapping
> > > + * should imply barriers already
> >
> > ok
> >
> > > and the reader would hit a page fault
> > > + * if it stumbled over a reaped memory.
> >
> > This last point I don't get. flag read could bypass data read
> > if that happens data read could happen after unmap
> > yes it might get a PF but you handle that, correct?
>
> The point I've tried to make is that if the reader really page faults
> then get_user will imply the full barrier already. If get_user didn't
> page fault then the state of the flag is not really important because
> the reaper shouldn't have touched it. Does it make more sense now or
> I've missed your question?
Can task flag read happen before the get_user pagefault?
If it does, task flag could not be set even though
page fault triggered.
> >
> > > + */
> > > + set_bit(MMF_UNSTABLE, &mm->flags);
> > > +
> >
> > I would really prefer a callback that vhost would register
> > and stop all accesses. Tell me if you need help on above idea.
>
>
> Well, in order to make callback workable the oom reaper would have to
> synchronize with the said callback until it declares all currently
> ongoing accesses done. That means oom reaper would have to block/wait
> and that is something I would really like to prevent from because it
> just adds another possibility of the lockup (say the get_user cannot
> make forward progress because it is stuck in the page fault allocating
> memory). Or do you see any other way how to implement such a callback
> mechanism without blocking on the oom_reaper side?
I'll think it over and respond.
>
> > But with the above nits addressed,
> > I think this would be acceptable as well.
>
> Thank you for your review and feedback!
> --
> Michal Hocko
> SUSE Labs
--
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:[~2016-07-29 13:14 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-28 19:42 [RFC PATCH 0/10] fortify oom killer even more Michal Hocko
2016-07-28 19:42 ` [PATCH 01/10] mm,oom_reaper: Reduce find_lock_task_mm() usage Michal Hocko
2016-07-28 19:42 ` [PATCH 02/10] mm,oom_reaper: Do not attempt to reap a task twice Michal Hocko
2016-07-28 19:42 ` [PATCH 03/10] oom: keep mm of the killed task available Michal Hocko
2016-07-28 19:42 ` [PATCH 04/10] mm, oom: get rid of signal_struct::oom_victims Michal Hocko
2016-07-28 19:42 ` [PATCH 05/10] kernel, oom: fix potential pgd_lock deadlock from __mmdrop Michal Hocko
2016-07-28 19:42 ` [PATCH 06/10] oom, suspend: fix oom_killer_disable vs. pm suspend properly Michal Hocko
2016-07-28 19:42 ` [PATCH 07/10] mm, oom: enforce exit_oom_victim on current task Michal Hocko
2016-07-28 19:42 ` [PATCH 08/10] exit, oom: postpone exit_oom_victim to later Michal Hocko
2016-07-30 8:20 ` Tetsuo Handa
2016-07-31 9:35 ` Michal Hocko
2016-07-31 10:19 ` Michal Hocko
2016-08-01 10:46 ` Tetsuo Handa
2016-08-01 11:33 ` Michal Hocko
2016-08-02 10:32 ` Tetsuo Handa
2016-08-02 11:31 ` Michal Hocko
2016-07-28 19:42 ` [PATCH 09/10] vhost, mm: make sure that oom_reaper doesn't reap memory read by vhost Michal Hocko
2016-07-28 20:41 ` Michael S. Tsirkin
2016-07-29 6:04 ` Michal Hocko
2016-07-29 13:14 ` Michael S. Tsirkin [this message]
2016-07-29 13:35 ` Michal Hocko
2016-07-29 17:57 ` Michael S. Tsirkin
2016-07-31 9:44 ` Michal Hocko
2016-08-12 9:42 ` Michal Hocko
2016-08-12 13:21 ` Oleg Nesterov
2016-08-12 14:41 ` Michal Hocko
2016-08-12 16:05 ` Oleg Nesterov
2016-08-12 15:57 ` Paul E. McKenney
2016-08-12 16:09 ` Oleg Nesterov
2016-08-12 16:26 ` Paul E. McKenney
2016-08-12 16:23 ` Michal Hocko
2016-08-13 0:15 ` Michael S. Tsirkin
2016-08-14 8:41 ` Michal Hocko
2016-08-14 16:57 ` Michael S. Tsirkin
2016-08-14 23:06 ` Michael S. Tsirkin
2016-08-15 9:49 ` Michal Hocko
2016-08-17 16:58 ` Michal Hocko
2016-08-22 13:03 ` Michal Hocko
2016-08-22 21:01 ` Michael S. Tsirkin
2016-08-23 7:55 ` Michal Hocko
2016-08-23 9:06 ` Michal Hocko
2016-08-23 12:54 ` Michael S. Tsirkin
2016-08-24 16:42 ` Michal Hocko
2016-08-12 9:43 ` Michal Hocko
2016-07-29 17:07 ` Oleg Nesterov
2016-07-31 9:11 ` Michal Hocko
2016-07-28 19:42 ` [PATCH 10/10] oom, oom_reaper: allow to reap mm shared by the kthreads 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=20160729161039-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=oleg@redhat.com \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=rientjes@google.com \
--cc=vdavydov@parallels.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;
as well as URLs for NNTP newsgroup(s).