All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Wood <john.wood@gmx.com>
To: "Valdis Klētnieks" <valdis.kletnieks@vt.edu>
Cc: John Wood <john.wood@gmx.com>, kernelnewbies@kernelnewbies.org
Subject: Re: Read the "real_parent" field of task_struct
Date: Thu, 8 Oct 2020 19:05:02 +0200	[thread overview]
Message-ID: <20201008170502.GA3340@ubuntu> (raw)
In-Reply-To: <20201002165922.GA4200@ubuntu>

Hi,

On Fri, Oct 02, 2020 at 06:59:22PM +0200, John Wood wrote:
>
> static void brute_share_stats(struct brute_stats **src,
> 			      struct brute_stats **dst)
> {
> 	spin_lock(&(*src)->lock);
> 	refcount_inc(&(*src)->refc);
> 	*dst = *src;
> 	spin_unlock(&(*src)->lock);
> }
>
> static int brute_task_alloc(struct task_struct *task, unsigned long clone_flags)
> {
> 	struct task_struct *p_task;
> 	struct brute_stats **stats, **p_stats;
>
> 	p_task = task->real_parent;		/////////// <----
> 	if (unlikely(!p_task))			/////////// <----
> 		return -ESRCH;
>
> 	stats = brute_stats_ptr(task);
> 	p_stats = brute_stats_ptr(p_task);	/////////// <----
>
> 	if (likely(*p_stats)) {
> 		brute_share_stats(p_stats, stats);
> 		return 0;
> 	}
>
> 	*stats = brute_new_stats();
> 	if (!*stats)
> 		return -ENOMEM;
>
> 	brute_share_stats(stats, p_stats);
> 	return 0;
> }
>
> This code is very untested.

Now the code is tested.

> And now my first question: how can I read the
> real_parent field in a secure way. Do I need to use an rcu_read_lock()/
> rcu_read_unlock() block? Do I need to use rcu_dereference? Do I need to
> use a read_lock(&task_list_lock)/read_unlock(&task_list_lock) block?
>
> The lines with the mark are not clear to me. Sorry.

Any help would be greatly appreciated. Thanks in advance.

Regards,
John Wood

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

      reply	other threads:[~2020-10-08 17:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-25 16:11 Read the "real_parent" field of task_struct John Wood
2020-09-30 11:59 ` Valdis Klētnieks
2020-10-01 17:49   ` John Wood
2020-10-02  0:29     ` Valdis Klētnieks
2020-10-02 16:59       ` John Wood
2020-10-08 17:05         ` John Wood [this message]

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=20201008170502.GA3340@ubuntu \
    --to=john.wood@gmx.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=valdis.kletnieks@vt.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.