xen/arm: Fixes and improvements to SMCCC
Subsystems (3)
v2 cover xen/arm: Fixes and improvements to SMCCC
Patch 1 is a bugfix for the issue reported by Jan Setje-Eilers. It needs backporting to Xen 4.22.
Everything else is because I couldn't bear to leave the code generation in such a bad state.
Only minor changes since v1, in patches 4 and 5.
Andrew Cooper (5):
xen/arm: Fix evaluation of parameters for SMCCC calls xen/arm: Introduce arm_smccc_guest_smc() xen/arm: Clean up 32bit arm_smccc_1_1_smc() xen/arm: Rewrite arm_smccc_smc() for arm64 xen/arm: Rewrite arm_smccc_*() to return by value
xen/arch/arm/arm64/smc.S | 16 -- xen/arch/arm/cpuerrata.c | 18 +- xen/arch/arm/firmware/scmi-smc.c | 16 +- xen/arch/arm/include/asm/smccc.h | 238 +++++++++++--------- xen/arch/arm/platforms/exynos5.c | 2 +- xen/arch/arm/platforms/imx8m.c | 16 +- xen/arch/arm/platforms/imx8qm.c | 16 +- xen/arch/arm/platforms/seattle.c | 4 +- xen/arch/arm/platforms/xilinx-zynqmp-eemi.c | 17 +- xen/arch/arm/psci.c | 17 +- xen/arch/arm/tee/optee.c | 50 ++-- xen/arch/arm/traps.c | 4 +- 12 files changed, 187 insertions(+), 227 deletions(-)
base-commit: 48728c33e43329c8037575320ce681a65cc13eb7
Signature · 1 line
2.39.5
PATCH v2 1/5 xen/arm: Fix evaluation of parameters for SMCCC calls
Contrary to what was claimed in commit 67bcf5eae709 ("xen/arm: Simplify type handling for SMCCC declarations"), there is an important reason to retain the intermediate variable. It is unsafe to have any logic between the assignment of the register variabes and the asm() block they're used in.
This logically reverts commit 67bcf5eae709 ("xen/arm: Simplify type handling for SMCCC declarations") while retaining the conversions from commit 7f15d5d13221 ("xen/treewide: More typeof() -> auto conversions").
Adjust __declare_arg_0() to match. It happens to be safe because it's the first register expression once all macros are expanded, but it really should be consistent with the others.
Leave a comment explaining why they must be written like this.
---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Setje-Eilers <[email protected]>
--- xen/arch/arm/include/asm/smccc.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
xen/arch/arm/include/asm/smccc.h +23 -8
@@ -108,37 +108,52 @@ struct arm_smccc_res {#define __constraint_read_6 __constraint_read_5, "r" (arg6)#define __constraint_read_7 __constraint_read_6, "r" (arg7) +/* +* Macro arguments MUST be evaluated before being assigned to a register +* variable. +* +* This is manual register scheduling for the asm() statement, and any other +* logic to evaluate may clobber the already-scheduled registers. +*/ #define __declare_arg_0 (a0, res) \ + auto __a0 = (uint32_t)(a0); \ struct arm_smccc_res *___res = (res); \ - register unsigned long arg0 ASM_REG(0) = (uint32_t)(a0) + register unsigned long arg0 ASM_REG(0) = __a0#define __declare_arg_1 (a0, a1, res) \ + auto __a1 = (a1); \ __declare_arg_0(a0, res); \ - register auto arg1 ASM_REG(1) = (a1) + register auto arg1 ASM_REG(1) = __a1#define __declare_arg_2 (a0, a1, a2, res) \ + auto __a2 = (a2); \ __declare_arg_1(a0, a1, res); \ - register auto arg2 ASM_REG(2) = (a2) + register auto arg2 ASM_REG(2) = __a2#define __declare_arg_3 (a0, a1, a2, a3, res) \ + auto __a3 = (a3); \ __declare_arg_2(a0, a1, a2, res); \ - register auto arg3 ASM_REG(3) = (a3) + register auto arg3 ASM_REG(3) = __a3#define __declare_arg_4 (a0, a1, a2, a3, a4, res) \ + auto __a4 = (a4); \ __declare_arg_3(a0, a1, a2, a3, res); \ - register auto arg4 ASM_REG(4) = (a4) + register auto arg4 ASM_REG(4) = __a4#define __declare_arg_5 (a0, a1, a2, a3, a4, a5, res) \ + auto __a5 = (a5); \ __declare_arg_4(a0, a1, a2, a3, a4, res); \ - register auto arg5 ASM_REG(5) = (a5) + register auto arg5 ASM_REG(5) = __a5#define __declare_arg_6 (a0, a1, a2, a3, a4, a5, a6, res) \ + auto __a6 = (a6); \ __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \ - register auto arg6 ASM_REG(6) = (a6) + register auto arg6 ASM_REG(6) = __a6#define __declare_arg_7 (a0, a1, a2, a3, a4, a5, a6, a7, res) \ + auto __a7 = (a7); \ __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \ - register auto arg7 ASM_REG(7) = (a7) + register auto arg7 ASM_REG(7) = __a7#define ___declare_args (count, ...) __declare_arg_ ## count(__VA_ARGS__)#define __declare_args (count, ...) ___declare_args(count, __VA_ARGS__)
Signature · 1 line
2.39.5
Re: [PATCH v2 1/5] xen/arm: Fix evaluation of parameters for SMCCC calls
Hi Andrew,
Quoted 6 lines · Andrew Cooper
Contrary to what was claimed in commit
67bcf5eae709("xen/arm: Simplify type handling for SMCCC declarations"), there is an important reason to retain the intermediate variable. It is unsafe to have any logic between the assignment of the register variabes and theasm()block they're used in.
One small typo here s/variabes/variables/
You can fix on commit and retain my R-b
Cheers
Bertrand
Quoted 94 lines
This logically reverts commit
67bcf5eae709("xen/arm: Simplify type handling for SMCCC declarations") while retaining the conversions from commit7f15d5d13221("xen/treewide: Moretypeof()-> auto conversions").Adjust
__declare_arg_0()to match. It happens to be safe because it's the first register expression once all macros are expanded, but it really should be consistent with the others.Leave a comment explaining why they must be written like this.
Fixes 67bcf5eae709 ("xen/arm: Simplify type handling for SMCCC declarations")Reported-by Jan Setje-Eilers <[email protected]>Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Setje-Eilers <[email protected]>
---xen/arch/arm/include/asm/smccc.h| 31 +++++++++++++++++++++++--------1 file changed, 23 insertions(+), 8 deletions(-)xen/arch/arm/include/asm/smccc.h +23
-8@@ -108,37 +108,52 @@ struct arm_smccc_res {#define __constraint_read_6 __constraint_read_5, "r" (arg6)#define __constraint_read_7 __constraint_read_6, "r" (arg7) +/* +* Macro arguments MUST be evaluated before being assigned to a register +* variable. +* +* This is manual register scheduling for the asm() statement, and any other +* logic to evaluate may clobber the already-scheduled registers. +*/ #define __declare_arg_0 (a0, res) \ + auto __a0 = (uint32_t)(a0); \ struct arm_smccc_res *___res = (res); \ - register unsigned long arg0 ASM_REG(0) = (uint32_t)(a0) + register unsigned long arg0 ASM_REG(0) = __a0#define __declare_arg_1 (a0, a1, res) \ + auto __a1 = (a1); \ __declare_arg_0(a0, res); \ - register auto arg1 ASM_REG(1) = (a1) + register auto arg1 ASM_REG(1) = __a1#define __declare_arg_2 (a0, a1, a2, res) \ + auto __a2 = (a2); \ __declare_arg_1(a0, a1, res); \ - register auto arg2 ASM_REG(2) = (a2) + register auto arg2 ASM_REG(2) = __a2#define __declare_arg_3 (a0, a1, a2, a3, res) \ + auto __a3 = (a3); \ __declare_arg_2(a0, a1, a2, res); \ - register auto arg3 ASM_REG(3) = (a3) + register auto arg3 ASM_REG(3) = __a3#define __declare_arg_4 (a0, a1, a2, a3, a4, res) \ + auto __a4 = (a4); \ __declare_arg_3(a0, a1, a2, a3, res); \ - register auto arg4 ASM_REG(4) = (a4) + register auto arg4 ASM_REG(4) = __a4#define __declare_arg_5 (a0, a1, a2, a3, a4, a5, res) \ + auto __a5 = (a5); \ __declare_arg_4(a0, a1, a2, a3, a4, res); \ - register auto arg5 ASM_REG(5) = (a5) + register auto arg5 ASM_REG(5) = __a5#define __declare_arg_6 (a0, a1, a2, a3, a4, a5, a6, res) \ + auto __a6 = (a6); \ __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \ - register auto arg6 ASM_REG(6) = (a6) + register auto arg6 ASM_REG(6) = __a6#define __declare_arg_7 (a0, a1, a2, a3, a4, a5, a6, a7, res) \ + auto __a7 = (a7); \ __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \ - register auto arg7 ASM_REG(7) = (a7) + register auto arg7 ASM_REG(7) = __a7#define ___declare_args (count, ...) __declare_arg_ ## count(__VA_ARGS__)#define __declare_args (count, ...) ___declare_args(count, __VA_ARGS__)Signature · 1 line
2.39.5
PATCH v2 2/5 xen/arm: Introduce arm_smccc_guest_smc()
In reply to Andrew CooperBoth {get,set}_user_reg() are out-of-line functions, leading to awful code generation.
Introduce arm_smccc_guest_smc() to operate directly on guest registers.
No functional change.
---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Setje-Eilers <[email protected]>
For arm64:
add/remove: 0/0 grow/shrink: 2/4 up/down: 27/-864 (-837)
Function old new delta
symbols_addresses 35096 35120 +24 symbols_names 42958 42961 +3 imx8qm_smc 544 348 -196 scmi_handle_smc 372 152 -220 imx8m_smc 576 356 -220 zynqmp_eemi 864 636 -228
For arm32:
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-160 (-160)
Function old new delta scmi_handle_smc 392 232 -160 --- xen/arch/arm/firmware/scmi-smc.c | 16 +----------- xen/arch/arm/include/asm/smccc.h | 29 +++++++++++++++++++++ xen/arch/arm/platforms/imx8m.c | 16 +----------- xen/arch/arm/platforms/imx8qm.c | 16 +----------- xen/arch/arm/platforms/xilinx-zynqmp-eemi.c | 17 ++---------- 5 files changed, 34 insertions(+), 60 deletions(-)
xen/arch/arm/firmware/scmi-smc.c +1 -15
@@ -50,7 +50,6 @@ static bool scmi_is_valid_smc_id(uint32_t fid)static bool scmi_handle_smc (struct cpu_user_regs *regs) {uint32_t fid = (uint32_t )get_user_reg (regs,0 ); -struct arm_smccc_res res;if ( !scmi_is_valid_smc_id (fid) )return false;
@@ -63,20 +62,7 @@ static bool scmi_handle_smc(struct cpu_user_regs *regs) }/* For the moment, forward the SCMI Request to FW running at EL3 */ -arm_smccc_1_1_smc (fid, -get_user_reg (regs,1 ), -get_user_reg (regs,2 ), -get_user_reg (regs,3 ), -get_user_reg (regs,4 ), -get_user_reg (regs,5 ), -get_user_reg (regs,6 ), -get_user_reg (regs,7 ), - &res); - -set_user_reg (regs,0 , res.a0); -set_user_reg (regs,1 , res.a1); -set_user_reg (regs,2 , res.a2); -set_user_reg (regs,3 , res.a3); +arm_smccc_guest_smc (regs);return true; }
xen/arch/arm/include/asm/smccc.h +29 -0
@@ -202,6 +202,21 @@ struct arm_smccc_res {#ifdef CONFIG_ARM_32 #define arm_smccc_1_0_smc (...) arm_smccc_1_1_smc(__VA_ARGS__)#define arm_smccc_smc (...) arm_smccc_1_1_smc(__VA_ARGS__) + +/* Make an SMCCC v1.1 compliant SMC call with guest register state. */ +static inline void arm_smccc_guest_smc (struct cpu_user_regs *regs) +{ +struct arm_smccc_res res; + +arm_smccc_1_1_smc (regs->r0, regs->r1, regs->r2, regs->r3, + regs->r4, regs->r5, regs->r6, regs->r7, &res); + + regs->r0 = res.a0; + regs->r1 = res.a1; + regs->r2 = res.a2; + regs->r3 = res.a3; +} +#else void __arm_smccc_1_0_smc(register_t a0, register_t a1, register_t a2,
@@ -251,6 +266,20 @@ void __arm_smccc_1_0_smc(register_t a0, register_t a1, register_t a2,arm_smccc_1_0_smc (__VA_ARGS__); \ }while (0 ) +/* Make an SMCCC v1.1 compliant SMC call with guest register state. */ +static inline void arm_smccc_guest_smc(struct cpu_user_regs *regs) +{ +struct arm_smccc_res res; + +arm_smccc_1_1_smc (regs->x0, regs->x1, regs->x2, regs->x3, + regs->x4, regs->x5, regs->x6, regs->x7, &res); + + regs->x0 = res.a0; + regs->x1 = res.a1; + regs->x2 = res.a2; + regs->x3 = res.a3; +} +/* * struct arm_smccc_1_2_regs - Arguments for or Results from SMC call * @a0-a17 argument values from registers 0 to 17
xen/arch/arm/platforms/imx8m.c +1 -15
@@ -50,7 +50,6 @@ static bool imx8m_smc(struct cpu_user_regs *regs) {uint32_t function_id =get_user_reg (regs,0 );uint32_t subfunction_id =get_user_reg (regs,1 ); -struct arm_smccc_res res;if ( !cpus_have_const_cap (ARM_SMCCC_1_1 ) ) {
@@ -122,20 +121,7 @@ static bool imx8m_smc(struct cpu_user_regs *regs)return false; } -arm_smccc_1_1_smc (function_id, - subfunction_id, -get_user_reg (regs,2 ), -get_user_reg (regs,3 ), -get_user_reg (regs,4 ), -get_user_reg (regs,5 ), -get_user_reg (regs,6 ), -get_user_reg (regs,7 ), - &res); - -set_user_reg (regs,0 , res.a0); -set_user_reg (regs,1 , res.a1); -set_user_reg (regs,2 , res.a2); -set_user_reg (regs,3 , res.a3); +arm_smccc_guest_smc (regs);return true; }
xen/arch/arm/platforms/imx8qm.c +1 -15
@@ -67,7 +67,6 @@ static bool imx8qm_smc(struct cpu_user_regs *regs) {uint32_t function_id =get_user_reg (regs,0 );uint32_t subfunction_id =get_user_reg (regs,1 ); -struct arm_smccc_res res;if ( !cpus_have_const_cap (ARM_SMCCC_1_1 ) ) {
@@ -106,20 +105,7 @@ static bool imx8qm_smc(struct cpu_user_regs *regs) } allow_call: -arm_smccc_1_1_smc (function_id, - subfunction_id, -get_user_reg (regs,2 ), -get_user_reg (regs,3 ), -get_user_reg (regs,4 ), -get_user_reg (regs,5 ), -get_user_reg (regs,6 ), -get_user_reg (regs,7 ), - &res); - -set_user_reg (regs,0 , res.a0); -set_user_reg (regs,1 , res.a1); -set_user_reg (regs,2 , res.a2); -set_user_reg (regs,3 , res.a3); +arm_smccc_guest_smc (regs);return true; }
xen/arch/arm/platforms/xilinx-zynqmp-eemi.c +2 -15
@@ -51,7 +51,6 @@ static inline bool domain_has_reset_access(struct domain *d, uint32_t rst)bool zynqmp_eemi (struct cpu_user_regs *regs) { -struct arm_smccc_res res;uint32_t fid =get_user_reg (regs,0 );uint32_t nodeid =get_user_reg (regs,1 );unsigned int pm_fn = fid &0xFFFF ;
@@ -187,20 +186,8 @@ bool zynqmp_eemi(struct cpu_user_regs *regs)* can forward the whole command to firmware without additional * parameters checks. */ -arm_smccc_1_1_smc (get_user_reg (regs,0 ), -get_user_reg (regs,1 ), -get_user_reg (regs,2 ), -get_user_reg (regs,3 ), -get_user_reg (regs,4 ), -get_user_reg (regs,5 ), -get_user_reg (regs,6 ), -get_user_reg (regs,7 ), - &res); - -set_user_reg (regs,0 , res.a0); -set_user_reg (regs,1 , res.a1); -set_user_reg (regs,2 , res.a2); -set_user_reg (regs,3 , res.a3); +arm_smccc_guest_smc (regs); +return true; done:
Signature · 1 line
2.39.5
PATCH v2 3/5 xen/arm: Clean up 32bit arm_smccc_1_1_smc()
In reply to Andrew Cooper... before making a related copy of it.
* Drop __constraints() so the output parameters are visible in the same block as they're defined. Use PASTE() rather than opencoding it.
* Adust the indentation of trailing \'s for consistency.
* Drop the newline at the end of the instruction.
* Indent the if condition correctly. ___res is always of type arm_smccc_res (declared in __declare_arg_0()), so drop the typeof().
* Drop arm_smccc_1_0_smc() as it has no users.
No functional change.
---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Setje-Eilers <[email protected]>
--- xen/arch/arm/include/asm/smccc.h | 45 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 23 deletions(-)
xen/arch/arm/include/asm/smccc.h +22 -23
@@ -56,6 +56,8 @@#ifndef __ASSEMBLER__ +#include <xen/macros.h> +extern uint32_t smccc_ver;/* Check if this is fast call. */
@@ -115,24 +117,24 @@ struct arm_smccc_res {* This is manual register scheduling for the asm() statement, and any other * logic to evaluate may clobber the already-scheduled registers. */ -#define __declare_arg_0 (a0, res) \ - auto __a0 = (uint32_t)(a0); \ - struct arm_smccc_res *___res = (res); \ +#define __declare_arg_0 (a0, res) \ + auto __a0 = (uint32_t)(a0); \ + struct arm_smccc_res *___res = (res); \ register unsigned long arg0 ASM_REG(0) = __a0 -#define __declare_arg_1 (a0, a1, res) \ - auto __a1 = (a1); \ - __declare_arg_0(a0, res); \ +#define __declare_arg_1 (a0, a1, res) \ + auto __a1 = (a1); \ + __declare_arg_0(a0, res); \ register auto arg1 ASM_REG(1) = __a1 -#define __declare_arg_2 (a0, a1, a2, res) \ - auto __a2 = (a2); \ - __declare_arg_1(a0, a1, res); \ +#define __declare_arg_2 (a0, a1, a2, res) \ + auto __a2 = (a2); \ + __declare_arg_1(a0, a1, res); \ register auto arg2 ASM_REG(2) = __a2 -#define __declare_arg_3 (a0, a1, a2, a3, res) \ - auto __a3 = (a3); \ - __declare_arg_2(a0, a1, a2, res); \ +#define __declare_arg_3 (a0, a1, a2, a3, res) \ + auto __a3 = (a3); \ + __declare_arg_2(a0, a1, a2, res); \ register auto arg3 ASM_REG(3) = __a3#define __declare_arg_4 (a0, a1, a2, a3, a4, res) \
@@ -158,12 +160,6 @@ struct arm_smccc_res {#define ___declare_args (count, ...) __declare_arg_ ## count(__VA_ARGS__)#define __declare_args (count, ...) ___declare_args(count, __VA_ARGS__) -#define ___constraints (count) \ - : "=r" (r0), "=r" (r1), "=r" (r2), "=r" (r3) \ - : __constraint_read_ ## count \ - : "memory" -#define __constraints (count) ___constraints(count) -/* * arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call *
@@ -189,10 +185,14 @@ struct arm_smccc_res { register unsigned long r2 ASM_REG(2); \ register unsigned long r3 ASM_REG(3); \__declare_args (__count_args (__VA_ARGS__), __VA_ARGS__); \ - asmvolatile ("smc #0\n" \ - __constraints(__count_args(__VA_ARGS__))); \ + asmvolatile ( \ +"smc #0" \ + :"=r" (r0),"=r" (r1),"=r" (r2),"=r" (r3) \ + : PASTE(__constraint_read_, \ + __count_args(__VA_ARGS__)) \ + : "memory" ); \if ( ___res ) \ - *___res = (typeof(*___res)){r0, r1, r2, r3}; \ + *___res = (struct arm_smccc_res ){ r0, r1, r2, r3 }; \ }while (0 )/*
@@ -200,7 +200,6 @@ struct arm_smccc_res {* v1.1. */ #ifdef CONFIG_ARM_32 -#define arm_smccc_1_0_smc (...) arm_smccc_1_1_smc(__VA_ARGS__)#define arm_smccc_smc (...) arm_smccc_1_1_smc(__VA_ARGS__)/* Make an SMCCC v1.1 compliant SMC call with guest register state. */
@@ -217,7 +216,7 @@ static inline void arm_smccc_guest_smc(struct cpu_user_regs *regs) regs->r3 = res.a3; } -#else +#else /* CONFIG_ARM_64 */ void __arm_smccc_1_0_smc(register_t a0, register_t a1, register_t a2, register_t a3, register_t a4, register_t a5,
Signature · 1 line
2.39.5
Re: [PATCH v2 3/5] xen/arm: Clean up 32bit arm_smccc_1_1_smc()
Hi Andrew,
Quoted 7 lines · Andrew Cooper
... before making a related copy of it.
* Drop
__constraints()so the output parameters are visible in the same block as they're defined. UsePASTE()rather than opencoding it.
* Adust the indentation of trailing \'s for consistency.
Small typo to fix s/Adust/Adjust/
Can be done on commit and retain my R-b
Cheers
Bertrand
Quoted 121 lines
* Drop the newline at the end of the instruction.
* Indent the if condition correctly.___resis always of typearm_smccc_res(declared in__declare_arg_0()), so drop thetypeof().
* Droparm_smccc_1_0_smc()as it has no users.No functional change.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Setje-Eilers <[email protected]>
---xen/arch/arm/include/asm/smccc.h| 45 ++++++++++++++++----------------1 file changed, 22 insertions(+), 23 deletions(-)xen/arch/arm/include/asm/smccc.h +22
-23@@ -56,6 +56,8 @@#ifndef __ASSEMBLER__ +#include <xen/macros.h> +extern uint32_t smccc_ver;/* Check if this is fast call. */ @@ -115,24 +117,24 @@ struct arm_smccc_res {* This is manual register scheduling for the asm() statement, and any other * logic to evaluate may clobber the already-scheduled registers. */ -#define __declare_arg_0 (a0, res) \ - auto __a0 = (uint32_t)(a0); \ - struct arm_smccc_res *___res = (res); \ +#define __declare_arg_0 (a0, res) \ + auto __a0 = (uint32_t)(a0); \ + struct arm_smccc_res *___res = (res); \ register unsigned long arg0 ASM_REG(0) = __a0 -#define __declare_arg_1 (a0, a1, res) \ - auto __a1 = (a1); \ - __declare_arg_0(a0, res); \ +#define __declare_arg_1 (a0, a1, res) \ + auto __a1 = (a1); \ + __declare_arg_0(a0, res); \ register auto arg1 ASM_REG(1) = __a1 -#define __declare_arg_2 (a0, a1, a2, res) \ - auto __a2 = (a2); \ - __declare_arg_1(a0, a1, res); \ +#define __declare_arg_2 (a0, a1, a2, res) \ + auto __a2 = (a2); \ + __declare_arg_1(a0, a1, res); \ register auto arg2 ASM_REG(2) = __a2 -#define __declare_arg_3 (a0, a1, a2, a3, res) \ - auto __a3 = (a3); \ - __declare_arg_2(a0, a1, a2, res); \ +#define __declare_arg_3 (a0, a1, a2, a3, res) \ + auto __a3 = (a3); \ + __declare_arg_2(a0, a1, a2, res); \ register auto arg3 ASM_REG(3) = __a3#define __declare_arg_4 (a0, a1, a2, a3, a4, res) \@@ -158,12 +160,6 @@ struct arm_smccc_res {#define ___declare_args (count, ...) __declare_arg_ ## count(__VA_ARGS__)#define __declare_args (count, ...) ___declare_args(count, __VA_ARGS__) -#define ___constraints (count) \ - : "=r" (r0), "=r" (r1), "=r" (r2), "=r" (r3) \ - : __constraint_read_ ## count \ - : "memory" -#define __constraints (count) ___constraints(count) -/* * arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call * @@ -189,10 +185,14 @@ struct arm_smccc_res { register unsigned long r2 ASM_REG(2); \ register unsigned long r3 ASM_REG(3); \__declare_args (__count_args (__VA_ARGS__), __VA_ARGS__); \ - asmvolatile ("smc #0\n" \ - __constraints(__count_args(__VA_ARGS__))); \ + asmvolatile ( \ +"smc #0" \ + :"=r" (r0),"=r" (r1),"=r" (r2),"=r" (r3) \ + : PASTE(__constraint_read_, \ + __count_args(__VA_ARGS__)) \ + : "memory" ); \if ( ___res ) \ - *___res = (typeof(*___res)){r0, r1, r2, r3}; \ + *___res = (struct arm_smccc_res ){ r0, r1, r2, r3 }; \ }while (0 )/* @@ -200,7 +200,6 @@ struct arm_smccc_res {* v1.1. */ #ifdef CONFIG_ARM_32 -#define arm_smccc_1_0_smc (...) arm_smccc_1_1_smc(__VA_ARGS__)#define arm_smccc_smc (...) arm_smccc_1_1_smc(__VA_ARGS__)/* Make an SMCCC v1.1 compliant SMC call with guest register state. */ @@ -217,7 +216,7 @@ static inline void arm_smccc_guest_smc(struct cpu_user_regs *regs) regs->r3 = res.a3; } -#else +#else /* CONFIG_ARM_64 */ void __arm_smccc_1_0_smc(register_t a0, register_t a1, register_t a2, register_t a3, register_t a4, register_t a5,Signature · 1 line
2.39.5
PATCH v2 4/5 xen/arm: Rewrite arm_smccc_smc() for arm64
In reply to Andrew CooperSMCCC v1.0 says that x4 through x17 may be clobbered. SMCCC v1.1 says they are strictly preserved, and SMCCC v1.2 permits them to contain extra return values.
Xen deals with this by having __arm_smccc_1_0_smc() as an out-of-line function, but this causes awful code generation in arm_smccc_smc(). cpus_have_const_cap() is opaque to the optimiser, so we end up with one basic block doing the reasonably-ok arm_smccc_1_1_smc() code generation and a second basic block setting up all 8 input registers even when they're not needed, spilling or discarding x8 through x17, and calling an out-of-line function.
Remove __arm_smccc_1_0_smc() entirely, and rewrite arm_smccc_smc() to declare x4 through x17 as clobbered.
This fully inlines the SMC, is a single basic block which instructs the compiler to spill or discard the potentially clobbered registers, and only sets up the necessary number of arguments for the call.
No functional change.
---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Setje-Eilers <[email protected]>
v2:
* s/PSCI/SMCCC/g
* Rewrite the comment for the new arm_smccc_smc().
Bloat-o-meter reports:
add/remove: 0/1 grow/shrink: 0/10 up/down: 0/-795 (-795)
Function old new delta
symbols_sorted_offsets 23832 23824 -8 symbols_names 42962 42943 -19 symbols_addresses 35128 35104 -24 __arm_smccc_1_0_smc 32 - -32 call_psci_cpu_off 144 76 -68 seattle_system_reset 92 16 -76 seattle_system_off 92 16 -76 call_psci_system_reset 112 32 -80 call_psci_system_off 112 32 -80 call_psci_cpu_on 252 124 -128 psci_init 628 424 -204
An alternative way to do this would be to have x8 thru x17 in the clobber list rather than the output list which would reduce the source size, but this form is more amenable to having SMCCC v1.2 worked into it too.
--- xen/arch/arm/arm64/smc.S | 16 ------ xen/arch/arm/include/asm/smccc.h | 92 ++++++++++++++++---------------- 2 files changed, 45 insertions(+), 63 deletions(-)
xen/arch/arm/arm64/smc.S +0 -16
@@ -13,22 +13,6 @@ * GNU General Public License for more details. */ -/* - * void __arm_smccc_1_0_smc(register_t a0, register_t a1, register_t a2, - * register_t a3, register_t a4, register_t a5, - * register_t a6, register_t a7, - * struct arm_smccc_res *res) - */ -FUNC(__arm_smccc_1_0_smc) - smc #0 - ldr x4, [sp] - cbz x4, 1f /* No need to store the result */ - stp x0, x1, [x4, #SMCCC_RES_a0] - stp x2, x3, [x4, #SMCCC_RES_a2] -1: - ret -END(__arm_smccc_1_0_smc) - /* * void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args, * struct arm_smccc_1_2_regs *res)
xen/arch/arm/include/asm/smccc.h +45 -47
126 lines not on this page · raw message
Signature · 1 line
2.39.5
Re: [PATCH v2 4/5] xen/arm: Rewrite arm_smccc_smc() for arm64
Hi Andrew,
Quoted 16 lines · Andrew Cooper
SMCCC v1.0 says that x4 through x17 may be clobbered. SMCCC v1.1 says they are strictly preserved, and SMCCC v1.2 permits them to contain extra return values.
Xen deals with this by having
__arm_smccc_1_0_smc()as an out-of-line function, but this causes awful code generation inarm_smccc_smc().cpus_have_const_cap()is opaque to the optimiser, so we end up with one basic block doing the reasonably-okarm_smccc_1_1_smc()code generation and a second basic block setting up all 8 input registers even when they're not needed, spilling or discarding x8 through x17, and calling an out-of-line function.Remove
__arm_smccc_1_0_smc()entirely, and rewritearm_smccc_smc()to declare x4 through x17 as clobbered.
Quoted 7 lines
This fully inlines the SMC, is a single basic block which instructs the compiler to spill or discard the potentially clobbered registers, and only sets up the necessary number of arguments for the call.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Lot better thanks for the fixes.
Cheers
Bertrand
Quoted 201 lines
---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Setje-Eilers <[email protected]>v2:
* s/PSCI/SMCCC/g
* Rewrite the comment for the newarm_smccc_smc().Bloat-o-meter reports:
add/remove: 0/1 grow/shrink: 0/10 up/down: 0/-795 (-795)
Function old new deltasymbols_sorted_offsets 23832 23824 -8 symbols_names 42962 42943 -19 symbols_addresses 35128 35104 -24 __arm_smccc_1_0_smc 32 - -32 call_psci_cpu_off 144 76 -68 seattle_system_reset 92 16 -76 seattle_system_off 92 16 -76 call_psci_system_reset 112 32 -80 call_psci_system_off 112 32 -80 call_psci_cpu_on 252 124 -128 psci_init 628 424 -204An alternative way to do this would be to have x8 thru x17 in the clobber list rather than the output list which would reduce the source size, but this form is more amenable to having SMCCC v1.2 worked into it too.
---xen/arch/arm/arm64/smc.S| 16 ------xen/arch/arm/include/asm/smccc.h| 92 ++++++++++++++++----------------2 files changed, 45 insertions(+), 63 deletions(-)xen/arch/arm/arm64/smc.S +0
-16@@ -13,22 +13,6 @@ * GNU General Public License for more details. */ -/* - * void __arm_smccc_1_0_smc(register_t a0, register_t a1, register_t a2, - * register_t a3, register_t a4, register_t a5, - * register_t a6, register_t a7, - * struct arm_smccc_res *res) - */ -FUNC(__arm_smccc_1_0_smc) - smc #0 - ldr x4, [sp] - cbz x4, 1f /* No need to store the result */ - stp x0, x1, [x4, #SMCCC_RES_a0] - stp x2, x3, [x4, #SMCCC_RES_a2] -1: - ret -END(__arm_smccc_1_0_smc) - /* * void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args, * struct arm_smccc_1_2_regs *res)xen/arch/arm/include/asm/smccc.h +45
-47@@ -16,9 +16,6 @@#ifndef __ASM_ARM_SMCCC_H__#define __ASM_ARM_SMCCC_H__ -#include <asm/alternative.h> -#include <asm/cpufeature.h> -#define SMCCC_VERSION_MAJOR_SHIFT 16#define SMCCC_VERSION_MINOR_MASK \ ((1U << SMCCC_VERSION_MAJOR_SHIFT) - 1)@@ -57,6 +54,9 @@#ifndef __ASSEMBLER__#include <xen/macros.h> +#include <xen/types.h> + +#include <asm/asm_defns.h> extern uint32_t smccc_ver;@@ -160,6 +160,8 @@ struct arm_smccc_res {#define ___declare_args (count, ...) __declare_arg_ ## count(__VA_ARGS__)#define __declare_args (count, ...) ___declare_args(count, __VA_ARGS__) +#ifdef CONFIG_ARM_32 +/* * arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call * @@ -199,7 +201,6 @@ struct arm_smccc_res {* The calling convention for arm32 is the same for both SMCCC v1.0 and * v1.1. */ -#ifdef CONFIG_ARM_32 #define arm_smccc_smc (...) arm_smccc_1_1_smc(__VA_ARGS__)/* Make an SMCCC v1.1 compliant SMC call with guest register state. */ @@ -218,53 +219,50 @@ static inline void arm_smccc_guest_smc(struct cpu_user_regs *regs)#else /* CONFIG_ARM_64 */ -void __arm_smccc_1_0_smc (register_t a0,register_t a1,register_t a2, -register_t a3,register_t a4,register_t a5, -register_t a6,register_t a7, -struct arm_smccc_res *res); - -/* Macros to handle variadic parameter for SMCCC v1.0 helper */ -#define __arm_smccc_1_0_smc_7 (a0, a1, a2, a3, a4, a5, a6, a7, res) \ - __arm_smccc_1_0_smc(a0, a1, a2, a3, a4, a5, a6, a7, res) - -#define __arm_smccc_1_0_smc_6 (a0, a1, a2, a3, a4, a5, a6, res) \ - __arm_smccc_1_0_smc_7(a0, a1, a2, a3, a4, a5, a6, 0, res) - -#define __arm_smccc_1_0_smc_5 (a0, a1, a2, a3, a4, a5, res) \ - __arm_smccc_1_0_smc_6(a0, a1, a2, a3, a4, a5, 0, res) - -#define __arm_smccc_1_0_smc_4 (a0, a1, a2, a3, a4, res) \ - __arm_smccc_1_0_smc_5(a0, a1, a2, a3, a4, 0, res) - -#define __arm_smccc_1_0_smc_3 (a0, a1, a2, a3, res) \ - __arm_smccc_1_0_smc_4(a0, a1, a2, a3, 0, res) - -#define __arm_smccc_1_0_smc_2 (a0, a1, a2, res) \ - __arm_smccc_1_0_smc_3(a0, a1, a2, 0, res) - -#define __arm_smccc_1_0_smc_1 (a0, a1, res) \ - __arm_smccc_1_0_smc_2(a0, a1, 0, res) - -#define __arm_smccc_1_0_smc_0 (a0, res) \ - __arm_smccc_1_0_smc_1(a0, 0, res) - -#define ___arm_smccc_1_0_smc_count (count, ...) \ - __arm_smccc_1_0_smc_ ## count(__VA_ARGS__) - -#define __arm_smccc_1_0_smc_count (count, ...) \ - ___arm_smccc_1_0_smc_count(count, __VA_ARGS__) - -#define arm_smccc_1_0_smc (...) \ - __arm_smccc_1_0_smc_count(__count_args(__VA_ARGS__), __VA_ARGS__) - +/* +* Make an SMC call compatible with both SMCCC v1.1 and v1.0. +* +* SMCCC v1.0 says that x4 through x17 are clobbered. SMCCC v1.1 says they +* are strictly preserved. Always mark x4 through x17 as clobbered. +*/ #define arm_smccc_smc (...) \ do { \ - if ( cpus_have_const_cap(ARM_SMCCC_1_1) ) \ - arm_smccc_1_1_smc(__VA_ARGS__); \ - else \ - arm_smccc_1_0_smc(__VA_ARGS__); \ + register unsigned long r0 ASM_REG(0); \ + register unsigned long r1 ASM_REG(1); \ + register unsigned long r2 ASM_REG(2); \ + register unsigned long r3 ASM_REG(3); \ +/* Potentially clobbered in SMCCC v1.0 */ \ + register unsigned long c4 ASM_REG(4); \ + register unsigned long c5 ASM_REG(5); \ + register unsigned long c6 ASM_REG(6); \ + register unsigned long c7 ASM_REG(7); \ + register unsigned long c8 ASM_REG(8); \ + register unsigned long c9 ASM_REG(9); \ + register unsigned long c10 ASM_REG(10); \ + register unsigned long c11 ASM_REG(11); \ + register unsigned long c12 ASM_REG(12); \ + register unsigned long c13 ASM_REG(13); \ + register unsigned long c14 ASM_REG(14); \ + register unsigned long c15 ASM_REG(15); \ + register unsigned long c16 ASM_REG(16); \ + register unsigned long c17 ASM_REG(17); \ +__declare_args (__count_args (__VA_ARGS__), __VA_ARGS__); \ + asmvolatile ( \ +"smc #0" \ + :"=r" (r0),"=r" (r1),"=r" (r2),"=r" (r3), \ +"=r" (c4),"=r" (c5),"=r" (c6),"=r" (c7), \ +"=r" (c8),"=r" (c9),"=r" (c10),"=r" (c11), \ +"=r" (c12),"=r" (c13),"=r" (c14),"=r" (c15), \ +"=r" (c16),"=r" (c17) \ + : PASTE(__constraint_read_, \ + __count_args(__VA_ARGS__)) \ + : "memory" ); \ +if ( ___res ) \ + *___res = (struct arm_smccc_res ){ r0, r1, r2, r3 }; \ } while ( 0 ) +#define arm_smccc_1_1_smc (...) arm_smccc_smc(__VA_ARGS__) +/* Make an SMCCC v1.1 compliant SMC call with guest register state. */ static inline void arm_smccc_guest_smc (struct cpu_user_regs *regs) {Signature · 1 line
2.39.5
PATCH v2 5/5 xen/arm: Rewrite arm_smccc_*() to return by value
In reply to Andrew CooperUse statement expressions to return struct arm_smccc_res which makes the code read a lot more normally, and avoids needing to pass in NULL in order to skip return information.
More importantly, it removes the local implementation of __count_args() which is off by two and deeply confusing to try and follow.
No functional change.
---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Setje-Eilers <[email protected]>
v2:
* Transform extra call in optee_probe()
Xen compiles identically before and after this change, for both arm32 and arm64.
--- xen/arch/arm/cpuerrata.c | 18 +++---- xen/arch/arm/include/asm/smccc.h | 87 ++++++++++++++------------------ xen/arch/arm/platforms/exynos5.c | 2 +- xen/arch/arm/platforms/seattle.c | 4 +- xen/arch/arm/psci.c | 17 +++---- xen/arch/arm/tee/optee.c | 50 +++++++++--------- xen/arch/arm/traps.c | 4 +- 7 files changed, 86 insertions(+), 96 deletions(-)
xen/arch/arm/cpuerrata.c +9 -9
@@ -179,8 +179,8 @@ static int enable_smccc_arch_workaround_1(void *data)if ( smccc_ver <SMCCC_VERSION (1 ,1 ) ) goto warn; -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , -ARM_SMCCC_ARCH_WORKAROUND_1_FID , &res); + res =arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , +ARM_SMCCC_ARCH_WORKAROUND_1_FID );/* The return value is in the lower 32-bits. */ if ( (int )res.a0 <0 ) goto warn;
@@ -256,8 +256,8 @@ static int enable_spectre_bhb_workaround(void *data)if ( smccc_ver <SMCCC_VERSION (1 ,1 ) ) goto warn; -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , -ARM_SMCCC_ARCH_WORKAROUND_3_FID , &res); + res =arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , +ARM_SMCCC_ARCH_WORKAROUND_3_FID );/* The return value is in the lower 32-bits. */ if ( (int )res.a0 <0 ) {
@@ -398,8 +398,8 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)if ( smccc_ver <SMCCC_VERSION (1 ,1 ) )return false; -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , -ARM_SMCCC_ARCH_WORKAROUND_2_FID , &res); + res =arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , +ARM_SMCCC_ARCH_WORKAROUND_2_FID );switch ( (int )res.a0 ) {
@@ -429,7 +429,7 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)case ARM_SSBD_FORCE_DISABLE :printk_once ("%s disabled from command-line\n" , entry->desc); -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ); required = false;break ;
@@ -437,7 +437,7 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)if ( required ) {this_cpu (ssbd_callback_required) =1 ; -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ); }break ;
@@ -445,7 +445,7 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)case ARM_SSBD_FORCE_ENABLE :printk_once ("%s forced from command-line\n" , entry->desc); -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ); required = true;break ;
xen/arch/arm/include/asm/smccc.h +39 -48
165 lines not on this page · raw message
xen/arch/arm/platforms/exynos5.c +1 -1
@@ -249,7 +249,7 @@ static int exynos5_cpu_up(int cpu)iounmap (power);if ( secure_firmware ) -arm_smccc_smc (SMC_CMD_CPU1BOOT , cpu,NULL ); +arm_smccc_smc (SMC_CMD_CPU1BOOT , cpu);return cpu_up_send_sgi (cpu); }
xen/arch/arm/platforms/seattle.c +2 -2
@@ -33,12 +33,12 @@ static const char * const seattle_dt_compat[] __initconst =*/ static void seattle_system_reset (void ) { -arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_RESET ,NULL ); +arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_RESET ); }static void seattle_system_off (void ) { -arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_OFF ,NULL ); +arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_OFF ); }PLATFORM_START (seattle,"SEATTLE" )
xen/arch/arm/psci.c +8 -9
@@ -41,8 +41,8 @@ int call_psci_cpu_on(int cpu) {struct arm_smccc_res res; -arm_smccc_smc (psci_cpu_on_nr,cpu_logical_map (cpu),__pa (init_secondary), - &res); + res =arm_smccc_smc (psci_cpu_on_nr,cpu_logical_map (cpu), +__pa (init_secondary));return PSCI_RET (res); }
@@ -54,7 +54,7 @@ void call_psci_cpu_off(void)struct arm_smccc_res res;/* If successfull the PSCI cpu_off call doesn't return */ -arm_smccc_smc (PSCI_0_2_FN32_CPU_OFF , &res); + res =arm_smccc_smc (PSCI_0_2_FN32_CPU_OFF );panic ("PSCI cpu off failed for CPU%d err=%d\n" ,smp_processor_id (),PSCI_RET (res)); }
@@ -63,13 +63,13 @@ void call_psci_cpu_off(void)void call_psci_system_off (void ) {if ( psci_ver >PSCI_VERSION (0 ,1 ) ) -arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_OFF ,NULL ); +arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_OFF ); }void call_psci_system_reset (void ) {if ( psci_ver >PSCI_VERSION (0 ,1 ) ) -arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_RESET ,NULL ); +arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_RESET ); }static int __init psci_features (uint32_t psci_func_id)
@@ -79,7 +79,7 @@ static int __init psci_features(uint32_t psci_func_id)if ( psci_ver <PSCI_VERSION (1 ,0 ) )return PSCI_NOT_SUPPORTED ; -arm_smccc_smc (PSCI_1_0_FN32_PSCI_FEATURES , psci_func_id, &res); + res =arm_smccc_smc (PSCI_1_0_FN32_PSCI_FEATURES , psci_func_id);return PSCI_RET (res); }
@@ -116,9 +116,8 @@ static void __init psci_init_smccc(void)if (psci_features (ARM_SMCCC_VERSION_FID ) !=PSCI_NOT_SUPPORTED ) { -struct arm_smccc_res res; +struct arm_smccc_res res =arm_smccc_smc (ARM_SMCCC_VERSION_FID ); -arm_smccc_smc (ARM_SMCCC_VERSION_FID , &res);if (PSCI_RET (res) !=ARM_SMCCC_NOT_SUPPORTED ) smccc_ver =PSCI_RET (res); }
@@ -191,7 +190,7 @@ static int __init psci_init_0_2(void) } } -arm_smccc_smc (PSCI_0_2_FN32_PSCI_VERSION , &res); + res =arm_smccc_smc (PSCI_0_2_FN32_PSCI_VERSION ); psci_ver =PSCI_RET (res);/* For the moment, we only support PSCI 0.2 and PSCI 1.x */
xen/arch/arm/tee/optee.c +25 -25
129 lines not on this page · raw message
xen/arch/arm/traps.c +2 -2
@@ -1991,7 +1991,7 @@ void asmlinkage enter_hypervisor_from_guest_preirq(void)/* If the guest has disabled the workaround, bring it back on. */ if (needs_ssbd_flip (v) ) -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ); }/*
@@ -2334,7 +2334,7 @@ void asmlinkage leave_hypervisor_to_guest(void)* If the guest wants it disabled, so be it... */ if (needs_ssbd_flip (current) ) -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ); }/*
Signature · 1 line
2.39.5
Re: [PATCH v2 5/5] xen/arm: Rewrite arm_smccc_*() to return by value
Hi Andrew,
Quoted 194 lines · Andrew Cooper
Use statement expressions to return struct
arm_smccc_reswhich makes the code read a lot more normally, and avoids needing to pass in NULL in order to skip return information.More importantly, it removes the local implementation of
__count_args()which is off by two and deeply confusing to try and follow.No functional change.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Setje-Eilers <[email protected]>v2:
* Transform extra call inoptee_probe()Xen compiles identically before and after this change, for both arm32 and arm64.
---xen/arch/arm/cpuerrata.c | 18 +++---- xen/arch/arm/include/asm/smccc.h | 87 ++++++++++++++------------------ xen/arch/arm/platforms/exynos5.c | 2 +- xen/arch/arm/platforms/seattle.c | 4 +- xen/arch/arm/psci.c | 17 +++---- xen/arch/arm/tee/optee.c | 50 +++++++++--------- xen/arch/arm/traps.c | 4 +- 7 files changed, 86 insertions(+), 96 deletions(-)xen/arch/arm/cpuerrata.c +9
-9@@ -179,8 +179,8 @@ static int enable_smccc_arch_workaround_1(void *data)if ( smccc_ver <SMCCC_VERSION (1 ,1 ) ) goto warn; -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , -ARM_SMCCC_ARCH_WORKAROUND_1_FID , &res); + res =arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , +ARM_SMCCC_ARCH_WORKAROUND_1_FID );/* The return value is in the lower 32-bits. */ if ( (int )res.a0 <0 ) goto warn;@@ -256,8 +256,8 @@ static int enable_spectre_bhb_workaround(void *data)if ( smccc_ver <SMCCC_VERSION (1 ,1 ) ) goto warn; -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , -ARM_SMCCC_ARCH_WORKAROUND_3_FID , &res); + res =arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , +ARM_SMCCC_ARCH_WORKAROUND_3_FID );/* The return value is in the lower 32-bits. */ if ( (int )res.a0 <0 ) {@@ -398,8 +398,8 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)if ( smccc_ver <SMCCC_VERSION (1 ,1 ) )return false; -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , -ARM_SMCCC_ARCH_WORKAROUND_2_FID , &res); + res =arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , +ARM_SMCCC_ARCH_WORKAROUND_2_FID );switch ( (int )res.a0 ) {@@ -429,7 +429,7 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)case ARM_SSBD_FORCE_DISABLE :printk_once ("%s disabled from command-line\n" , entry->desc); -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ); required = false;break ;@@ -437,7 +437,7 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)if ( required ) {this_cpu (ssbd_callback_required) =1 ; -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ); }break ;@@ -445,7 +445,7 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)case ARM_SSBD_FORCE_ENABLE :printk_once ("%s forced from command-line\n" , entry->desc); -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ); required = true;break ;xen/arch/arm/include/asm/smccc.h +25
-32@@ -95,20 +95,14 @@ struct arm_smccc_res {unsigned long a3; }; -/* SMCCC v1.1 implementation madness follows */ -#define ___count_args (_0, _1, _2, _3, _4, _5, _6, _7, _8, x, ...) x - -#define __count_args (...) \ - ___count_args(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0) - -#define __constraint_read_0 "r" (arg0) -#define __constraint_read_1 __constraint_read_0, "r" (arg1) -#define __constraint_read_2 __constraint_read_1, "r" (arg2) -#define __constraint_read_3 __constraint_read_2, "r" (arg3) -#define __constraint_read_4 __constraint_read_3, "r" (arg4) -#define __constraint_read_5 __constraint_read_4, "r" (arg5) -#define __constraint_read_6 __constraint_read_5, "r" (arg6) -#define __constraint_read_7 __constraint_read_6, "r" (arg7) +#define __constraint_read_1 "r" (arg0) +#define __constraint_read_2 __constraint_read_1, "r" (arg1) +#define __constraint_read_3 __constraint_read_2, "r" (arg2) +#define __constraint_read_4 __constraint_read_3, "r" (arg3) +#define __constraint_read_5 __constraint_read_4, "r" (arg4) +#define __constraint_read_6 __constraint_read_5, "r" (arg5) +#define __constraint_read_7 __constraint_read_6, "r" (arg6) +#define __constraint_read_8 __constraint_read_7, "r" (arg7)/* * Macro arguments MUST be evaluated before being assigned to a register @@ -117,44 +111,43 @@ struct arm_smccc_res {* This is manual register scheduling for the asm() statement, and any other * logic to evaluate may clobber the already-scheduled registers. */ -#define __declare_arg_0 (a0, res) \ +#define __declare_arg_1 (a0) \ auto __a0 = (uint32_t)(a0); \ - struct arm_smccc_res *___res = (res); \ register unsigned long arg0 ASM_REG(0) = __a0 -#define __declare_arg_1 (a0, a1, res) \ +#define __declare_arg_2 (a0, a1) \ auto __a1 = (a1); \ - __declare_arg_0(a0, res); \ + __declare_arg_1(a0); \ register auto arg1 ASM_REG(1) = __a1 -#define __declare_arg_2 (a0, a1, a2, res) \ +#define __declare_arg_3 (a0, a1, a2) \ auto __a2 = (a2); \ - __declare_arg_1(a0, a1, res); \ + __declare_arg_2(a0, a1); \ register auto arg2 ASM_REG(2) = __a2 -#define __declare_arg_3 (a0, a1, a2, a3, res) \ +#define __declare_arg_4 (a0, a1, a2, a3) \ auto __a3 = (a3); \ - __declare_arg_2(a0, a1, a2, res); \ + __declare_arg_3(a0, a1, a2); \ register auto arg3 ASM_REG(3) = __a3 -#define __declare_arg_4 (a0, a1, a2, a3, a4, res) \ +#define __declare_arg_5 (a0, a1, a2, a3, a4) \ auto __a4 = (a4); \ - __declare_arg_3(a0, a1, a2, a3, res); \ + __declare_arg_4(a0, a1, a2, a3); \ register auto arg4 ASM_REG(4) = __a4 -#define __declare_arg_5 (a0, a1, a2, a3, a4, a5, res) \ +#define __declare_arg_6 (a0, a1, a2, a3, a4, a5) \ auto __a5 = (a5); \ - __declare_arg_4(a0, a1, a2, a3, a4, res); \ + __declare_arg_5(a0, a1, a2, a3, a4); \ register auto arg5 ASM_REG(5) = __a5 -#define __declare_arg_6 (a0, a1, a2, a3, a4, a5, a6, res) \ - auto __a6 = (a6); \ - __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \ +#define __declare_arg_7 (a0, a1, a2, a3, a4, a5, a6) \ + auto __a6 = (a6); \ + __declare_arg_6(a0, a1, a2, a3, a4, a5); \ register auto arg6 ASM_REG(6) = __a6 -#define __declare_arg_7 (a0, a1, a2, a3, a4, a5, a6, a7, res) \ - auto __a7 = (a7); \ - __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \ +#define __declare_arg_8 (a0, a1, a2, a3, a4, a5, a6, a7) \ + auto __a7 = (a7); \ + __declare_arg_7(a0, a1, a2, a3, a4, a5, a6); \ register auto arg7 ASM_REG(7) = __a7#define ___declare_args (count, ...) __declare_arg_ ## count(__VA_ARGS__)
xen/arch/arm/include/asm/smccc.h struct arm_smccc_res { · line 176
Quoted 3 lines
xen/arch/arm/include/asm/smccc.h +0
-0@@ -181,21 +174,20 @@ struct arm_smccc_res {* makes it stick. */ #define arm_smccc_1_1_smc (...) \
The comment would need fixing on top of this as current one still describes the optional @res argument while now we only take a0 to a7 as arguments and return the structure instead.
Cheers
Bertrand
Quoted 347 lines
xen/arch/arm/include/asm/smccc.h +14
-16-do { \ + ({ \ register unsigned long r0 ASM_REG(0); \ register unsigned long r1 ASM_REG(1); \ register unsigned long r2 ASM_REG(2); \ register unsigned long r3 ASM_REG(3); \ -__declare_args (__count_args (__VA_ARGS__), __VA_ARGS__); \ +__declare_args (count_args (__VA_ARGS__), __VA_ARGS__); \ asmvolatile ( \"smc #0" \ :"=r" (r0),"=r" (r1),"=r" (r2),"=r" (r3) \ : PASTE(__constraint_read_, \ - __count_args(__VA_ARGS__)) \ + count_args(__VA_ARGS__)) \ : "memory" ); \ -if ( ___res ) \ - *___res = (struct arm_smccc_res ){ r0, r1, r2, r3 }; \ - }while (0 ) + (struct arm_smccc_res ){ r0, r1, r2, r3 }; \ + })/* * The calling convention for arm32 is the same for both SMCCC v1.0 and @@ -208,8 +200,8 @@ static inline void arm_smccc_guest_smc(struct cpu_user_regs *regs) {struct arm_smccc_res res; -arm_smccc_1_1_smc (regs->r0, regs->r1, regs->r2, regs->r3, - regs->r4, regs->r5, regs->r6, regs->r7, &res); + res =arm_smccc_1_1_smc (regs->r0, regs->r1, regs->r2, regs->r3, + regs->r4, regs->r5, regs->r6, regs->r7); regs->r0 = res.a0; regs->r1 = res.a1;@@ -226,7 +218,7 @@ static inline void arm_smccc_guest_smc(struct cpu_user_regs *regs)* are strictly preserved. Always mark x4 through x17 as clobbered. */ #define arm_smccc_smc (...) \ - do { \ + ({ \ register unsigned long r0 ASM_REG(0); \ register unsigned long r1 ASM_REG(1); \ register unsigned long r2 ASM_REG(2); \@@ -246,7 +238,7 @@ static inline void arm_smccc_guest_smc(struct cpu_user_regs *regs) register unsigned long c15 ASM_REG(15); \ register unsigned long c16 ASM_REG(16); \ register unsigned long c17 ASM_REG(17); \ -__declare_args (__count_args (__VA_ARGS__), __VA_ARGS__); \ +__declare_args (count_args (__VA_ARGS__), __VA_ARGS__); \ asm volatile ( \ "smc #0" \ : "=r" (r0), "=r" (r1), "=r" (r2), "=r" (r3), \@@ -255,11 +247,10 @@ static inline void arm_smccc_guest_smc(struct cpu_user_regs *regs) "=r" (c12), "=r" (c13), "=r" (c14), "=r" (c15), \ "=r" (c16), "=r" (c17) \ : PASTE(__constraint_read_, \ - __count_args(__VA_ARGS__)) \ + count_args(__VA_ARGS__)) \ : "memory" ); \ -if ( ___res ) \ - *___res = (struct arm_smccc_res ){ r0, r1, r2, r3 }; \ - } while ( 0 ) + (struct arm_smccc_res ){ r0, r1, r2, r3 }; \ + })#define arm_smccc_1_1_smc (...) arm_smccc_smc(__VA_ARGS__)@@ -268,8 +259,8 @@ static inline void arm_smccc_guest_smc(struct cpu_user_regs *regs) {struct arm_smccc_res res; -arm_smccc_1_1_smc (regs->x0, regs->x1, regs->x2, regs->x3, - regs->x4, regs->x5, regs->x6, regs->x7, &res); + res =arm_smccc_1_1_smc (regs->x0, regs->x1, regs->x2, regs->x3, + regs->x4, regs->x5, regs->x6, regs->x7); regs->x0 = res.a0; regs->x1 = res.a1;xen/arch/arm/platforms/exynos5.c +1
-1@@ -249,7 +249,7 @@ static int exynos5_cpu_up(int cpu)iounmap (power);if ( secure_firmware ) -arm_smccc_smc (SMC_CMD_CPU1BOOT , cpu,NULL ); +arm_smccc_smc (SMC_CMD_CPU1BOOT , cpu);return cpu_up_send_sgi (cpu); }xen/arch/arm/platforms/seattle.c +2
-2@@ -33,12 +33,12 @@ static const char * const seattle_dt_compat[] __initconst =*/ static void seattle_system_reset (void ) { -arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_RESET ,NULL ); +arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_RESET ); }static void seattle_system_off (void ) { -arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_OFF ,NULL ); +arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_OFF ); }PLATFORM_START (seattle,"SEATTLE" )xen/arch/arm/psci.c +8
-9@@ -41,8 +41,8 @@ int call_psci_cpu_on(int cpu) {struct arm_smccc_res res; -arm_smccc_smc (psci_cpu_on_nr,cpu_logical_map (cpu),__pa (init_secondary), - &res); + res =arm_smccc_smc (psci_cpu_on_nr,cpu_logical_map (cpu), +__pa (init_secondary));return PSCI_RET (res); }@@ -54,7 +54,7 @@ void call_psci_cpu_off(void)struct arm_smccc_res res;/* If successfull the PSCI cpu_off call doesn't return */ -arm_smccc_smc (PSCI_0_2_FN32_CPU_OFF , &res); + res =arm_smccc_smc (PSCI_0_2_FN32_CPU_OFF );panic ("PSCI cpu off failed for CPU%d err=%d\n" ,smp_processor_id (),PSCI_RET (res)); }@@ -63,13 +63,13 @@ void call_psci_cpu_off(void)void call_psci_system_off (void ) {if ( psci_ver >PSCI_VERSION (0 ,1 ) ) -arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_OFF ,NULL ); +arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_OFF ); }void call_psci_system_reset (void ) {if ( psci_ver >PSCI_VERSION (0 ,1 ) ) -arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_RESET ,NULL ); +arm_smccc_smc (PSCI_0_2_FN32_SYSTEM_RESET ); }static int __init psci_features (uint32_t psci_func_id)@@ -79,7 +79,7 @@ static int __init psci_features(uint32_t psci_func_id)if ( psci_ver <PSCI_VERSION (1 ,0 ) )return PSCI_NOT_SUPPORTED ; -arm_smccc_smc (PSCI_1_0_FN32_PSCI_FEATURES , psci_func_id, &res); + res =arm_smccc_smc (PSCI_1_0_FN32_PSCI_FEATURES , psci_func_id);return PSCI_RET (res); }@@ -116,9 +116,8 @@ static void __init psci_init_smccc(void)if (psci_features (ARM_SMCCC_VERSION_FID ) !=PSCI_NOT_SUPPORTED ) { -struct arm_smccc_res res; +struct arm_smccc_res res =arm_smccc_smc (ARM_SMCCC_VERSION_FID ); -arm_smccc_smc (ARM_SMCCC_VERSION_FID , &res);if (PSCI_RET (res) !=ARM_SMCCC_NOT_SUPPORTED ) smccc_ver =PSCI_RET (res); }@@ -191,7 +190,7 @@ static int __init psci_init_0_2(void) } } -arm_smccc_smc (PSCI_0_2_FN32_PSCI_VERSION , &res); + res =arm_smccc_smc (PSCI_0_2_FN32_PSCI_VERSION ); psci_ver =PSCI_RET (res);/* For the moment, we only support PSCI 0.2 and PSCI 1.x */ xen/arch/arm/tee/optee.c +25
-25@@ -178,7 +178,7 @@ static bool optee_probe(void)return false;/* Check UID */ -arm_smccc_smc (ARM_SMCCC_CALL_UID_FID (TRUSTED_OS_END ), &resp); + resp =arm_smccc_smc (ARM_SMCCC_CALL_UID_FID (TRUSTED_OS_END )); if ( (uint32_t)resp.a0 != OPTEE_MSG_UID_0 || (uint32_t)resp.a1 != OPTEE_MSG_UID_1 ||@@ -187,7 +187,7 @@ static bool optee_probe(void)return false;/* Read number of threads */ -arm_smccc_smc (OPTEE_SMC_GET_THREAD_COUNT , &resp); + resp =arm_smccc_smc (OPTEE_SMC_GET_THREAD_COUNT );if ( resp.a0 ==OPTEE_SMC_RETURN_OK ) { max_optee_threads = resp.a1;@@ -209,7 +209,7 @@ static bool optee_probe(void)* call. It will return OPTEE_SMC_RETURN_UNKNOWN_FUNCTION if * OP-TEE have no virtualization support enabled. */ -arm_smccc_smc (OPTEE_SMC_VM_DESTROYED ,0 ,0 ,0 ,0 ,0 ,0 ,0 , &resp); + resp =arm_smccc_smc (OPTEE_SMC_VM_DESTROYED ,0 ,0 ,0 ,0 ,0 ,0 ,0 );if ( resp.a0 ==OPTEE_SMC_RETURN_UNKNOWN_FUNCTION )return false;@@ -243,8 +243,8 @@ static int optee_domain_init(struct domain *d)* * a7 should be 0, so we can't skip last 6 parameters of arm_smccc_smc() */ -arm_smccc_smc (OPTEE_SMC_VM_CREATED ,OPTEE_CLIENT_ID (d),0 ,0 ,0 ,0 ,0 ,0 , - &resp); + resp =arm_smccc_smc (OPTEE_SMC_VM_CREATED ,OPTEE_CLIENT_ID (d), +0 ,0 ,0 ,0 ,0 ,0 );if ( resp.a0 !=OPTEE_SMC_RETURN_OK ) { printk(XENLOG_WARNING "%pd: Unable to create OPTEE client: rc = 0x%X\n",@@ -681,8 +681,8 @@ static int optee_relinquish_resources(struct domain *d)* * a7 should be 0, so we can't skip last 6 parameters of arm_smccc_smc() */ -arm_smccc_smc (OPTEE_SMC_VM_DESTROYED ,OPTEE_CLIENT_ID (d),0 ,0 ,0 ,0 ,0 ,0 , - &resp); + resp =arm_smccc_smc (OPTEE_SMC_VM_DESTROYED ,OPTEE_CLIENT_ID (d), +0 ,0 ,0 ,0 ,0 ,0 );ASSERT (!spin_is_locked (&ctx->lock));ASSERT (!atomic_read (&ctx->call_count));@@ -1171,15 +1171,15 @@ static void do_call_with_arg(struct optee_domain *ctx, {struct arm_smccc_res res; -arm_smccc_smc (a0, a1, a2, a3, a4, a5,0 ,OPTEE_CLIENT_ID (current->domain), - &res); + res =arm_smccc_smc (a0, a1, a2, a3, a4, a5,0 , +OPTEE_CLIENT_ID (current->domain));if (OPTEE_SMC_RETURN_IS_RPC (res.a0) ) {while (handle_rpc_return (ctx, &res, regs, call) == -ERESTART ) { -arm_smccc_smc (res.a0, res.a1, res.a2, res.a3,0 ,0 ,0 , -OPTEE_CLIENT_ID (current->domain), &res); + res =arm_smccc_smc (res.a0, res.a1, res.a2, res.a3,0 ,0 ,0 , +OPTEE_CLIENT_ID (current->domain));if ( !OPTEE_SMC_RETURN_IS_RPC (res.a0) )break ;@@ -1619,8 +1619,8 @@ static void handle_exchange_capabilities(struct cpu_user_regs *regs) caps =get_user_reg (regs,1 ); caps &=OPTEE_KNOWN_NSEC_CAPS ; -arm_smccc_smc (OPTEE_SMC_EXCHANGE_CAPABILITIES , caps,0 ,0 ,0 ,0 ,0 , -OPTEE_CLIENT_ID (current->domain), &resp); + resp =arm_smccc_smc (OPTEE_SMC_EXCHANGE_CAPABILITIES , caps,0 ,0 ,0 ,0 ,0 , +OPTEE_CLIENT_ID (current->domain));if ( resp.a0 !=OPTEE_SMC_RETURN_OK ) {set_user_reg (regs,0 , resp.a0);return ;@@ -1664,8 +1664,8 @@ static bool optee_handle_call(struct cpu_user_regs *regs)return true;case OPTEE_SMC_CALLS_UID : -arm_smccc_smc (OPTEE_SMC_CALLS_UID ,0 ,0 ,0 ,0 ,0 ,0 , -OPTEE_CLIENT_ID (current->domain), &resp); + resp =arm_smccc_smc (OPTEE_SMC_CALLS_UID ,0 ,0 ,0 ,0 ,0 ,0 , +OPTEE_CLIENT_ID (current->domain));set_user_reg (regs,0 , resp.a0);set_user_reg (regs,1 , resp.a1);set_user_reg (regs,2 , resp.a2);@@ -1673,15 +1673,15 @@ static bool optee_handle_call(struct cpu_user_regs *regs)return true;case OPTEE_SMC_CALLS_REVISION : -arm_smccc_smc (OPTEE_SMC_CALLS_REVISION ,0 ,0 ,0 ,0 ,0 ,0 , -OPTEE_CLIENT_ID (current->domain), &resp); + resp =arm_smccc_smc (OPTEE_SMC_CALLS_REVISION ,0 ,0 ,0 ,0 ,0 ,0 , +OPTEE_CLIENT_ID (current->domain));set_user_reg (regs,0 , resp.a0);set_user_reg (regs,1 , resp.a1);return true;case OPTEE_SMC_CALL_GET_OS_UUID : -arm_smccc_smc (OPTEE_SMC_CALL_GET_OS_UUID ,0 ,0 ,0 ,0 ,0 ,0 , -OPTEE_CLIENT_ID (current->domain),&resp); + resp =arm_smccc_smc (OPTEE_SMC_CALL_GET_OS_UUID ,0 ,0 ,0 ,0 ,0 ,0 , +OPTEE_CLIENT_ID (current->domain));set_user_reg (regs,0 , resp.a0);set_user_reg (regs,1 , resp.a1);set_user_reg (regs,2 , resp.a2);@@ -1689,21 +1689,21 @@ static bool optee_handle_call(struct cpu_user_regs *regs)return true;case OPTEE_SMC_CALL_GET_OS_REVISION : -arm_smccc_smc (OPTEE_SMC_CALL_GET_OS_REVISION ,0 ,0 ,0 ,0 ,0 ,0 , -OPTEE_CLIENT_ID (current->domain), &resp); + resp =arm_smccc_smc (OPTEE_SMC_CALL_GET_OS_REVISION ,0 ,0 ,0 ,0 ,0 ,0 , +OPTEE_CLIENT_ID (current->domain));set_user_reg (regs,0 , resp.a0);set_user_reg (regs,1 , resp.a1);return true;case OPTEE_SMC_ENABLE_SHM_CACHE : -arm_smccc_smc (OPTEE_SMC_ENABLE_SHM_CACHE ,0 ,0 ,0 ,0 ,0 ,0 , -OPTEE_CLIENT_ID (current->domain), &resp); + resp =arm_smccc_smc (OPTEE_SMC_ENABLE_SHM_CACHE ,0 ,0 ,0 ,0 ,0 ,0 , +OPTEE_CLIENT_ID (current->domain));set_user_reg (regs,0 , resp.a0);return true;case OPTEE_SMC_DISABLE_SHM_CACHE : -arm_smccc_smc (OPTEE_SMC_DISABLE_SHM_CACHE ,0 ,0 ,0 ,0 ,0 ,0 , -OPTEE_CLIENT_ID (current->domain), &resp); + resp =arm_smccc_smc (OPTEE_SMC_DISABLE_SHM_CACHE ,0 ,0 ,0 ,0 ,0 ,0 , +OPTEE_CLIENT_ID (current->domain));set_user_reg (regs,0 , resp.a0);if ( resp.a0 ==OPTEE_SMC_RETURN_OK ) {free_shm_rpc (ctx,regpair_to_uint64 (resp.a1, resp.a2));xen/arch/arm/traps.c +2
-2@@ -1991,7 +1991,7 @@ void asmlinkage enter_hypervisor_from_guest_preirq(void)/* If the guest has disabled the workaround, bring it back on. */ if (needs_ssbd_flip (v) ) -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ); }/* @@ -2334,7 +2334,7 @@ void asmlinkage leave_hypervisor_to_guest(void)* If the guest wants it disabled, so be it... */ if (needs_ssbd_flip (current) ) -arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ); }/* Signature · 1 line
2.39.5
Re: [PATCH v2 5/5] xen/arm: Rewrite arm_smccc_*() to return by value
Quoted 4 lines · Bertrand Marquis
Hi Andrew,
Quoted 2 lines · Andrew Cooper
Quoted 12 lines
xen/arch/arm/include/asm/smccc.h struct arm_smccc_res { · line 176
Quoted 8 lines
xen/arch/arm/include/asm/smccc.h +0
-0@@ -181,21 +174,20 @@ struct arm_smccc_res {* makes it stick. */ #define arm_smccc_1_1_smc (...) \The comment would need fixing on top of this as current one still describes the optional @res argument while now we only take a0 to a7 as arguments and return the structure instead.
Are you happy with this delta?
(quoted diff) +0 -0
b/xen/arch/arm/include/asm/smccc.h
index 2d0f2db0b256..c7763acd7f7d 100644
xen/arch/arm/include/asm/smccc.h +0 -0
@@ -159,15 +159,14 @@ struct arm_smccc_res {
* arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call *
* This is a variadic macro taking one to eight source arguments, and
- * an optional return structure.
+ * returns four values.
*
* @a0-a7: arguments passed in registers 0 to 7
* @res: result values from registers 0 to 3
*
* This macro is used to make SMC calls following SMC Calling Convention v1.1.
* The content of the supplied param are copied to registers 0 to 7 prior
- * to the SMC instruction. The return values are updated with the content
- * from register 0 to 3 on return from the SMC instruction if not NULL.
+ * to the SMC instruction.
*
* We have an output list that is not necessarily used, and GCC feels
* entitled to optimise the whole sequence away. "volatile" is what
The overall comment now reads:
/*
* arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call *
* This is a variadic macro taking one to eight source arguments, and
* returns four values.
*
* @a0-a7: arguments passed in registers 0 to 7
* @res: result values from registers 0 to 3
*
* This macro is used to make SMC calls following SMC Calling Convention v1.1.
* The content of the supplied param are copied to registers 0 to 7 prior
* to the SMC instruction.
*
* We have an output list that is not necessarily used, and GCC feels
* entitled to optimise the whole sequence away. "volatile" is what
* makes it stick.
*/
~Andrew
Bertrand Marquis
Reviewed-byRe: [PATCH v2 5/5] xen/arm: Rewrite arm_smccc_*() to return by value
Hi Andrew,
Quoted 59 lines · Andrew Cooper
Quoted 4 lines · Bertrand Marquis
Hi Andrew,
Quoted 2 lines · Andrew Cooper
Quoted 12 lines
xen/arch/arm/include/asm/smccc.h struct arm_smccc_res { · line 176
Quoted 8 lines
xen/arch/arm/include/asm/smccc.h +0
-0@@ -181,21 +174,20 @@ struct arm_smccc_res {* makes it stick. */ #define arm_smccc_1_1_smc (...) \The comment would need fixing on top of this as current one still describes the optional @res argument while now we only take a0 to a7 as arguments and return the structure instead.
Are you happy with this delta?
xen/arch/arm/include/asm/smccc.h +1
-1@@ -159,15 +159,14 @@ struct arm_smccc_res {* arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call * * This is a variadic macro taking one to eight source arguments, and -* an optional return structure. +* returns four values. * * @a0-a7: arguments passed in registers 0 to 7 * @res: result values from registers 0 to 3 * * This macro is used to make SMC calls following SMC Calling Convention v1.1.
* The content of the supplied param are copied to registers 0 to 7 prior
- * to the SMC instruction. The return values are updated with the content
- * from register 0 to 3 on return from the SMC instruction if not NULL.
+ * to the SMC instruction.
*
* We have an output list that is not necessarily used, and GCC feels
* entitled to optimise the whole sequence away. "volatile" is whatThe overall comment now reads:
/*
*arm_smccc_1_1_smc()- make an SMCCC v1.1 compliant SMC call *
* This is a variadic macro taking one to eight source arguments, and
* returns four values.
*
* @a0-a7: arguments passed in registers 0 to 7
* @res: result values from registers 0 to 3
*
* This macro is used to make SMC calls following SMC Calling Convention
Quoted 8 lines
v1.1.
* The content of the supplied param are copied to registers 0 to 7 prior
* to the SMC instruction.
*
* We have an output list that is not necessarily used, and GCC feels
* entitled to optimise the whole sequence away. "volatile" is what
* makes it stick.
*/
Looks good to me.
With that:
Cheers
Bertrand
Quoted 2 lines
~Andrew