mt7601u: make write with mask access atomic
Subsystems (2)
PATCH 1/1 mt7601u: make write with mask access atomic
In reply to a message not in the archiveIntroduce __mt7601u_rr and __mt7601u_vendor_single_wr routines in order to make mt7601u_rmw and mt7601u_rmc atomic since it is possible that read and write accesses of mt7601u_rmw/mt7601u_rmc can be interleaved with a different write operation on the same register. Moreover move write trace point in __mt7601u_vendor_single_wr
--- drivers/net/wireless/mediatek/mt7601u/mt7601u.h | 3 +- drivers/net/wireless/mediatek/mt7601u/usb.c | 52 ++++++++++++++++++------- 2 files changed, 39 insertions(+), 16 deletions(-)
drivers/net/wireless/mediatek/mt7601u/mt7601u.h +2 -1
@@ -147,7 +147,8 @@ enum {* @rx_lock: protects @rx_q. * @con_mon_lock: protects @ap_bssid, @bcn_*, @avg_rssi. * @mutex: ensures exclusive access from mac80211 callbacks. -* @vendor_req_mutex: protects @vend_buf, ensures atomicity of split writes. +* @vendor_req_mutex: protects @vend_buf, ensures atomicity of read/write +* accesses * @reg_atomic_mutex: ensures atomicity of indirect register accesses * (accesses to RF and BBP). * @hw_atomic_mutex: ensures exclusive access to HW during critical
drivers/net/wireless/mediatek/mt7601u/usb.c +37 -15
100 lines not on this page · raw message
Signature · 1 line
2.14.3
Quoted 7 lines · Lorenzo Bianconi
Introduce
__mt7601u_rrand__mt7601u_vendor_single_wrroutines in order to makemt7601u_rmwandmt7601u_rmcatomic since it is possible that read and write accesses of mt7601u_rmw/mt7601u_rmc can be interleaved with a different write operation on the same register. Moreover move write trace point in__mt7601u_vendor_single_wrSigned-off-by Lorenzo Bianconi <[email protected]>
Could you provide an example of which accesses make it problematic? Is this fixing an actual bug?
Quoted 11 lines · Lorenzo Bianconi
Quoted 7 lines
Introduce
__mt7601u_rrand__mt7601u_vendor_single_wrroutines in order to makemt7601u_rmwandmt7601u_rmcatomic since it is possible that read and write accesses of mt7601u_rmw/mt7601u_rmc can be interleaved with a different write operation on the same register. Moreover move write trace point in__mt7601u_vendor_single_wrSigned-off-by Lorenzo Bianconi <[email protected]>Could you provide an example of which accesses make it problematic? Is this fixing an actual bug?
Hi Jakub,
it is not an issue I had experimented, I noticed a theoretical race reviewing the code.
AFAIU, based on the current implementation it is possible that mt7601u_rmw (with mt7601u_rr) loads data from given register but its store access (mt7601u_wr) is
preceded by another mt7601u_wr on the same register. In this case the value configured by
the first mt7601u_wr executed is overwritten by the second one (the store from mt7601u_rmw)
even if the first write is setting a different subfield respect to mt7601u_rmw.
Regards,
Lorenzo
Quoted 14 lines · Lorenzo Bianconi
Quoted 11 lines · Lorenzo Bianconi
Quoted 7 lines
Introduce
__mt7601u_rrand__mt7601u_vendor_single_wrroutines in order to makemt7601u_rmwandmt7601u_rmcatomic since it is possible that read and write accesses of mt7601u_rmw/mt7601u_rmc can be interleaved with a different write operation on the same register. Moreover move write trace point in__mt7601u_vendor_single_wrSigned-off-by Lorenzo Bianconi <[email protected]>Could you provide an example of which accesses make it problematic? Is this fixing an actual bug?
Hi Jakub,
Quoted 11 lines
it is not an issue I had experimented, I noticed a theoretical race reviewing the code.
AFAIU, based on the current implementation it is possible thatmt7601u_rmw(withmt7601u_rr) loads data from given register but its store access (mt7601u_wr) is
preceded by anothermt7601u_wron the same register. In this case the value configured by
the firstmt7601u_wrexecuted is overwritten by the second one (the store frommt7601u_rmw)
even if the first write is setting a different subfield respect tomt7601u_rmw.
Hm.. There should be no path in the driver where that could cause problems AFAIR. We have reg_atomic_mutex and hw_atomic_mutex to protect from concurrent access to the HW where they are possible. RMW operations are non-atomic by definition, it's supposed to work like PCIe register accesses would - 32bit reads/writes are atomic, but RMW is not.
So I'm not sure what to do with this patch. Doesn't seem necessary...
Quoted 27 lines · Jakub Kicinski
Quoted 14 lines · Lorenzo Bianconi
Quoted 11 lines · Lorenzo Bianconi
Quoted 7 lines
Introduce
__mt7601u_rrand__mt7601u_vendor_single_wrroutines in order to makemt7601u_rmwandmt7601u_rmcatomic since it is possible that read and write accesses of mt7601u_rmw/mt7601u_rmc can be interleaved with a different write operation on the same register. Moreover move write trace point in__mt7601u_vendor_single_wrSigned-off-by Lorenzo Bianconi <[email protected]>Could you provide an example of which accesses make it problematic? Is this fixing an actual bug?
Hi Jakub,
Quoted 11 lines
it is not an issue I had experimented, I noticed a theoretical race reviewing the code.
AFAIU, based on the current implementation it is possible thatmt7601u_rmw(withmt7601u_rr) loads data from given register but its store access (mt7601u_wr) is
preceded by anothermt7601u_wron the same register. In this case the value configured by
the firstmt7601u_wrexecuted is overwritten by the second one (the store frommt7601u_rmw)
even if the first write is setting a different subfield respect tomt7601u_rmw.
Quoted 6 lines
Hm.. There should be no path in the driver where that could cause problems AFAIR. We have
reg_atomic_mutexandhw_atomic_mutexto protect from concurrent access to the HW where they are possible. RMW operations are non-atomic by definition, it's supposed to work like PCIe register accesses would - 32bit reads/writes are atomic, but RMW is not.
Yes, RMW accesses are non-atomic by default but since vendor_req_mutex mutex is already there (and grabbed for RMW operations), why not use it to make write with mask access atomic without adding complexity? Moreover it would be a micro-optimisation since vendor_req_mutex would be grabbed just once instead of twice
Quoted 2 lines
So I'm not sure what to do with this patch. Doesn't seem necessary...
It is just a trivial rework of locking in usb read/write accesses, not mandatory, so if you prefer we can just drop it
Regards,
Lorenzo
Quoted 14 lines · Lorenzo Bianconi
Quoted 6 lines
Hm.. There should be no path in the driver where that could cause problems AFAIR. We have
reg_atomic_mutexandhw_atomic_mutexto protect from concurrent access to the HW where they are possible. RMW operations are non-atomic by definition, it's supposed to work like PCIe register accesses would - 32bit reads/writes are atomic, but RMW is not.Yes, RMW accesses are non-atomic by default but since
vendor_req_mutexmutex is already there (and grabbed for RMW operations), why not use it to make write with mask access atomic without adding complexity? Moreover it would be a micro-optimisation sincevendor_req_mutexwould be grabbed just once instead of twiceQuoted 1 line
Quoted 4 lines
Quoted 1 line
So I'm not sure what to do with this patch. Doesn't seem necessary...
It is just a trivial rework of locking in usb read/write accesses, not mandatory, so if you prefer we can just drop it
You make good points :) Could you please respin stating clearly in the commit message that this is not a bug fix, but a micro-optimization and may be useful in the future?
Quoted 7 lines · Lorenzo Bianconi
Quoted 7 lines · Lorenzo Bianconi
Quoted 6 lines
Introduce
__mt7601u_rrand__mt7601u_vendor_single_wrroutines in order to makemt7601u_rmwandmt7601u_rmcatomic since it is possible that read and write accesses of mt7601u_rmw/mt7601u_rmc can be interleaved with a different write operation on the same register. Moreover move write trace point in__mt7601u_vendor_single_wr
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Lorenzo Bianconi <[email protected]>Could you provide an example of which accesses make it problematic? Is this fixing an actual bug?
it is not an issue I had experimented, I noticed a theoretical race reviewing the code.
The commit log should always answer the question "Why?". If you find a theoretical issue in the code document that clearly in the commit log. That helps to choose correct tree and sending to stable releases etc.
Signature · 1 line
Kalle Valo
Quoted 17 lines
Quoted 7 lines · Lorenzo Bianconi
Quoted 7 lines · Lorenzo Bianconi
Quoted 6 lines
Introduce
__mt7601u_rrand__mt7601u_vendor_single_wrroutines in order to makemt7601u_rmwandmt7601u_rmcatomic since it is possible that read and write accesses of mt7601u_rmw/mt7601u_rmc can be interleaved with a different write operation on the same register. Moreover move write trace point in__mt7601u_vendor_single_wrQuoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Lorenzo Bianconi <[email protected]>Could you provide an example of which accesses make it problematic? Is this fixing an actual bug?
it is not an issue I had experimented, I noticed a theoretical race reviewing the code.
Quoted 8 lines
The commit log should always answer the question "Why?". If you find a theoretical issue in the code document that clearly in the commit log. That helps to choose correct tree and sending to stable releases etc.
--
Kalle Valo
Hi Kalle,
I have already sent a v2: https://patchwork.kernel.org/patch/10225849/
Is the commit message ok?
Regards,
Lorenzo
Quoted 17 lines · Lorenzo Bianconi
Quoted 17 lines
Quoted 14 lines · Lorenzo Bianconi
Quoted 11 lines · Lorenzo Bianconi
Quoted 7 lines
Introduce
__mt7601u_rrand__mt7601u_vendor_single_wrroutines in order to makemt7601u_rmwandmt7601u_rmcatomic since it is possible that read and write accesses of mt7601u_rmw/mt7601u_rmc can be interleaved with a different write operation on the same register. Moreover move write trace point in__mt7601u_vendor_single_wrSigned-off-by Lorenzo Bianconi <[email protected]>Could you provide an example of which accesses make it problematic? Is this fixing an actual bug?
it is not an issue I had experimented, I noticed a theoretical race reviewing the code.
Quoted 8 lines
Quoted 5 lines
The commit log should always answer the question "Why?". If you find a theoretical issue in the code document that clearly in the commit log. That helps to choose correct tree and sending to stable releases etc.
I have already sent a v2: https://patchwork.kernel.org/patch/10225849/
Is the commit message ok?
Yeah, I already applied it.
Signature · 1 line
Kalle Valo