public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: devnull+satishkh.cisco.com@kernel.org
Cc: Jakub Kicinski <kuba@kernel.org>,
	satishkh@cisco.com, andrew+netdev@lunn.ch, davem@davemloft.net,
	edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v2 4/6] enic: make enic_dev_enable/disable ref-counted
Date: Sun, 29 Mar 2026 13:13:37 -0700	[thread overview]
Message-ID: <20260329201337.2798745-1-kuba@kernel.org> (raw)
In-Reply-To: <20260325-enic-sriov-v2-prep-v2-4-f72cf716ebfa@cisco.com>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
enic: make enic_dev_enable/disable ref-counted

Both the data path (ndo_open/ndo_stop) and the upcoming admin channel
need to enable and disable the vNIC device independently. Without
reference counting, closing the admin channel while the netdev is up
would inadvertently disable the entire device.

[ ... ]
> diff --git a/drivers/net/ethernet/cisco/enic/enic_dev.c b/drivers/net/ethernet/cisco/enic/enic_dev.c
> index 2cbae7c6cc3d6..659787f73cf18 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_dev.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_dev.c
> @@ -131,10 +131,13 @@ int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic)
>  
>  int enic_dev_enable(struct enic *enic)
>  {
> -	int err;
> +	int err = 0;
>  
>  	spin_lock_bh(&enic->devcmd_lock);
> -	err = vnic_dev_enable_wait(enic->vdev);
> +	if (enic->enable_count == 0)
> +		err = vnic_dev_enable_wait(enic->vdev);
> +	if (!err)
> +		enic->enable_count++;
>  	spin_unlock_bh(&enic->devcmd_lock);
>  
>  	return err;
> @@ -142,10 +145,16 @@ int enic_dev_enable(struct enic *enic)
>  
>  int enic_dev_disable(struct enic *enic)
>  {
> -	int err;
> +	int err = 0;
>  
>  	spin_lock_bh(&enic->devcmd_lock);
> -	err = vnic_dev_disable(enic->vdev);
> +	if (enic->enable_count == 0) {
> +		spin_unlock_bh(&enic->devcmd_lock);
> +		return 0;
> +	}
> +	enic->enable_count--;
> +	if (enic->enable_count == 0)
> +		err = vnic_dev_disable(enic->vdev);
>  	spin_unlock_bh(&enic->devcmd_lock);
>  
>  	return err;

If vnic_dev_enable_wait() fails, enable_count remains 0. However, the data
path caller enic_open() ignores the return value of enic_dev_enable() and
unconditionally returns 0:

drivers/net/ethernet/cisco/enic/enic_main.c:enic_open() {
    ...
	enic_dev_enable(enic);

	for (i = 0; i < enic->intr_count; i++)
		vnic_intr_unmask(&enic->intr[i]);
    ...
	return 0;
}

Can this cause the device reference count to become unbalanced?

If enic_dev_enable() fails during enic_open(), the interface is marked
logically up but enable_count remains 0. If enic_stop() is called later,
enic_dev_disable() will return early since the count is 0, skipping the
hardware disable command.

Additionally, if the new admin channel calls enic_dev_enable() while
the device is in this state, it will increment the count from 0 to 1.
When the admin channel later calls enic_dev_disable(), the count will
drop back to 0 and issue vnic_dev_disable(), incorrectly disabling the
hardware while the netdev data path is still up.

Should enic_open() check the return value of enic_dev_enable() and
handle failures appropriately, or should the enable_count be incremented
regardless of the hardware command success to keep the logical states
aligned?
-- 
pw-bot: cr

  reply	other threads:[~2026-03-29 20:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-26  5:18 [PATCH net-next v2 0/6] enic: SR-IOV V2 preparatory infrastructure Satish Kharat via B4 Relay
2026-03-26  5:18 ` [PATCH net-next v2 1/6] enic: extend resource discovery for SR-IOV admin channel Satish Kharat via B4 Relay
2026-03-26  5:19 ` [PATCH net-next v2 2/6] enic: add V2 SR-IOV VF device ID Satish Kharat via B4 Relay
2026-03-26  5:19 ` [PATCH net-next v2 3/6] enic: detect SR-IOV VF type from PCI capability Satish Kharat via B4 Relay
2026-03-26  5:19 ` [PATCH net-next v2 4/6] enic: make enic_dev_enable/disable ref-counted Satish Kharat via B4 Relay
2026-03-29 20:13   ` Jakub Kicinski [this message]
2026-03-26  5:19 ` [PATCH net-next v2 5/6] enic: add type-aware alloc for WQ, RQ, CQ and INTR resources Satish Kharat via B4 Relay
2026-03-26  5:19 ` [PATCH net-next v2 6/6] enic: detect admin channel resources for SR-IOV Satish Kharat via B4 Relay
2026-03-29 20:13   ` Jakub Kicinski

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=20260329201337.2798745-1-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devnull+satishkh.cisco.com@kernel.org \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=satishkh@cisco.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