linux/drivers/hid/intel-ish-hid/ishtp
Even Xu e1fa076706 hid: intel-ish-hid: ishtp: Fix ishtp client sending disordered message
There is a timing issue captured during ishtp client sending stress tests.
It was observed during stress tests that ISH firmware is getting out of
ordered messages. This is a rare scenario as the current set of ISH client
drivers don't send much data to firmware. But this may not be the case
going forward.

When message size is bigger than IPC MTU, ishtp splits the message into
fragments and uses serialized async method to send message fragments.
The call stack:
ishtp_cl_send_msg_ipc->ipc_tx_callback(first fregment)->
ishtp_send_msg(with callback)->write_ipc_to_queue->
write_ipc_from_queue->callback->ipc_tx_callback(next fregment)......

When an ipc write complete interrupt is received, driver also calls
write_ipc_from_queue->ipc_tx_callback in ISR to start sending of next fragment.

Through ipc_tx_callback uses spin_lock to protect message splitting, as the
serialized sending method will call back to ipc_tx_callback again, so it doesn't
put sending under spin_lock, it causes driver cannot guarantee all fragments
be sent in order.

Considering this scenario:
ipc_tx_callback just finished a fragment splitting, and not call ishtp_send_msg
yet, there is a write complete interrupt happens, then ISR->write_ipc_from_queue
->ipc_tx_callback->ishtp_send_msg->write_ipc_to_queue......

Because ISR has higher exec priority than normal thread, this causes the new
fragment be sent out before previous fragment. This disordered message causes
invalid message to firmware.

The solution is, to send fragments synchronously:
Use ishtp_write_message writing fragments into tx queue directly one by one,
instead of ishtp_send_msg only writing one fragment with completion callback.
As no completion callback be used, so change ipc_tx_callback to ipc_tx_send.

Signed-off-by: Even Xu <even.xu@intel.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@intel.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2022-08-25 11:35:44 +02:00
..
bus.c HID: intel-ish-hid: fix module device-id handling 2021-11-11 22:45:40 +01:00
bus.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
client-buffers.c HID: intel-ish-hid: fix wrong error handling in ishtp_cl_alloc_tx_ring() 2019-10-16 08:26:55 +02:00
client.c hid: intel-ish-hid: ishtp: Fix ishtp client sending disordered message 2022-08-25 11:35:44 +02:00
client.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
dma-if.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
hbm.c HID: intel-ish: Fix a naming disparity and a formatting error 2021-04-07 17:55:45 +02:00
hbm.h HID: intel_ish-hid: HBM: Use connected standby state bit during suspend/resume 2021-03-19 14:34:51 +01:00
init.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
ishtp-dev.h HID: intel-ish-hid: ishtp: Add dma_no_cache_snooping() callback 2021-06-14 15:55:09 +02:00