ice: make writes to /dev/gnssX synchronous
Subsystems (3)
PATCH v2 1/1 ice: make writes to /dev/gnssX synchronous
The current ice driver's GNSS write implementation buffers writes and works through them asynchronously in a kthread. That's bad because:
- The GNSS write_raw operation is supposed to be synchronous[1][2].
- There is no upper bound on the number of pending writes. Userspace can submit writes much faster than the driver can process, consuming unlimited amounts of kernel memory.
A patch that's currently on review[3] ("[v3,net] ice: Write all GNSS buffers instead of first one") would add one more problem:
- The possibility of waiting for a very long time to flush the write work when doing rmmod, softlockups.
To fix these issues, simplify the implementation: Drop the buffering, the write_work, and make the writes synchronous.
I tested this with gpsd and ubxtool.
[1] https://events19.linuxfoundation.org/wp-content/uploads/2017/12/The-GNSS-Subsystem-Johan-Hovold-Hovold-Consulting-AB.pdf
"User interface" slide.
[2] A comment in drivers/gnss/core.c:gnss_write():
/* Ignoring O_NONBLOCK, write_raw() is synchronous. */
[3] https://patchwork.ozlabs.org/project/intel-wired-lan/patch/[email protected]/
---
v2: No real change. Just rebased, per Michal Michalik's request.
--- drivers/net/ethernet/intel/ice/ice_common.c | 2 +- drivers/net/ethernet/intel/ice/ice_common.h | 2 +- drivers/net/ethernet/intel/ice/ice_gnss.c | 64 ++------------------- drivers/net/ethernet/intel/ice/ice_gnss.h | 10 ---- 4 files changed, 6 insertions(+), 72 deletions(-)
drivers/net/ethernet/intel/ice/ice_common.c +1 -1
@@ -5160,7 +5160,7 @@ ice_aq_read_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr,*/ int ice_aq_write_i2c (struct ice_hw *hw,struct ice_aqc_link_topo_addr topo_addr, -u16 bus_addr,__le16 addr,u8 params,u8 *data, +u16 bus_addr,__le16 addr,u8 params,const u8 *data,struct ice_sq_cd *cd) {struct ice_aq_desc desc = {0 };
drivers/net/ethernet/intel/ice/ice_common.h +1 -1
@@ -229,7 +229,7 @@ ice_aq_read_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr, struct ice_sq_cd *cd);int ice_aq_write_i2c (struct ice_hw *hw,struct ice_aqc_link_topo_addr topo_addr, -u16 bus_addr,__le16 addr,u8 params,u8 *data, +u16 bus_addr,__le16 addr,u8 params,const u8 *data,struct ice_sq_cd *cd);bool ice_fw_supports_report_dflt_cfg (struct ice_hw *hw);#endif /* _ICE_COMMON_H_ */
drivers/net/ethernet/intel/ice/ice_gnss.c +4 -60
107 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_gnss.h +0 -10
@@ -22,26 +22,16 @@*/ #define ICE_GNSS_UBX_WRITE_BYTES (ICE_MAX_I2C_WRITE_BYTES + 1) -struct gnss_write_buf { -struct list_head queue; -unsigned int size; -unsigned char *buf; -}; -/** * struct gnss_serial - data used to initialize GNSS TTY port * @back: back pointer to PF * @kworker: kwork thread for handling periodic work * @read_work: read_work function for handling GNSS reads -* @write_work: write_work function for handling GNSS writes -* @queue: write buffers queue */ struct gnss_serial {struct ice_pf *back;struct kthread_worker *kworker;struct kthread_delayed_work read_work; -struct kthread_work write_work; -struct list_head queue; };#if IS_ENABLED (CONFIG_GNSS )
Signature · 1 line
2.40.1
Quoted 20 lines · Michal Schmidt
The current ice driver's GNSS write implementation buffers writes and works through them asynchronously in a kthread. That's bad because:
- The GNSSwrite_rawoperation is supposed to be synchronous[1][2].
- There is no upper bound on the number of pending writes. Userspace can submit writes much faster than the driver can process, consuming unlimited amounts of kernel memory.A patch that's currently on review[3] ("[v3,net] ice: Write all GNSS buffers instead of first one") would add one more problem:
- The possibility of waiting for a very long time to flush the write work when doing rmmod, softlockups.To fix these issues, simplify the implementation: Drop the buffering, the
write_work, and make the writes synchronous.I tested this with gpsd and ubxtool.
[1] https://events19.linuxfoundation.org/wp-content/uploads/2017/12/The-GNSS-Subsystem-Johan-Hovold-Hovold-Consulting-AB.pdf
"User interface" slide.
[2] A comment in drivers/gnss/core.c:gnss_write():
Quoted 7 lines
/* Ignoring O_NONBLOCK, write_raw() is synchronous. */[3] https://patchwork.ozlabs.org/project/intel-wired-lan/patch/[email protected]/
Fixes d6b98c8d242a ("ice: add write functionality for GNSS TTY")Signed-off-by Michal Schmidt <[email protected]>---
v2: No real change. Just rebased, per Michal Michalik's request.
Added Johan Hovold to CC list in case he has any feedback.
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Mekala, SunithaX D
Tested-byQuoted 32 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Simon Horman
Sent: Friday, May 26, 2023 2:13 AM
To: mschmidt <[email protected]>
Cc: [email protected]; Kolacinski, Karol <[email protected]>; Nguyen, Anthony L <[email protected]>; [email protected]; Johan Hovold <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net v2] ice: make writes to/dev/gnssXsynchronousQuoted 24 lines · Michal Schmidt
The current ice driver's GNSS write implementation buffers writes and works through them asynchronously in a kthread. That's bad because:
- The GNSSwrite_rawoperation is supposed to be synchronous[1][2].
- There is no upper bound on the number of pending writes. Userspace can submit writes much faster than the driver can process, consuming unlimited amounts of kernel memory.A patch that's currently on review[3] ("[v3,net] ice: Write all GNSS buffers instead of first one") would add one more problem:
- The possibility of waiting for a very long time to flush the write work when doing rmmod, softlockups.To fix these issues, simplify the implementation: Drop the buffering, the
write_work, and make the writes synchronous.I tested this with gpsd and ubxtool.
[1] https://events19.linuxfoundation.org/wp-content/uploads/2017/12/The-GNSS-Subsystem-Johan-Hovold-Hovold-Consulting-AB.pdf
"User interface" slide.
[2] A comment in drivers/gnss/core.c:gnss_write():/* Ignoring O_NONBLOCK, write_raw() is synchronous. */ [3]https://patchwork.ozlabs.org/project/intel-wired-lan/patch/20230217120
[email protected]/
Quoted 9 lines
Quoted 4 lines
Fixes d6b98c8d242a ("ice: add write functionality for GNSS TTY")Signed-off-by Michal Schmidt <[email protected]>---
v2: No real change. Just rebased, per Michal Michalik's request.Reviewed-by Simon Horman <[email protected]>Added Johan Hovold to CC list in case he has any feedback.