From: Michal Hocko <mhocko@kernel.org>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Vladimir Davydov <vdavydov@virtuozzo.com>,
Andrew Morton <akpm@linux-foundation.org>,
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
David Rientjes <rientjes@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] exit: clear TIF_MEMDIE after exit_task_work
Date: Tue, 7 Jun 2016 14:50:14 +0200 [thread overview]
Message-ID: <20160607125014.GL12305@dhcp22.suse.cz> (raw)
In-Reply-To: <20160314163943.GE11400@dhcp22.suse.cz>
On Mon 14-03-16 17:39:43, Michal Hocko wrote:
> On Tue 01-03-16 19:20:24, Michael S. Tsirkin wrote:
> > On Tue, Mar 01, 2016 at 06:17:58PM +0100, Michal Hocko wrote:
> [...]
> > > Sorry, I could have been more verbose... The code would have to make sure
> > > that the mm is still alive before calling g-u-p by
> > > atomic_inc_not_zero(&mm->mm_users) and fail if the user count dropped to
> > > 0 in the mean time. See how fs/proc/task_mmu.c does that (proc_mem_open
> > > + m_start + m_stop.
> > >
> > > The biggest advanatage would be that the mm address space pin would be
> > > only for the particular operation. Not sure whether that is possible in
> > > the driver though. Anyway pinning the mm for a potentially unbounded
> > > amount of time doesn't sound too nice.
> >
> > Hmm that would be another atomic on data path ...
> > I'd have to explore that.
>
> Did you have any chance to look into this?
So this is my take to get rid of mm_users pinning for an unbounded
amount of time. This is even not compile tested. I am not sure how to
handle when the mm goes away while there are still work items pending.
It seems this is not handled current anyway and only shouts with a
warning so this shouldn't cause a new regression AFAICS. I am not
familiar with the vnet code at all so I might be missing many things,
though. Does the below sound even remotely reasonable to you Michael?
---
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 669fef1e2bb6..47a3e2c832ea 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -343,7 +343,12 @@ static int vhost_worker(void *data)
if (work) {
__set_current_state(TASK_RUNNING);
+ if (!mmget_not_zero(dev->mm)) {
+ pr_warn("vhost: device owner mm got released unexpectedly\n");
+ break;
+ }
work->fn(work);
+ mmput(dev->mm);
if (need_resched())
schedule();
} else
@@ -481,7 +486,16 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
}
/* No owner, become one */
- dev->mm = get_task_mm(current);
+ task_lock(current);
+ if (current->mm) {
+ dev->mm = current->mm;
+ atomic_inc(&curent->mm->mm_count);
+ }
+ task_unlock(current);
+ if (!dev->mm) {
+ err = -EINVAL;
+ goto err_mm;
+ }
worker = kthread_create(vhost_worker, dev, "vhost-%d", current->pid);
if (IS_ERR(worker)) {
err = PTR_ERR(worker);
@@ -505,7 +519,7 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
dev->worker = NULL;
err_worker:
if (dev->mm)
- mmput(dev->mm);
+ mmdrop(dev->mm);
dev->mm = NULL;
err_mm:
return err;
@@ -583,7 +597,7 @@ void vhost_dev_cleanup(struct vhost_dev *dev, bool locked)
dev->worker = NULL;
}
if (dev->mm)
- mmput(dev->mm);
+ mmdrop(dev->mm);
dev->mm = NULL;
}
EXPORT_SYMBOL_GPL(vhost_dev_cleanup);
--
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-06-07 12:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-29 17:02 [PATCH] exit: clear TIF_MEMDIE after exit_task_work Vladimir Davydov
2016-02-29 18:21 ` Michal Hocko
2016-02-29 18:44 ` Michal Hocko
2016-03-01 15:52 ` Michal Hocko
2016-03-01 15:57 ` Michael S. Tsirkin
2016-03-01 16:08 ` Michal Hocko
2016-03-01 16:14 ` Michael S. Tsirkin
2016-03-01 16:22 ` Michael S. Tsirkin
2016-03-01 16:35 ` Michal Hocko
2016-03-01 16:46 ` Michael S. Tsirkin
2016-03-01 17:17 ` Michal Hocko
2016-03-01 17:20 ` Michael S. Tsirkin
2016-03-14 16:39 ` Michal Hocko
2016-06-07 12:50 ` Michal Hocko [this message]
2016-06-13 11:50 ` Michal Hocko
2016-06-13 13:52 ` Tetsuo Handa
2016-06-13 14:00 ` Michal Hocko
2016-06-13 18:11 ` Michael S. Tsirkin
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=20160607125014.GL12305@dhcp22.suse.cz \
--to=mhocko@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mst@redhat.com \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=rientjes@google.com \
--cc=vdavydov@virtuozzo.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).