From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
Bertrand Marquis <bertrand.marquis@arm.com>,
Michal Orzel <michal.orzel@amd.com>,
Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
Subject: [PATCH 2/6] xen/arm: Introduce arm_smccc_guest_smc()
Date: Mon, 31 Aug 2026 13:19:41 +0100 [thread overview]
Message-ID: <20260831121944.2908139-3-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <20260831121944.2908139-1-andrew.cooper3@citrix.com>
Both {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.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien@xen.org>
CC: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
CC: Bertrand Marquis <bertrand.marquis@arm.com>
CC: Michal Orzel <michal.orzel@amd.com>
CC: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
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(-)
diff --git a/xen/arch/arm/firmware/scmi-smc.c b/xen/arch/arm/firmware/scmi-smc.c
index 0835ddeeeccc..a0cc6c6192f8 100644
--- a/xen/arch/arm/firmware/scmi-smc.c
+++ b/xen/arch/arm/firmware/scmi-smc.c
@@ -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;
}
diff --git a/xen/arch/arm/include/asm/smccc.h b/xen/arch/arm/include/asm/smccc.h
index 53cdddb690b7..832157f43734 100644
--- a/xen/arch/arm/include/asm/smccc.h
+++ b/xen/arch/arm/include/asm/smccc.h
@@ -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
diff --git a/xen/arch/arm/platforms/imx8m.c b/xen/arch/arm/platforms/imx8m.c
index 669dd517e057..efb0ad20d6e8 100644
--- a/xen/arch/arm/platforms/imx8m.c
+++ b/xen/arch/arm/platforms/imx8m.c
@@ -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;
}
diff --git a/xen/arch/arm/platforms/imx8qm.c b/xen/arch/arm/platforms/imx8qm.c
index 3600a073e8ba..7249e14ab640 100644
--- a/xen/arch/arm/platforms/imx8qm.c
+++ b/xen/arch/arm/platforms/imx8qm.c
@@ -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;
}
diff --git a/xen/arch/arm/platforms/xilinx-zynqmp-eemi.c b/xen/arch/arm/platforms/xilinx-zynqmp-eemi.c
index 2053ed7ac5f6..326c8a1ba6e5 100644
--- a/xen/arch/arm/platforms/xilinx-zynqmp-eemi.c
+++ b/xen/arch/arm/platforms/xilinx-zynqmp-eemi.c
@@ -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:
--
2.39.5
next prev parent reply other threads:[~2026-08-31 12:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 12:19 [PATCH 0/5] xen/arm: Fixes and improvements to SMCCC Andrew Cooper
2026-08-31 12:19 ` [PATCH 1/6] xen/arm: Fix evaluation of parameters for SMCCC calls Andrew Cooper
2026-09-03 11:46 ` Bertrand Marquis
2026-08-31 12:19 ` Andrew Cooper [this message]
2026-09-03 11:49 ` [PATCH 2/6] xen/arm: Introduce arm_smccc_guest_smc() Bertrand Marquis
2026-08-31 12:19 ` [PATCH 3/6] xen/arm: Clean up 32bit arm_smccc_1_1_smc() Andrew Cooper
2026-09-03 11:52 ` Bertrand Marquis
2026-08-31 12:19 ` [PATCH 4/6] xen/arm: Rewrite arm_smccc_smc() for arm64 Andrew Cooper
2026-09-03 12:16 ` Bertrand Marquis
2026-09-04 10:50 ` Andrew Cooper
2026-08-31 12:19 ` [PATCH 5/6] xen/arm: Rewrite arm_smccc_*() to return by value Andrew Cooper
2026-09-03 12:21 ` Bertrand Marquis
2026-09-03 9:20 ` [PATCH 0/5] xen/arm: Fixes and improvements to SMCCC Bertrand Marquis
2026-09-03 9:35 ` Andrew Cooper
2026-09-03 10:26 ` Bertrand Marquis
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=20260831121944.2908139-3-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=Jan.SetjeEilers@oracle.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=bertrand.marquis@arm.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.