linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Additional compiler barrier required in sched_preempt_enable_no_resched?
@ 2016-05-13  6:39 Vikram Mulukutla
  2016-05-13 14:21 ` Thomas Gleixner
  2016-05-13 14:58 ` Peter Zijlstra
  0 siblings, 2 replies; 10+ messages in thread
From: Vikram Mulukutla @ 2016-05-13  6:39 UTC (permalink / raw)
  To: peterz, tglx; +Cc: linux-kernel

Hi,

I came across a piece of engineering code that looked like:

preempt_disable();
/* --cut, lots of code-- */
preempt_enable_no_resched();
put_user()
preempt_disable();

(If you wish to seriously question the usage of the preempt API in this 
manner, I unfortunately have no comment since I didn't write the code.)

This particular block of code was causing lockups and crashes on a 
certain ARM64 device. The generated assembly revealed that the compiler 
was simply optimizing out the increment and decrement of the preempt 
count, allowing put_user to run without preemption enabled, causing all 
sorts of badness. Since put_user doesn't actually access the preempt 
count and translates to just a few instructions without any branching, I 
suppose that the compiler figured it was OK to optimize.

The immediate solution is to add a compiler barrier to the code above, 
but should sched_preempt_enable_no_resched have an additional compiler 
barrier after (has one before already) the preempt-count decrement to 
prevent this sort of thing?

Thanks,
Vikram

--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora 
Forum, a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-05-17 14:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-13  6:39 Additional compiler barrier required in sched_preempt_enable_no_resched? Vikram Mulukutla
2016-05-13 14:21 ` Thomas Gleixner
2016-05-13 14:58 ` Peter Zijlstra
2016-05-13 22:44   ` Vikram Mulukutla
2016-05-14 15:39     ` Thomas Gleixner
2016-05-14 18:28       ` Vikram Mulukutla
2016-05-16 10:55       ` Peter Zijlstra
2016-05-16 11:00         ` Peter Zijlstra
2016-05-16 13:17         ` Peter Zijlstra
2016-05-17 14:21           ` [tip:sched/urgent] sched/preempt: Fix preempt_count manipulations tip-bot for Peter Zijlstra

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).