From: Simon Horman <horms@kernel.org>
To: Suman Ghosh <sumang@marvell.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, sgoutham@marvell.com, sbhatta@marvell.com,
jerinj@marvell.com, gakula@marvell.com, hkelam@marvell.com,
lcherian@marvell.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [net-next PATCH] octeontx2-af: Fix multicast/mirror group lock/unlock issue
Date: Tue, 12 Dec 2023 11:16:01 +0000 [thread overview]
Message-ID: <20231212111601.GY5817@kernel.org> (raw)
In-Reply-To: <20231212091558.49579-1-sumang@marvell.com>
On Tue, Dec 12, 2023 at 02:45:58PM +0530, Suman Ghosh wrote:
> As per the existing implementation, there exists a race between finding
> a multicast/mirror group entry and deleting that entry. The group lock
> was taken and released independently by rvu_nix_mcast_find_grp_elem()
> function. Which is incorrect and group lock should be taken during the
> entire operation of group updation/deletion. This patch fixes the same.
>
> Fixes: 51b2804c19cd ("octeontx2-af: Add new mbox to support multicast/mirror offload")
> Signed-off-by: Suman Ghosh <sumang@marvell.com>
...
> @@ -6306,6 +6310,13 @@ int rvu_mbox_handler_nix_mcast_grp_destroy(struct rvu *rvu,
> return err;
>
> mcast_grp = &nix_hw->mcast_grp;
> +
> + /* If AF is requesting for the deletion,
> + * then AF is already taking the lock
> + */
> + if (!req->is_af)
> + mutex_lock(&mcast_grp->mcast_grp_lock);
> +
> elem = rvu_nix_mcast_find_grp_elem(mcast_grp, req->mcast_grp_idx);
> if (!elem)
Hi Suman,
Does mcast_grp_lock need to be released here?
If so, I would suggest a goto label, say unlock_grp.
> return NIX_AF_ERR_INVALID_MCAST_GRP;
> @@ -6333,12 +6344,6 @@ int rvu_mbox_handler_nix_mcast_grp_destroy(struct rvu *rvu,
> mutex_unlock(&mcast->mce_lock);
>
> delete_grp:
> - /* If AF is requesting for the deletion,
> - * then AF is already taking the lock
> - */
> - if (!req->is_af)
> - mutex_lock(&mcast_grp->mcast_grp_lock);
> -
> list_del(&elem->list);
> kfree(elem);
> mcast_grp->count--;
> @@ -6370,9 +6375,20 @@ int rvu_mbox_handler_nix_mcast_grp_update(struct rvu *rvu,
> return err;
>
> mcast_grp = &nix_hw->mcast_grp;
> +
> + /* If AF is requesting for the updation,
> + * then AF is already taking the lock
> + */
> + if (!req->is_af)
> + mutex_lock(&mcast_grp->mcast_grp_lock);
> +
> elem = rvu_nix_mcast_find_grp_elem(mcast_grp, req->mcast_grp_idx);
> - if (!elem)
> + if (!elem) {
> + if (!req->is_af)
> + mutex_unlock(&mcast_grp->mcast_grp_lock);
> +
> return NIX_AF_ERR_INVALID_MCAST_GRP;
> + }
>
> /* If any pcifunc matches the group's pcifunc, then we can
> * delete the entire group.
> @@ -6383,8 +6399,11 @@ int rvu_mbox_handler_nix_mcast_grp_update(struct rvu *rvu,
> /* Delete group */
> dreq.hdr.pcifunc = elem->pcifunc;
> dreq.mcast_grp_idx = elem->mcast_grp_idx;
> - dreq.is_af = req->is_af;
> + dreq.is_af = 1;
> rvu_mbox_handler_nix_mcast_grp_destroy(rvu, &dreq, NULL);
> + if (!req->is_af)
> + mutex_unlock(&mcast_grp->mcast_grp_lock);
> +
> return 0;
> }
> }
> @@ -6467,5 +6486,8 @@ int rvu_mbox_handler_nix_mcast_grp_update(struct rvu *rvu,
>
> done:
I think it would be good to rename this label, say unlock_mce;
> mutex_unlock(&mcast->mce_lock);
Add a new label here, say unlock_grp;
And jump to this label whenever there is a need for the mutex_unlock() below.
> + if (!req->is_af)
> + mutex_unlock(&mcast_grp->mcast_grp_lock);
> +
> return ret;
> }
> --
> 2.25.1
>
next prev parent reply other threads:[~2023-12-12 11:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-12 9:15 [net-next PATCH] octeontx2-af: Fix multicast/mirror group lock/unlock issue Suman Ghosh
2023-12-12 11:16 ` Simon Horman [this message]
2023-12-13 4:52 ` [EXT] " Suman Ghosh
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=20231212111601.GY5817@kernel.org \
--to=horms@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gakula@marvell.com \
--cc=hkelam@marvell.com \
--cc=jerinj@marvell.com \
--cc=kuba@kernel.org \
--cc=lcherian@marvell.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sbhatta@marvell.com \
--cc=sgoutham@marvell.com \
--cc=sumang@marvell.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 NNTP newsgroup(s).