From: Leon Romanovsky <leon@kernel.org>
To: Shiraz Saleem <shirazsaleem@microsoft.com>
Cc: Konstantin Taranov <kotaranov@linux.microsoft.com>,
Konstantin Taranov <kotaranov@microsoft.com>,
"pabeni@redhat.com" <pabeni@redhat.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
KY Srinivasan <kys@microsoft.com>,
"edumazet@google.com" <edumazet@google.com>,
"kuba@kernel.org" <kuba@kernel.org>,
"davem@davemloft.net" <davem@davemloft.net>,
Dexuan Cui <decui@microsoft.com>,
"wei.liu@kernel.org" <wei.liu@kernel.org>,
Long Li <longli@microsoft.com>, "jgg@ziepe.ca" <jgg@ziepe.ca>,
"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH rdma-next 4/4] net: mana: Add support for auxiliary device servicing events
Date: Thu, 24 Apr 2025 13:49:12 +0300 [thread overview]
Message-ID: <20250424104912.GR48485@unreal> (raw)
In-Reply-To: <BL1PR21MB3089EF4639B5CC2AD5E70B96C9852@BL1PR21MB3089.namprd21.prod.outlook.com>
On Thu, Apr 24, 2025 at 02:33:24AM +0000, Shiraz Saleem wrote:
> > Subject: [EXTERNAL] Re: [PATCH rdma-next 4/4] net: mana: Add support for
> > auxiliary device servicing events
> >
> > On Mon, Apr 14, 2025 at 11:28:49AM -0700, Konstantin Taranov wrote:
> > > From: Shiraz Saleem <shirazsaleem@microsoft.com>
> > >
> > > Handle soc servcing events which require the rdma auxiliary device
> > > resources to be cleaned up during a suspend, and re-initialized during a
> > resume.
> > >
> > > Signed-off-by: Shiraz Saleem <shirazsaleem@microsoft.com>
> > > Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>
> > > ---
> > > .../net/ethernet/microsoft/mana/gdma_main.c | 11 +++-
> > > .../net/ethernet/microsoft/mana/hw_channel.c | 19 ++++++
> > > drivers/net/ethernet/microsoft/mana/mana_en.c | 60
> > +++++++++++++++++++
> > > include/net/mana/gdma.h | 18 ++++++
> > > include/net/mana/hw_channel.h | 9 +++
> > > 5 files changed, 116 insertions(+), 1 deletion(-)
> >
> > <...>
> >
> > > @@ -1474,6 +1481,8 @@ static void mana_gd_cleanup(struct pci_dev
> > *pdev)
> > > mana_hwc_destroy_channel(gc);
> > >
> > > mana_gd_remove_irqs(pdev);
> > > +
> > > + destroy_workqueue(gc->service_wq);
> > > }
> >
> > <...>
> >
> > > +static void mana_handle_rdma_servicing(struct work_struct *work) {
> > > + struct mana_service_work *serv_work =
> > > + container_of(work, struct mana_service_work, work);
> > > + struct gdma_dev *gd = serv_work->gdma_dev;
> > > + struct device *dev = gd->gdma_context->dev;
> > > + int ret;
> > > +
> > > + switch (serv_work->event) {
> > > + case GDMA_SERVICE_TYPE_RDMA_SUSPEND:
> > > + if (!gd->adev || gd->is_suspended)
> > > + break;
> > > +
> > > + remove_adev(gd);
> > > + gd->is_suspended = true;
> > > + break;
> > > +
> > > + case GDMA_SERVICE_TYPE_RDMA_RESUME:
> > > + if (!gd->is_suspended)
> > > + break;
> > > +
> > > + ret = add_adev(gd, "rdma");
> > > + if (ret)
> > > + dev_err(dev, "Failed to add adev on resume: %d\n",
> > ret);
> > > + else
> > > + gd->is_suspended = false;
> > > + break;
> > > +
> > > + default:
> > > + dev_warn(dev, "unknown adev service event %u\n",
> > > + serv_work->event);
> > > + break;
> > > + }
> > > +
> > > + kfree(serv_work);
> >
> > The series looks ok to me, except one question. Are you sure that it is safe to
> > have not-connected and not-locked general work while
> > add_adev/remove_adev can be called in parallel from different thread? For
> > example getting event GDMA_SERVICE_TYPE_RDMA_SUSPEND while
> > mana_gd_probe() fails or some other intervention with PCI
> > (GDMA_SERVICE_TYPE_RDMA_SUSPEND and PCI shutdown).
> >
> > What type of protection do you have here?
> >
> Hi Leon,
>
> Thanks for spotting this.
>
> There are two cases.
>
> -Probe / Resume
> add_adev() stores gd->adev only after auxiliary_device_add() succeeds.
> While gd->adev is still NULL the worker drops any GDMA_SERVICE_TYPE_RDMA_SUSPEND event, so an early suspend that arrives during probe is harmless and cannot race with the later add_adev().
>
> -Remove / Suspend / Shutdown
> During teardown the worker may still be inside add_adev()/remove_adev() while the PCI thread starts its own remove_adev().
>
> In v2 I ll serialize them with flag + flush pattern.
>
> void mana_rdma_remove(struct gdma_dev *gd)
> {
> [....]
> WRITE_ONCE(gd->rdma_teardown, true); /* block new events */
> flush_workqueue(gc->service_wq); /* wait running worker */
>
> if (gd->adev)
> remove_adev(gd);
>
> [....]
> }
> i.e. during teardown, we stop the producer and drain the queue
>
> and,
>
> static void mana_handle_rdma_servicing(struct work_struct *work)
> {
> [....]
> if (READ_ONCE(gd->rdma_teardown))
> goto out;
> [.....]
> }
> The flag blocks any new work, and flush_workqueue() waits for anything already running. This serialises the two paths and removes
> the race you pointed out.
Yes, I also think that it solves, so let's post v2 please.
Just remember that WRITE_ONCE/READ_ONCE is not a replacement for locks.
Thanks
>
> Shiraz
>
prev parent reply other threads:[~2025-04-24 10:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-14 18:28 [PATCH rdma-next 0/4] RDMA/mana_ib: allow separate mana_ib for each mana client Konstantin Taranov
2025-04-14 18:28 ` [PATCH rdma-next 1/4] net: mana: Probe rdma device in mana driver Konstantin Taranov
2025-04-14 18:28 ` [PATCH rdma-next 2/4] RDMA/mana_ib: Add support of mana_ib for RNIC and ETH nic Konstantin Taranov
2025-04-14 18:28 ` [PATCH rdma-next 3/4] RDMA/mana_ib: unify mana_ib functions to support any gdma device Konstantin Taranov
2025-04-14 18:28 ` [PATCH rdma-next 4/4] net: mana: Add support for auxiliary device servicing events Konstantin Taranov
2025-04-20 10:53 ` Leon Romanovsky
2025-04-24 2:33 ` Shiraz Saleem
2025-04-24 10:49 ` Leon Romanovsky [this message]
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=20250424104912.GR48485@unreal \
--to=leon@kernel.org \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=edumazet@google.com \
--cc=haiyangz@microsoft.com \
--cc=jgg@ziepe.ca \
--cc=kotaranov@linux.microsoft.com \
--cc=kotaranov@microsoft.com \
--cc=kuba@kernel.org \
--cc=kys@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=longli@microsoft.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shirazsaleem@microsoft.com \
--cc=wei.liu@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.