[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250630172005.0000747c@huawei.com>
Date: Mon, 30 Jun 2025 17:20:05 +0100
From: Jonathan Cameron <Jonathan.Cameron@...wei.com>
To: Dave Jiang <dave.jiang@...el.com>
CC: <alejandro.lucero-palau@....com>, <linux-cxl@...r.kernel.org>,
<netdev@...r.kernel.org>, <dan.j.williams@...el.com>, <edward.cree@....com>,
<davem@...emloft.net>, <kuba@...nel.org>, <pabeni@...hat.com>,
<edumazet@...gle.com>, Alejandro Lucero <alucerop@....com>
Subject: Re: [PATCH v17 10/22] cx/memdev: Indicate probe deferral
Hi Dave,
> > +/*
> > + * Try to get a locked reference on a memdev's CXL port topology
> > + * connection. Be careful to observe when cxl_mem_probe() has deposited
> > + * a probe deferral awaiting the arrival of the CXL root driver.
> > + */
> > +struct cxl_port *cxl_acquire_endpoint(struct cxl_memdev *cxlmd)
>
Just focusing on this part.
> Annotation of __acquires() is needed here to annotate that this function is taking multiple locks and keeping the locks.
Messy because it's a conditional case and on error we never have
a call marked __releases() so sparse may moan.
In theory we have __cond_acquires() but I think the sparse tooling
is still missing for that.
One option is to hike the thing into a header as inline and use __acquire()
in the appropriate places. Then sparse can see the markings
without problems.
https://lore.kernel.org/all/20250305161652.GA18280@noisy.programming.kicks-ass.net/
has some discussion on fixing the annotation issues around conditional locks
for LLVM but for now I think we are still stuck.
For the original __cond_acquires()
https://lore.kernel.org/all/CAHk-=wjZfO9hGqJ2_hGQG3U_XzSh9_XaXze=HgPdvJbgrvASfA@mail.gmail.com/
Linus posted sparse and kernel support but I think only the kernel bit merged
as sparse is currently (I think) unmaintained.
>
> > +{
> > + struct cxl_port *endpoint;
> > + int rc = -ENXIO;
> > +
> > + device_lock(&cxlmd->dev);
> > +> + endpoint = cxlmd->endpoint;
> > + if (!endpoint)
> > + goto err;
> > +
> > + if (IS_ERR(endpoint)) {
> > + rc = PTR_ERR(endpoint);
> > + goto err;
> > + }
> > +
> > + device_lock(&endpoint->dev);
> > + if (!endpoint->dev.driver)> + goto err_endpoint;
> > +
> > + return endpoint;
> > +
> > +err_endpoint:
> > + device_unlock(&endpoint->dev);
> > +err:
> > + device_unlock(&cxlmd->dev);
> > + return ERR_PTR(rc);
> > +}
> > +EXPORT_SYMBOL_NS_GPL(cxl_acquire_endpoint, "CXL");
> > +
> > +void cxl_release_endpoint(struct cxl_memdev *cxlmd, struct cxl_port *endpoint)
>
> And __releases() here to release the lock annotations
> > +{
> > + device_unlock(&endpoint->dev);
> > + device_unlock(&cxlmd->dev);
> > +}
> > +EXPORT_SYMBOL_NS_GPL(cxl_release_endpoint, "CXL");
Powered by blists - more mailing lists