* Is read barrier missed in kfifo? @ 2018-05-11 7:25 Xiao Guangrong 2018-05-11 7:33 ` Stefani Seibold 2018-05-11 8:32 ` Peter Zijlstra 0 siblings, 2 replies; 6+ messages in thread From: Xiao Guangrong @ 2018-05-11 7:25 UTC (permalink / raw) To: paulmck Cc: peterz, rostedt, Lai Jiangshan, stefani, linux-kernel@vger.kernel.org Hi, Currently, there is no read barrier between reading the index (kfifo.in) and fetching the real data from the fifo. I am afraid that will cause the vfifo is observed as not empty however the data is not actually ready for read. Right? Thanks! ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Is read barrier missed in kfifo? 2018-05-11 7:25 Is read barrier missed in kfifo? Xiao Guangrong @ 2018-05-11 7:33 ` Stefani Seibold 2018-05-11 8:32 ` Peter Zijlstra 1 sibling, 0 replies; 6+ messages in thread From: Stefani Seibold @ 2018-05-11 7:33 UTC (permalink / raw) To: Xiao Guangrong, paulmck Cc: peterz, rostedt, Lai Jiangshan, linux-kernel@vger.kernel.org My guts thinks you are right. Feel free to send a patch... Am Freitag, den 11.05.2018, 15:25 +0800 schrieb Xiao Guangrong: > Hi, > > Currently, there is no read barrier between reading the index > (kfifo.in) and fetching the real data from the fifo. > > I am afraid that will cause the vfifo is observed as not empty > however the data is not actually ready for read. Right? > > Thanks! ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Is read barrier missed in kfifo? 2018-05-11 7:25 Is read barrier missed in kfifo? Xiao Guangrong 2018-05-11 7:33 ` Stefani Seibold @ 2018-05-11 8:32 ` Peter Zijlstra 2018-05-11 16:20 ` Paul E. McKenney 1 sibling, 1 reply; 6+ messages in thread From: Peter Zijlstra @ 2018-05-11 8:32 UTC (permalink / raw) To: Xiao Guangrong Cc: paulmck, rostedt, Lai Jiangshan, stefani, linux-kernel@vger.kernel.org On Fri, May 11, 2018 at 03:25:18PM +0800, Xiao Guangrong wrote: > > Hi, > > Currently, there is no read barrier between reading the index > (kfifo.in) and fetching the real data from the fifo. > > I am afraid that will cause the vfifo is observed as not empty > however the data is not actually ready for read. Right? That code is decidedly dodgy indeed. I can only see smp_wmb() but no matching barriers at all -- therefore the code is almost certainly as good as not having any barriers at all. I would suggest you try and convert the code to smp_store_release() and smp_load_acquire() while you're at it. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Is read barrier missed in kfifo? 2018-05-11 8:32 ` Peter Zijlstra @ 2018-05-11 16:20 ` Paul E. McKenney 2018-05-14 6:57 ` Peter Zijlstra 0 siblings, 1 reply; 6+ messages in thread From: Paul E. McKenney @ 2018-05-11 16:20 UTC (permalink / raw) To: Peter Zijlstra Cc: Xiao Guangrong, rostedt, Lai Jiangshan, stefani, linux-kernel@vger.kernel.org On Fri, May 11, 2018 at 10:32:42AM +0200, Peter Zijlstra wrote: > On Fri, May 11, 2018 at 03:25:18PM +0800, Xiao Guangrong wrote: > > > > Hi, > > > > Currently, there is no read barrier between reading the index > > (kfifo.in) and fetching the real data from the fifo. > > > > I am afraid that will cause the vfifo is observed as not empty > > however the data is not actually ready for read. Right? > > That code is decidedly dodgy indeed. I can only see smp_wmb() but no > matching barriers at all -- therefore the code is almost certainly as > good as not having any barriers at all. > > I would suggest you try and convert the code to smp_store_release() and > smp_load_acquire() while you're at it. Isn't this one of the places where we rely on control dependencies? Thanx, Paul ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Is read barrier missed in kfifo? 2018-05-11 16:20 ` Paul E. McKenney @ 2018-05-14 6:57 ` Peter Zijlstra 2018-05-14 13:25 ` Paul E. McKenney 0 siblings, 1 reply; 6+ messages in thread From: Peter Zijlstra @ 2018-05-14 6:57 UTC (permalink / raw) To: Paul E. McKenney Cc: Xiao Guangrong, rostedt, Lai Jiangshan, stefani, linux-kernel@vger.kernel.org On Fri, May 11, 2018 at 09:20:53AM -0700, Paul E. McKenney wrote: > On Fri, May 11, 2018 at 10:32:42AM +0200, Peter Zijlstra wrote: > > On Fri, May 11, 2018 at 03:25:18PM +0800, Xiao Guangrong wrote: > > > > > > Hi, > > > > > > Currently, there is no read barrier between reading the index > > > (kfifo.in) and fetching the real data from the fifo. > > > > > > I am afraid that will cause the vfifo is observed as not empty > > > however the data is not actually ready for read. Right? > > > > That code is decidedly dodgy indeed. I can only see smp_wmb() but no > > matching barriers at all -- therefore the code is almost certainly as > > good as not having any barriers at all. > > > > I would suggest you try and convert the code to smp_store_release() and > > smp_load_acquire() while you're at it. > > Isn't this one of the places where we rely on control dependencies? Then it bloody well should have a comment. But at least one side of the fifo needs a read barrier I think. We can rely on a ctrl-dep on the write side, where we read the head/tail values, compute space and then conditionally allow writes to happen. But on the read side it's all reads and ctrl-dep doesn't help anything. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Is read barrier missed in kfifo? 2018-05-14 6:57 ` Peter Zijlstra @ 2018-05-14 13:25 ` Paul E. McKenney 0 siblings, 0 replies; 6+ messages in thread From: Paul E. McKenney @ 2018-05-14 13:25 UTC (permalink / raw) To: Peter Zijlstra Cc: Xiao Guangrong, rostedt, Lai Jiangshan, stefani, linux-kernel@vger.kernel.org On Mon, May 14, 2018 at 08:57:55AM +0200, Peter Zijlstra wrote: > On Fri, May 11, 2018 at 09:20:53AM -0700, Paul E. McKenney wrote: > > On Fri, May 11, 2018 at 10:32:42AM +0200, Peter Zijlstra wrote: > > > On Fri, May 11, 2018 at 03:25:18PM +0800, Xiao Guangrong wrote: > > > > > > > > Hi, > > > > > > > > Currently, there is no read barrier between reading the index > > > > (kfifo.in) and fetching the real data from the fifo. > > > > > > > > I am afraid that will cause the vfifo is observed as not empty > > > > however the data is not actually ready for read. Right? > > > > > > That code is decidedly dodgy indeed. I can only see smp_wmb() but no > > > matching barriers at all -- therefore the code is almost certainly as > > > good as not having any barriers at all. > > > > > > I would suggest you try and convert the code to smp_store_release() and > > > smp_load_acquire() while you're at it. > > > > Isn't this one of the places where we rely on control dependencies? > > Then it bloody well should have a comment. But at least one side of the > fifo needs a read barrier I think. We can rely on a ctrl-dep on the > write side, where we read the head/tail values, compute space and then > conditionally allow writes to happen. > > But on the read side it's all reads and ctrl-dep doesn't help anything. Agreed, for a control depdendency to help, there does need to be a control dependency. ;-) Thanx, Paul ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-05-14 13:24 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-05-11 7:25 Is read barrier missed in kfifo? Xiao Guangrong 2018-05-11 7:33 ` Stefani Seibold 2018-05-11 8:32 ` Peter Zijlstra 2018-05-11 16:20 ` Paul E. McKenney 2018-05-14 6:57 ` Peter Zijlstra 2018-05-14 13:25 ` Paul E. McKenney
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox