Skip to contentSkip to conversation

iio meter patches - same!

DISCUSSION Alison Schofield 3 participants 4 messages Mar 21, 2017 – Mar 22, 2017

lore
Share & tools
lore
#0 lore raw

Simran, Gargi, Sayli, Arushi,

With respect to these...

meter/ade7753.c: simran singhal
meter/ade7754.c: Gargi Sharma
meter/ade7758_core.c: Sayli Karnik
meter/ade7759.c: ArushiSinghal

They are all near identical and therefore should have near identical solutions. You could work together, or follow one another, but, in the end we don't want to see 4 different flavors of the solution. That makes it harder to maintain.

Also - if 'we' can get one reviewed/ACK'd/applied, then we make the reviewers and maintainers life easier when we follow it with 3 similar patches.

Here's where I think you all dancing around...
You have Lars' feedback from ade7753:

Quoted 6 lines

It might make sense to reuse the existing lock which currently protects the
read/write functions. You can do this by introducing a variant of ade7753_spi_{read,write}_reg_16() that does not take a lock and use these to
implement the read-modify-write cycle in a protected section.

I'll add to that:
They were all using mlock to try to protect the spi read followed by write operation. I don't think the lock was actually doing that. I don't see a guarantee that another spi write could not intervene, So perhaps there was no real protection.

I'm thinking one function that locks the existing transaction lock, does the read, does the write, unlocks.

Can you all coordinate that please. This way the next patch we see on this is agreed upon by all four. Once that is applauded ;), the others can follow easily!

thanks,
alison

#1 lore raw
Quoted 27 lines · Alison Schofield

Simran, Gargi, Sayli, Arushi,

With respect to these...

meter/ade7753.c: simran singhal
meter/ade7754.c: Gargi Sharma
meter/ade7758_core.c: Sayli Karnik
meter/ade7759.c: ArushiSinghal

They are all near identical and therefore should have near identical solutions. You could work together, or follow one another, but, in the end we don't want to see 4 different flavors of the solution. That makes it harder to maintain.

Also - if 'we' can get one reviewed/ACK'd/applied, then we make the reviewers and maintainers life easier when we follow it with 3 similar patches.

Here's where I think you all dancing around...
You have Lars' feedback from ade7753:

Quoted 6 lines

It might make sense to reuse the existing lock which currently protects the
read/write functions. You can do this by introducing a variant of ade7753_spi_{read,write}_reg_16() that does not take a lock and use these to
implement the read-modify-write cycle in a protected section.

Quoted 9 lines

I'll add to that:
They were all using mlock to try to protect the spi read followed by write operation. I don't think the lock was actually doing that. I don't see a guarantee that another spi write could not intervene, So perhaps there was no real protection.

I'm thinking one function that locks the existing transaction lock, does the read, does the write, unlocks.

So if I'm not wrong, an ade7758_spi_read_write_reg_8() to do read followed by write. The ade7758_spi_read_reg_8() stays as is, but with the lock removed since the write has it's own read code and does not require a lock?

Quoted 4 lines

Can you all coordinate that please. This way the next patch we see on this is agreed upon by all four. Once that is applauded ;), the others can follow easily!

Sure, that'll be better!

thanks,
sayli

Quoted 5 lines

thanks,
alison

#2 lore raw
In reply to Alison Schofield
Quoted 28 lines · Alison Schofield

Simran, Gargi, Sayli, Arushi,

With respect to these...

meter/ade7753.c: simran singhal
meter/ade7754.c: Gargi Sharma
meter/ade7758_core.c: Sayli Karnik
meter/ade7759.c: ArushiSinghal

They are all near identical and therefore should have near identical solutions. You could work together, or follow one another, but, in the end we don't want to see 4 different flavors of the solution. That makes it harder to maintain.

Also - if 'we' can get one reviewed/ACK'd/applied, then we make the reviewers and maintainers life easier when we follow it with 3 similar patches.

Here's where I think you all dancing around...
You have Lars' feedback from ade7753:

Quoted 6 lines

It might make sense to reuse the existing lock which currently protects the
read/write functions. You can do this by introducing a variant of ade7753_spi_{read,write}_reg_16() that does not take a lock and use these to
implement the read-modify-write cycle in a protected section.

Quoted 3 lines

I'll add to that:
They were all using mlock to try to protect the spi read followed by write operation.

I have a question here: why do we want to protect the spi read?, I mean usually we want to protect writes since there might be a race condition. Or is it because if two threads are running the same function concurrently we want to give access of the function to the thread number 2 only once thread number 1 has written to the register?

Quoted 3 lines

