public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* Potential bug of arm64 SMCCC call
@ 2024-03-25 13:36 崇文 李
  2024-03-25 17:00 ` Mark Rutland
  0 siblings, 1 reply; 2+ messages in thread
From: 崇文 李 @ 2024-03-25 13:36 UTC (permalink / raw)
  To: linux-arm-kernel@lists.infradead.org

Hello. I saw a potential bug when I was checking arm64 SMCCC call.

In arm-smccc.h [see link 0], from line 481 to line 497 resides the
definition of "__arm_smccc_1_1", which is in turn used to implement
the RMI interface in rmi_cmds.h [see link 1].

In the definition of "__arm_smccc_1_1", there is no clobbering of
registers x4 -- x17.  However, according to Arm SMC Calling Convention
[see link 2, page 10 of 19], registers x4 -- x17 are scratch registers. 
Upon returning from an arm64 smc instruction, x4 -- x17 registers may 
be overwritten with mysterious values from the firmware.

So it is safer to mark x4--x17 registers as clobbered registers in the
"asm" statement inside the definition of "__arm_smccc_1_1", so the
compiler avoids using x4--x17 registers around arm64 smc instructions.

Best regards.



Links
============

[0] arm-smccc.h in arm's linux kernel repository
   https://gitlab.arm.com/linux-arm/linux-cca/-/blob/cca-host/rmm-v1.0-eac5/include/linux/arm-smccc.h?ref_type=heads

[1] rmi_cmds.h in arm's linux kernel repository
   https://gitlab.arm.com/linux-arm/linux-cca/-/blob/cca-host/rmm-v1.0-eac5/arch/arm64/include/asm/rmi_cmds.h?ref_type=heads

[2] Arm SMC Calling Convention
   https://documentation-service.arm.com/static/5f8ea482f86e16515cdbe3c6?token=
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Potential bug of arm64 SMCCC call
  2024-03-25 13:36 Potential bug of arm64 SMCCC call 崇文 李
@ 2024-03-25 17:00 ` Mark Rutland
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Rutland @ 2024-03-25 17:00 UTC (permalink / raw)
  To: 崇文 李; +Cc: linux-arm-kernel@lists.infradead.org

On Mon, Mar 25, 2024 at 01:36:37PM +0000, 崇文 李 wrote:
> Hello. I saw a potential bug when I was checking arm64 SMCCC call.
 
Hi,

> In arm-smccc.h [see link 0], from line 481 to line 497 resides the
> definition of "__arm_smccc_1_1", which is in turn used to implement
> the RMI interface in rmi_cmds.h [see link 1].
> 
> In the definition of "__arm_smccc_1_1", there is no clobbering of
> registers x4 -- x17.  However, according to Arm SMC Calling Convention
> [see link 2, page 10 of 19], registers x4 -- x17 are scratch registers. 
> Upon returning from an arm64 smc instruction, x4 -- x17 registers may 
> be overwritten with mysterious values from the firmware.

I think you're looking at a very old version of the SMCCC specification. The
__arm_smccc_1_1 helper is only intended to be used for SMCCCv1.1+, which is
newer than the specification that you link to below.

Please see a more recent version, e.g. ARM DEN 0028F: 

  https://developer.arm.com/documentation/den0028/f/?lang=en

If you look in "13 Appendix F: Changelog", you'll see the key change in
SMCCCv1.1:

| Result register set:
| Mandates preservation of registers X4—X17 across a SMC or HVC call.

... and this is described earlier in the document.

> So it is safer to mark x4--x17 registers as clobbered registers in the
> "asm" statement inside the definition of "__arm_smccc_1_1", so the
> compiler avoids using x4--x17 registers around arm64 smc instructions.

As above, this should not be necessary. These SMCCC invocation functions should
only be used with SMCCCv1.1+ compliant firmware, and in those cases x4-x17 are
preserved.

Note that specific SMCCC calls imply that the SMCCC version is 1.1 or later.

Thanks,
Mark

> 
> Best regards.
> 
> 
> 
> Links
> ============
> 
> [0] arm-smccc.h in arm's linux kernel repository
>    https://gitlab.arm.com/linux-arm/linux-cca/-/blob/cca-host/rmm-v1.0-eac5/include/linux/arm-smccc.h?ref_type=heads
> 
> [1] rmi_cmds.h in arm's linux kernel repository
>    https://gitlab.arm.com/linux-arm/linux-cca/-/blob/cca-host/rmm-v1.0-eac5/arch/arm64/include/asm/rmi_cmds.h?ref_type=heads
> 
> [2] Arm SMC Calling Convention
>    https://documentation-service.arm.com/static/5f8ea482f86e16515cdbe3c6?token=
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-25 17:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-25 13:36 Potential bug of arm64 SMCCC call 崇文 李
2024-03-25 17:00 ` Mark Rutland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox