Switch Arm SMCCC firmware services to an SMCCC bus
Subsystems (5)
v8 cover Switch Arm SMCCC firmware services to an SMCCC bus
As discussed here:
https://lore.kernel.org/all/[email protected]
The earlier CCA guest support used an arm-cca-dev platform device as a pure software anchor for the TSM class device. That platform device did not correspond to a DT/ACPI described device, MMIO range, interrupt, or other platform resource; it existed only to make the CCA guest driver bind and to place the resulting TSM device in the driver model. The same pattern also exists for smccc_trng. Creating separate platform devices for such SMCCC-discovered features is misleading, because those features are not independent platform devices.
This series adds an Arm SMCCC bus for services discovered through the SMCCC firmware interface. The bus provides SMCCC device and driver registration helpers, name-based matching, uevent modalias generation, and a sysfs modalias attribute. SMCCC service drivers can use MODULE_DEVICE_TABLE(arm_smccc, ...) to emit arm_smccc:<name> aliases, allowing userspace to autoload service drivers when the SMCCC core registers matching firmware-service devices.
The series then moves SMCCC TRNG and the Arm CCA guest RSI service off the platform bus. When the SMCCC core discovers the corresponding firmware service, it registers an arm-smccc device for that service. The hwrng arm_smccc_trng driver and the Arm CCA guest TSM provider are converted to SMCCC drivers that bind to those discovered devices.
The old arm-cca-dev platform device has also been used by userspace as a Realm guest indicator. Removing it without a replacement would leave userspace depending on an internal driver-binding device. This series therefore adds /sys/firmware/cca/realm_guest as a stable, architecture-provided ABI for detecting whether the kernel is running as an Arm CCA Realm guest, and then removes the dummy arm-cca-dev platform-device registration.
Changes from v7:
https://lore.kernel.org/all/[email protected]
* Rebase to latest kernel
* Add id_table check in arm_smccc_driver_register
* Add smccc device name check in arm_smccc_device_register
* Drop driver_data from struct arm_smccc_device_id
Changes from v6:
https://lore.kernel.org/all/[email protected]
* Move SMCCC bus-related code to bus.c.
* Remove CONFIG_ARM64 #ifdefs and switch device creation to use the generic function-ID support framework.
* Move version-specific checks and other conditionals to the device driver probe routines.
* Move RSI definitions to include/linux/arm-smccc-rsi.h.
* Split the file and variable renames into a separate patch.
Changes from v5:
https://lore.kernel.org/all/[email protected]
* Replace the arm-smccc platform-device plus auxiliary-child model with a dedicated Arm SMCCC bus.
* Add SMCCC module alias support so SMCCC service drivers can use MODULE_DEVICE_TABLE(arm_smccc, ...) and autoload through arm_smccc:<name> aliases.
* Convert smccc_trng from a platform driver to an SMCCC driver.
* Convert the Arm CCA guest TSM provider from the arm-cca-dev platform device to an SMCCC driver bound to the discovered RSI service.
* Add /sys/firmware/cca/realm_guest before removing the old arm-cca-dev dummy platform device.
Changes from v4:
https://lore.kernel.org/all/[email protected]
* Add /sys/firmware/cca/realm_guest for detecting realm guest
* Convert smccc_trng to auxiliary device from platform device
Changes from v3:
https://lore.kernel.org/all/[email protected]
* Rebased onto the latest kernel
* Drop pr_fmt() from drivers/firmware/smccc/rmm.c
Aneesh Kumar K.V (Arm) (6):
firmware: smccc: Add an Arm SMCCC bus
firmware: hwrng: arm_smccc_trng: Register as an SMCCC device
firmware: smccc: Move RSI definitions to include/linux
virt: coco: arm-cca-guest: Rename TSM report source file
firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC
device
coco: guest: arm64: Replace dummy CCA device with sysfs ABI
Documentation/ABI/testing/sysfs-firmware-cca | 10 ++
arch/arm/include/asm/archrandom.h | 2 +-
arch/arm64/include/asm/archrandom.h | 2 +-
arch/arm64/include/asm/rsi.h | 2 -
arch/arm64/include/asm/rsi_cmds.h | 75 +-------
arch/arm64/kernel/rsi.c | 39 ++--
drivers/char/hw_random/arm_smccc_trng.c | 32 ++--
drivers/firmware/smccc/Makefile | 2 +-
drivers/firmware/smccc/bus.c | 167 ++++++++++++++++++
drivers/firmware/smccc/smccc.c | 65 ++++++-
drivers/virt/coco/arm-cca-guest/Kconfig | 1 +
drivers/virt/coco/arm-cca-guest/Makefile | 2 +
.../{arm-cca-guest.c => arm-cca.c} | 62 +++----
drivers/virt/coco/arm-cca-guest/rsi.h | 84 +++++++++
include/linux/arm-smccc-bus.h | 49 +++++
.../linux/arm-smccc-rsi.h | 8 +-
include/linux/device-id/arm_smccc.h | 16 ++
include/linux/mod_devicetable.h | 1 +
scripts/mod/devicetable-offsets.c | 3 +
scripts/mod/file2alias.c | 8 +
20 files changed, 488 insertions(+), 142 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-firmware-cca
create mode 100644 drivers/firmware/smccc/bus.c
rename drivers/virt/coco/arm-cca-guest/{arm-cca-guest.c => arm-cca.c} (85%)
create mode 100644 drivers/virt/coco/arm-cca-guest/rsi.h
create mode 100644 include/linux/arm-smccc-bus.h
rename arch/arm64/include/asm/rsi_smc.h => include/linux/arm-smccc-rsi.h (97%)
create mode 100644 include/linux/device-id/arm_smccc.hbase-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
Signature · 1 line
2.43.0
PATCH v8 1/6 firmware: smccc: Add an Arm SMCCC bus
SMCCC-discovered firmware services are currently represented by separate platform devices, such as smccc_trng and arm-cca-dev. Those devices do not represent independent DT/ACPI-described platform resources; they are features of the SMCCC firmware interface.
Add an Arm SMCCC bus for services discovered through the SMCCC firmware interface. The bus provides SMCCC device and driver registration helpers, name-based matching, modalias generation, and a sysfs modalias attribute so SMCCC service drivers can bind to discovered firmware services and autoload as modules.
Follow-up changes can then register SMCCC firmware services as arm-smccc devices instead of creating independent per-feature platform devices.
Based on arm_ffa code
--- drivers/firmware/smccc/Makefile | 2 +- drivers/firmware/smccc/bus.c | 167 ++++++++++++++++++++++++++++ include/linux/arm-smccc-bus.h | 49 ++++++++ include/linux/device-id/arm_smccc.h | 16 +++ include/linux/mod_devicetable.h | 1 + scripts/mod/devicetable-offsets.c | 3 + scripts/mod/file2alias.c | 8 ++ 7 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/smccc/bus.c create mode 100644 include/linux/arm-smccc-bus.h create mode 100644 include/linux/device-id/arm_smccc.h
drivers/firmware/smccc/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 # -obj-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += smccc.o kvm_guest.o +obj-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += bus.o smccc.o kvm_guest.o obj-$(CONFIG_ARM_SMCCC_SOC_ID) += soc_id.o
drivers/firmware/smccc/bus.c new file +167 -0
167 lines not on this page · raw message
include/linux/arm-smccc-bus.h new file +49 -0
49 lines not on this page · raw message
include/linux/device-id/arm_smccc.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_DEVICE_ID_ARM_SMCCC_H +#define __LINUX_DEVICE_ID_ARM_SMCCC_H + +#define ARM_SMCCC_NAME_SIZE 40 +#define ARM_SMCCC_MODULE_PREFIX "arm_smccc:" + +/** +* struct arm_smccc_device_id - Arm SMCCC bus device identifier +* @name: SMCCC device name +*/ +struct arm_smccc_device_id { +char name[ARM_SMCCC_NAME_SIZE ]; +}; + +#endif /* __LINUX_DEVICE_ID_ARM_SMCCC_H */
include/linux/mod_devicetable.h +1 -0
@@ -16,6 +16,7 @@#include "device-id/amba.h" #include "device-id/ap.h" #include "device-id/apr.h" +#include "device-id/arm_smccc.h" #include "device-id/auxiliary.h" #include "device-id/bcma.h" #include "device-id/ccw.h"
scripts/mod/devicetable-offsets.c +3 -0
@@ -254,6 +254,9 @@ int main(void)DEVID (auxiliary_device_id);DEVID_FIELD (auxiliary_device_id, name); +DEVID (arm_smccc_device_id); +DEVID_FIELD (arm_smccc_device_id, name); +DEVID (ssam_device_id);DEVID_FIELD (ssam_device_id, match_flags);DEVID_FIELD (ssam_device_id, domain);
scripts/mod/file2alias.c +8 -0
@@ -1349,6 +1349,13 @@ static void do_auxiliary_entry(struct module *mod, void *symval)module_alias_printf (mod, false,AUXILIARY_MODULE_PREFIX "%s" , *name); } +static void do_arm_smccc_entry (struct module *mod,void *symval) +{ +DEF_FIELD_ADDR (symval, arm_smccc_device_id, name); + +module_alias_printf (mod, false,ARM_SMCCC_MODULE_PREFIX "%s" , *name); +} +/* * Looks like: ssam:dNcNtNiNfN *
@@ -1519,6 +1526,7 @@ static const struct devtable devtable[] = { {"mhi", SIZE_mhi_device_id, do_mhi_entry}, {"mhi_ep", SIZE_mhi_device_id, do_mhi_ep_entry}, {"auxiliary", SIZE_auxiliary_device_id, do_auxiliary_entry}, + {"arm_smccc", SIZE_arm_smccc_device_id, do_arm_smccc_entry}, {"ssam", SIZE_ssam_device_id, do_ssam_entry}, {"dfl", SIZE_dfl_device_id, do_dfl_entry}, {"ishtp", SIZE_ishtp_device_id, do_ishtp_entry},
Signature · 1 line
2.43.0
Re: [PATCH v8 1/6] firmware: smccc: Add an Arm SMCCC bus
Quoted 11 lines · Aneesh Kumar K.V (Arm)
SMCCC-discovered firmware services are currently represented by separate platform devices, such as
smccc_trngand arm-cca-dev. Those devices do not represent independent DT/ACPI-described platform resources; they are features of the SMCCC firmware interface.Add an Arm SMCCC bus for services discovered through the SMCCC firmware interface. The bus provides SMCCC device and driver registration helpers, name-based matching, modalias generation, and a sysfs modalias attribute so SMCCC service drivers can bind to discovered firmware services and autoload as modules.
Quoted 5 lines
Follow-up changes can then register SMCCC firmware services as arm-smccc devices instead of creating independent per-feature platform devices.
Based on
arm_ffacode
Signature · 2 lines
Regards, Sudeep
PATCH v8 2/6 firmware: hwrng: arm_smccc_trng: Register as an SMCCC device
In reply to Aneesh Kumar K.V (Arm)The SMCCC TRNG interface is a firmware-provided SMCCC service rather than a standalone platform device. Now that the SMCCC core has an SMCCC bus, create an arm-smccc-trng device for the discovered TRNG service and convert the hwrng driver to an SMCCC driver.
The SMCCC id table preserves module autoloading for systems where the TRNG driver is built as a module.
The sysfs device path changes from the old smccc_trng platform-device path to an arm-smccc device path. No known userspace dependency on the old path was found; a Debian Code Search lookup for the existing platform-device name/path did not find any users.
--- arch/arm/include/asm/archrandom.h | 2 +- arch/arm64/include/asm/archrandom.h | 2 +- drivers/char/hw_random/arm_smccc_trng.c | 32 +++++++++----- drivers/firmware/smccc/smccc.c | 58 +++++++++++++++++++++---- 4 files changed, 72 insertions(+), 22 deletions(-)
arch/arm/include/asm/archrandom.h +1 -1
@@ -2,7 +2,7 @@#ifndef _ASM_ARCHRANDOM_H#define _ASM_ARCHRANDOM_H -static inline bool __init smccc_probe_trng (void ) +static inline bool smccc_probe_trng (void ) {return false; }
arch/arm64/include/asm/archrandom.h +1 -1
@@ -12,7 +12,7 @@extern bool smccc_trng_available; -static inline bool __init smccc_probe_trng (void ) +static inline bool smccc_probe_trng (void ) {struct arm_smccc_res res;
drivers/char/hw_random/arm_smccc_trng.c +21 -11
@@ -16,8 +16,10 @@#include <linux/device.h> #include <linux/hw_random.h> #include <linux/module.h> -#include <linux/platform_device.h> #include <linux/arm-smccc.h> +#include <linux/arm-smccc-bus.h> + +#include <asm/archrandom.h> #ifdef CONFIG_ARM64 #define ARM_SMCCC_TRNG_RND ARM_SMCCC_TRNG_RND64
@@ -94,29 +96,37 @@ static int smccc_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)return copied; } -static int smccc_trng_probe (struct platform_device *pdev) +static int smccc_trng_probe (struct arm_smccc_device *sdev) {struct hwrng *trng; - trng =devm_kzalloc (&pdev->dev,sizeof (*trng),GFP_KERNEL ); +/* validate the minimum version requirement */ +if (!smccc_probe_trng ()) +return -ENODEV ; + + trng =devm_kzalloc (&sdev->dev,sizeof (*trng),GFP_KERNEL );if (!trng)return -ENOMEM ; trng->name ="smccc_trng" ; trng->read = smccc_trng_read; -return devm_hwrng_register (&pdev->dev, trng); +return devm_hwrng_register (&sdev->dev, trng); } -static struct platform_driver smccc_trng_driver = { - .driver = { - .name ="smccc_trng" , - }, - .probe = smccc_trng_probe, +static const struct arm_smccc_device_id smccc_trng_id_table[] = { + { .name ="arm-smccc-trng" }, + {} +}; +MODULE_DEVICE_TABLE (arm_smccc, smccc_trng_id_table); + +static struct arm_smccc_driver smccc_trng_driver = { + .name =KBUILD_MODNAME , + .probe = smccc_trng_probe, + .id_table = smccc_trng_id_table, }; -module_platform_driver (smccc_trng_driver); +module_arm_smccc_driver (smccc_trng_driver); -MODULE_ALIAS ("platform:smccc_trng" );MODULE_AUTHOR ("Andre Przywara" );MODULE_DESCRIPTION ("Arm SMCCC TRNG firmware interface support" );MODULE_LICENSE ("GPL" );
drivers/firmware/smccc/smccc.c +49 -9
72 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v8 3/6 firmware: smccc: Move RSI definitions to include/linux
In reply to Aneesh Kumar K.V (Arm)The RSI SMCCC function IDs describe a firmware ABI and are not arm64 architecture specific definitions. Follow-up changes need to use them from non-arch code, including drivers/firmware/smccc and the Arm CCA guest driver.
Move the RSI SMCCC definitions from arch/arm64/include/asm/ to include/linux/ so they can be shared with the driver code. This also keeps the firmware interface outside architecture code, as requested [1].
Not all helpers in rsi_cmds.h are used by architecture code. The attestation token helper wrappers are only used by the Arm CCA guest driver, so move them to a driver-private header under drivers/virt/coco/arm-cca-guest/. Keep the remaining RSI command helpers, which are shared by architecture code and drivers, in the arm64 header.
[1] https://lore.kernel.org/all/agsNO9cc7H-b0H8L@willie-the-truck
--- arch/arm64/include/asm/rsi_cmds.h | 75 +---------------- .../virt/coco/arm-cca-guest/arm-cca-guest.c | 2 + drivers/virt/coco/arm-cca-guest/rsi.h | 84 +++++++++++++++++++ .../linux/arm-smccc-rsi.h | 6 +- 4 files changed, 90 insertions(+), 77 deletions(-) create mode 100644 drivers/virt/coco/arm-cca-guest/rsi.h rename arch/arm64/include/asm/rsi_smc.h => include/linux/arm-smccc-rsi.h (98%)
arch/arm64/include/asm/rsi_cmds.h +1 -74
@@ -6,12 +6,10 @@#ifndef __ASM_RSI_CMDS_H#define __ASM_RSI_CMDS_H -#include <linux/arm-smccc.h> +#include <linux/arm-smccc-rsi.h> #include <linux/string.h> #include <asm/memory.h> -#include <asm/rsi_smc.h> -#define RSI_GRANULE_SHIFT 12#define RSI_GRANULE_SIZE (_AC(1, UL) << RSI_GRANULE_SHIFT)
@@ -88,75 +86,4 @@ static inline long rsi_set_addr_range_state(phys_addr_t start, return res.a0; } -/** -* rsi_attestation_token_init - Initialise the operation to retrieve an -* attestation token. -* -* @challenge: The challenge data to be used in the attestation token -* generation. -* @size: Size of the challenge data in bytes. -* -* Initialises the attestation token generation and returns an upper bound -* on the attestation token size that can be used to allocate an adequate -* buffer. The caller is expected to subsequently call -* rsi_attestation_token_continue() to retrieve the attestation token data on -* the same CPU. -* -* Returns: -* On success, returns the upper limit of the attestation report size. -* Otherwise, -EINVAL -*/ -static inline long -rsi_attestation_token_init (const u8 *challenge,unsigned long size) -{ -struct arm_smccc_1_2_regs regs = {0 }; - -/* The challenge must be at least 32bytes and at most 64bytes */ -if (!challenge || size <32 || size >64 ) -return -EINVAL ; - - regs.a0 =SMC_RSI_ATTESTATION_TOKEN_INIT ; -memcpy (®s.a1, challenge, size); -arm_smccc_1_2_smc (®s, ®s); - -if (regs.a0 ==RSI_SUCCESS ) -return regs.a1; - -return -EINVAL ; -} - -/** -* rsi_attestation_token_continue - Continue the operation to retrieve an -* attestation token. -* -* @granule: {I}PA of the Granule to which the token will be written. -* @offset: Offset within Granule to start of buffer in bytes. -* @size: The size of the buffer. -* @len: The number of bytes written to the buffer. -* -* Retrieves up to a RSI_GRANULE_SIZE worth of token data per call. The caller -* is expected to call rsi_attestation_token_init() before calling this -* function to retrieve the attestation token. -* -* Return: -* * %RSI_SUCCESS - Attestation token retrieved successfully. -* * %RSI_INCOMPLETE - Token generation is not complete. -* * %RSI_ERROR_INPUT - A parameter was not valid. -* * %RSI_ERROR_STATE - Attestation not in progress. -*/ -static inline unsigned long rsi_attestation_token_continue (phys_addr_t granule, -unsigned long offset, -unsigned long size, -unsigned long *len) -{ -struct arm_smccc_res res; - -arm_smccc_1_1_invoke (SMC_RSI_ATTESTATION_TOKEN_CONTINUE , - granule, offset, size,0 , &res); - -if (len) - *len = res.a1; -return res.a0; -} -#endif /* __ASM_RSI_CMDS_H */
drivers/virt/coco/arm-cca-guest/arm-cca-guest.c +2 -0
@@ -14,6 +14,8 @@#include <asm/rsi.h> +#include "rsi.h" +/** * struct arm_cca_token_info - a descriptor for the token buffer. * @challenge: Pointer to the challenge data
drivers/virt/coco/arm-cca-guest/rsi.h new file +84 -0
84 lines not on this page · raw message
include/linux/arm-smccc-rsi.h renamed from arch/arm64/include/asm/rsi_smc.h +3 -3
@@ -3,8 +3,8 @@* Copyright (C) 2023 ARM Ltd. */ -#ifndef __ASM_RSI_SMC_H_ -#define __ASM_RSI_SMC_H_ +#ifndef __LINUX_ARM_SMCCC_RSI_H_ +#define __LINUX_ARM_SMCCC_RSI_H_#include <linux/arm-smccc.h>
@@ -190,4 +190,4 @@ struct realm_config {*/ #define SMC_RSI_HOST_CALL SMC_RSI_FID(0x199) -#endif /* __ASM_RSI_SMC_H_ */ +#endif /* __LINUX_ARM_SMCCC_RSI_H_ */
Signature · 1 line
2.43.0
PATCH v8 4/6 virt: coco: arm-cca-guest: Rename TSM report source file
In reply to Aneesh Kumar K.V (Arm)The Arm CCA guest driver currently only implements TSM report support, but follow-up changes will add more TSM-related functionality to the same module.
Rename arm-cca-guest.c to arm-cca.c and build it as an object of the arm-cca-guest module. This leaves room for the module to grow additional source files.
---
drivers/virt/coco/arm-cca-guest/Makefile | 2 ++
.../virt/coco/arm-cca-guest/{arm-cca-guest.c => arm-cca.c} | 6 +++---
2 files changed, 5 insertions(+), 3 deletions(-)
rename drivers/virt/coco/arm-cca-guest/{arm-cca-guest.c => arm-cca.c} (97%)drivers/virt/coco/arm-cca-guest/Makefile +2 -0
@@ -1,2 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_ARM_CCA_GUEST) += arm-cca-guest.o + +arm-cca-guest-y += arm-cca.o
drivers/virt/coco/arm-cca-guest/arm-cca.c renamed from drivers/virt/coco/arm-cca-guest/arm-cca-guest.c +3 -3
@@ -184,7 +184,7 @@ static int arm_cca_report_new(struct tsm_report *report, void *data)return ret; } -static const struct tsm_report_ops arm_cca_tsm_ops = { +static const struct tsm_report_ops arm_cca_tsm_report_ops = { .name =KBUILD_MODNAME , .report_new = arm_cca_report_new, };
@@ -205,7 +205,7 @@ static int __init arm_cca_guest_init(void)if (!is_realm_world ())return -ENODEV ; - ret =tsm_report_register (&arm_cca_tsm_ops,NULL ); + ret =tsm_report_register (&arm_cca_tsm_report_ops,NULL );if (ret <0 )pr_err ("Error %d registering with TSM\n" , ret);
@@ -219,7 +219,7 @@ module_init(arm_cca_guest_init);*/ static void __exit arm_cca_guest_exit(void) { -tsm_report_unregister (&arm_cca_tsm_ops); +tsm_report_unregister (&arm_cca_tsm_report_ops); }module_exit (arm_cca_guest_exit);
Signature · 1 line
2.43.0
Re: [PATCH v8 4/6] virt: coco: arm-cca-guest: Rename TSM report source file
Quoted 9 lines · Aneesh Kumar K.V (Arm)
The Arm CCA guest driver currently only implements TSM report support, but follow-up changes will add more TSM-related functionality to the same module.
Rename
arm-cca-guest.ctoarm-cca.cand build it as an object of the arm-cca-guest module. This leaves room for the module to grow additional source files.Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>
Quoted 49 lines
--- drivers/virt/coco/arm-cca-guest/Makefile | 2 ++ .../virt/coco/arm-cca-guest/{arm-cca-guest.c => arm-cca.c} | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-)rename
drivers/virt/coco/arm-cca-guest/{arm-cca-guest.c=>arm-cca.c} (97%)drivers/virt/coco/arm-cca-guest/Makefile +2
-0@@ -1,2 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_ARM_CCA_GUEST) += arm-cca-guest.o + +arm-cca-guest-y += arm-cca.odrivers/virt/coco/arm-cca-guest/arm-cca.c renamed from drivers/virt/coco/arm-cca-guest/arm-cca-guest.c +3
-3@@ -184,7 +184,7 @@ static int arm_cca_report_new(struct tsm_report *report, void *data)return ret; } -static const struct tsm_report_ops arm_cca_tsm_ops = { +static const struct tsm_report_ops arm_cca_tsm_report_ops = { .name =KBUILD_MODNAME , .report_new = arm_cca_report_new, };@@ -205,7 +205,7 @@ static int __init arm_cca_guest_init(void)if (!is_realm_world ())return -ENODEV ; - ret =tsm_report_register (&arm_cca_tsm_ops,NULL ); + ret =tsm_report_register (&arm_cca_tsm_report_ops,NULL );if (ret <0 )pr_err ("Error %d registering with TSM\n" , ret);@@ -219,7 +219,7 @@ module_init(arm_cca_guest_init);*/ static void __exit arm_cca_guest_exit(void) { -tsm_report_unregister (&arm_cca_tsm_ops); +tsm_report_unregister (&arm_cca_tsm_report_ops); }module_exit (arm_cca_guest_exit);
PATCH v8 5/6 firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
In reply to Aneesh Kumar K.V (Arm)The Arm CCA guest TSM provider currently binds through the arm-cca-dev platform device. Like arm-smccc-trng, this device is not an independent platform resource; it is a software representation of the RSI firmware service discovered through SMCCC.
Move RSI discovery into the SMCCC firmware driver. When the SMCCC conduit is SMC and if RSI ABI version call is supported, create an arm-rsi-dev SMCCC device. Convert the Arm CCA guest TSM provider to an SMCCC driver so it binds to that discovered RSI service and keeps module autoloading through the SMCCC device id table.
Keep the old arm-cca-dev platform-device registration for now. Userspace has used that device as a Realm-guest indicator, so removing it is left to a follow-up patch that adds a replacement sysfs ABI.
--- arch/arm64/include/asm/rsi.h | 2 - arch/arm64/kernel/rsi.c | 2 +- drivers/firmware/smccc/smccc.c | 7 +++ drivers/virt/coco/arm-cca-guest/Kconfig | 1 + drivers/virt/coco/arm-cca-guest/arm-cca.c | 56 +++++++++++------------ include/linux/arm-smccc-rsi.h | 2 + 6 files changed, 39 insertions(+), 31 deletions(-)
arch/arm64/include/asm/rsi.h +0 -2
@@ -10,8 +10,6 @@#include <linux/jump_label.h> #include <asm/rsi_cmds.h> -#define RSI_PDEV_NAME "arm-cca-dev" -DECLARE_STATIC_KEY_FALSE (rsi_present);void __init arm64_rsi_init (void );
arch/arm64/kernel/rsi.c +1 -1
@@ -161,7 +161,7 @@ void __init arm64_rsi_init(void) }static struct platform_device rsi_dev = { - .name =RSI_PDEV_NAME , + .name ="arm-cca-dev" , .id =PLATFORM_DEVID_NONE };
drivers/firmware/smccc/smccc.c +7 -0
@@ -10,6 +10,7 @@#include <linux/arm-smccc.h> #include <linux/kernel.h> #include <linux/arm-smccc-bus.h> +#include <linux/arm-smccc-rsi.h> #include <asm/archrandom.h>
@@ -94,6 +95,12 @@ static const struct smccc_device_info smccc_devices[] __initconst = { .requires_smc = false, .device_name = "arm-smccc-trng", }, + + { + .func_id = SMC_RSI_ABI_VERSION, + .requires_smc = true, + .device_name = RSI_DEV_NAME, + }, };static bool __init smccc_probe_smccc_device (const struct smccc_device_info *smccc_dev)
drivers/virt/coco/arm-cca-guest/Kconfig +1 -0
@@ -1,6 +1,7 @@ config ARM_CCA_GUEST tristate "Arm CCA Guest driver" depends on ARM64 + depends on HAVE_ARM_SMCCC_DISCOVERY select TSM_REPORTS help The driver provides userspace interface to request and
drivers/virt/coco/arm-cca-guest/arm-cca.c +28 -28
80 lines not on this page · raw message
include/linux/arm-smccc-rsi.h +2 -0
@@ -8,6 +8,8 @@#include <linux/arm-smccc.h> +#define RSI_DEV_NAME "arm-rsi-dev" +/* * This file describes the Realm Services Interface (RSI) Application Binary * Interface (ABI) for SMC calls made from within the Realm to the RMM and
Signature · 1 line
2.43.0
Re: [PATCH v8 5/6] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
Quoted 11 lines · Aneesh Kumar K.V (Arm)
The Arm CCA guest TSM provider currently binds through the arm-cca-dev platform device. Like arm-smccc-trng, this device is not an independent platform resource; it is a software representation of the RSI firmware service discovered through SMCCC.
Move RSI discovery into the SMCCC firmware driver. When the SMCCC conduit is SMC and if RSI ABI version call is supported, create an arm-rsi-dev SMCCC device. Convert the Arm CCA guest TSM provider to an SMCCC driver so it binds to that discovered RSI service and keeps module autoloading through the SMCCC device id table.
Quoted 5 lines
Keep the old arm-cca-dev platform-device registration for now. Userspace has used that device as a Realm-guest indicator, so removing it is left to a follow-up patch that adds a replacement sysfs ABI.
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>
Quoted 172 lines
--- arch/arm64/include/asm/rsi.h | 2 - arch/arm64/kernel/rsi.c | 2 +- drivers/firmware/smccc/smccc.c | 7 +++ drivers/virt/coco/arm-cca-guest/Kconfig | 1 + drivers/virt/coco/arm-cca-guest/arm-cca.c | 56 +++++++++++------------ include/linux/arm-smccc-rsi.h | 2 + 6 files changed, 39 insertions(+), 31 deletions(-)arch/arm64/include/asm/rsi.h +0
-2@@ -10,8 +10,6 @@#include <linux/jump_label.h> #include <asm/rsi_cmds.h> -#define RSI_PDEV_NAME "arm-cca-dev" -DECLARE_STATIC_KEY_FALSE (rsi_present);void __init arm64_rsi_init (void );arch/arm64/kernel/rsi.c +1
-1@@ -161,7 +161,7 @@ void __init arm64_rsi_init(void) }static struct platform_device rsi_dev = { - .name =RSI_PDEV_NAME , + .name ="arm-cca-dev" , .id =PLATFORM_DEVID_NONE };drivers/firmware/smccc/smccc.c +7
-0@@ -10,6 +10,7 @@#include <linux/arm-smccc.h> #include <linux/kernel.h> #include <linux/arm-smccc-bus.h> +#include <linux/arm-smccc-rsi.h> #include <asm/archrandom.h> @@ -94,6 +95,12 @@ static const struct smccc_device_info smccc_devices[] __initconst = { .requires_smc = false, .device_name = "arm-smccc-trng", }, + + { + .func_id = SMC_RSI_ABI_VERSION, + .requires_smc = true, + .device_name = RSI_DEV_NAME, + }, };static bool __init smccc_probe_smccc_device (const struct smccc_device_info *smccc_dev)drivers/virt/coco/arm-cca-guest/Kconfig +1
-0@@ -1,6 +1,7 @@ config ARM_CCA_GUEST tristate "Arm CCA Guest driver" depends on ARM64 + depends on HAVE_ARM_SMCCC_DISCOVERY select TSM_REPORTS help The driver provides userspace interface to request anddrivers/virt/coco/arm-cca-guest/arm-cca.c +28
-28@@ -4,6 +4,7 @@*/ #include <linux/arm-smccc.h> +#include <linux/arm-smccc-bus.h> #include <linux/cc_platform.h> #include <linux/kernel.h> #include <linux/device-id/platform.h> @@ -189,16 +190,12 @@ static const struct tsm_report_ops arm_cca_tsm_report_ops = { .report_new = arm_cca_report_new, }; -/** -* arm_cca_guest_init - Register with the Trusted Security Module (TSM) -* interface. -* -* Return: -* * %0 - Registered successfully with the TSM interface. -* * %-ENODEV - The execution context is not an Arm Realm. -* * %-EBUSY - Already registered. -*/ -static int __init arm_cca_guest_init (void ) +static void unregister_cca_tsm_report (void *data) +{ +tsm_report_unregister (&arm_cca_tsm_report_ops); +} + +static int cca_tsm_probe (struct arm_smccc_device *sdev) {int ret;@@ -206,30 +203,33 @@ static int __init arm_cca_guest_init(void)return -ENODEV ; ret =tsm_report_register (&arm_cca_tsm_report_ops,NULL ); -if (ret <0 ) -pr_err ("Error %d registering with TSM\n" , ret); +if (ret <0 ) { +dev_err_probe (&sdev->dev, ret,"Error registering with TSM\n" ); +return ret; + } -return ret; -} -module_init (arm_cca_guest_init); + ret =devm_add_action_or_reset (&sdev->dev, unregister_cca_tsm_report, +NULL ); +if (ret <0 ) { +dev_err_probe (&sdev->dev, ret,"Error registering devm action\n" ); +return ret; + } -/** -* arm_cca_guest_exit - unregister with the Trusted Security Module (TSM) -* interface. -*/ -static void __exit arm_cca_guest_exit(void) -{ -tsm_report_unregister (&arm_cca_tsm_report_ops); +return 0 ; } -module_exit (arm_cca_guest_exit); -/* modalias, so userspace can autoload this module when RSI is available */ -static const struct platform_device_id arm_cca_match[]__maybe_unused = { - {RSI_PDEV_NAME ,0 }, - { } +static const struct arm_smccc_device_id cca_tsm_id_table[] = { + { .name =RSI_DEV_NAME }, + {} }; +MODULE_DEVICE_TABLE (arm_smccc, cca_tsm_id_table); -MODULE_DEVICE_TABLE (platform, arm_cca_match); +static struct arm_smccc_driver cca_tsm_driver = { + .name =KBUILD_MODNAME , + .probe = cca_tsm_probe, + .id_table = cca_tsm_id_table, +}; +module_arm_smccc_driver (cca_tsm_driver);MODULE_AUTHOR ("Sami Mujawar <[email protected]>" );MODULE_DESCRIPTION ("Arm CCA Guest TSM Driver" );MODULE_LICENSE ("GPL" );include/linux/arm-smccc-rsi.h +2
-0@@ -8,6 +8,8 @@#include <linux/arm-smccc.h> +#define RSI_DEV_NAME "arm-rsi-dev" +/* * This file describes the Realm Services Interface (RSI) Application Binary * Interface (ABI) for SMC calls made from within the Realm to the RMM and
PATCH v8 6/6 coco: guest: arm64: Replace dummy CCA device with sysfs ABI
In reply to Aneesh Kumar K.V (Arm)The SMCCC firmware driver now creates the arm-smccc platform device and instantiates the CCA RSI auxiliary devices once the RSI ABI is discovered. The arm64-specific arm-cca-dev platform device stub is therefore no longer needed.
However, userspace has used the arm-cca-dev platform device to detect Arm CCA Realm guests [1]. Removing it without a replacement would break that detection and would also leave userspace depending on kernel device-model details.
Add /sys/firmware/cca/realm_guest as a stable, architecture-provided ABI for detecting whether the kernel is running as an Arm CCA Realm guest. The file returns 1 in Realm world and 0 otherwise, similar to the existing s390 /sys/firmware/uv/prot_virt_guest interface for protected virtualization guests.
Remove the dummy arm-cca-dev registration now that userspace has a dedicated CCA Realm guest indicator, and document the new ABI in Documentation/ABI/testing/sysfs-firmware-cca.
[1] https://lore.kernel.org/all/[email protected]
--- Documentation/ABI/testing/sysfs-firmware-cca | 10 +++++ arch/arm64/kernel/rsi.c | 39 +++++++++++++++----- 2 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-firmware-cca
Documentation/ABI/testing/sysfs-firmware-cca new file +10 -0
@@ -0,0 +1,10 @@ +What: /sys/firmware/cca/realm_guest +Date: May 2026 +Contact: Linux ARM Kernel Mailing list <[email protected]> +Description: Read-only. Indicates whether the kernel is running as an + Arm Confidential Compute Architecture (CCA) Realm guest. + + The value is one of: + + 0: the kernel is not running as a Realm guest + 1: the kernel is running as a Realm guest
arch/arm64/kernel/rsi.c +29 -10
@@ -9,6 +9,8 @@#include <linux/swiotlb.h> #include <linux/cc_platform.h> #include <linux/platform_device.h> +#include <linux/kobject.h> +#include <linux/sysfs.h> #include <asm/io.h> #include <asm/mem_encrypt.h>
@@ -16,6 +18,7 @@#include <asm/rsi.h> static struct realm_config config; +static struct kobject *cca_kobj;unsigned long prot_ns_shared;EXPORT_SYMBOL (prot_ns_shared);
@@ -160,17 +163,33 @@ void __init arm64_rsi_init(void)static_branch_enable (&rsi_present); } -static struct platform_device rsi_dev = { - .name ="arm-cca-dev" , - .id =PLATFORM_DEVID_NONE +static ssize_t cca_is_realm_guest (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%d\n" ,is_realm_world ()); +} + +static struct kobj_attribute cca_realm_guest = +__ATTR (realm_guest,0444 , cca_is_realm_guest,NULL ); + +static const struct attribute *cca_realm_attrs[] = { + &cca_realm_guest.attr, +NULL , }; -static int __init arm64_create_dummy_rsi_dev (void ) +static int __init realm_sysfs_init (void ) { -if (is_realm_world () && -platform_device_register (&rsi_dev)) -pr_err ("failed to register rsi platform device\n" ); -return 0 ; -} +int ret; + + cca_kobj =kobject_create_and_add ("cca" , firmware_kobj); +if (!cca_kobj) +return -ENOMEM ; -arch_initcall (arm64_create_dummy_rsi_dev) + ret =sysfs_create_files (cca_kobj, cca_realm_attrs); +if (!ret) +return 0 ; + +kobject_put (cca_kobj); +return ret; +} +device_initcall (realm_sysfs_init);
Signature · 1 line
2.43.0
Re: [PATCH v8 6/6] coco: guest: arm64: Replace dummy CCA device with sysfs ABI
Quoted 16 lines · Aneesh Kumar K.V (Arm)
The SMCCC firmware driver now creates the arm-smccc platform device and instantiates the CCA RSI auxiliary devices once the RSI ABI is discovered. The arm64-specific arm-cca-dev platform device stub is therefore no longer needed.
However, userspace has used the arm-cca-dev platform device to detect Arm CCA Realm guests [1]. Removing it without a replacement would break that detection and would also leave userspace depending on kernel device-model details.
Add
/sys/firmware/cca/realm_guestas a stable, architecture-provided ABI for detecting whether the kernel is running as an Arm CCA Realm guest. The file returns 1 in Realm world and 0 otherwise, similar to the existing s390/sys/firmware/uv/prot_virt_guestinterface for protected virtualization guests.
Quoted 7 lines
Remove the dummy arm-cca-dev registration now that userspace has a dedicated CCA Realm guest indicator, and document the new ABI in
Documentation/ABI/testing/sysfs-firmware-cca.[1] https://lore.kernel.org/all/[email protected]
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>
Quoted 25 lines · Aneesh Kumar K.V (Arm)
As discussed here:
https://lore.kernel.org/all/[email protected]The earlier CCA guest support used an arm-cca-dev platform device as a pure software anchor for the TSM class device. That platform device did not correspond to a DT/ACPI described device, MMIO range, interrupt, or other platform resource; it existed only to make the CCA guest driver bind and to place the resulting TSM device in the driver model. The same pattern also exists for
smccc_trng. Creating separate platform devices for such SMCCC-discovered features is misleading, because those features are not independent platform devices.This series adds an Arm SMCCC bus for services discovered through the SMCCC firmware interface. The bus provides SMCCC device and driver registration helpers, name-based matching, uevent modalias generation, and a sysfs modalias attribute. SMCCC service drivers can use
MODULE_DEVICE_TABLE(arm_smccc, ...)to emit arm_smccc:<name> aliases, allowing userspace to autoload service drivers when the SMCCC core registers matching firmware-service devices.The series then moves SMCCC TRNG and the Arm CCA guest RSI service off the platform bus. When the SMCCC core discovers the corresponding firmware service, it registers an arm-smccc device for that service. The hwrng
arm_smccc_trngdriver and the Arm CCA guest TSM provider are converted to SMCCC drivers that bind to those discovered devices.
Quoted 7 lines
The old arm-cca-dev platform device has also been used by userspace as a Realm guest indicator. Removing it without a replacement would leave userspace depending on an internal driver-binding device. This series therefore adds
/sys/firmware/cca/realm_guestas a stable, architecture-provided ABI for detecting whether the kernel is running as an Arm CCA Realm guest, and then removes the dummy arm-cca-dev platform-device registration.
Hi Will and Catalin,
Gentle ping. Can this be picked up for the next merge window?
-aneesh