Netdev List
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Jijie Shao <shaojijie@huawei.com>,
	yisen.zhuang@huawei.com,  salil.mehta@huawei.com,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org
Cc: shenjian15@huawei.com, wangjie125@huawei.com,
	liuyonglong@huawei.com,  netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net 1/7] net: hns3: fix add VLAN fail issue
Date: Thu, 02 Nov 2023 11:31:22 +0100	[thread overview]
Message-ID: <6603e0480feea2e7a28a865705da52bb99679a35.camel@redhat.com> (raw)
In-Reply-To: <20231028025917.314305-2-shaojijie@huawei.com>

On Sat, 2023-10-28 at 10:59 +0800, Jijie Shao wrote:
> From: Jian Shen <shenjian15@huawei.com>
> 
> The hclge_sync_vlan_filter is called in periodic task,
> trying to remove VLAN from vlan_del_fail_bmap. It can
> be concurrence with VLAN adding operation from user.
> So once user failed to delete a VLAN id, and add it
> again soon, it may be removed by the periodic task,
> which may cause the software configuration being
> inconsistent with hardware. So add mutex handling
> to avoid this.
> 
>      user                        hns3 driver
> 
>                                            periodic task
>                                                 │
>   add vlan 10 ───── hns3_vlan_rx_add_vid        │
>        │             (suppose success)          │
>        │                                        │
>   del vlan 10 ─────  hns3_vlan_rx_kill_vid      │
>        │           (suppose fail,add to         │
>        │             vlan_del_fail_bmap)        │
>        │                                        │
>   add vlan 10 ───── hns3_vlan_rx_add_vid        │
>                      (suppose success)          │
>                                        foreach vlan_del_fail_bmp
>                                             del vlan 10
> 
> Fixes: fe4144d47eef ("net: hns3: sync VLAN filter entries when kill VLAN ID failed")
> Signed-off-by: Jian Shen <shenjian15@huawei.com>
> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
> ---
>  .../hisilicon/hns3/hns3pf/hclge_main.c        | 21 +++++++++++++------
>  .../hisilicon/hns3/hns3vf/hclgevf_main.c      | 11 ++++++++--
>  2 files changed, 24 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
> index c42574e29747..a3230ac928a9 100644
> --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
> @@ -10026,8 +10026,6 @@ static void hclge_rm_vport_vlan_table(struct hclge_vport *vport, u16 vlan_id,
>  	struct hclge_vport_vlan_cfg *vlan, *tmp;
>  	struct hclge_dev *hdev = vport->back;
>  
> -	mutex_lock(&hdev->vport_lock);
> -
>  	list_for_each_entry_safe(vlan, tmp, &vport->vlan_list, node) {
>  		if (vlan->vlan_id == vlan_id) {
>  			if (is_write_tbl && vlan->hd_tbl_status)
> @@ -10042,8 +10040,6 @@ static void hclge_rm_vport_vlan_table(struct hclge_vport *vport, u16 vlan_id,
>  			break;
>  		}
>  	}
> -
> -	mutex_unlock(&hdev->vport_lock);
>  }
>  
>  void hclge_rm_vport_all_vlan_table(struct hclge_vport *vport, bool is_del_list)
> @@ -10452,11 +10448,16 @@ int hclge_set_vlan_filter(struct hnae3_handle *handle, __be16 proto,
>  	 * handle mailbox. Just record the vlan id, and remove it after
>  	 * reset finished.
>  	 */
> +	mutex_lock(&hdev->vport_lock);
>  	if ((test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state) ||
>  	     test_bit(HCLGE_STATE_RST_FAIL, &hdev->state)) && is_kill) {
>  		set_bit(vlan_id, vport->vlan_del_fail_bmap);
> +		mutex_unlock(&hdev->vport_lock);
>  		return -EBUSY;
> +	} else if (!is_kill && test_bit(vlan_id, vport->vlan_del_fail_bmap)) {
> +		clear_bit(vlan_id, vport->vlan_del_fail_bmap);
>  	}
> +	mutex_unlock(&hdev->vport_lock);
>  
>  	/* when port base vlan enabled, we use port base vlan as the vlan
>  	 * filter entry. In this case, we don't update vlan filter table
> @@ -10481,7 +10482,9 @@ int hclge_set_vlan_filter(struct hnae3_handle *handle, __be16 proto,
>  		 * and try to remove it from hw later, to be consistence
>  		 * with stack
>  		 */
> +		mutex_lock(&hdev->vport_lock);
>  		set_bit(vlan_id, vport->vlan_del_fail_bmap);
> +		mutex_unlock(&hdev->vport_lock);

It looks like that the 'hclge_rm_vport_vlan_table()' call a few lines
above will now happen with the vport_lock unlocked.

That looks racy and would deserve at least a comment explaining why
it's safe.

Thanks,

Paolo


  reply	other threads:[~2023-11-02 10:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-28  2:59 [PATCH net 0/7] There are some bugfix for the HNS3 ethernet driver Jijie Shao
2023-10-28  2:59 ` [PATCH net 1/7] net: hns3: fix add VLAN fail issue Jijie Shao
2023-11-02 10:31   ` Paolo Abeni [this message]
2023-11-02 12:29     ` Jijie Shao
2023-10-28  2:59 ` [PATCH net 2/7] net: hns3: add barrier in vf mailbox reply process Jijie Shao
2023-10-28  2:59 ` [PATCH net 3/7] net: hns3: fix incorrect capability bit display for copper port Jijie Shao
2023-10-28  2:59 ` [PATCH net 4/7] net: hns3: fix out-of-bounds access may occur when coalesce info is read via debugfs Jijie Shao
2023-10-28  2:59 ` [PATCH net 5/7] net: hns3: fix variable may not initialized problem in hns3_init_mac_addr() Jijie Shao
2023-10-28  2:59 ` [PATCH net 6/7] net: hns3: fix VF reset fail issue Jijie Shao
2023-11-02 10:45   ` Paolo Abeni
2023-11-02 12:16     ` Jijie Shao
2023-11-02 16:24       ` Paolo Abeni
2023-10-28  2:59 ` [PATCH net 7/7] net: hns3: fix VF wrong speed and duplex issue 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=6603e0480feea2e7a28a865705da52bb99679a35.camel@redhat.com \
    --to=pabeni@redhat.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuyonglong@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=salil.mehta@huawei.com \
    --cc=shaojijie@huawei.com \
    --cc=shenjian15@huawei.com \
    --cc=wangjie125@huawei.com \
    --cc=yisen.zhuang@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