From: Maximilian Luz <luzmaximilian@gmail.com>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
Bjorn Andersson <andersson@kernel.org>
Cc: Andy Gross <agross@kernel.org>,
Konrad Dybcio <konrad.dybcio@linaro.org>,
Ard Biesheuvel <ardb@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Johan Hovold <johan@kernel.org>,
Sudeep Holla <sudeep.holla@arm.com>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Sumit Garg <sumit.garg@linaro.org>,
Steev Klimaszewski <steev@kali.org>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/4] firmware: Add support for Qualcomm Secure Execution Environment SCM interface
Date: Wed, 8 Mar 2023 14:59:38 +0100 [thread overview]
Message-ID: <fa9cfc41-1d6c-1003-e6d9-6a1545487177@gmail.com> (raw)
In-Reply-To: <84e6cfd8-ee4b-a5f4-5249-d87df9909246@linaro.org>
On 3/7/23 16:32, Dmitry Baryshkov wrote:
> On 05/03/2023 04:21, Maximilian Luz wrote:
[...]
>> +/* -- DMA helpers. ---------------------------------------------------------- */
>> +
>> +/* DMA requirements for QSEECOM SCM calls. */
>> +#define QSEECOM_DMA_ALIGNMENT 8
>> +#define QSEECOM_DMA_ALIGN(ptr) ALIGN(ptr, QSEECOM_DMA_ALIGNMENT)
>> +
>> +/**
>> + * struct qseecom_dma - DMA memory region.
>> + * @size: Size of the memory region, in bytes.
>> + * @virt: Pointer / virtual address to the memory, accessible by the kernel.
>> + * @phys: Physical address of the memory region.
>> + */
>> +struct qseecom_dma {
>> + unsigned long size;
>
> size_t ?
Will fix.
>> + void *virt;
>> + dma_addr_t phys;
>> +};
>
> Do we really need this wrapper and the wrappers bellow? They look like a pure syntax sugar for me, hiding the dma functions from the user.
The idea was that they take care of proper allocation. The Windows driver that
I've reverse-engineered this from allocates memory in multiples of PAGE_SIZE,
so I believe that this might be a requirement (at least on some systems). These
functions are there to ensure that and with that prevent potential bugs by
taking that responsibility from the caller.
>> +
>> +/**
>> + * qseecom_dma_alloc() - Allocate a DMA-able memory region suitable for QSEECOM
>> + * SCM calls.
>> + * @dev: The device used for DMA memory allocation.
>> + * @dma: Where to write the allocated memory addresses and size to.
>> + * @size: Minimum size of the memory to be allocated.
>> + * @gfp: Flags used for allocation.
>> + *
>> + * Allocate a DMA-able memory region suitable for interaction with SEE
>> + * services/applications and the TzOS. The provided size is treated as the
>> + * minimum required size and rounded up, if necessary. The actually allocated
>> + * memory region will be stored in @dma. Allocated memory must be freed via
>> + * qseecom_dma_free().
>> + *
>> + * Return: Returns zero on success, -ENOMEM on allocation failure.
>> + */
>> +static inline int qseecom_dma_alloc(struct device *dev, struct qseecom_dma *dma,
>> + unsigned long size, gfp_t gfp)
>
> size_t size
>
> gfp is not used
Right, that should have been passed to dma_alloc_coherent(). Will fix that.
>> +{
>> + size = PAGE_ALIGN(size);
>> +
>> + dma->virt = dma_alloc_coherent(dev, size, &dma->phys, GFP_KERNEL);
>> + if (!dma->virt)
>> + return -ENOMEM;
>> +
>> + dma->size = size;
>> + return 0;
>> +}
>> +
>> +/**
>> + * qseecom_dma_free() - Free a DMA memory region.
>> + * @dev: The device used for allocation.
>> + * @dma: The DMA region to be freed.
>> + *
>> + * Free a DMA region previously allocated via qseecom_dma_alloc(). Note that
>> + * freeing sub-regions is not supported.
>> + */
>> +static inline void qseecom_dma_free(struct device *dev, struct qseecom_dma *dma)
>> +{
>> + dma_free_coherent(dev, dma->size, dma->virt, dma->phys);
>> +}
>> +
>> +/**
>> + * qseecom_dma_realloc() - Re-allocate DMA memory region with the requested size.
>> + * @dev: The device used for allocation.
>> + * @dma: The region descriptor to be updated.
>> + * @size: The new requested size.
>> + * @gfp: Flags used for allocation.
>> + *
>> + * Re-allocates a DMA memory region suitable for QSEECOM SCM calls to fit the
>> + * requested amount of bytes, if necessary. Does nothing if the provided region
>> + * already has enough space to store the requested data.
>> + *
>> + * See qseecom_dma_alloc() for details.
>> + *
>> + * Return: Returns zero on success, -ENOMEM on allocation failure.
>> + */
>> +static inline int qseecom_dma_realloc(struct device *dev, struct qseecom_dma *dma,
>> + unsigned long size, gfp_t gfp)
>> +{
>> + if (PAGE_ALIGN(size) <= dma->size)
>> + return 0;
>> +
>> + qseecom_dma_free(dev, dma);
>> + return qseecom_dma_alloc(dev, dma, size, gfp);
>> +}
>
> I'll comment on this function when commenting patch 4.
>
>> +
>> +/**
>> + * qseecom_dma_aligned() - Create a aligned DMA memory sub-region suitable for
>> + * QSEECOM SCM calls.
>> + * @base: Base DMA memory region, in which the new region will reside.
>> + * @out: Descriptor to store the aligned sub-region in.
>> + * @offset: The offset inside base region at which to place the new sub-region.
>> + *
>> + * Creates an aligned DMA memory region suitable for QSEECOM SCM calls at or
>> + * after the given offset. The size of the sub-region will be set to the
>> + * remaining size in the base region after alignment, i.e., the end of the
>> + * sub-region will be equal the end of the base region.
>> + *
>> + * Return: Returns zero on success or -EINVAL if the new aligned memory address
>> + * would point outside the base region.
>> + */
>> +static inline int qseecom_dma_aligned(const struct qseecom_dma *base, struct qseecom_dma *out,
>> + unsigned long offset)
>> +{
>> + void *aligned = (void *)QSEECOM_DMA_ALIGN((uintptr_t)base->virt + offset);
>> +
>> + if (aligned - base->virt > base->size)
>> + return -EINVAL;
>> +
>> + out->virt = aligned;
>> + out->phys = base->phys + (out->virt - base->virt);
>> + out->size = base->size - (out->virt - base->virt);
>> +
>> + return 0;
>> +}
>> +
>> +
>> +/* -- Common interface. ----------------------------------------------------- */
>> +
>> +struct qseecom_device {
>> + struct device *dev;
>> + struct mutex scm_call_lock; /* Guards QSEECOM SCM calls. */
>
> There can be only one instance of the qseecom call infrastructure. Make this mutex static in the qcom_scm.c
Right, will do that.
>> +};
>> +
>> +
>> +/* -- Secure-OS SCM call interface. ----------------------------------------- */
>> +
>> +#define QSEECOM_TZ_OWNER_TZ_APPS 48
>> +#define QSEECOM_TZ_OWNER_QSEE_OS 50
>> +
>> +#define QSEECOM_TZ_SVC_APP_ID_PLACEHOLDER 0
>> +#define QSEECOM_TZ_SVC_APP_MGR 1
>> +
>> +enum qseecom_scm_result {
>> + QSEECOM_RESULT_SUCCESS = 0,
>> + QSEECOM_RESULT_INCOMPLETE = 1,
>> + QSEECOM_RESULT_BLOCKED_ON_LISTENER = 2,
>> + QSEECOM_RESULT_FAILURE = 0xFFFFFFFF,
>> +};
>> +
>> +enum qseecom_scm_resp_type {
>> + QSEECOM_SCM_RES_APP_ID = 0xEE01,
>> + QSEECOM_SCM_RES_QSEOS_LISTENER_ID = 0xEE02,
>> +};
>> +
>> +/**
>> + * struct qseecom_scm_resp - QSEECOM SCM call response.
>> + * @status: Status of the SCM call. See &enum qseecom_scm_result.
>> + * @resp_type: Type of the response. See &enum qseecom_scm_resp_type.
>> + * @data: Response data. The type of this data is given in @resp_type.
>> + */
>> +struct qseecom_scm_resp {
>> + u64 status;
>> + u64 resp_type;
>> + u64 data;
>> +};
>> +
>> +int qseecom_scm_call(struct qseecom_device *qsee, const struct qcom_scm_desc *desc,
>> + struct qseecom_scm_resp *res);
>> +
>> +
>> +/* -- Secure App interface. ------------------------------------------------- */
>> +
>> +#define QSEECOM_MAX_APP_NAME_SIZE 64
>> +
>> +int qseecom_app_get_id(struct qseecom_device *qsee, const char *app_name, u32 *app_id);
>> +int qseecom_app_send(struct qseecom_device *qsee, u32 app_id, struct qseecom_dma *req,
>> + struct qseecom_dma *rsp);
>
> I think that only these calls should be made public / available to other modules. qseecom_scm_call also is an internal helper.
So move all calls to qcom_scm and only make these two public? Or move only
qseecom_scm_call() to qcom_scm (which would require to make it public there,
however). Or how would you want this to look?
>> +
>> +#endif /* _LINUX_QCOM_QSEECOM_H */
>
Regards,
Max
next prev parent reply other threads:[~2023-03-08 14:01 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-05 2:21 [PATCH v3 0/4] firmware: Add support for Qualcomm UEFI Secure Application Maximilian Luz
2023-03-05 2:21 ` [PATCH v3 1/4] firmware: qcom_scm: Export SCM call functions Maximilian Luz
2023-03-07 15:23 ` Dmitry Baryshkov
2023-03-08 12:53 ` Srinivas Kandagatla
2023-03-08 13:48 ` Maximilian Luz
2023-03-08 14:20 ` Srinivas Kandagatla
2023-03-08 15:09 ` Maximilian Luz
2023-03-08 13:29 ` Maximilian Luz
2023-03-05 2:21 ` [PATCH v3 2/4] firmware: Add support for Qualcomm Secure Execution Environment SCM interface Maximilian Luz
2023-03-07 15:32 ` Dmitry Baryshkov
2023-03-08 13:59 ` Maximilian Luz [this message]
2023-03-09 8:45 ` Dmitry Baryshkov
2023-03-09 20:54 ` Maximilian Luz
2023-03-07 15:36 ` Dmitry Baryshkov
2023-03-08 14:06 ` Maximilian Luz
2023-03-09 8:07 ` Dmitry Baryshkov
2023-03-05 2:21 ` [PATCH v3 3/4] dt-bindings: firmware: Add Qualcomm QSEECOM interface Maximilian Luz
2023-03-08 22:16 ` Rob Herring
2023-03-08 22:44 ` Maximilian Luz
2023-03-09 1:33 ` Dmitry Baryshkov
2023-03-09 2:27 ` Maximilian Luz
2023-03-09 8:19 ` Dmitry Baryshkov
2023-03-09 20:34 ` Maximilian Luz
2023-03-09 20:43 ` Dmitry Baryshkov
2023-05-02 8:38 ` Sudeep Holla
2023-05-02 10:52 ` Maximilian Luz
2023-05-02 8:31 ` Krzysztof Kozlowski
2023-05-02 10:57 ` Maximilian Luz
2023-03-05 2:21 ` [PATCH v3 4/4] firmware: Add support for Qualcomm UEFI Secure Application Maximilian Luz
2023-03-07 15:51 ` Dmitry Baryshkov
2023-03-08 15:02 ` Maximilian Luz
2023-03-09 8:36 ` Dmitry Baryshkov
2023-03-09 20:44 ` Maximilian Luz
2023-06-29 12:26 ` Johan Hovold
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=fa9cfc41-1d6c-1003-e6d9-6a1545487177@gmail.com \
--to=luzmaximilian@gmail.com \
--cc=agross@kernel.org \
--cc=andersson@kernel.org \
--cc=ardb@kernel.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=ilias.apalodimas@linaro.org \
--cc=johan@kernel.org \
--cc=konrad.dybcio@linaro.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=srinivas.kandagatla@linaro.org \
--cc=steev@kali.org \
--cc=sudeep.holla@arm.com \
--cc=sumit.garg@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox