[PATCH 5/6] mailbox: pcc: Initialize SHMEM before binding the channel with the client

Sudeep Holla posted 6 patches 3 months, 3 weeks ago
[PATCH 5/6] mailbox: pcc: Initialize SHMEM before binding the channel with the client
Posted by Sudeep Holla 3 months, 3 weeks ago
The PCC channel's shared memory region must be set up before the
mailbox controller binds the channel with the client, as the binding
process may trigger client operations like startup() that may rely on
SHMEM being initialized.

Reorder the setup sequence to ensure the shared memory is ready before
binding. Initialize and map the PCC shared memory (SHMEM) prior to
calling mbox_bind_client() so that clients never observe an uninitialized
or NULL SHMEM during bind-time callbacks or early use in startup().

This makes the PCC mailbox channel bring-up order consistent and
eliminates a race between SHMEM setup and client binding.

This will be needed in channel startup to clear/acknowledge any pending
interrupts before enabling them.

Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/mailbox/pcc.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c
index 33bd2d05704b..2829ec51b47f 100644
--- a/drivers/mailbox/pcc.c
+++ b/drivers/mailbox/pcc.c
@@ -378,18 +378,20 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id)
 		return ERR_PTR(-EBUSY);
 	}
 
-	rc = mbox_bind_client(chan, cl);
-	if (rc)
-		return ERR_PTR(rc);
-
 	pcc_mchan = &pchan->chan;
 	pcc_mchan->shmem = acpi_os_ioremap(pcc_mchan->shmem_base_addr,
 					   pcc_mchan->shmem_size);
-	if (pcc_mchan->shmem)
-		return pcc_mchan;
+	if (!pcc_mchan->shmem)
+		return ERR_PTR(-ENXIO);
 
-	mbox_free_channel(chan);
-	return ERR_PTR(-ENXIO);
+	rc = mbox_bind_client(chan, cl);
+	if (rc) {
+		iounmap(pcc_mchan->shmem);
+		pcc_mchan->shmem = NULL;
+		return ERR_PTR(rc);
+	}
+
+	return pcc_mchan;
 }
 EXPORT_SYMBOL_GPL(pcc_mbox_request_channel);
 

-- 
2.34.1
Re: [PATCH 5/6] mailbox: pcc: Initialize SHMEM before binding the channel with the client
Posted by lihuisong (C) 3 months, 3 weeks ago
在 2025/10/17 3:08, Sudeep Holla 写道:
> The PCC channel's shared memory region must be set up before the
> mailbox controller binds the channel with the client, as the binding
> process may trigger client operations like startup() that may rely on
> SHMEM being initialized.
>
> Reorder the setup sequence to ensure the shared memory is ready before
> binding. Initialize and map the PCC shared memory (SHMEM) prior to
> calling mbox_bind_client() so that clients never observe an uninitialized
> or NULL SHMEM during bind-time callbacks or early use in startup().
>
> This makes the PCC mailbox channel bring-up order consistent and
> eliminates a race between SHMEM setup and client binding.

I don't think this race exists. The above reason is enough.

This patch should be for patch 6/6, right?

>
> This will be needed in channel startup to clear/acknowledge any pending
> interrupts before enabling them.
>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Acked-by: lihuisong@huawei.com
> ---
>   drivers/mailbox/pcc.c | 18 ++++++++++--------
>   1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c
> index 33bd2d05704b..2829ec51b47f 100644
> --- a/drivers/mailbox/pcc.c
> +++ b/drivers/mailbox/pcc.c
> @@ -378,18 +378,20 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id)

>
Re: [PATCH 5/6] mailbox: pcc: Initialize SHMEM before binding the channel with the client
Posted by Adam Young 3 months, 3 weeks ago
Tested-by: Adam Young <admiyo@os.amperecomputing.com>

On 10/16/25 15:08, Sudeep Holla wrote:
> The PCC channel's shared memory region must be set up before the
> mailbox controller binds the channel with the client, as the binding
> process may trigger client operations like startup() that may rely on
> SHMEM being initialized.
>
> Reorder the setup sequence to ensure the shared memory is ready before
> binding. Initialize and map the PCC shared memory (SHMEM) prior to
> calling mbox_bind_client() so that clients never observe an uninitialized
> or NULL SHMEM during bind-time callbacks or early use in startup().
>
> This makes the PCC mailbox channel bring-up order consistent and
> eliminates a race between SHMEM setup and client binding.
>
> This will be needed in channel startup to clear/acknowledge any pending
> interrupts before enabling them.
>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>   drivers/mailbox/pcc.c | 18 ++++++++++--------
>   1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c
> index 33bd2d05704b..2829ec51b47f 100644
> --- a/drivers/mailbox/pcc.c
> +++ b/drivers/mailbox/pcc.c
> @@ -378,18 +378,20 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id)
>   		return ERR_PTR(-EBUSY);
>   	}
>   
> -	rc = mbox_bind_client(chan, cl);
> -	if (rc)
> -		return ERR_PTR(rc);
> -
>   	pcc_mchan = &pchan->chan;
>   	pcc_mchan->shmem = acpi_os_ioremap(pcc_mchan->shmem_base_addr,
>   					   pcc_mchan->shmem_size);
> -	if (pcc_mchan->shmem)
> -		return pcc_mchan;
> +	if (!pcc_mchan->shmem)
> +		return ERR_PTR(-ENXIO);
>   
> -	mbox_free_channel(chan);
> -	return ERR_PTR(-ENXIO);
> +	rc = mbox_bind_client(chan, cl);
> +	if (rc) {
> +		iounmap(pcc_mchan->shmem);
> +		pcc_mchan->shmem = NULL;
> +		return ERR_PTR(rc);
> +	}
> +
> +	return pcc_mchan;
>   }
>   EXPORT_SYMBOL_GPL(pcc_mbox_request_channel);
>   
>