Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
From: Bjorn Andersson <andersson@kernel.org>
To: Gokul krishna Krishnakumar <quic_gokukris@quicinc.com>
Cc: Andy Gross <agross@kernel.org>,
	Konrad Dybcio <konrad.dybcio@somainline.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Trilok Soni <quic_tsoni@quicinc.com>,
	Satya Durga Srinivasu Prabhala <quic_satyap@quicinc.com>,
	Rajendra Nayak <quic_rjendra@quicinc.com>,
	Elliot Berman <quic_eberman@quicinc.com>,
	Guru Das Srinagesh <quic_gurus@quicinc.com>
Subject: Re: [PATCH v1 2/2] soc: qcom: mdt_loader: Move the memory allocation into mdt loader
Date: Tue, 13 Sep 2022 15:11:02 -0500	[thread overview]
Message-ID: <20220913201102.mjmtvsx5xyfcr5cw@builder.lan> (raw)
In-Reply-To: <2ba262668e86e58acb086c64fc759ba02b39a525.1663007783.git.quic_gokukris@quicinc.com>

On Mon, Sep 12, 2022 at 11:41:32AM -0700, Gokul krishna Krishnakumar wrote:
> By moving the memory allocation to mdt loader we can simplify the scm
> call, by just packing arguments provided to it from the clients for
> making secuer world calls. We can also simplify the memory allocation
> for the qcom metadata, by just doing one memory allocation in the
> mdt loader.
> 
> Signed-off-by: Gokul krishna Krishnakumar <quic_gokukris@quicinc.com>
> ---
>  drivers/remoteproc/qcom_q6v5_mss.c  |  2 +-
>  drivers/soc/qcom/mdt_loader.c       | 41 ++++++++++++++++++++++++++++---------
>  include/linux/soc/qcom/mdt_loader.h |  5 +++--
>  3 files changed, 35 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c
> index fddb63c..1919bfc 100644
> --- a/drivers/remoteproc/qcom_q6v5_mss.c
> +++ b/drivers/remoteproc/qcom_q6v5_mss.c
> @@ -947,7 +947,7 @@ static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw,
>  	int ret;
>  	int i;
>  
> -	metadata = qcom_mdt_read_metadata(fw, &size, fw_name, qproc->dev);
> +	metadata = qcom_mdt_read_metadata(fw, &size, fw_name, qproc->dev, NULL);

At the end of this function we invoke kfree(metadata), which would be
bad if that comes from dma_alloc_coherent().

>  	if (IS_ERR(metadata))
>  		return PTR_ERR(metadata);
>  
> diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c
[..]
> @@ -160,9 +164,18 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len,
>  	ehdr_size = phdrs[0].p_filesz;
>  	hash_size = phdrs[hash_segment].p_filesz;
>  
> -	data = kmalloc(ehdr_size + hash_size, GFP_KERNEL);
> -	if (!data)
> -		return ERR_PTR(-ENOMEM);
> +	/*
> +	 * During the scm call memory protection will be enabled for the meta
> +	 * data blob, so make sure it's physically contiguous, 4K aligned and
> +	 * non-cachable to avoid XPU violations.
> +	 */
> +	scm_dev = qcom_get_scm_device();

As LKP points out, I don't seem to have this function.

> +	data = dma_alloc_coherent(scm_dev, ehdr_size + hash_size, mdata_phys,
> +				       GFP_KERNEL);

I am not thrilled about the idea of doing dma_alloc_coherent() in this
file and dma_free_coherent() in the scm driver. Similarly, I consider
these functions to operate in the context of the caller, so operating on
the scm device's struct device isn't so nice.


After trying various models I came to the conclusion that it was better
to try to keep the MDT loader to just load MDT files, and move the
SCM/PAS interaction out of that. Unfortunately we have a number of
client drivers that would then need to (essentially) duplicate the
content of qcom_mdt_pas_init() - so I left that in there.

I still believe that keeping the MDT loader focused on loading MDTs is a
good idea, but I'm open to any suggestions for improvements in the
interaction between these different components.

Regards,
Bjorn

  reply	other threads:[~2022-09-13 20:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-12 18:41 [PATCH v1 0/2] Memory allocation change in scm/mdt_loader Gokul krishna Krishnakumar
2022-09-12 18:41 ` [PATCH v1 1/2] firmware: qcom_scm: Remove memory alloc call from qcom_scm_pas_init_image() Gokul krishna Krishnakumar
2022-09-12 18:41 ` [PATCH v1 2/2] soc: qcom: mdt_loader: Move the memory allocation into mdt loader Gokul krishna Krishnakumar
2022-09-13 20:11   ` Bjorn Andersson [this message]
2022-09-21 16:39     ` Gokul krishna Krishnakumar (QUIC)
2022-10-04  2:07       ` Gokul Krishna Krishnakumar

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=20220913201102.mjmtvsx5xyfcr5cw@builder.lan \
    --to=andersson@kernel.org \
    --cc=agross@kernel.org \
    --cc=konrad.dybcio@somainline.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=quic_eberman@quicinc.com \
    --cc=quic_gokukris@quicinc.com \
    --cc=quic_gurus@quicinc.com \
    --cc=quic_rjendra@quicinc.com \
    --cc=quic_satyap@quicinc.com \
    --cc=quic_tsoni@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