I don't think the lock was actually doing that.
I don't see a guarantee that another spi write could not intervene, So perhaps there was no real protection.

Again, if we have two threads 1 and 2, won't the structure indio_dev be same for the both of them? And only one thread can hold the lock at a time.

Quoted 3 lines

I'm thinking one function that locks the existing transaction lock, does the read, does the write, unlocks.

Simran wrote a function write_then_read in this patch
http://marc.info/?l=linux-driver-devel&m=149001635402891&w=2. Do we want to do something similar?

Quoted 5 lines

Can you all coordinate that please. This way the next patch we see on this is agreed upon by all four. Once that is applauded ;), the others can follow easily!

Yeah that makes sense and is the most productive use of all of our ability! :)

Thanks!
Gargi

Quoted 11 lines

thanks,
alison

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20170321203110.GB12475%40d830.WORKGROUP.
For more options, visit https://groups.google.com/d/optout.

#3 lore raw
Quoted 45 lines · Gargi Sharma
Quoted 28 lines · Alison Schofield

Simran, Gargi, Sayli, Arushi,

With respect to these...

meter/ade7753.c: simran singhal
meter/ade7754.c: Gargi Sharma
meter/ade7758_core.c: Sayli Karnik
meter/ade7759.c: ArushiSinghal

They are all near identical and therefore should have near identical solutions. You could work together, or follow one another, but, in the end we don't want to see 4 different flavors of the solution. That makes it harder to maintain.

Also - if 'we' can get one reviewed/ACK'd/applied, then we make the reviewers and maintainers life easier when we follow it with 3 similar patches.

Here's where I think you all dancing around...
You have Lars' feedback from ade7753:

Quoted 6 lines

It might make sense to reuse the existing lock which currently protects the
read/write functions. You can do this by introducing a variant of ade7753_spi_{read,write}_reg_16() that does not take a lock and use these to
implement the read-modify-write cycle in a protected section.

Quoted 3 lines

I'll add to that:
They were all using mlock to try to protect the spi read followed by write operation.

I have a question here: why do we want to protect the spi read?, I mean usually we want to protect writes since there might be a race condition. Or is it because if two threads are running the same function concurrently we want to give access of the function to the thread number 2 only once thread number 1 has written to the register?

Quoted 3 lines

I don't think the lock was actually doing that.
I don't see a guarantee that another spi write could not intervene, So perhaps there was no real protection.

Again, if we have two threads 1 and 2, won't the structure indio_dev be same for the both of them? And only one thread can hold the lock at a time.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

I'm thinking one function that locks the existing transaction lock, does the read, does the write, unlocks.

Simran wrote a function write_then_read in this patch
http://marc.info/?l=linux-driver-devel&m=149001635402891&w=2. Do we want to do something similar?

Good questions Gargi!

Code was doing this - lock mlock, read, write, unlock mlock. I actually think that sysfs would handle allowing only one reader/write of that frequency at a time. And, the driver doesn't use mlock anywhere else. The vulnerable place was between the read and the write...

If you trace the code down to the spi subsystem calls you'll see that the read you are questioning, is actually a write followed by a read. Now, most iio developers would just surmise that was needed, but let's follow that to the data sheet:

http://www.analog.com/media/en/technical-documentation/data-sheets/ADE7754.pdf
page 32 tells us "Each register is accessed by first writing to the communications register, then transferring the register data."

The driver needs to read the current value of the register, change the values and write the register back out to the device. That is what you see happening in ade7754_write_frequency() We want to protect that set of transactions - the "read_modify_write" (Yes - it's like Simran's other patch- but opposite I guess ;))

I think the vulnerability here is that we don't want anyone coming in and changing the designated register that we are about to write. Another spi_read at this point could reset the register pointer, and an spi_write type operation could write trash to the frequency register.

The answer won't be to replace mlock with a new lock, because that won't prevent other types of spi reads or writes from happening. That would only protect this path.

BTW - I don't think you are just migrating away from mlock usage anymore. You are fixing a bug :)

OK- that's all my input for tonite. btw - I'm looking this all up alongside you. I'm not holding back. I don't have a solution in mind. This needs to simmer in my brain overnite. I look forward to seeing what you all come up with while I'm sleeping.

alisons

Quoted 21 lines
Quoted 5 lines

Can you all coordinate that please. This way the next patch we see on this is agreed upon by all four. Once that is applauded ;), the others can follow easily!

Yeah that makes sense and is the most productive use of all of our ability! :)

Thanks!
Gargi

Quoted 11 lines

thanks,
alison

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20170321203110.GB12475%40d830.WORKGROUP.
For more options, visit https://groups.google.com/d/optout.