linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
To: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Cc: Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konradybcio@kernel.org>,
	Vikash Garodia <quic_vgarodia@quicinc.com>,
	Dikshita Agarwal <quic_dikshita@quicinc.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Abhinav Kumar <abhinav.kumar@linux.dev>,
	linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-media@vger.kernel.org, linux-remoteproc@vger.kernel.org
Subject: Re: [PATCH v2 03/11] firmware: qcom_scm: Add a prep version of auth_and_reset function
Date: Wed, 20 Aug 2025 17:54:30 +0530	[thread overview]
Message-ID: <20250820122430.pasbypbrtbaynxv7@hu-mojha-hyd.qualcomm.com> (raw)
In-Reply-To: <fd9eadb2-a209-4b52-a269-4e45c884bbc1@linaro.org>

On Wed, Aug 20, 2025 at 01:03:41PM +0100, Bryan O'Donoghue wrote:
> On 19/08/2025 17:54, Mukesh Ojha wrote:
> > Qualcomm SoCs running with QHEE (Qualcomm Hypervisor Execution
> > Environment—a library present in the Gunyah hypervisor) utilize the
> > Peripheral Authentication Service (PAS) from TrustZone (TZ) firmware to
> > securely authenticate and reset remote processors via a sequence of SMC
> > calls such as qcom_scm_pas_init_image(), qcom_scm_pas_mem_setup(), and
> > qcom_scm_pas_auth_and_reset().
> > 
> > For memory passed to Qualcomm TrustZone, it must either be part of a
> > pool registered with TZ or be directly registered via SHMbridge SMC
> > calls.
> > 
> > When QHEE is present, PAS SMC calls from Linux running at EL1 are
> > trapped by QHEE (running at EL2), which then creates or retrieves memory
> > from the SHMbridge for both metadata and remoteproc carveout memory
> > before passing them to TZ. However, when the SoC runs with a
> > non-QHEE-based hypervisor, Linux must create the SHM bridge for both
> > metadata (before it is passed to TZ in qcom_scm_pas_init_image()) and
> > for remoteproc memory (before the call is made to TZ in
> > qcom_scm_pas_auth_and_reset()).
> > 
> > For auth_and_reset() call, first it need to register remoteproc carveout
> > memory with TZ via SHMbridge SMC call and then it can trigger
> > auth_and_reset SMC call and once the call returns, remoteproc carveout
> > memory can be deregisterd with TZ.
> > 
> > Add qcom_scm_pas_prepare_and_auth_reset() function which does prepare
> > the SHMbridge over carveout memory and call auth_and_reset SMC call.
> > 
> > Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
> > ---
> >   drivers/firmware/qcom/qcom_scm.c       | 46 ++++++++++++++++++++++++++
> >   include/linux/firmware/qcom/qcom_scm.h |  2 ++
> >   2 files changed, 48 insertions(+)
> > 
> > diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
> > index 33187d4f4aef..9a5b34f5bacb 100644
> > --- a/drivers/firmware/qcom/qcom_scm.c
> > +++ b/drivers/firmware/qcom/qcom_scm.c
> > @@ -759,6 +759,52 @@ int qcom_scm_pas_auth_and_reset(u32 peripheral)
> >   }
> >   EXPORT_SYMBOL_GPL(qcom_scm_pas_auth_and_reset);
> > +/**
> > + * qcom_scm_pas_prepare_and_auth_reset() - Prepare, authenticate, and reset the remote processor
> > + *
> > + * @ctx:	Context saved during call to qcom_scm_pas_ctx_init()
> > + *
> > + * This function performs the necessary steps to prepare a PAS subsystem,
> > + * authenticate it using the provided metadata, and initiate a reset sequence.
> > + *
> > + * It is typically used when Linux is in control setting up the IOMMU hardware
> 
> Is there a non-typical case ?

In non-typical case is when system runs with Gunyah which in control of
IOMMU and create shmbridge before it passes the call to TrustZone.

> 
> "This function is used"

Ack.

> > + * for remote subsystem during secure firmware loading processes. The preparation
> > + * step sets up shmbridge over the firmware memory before TrustZone access the
> 
> shmbridge -> "a shmbridge"
> "access" -> "accesses"

Ack.

> 
> > + * firmware memory region for authentication. The authentication step verifies
> > + * the integrity and authenticity of the firmware or configuration using secure
> > + * metadata. Finally, the reset step ensures the subsystem starts in a clean and
> > + * sane state.
> > + *
> > + * Return: 0 on success, negative errno on failure.
> > + */
> > +int qcom_scm_pas_prepare_and_auth_reset(struct qcom_scm_pas_ctx *ctx)
> > +{
> > +	u64 handle;
> > +	int ret;
> > +
> > +	if (!ctx->has_iommu)
> > +		return qcom_scm_pas_auth_and_reset(ctx->peripheral);
> > +
> > +	/*
> > +	 * When Linux running at EL1, Gunyah(EL2) traps auth_and_reset call and creates
> > +	 * shmbridge on subsystem memory region before it passes the call to TrustZone
> > +	 * to authenticate it while when Linux runs at EL2, it needs to create shmbridge
> > +	 * before this call goes to TrustZone.
> > +	 */
> 
> If Linux is running at EL1, Gunyah running at EL2 traps the auth_and_reset
> call, creates a shmbridge in "subsystem memory ? bod: which subsystem do you
> mean here"

Subsystem memory => remote processor carve out memory

> and then passes the call to TrustZone. If Linux is running at EL2
> then Linux needs to create the shmbridge before calling into TrustZone.
> 
> > +	ret = qcom_tzmem_shm_bridge_create(ctx->mem_phys, ctx->mem_size, &handle);
> > +	if (ret) {
> > +		dev_err(__scm->dev, "Failed to create shmbridge ret=%d %u\n",
> > +			ret, ctx->peripheral);
> > +		return ret;
> > +	}
> > +
> > +	ret = qcom_scm_pas_auth_and_reset(ctx->peripheral);
> > +	qcom_tzmem_shm_bridge_delete(handle);
> > +
> > +	return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(qcom_scm_pas_prepare_and_auth_reset);
> > +
> >   /**
> >    * qcom_scm_pas_shutdown() - Shut down the remote processor
> >    * @peripheral: peripheral id
> > diff --git a/include/linux/firmware/qcom/qcom_scm.h b/include/linux/firmware/qcom/qcom_scm.h
> > index b7eb206561a9..a31006fe49a9 100644
> > --- a/include/linux/firmware/qcom/qcom_scm.h
> > +++ b/include/linux/firmware/qcom/qcom_scm.h
> > @@ -79,6 +79,7 @@ struct qcom_scm_pas_ctx {
> >   	size_t mem_size;
> >   	struct qcom_scm_pas_metadata *metadata;
> >   	bool save_mdt_ctx;
> > +	bool has_iommu;
> >   };
> >   void *qcom_scm_pas_ctx_init(struct device *dev, u32 peripheral, phys_addr_t mem_phys,
> > @@ -87,6 +88,7 @@ int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size,
> >   			    struct qcom_scm_pas_metadata *ctx);
> >   void qcom_scm_pas_metadata_release(struct qcom_scm_pas_metadata *ctx);
> >   int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr, phys_addr_t size);
> > +int qcom_scm_pas_prepare_and_auth_reset(struct qcom_scm_pas_ctx *ctx);
> >   int qcom_scm_pas_auth_and_reset(u32 peripheral);
> >   int qcom_scm_pas_shutdown(u32 peripheral);
> >   bool qcom_scm_pas_supported(u32 peripheral);
> 

-- 
-Mukesh Ojha

  reply	other threads:[~2025-08-20 12:24 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-19 16:54 [PATCH v2 00/11] Peripheral Image Loader support for Qualcomm SoCs running Linux host at EL2 Mukesh Ojha
2025-08-19 16:54 ` [PATCH v2 01/11] firmware: qcom_scm: Introduce PAS context initialization helper Mukesh Ojha
2025-08-19 17:17   ` Pavan Kondeti
2025-08-20  6:19     ` Mukesh Ojha
2025-08-20 11:40   ` Bryan O'Donoghue
2025-08-20 12:28     ` Mukesh Ojha
2025-08-19 16:54 ` [PATCH v2 02/11] soc: qcom: mdtloader: Add context aware qcom_mdt_pas_load() helper Mukesh Ojha
2025-08-20 11:48   ` Bryan O'Donoghue
2025-08-20 12:25     ` Mukesh Ojha
2025-09-03 15:03   ` Bryan O'Donoghue
2025-09-04  9:52     ` Mukesh Ojha
2025-09-04 10:15       ` Bryan O'Donoghue
2025-09-04 11:43         ` Mukesh Ojha
2025-08-19 16:54 ` [PATCH v2 03/11] firmware: qcom_scm: Add a prep version of auth_and_reset function Mukesh Ojha
2025-08-20 12:03   ` Bryan O'Donoghue
2025-08-20 12:24     ` Mukesh Ojha [this message]
2025-08-19 16:54 ` [PATCH v2 04/11] firmware: qcom_scm: Simplify qcom_scm_pas_init_image() Mukesh Ojha
2025-08-21 14:36   ` Bryan O'Donoghue
2025-08-21 16:29     ` Mukesh Ojha
2025-08-19 16:54 ` [PATCH v2 05/11] firmware: qcom_scm: Add shmbridge support to pas_init/release function Mukesh Ojha
2025-08-21 15:23   ` Bryan O'Donoghue
2025-08-21 17:03     ` Mukesh Ojha
2025-08-22 16:52       ` Mukesh Ojha
2025-08-22 23:13       ` Bryan O'Donoghue
2025-08-19 16:54 ` [PATCH v2 06/11] remoteproc: Move resource table data structure to its own header Mukesh Ojha
2025-08-20  8:12   ` Stephan Gerhold
2025-08-20 15:18     ` Mukesh Ojha
2025-08-20 15:31       ` Stephan Gerhold
2025-08-22  7:56         ` Mukesh Ojha
2025-08-20 16:32       ` Mukesh Ojha
2025-08-20 16:53         ` Stephan Gerhold
2025-08-22  9:21           ` Mukesh Ojha
2025-08-22  8:35         ` Krzysztof Kozlowski
2025-08-22  9:30           ` Mukesh Ojha
2025-08-19 16:54 ` [PATCH v2 07/11] firmware: qcom_scm: Add qcom_scm_pas_get_rsc_table() to get resource table Mukesh Ojha
2025-08-21 15:05   ` Krzysztof Kozlowski
2025-08-21 17:20     ` Mukesh Ojha
2025-08-22  6:22       ` Krzysztof Kozlowski
2025-08-22  7:21         ` Mukesh Ojha
2025-08-22  8:30         ` Krzysztof Kozlowski
2025-08-19 16:54 ` [PATCH v2 08/11] soc: qcom: mdt_loader: Add helper functions to map and unmap resources Mukesh Ojha
2025-08-19 16:54 ` [PATCH v2 09/11] remoteproc: pas: Extend parse_fw callback to parse resource table Mukesh Ojha
2025-08-20  8:36   ` Stephan Gerhold
2025-08-20 11:14     ` Mukesh Ojha
2025-08-20 13:07       ` Stephan Gerhold
2025-08-21 14:49     ` Krzysztof Kozlowski
2025-08-21 17:41       ` Mukesh Ojha
2025-08-19 16:54 ` [PATCH v2 10/11] remoteproc: qcom: pas: Enable Secure PAS support with IOMMU managed by Linux Mukesh Ojha
2025-08-20  8:40   ` Stephan Gerhold
2025-08-20 12:03     ` Mukesh Ojha
2025-08-19 16:54 ` [PATCH v2 11/11] media: iris: " Mukesh Ojha
2025-08-20  8:46   ` Stephan Gerhold
2025-08-20 11:56     ` Mukesh Ojha
2025-08-20 13:39       ` Stephan Gerhold
2025-08-22  4:26         ` Vikash Garodia
2025-08-22  8:46           ` Stephan Gerhold
2025-08-22 15:06             ` Mukesh Ojha
2025-08-22 16:26               ` Stephan Gerhold
2025-08-22 16:40                 ` Mukesh Ojha
2025-08-23 20:43                   ` Stephan Gerhold
2025-08-25 11:19                     ` Mukesh Ojha
2025-08-20 11:33   ` Bryan O'Donoghue
2025-08-20 12:00     ` Mukesh Ojha
2025-08-22  8:45   ` Krzysztof Kozlowski
2025-08-22 15:13     ` Mukesh Ojha
2025-08-23 15:41       ` Krzysztof Kozlowski
2025-08-23 15:46         ` Krzysztof Kozlowski
2025-08-23 15:52           ` Krzysztof Kozlowski
2025-08-20 11:03 ` [PATCH v2 00/11] Peripheral Image Loader support for Qualcomm SoCs running Linux host at EL2 Bryan O'Donoghue
2025-08-20 11:22   ` Mukesh Ojha
2025-09-03 11:56     ` Konrad Dybcio
2025-09-03 13:31       ` Bryan O'Donoghue
2025-09-03 14:02         ` Dmitry Baryshkov
2025-09-03 14:05           ` Bryan O'Donoghue
2025-09-03 14:13           ` Bryan O'Donoghue
2025-09-03 14:21             ` Bryan O'Donoghue
2025-09-03 14:28             ` Dmitry Baryshkov

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=20250820122430.pasbypbrtbaynxv7@hu-mojha-hyd.qualcomm.com \
    --to=mukesh.ojha@oss.qualcomm.com \
    --cc=abhinav.kumar@linux.dev \
    --cc=andersson@kernel.org \
    --cc=bryan.odonoghue@linaro.org \
    --cc=konradybcio@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mchehab@kernel.org \
    --cc=quic_dikshita@quicinc.com \
    --cc=quic_vgarodia@quicinc.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).