Merge branch 'net-ipa-simplify-tx-power-handling'
Alex Elder says: ==================== net: ipa: simplify TX power handling In order to deliver a packet to the IPA hardware, we must ensure it is powered. We request power by calling pm_runtime_get(), and its return value tells us the power state. We can't block in ipa_start_xmit(), so if power isn't enabled we prevent further transmit attempts by calling netif_stop_queue(). Power will eventually become enabled, at which point we call netif_wake_queue() to allow the transmit to be retried. When it does, the power should be enabled, so the packet delivery can proceed. The logic that handles this is convoluted, and was put in place to address a race condition pointed out by Jakub Kicinski during review. The fix addressed that race, as well as another one that was found while investigating it: b8e36e13 ("net: ipa: fix TX queue race") I have wanted to simplify this code ever since, and I'm pleased to report that this series implements a much better solution that avoids both race conditions. The first race occurs between the ->ndo_start_xmit thread and the runtime resume thread. If we find power is not enabled when requested in ipa_start_xmit(), we stop queueing. But there's a chance the runtime resume will enable queuing just before that, leaving queueing stopped forever. A flag is used to ensure that does not occur. A second flag is used to prevent NETDEV_TX_BUSY from being returned repeatedly during the small window between enabling queueing and finishing power resume. This can happen if resume was underway when pm_runtime_get() was called and completes immediately afterward. This condition only exists because of the use of the first flag. The fix is to disable transmit for *every* call to ipa_start_xmit(), disabling it *before* calling pm_runtime_get(). This leaves three cases: - If the return value indicates power is not active (or is in transition), queueing remains disabled--thereby avoiding the race between disabling it and a concurrent power thread enabling it. - If pm_runtime_get() returns an error, we drop the packet and re-enable queueing. - Finally, if the hardware is powered, we re-enable queueing before delivering the packet to the hardware. So the first race is avoided. And as a result, the second condition will not occur. The first patch adds pointers to the TX and RX IPA endpoints in the netdev private data. The second patch has netif_stop_queue() be called for all packets; if pm_runtime_get() indicates power is enabled (or an error), netif_wake_queue() is called to enable it again. The third and fourth patches get rid of the STARTED and STOPPED IPA power flags, as well as the power spinlock, because they are no longer needed. The last three patches just eliminate some trivial functions, open-coding them instead. ==================== Link: https://lore.kernel.org/r/20240130192305.250915-1-elder@linaro.orgSigned-off-by: Jakub Kicinski <kuba@kernel.org>
Showing
Please register or sign in to comment