devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Nikunj Kela <quic_nkela@quicinc.com>, sudeep.holla@arm.com
Cc: cristian.marussi@arm.com, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] firmware: arm_scmi: Augment SMC/HVC to allow optional parameter
Date: Mon, 17 Apr 2023 11:01:13 -0700	[thread overview]
Message-ID: <02b34c80-f37e-deee-29cd-de7db902797d@gmail.com> (raw)
In-Reply-To: <20230417174401.19563-3-quic_nkela@quicinc.com>

On 4/17/23 10:44, Nikunj Kela wrote:
> This patch add support for passing shmem channel address as parameter
> in smc/hvc call. This patch is useful when multiple scmi instances are
> using same smc-id and firmware needs to distiguish among the instances.

Typo: distinguish.

It really would have been a lot clearer and made a whole lot more sense 
to encode a VM ID/channel number within some of the SMCCC parameters, 
possibly as part of the function ID itself.

> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>   drivers/firmware/arm_scmi/driver.c |  1 +
>   drivers/firmware/arm_scmi/smc.c    | 25 ++++++++++++++++++++++++-
>   2 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> index e7d97b59963b..b5957cc12fee 100644
> --- a/drivers/firmware/arm_scmi/driver.c
> +++ b/drivers/firmware/arm_scmi/driver.c
> @@ -2914,6 +2914,7 @@ static const struct of_device_id scmi_of_match[] = {
>   #endif
>   #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>   	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
> +	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
>   #endif
>   #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>   	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> index 93272e4bbd12..e28387346d33 100644
> --- a/drivers/firmware/arm_scmi/smc.c
> +++ b/drivers/firmware/arm_scmi/smc.c
> @@ -20,6 +20,9 @@
>   
>   #include "common.h"
>   
> +#define lower32(x)	((u32)((x) & 0xffffffff))
> +#define upper32(x)	((u32)(((u64)(x) >> 32) & 0xffffffff))

Cannot you use the existing lower_32_bits and upper_32_bits macros from 
kernel.h here?

> +
>   /**
>    * struct scmi_smc - Structure representing a SCMI smc transport
>    *
> @@ -30,6 +33,8 @@
>    * @inflight: Atomic flag to protect access to Tx/Rx shared memory area.
>    *	      Used when operating in atomic mode.
>    * @func_id: smc/hvc call function id
> + * @is_smc64: smc/hvc calling convention type 64 vs 32
> + * @param: physical address of the shmem channel
>    */
>   
>   struct scmi_smc {
> @@ -40,6 +45,8 @@ struct scmi_smc {
>   #define INFLIGHT_NONE	MSG_TOKEN_MAX
>   	atomic_t inflight;
>   	u32 func_id;
> +	bool is_smc64;
> +	phys_addr_t param;
>   };
>   
>   static irqreturn_t smc_msg_done_isr(int irq, void *data)
> @@ -137,6 +144,8 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>   	if (ret < 0)
>   		return ret;
>   
> +	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param"))
> +		scmi_info->param = res.start;

There is not even a check that this is going to be part of the kernel's 
view of memory, that seems a bit brittle and possibly a security hole, 
too. Your hypervisor presumably needs to have carved out some amount of 
memory in order for the messages to be written to/read from, and so 
would the VM kernel, so eventually we should have a 'reserved-memory' 
entry of some sort, no?

>   	/*
>   	 * If there is an interrupt named "a2p", then the service and
>   	 * completion of a message is signaled by an interrupt rather than by
> @@ -156,6 +165,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>   	}
>   
>   	scmi_info->func_id = func_id;
> +	scmi_info->is_smc64 = ARM_SMCCC_IS_64(func_id);
>   	scmi_info->cinfo = cinfo;
>   	smc_channel_lock_init(scmi_info);
>   	cinfo->transport_info = scmi_info;
> @@ -188,7 +198,20 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>   
>   	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>   
> -	arm_smccc_1_1_invoke(scmi_info->func_id, 0, 0, 0, 0, 0, 0, 0, &res);
> +#ifdef CONFIG_ARM64
> +	/*
> +	 * if SMC32 convention is used, pass 64 bit address in
> +	 * two parameters
> +	 */
> +	if (!scmi_info->is_smc64)

There is no need for scmi_info to store is_smc64, just check the func_id 
here and declare is_smc64 as a local variable to the function.

Also, another way to approach this would be to encode the parameters 
region in 4KB units such that event on a 32-bit system with LPAE you are 
guaranteed to fit the region into a 32-bit unsigned long. AFAIR 
virtualization and LPAE are indistinguishable on real CPUs?

> +		arm_smccc_1_1_invoke(scmi_info->func_id,
> +				     lower32(scmi_info->param),
> +				     upper32(scmi_info->param),
> +				     0, 0, 0, 0, 0, &res);
> +	else
> +#endif
> +		arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->param,
> +				     0, 0, 0, 0, 0, 0, &res);
>   
>   	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
>   	if (res.a0) {

-- 
Florian


  reply	other threads:[~2023-04-17 18:01 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-09 18:19 [PATCH 0/2] Allow parameter in smc/hvc calls Nikunj Kela
2023-04-09 18:19 ` [PATCH 1/2] dt-bindings: firmware: arm,scmi: support parameter passing in smc/hvc Nikunj Kela
2023-04-10 17:20   ` Krzysztof Kozlowski
2023-04-10 17:33     ` Nikunj Kela
2023-04-11 17:17       ` Krzysztof Kozlowski
2023-04-09 18:19 ` [PATCH 2/2] firmware: arm_scmi: Augment SMC/HVC to allow optional parameters Nikunj Kela
2023-04-09 22:22   ` kernel test robot
2023-04-10 18:20 ` [PATCH v2 0/2] Allow parameter in smc/hvc calls Nikunj Kela
2023-04-10 18:20   ` [PATCH v2 1/2] dt-bindings: firmware: arm,scmi: support parameter passing in smc/hvc Nikunj Kela
2023-04-11 12:54     ` Sudeep Holla
2023-04-11 14:46       ` Nikunj Kela
2023-04-11 17:18     ` Krzysztof Kozlowski
2023-04-11 17:25       ` Nikunj Kela
2023-04-10 18:20   ` [PATCH v2 2/2] firmware: arm_scmi: Augment SMC/HVC to allow optional parameters Nikunj Kela
2023-04-11 13:01   ` [PATCH v2 0/2] Allow parameter in smc/hvc calls Sudeep Holla
2023-04-11 14:42     ` Nikunj Kela
2023-04-12  8:37       ` Sudeep Holla
2023-04-12 14:54         ` Nikunj Kela
2023-04-17 17:43 ` [PATCH v3 " Nikunj Kela
2023-04-17 17:44   ` [PATCH v3 1/2] dt-bindings: firmware: arm,scmi: support for parameter in smc/hvc call Nikunj Kela
2023-04-17 17:44   ` [PATCH v3 2/2] firmware: arm_scmi: Augment SMC/HVC to allow optional parameter Nikunj Kela
2023-04-17 18:01     ` Florian Fainelli [this message]
2023-04-17 18:17       ` Nikunj Kela
2023-04-18  9:58       ` Sudeep Holla
2023-04-18 14:20         ` Nikunj Kela
2023-04-18 16:33           ` Florian Fainelli
2023-04-18 17:07             ` Nikunj Kela
2023-04-18 18:56 ` [PATCH v4 0/2] Allow parameter in smc/hvc calls Nikunj Kela
2023-04-18 18:56   ` [PATCH v4 1/2] dt-bindings: firmware: arm,scmi: support for parameter in smc/hvc call Nikunj Kela
2023-04-25 16:50     ` Rob Herring
2023-04-18 18:56   ` [PATCH v4 2/2] firmware: arm_scmi: Augment SMC/HVC to allow optional parameters Nikunj Kela
2023-05-01 14:39     ` Nikunj Kela
2023-05-02 10:46       ` Sudeep Holla
2023-05-02 14:41         ` Nikunj Kela
2023-04-25 14:01   ` [PATCH v4 0/2] Allow parameter in smc/hvc calls Nikunj Kela

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=02b34c80-f37e-deee-29cd-de7db902797d@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=cristian.marussi@arm.com \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_nkela@quicinc.com \
    --cc=robh+dt@kernel.org \
    --cc=sudeep.holla@arm.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).