From nobody Fri Oct 10 13:44:20 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BD152AF19 for ; Sat, 14 Jun 2025 00:08:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749859689; cv=none; b=Yyx39rS6Hx7cXesFSLcrM3TWc5zSJd0KR+3EmwT4zluo0V79s86M/AYd6IrX/TfvW0manoNseu/CnfiU3zKSocANOBjHlYRNWiEO0g6T16k0W8AJV4jcAyfMMOcCib0xt+1Vh2Vka3GnoIN9Fvelvz0ggCr+C0LZl5QDtHPisaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749859689; c=relaxed/simple; bh=1znNIB3u16ieepj82rVPi9LAndQlC4ZRrWSXKxSRCb0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RPp1I3KUo49mlVYpcS0eQegL3IEqi5ob/yILV/Ho7O97qnYaI/03FkyaHTQ6qpt/+03j1iK4QpEHMEB3Zij92yjEa48kAJIIC7Sj33NTcUQc/qeQQdEQrYHhT44aqBuRqpHuWdsYnjJ+ocXWKdguBOH9UIlTH5glYr9Klke9Pzc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--hramamurthy.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=VxppQ7n+; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--hramamurthy.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VxppQ7n+" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7489ac848f3so760400b3a.1 for ; Fri, 13 Jun 2025 17:08:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749859687; x=1750464487; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=R1odHZAHpj6iymdK8bPN6NeFlgVHA1tN8g6qXmugLMo=; b=VxppQ7n+KPojAjsyBsVdggIwzBxxEalhkoKHbwOwLopjkUqIqwACqfKKjvBhb3N48V v1H4ub3I8HrqgGiW8Cp17FsSnZh8xShMAVRq+HapSgdwnbFfOTvABMX+GtnmeE60n+kF YCVwbJgvlGFg17fI4QefhBpI/RFqwt9M4DI+0r21QVxz9olObLZAiiEcgO7tT0jaPP5C nQaUYkR4sXR2ppbko4iDskVSmnQb7MD5MdE8xK4pCVNF5U33pfyNjkEzvxRyI1fR/lkr aXRp3UGtDK28e8Y55sFIl8y8VS21P6sSEX0qNdYAtPg+LB71KKv34FfA8c4hcxZtfmO+ sItA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749859687; x=1750464487; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=R1odHZAHpj6iymdK8bPN6NeFlgVHA1tN8g6qXmugLMo=; b=EVQOimc9jhDJ1o+bqwukROiC6aBDYwT0zO12M6U6YFoBFNQLA3JxCjUdTcNPohCXQh p1xhIzJOJ8AyF1gXbJA0J7ddWgVATMD976f6i3EwNI1BV5HHPsCtQ8SAEbDoMyqHXZrZ Vtwp/+6mNxKjkgcdopHfHA3Qop0ou+7dHV7pgXdJdokzZrrOQXgdljftmVrhRfV5ZIdl XE9i8E64U5U6VspH0rJ6MWyv9Ji+8jR3/torg3mfKDeSRIZieIjmk1Sy2siLNem9YIB0 iSksehSK07NfdSu6rkCpI/sD7Jh2x38os8rdNrCGhPOHVh6/8HMrxvhQC3EIhF+b58e9 jSIw== X-Forwarded-Encrypted: i=1; AJvYcCXUx9A7PL+f/I+ie8aCV8MRd4pI9KLE0wACLOwou7JHe7M57oCZz8a7bmqYnT8sTmpe+ObwWtptAA30DhI=@vger.kernel.org X-Gm-Message-State: AOJu0Yw37R097fczG6C6PHoWR4B7uVacdNtLo3B4qNBou4uOQzgTpQ/f CDEUh3NMOHk+I5ShoffrvQFWvq9eXpnT4JC0o9AAktfLpufcVj3PyKzxzG3wXuKQ81Iz4H8t1pi QmkUkTKLb6HZdf/inzVmdX0cMkA== X-Google-Smtp-Source: AGHT+IH7ciQkm2gQh9f6uUBhI69AkVCgzEFU2c/bchRIarpXJlTId5swmE6bncuVJaYDXMQdZ2uwdNz56xJf5gmmNA== X-Received: from pfhx39.prod.google.com ([2002:a05:6a00:18a7:b0:747:abae:78e8]) (user=hramamurthy job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1acd:b0:740:6fa3:e429 with SMTP id d2e1a72fcca58-7489cfcb063mr1516682b3a.11.1749859687347; Fri, 13 Jun 2025 17:08:07 -0700 (PDT) Date: Sat, 14 Jun 2025 00:07:50 +0000 In-Reply-To: <20250614000754.164827-1-hramamurthy@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250614000754.164827-1-hramamurthy@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250614000754.164827-5-hramamurthy@google.com> Subject: [PATCH net-next v5 4/8] gve: Add adminq lock for queues creation and destruction From: Harshitha Ramamurthy To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jeroendb@google.com, hramamurthy@google.com, andrew+netdev@lunn.ch, willemb@google.com, ziweixiao@google.com, pkaligineedi@google.com, yyd@google.com, joshwash@google.com, shailend@google.com, linux@treblig.org, thostet@google.com, jfraker@google.com, richardcochran@gmail.com, jdamato@fastly.com, vadim.fedorenko@linux.dev, horms@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ziwei Xiao Adminq commands for queues creation and destruction were not consistently protected by the driver's adminq_lock. This was previously benign as these operations were always initiated from contexts holding kernel-level locks (e.g., rtnl_lock, netdev_lock), which provided serialization. Upcoming PTP aux_work will issue adminq commands directly from the driver to read the NIC clock, without such kernel lock protection. To prevent race conditions with this new PTP work, this patch ensures the adminq_lock is held during queues creation and destruction. Signed-off-by: Ziwei Xiao Reviewed-by: Willem de Bruijn Signed-off-by: Harshitha Ramamurthy --- Changes in v2: - Send this patch together with the rx timestamping patches to net-next instead of sending it to net (Jakub Kicinski) - Remove the unnecessary cleanup (Jakub Kicinski) --- drivers/net/ethernet/google/gve/gve_adminq.c | 47 +++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/eth= ernet/google/gve/gve_adminq.c index f57913a673b4..a0cc05a9eefc 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -463,6 +463,8 @@ static int gve_adminq_kick_and_wait(struct gve_priv *pr= iv) int tail, head; int i; =20 + lockdep_assert_held(&priv->adminq_lock); + tail =3D ioread32be(&priv->reg_bar0->adminq_event_counter); head =3D priv->adminq_prod_cnt; =20 @@ -488,9 +490,6 @@ static int gve_adminq_kick_and_wait(struct gve_priv *pr= iv) return 0; } =20 -/* This function is not threadsafe - the caller is responsible for any - * necessary locks. - */ static int gve_adminq_issue_cmd(struct gve_priv *priv, union gve_adminq_command *cmd_orig) { @@ -498,6 +497,8 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv, u32 opcode; u32 tail; =20 + lockdep_assert_held(&priv->adminq_lock); + tail =3D ioread32be(&priv->reg_bar0->adminq_event_counter); =20 // Check if next command will overflow the buffer. @@ -733,13 +734,19 @@ int gve_adminq_create_tx_queues(struct gve_priv *priv= , u32 start_id, u32 num_que int err; int i; =20 + mutex_lock(&priv->adminq_lock); + for (i =3D start_id; i < start_id + num_queues; i++) { err =3D gve_adminq_create_tx_queue(priv, i); if (err) - return err; + goto out; } =20 - return gve_adminq_kick_and_wait(priv); + err =3D gve_adminq_kick_and_wait(priv); + +out: + mutex_unlock(&priv->adminq_lock); + return err; } =20 static void gve_adminq_get_create_rx_queue_cmd(struct gve_priv *priv, @@ -812,13 +819,19 @@ int gve_adminq_create_rx_queues(struct gve_priv *priv= , u32 num_queues) int err; int i; =20 + mutex_lock(&priv->adminq_lock); + for (i =3D 0; i < num_queues; i++) { err =3D gve_adminq_create_rx_queue(priv, i); if (err) - return err; + goto out; } =20 - return gve_adminq_kick_and_wait(priv); + err =3D gve_adminq_kick_and_wait(priv); + +out: + mutex_unlock(&priv->adminq_lock); + return err; } =20 static int gve_adminq_destroy_tx_queue(struct gve_priv *priv, u32 queue_in= dex) @@ -844,13 +857,19 @@ int gve_adminq_destroy_tx_queues(struct gve_priv *pri= v, u32 start_id, u32 num_qu int err; int i; =20 + mutex_lock(&priv->adminq_lock); + for (i =3D start_id; i < start_id + num_queues; i++) { err =3D gve_adminq_destroy_tx_queue(priv, i); if (err) - return err; + goto out; } =20 - return gve_adminq_kick_and_wait(priv); + err =3D gve_adminq_kick_and_wait(priv); + +out: + mutex_unlock(&priv->adminq_lock); + return err; } =20 static void gve_adminq_make_destroy_rx_queue_cmd(union gve_adminq_command = *cmd, @@ -885,13 +904,19 @@ int gve_adminq_destroy_rx_queues(struct gve_priv *pri= v, u32 num_queues) int err; int i; =20 + mutex_lock(&priv->adminq_lock); + for (i =3D 0; i < num_queues; i++) { err =3D gve_adminq_destroy_rx_queue(priv, i); if (err) - return err; + goto out; } =20 - return gve_adminq_kick_and_wait(priv); + err =3D gve_adminq_kick_and_wait(priv); + +out: + mutex_unlock(&priv->adminq_lock); + return err; } =20 static void gve_set_default_desc_cnt(struct gve_priv *priv, --=20 2.50.0.rc1.591.g9c95f17f64-goog