public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Tejun Heo <tj@kernel.org>
Cc: axboe@kernel.dk, akpm@linux-foundation.org, jack@suse.cz,
	david@fromorbit.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] kthread: implement probe_kthread_data()
Date: Sat, 30 Mar 2013 15:36:00 +0100	[thread overview]
Message-ID: <20130330143600.GA8650@redhat.com> (raw)
In-Reply-To: <1364612447-6810-2-git-send-email-tj@kernel.org>

On 03/29, Tejun Heo wrote:
>
> Implement probe_kthread_data() which returns kthread_data if
> accessible.  The function is equivalent to kthread_data() except that
> the specified @task may not be a kthread
                 ^^^^^^^^^^^^^^^^^^^^^^^^^

This doesn't necessarily mean its ->vfork_done != NULL... but I guess
the "false positive" is fine for your purpose.

> or its vfork_done is already
> cleared rendering struct kthread inaccessible.
> ...

> +/**
> + * probe_kthread_data - speculatively version of kthread_data()
> + * @task: possible kthread task in question
> + *
> + * @task could be a kthread task.  Return the data value specified when it
> + * was created if accessible.  If @task isn't a kthread task or its data is
> + * inaccessible for any reason, %NULL is returned.  This function requires
> + * that @task itself is safe to dereference.
> + */
> +void *probe_kthread_data(struct task_struct *task)
> +{
> +	struct kthread *kthread = to_kthread(task);
> +	void *data = NULL;
> +
> +	probe_kernel_read(&data, &kthread->data, sizeof(data));
> +	return data;
> +}

OK, but we can simply check ->vfork_done != NULL ?

We do not care if we race with the exiting thread which can clear
its ->vfork_done. If it is safe to dereference this @task then
kthread is also safe.

kthread-introduce-to_live_kthread.patch in -mm adds the trivial
helper,

	static inline struct kthread *to_kthread(struct task_struct *k)
	{
	       return __to_kthread(k->vfork_done);
	}

	static struct kthread *to_live_kthread(struct task_struct *k)
	{
	       struct completion *vfork = ACCESS_ONCE(k->vfork_done);
	       if (likely(vfork))
		       return __to_kthread(vfork);
	       return NULL;
	}

So, perhaps,

	voif *kthread_data_safe(struct task_struct *task)
	{
		struct kthread *kthread = to_live_kthread(task);
		return kthread ? kthread->data : NULL;
	}

?

Oleg.


  reply	other threads:[~2013-03-30 14:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-30  3:00 [PATCHSET] workqueue, writeback: better worker information in task dumps Tejun Heo
2013-03-30  3:00 ` [PATCH 1/3] kthread: implement probe_kthread_data() Tejun Heo
2013-03-30 14:36   ` Oleg Nesterov [this message]
2013-03-30 16:17     ` Tejun Heo
2013-03-30 17:00       ` Oleg Nesterov
     [not found]         ` <CAOS58YNMbTY2fZzUXeyLwuA+nowW2AhgLvQwKf_0jWXDen6HzQ@mail.gmail.com>
2013-03-30 19:12           ` Oleg Nesterov
2013-04-03  9:26   ` Jan Kara
2013-03-30  3:00 ` [PATCH 2/3] workqueue: include workqueue info when printing debug dump of a worker task Tejun Heo
2013-03-30  3:00 ` [PATCH 3/3] writeback: set worker desc to identify writeback workers in task dumps Tejun Heo
  -- strict thread matches above, loose matches on Subject: below --
2013-04-03 19:24 [PATCHSET v2] workqueue, writeback: better worker information " Tejun Heo
2013-04-03 19:24 ` [PATCH 1/3] kthread: implement probe_kthread_data() Tejun Heo

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=20130330143600.GA8650@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=david@fromorbit.com \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.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