mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Jijie Shao <shaojijie@huawei.com>
Cc: Kalesh Anakkur Purayil <kalesh-anakkur.purayil@broadcom.com>,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, shenjian15@huawei.com,
	wangpeiyang1@huawei.com, liuyonglong@huawei.com,
	chenhao418@huawei.com, sudongming1@huawei.com,
	xujunsheng@huawei.com, shiyongbang@huawei.com,
	libaihan@huawei.com, zhuyuan@huawei.com,
	forest.zhouchang@huawei.com, jdamato@fastly.com,
	horms@kernel.org, jonathan.cameron@huawei.com,
	shameerali.kolothum.thodi@huawei.com, salil.mehta@huawei.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH V8 net-next 05/11] net: hibmcge: Implement some .ndo functions
Date: Mon, 9 Sep 2024 14:19:39 +0200	[thread overview]
Message-ID: <fec0a530-64d9-401c-bb43-4c5670587909@lunn.ch> (raw)
In-Reply-To: <116bff77-f12f-43f0-8325-b513a6779a55@huawei.com>

On Mon, Sep 09, 2024 at 12:04:53PM +0800, Jijie Shao wrote:
> 
> on 2024/9/9 11:05, Kalesh Anakkur Purayil wrote:
> > On Mon, Sep 9, 2024 at 8:11 AM Jijie Shao <shaojijie@huawei.com> wrote:
> > > +}
> > > +
> > > +static int hbg_net_open(struct net_device *netdev)
> > > +{
> > > +       struct hbg_priv *priv = netdev_priv(netdev);
> > > +
> > > +       if (test_and_set_bit(HBG_NIC_STATE_OPEN, &priv->state))
> > > +               return 0;
> > [Kalesh] Is there a possibility that dev_open() can be invoked twice?
> 
> We want stop NIC when chang_mtu 、self_test or FLR.
> So, driver will directly invoke hbg_net_stop() not dev_open() if need.
> Therefore, driver must ensure that hbg_net_open() or hbg_net_stop() can not be invoked twice.

Generally, we don't want defensive programming. You seem to suggest
hbg_net_open and hbg_net_stop are called in pairs. If this is not
true, you have a bug? Rather than paper over the bug with a return,
let bad things happen so the bug is obvious.

> > > +
> > > +       hbg_all_irq_enable(priv, true);
> > > +       hbg_hw_mac_enable(priv, HBG_STATUS_ENABLE);
> > > +       netif_start_queue(netdev);
> > > +       hbg_phy_start(priv);
> > > +
> > > +       return 0;
> > > +}
> > > +
> > > +static int hbg_net_stop(struct net_device *netdev)
> > > +{
> > > +       struct hbg_priv *priv = netdev_priv(netdev);
> > > +
> > > +       if (!hbg_nic_is_open(priv))
> > > +               return 0;
> > [Kalesh] Is there any reason to not check HBG_NIC_STATE_OPEN here?
> 
> Actually, hbg_nic_is_open() is used to check HBG_NIC_STATE_OPEN.
> :
> #define hbg_nic_is_open(priv) test_bit(HBG_NIC_STATE_OPEN, &(priv)->state)

Which is horrible. Why hide this, when it is in full view in other
places.

Please take a step back. Take time to understand the driver locking
with RTNL, look at what state is already available, and try very hard
to remove priv->state.

> 
> > > +
> > > +       clear_bit(HBG_NIC_STATE_OPEN, &priv->state);
> > > +

While we are at it, why is there not a race condition here between
testing and clearing the bit?

> > > +       hbg_phy_stop(priv);
> > > +       netif_stop_queue(netdev);
> > > +       hbg_hw_mac_enable(priv, HBG_STATUS_DISABLE);
> > > +       hbg_all_irq_enable(priv, false);
> > > +
> > > +       return 0;
> > > +}
> > > +
> > > +static int hbg_net_change_mtu(struct net_device *netdev, int new_mtu)
> > > +{
> > > +       struct hbg_priv *priv = netdev_priv(netdev);
> > > +       bool is_opened = hbg_nic_is_open(priv);
> > > +
> > > +       hbg_net_stop(netdev);
> > [Kalesh] Do you still need to call stop when NIC is not opened yet?
> > Instead of a new variable, I think you can check netif_running here.

Correct. running is used by every driver, it has withstood years of
testing, so is guaranteed to be set/cleared in race free ways. It
should be used instead of this racy priv->state.

	Andrew

  reply	other threads:[~2024-09-09 12:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-09  2:31 [PATCH V8 net-next 00/11] Add support of HIBMCGE Ethernet Driver Jijie Shao
2024-09-09  2:31 ` [PATCH V8 net-next 01/11] net: hibmcge: Add pci table supported in this module Jijie Shao
2024-09-09  2:31 ` [PATCH V8 net-next 02/11] net: hibmcge: Add read/write registers supported through the bar space Jijie Shao
2024-09-09  2:31 ` [PATCH V8 net-next 03/11] net: hibmcge: Add mdio and hardware configuration supported in this module Jijie Shao
2024-09-09  2:31 ` [PATCH V8 net-next 04/11] net: hibmcge: Add interrupt " Jijie Shao
2024-09-09  2:31 ` [PATCH V8 net-next 05/11] net: hibmcge: Implement some .ndo functions Jijie Shao
2024-09-09  3:05   ` Kalesh Anakkur Purayil
2024-09-09  4:04     ` Jijie Shao
2024-09-09 12:19       ` Andrew Lunn [this message]
2024-09-09 14:30         ` Jijie Shao
2024-09-09 14:48           ` Andrew Lunn
2024-09-10  6:26             ` Jijie Shao
2024-09-09  2:31 ` [PATCH V8 net-next 06/11] net: hibmcge: Implement .ndo_start_xmit function Jijie Shao
2024-09-09  2:31 ` [PATCH V8 net-next 07/11] net: hibmcge: Implement rx_poll function to receive packets Jijie Shao
2024-09-09  2:31 ` [PATCH V8 net-next 08/11] net: hibmcge: Implement some ethtool_ops functions Jijie Shao
2024-09-09  2:31 ` [PATCH V8 net-next 09/11] net: hibmcge: Add a Makefile and update Kconfig for hibmcge Jijie Shao
2024-09-09  2:31 ` [PATCH V8 net-next 10/11] net: hibmcge: Add maintainer " Jijie Shao
2024-09-09  2:31 ` [PATCH V8 net-next 11/11] net: add ndo_validate_addr check in dev_set_mac_address Jijie Shao

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=fec0a530-64d9-401c-bb43-4c5670587909@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=chenhao418@huawei.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=forest.zhouchang@huawei.com \
    --cc=horms@kernel.org \
    --cc=jdamato@fastly.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=kalesh-anakkur.purayil@broadcom.com \
    --cc=kuba@kernel.org \
    --cc=libaihan@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuyonglong@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=salil.mehta@huawei.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=shaojijie@huawei.com \
    --cc=shenjian15@huawei.com \
    --cc=shiyongbang@huawei.com \
    --cc=sudongming1@huawei.com \
    --cc=wangpeiyang1@huawei.com \
    --cc=xujunsheng@huawei.com \
    --cc=zhuyuan@huawei.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

all inboxes | Powered by JetHome®