]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commit
net: ena: fix race condition between submit and completion admin command
authorNetanel Belgazal <netanel@amazon.com>
Sun, 11 Jun 2017 12:42:46 +0000 (15:42 +0300)
committerKamal Mostafa <kamal@canonical.com>
Mon, 10 Jul 2017 17:31:40 +0000 (10:31 -0700)
commit2b75ec904b5c618a9f7d7ced7e3558c7e5fc92f6
tree5926caf98a00b458bfe99619be5c986c44a43c57
parent50b95fe7f4391c7618759dad8820a713e5902155
net: ena: fix race condition between submit and completion admin command

BugLink: http://bugs.launchpad.net/bugs/1701575
Bug:
"Completion context is occupied" error printout will be noticed in
dmesg.
This error will cause the admin command to fail, which will lead to
an ena_probe() failure or a watchdog reset (depends on which admin
command failed).

Root cause:
__ena_com_submit_admin_cmd() is the function that submits new entries to
the admin queue.
The function have a check that makes sure the queue is not full and the
function does not override any outstanding command.
It uses head and tail indexes for this check.
The head is increased by ena_com_handle_admin_completion() which runs
from interrupt context, and the tail index is increased by the submit
function (the function is running under ->q_lock, so there is no risk
of multithread increment).
Each command is associated with a completion context. This context
allocated before call to __ena_com_submit_admin_cmd() and freed by
ena_com_wait_and_process_admin_cq_interrupts(), right after the command
was completed.

This can lead to a state where the head was increased, the check passed,
but the completion context is still in use.

Solution:
Use the atomic variable ->outstanding_cmds instead of using the head and
the tail indexes.
This variable is safe for use since it is bumped in get_comp_ctx() in
__ena_com_submit_admin_cmd() and is freed by comp_ctxt_release()

Fixes: 1738cd3ed342 ("Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Netanel Belgazal <netanel@amazon.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 661d2b0ccef6a63f48b61105cf7be17403d1db01)
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Acked-by: Seth Forshee <seth.forshee@canonical.com>
Acked-by: Brad Figg <brad.figg@canonical.com>
drivers/net/ethernet/amazon/ena/ena_com.c