Skip to contentSkip to conversation

Is read barrier missed in kfifo?

DISCUSSION Xiao Guangrong 4 participants 6 messages May 11, 2018 – May 14, 2018

lore
Share & tools
lore
#0 lore raw

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!

#1 lore raw

My guts thinks you are right. Feel free to send a patch...

Am Freitag, den 11.05.2018, 15:25 +0800 schrieb Xiao Guangrong:

Quoted 9 lines

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!

#2 lore raw
In reply to Xiao Guangrong
Quoted 8 lines · 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?

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.

#3 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 8 lines · 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?

Quoted 6 lines

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

#4 lore raw
Quoted 11 lines · Paul E. McKenney
Quoted 10 lines · Peter Zijlstra
Quoted 8 lines · 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?

Quoted 8 lines
Quoted 6 lines

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.

#5 lore raw
Quoted 19 lines · Peter Zijlstra
Quoted 18 lines · Paul E. McKenney
Quoted 16 lines · Peter Zijlstra
Quoted 8 lines · 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?

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.

Quoted 8 lines
Quoted 1 line

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