All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leonid Yegoshin <Leonid.Yegoshin@imgtec.com>
To: Paul Burton <paul.burton@imgtec.com>, <linux-mips@linux-mips.org>
Cc: Matthew Fortune <matthew.fortune@imgtec.com>,
	Markos Chandras <markos.chandras@imgtec.com>
Subject: Re: MIPS,prctl: add PR_[GS]ET_FP_MODE prctl options for MIPS
Date: Thu, 8 Jan 2015 18:25:48 -0800	[thread overview]
Message-ID: <54AF3C2C.7040807@imgtec.com> (raw)
In-Reply-To: <1420719457-690-1-git-send-email-paul.burton@imgtec.com>

> +	/* Prevent any threads from obtaining live FP context */
> +	atomic_set(&task->mm->context.fp_mode_switching, 1);
> +	smp_mb__after_atomic();
> +
> +	/*
> +	 * If there are multiple online CPUs then wait until all threads whose
> +	 * FP mode is about to change have been context switched. This approach
> +	 * allows us to only worry about whether an FP mode switch is in
> +	 * progress when FP is first used in a tasks time slice. Pretty much all
> +	 * of the mode switch overhead can thus be confined to cases where mode
> +	 * switches are actually occuring. That is, to here. However for the
> +	 * thread performing the mode switch it may take a while...
> +	 */
> +	if (num_online_cpus() > 1) {
> +		spin_lock_irq(&task->sighand->siglock);
> +
> +		for_each_thread(task, t) {
> +			if (t == current)
> +				continue;
> +
> +			switch_count = t->nvcsw + t->nivcsw;
> +
> +			do {
> +				spin_unlock_irq(&task->sighand->siglock);
> +				cond_resched();
> +				spin_lock_irq(&task->sighand->siglock);
> +			} while ((t->nvcsw + t->nivcsw) == switch_count);
> +		}
> +
> +		spin_unlock_irq(&task->sighand->siglock);
> +	}
>
This piece of thread walking seems to be not thread safe for newly 
created thread.
Thread creation is not locked between points of copy_thread which copies 
task thread flags
and makeing thread visible to walking via "for_each_thread".

So it is possible in environment with two threads - one is creating an 
another thread,
another one switching FPU mode and waiting and race condition may causes 
a newly thread in old mode
but the rest of thread group is in new mode.

Besides that, it looks like in kernel with tickless mode a scheduler may 
no come a long time in idle system,
in extreme case - forever.

- Leonid.

WARNING: multiple messages have this Message-ID (diff)
From: Leonid Yegoshin <Leonid.Yegoshin@imgtec.com>
To: Paul Burton <paul.burton@imgtec.com>, linux-mips@linux-mips.org
Cc: Matthew Fortune <matthew.fortune@imgtec.com>,
	Markos Chandras <markos.chandras@imgtec.com>
Subject: Re: MIPS,prctl: add PR_[GS]ET_FP_MODE prctl options for MIPS
Date: Thu, 8 Jan 2015 18:25:48 -0800	[thread overview]
Message-ID: <54AF3C2C.7040807@imgtec.com> (raw)
Message-ID: <20150109022548.2ZM4XRg2U8mLdTmWl7-BAsJKQqzeMu5NogplA1jScco@z> (raw)
In-Reply-To: <1420719457-690-1-git-send-email-paul.burton@imgtec.com>

> +	/* Prevent any threads from obtaining live FP context */
> +	atomic_set(&task->mm->context.fp_mode_switching, 1);
> +	smp_mb__after_atomic();
> +
> +	/*
> +	 * If there are multiple online CPUs then wait until all threads whose
> +	 * FP mode is about to change have been context switched. This approach
> +	 * allows us to only worry about whether an FP mode switch is in
> +	 * progress when FP is first used in a tasks time slice. Pretty much all
> +	 * of the mode switch overhead can thus be confined to cases where mode
> +	 * switches are actually occuring. That is, to here. However for the
> +	 * thread performing the mode switch it may take a while...
> +	 */
> +	if (num_online_cpus() > 1) {
> +		spin_lock_irq(&task->sighand->siglock);
> +
> +		for_each_thread(task, t) {
> +			if (t == current)
> +				continue;
> +
> +			switch_count = t->nvcsw + t->nivcsw;
> +
> +			do {
> +				spin_unlock_irq(&task->sighand->siglock);
> +				cond_resched();
> +				spin_lock_irq(&task->sighand->siglock);
> +			} while ((t->nvcsw + t->nivcsw) == switch_count);
> +		}
> +
> +		spin_unlock_irq(&task->sighand->siglock);
> +	}
>
This piece of thread walking seems to be not thread safe for newly 
created thread.
Thread creation is not locked between points of copy_thread which copies 
task thread flags
and makeing thread visible to walking via "for_each_thread".

So it is possible in environment with two threads - one is creating an 
another thread,
another one switching FPU mode and waiting and race condition may causes 
a newly thread in old mode
but the rest of thread group is in new mode.

Besides that, it looks like in kernel with tickless mode a scheduler may 
no come a long time in idle system,
in extreme case - forever.

- Leonid.

  parent reply	other threads:[~2015-01-09  2:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-08 12:17 [PATCH] MIPS,prctl: add PR_[GS]ET_FP_MODE prctl options for MIPS Paul Burton
2015-01-08 12:17 ` Paul Burton
2015-01-08 12:54 ` Matthew Fortune
2015-01-09  2:25 ` Leonid Yegoshin [this message]
2015-01-09  2:25   ` Leonid Yegoshin
2015-01-09  8:34   ` Matthew Fortune
2015-01-09 18:42     ` Leonid Yegoshin
     [not found] ` <54B024AA.1020400@imgtec.com>
2015-01-09 21:25   ` Matthew Fortune
2015-01-09 21:25     ` Matthew Fortune
     [not found] ` <1420719457-690-1-git-send-email-paul.burton-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-01-13 13:12   ` [PATCH] " Markos Chandras
2015-01-13 13:12     ` Markos Chandras
2015-01-13 13:12     ` Markos Chandras
     [not found]     ` <54B519B6.5040604-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-01-16 15:43       ` Markos Chandras
2015-01-16 15:43         ` Markos Chandras
2015-01-16 15:43         ` Markos Chandras
2015-01-18 21:47       ` Paul Burton
2015-01-18 21:47         ` Paul Burton
2015-01-18 21:47         ` Paul Burton

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=54AF3C2C.7040807@imgtec.com \
    --to=leonid.yegoshin@imgtec.com \
    --cc=linux-mips@linux-mips.org \
    --cc=markos.chandras@imgtec.com \
    --cc=matthew.fortune@imgtec.com \
    --cc=paul.burton@imgtec.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 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.