Re: vhost_dev_cleanup() crash: BUG: unable to handle kernel NULLpointer dereference

From: Eric Dumazet
Date: Tue Aug 31 2010 - 08:14:35 EST


Le mardi 31 aoÃt 2010 Ã 13:14 +0200, Ingo Molnar a Ãcrit :
> * Eric Dumazet <eric.dumazet@xxxxxxxxx> wrote:

> >
> > Seems to be commit c23f3445e68e1
> > (vhost: replace vhost_workqueue with per-vhost kthread)
> >
> > following patch should cure it ?
> >
> > Thanks
> >
> > [PATCH] vhost: stop worker only if created
> >
> > Its illegal to call kthread_stop(NULL)
> >
> > Reported-by: Ingo Molnar <mingo@xxxxxxx>
> > Signed-off-by: Eric Dumazet <eric.dumazet@xxxxxxxxx>
> > ---
> > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> > index e05557d..0a00121 100644
> > --- a/drivers/vhost/vhost.c
> > +++ b/drivers/vhost/vhost.c
> > @@ -323,7 +323,8 @@ void vhost_dev_cleanup(struct vhost_dev *dev)
> > dev->mm = NULL;
> >
> > WARN_ON(!list_empty(&dev->work_list));
> > - kthread_stop(dev->worker);
> > + if (dev->worker)
> > + kthread_stop(dev->worker);
>
> Btw., i think this check should be pushed into kthread_stop() instead -
> just like kfree(NULL) is possible as well - it simplifies cleanup
> sequences.
>

Sure !

Just in case, I resubmit the patch, clearing dev->worker, because I am
not sure if vhost_dev_cleanup() can be run several times on same struct
vhost_dev. Patch is needed even if you add this check in kthread_stop()

[PATCH v2] vhost: stop worker only if created

Its currently illegal to call kthread_stop(NULL)

Reported-by: Ingo Molnar <mingo@xxxxxxx>
Signed-off-by: Eric Dumazet <eric.dumazet@xxxxxxxxx>
---
drivers/vhost/vhost.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index e05557d..4b99117 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -323,7 +323,10 @@ void vhost_dev_cleanup(struct vhost_dev *dev)
dev->mm = NULL;

WARN_ON(!list_empty(&dev->work_list));
- kthread_stop(dev->worker);
+ if (dev->worker) {
+ kthread_stop(dev->worker);
+ dev->worker = NULL;
+ }
}

static int log_access_ok(void __user *log_base, u64 addr, unsigned long sz)


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/