From: Saeed Mahameed <saeedm@mellanox.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, Or Gerlitz <ogerlitz@mellanox.com>,
Alex Vesker <valex@mellanox.com>,
Saeed Mahameed <saeedm@mellanox.com>
Subject: [net 9/9] net/mlx5: Fix command interface race in polling mode
Date: Tue, 26 Jun 2018 17:21:18 -0700 [thread overview]
Message-ID: <20180627002118.9856-10-saeedm@mellanox.com> (raw)
In-Reply-To: <20180627002118.9856-1-saeedm@mellanox.com>
From: Alex Vesker <valex@mellanox.com>
The command interface can work in two modes: Events and Polling.
In the general case, each time we invoke a command, a work is
queued to handle it.
When working in events, the interrupt handler completes the
command execution. On the other hand, when working in polling
mode, the work itself completes it.
Due to a bug in the work handler, a command could have been
completed by the interrupt handler, while the work handler
hasn't finished yet, causing the it to complete once again
if the command interface mode was changed from Events to
polling after the interrupt handler was called.
mlx5_unload_one()
mlx5_stop_eqs()
// Destroy the EQ before cmd EQ
...cmd_work_handler()
write_doorbell()
--> EVENT_TYPE_CMD
mlx5_cmd_comp_handler() // First free
free_ent(cmd, ent->idx)
complete(&ent->done)
<-- mlx5_stop_eqs //cmd was complete
// move to polling before destroying the last cmd EQ
mlx5_cmd_use_polling()
cmd->mode = POLL;
--> cmd_work_handler (continues)
if (cmd->mode == POLL)
mlx5_cmd_comp_handler() // Double free
The solution is to store the cmd->mode before writing the doorbell.
Fixes: e126ba97dba9 ("mlx5: Add driver for Mellanox Connect-IB adapters")
Signed-off-by: Alex Vesker <valex@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
---
drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
index 2db5fe571594..384c1fa49081 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
@@ -807,6 +807,7 @@ static void cmd_work_handler(struct work_struct *work)
unsigned long flags;
bool poll_cmd = ent->polling;
int alloc_ret;
+ int cmd_mode;
sem = ent->page_queue ? &cmd->pages_sem : &cmd->sem;
down(sem);
@@ -853,6 +854,7 @@ static void cmd_work_handler(struct work_struct *work)
set_signature(ent, !cmd->checksum_disabled);
dump_command(dev, ent, 1);
ent->ts1 = ktime_get_ns();
+ cmd_mode = cmd->mode;
if (ent->callback)
schedule_delayed_work(&ent->cb_timeout_work, cb_timeout);
@@ -877,7 +879,7 @@ static void cmd_work_handler(struct work_struct *work)
iowrite32be(1 << ent->idx, &dev->iseg->cmd_dbell);
mmiowb();
/* if not in polling don't use ent after this point */
- if (cmd->mode == CMD_MODE_POLLING || poll_cmd) {
+ if (cmd_mode == CMD_MODE_POLLING || poll_cmd) {
poll_timeout(ent);
/* make sure we read the descriptor after ownership is SW */
rmb();
--
2.17.0
next prev parent reply other threads:[~2018-06-27 0:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-27 0:21 [pull request][net 0/9] Mellanox, mlx5 fixes 2018-06-26 Saeed Mahameed
2018-06-27 0:21 ` [net 1/9] net/mlx5e: Don't attempt to dereference the ppriv struct if not being eswitch manager Saeed Mahameed
2018-06-27 0:21 ` [net 2/9] net/mlx5: E-Switch, Avoid setup attempt if not being e-switch manager Saeed Mahameed
2018-06-27 0:21 ` [net 3/9] net/mlx5e: Avoid dealing with vport representors " Saeed Mahameed
2018-06-27 0:21 ` [net 4/9] IB/mlx5: " Saeed Mahameed
2018-06-27 0:21 ` [net 5/9] net/mlx5: E-Switch, Disallow vlan/spoofcheck setup if not being esw manager Saeed Mahameed
2018-06-27 0:21 ` [net 6/9] net/mlx5: Fix required capability for manipulating MPFS Saeed Mahameed
2018-06-27 0:21 ` [net 7/9] net/mlx5: Fix wrong size allocation for QoS ETC TC regitster Saeed Mahameed
2018-06-27 0:21 ` [net 8/9] net/mlx5: Fix incorrect raw command length parsing Saeed Mahameed
2018-06-27 0:21 ` Saeed Mahameed [this message]
2018-06-28 7:57 ` [pull request][net 0/9] Mellanox, mlx5 fixes 2018-06-26 David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180627002118.9856-10-saeedm@mellanox.com \
--to=saeedm@mellanox.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=ogerlitz@mellanox.com \
--cc=valex@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox