From: Ziwei Xiao <ziweixiao@google.com>
To: netdev@vger.kernel.org
Cc: jeroendb@google.com, pkaligineedi@google.com,
shailend@google.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
hramamurthy@google.com, rushilg@google.com,
ziweixiao@google.com, jfraker@google.com,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next 1/5] gve: Add adminq mutex lock
Date: Tue, 7 May 2024 22:59:41 +0000 [thread overview]
Message-ID: <20240507225945.1408516-2-ziweixiao@google.com> (raw)
In-Reply-To: <20240507225945.1408516-1-ziweixiao@google.com>
We were depending on the rtnl_lock to make sure there is only one adminq
command running at a time. But some commands may take too long to hold
the rtnl_lock, such as the upcoming flow steering operations. For such
situations, it can temporarily drop the rtnl_lock, and replace it for
these operations with a new adminq lock, which can ensure the adminq
command execution to be thread-safe.
Signed-off-by: Ziwei Xiao <ziweixiao@google.com>
Reviewed-by: Praveen Kaligineedi <pkaligineedi@google.com>
Reviewed-by: Harshitha Ramamurthy <hramamurthy@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
---
drivers/net/ethernet/google/gve/gve.h | 1 +
drivers/net/ethernet/google/gve/gve_adminq.c | 22 +++++++++++---------
2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h
index ae1e21c9b0a5..ca7fce17f2c0 100644
--- a/drivers/net/ethernet/google/gve/gve.h
+++ b/drivers/net/ethernet/google/gve/gve.h
@@ -724,6 +724,7 @@ struct gve_priv {
union gve_adminq_command *adminq;
dma_addr_t adminq_bus_addr;
struct dma_pool *adminq_pool;
+ struct mutex adminq_lock; /* Protects adminq command execution */
u32 adminq_mask; /* masks prod_cnt to adminq size */
u32 adminq_prod_cnt; /* free-running count of AQ cmds executed */
u32 adminq_cmd_fail; /* free-running count of AQ cmds failed */
diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c
index 3df8243680d9..2c3ec5c3b114 100644
--- a/drivers/net/ethernet/google/gve/gve_adminq.c
+++ b/drivers/net/ethernet/google/gve/gve_adminq.c
@@ -284,6 +284,7 @@ int gve_adminq_alloc(struct device *dev, struct gve_priv *priv)
&priv->reg_bar0->adminq_base_address_lo);
iowrite32be(GVE_DRIVER_STATUS_RUN_MASK, &priv->reg_bar0->driver_status);
}
+ mutex_init(&priv->adminq_lock);
gve_set_admin_queue_ok(priv);
return 0;
}
@@ -511,28 +512,29 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
return 0;
}
-/* This function is not threadsafe - the caller is responsible for any
- * necessary locks.
- * The caller is also responsible for making sure there are no commands
- * waiting to be executed.
- */
static int gve_adminq_execute_cmd(struct gve_priv *priv,
union gve_adminq_command *cmd_orig)
{
u32 tail, head;
int err;
+ mutex_lock(&priv->adminq_lock);
tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
head = priv->adminq_prod_cnt;
- if (tail != head)
- // This is not a valid path
- return -EINVAL;
+ if (tail != head) {
+ err = -EINVAL;
+ goto out;
+ }
err = gve_adminq_issue_cmd(priv, cmd_orig);
if (err)
- return err;
+ goto out;
- return gve_adminq_kick_and_wait(priv);
+ err = gve_adminq_kick_and_wait(priv);
+
+out:
+ mutex_unlock(&priv->adminq_lock);
+ return err;
}
/* The device specifies that the management vector can either be the first irq
--
2.45.0.rc1.225.g2a3ae87e7f-goog
next prev parent reply other threads:[~2024-05-07 23:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-07 22:59 [PATCH net-next 0/5] gve: Add flow steering support Ziwei Xiao
2024-05-07 22:59 ` Ziwei Xiao [this message]
2024-05-08 12:07 ` [PATCH net-next 1/5] gve: Add adminq mutex lock Markus Elfring
2024-05-07 22:59 ` [PATCH net-next 2/5] gve: Add adminq extended command Ziwei Xiao
2024-05-08 12:17 ` Markus Elfring
2024-05-11 14:32 ` Simon Horman
2024-05-07 22:59 ` [PATCH net-next 3/5] gve: Add flow steering device option Ziwei Xiao
2024-05-08 5:32 ` David Wei
2024-05-10 0:18 ` Ziwei Xiao
2024-05-08 5:34 ` [PATCH net-next 2/5] gve: Add adminq extended command David Wei
2024-05-10 0:17 ` Ziwei Xiao
2024-05-07 22:59 ` [PATCH net-next 4/5] gve: Add flow steering adminq commands Ziwei Xiao
2024-05-08 6:24 ` David Wei
2024-05-10 0:18 ` Ziwei Xiao
2024-05-20 17:27 ` David Wei
2024-05-08 13:23 ` Markus Elfring
2024-05-08 14:24 ` kernel test robot
2024-05-07 22:59 ` [PATCH net-next 5/5] gve: Add flow steering ethtool support Ziwei Xiao
2024-05-08 14:09 ` Markus Elfring
2024-05-10 0:19 ` Ziwei Xiao
2024-05-10 3:16 ` Jakub Kicinski
2024-05-10 6:45 ` Markus Elfring
2024-05-11 14:45 ` Simon Horman
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=20240507225945.1408516-2-ziweixiao@google.com \
--to=ziweixiao@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hramamurthy@google.com \
--cc=jeroendb@google.com \
--cc=jfraker@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pkaligineedi@google.com \
--cc=rushilg@google.com \
--cc=shailend@google.com \
--cc=willemb@google.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).