[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] xen/arm: smccc: Preserve argument types in v1.1 SMC


  • To: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Mon, 16 Feb 2026 10:28:26 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gbGg41ZdlDnfHtAVLQWesczoMuWjWJroBHnPOBLs/bA=; b=tz3Ie9Ekxch81lpWtsjyXgPjUk3t9XBS7TO/UFvu3K8v2aKh9oPoQ2yBDEO7E8WB3yKV8mYIMHQWFIFF6Ne38SFYvSx9xZ6bdGqY93kN3LhNvBA81bViAAnDVHoc4tAGIzTI/LbKh98bwcAALKtXUATlnPTzbhqkVztmly+4LC1jW5msXMDSgiiYSeGefxuTGrY82mCzei/dO6Dz8t5w9tqumj9ct/yLHzR/9rNPoDPMIT5dvOz17y1QQBK9H2k+0NDbdLQJLrnzz9obaxvQB45XsRkea4xGSYjnLuvNIaxKE2haHErbooR4D7J2NG1m9AoyVdvJrd9DFpFzhd3oQA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YAMzgTWLNiZqDzP+a1Rdq1Nqz2/ROShRZCR9htwVSd0X6FBcKyVRzOoptkhpSTfwRvqdq7U9EBg4KC2WM73/ybs+W95pXJcARthG/LAyX4uYN94KG9ukyxQbeB1IylLOvxp4kNSIixsDkkO18Cw1t5u162nWbvHghFsyzUarweejqCWaTuCs1pGyFKu8cZ0lgRC4NTiakyOadN7WVcDjKicDBEZmMGBpS4EzEOSubJRUT6sgYMAowgdeiKf/QKnvFWtMiJdxieC5+FZwlBXRpOa6nlQgJOZekI+CXZvgVGgoqDMmm3CnO+xGfsIKRlf/7/yzqs6saIp526nH5OLuhg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 16 Feb 2026 10:28:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 16/02/2026 9:31 am, Bertrand Marquis wrote:
> Hi Jan,
>
>> On 16 Feb 2026, at 10:21, Jan Beulich <jbeulich@xxxxxxxx> wrote:
>>
>> On 16.02.2026 08:47, Bertrand Marquis wrote:
>>> The SMCCC v1.1 inline helper currently forces a1-a4 into
>>> unsigned long and uses in/out constraints for r0-r3. In
>>> contrast, a5-a7 are passed with their original types via
>>> read-only constraints. On arm64 this means a 32-bit signed
>>> value in a1-a4 is converted to a 64-bit unsigned value, while
>>> the same value in a5-a7 keeps its signed 32-bit form. For
>>> example, a negative int in a2 is widened to unsigned long, but
>>> a negative int in a5 is passed as a 32-bit signed value, so the
>>> SMC sees different encodings depending on argument position.
>>>
>>> Switch the helper to use typed input registers arg0-arg7
>>> derived from the call arguments (keeping a0 cast to u32) and
>>> separate output registers r0-r3. This preserves argument types
>>> consistently across all positions. Argument evaluation order
>>> is unchanged, so we do not reintroduce the issue fixed in
>>> "e00dc325bd9e" ("xen/arm: smccc-1.1: Handle function result as
>>> parameters").
>>>
>>> This also aligns Xen's SMCCC parameter handling with Linux's type-
>>> preserving behavior (same externally visible argument handling,
>>> independent implementation) to avoid surprising differences
>>> between a1-a4 and a5-a7.
>>>
>>> Current callers (PSCI, SCMI, platform SMC pass-through, OP-TEE,
>>> and exynos5) pass unsigned values; exynos5 passes an int CPU id
>>> which should always be > 0.
>> Reported-by: Andrew ?
> Ack, sorry forgot that.
>
>>> Signed-off-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>
>>> ---
>>> xen/arch/arm/include/asm/smccc.h | 69 +++++++++++++-------------------
>>> 1 file changed, 27 insertions(+), 42 deletions(-)
>>>
>>> diff --git a/xen/arch/arm/include/asm/smccc.h 
>>> b/xen/arch/arm/include/asm/smccc.h
>>> index 441b3ab65dee..5b30dd57b69d 100644
>>> --- a/xen/arch/arm/include/asm/smccc.h
>>> +++ b/xen/arch/arm/include/asm/smccc.h
>>> @@ -99,87 +99,68 @@ struct arm_smccc_res {
>>> #define __count_args(...)                               \
>>>     ___count_args(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0)
>>>
>>> -#define __constraint_write_0                        \
>>> -    "+r" (r0), "=&r" (r1), "=&r" (r2), "=&r" (r3)
>>> -#define __constraint_write_1                        \
>>> -    "+r" (r0), "+r" (r1), "=&r" (r2), "=&r" (r3)
>>> -#define __constraint_write_2                        \
>>> -    "+r" (r0), "+r" (r1), "+r" (r2), "=&r" (r3)
>>> -#define __constraint_write_3                        \
>>> -    "+r" (r0), "+r" (r1), "+r" (r2), "+r" (r3)
>>> -#define __constraint_write_4    __constraint_write_3
>>> -#define __constraint_write_5    __constraint_write_4
>>> -#define __constraint_write_6    __constraint_write_5
>>> -#define __constraint_write_7    __constraint_write_6
>>> -
>>> -#define __constraint_read_0
>>> -#define __constraint_read_1
>>> -#define __constraint_read_2
>>> -#define __constraint_read_3
>>> -#define __constraint_read_4 "r" (r4)
>>> -#define __constraint_read_5 __constraint_read_4, "r" (r5)
>>> -#define __constraint_read_6 __constraint_read_5, "r" (r6)
>>> -#define __constraint_read_7 __constraint_read_6, "r" (r7)
>>> +#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 __declare_arg_0(a0, res)                            \
>>>     struct arm_smccc_res    *___res = (res);                \
>>> -    register unsigned long  r0 ASM_REG(0) = (uint32_t)(a0); \
>>> -    register unsigned long  r1 ASM_REG(1);                  \
>>> -    register unsigned long  r2 ASM_REG(2);                  \
>>> -    register unsigned long  r3 ASM_REG(3)
>>> +    register unsigned long  arg0 ASM_REG(0) = (uint32_t)(a0)
>>>
>>> #define __declare_arg_1(a0, a1, res)                        \
>>>     typeof(a1) __a1 = (a1);                                 \
>>>     struct arm_smccc_res    *___res = (res);                \
>>> -    register unsigned long  r0 ASM_REG(0) = (uint32_t)(a0); \
>>> -    register unsigned long  r1 ASM_REG(1) = __a1;           \
>>> -    register unsigned long  r2 ASM_REG(2);                  \
>>> -    register unsigned long  r3 ASM_REG(3)
>>> +    register unsigned long  arg0 ASM_REG(0) = (uint32_t)(a0);\
>>> +    register typeof(a1)     arg1 ASM_REG(1) = __a1
>> Is it intentional that you switch to typeof() rather than directly going
>> to auto? This was it'll be more churn, aiui. And if deliberately going
>> only half a step, perhaps worth saying so in the description?
>>
> Yes it is because Andrew wants to rebase his serie on top of this
> patch.

This patch potentially wants backporting, but even if it ends up not
being, fixing the SMCCC types should not be mixed with the auto
conversion; they're both subtle changes and unrelated.

~Andrew



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.