Skip to contentSkip to conversation

firmware: smccc: Pass only the required device probe arguments

PATCH Applied Aneesh Kumar K.V (Arm) 4 participants 7 messages Oct 10 – Oct 12 Secure monitor call(SMC) calling convention (SMCCC)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware: smccc: Pass only the required device probe arguments

The device probe passes zeroes for all seven argument registers to arm_smccc_1_1_invoke(). On ARM32 Thumb-2, this binds an input to r7 and GCC 8.5 reports "r7 cannot be used in asm here".

The current smccc_devices entries need at most one argument after the function ID: TRNG_VERSION has none and RSI_ABI_VERSION takes a requested version. Pass zero for that argument and omit the unused arguments, avoiding the r7 constraint. Check argument requirements when adding new probe functions to smccc_devices.

Cc Catalin Marinas <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Sudeep Holla <[email protected]>
Cc Will Deacon <[email protected]>
Cc Steven Price <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Andre Przywara <[email protected]>
Cc Russell King <[email protected]>
Fixes d8263a131bb0 ("firmware: hwrng: arm_smccc_trng: Register as an SMCCC device")
---
 drivers/firmware/smccc/smccc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/firmware/smccc/smccc.c +1 -2
index 07b864ff079d..377d2cda2b6e 100644
@@ -122,8 +122,7 @@ static bool __init smccc_probe_smccc_device(const struct smccc_device_info *smcc
 	if (IS_ENABLED(CONFIG_ARM) && ARM_SMCCC_IS_64(smccc_dev->func_id))
 		return false;
 
-	arm_smccc_1_1_invoke(smccc_dev->func_id,
-			     0, 0, 0, 0, 0, 0, 0, &res);
+	arm_smccc_1_1_invoke(smccc_dev->func_id, 0, &res);
 	ret = res.a0;
 
 	if (ret == SMCCC_RET_NOT_SUPPORTED)
Signature · 1 line
2.43.0
#1 lore raw

Hi Aneesh

Quoted 9 lines · Aneesh Kumar K.V (Arm)

The device probe passes zeroes for all seven argument registers to arm_smccc_1_1_invoke(). On ARM32 Thumb-2, this binds an input to r7 and GCC 8.5 reports "r7 cannot be used in asm here".

The current smccc_devices entries need at most one argument after the function ID: TRNG_VERSION has none and RSI_ABI_VERSION takes a requested version. Pass zero for that argument and omit the unused arguments, avoiding the r7 constraint. Check argument requirements when adding new probe functions to smccc_devices.

Is it safer to use x1-x3 to 0 as they could be the results that we get back from SMCCC v1.0 onwards ?

Suzuki

Quoted 32 lines
Cc Catalin Marinas <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Sudeep Holla <[email protected]>
Cc Will Deacon <[email protected]>
Cc Steven Price <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Andre Przywara <[email protected]>
Cc Russell King <[email protected]>
Fixes d8263a131bb0 ("firmware: hwrng: arm_smccc_trng: Register as an SMCCC device")
---
  drivers/firmware/smccc/smccc.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/firmware/smccc/smccc.c +1 -2
index 07b864ff079d..377d2cda2b6e 100644
@@ -122,8 +122,7 @@ static bool __init smccc_probe_smccc_device(const struct smccc_device_info *smcc
  	if (IS_ENABLED(CONFIG_ARM) && ARM_SMCCC_IS_64(smccc_dev->func_id))
  		return false;
 
-	arm_smccc_1_1_invoke(smccc_dev->func_id,
-			     0, 0, 0, 0, 0, 0, 0, &res);
+	arm_smccc_1_1_invoke(smccc_dev->func_id, 0, &res);
  	ret = res.a0;
 
  	if (ret == SMCCC_RET_NOT_SUPPORTED)
#2 lore raw
Quoted 7 lines · Suzuki K Poulose

Hi Aneesh

Quoted 4 lines · Aneesh Kumar K.V (Arm)

The device probe passes zeroes for all seven argument registers to arm_smccc_1_1_invoke(). On ARM32 Thumb-2, this binds an input to r7 and GCC 8.5 reports "r7 cannot be used in asm here".

Quoted 9 lines
Quoted 5 lines

The current smccc_devices entries need at most one argument after the function ID: TRNG_VERSION has none and RSI_ABI_VERSION takes a requested version. Pass zero for that argument and omit the unused arguments, avoiding the r7 constraint. Check argument requirements when adding new probe functions to smccc_devices.

Is it safer to use x1-x3 to 0 as they could be the results that we get back from SMCCC v1.0 onwards ?

I'm not sure I follow. Passing additional zero arguments only initializes the input registers; it should not affect how return values are handled. arm_smccc_1_1_invoke() already declares x0-x3 as outputs. Since these probe functions require no inputs in x2 or x3 and we only inspect x0 on return, why do we need to initialize them to zero?

-aneesh

maintainer Reviewed-by on v1 1/1
#5 lore raw
In reply to Aneesh Kumar K.V (Arm)
Quoted 10 lines · Aneesh Kumar K.V (Arm)

The device probe passes zeroes for all seven argument registers to arm_smccc_1_1_invoke(). On ARM32 Thumb-2, this binds an input to r7 and GCC 8.5 reports "r7 cannot be used in asm here".

The current smccc_devices entries need at most one argument after the function ID: TRNG_VERSION has none and RSI_ABI_VERSION takes a requested version. Pass zero for that argument and omit the unused arguments, avoiding the r7 constraint. Check argument requirements when adding new probe functions to smccc_devices.

LGTM and should be enough for now.

Signature · 2 lines
Regards,
Sudeep
Reviewed-by
#3 lore raw
In reply to Aneesh Kumar K.V
Quoted 20 lines · Aneesh Kumar K.V
Quoted 7 lines · Suzuki K Poulose

Hi Aneesh

Quoted 4 lines · Aneesh Kumar K.V (Arm)

The device probe passes zeroes for all seven argument registers to arm_smccc_1_1_invoke(). On ARM32 Thumb-2, this binds an input to r7 and GCC 8.5 reports "r7 cannot be used in asm here".

Quoted 9 lines
Quoted 5 lines

The current smccc_devices entries need at most one argument after the function ID: TRNG_VERSION has none and RSI_ABI_VERSION takes a requested version. Pass zero for that argument and omit the unused arguments, avoiding the r7 constraint. Check argument requirements when adding new probe functions to smccc_devices.

Is it safer to use x1-x3 to 0 as they could be the results that we get back from SMCCC v1.0 onwards ?

Quoted 5 lines

I'm not sure I follow. Passing additional zero arguments only initializes the input registers; it should not affect how return values are handled. arm_smccc_1_1_invoke() already declares x0-x3 as outputs. Since these probe functions require no inputs in x2 or x3 and we only inspect x0 on return, why do we need to initialize them to zero?

Agree, I meant, passing 0s for x0-x3 future proofs the new calls. We know that x0-x3 could get overwritten by these calls, and is safe to be zero'd on a call.

But agree, for the existing users just x1 is enough.

Either way,

Cheers
Suzuki

Quoted 3 lines

-aneesh

#4 lore raw
Quoted 22 lines · Suzuki K Poulose
Quoted 12 lines · Aneesh Kumar K.V
Quoted 11 lines · Suzuki K Poulose
Quoted 9 lines · Aneesh Kumar K.V (Arm)

The device probe passes zeroes for all seven argument registers to arm_smccc_1_1_invoke(). On ARM32 Thumb-2, this binds an input to r7 and GCC 8.5 reports "r7 cannot be used in asm here".

The current smccc_devices entries need at most one argument after the function ID: TRNG_VERSION has none and RSI_ABI_VERSION takes a requested version. Pass zero for that argument and omit the unused arguments, avoiding the r7 constraint. Check argument requirements when adding new probe functions to smccc_devices.

Quoted 8 lines
Quoted 2 lines

Is it safer to use x1-x3 to 0 as they could be the results that we get back from SMCCC v1.0 onwards ?

I'm not sure I follow. Passing additional zero arguments only initializes the input registers; it should not affect how return values are handled. arm_smccc_1_1_invoke() already declares x0-x3 as outputs. Since these probe functions require no inputs in x2 or x3 and we only inspect x0 on return, why do we need to initialize them to zero?

Quoted 5 lines

Agree, I meant, passing 0s for x0-x3 future proofs the new calls. We know that x0-x3 could get overwritten by these calls, and is safe to be zero'd on a call.

But agree, for the existing users just x1 is enough.

I'd keep it like this for now, it's pretty random anyway. The next time we need a meaningful argument to pass, we'll probably add an args array in struct smccc_device_info.

Quoted 3 lines

Either way,

Thanks.

Signature · 1 line
Catalin
#6 lore raw
In reply to Aneesh Kumar K.V (Arm)
Quoted 11 lines · Aneesh Kumar K.V (Arm)

The device probe passes zeroes for all seven argument registers to arm_smccc_1_1_invoke(). On ARM32 Thumb-2, this binds an input to r7 and GCC 8.5 reports "r7 cannot be used in asm here".

The current smccc_devices entries need at most one argument after the function ID: TRNG_VERSION has none and RSI_ABI_VERSION takes a requested version. Pass zero for that argument and omit the unused arguments, avoiding the r7 constraint. Check argument requirements when adding new probe functions to smccc_devices.

[...]

Applied to arm64 (for-next/smccc-bus), thanks!

[1/1] firmware: smccc: Pass only the required device probe arguments

      https://git.kernel.org/arm64/c/c6e78a4080a3