Re: [PATCH v6 8/9] arm64: realm: Add RHI helper to query IPA state change alignment
From: Aneesh Kumar K . V
Date: Fri Sep 18 2026 - 06:47:14 EST
Suzuki K Poulose <suzuki.poulose@xxxxxxx> writes:
> On 04/09/2026 11:34, Aneesh Kumar K.V (Arm) wrote:
>> Arm CCA guests need to know the granularity at which the host expects IPA
>> state changes to be performed. This can be larger than the guest page size
>> and is needed when deciding the alignment for memory shared with the host.
>>
>> Add the Realm Host Interface host configuration definitions and an
>> get_ipa_state_change_alignment() helper. The helper uses RSI_HOST_CALL to
>> query the supported HostConf version and features, reads the IPA change
>> alignment when available, and falls back to PAGE_SIZE if the interface is
>> unavailable or returns an invalid value.
>>
>> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@xxxxxxxxxx>
>
> It may be worth mentioning the document number and may be the link
> for RHI spec.
>
> e.g., The Realm Host Interface specification Arm DEN00148 defines ...
>
>
>
>> ---
>> drivers/firmware/arm_rmm/rsi.c | 46 ++++++++++++++++++++++++++++++++++
>> include/linux/arm-rsi-cmds.h | 10 ++++++++
>> include/linux/arm-smccc-rhi.h | 25 ++++++++++++++++++
>> include/linux/arm-smccc-rsi.h | 7 ++++++
>> 4 files changed, 88 insertions(+)
>> create mode 100644 include/linux/arm-smccc-rhi.h
>>
>> diff --git a/drivers/firmware/arm_rmm/rsi.c b/drivers/firmware/arm_rmm/rsi.c
>> index 52f40256bd78..2cd53f82432f 100644
>> --- a/drivers/firmware/arm_rmm/rsi.c
>> +++ b/drivers/firmware/arm_rmm/rsi.c
>> @@ -9,6 +9,7 @@
>> #include <linux/swiotlb.h>
>> #include <linux/platform_device.h>
>> #include <linux/arm-rsi-cmds.h>
>> +#include <linux/arm-smccc-rhi.h>
>> #include <linux/kobject.h>
>> #include <linux/sysfs.h>
>>
>> @@ -164,6 +165,51 @@ static int realm_register_memory_enc_ops(void)
>> return arm64_mem_crypt_ops_register(&realm_crypt_ops);
>> }
>>
>> +/* we need an aligned struct for rsi_host_call. slab is not yet ready */
>> +static struct rsi_host_call hostconf_call __initdata;
>> +static unsigned long __maybe_unused __init get_ipa_state_change_alignment(void)
>> +{
>> + long ret;
>> + unsigned long shared_granule_size;
>> +
>> + hostconf_call.imm = 0;
>> + hostconf_call.gprs[0] = RHI_HOSTCONF_VERSION;
>
> Do we need to 0 out the other GPRs for RES0 arguments ?
>
>> + ret = rsi_host_call(lm_alias(&hostconf_call));
>> + if (ret != RSI_SUCCESS)
>> + goto err_out;
>> +
>> + if (hostconf_call.gprs[0] != RHI_HOSTCONF_VER_1_0)
>> + goto err_out;
>> +
>> + hostconf_call.imm = 0;
>> + hostconf_call.gprs[0] = RHI_HOSTCONF_FEATURES;
>
> Same here, especially gprs[] could be overwritten by the results from
> the Host for the previous call.
>
[ ... 75 lines skipped ... ]
>> +
>> +#define RHI_HOSTCONF_VER_1_0 0x10000
>> +#define RHI_HOSTCONF_VERSION SMC_RHI_CALL(0x004E)
>> +
>> +#define __RHI_HOSTCONF_GET_IPA_CHANGE_ALIGNMENT BIT(0)
>
> minor nit: Could this be:
>
> RHI_HOSTCONF_FEATURE_GET_IPA_CHANGE_ALIGNMENT BIT(0)
>
> to indicate this applies to the RHI_HOSTCONF_FEATURES output ?
>
Will make this change.
- hostconf_call.imm = 0;
+ memset(&hostconf_call, 0, sizeof(hostconf_call));
hostconf_call.gprs[0] = RHI_HOSTCONF_FEATURES;
ret = rsi_host_call(lm_alias(&hostconf_call));
if (ret != RSI_SUCCESS)
goto err_out;
- if (!(hostconf_call.gprs[0] & __RHI_HOSTCONF_GET_IPA_CHANGE_ALIGNMENT))
+ if (!(hostconf_call.gprs[0] & RHI_HOSTCONF_FEATURE_GET_IPA_CHANGE_ALIGNMENT))
goto err_out;
-aneesh