Re: [PATCH v4 3/3] firmware: qcom: scm: Fix tzmem state on probe retry

Mukesh Ojha <[email protected]>
Newsgroups org.kernel.vger.linux-arm-msm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Thu, Aug 06, 2026 at 04:42:09PM +0530, Mukesh Ojha wrote:
> On Thu, Aug 06, 2026 at 11:27:39AM +0200, Marek Szyprowski wrote:
> > On 24.07.2026 11:49, Mukesh Ojha wrote:
> > > qcom_tzmem_enable() returns -EBUSY if called a second time, but this
> > > causes probe retries to fail permanently if a later step in
> > > qcom_scm_probe() defers after qcom_tzmem_enable() has already succeeded.
> > >
> > > Use DO_ONCE() to ensure qcom_tzmem_init() runs exactly once across all
> > > calls in a thread-safe manner. qcom_tzmem_dev is set on every call since
> > > probe retries use the same device pointer. The result of the first
> > > initialisation is cached and returned to every subsequent caller.
> > >
> > > Fixes: 40289e35ca52 ("firmware: qcom: scm: enable the TZ mem allocator")
> > > Reviewed-by: Bartosz Golaszewski <[email protected]>
> > > Reviewed-by: Konrad Dybcio <[email protected]>
> > > Signed-off-by: Mukesh Ojha <[email protected]>
> > > ---
> > >  drivers/firmware/qcom/qcom_tzmem.c | 13 +++++++++----
> > >  1 file changed, 9 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/firmware/qcom/qcom_tzmem.c b/drivers/firmware/qcom/qcom_tzmem.c
> > > index 0635cbeacfc8..0fd9581275f1 100644
> > > --- a/drivers/firmware/qcom/qcom_tzmem.c
> > > +++ b/drivers/firmware/qcom/qcom_tzmem.c
> > > @@ -15,6 +15,7 @@
> > >  #include <linux/kernel.h>
> > >  #include <linux/list.h>
> > >  #include <linux/mm.h>
> > > +#include <linux/once.h>
> > >  #include <linux/radix-tree.h>
> > >  #include <linux/slab.h>
> > >  #include <linux/spinlock.h>
> > > @@ -507,14 +508,18 @@ phys_addr_t qcom_tzmem_to_phys(void *vaddr)
> > >  }
> > >  EXPORT_SYMBOL_GPL(qcom_tzmem_to_phys);
> > >  
> > > +static void qcom_tzmem_do_init(int *result)
> > > +{
> > > +	*result = qcom_tzmem_init();
> > > +}
> > > +
> > >  int qcom_tzmem_enable(struct device *dev)
> > >  {
> > > -	if (qcom_tzmem_dev)
> > > -		return -EBUSY;
> > > +	static int result;
> > >  
> > >  	qcom_tzmem_dev = dev;
> > > -
> > > -	return qcom_tzmem_init();
> > > +	DO_ONCE(qcom_tzmem_do_init, &result);
> > One should use DO_ONCE_SLEEPABLE() here, otherwise it triggers a warning during
> > boot on some on my test systems. Here is a log captured with
> > CONFIG_DEBUG_ATOMIC_SLEEP=y on recent linux-next releases, where this patch is
> > applied as commit 9941fe8a04f3 ("firmware: qcom: scm: Fix tzmem state on probe
> > retry"):
> 
> Thanks for reporting; I will spin a fix..and yes DO_ONCE_SLEEPABLE() is the right one.
>

Sent the change here https://lore.kernel.org/lkml/[email protected]/

-Mukesh
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.