Skip to contentSkip to conversation

Switch Arm SMCCC firmware services to an SMCCC bus

PATCH Superseded Aneesh Kumar K.V (Arm) 6 participants 35 messages Sep 14 – Sep 24

Subsystems (5)

v11 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v11 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, SMCCC function id based matching, uevent modalias generation, and a sysfs modalias attribute. SMCCC service drivers can use MODULE_DEVICE_TABLE(arm_smccc, ...) to emit arm_smccc:f<functionid> 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 v10:
https://lore.kernel.org/all/[email protected]
* Collect Reviewed-by tags.
* Add the missing linux/types.h include.
* Update the arm_smccc_1_1_invoke() call to pass 0 as the input value for x1-x7.

Changes from v9:
https://lore.kernel.org/all/[email protected]
* Rename CONFIG_ARM_RMM to CONFIG_ARM_RMM_RSI to make the Kconfig option RSI-specific.
* Update the modalias to use the SMCCC function ID.
* Don't issue SMC64 SMCCC calls on arm32.
* Drop the IDA usage.

Changes from v8:
https://lore.kernel.org/all/[email protected]
* Rebase onto the arm64 for-next/core branch.
* Move the RSI code from arch/arm64 to drivers/firmware/arm_rmm in patch 3.
* Add a new patch to move the Realm memory-encryption operations to the RSI code.
* Drop the Reviewed-by tag from patch 3.

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

Cc Jason Gunthorpe <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Greg KH <[email protected]>
Cc Jeremy Linton <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Sudeep Holla <[email protected]>
Cc Will Deacon <[email protected]>
Cc Steven Price <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Andre Przywara <[email protected]>

Aneesh Kumar K.V (Arm) (7):
firmware: smccc: Add an Arm SMCCC bus
firmware: hwrng: arm_smccc_trng: Register as an SMCCC device
firmware: arm_rmm: Move RSI support out of arch/arm64
arm64: realm: Move Realm memory encryption ops to RSI code
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/Kconfig                            |   1 +
 arch/arm64/include/asm/archrandom.h           |   2 +-
 arch/arm64/include/asm/io.h                   |   2 +-
 arch/arm64/include/asm/mem_encrypt.h          |   5 +-
 arch/arm64/include/asm/pgtable-prot.h         |   2 +-
 arch/arm64/include/asm/rsi.h                  |  70 --------
 arch/arm64/kernel/Makefile                    |   2 +-
 arch/arm64/kernel/setup.c                     |   2 +-
 arch/arm64/mm/init.c                          |   3 +-
 arch/arm64/mm/pageattr.c                      |  38 +----
 drivers/char/hw_random/arm_smccc_trng.c       |  32 ++--
 drivers/firmware/Kconfig                      |   1 +
 drivers/firmware/Makefile                     |   1 +
 drivers/firmware/arm_rmm/Kconfig              |  17 ++
 drivers/firmware/arm_rmm/Makefile             |   2 +
 .../kernel => drivers/firmware/arm_rmm}/rsi.c |  78 +++++++--
 drivers/firmware/smccc/Makefile               |   2 +-
 drivers/firmware/smccc/bus.c                  | 151 ++++++++++++++++++
 drivers/firmware/smccc/smccc.c                |  68 ++++++--
 drivers/virt/coco/arm-cca-guest/Kconfig       |   3 +-
 drivers/virt/coco/arm-cca-guest/Makefile      |   2 +
 .../arm-cca-guest/{arm-cca-guest.c => main.c} |  55 +++----
 .../linux/arm-rsi-cmds.h                      |  76 ++++++++-
 include/linux/arm-smccc-bus.h                 |  48 ++++++
 .../linux/arm-smccc-rsi.h                     |   6 +-
 include/linux/device-id/arm_smccc.h           |  19 +++
 include/linux/mod_devicetable.h               |   1 +
 scripts/mod/devicetable-offsets.c             |   3 +
 scripts/mod/file2alias.c                      |   8 +
 31 files changed, 523 insertions(+), 189 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-firmware-cca
 delete mode 100644 arch/arm64/include/asm/rsi.h
 create mode 100644 drivers/firmware/arm_rmm/Kconfig
 create mode 100644 drivers/firmware/arm_rmm/Makefile
 rename {arch/arm64/kernel => drivers/firmware/arm_rmm}/rsi.c (70%)
 create mode 100644 drivers/firmware/smccc/bus.c
 rename drivers/virt/coco/arm-cca-guest/{arm-cca-guest.c => main.c} (82%)
 rename arch/arm64/include/asm/rsi_cmds.h => include/linux/arm-rsi-cmds.h (69%)
 create mode 100644 include/linux/arm-smccc-bus.h
 rename arch/arm64/include/asm/rsi_smc.h => include/linux/arm-smccc-rsi.h (98%)
 create mode 100644 include/linux/device-id/arm_smccc.h

base-commit: 704340f1cd0dcef829eb62f5b48ae95a2ce17bdf

Signature · 1 line
2.43.0
#1 lore raw

PATCH v11 1/7 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        | 151 ++++++++++++++++++++++++++++
 include/linux/arm-smccc-bus.h       |  48 +++++++++
 include/linux/device-id/arm_smccc.h |  19 ++++
 include/linux/mod_devicetable.h     |   1 +
 scripts/mod/devicetable-offsets.c   |   3 +
 scripts/mod/file2alias.c            |   8 ++
 7 files changed, 231 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
index 40d19144a860..68bbff1407b8 100644
@@ -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 +151 -0

151 lines not on this page · raw message

include/linux/arm-smccc-bus.h new file +48 -0

48 lines not on this page · raw message

include/linux/device-id/arm_smccc.h new file +19 -0
new file mode 100644
index 000000000000..a8579832fc1c
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LINUX_DEVICE_ID_ARM_SMCCC_H
+#define __LINUX_DEVICE_ID_ARM_SMCCC_H
+
+#ifdef __KERNEL__
+#include <linux/types.h>
+#endif
+
+#define ARM_SMCCC_MODULE_PREFIX "arm_smccc:"
+
+/**
+ * struct arm_smccc_device_id - Arm SMCCC bus device identifier
+ * @func_id: SMCCC function identifier
+ */
+struct arm_smccc_device_id {
+	__u32 func_id;
+};
+
+#endif /* __LINUX_DEVICE_ID_ARM_SMCCC_H */
include/linux/mod_devicetable.h +1 -0
index a397213bedac..318c4b5c3451 100644
@@ -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
index b4178c42d08f..1492e9fdc7cb 100644
@@ -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, func_id);
+
 	DEVID(ssam_device_id);
 	DEVID_FIELD(ssam_device_id, match_flags);
 	DEVID_FIELD(ssam_device_id, domain);
scripts/mod/file2alias.c +8 -0
index 8d36c74dec2d..980d7da456bb 100644
@@ -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(symval, arm_smccc_device_id, func_id);
+
+	module_alias_printf(mod, false, ARM_SMCCC_MODULE_PREFIX "f%08X", func_id);
+}
+
 /*
  * 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
maintainer Reviewed-by on v11 1/7
#2 lore raw

Re: [PATCH v11 1/7] firmware: smccc: Add an Arm SMCCC bus

Quoted 8 lines · Aneesh Kumar K.V (Arm)

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

Nit: "name-based matching" is no longer true. The latest series uses function ID.

Reviewed-by on v11 1/7
#3 lore raw

Re: [PATCH v11 1/7] firmware: smccc: Add an Arm SMCCC bus

In reply to Aneesh Kumar K.V (Arm)
Quoted 11 lines · On Mon, 14 Sep 2026 11:35:05 +0530 "Aneesh Kumar K.V (Arm)"…

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.

Quoted 4 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_ffa code

That code has the same issue as below and for bonus points doesn't check if dev_set_name() succeeds or not.

Quoted 4 lines

On tiny bit of fragility inline that I'd suggestion avoiding now rather than later. Down to dev_set_name() doing allocations in some cases under the hood that are tricky to tidy up with device_register() being used.

With that tidied up

Quoted 14 lines
drivers/firmware/smccc/bus.c new file +8 -0
new file mode 100644
index 000000000000..caba1a03c997
 
+
+struct arm_smccc_device *arm_smccc_device_register(const char *name, u32 func_id)
+{
+	int ret;
+	struct arm_smccc_device *smccc_dev;
+
+	if (!name)
+		return ERR_PTR(-EINVAL);

drivers/firmware/smccc/bus.c line 122

Quoted 10 lines
drivers/firmware/smccc/bus.c new file +10 -0
+
+	smccc_dev = kzalloc_obj(*smccc_dev);
+	if (!smccc_dev)
+		return ERR_PTR(-ENOMEM);
+
+	smccc_dev->func_id = func_id;
+	smccc_dev->dev.bus = &arm_smccc_bus_type;
+	smccc_dev->dev.release = arm_smccc_release_device;
+
+	ret = dev_set_name(&smccc_dev->dev, "%s", name);

Does protecting the string defeat the nice underlying const handling? e.g.

	ret = dev_set_name(&smccc_dev->dev, name);

might be better. Not particular important - I only noticed because you'd often see this between an device_initialize() and device_add() and then we'd be relying on the device_put() to clean it up.

So as this stands this is fragile as any error paths that later get added...

drivers/firmware/smccc/bus.c line 127

Quoted 5 lines
drivers/firmware/smccc/bus.c new file +5 -0
+	if (ret) {
+		kfree(smccc_dev);
+		return ERR_PTR(ret);
+	}
+

here can't free the name allocation.

So I'd just switch this to a split device setup - something like...

	smccc_dev = kzalloc_obj(*smccc_dev);
	if (!smccc_dev)
		return ERR_PTR(-ENOMEM);

	smccc_dev->func_id = func_id;
	smccc_dev->dev.bus = &arm_smccc_bus_type;
	smccc_dev->dev.release = arm_smccc_release_device;

	device_initialize(&smccc_dev->dev);
	ret = dev_set_name(&smccc_dev->dev, "%s", name);

//up to you whether you care about const string handling.

	if (ret) {
		put_device(&smcc_dev->dev);
		return ret;
	}

	ret = device_register(&smccc_dev->dev);
	if (ret) {
		put_device(&smccc_dev->dev);
		return ERR_PTR(ret);
	}

	return smccc_dev;
Quoted 24 lines
drivers/firmware/smccc/bus.c new file +24 -0
+	ret = device_register(&smccc_dev->dev);
+	if (ret) {
+		put_device(&smccc_dev->dev);
+		return ERR_PTR(ret);
+	}
+
+	return smccc_dev;
+}
+EXPORT_SYMBOL_GPL(arm_smccc_device_register);
+
+void arm_smccc_device_unregister(struct arm_smccc_device *smccc_dev)
+{
+	if (!smccc_dev)
+		return;
+
+	device_unregister(&smccc_dev->dev);
+}
+EXPORT_SYMBOL_GPL(arm_smccc_device_unregister);
+
+static int __init arm_smccc_bus_init(void)
+{
+	return bus_register(&arm_smccc_bus_type);
+}
+subsys_initcall(arm_smccc_bus_init);
#4 lore raw

Re: [PATCH v11 1/7] firmware: smccc: Add an Arm SMCCC bus

Quoted 20 lines · Jonathan Cameron
Quoted 7 lines
drivers/firmware/smccc/bus.c new file +7 -0
+struct arm_smccc_device *arm_smccc_device_register(const char *name, u32 func_id)
+{
+	int ret;
+	struct arm_smccc_device *smccc_dev;
+
+	if (!name)
+		return ERR_PTR(-EINVAL);

drivers/firmware/smccc/bus.c line 122

Quoted 10 lines
drivers/firmware/smccc/bus.c new file +10 -0
+
+	smccc_dev = kzalloc_obj(*smccc_dev);
+	if (!smccc_dev)
+		return ERR_PTR(-ENOMEM);
+
+	smccc_dev->func_id = func_id;
+	smccc_dev->dev.bus = &arm_smccc_bus_type;
+	smccc_dev->dev.release = arm_smccc_release_device;
+
+	ret = dev_set_name(&smccc_dev->dev, "%s", name);

Does protecting the string defeat the nice underlying const handling? e.g.

Quoted 2 lines
	ret = dev_set_name(&smccc_dev->dev, name);

might be better.

Pedenatically the %s is better as it doesn't restrict name to not include % characters.

Quoted 5 lines

you'd often see this between an device_initialize() and device_add() and then we'd be relying on the device_put() to clean it up.

So as this stands this is fragile as any error paths that later get added...

Yes, but as written it is OK, and this is a common pattern in the kernel. I agree it is fragile tricky..

Still it isn't an urgent reason to change it around, but the best pattern is to put the allocate, dev.release=, and device_initialize() in one 'alloc' function. Then the other function calls it and always unwinds with put_device. Use device_add().

This avoids mixing the different kfree/put_device error unwind regimes into the same function..

Quoted 7 lines

drivers/firmware/smccc/bus.c line 127

Quoted 5 lines
drivers/firmware/smccc/bus.c new file +5 -0
+	if (ret) {
+		kfree(smccc_dev);
+		return ERR_PTR(ret);
+	}
+

here can't free the name allocation.

The funky reasoning is since name failed there is no name allocation to free

And then device_register() failure must always be done with put_device, so it will capture the name. As long as name/register are a pair with nothing between it is "fine".

Jason

#5 lore raw

Re: [PATCH v11 1/7] firmware: smccc: Add an Arm SMCCC bus

Quoted 36 lines · Jason Gunthorpe
Quoted 20 lines · Jonathan Cameron
Quoted 7 lines
drivers/firmware/smccc/bus.c new file +7 -0
+struct arm_smccc_device *arm_smccc_device_register(const char *name, u32 func_id)
+{
+	int ret;
+	struct arm_smccc_device *smccc_dev;
+
+	if (!name)
+		return ERR_PTR(-EINVAL);

drivers/firmware/smccc/bus.c line 122

Quoted 10 lines
drivers/firmware/smccc/bus.c new file +10 -0
+
+	smccc_dev = kzalloc_obj(*smccc_dev);
+	if (!smccc_dev)
+		return ERR_PTR(-ENOMEM);
+
+	smccc_dev->func_id = func_id;
+	smccc_dev->dev.bus = &arm_smccc_bus_type;
+	smccc_dev->dev.release = arm_smccc_release_device;
+
+	ret = dev_set_name(&smccc_dev->dev, "%s", name);

Does protecting the string defeat the nice underlying const handling? e.g.

Quoted 2 lines
	ret = dev_set_name(&smccc_dev->dev, name);

might be better.

Pedenatically the %s is better as it doesn't restrict name to not include % characters.

Quoted 5 lines

you'd often see this between an device_initialize() and device_add() and then we'd be relying on the device_put() to clean it up.

So as this stands this is fragile as any error paths that later get added...

Yes, but as written it is OK, and this is a common pattern in the kernel. I agree it is fragile tricky..

Quoted 8 lines

Still it isn't an urgent reason to change it around, but the best pattern is to put the allocate, dev.release=, and device_initialize() in one 'alloc' function. Then the other function calls it and always unwinds with put_device. Use device_add().

This avoids mixing the different kfree/put_device error unwind regimes into the same function..

Something like

+static struct arm_smccc_device *arm_smccc_device_alloc(u32 func_id) +{
+ struct arm_smccc_device *smccc_dev;
+
+ smccc_dev = kzalloc_obj(*smccc_dev);
+ if (!smccc_dev)
+ return NULL;
+
+ smccc_dev->func_id = func_id;
+ smccc_dev->dev.bus = &arm_smccc_bus_type;
+ smccc_dev->dev.release = arm_smccc_release_device;
+ device_initialize(&smccc_dev->dev);
+
+ return smccc_dev;
+}
+
struct arm_smccc_device *arm_smccc_device_register(const char *name, u32 func_id) {
+ struct arm_smccc_device *smccc_dev;
int ret;
- struct arm_smccc_device *smccc_dev;

if (!name)
return ERR_PTR(-EINVAL);

- smccc_dev = kzalloc_obj(*smccc_dev);
+ smccc_dev = arm_smccc_device_alloc(func_id);
if (!smccc_dev)
return ERR_PTR(-ENOMEM);

- smccc_dev->func_id = func_id;
- smccc_dev->dev.bus = &arm_smccc_bus_type;
- smccc_dev->dev.release = arm_smccc_release_device;
-
ret = dev_set_name(&smccc_dev->dev, "%s", name);
- if (ret) {
- kfree(smccc_dev);
- return ERR_PTR(ret);
- }
+ if (ret)
+ goto err_put_device;

- ret = device_register(&smccc_dev->dev);
- if (ret) {
- put_device(&smccc_dev->dev);
- return ERR_PTR(ret);
- }
+ ret = device_add(&smccc_dev->dev);
+ if (ret)
+ goto err_put_device;

return smccc_dev;
+
+err_put_device:
+ put_device(&smccc_dev->dev);
+ return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(arm_smccc_device_register);

#6 lore raw

Re: [PATCH v11 1/7] firmware: smccc: Add an Arm SMCCC bus

Quoted 8 lines · Aneesh Kumar K.V
Quoted 8 lines

Yes, but as written it is OK, and this is a common pattern in the kernel. I agree it is fragile tricky..

Still it isn't an urgent reason to change it around, but the best pattern is to put the allocate, dev.release=, and device_initialize() in one 'alloc' function. Then the other function calls it and always unwinds with put_device. Use device_add().

Quoted 5 lines
Quoted 3 lines

This avoids mixing the different kfree/put_device error unwind regimes into the same function..

Something like

Yeah, this is the safest way I know to use these interfaces

Jason

#7 lore raw

Re: [PATCH v11 1/7] firmware: smccc: Add an Arm SMCCC bus

Quoted 10 lines · On Tue, 15 Sep 2026 08:46:01 -0300 Jason Gunthorpe <[email protected]> wrote:
Quoted 8 lines · Aneesh Kumar K.V
Quoted 8 lines

Yes, but as written it is OK, and this is a common pattern in the kernel. I agree it is fragile tricky..

Still it isn't an urgent reason to change it around, but the best pattern is to put the allocate, dev.release=, and device_initialize() in one 'alloc' function. Then the other function calls it and always unwinds with put_device. Use device_add().

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

This avoids mixing the different kfree/put_device error unwind regimes into the same function..

Something like

Yeah, this is the safest way I know to use these interfaces

Agreed.

Quoted 1 line

Jason

#8 lore raw

PATCH v11 2/7 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          | 62 +++++++++++++++++++++----
 4 files changed, 76 insertions(+), 22 deletions(-)
arch/arm/include/asm/archrandom.h +1 -1
index cc4714eb1a75..ee39a03ddf8a 100644
@@ -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
index 8babfbe31f95..7605dd81bd1e 100644
@@ -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
index dcb8e7f37f25..01c1a30cbab8 100644
@@ -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[] = {
+	{ .func_id = ARM_SMCCC_TRNG_VERSION },
+	{}
+};
+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 +53 -9

76 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer Reviewed-by on v11 2/7
#9 lore raw

Re: [PATCH v11 2/7] firmware: hwrng: arm_smccc_trng: Register as an SMCCC device

You still haven't copied Olivia and Herbert for the hw_random bits.

Quoted 8 lines · 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.

Quoted 8 lines

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.

Quoted 181 lines
---
 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          | 62 +++++++++++++++++++++----
 4 files changed, 76 insertions(+), 22 deletions(-)
arch/arm/include/asm/archrandom.h +1 -1
index cc4714eb1a75..ee39a03ddf8a 100644
@@ -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
index 8babfbe31f95..7605dd81bd1e 100644
@@ -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
index dcb8e7f37f25..01c1a30cbab8 100644
@@ -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[] = {
+	{ .func_id = ARM_SMCCC_TRNG_VERSION },
+	{}
+};
+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 +53 -9
index bdee057db2fd..756c79204e44 100644
@@ -9,7 +9,8 @@
 #include <linux/init.h>
 #include <linux/arm-smccc.h>
 #include <linux/kernel.h>
-#include <linux/platform_device.h>
+#include <linux/arm-smccc-bus.h>
+
 #include <asm/archrandom.h>
 
 static u32 smccc_version = ARM_SMCCC_VERSION_1_0;
@@ -81,16 +82,59 @@ bool arm_smccc_hypervisor_has_uuid(const uuid_t *hyp_uuid)
 }
 EXPORT_SYMBOL_GPL(arm_smccc_hypervisor_has_uuid);
 
+struct smccc_device_info {
+	u32 func_id;
+	bool requires_smc;
+	const char *device_name;
+};
+
+static const struct smccc_device_info smccc_devices[] __initconst = {
+	{
+		.func_id        = ARM_SMCCC_TRNG_VERSION,
+		.requires_smc   = false,
+		.device_name    = "arm-smccc-trng",
+	},
+};
+
+static bool __init smccc_probe_smccc_device(const struct smccc_device_info *smccc_dev)
+{
+	int ret;
+	struct arm_smccc_res res = {};
+
+	if (smccc_conduit == SMCCC_CONDUIT_NONE)
+		return false;
+
+	if (smccc_dev->requires_smc && smccc_conduit != SMCCC_CONDUIT_SMC)
+		return false;
+
+	if (IS_ENABLED(CONFIG_ARM) && ARM_SMCCC_IS_64(smccc_dev->func_id))
+		return false;
+
+	arm_smccc_1_1_invoke(smccc_dev->func_id,
+			     0, 0, 0, 0, 0, 0, 0, &res);
+	ret = res.a0;
+
+	if (ret == SMCCC_RET_NOT_SUPPORTED)
+		return false;
+
+	return true;
+}
+
 static int __init smccc_devices_init(void)
 {
-	struct platform_device *pdev;
-
-	if (smccc_trng_available) {
-		pdev = platform_device_register_simple("smccc_trng", -1,
-						       NULL, 0);
-		if (IS_ERR(pdev))
-			pr_err("smccc_trng: could not register device: %ld\n",
-			       PTR_ERR(pdev));
+	struct arm_smccc_device *sdev;
+	const struct smccc_device_info *smccc_dev;
+
+	for (int i = 0; i < ARRAY_SIZE(smccc_devices); i++) {
+		smccc_dev = &smccc_devices[i];
+
+		if (!smccc_probe_smccc_device(smccc_dev))
+			continue;
+
+		sdev = arm_smccc_device_register(smccc_dev->device_name, smccc_dev->func_id);
+		if (IS_ERR(sdev))
+			pr_err("%s: could not register device: %ld\n",
+			       smccc_dev->device_name, PTR_ERR(sdev));
 	}
 
 	return 0;
Signature · 1 line
2.43.0
Reviewed-by on v11 2/7
#10 lore raw

Re: [PATCH v11 2/7] firmware: hwrng: arm_smccc_trng: Register as an SMCCC device

In reply to Aneesh Kumar K.V (Arm)
Quoted 8 lines · On Mon, 14 Sep 2026 11:35:06 +0530 "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.

Quoted 8 lines

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.

Trivial stuff inline - nothing that needs changes

drivers/firmware/smccc/smccc.c bool arm_smccc_hypervisor_has_uuid(const uuid_t *hyp_uuid) · line 91

Quoted 7 lines
drivers/firmware/smccc/smccc.c +2 -0
index bdee057db2fd..756c79204e44 100644
 
+
+static const struct smccc_device_info smccc_devices[] __initconst = {

Ah. With __init_const I suspect the string constant stuff I mentioned in previous patch won't work anyway.

Quoted 13 lines
drivers/firmware/smccc/smccc.c +13 -0
+	{
+		.func_id        = ARM_SMCCC_TRNG_VERSION,
+		.requires_smc   = false,
+		.device_name    = "arm-smccc-trng",
+	},
+};
+
+static bool __init smccc_probe_smccc_device(const struct smccc_device_info *smccc_dev)
+{
+	int ret;
+	struct arm_smccc_res res = {};
+
+	if (smccc_conduit == SMCCC_CONDUIT_NONE)

drivers/firmware/smccc/smccc.c bool arm_smccc_hypervisor_has_uuid(const uuid_t *hyp_uuid) · line 114

Quoted 10 lines
drivers/firmware/smccc/smccc.c +10 -0
+		return false;
+
+	if (smccc_dev->requires_smc && smccc_conduit != SMCCC_CONDUIT_SMC)
+		return false;
+
+	if (IS_ENABLED(CONFIG_ARM) && ARM_SMCCC_IS_64(smccc_dev->func_id))
+		return false;
+
+	arm_smccc_1_1_invoke(smccc_dev->func_id,
+			     0, 0, 0, 0, 0, 0, 0, &res);

Fits on one line. Up to you though as maybe it's cleaner to have all the numbers start on a new row.

Quoted 21 lines
drivers/firmware/smccc/smccc.c +11 -8
+	ret = res.a0;
+
+	if (ret == SMCCC_RET_NOT_SUPPORTED)
+		return false;
+
+	return true;
+}
+
 static int __init smccc_devices_init(void)
 {
-	struct platform_device *pdev;
-
-	if (smccc_trng_available) {
-		pdev = platform_device_register_simple("smccc_trng", -1,
-						       NULL, 0);
-		if (IS_ERR(pdev))
-			pr_err("smccc_trng: could not register device: %ld\n",
-			       PTR_ERR(pdev));
+	struct arm_smccc_device *sdev;
+	const struct smccc_device_info *smccc_dev;
+

drivers/firmware/smccc/smccc.c bool arm_smccc_hypervisor_has_uuid(const uuid_t *hyp_uuid) · line 137

Quoted 10 lines
drivers/firmware/smccc/smccc.c +10 -0
+	for (int i = 0; i < ARRAY_SIZE(smccc_devices); i++) {
+		smccc_dev = &smccc_devices[i];
+
+		if (!smccc_probe_smccc_device(smccc_dev))
+			continue;
+
+		sdev = arm_smccc_device_register(smccc_dev->device_name, smccc_dev->func_id);
+		if (IS_ERR(sdev))
+			pr_err("%s: could not register device: %ld\n",
+			       smccc_dev->device_name, PTR_ERR(sdev));

Could be friendly to anyone reading this and use %pe. Up to you.

Quoted 3 lines
drivers/firmware/smccc/smccc.c +0 -0
 	}
 
 	return 0;
maintainer Reviewed-by on v11 2/7
#11 lore raw

Re: [PATCH v11 2/7] firmware: hwrng: arm_smccc_trng: Register as an SMCCC device

In reply to Aneesh Kumar K.V (Arm)
Quoted 17 lines · 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.

---

[...]

Quoted 1 line
 drivers/firmware/smccc/smccc.c          | 62 +++++++++++++++++++++----
Signature · 2 lines
Regards,
Sudeep
#12 lore raw

PATCH v11 3/7 firmware: arm_rmm: Move RSI support out of arch/arm64

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 complete Realm Service Interface (RSI) implementation from arch/arm64 to drivers/firmware/arm_rmm. The RSI SMCCC definitions and command helpers are also moved to include/linux so they can be shared by architecture code and firmware or driver code. This also keeps the firmware interface outside architecture code, as requested [1].

[1] https://lore.kernel.org/all/agsNO9cc7H-b0H8L@willie-the-truck

---
 arch/arm64/Kconfig                            |  1 +
 arch/arm64/include/asm/io.h                   |  2 +-
 arch/arm64/include/asm/mem_encrypt.h          |  2 +-
 arch/arm64/include/asm/pgtable-prot.h         |  2 +-
 arch/arm64/include/asm/rsi.h                  | 70 -----------------
 arch/arm64/kernel/Makefile                    |  2 +-
 arch/arm64/kernel/setup.c                     |  2 +-
 arch/arm64/mm/init.c                          |  3 +-
 drivers/firmware/Kconfig                      |  1 +
 drivers/firmware/Makefile                     |  1 +
 drivers/firmware/arm_rmm/Kconfig              | 17 ++++
 drivers/firmware/arm_rmm/Makefile             |  2 +
 .../kernel => drivers/firmware/arm_rmm}/rsi.c |  2 +-
 drivers/virt/coco/arm-cca-guest/Kconfig       |  2 +-
 .../virt/coco/arm-cca-guest/arm-cca-guest.c   |  5 +-
 .../linux/arm-rsi-cmds.h                      | 77 +++++++++++++++++--
 .../linux/arm-smccc-rsi.h                     |  6 +-
 17 files changed, 108 insertions(+), 89 deletions(-)
 delete mode 100644 arch/arm64/include/asm/rsi.h
 create mode 100644 drivers/firmware/arm_rmm/Kconfig
 create mode 100644 drivers/firmware/arm_rmm/Makefile
 rename {arch/arm64/kernel => drivers/firmware/arm_rmm}/rsi.c (99%)
 rename arch/arm64/include/asm/rsi_cmds.h => include/linux/arm-rsi-cmds.h (69%)
 rename arch/arm64/include/asm/rsi_smc.h => include/linux/arm-smccc-rsi.h (98%)
arch/arm64/Kconfig +1 -0
index b5a51b0ef944..ff9565d3ffa5 100644
@@ -38,6 +38,7 @@ config ARM64
 	select ARCH_HAS_MEMBARRIER_SYNC_CORE
 	select ARCH_HAS_MEM_ENCRYPT
 	select ARCH_SUPPORTS_MSEAL_SYSTEM_MAPPINGS
+	select ARCH_SUPPORTS_RMM
 	select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS
 	select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
 	select ARCH_HAS_NONLEAF_PMD_YOUNG if ARM64_HAFT
arch/arm64/include/asm/io.h +1 -1
index 49a7002661a9..1620537f0332 100644
@@ -8,6 +8,7 @@
 #ifndef __ASM_IO_H
 #define __ASM_IO_H
 
+#include <linux/arm-rsi-cmds.h>
 #include <linux/types.h>
 #include <linux/pgtable.h>
 
@@ -17,7 +18,6 @@
 #include <asm/early_ioremap.h>
 #include <asm/alternative.h>
 #include <asm/cpufeature.h>
-#include <asm/rsi.h>
 
 /*
  * Generic IO read/write.  These perform native-endian accesses.
arch/arm64/include/asm/mem_encrypt.h +1 -1
index 636f45b4d8af..f03b9d7b83b4 100644
@@ -2,8 +2,8 @@
 #ifndef __ASM_MEM_ENCRYPT_H
 #define __ASM_MEM_ENCRYPT_H
 
+#include <linux/arm-rsi-cmds.h>
 #include <asm/hypervisor.h>
-#include <asm/rsi.h>
 
 struct device;
 
arch/arm64/include/asm/pgtable-prot.h +1 -1
index 09d7c00cf405..58e71e592175 100644
@@ -66,9 +66,9 @@
 
 #ifndef __ASSEMBLER__
 
+#include <linux/arm-rsi-cmds.h>
 #include <asm/cpufeature.h>
 #include <asm/pgtable-types.h>
-#include <asm/rsi.h>
 
 extern bool arm64_use_ng_mappings;
 extern unsigned long prot_ns_shared;
arch/arm64/include/asm/rsi.h deleted +0 -70

70 lines not on this page · raw message

arch/arm64/kernel/Makefile +1 -1
index d2690c3ec528..21fc3a3d25c9 100644
@@ -34,7 +34,7 @@ obj-y			:= debug-monitors.o entry.o irq.o fpsimd.o		\
 			   cpufeature.o alternative.o cacheinfo.o		\
 			   smp.o smp_spin_table.o topology.o smccc-call.o	\
 			   syscall.o proton-pack.o idle.o patching.o pi/	\
-			   rsi.o jump_label.o
+			   jump_label.o
 
 obj-$(CONFIG_COMPAT)			+= sys32.o signal32.o			\
 					   sys_compat.o
arch/arm64/kernel/setup.c +1 -1
index 29c6100f0c50..a707deba6ae7 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/arm-rsi-cmds.h>
 #include <linux/export.h>
 #include <linux/kernel.h>
 #include <linux/stddef.h>
@@ -43,7 +44,6 @@
 #include <asm/cpu_ops.h>
 #include <asm/kasan.h>
 #include <asm/numa.h>
-#include <asm/rsi.h>
 #include <asm/scs.h>
 #include <asm/sections.h>
 #include <asm/setup.h>
arch/arm64/mm/init.c +2 -1
index fbf215ecc7d0..2a8de20d2b44 100644
@@ -34,6 +34,8 @@
 #include <linux/acpi_iort.h>
 #include <linux/kmemleak.h>
 #include <linux/execmem.h>
+#include <linux/arm-rsi-cmds.h>
+
 
 #include <asm/boot.h>
 #include <asm/fixmap.h>
@@ -43,7 +45,6 @@
 #include <asm/kvm_host.h>
 #include <asm/memory.h>
 #include <asm/numa.h>
-#include <asm/rsi.h>
 #include <asm/sections.h>
 #include <asm/setup.h>
 #include <linux/sizes.h>
drivers/firmware/Kconfig +1 -0
index b7cc11e4fbfa..62660bf520a8 100644
@@ -310,5 +310,6 @@ source "drivers/firmware/samsung/Kconfig"
 source "drivers/firmware/smccc/Kconfig"
 source "drivers/firmware/tegra/Kconfig"
 source "drivers/firmware/xilinx/Kconfig"
+source "drivers/firmware/arm_rmm/Kconfig"
 
 endmenu
drivers/firmware/Makefile +1 -0
index be46f1e1dc77..196a650ccf02 100644
@@ -39,3 +39,4 @@ obj-y				+= samsung/
 obj-y				+= smccc/
 obj-y				+= tegra/
 obj-y				+= xilinx/
+obj-y				+= arm_rmm/
drivers/firmware/arm_rmm/Kconfig new file +17 -0
new file mode 100644
index 000000000000..e981e12fdbe6
@@ -0,0 +1,17 @@
+
+config ARCH_SUPPORTS_RMM
+	bool
+
+config ARM_RMM_RSI
+	bool "Realm Service Interface (RSI) Support"
+	depends on ARCH_SUPPORTS_RMM
+	default y
+	help
+	  Enable support for running Linux as a Realm guest under a Realm
+	  Management Monitor (RMM), as defined by the Arm Confidential
+	  Compute Architecture.
+
+	  The RMM exposes the Realm Service Interface (RSI) to Realm guests.
+	  Linux uses RSI to negotiate the interface version, obtain the Realm
+	  configuration, and manage the protected or shared state of guest
+	  memory.
drivers/firmware/arm_rmm/Makefile new file +2 -0
new file mode 100644
index 000000000000..3708b37a9aaf
@@ -0,0 +1,2 @@
+
+obj-$(CONFIG_ARM_RMM_RSI)	= rsi.o
drivers/firmware/arm_rmm/rsi.c renamed from arch/arm64/kernel/rsi.c +1 -1
similarity index 99%
rename from arch/arm64/kernel/rsi.c
rename to drivers/firmware/arm_rmm/rsi.c
index 25ca75ce1a4d..8e716f1c1e31 100644
@@ -8,11 +8,11 @@
 #include <linux/psci.h>
 #include <linux/swiotlb.h>
 #include <linux/platform_device.h>
+#include <linux/arm-rsi-cmds.h>
 
 #include <asm/io.h>
 #include <asm/mem_encrypt.h>
 #include <asm/pgtable.h>
-#include <asm/rsi.h>
 
 static struct realm_config config;
 
drivers/virt/coco/arm-cca-guest/Kconfig +1 -1
index 3f0f013f03f1..2582ebb36922 100644
@@ -1,6 +1,6 @@
 config ARM_CCA_GUEST
 	tristate "Arm CCA Guest driver"
-	depends on ARM64
+	depends on ARM_RMM_RSI
 	select TSM_REPORTS
 	help
 	  The driver provides userspace interface to request and
drivers/virt/coco/arm-cca-guest/arm-cca-guest.c +2 -3
index 0eeddd1ff05b..b741643d1364 100644
@@ -3,7 +3,8 @@
  * Copyright (C) 2023 ARM Ltd.
  */
 
-#include <linux/arm-smccc.h>
+#include <linux/arm-rsi-cmds.h>
+#include <linux/arm-smccc-rsi.h>
 #include <linux/cc_platform.h>
 #include <linux/kernel.h>
 #include <linux/device-id/platform.h>
@@ -12,8 +13,6 @@
 #include <linux/tsm.h>
 #include <linux/types.h>
 
-#include <asm/rsi.h>
-
 /**
  * struct arm_cca_token_info - a descriptor for the token buffer.
  * @granule:		PA of the granule to which the token will be written
include/linux/arm-rsi-cmds.h renamed from arch/arm64/include/asm/rsi_cmds.h +72 -5

96 lines not on this page · raw message

include/linux/arm-smccc-rsi.h renamed from arch/arm64/include/asm/rsi_smc.h +3 -3
similarity index 98%
rename from arch/arm64/include/asm/rsi_smc.h
rename to include/linux/arm-smccc-rsi.h
index e19253f96c94..fddb77986f70 100644
@@ -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
maintainer Reviewed-by on v11 3/7
#13 lore raw

Re: [PATCH v11 3/7] firmware: arm_rmm: Move RSI support out of arch/arm64

Quoted 11 lines · 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 complete Realm Service Interface (RSI) implementation from arch/arm64 to drivers/firmware/arm_rmm. The RSI SMCCC definitions and command helpers are also moved to include/linux so they can be shared by architecture code and firmware or driver code. This also keeps the firmware interface outside architecture code, as requested [1].

Quoted 5 lines

[1] https://lore.kernel.org/all/agsNO9cc7H-b0H8L@willie-the-truck

The patch looks alright but always wondered why this and the following two patches are not first in the series. They look like some almost independent cleanup randomly in the middle of the SMCCC bus series.

Otherwise,

Reviewed-by on v11 3/7
#14 lore raw

Re: [PATCH v11 3/7] firmware: arm_rmm: Move RSI support out of arch/arm64

In reply to Aneesh Kumar K.V (Arm)
Quoted 11 lines · On Mon, 14 Sep 2026 11:35:07 +0530 "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 complete Realm Service Interface (RSI) implementation from arch/arm64 to drivers/firmware/arm_rmm. The RSI SMCCC definitions and command helpers are also moved to include/linux so they can be shared by architecture code and firmware or driver code. This also keeps the firmware interface outside architecture code, as requested [1].

Quoted 5 lines

[1] https://lore.kernel.org/all/agsNO9cc7H-b0H8L@willie-the-truck

Moving the code makes sense and indeed that is what the patch does so

Trivial gripe about the original code inline.

Quoted 8 lines
include/linux/arm-rsi-cmds.h renamed from arch/arm64/include/asm/rsi_cmds.h +0 -0
similarity index 69%
rename from arch/arm64/include/asm/rsi_cmds.h
rename to include/linux/arm-rsi-cmds.h
index c1fab41f671e..9e8a8c189ca1 100644
 

include/linux/arm-rsi-cmds.h static inline long rsi_set_addr_range_state(phys_addr_t start, · line 121

Quoted 10 lines
include/linux/arm-rsi-cmds.h renamed from arch/arm64/include/asm/rsi_cmds.h +9 -0
 
+static inline int rsi_set_memory_range(phys_addr_t start, phys_addr_t end,
+				       enum ripas state, unsigned long flags)
+{
+	unsigned long ret;
+	phys_addr_t top;
+
+	while (start != end) {
+		ret = rsi_set_addr_range_state(start, end, state, flags, &top);
+		if (ret || top < start || top > end)

Obviously this is just code movement, but why eat the error value that rsi_set_addr_range_state() returns?

Quoted 6 lines
include/linux/arm-rsi-cmds.h renamed from arch/arm64/include/asm/rsi_cmds.h +6 -0
+			return -EINVAL;
+		start = top;
+	}
+
+	return 0;
+}
maintainer
#15 lore raw

Re: [PATCH v11 3/7] firmware: arm_rmm: Move RSI support out of arch/arm64

In reply to Aneesh Kumar K.V (Arm)
Quoted 33 lines · 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 complete Realm Service Interface (RSI) implementation from arch/arm64 to drivers/firmware/arm_rmm. The RSI SMCCC definitions and command helpers are also moved to include/linux so they can be shared by architecture code and firmware or driver code. This also keeps the firmware interface outside architecture code, as requested [1].

[1] https://lore.kernel.org/all/agsNO9cc7H-b0H8L@willie-the-truck

---
 arch/arm64/Kconfig                            |  1 +
 arch/arm64/include/asm/io.h                   |  2 +-
 arch/arm64/include/asm/mem_encrypt.h          |  2 +-
 arch/arm64/include/asm/pgtable-prot.h         |  2 +-
 arch/arm64/include/asm/rsi.h                  | 70 -----------------
 arch/arm64/kernel/Makefile                    |  2 +-
 arch/arm64/kernel/setup.c                     |  2 +-
 arch/arm64/mm/init.c                          |  3 +-
 drivers/firmware/Kconfig                      |  1 +
 drivers/firmware/Makefile                     |  1 +
 drivers/firmware/arm_rmm/Kconfig              | 17 ++++
 drivers/firmware/arm_rmm/Makefile             |  2 +
 .../kernel => drivers/firmware/arm_rmm}/rsi.c |  2 +-
 drivers/virt/coco/arm-cca-guest/Kconfig       |  2 +-
 .../virt/coco/arm-cca-guest/arm-cca-guest.c   |  5 +-
 .../linux/arm-rsi-cmds.h                      | 77 +++++++++++++++++--
Quoted 8 lines
 .../linux/arm-smccc-rsi.h                     |  6 +-
 17 files changed, 108 insertions(+), 89 deletions(-)
 delete mode 100644 arch/arm64/include/asm/rsi.h
 create mode 100644 drivers/firmware/arm_rmm/Kconfig
 create mode 100644 drivers/firmware/arm_rmm/Makefile
 rename {arch/arm64/kernel => drivers/firmware/arm_rmm}/rsi.c (99%)
 rename arch/arm64/include/asm/rsi_cmds.h => include/linux/arm-rsi-cmds.h (69%)
 rename arch/arm64/include/asm/rsi_smc.h => include/linux/arm-smccc-rsi.h (98%)

BTW, can you also add the new files under the ARM64 PORT in MAINTAINERS, similar to arm-cca-guest?

Thanks.

Signature · 1 line
Catalin
#16 lore raw

PATCH v11 4/7 arm64: realm: Move Realm memory encryption ops to RSI code

In reply to Aneesh Kumar K.V (Arm)

Realm memory encryption callbacks are CCA-specific. Keep the Realm callback registration with the RSI initialization code instead of pageattr.c, which only needs to provide the low-level page-attribute transition helper.

Export __set_memory_enc_dec() within arm64 so the RSI code can wrap it with the Realm-specific encrypt/decrypt callbacks and warning policy.

No functional changes in this patch.

---
 arch/arm64/include/asm/mem_encrypt.h |  3 +--
 arch/arm64/mm/pageattr.c             | 38 +---------------------------
 drivers/firmware/arm_rmm/rsi.c       | 34 +++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 39 deletions(-)
arch/arm64/include/asm/mem_encrypt.h +1 -2
index f03b9d7b83b4..ef8b8463e52b 100644
@@ -16,8 +16,7 @@ int arm64_mem_crypt_ops_register(const struct arm64_mem_crypt_ops *ops);
 
 int set_memory_encrypted(unsigned long addr, int numpages);
 int set_memory_decrypted(unsigned long addr, int numpages);
-
-int realm_register_memory_enc_ops(void);
+int __set_memory_enc_dec(unsigned long addr, int numpages, bool encrypt);
 
 static inline bool force_dma_unencrypted(struct device *dev)
 {
arch/arm64/mm/pageattr.c +1 -37
index bbe98ac9ad8c..14b2a3801f40 100644
@@ -275,9 +275,7 @@ int set_direct_map_default_noflush(struct page *page)
 				 PAGE_SIZE, set_mask, clear_mask);
 }
 
-static int __set_memory_enc_dec(unsigned long addr,
-				int numpages,
-				bool encrypt)
+int __set_memory_enc_dec(unsigned long addr, int numpages, bool encrypt)
 {
 	unsigned long set_prot = 0, clear_prot = 0;
 	phys_addr_t start, end;
@@ -321,40 +319,6 @@ static int __set_memory_enc_dec(unsigned long addr,
 				      __pgprot(PTE_PRESENT_INVALID));
 }
 
-static int realm_set_memory_encrypted(unsigned long addr, int numpages)
-{
-	int ret = __set_memory_enc_dec(addr, numpages, true);
-
-	/*
-	 * If the request to change state fails, then the only sensible cause
-	 * of action for the caller is to leak the memory
-	 */
-	WARN(ret, "Failed to encrypt memory, %d pages will be leaked",
-	     numpages);
-
-	return ret;
-}
-
-static int realm_set_memory_decrypted(unsigned long addr, int numpages)
-{
-	int ret = __set_memory_enc_dec(addr, numpages, false);
-
-	WARN(ret, "Failed to decrypt memory, %d pages will be leaked",
-	     numpages);
-
-	return ret;
-}
-
-static const struct arm64_mem_crypt_ops realm_crypt_ops = {
-	.encrypt = realm_set_memory_encrypted,
-	.decrypt = realm_set_memory_decrypted,
-};
-
-int realm_register_memory_enc_ops(void)
-{
-	return arm64_mem_crypt_ops_register(&realm_crypt_ops);
-}
-
 int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid)
 {
 	unsigned long addr = (unsigned long)page_address(page);
drivers/firmware/arm_rmm/rsi.c +34 -0
index 8e716f1c1e31..ada139d0e344 100644
@@ -127,6 +127,40 @@ static int realm_ioremap_hook(phys_addr_t phys, size_t size, pgprot_t *prot)
 	return 0;
 }
 
+static int realm_set_memory_encrypted(unsigned long addr, int numpages)
+{
+	int ret = __set_memory_enc_dec(addr, numpages, true);
+
+	/*
+	 * If the request to change state fails, then the only sensible cause
+	 * of action for the caller is to leak the memory
+	 */
+	WARN(ret, "Failed to encrypt memory, %d pages will be leaked",
+	     numpages);
+
+	return ret;
+}
+
+static int realm_set_memory_decrypted(unsigned long addr, int numpages)
+{
+	int ret = __set_memory_enc_dec(addr, numpages, false);
+
+	WARN(ret, "Failed to decrypt memory, %d pages will be leaked",
+	     numpages);
+
+	return ret;
+}
+
+static const struct arm64_mem_crypt_ops realm_crypt_ops = {
+	.encrypt = realm_set_memory_encrypted,
+	.decrypt = realm_set_memory_decrypted,
+};
+
+static int realm_register_memory_enc_ops(void)
+{
+	return arm64_mem_crypt_ops_register(&realm_crypt_ops);
+}
+
 void __init arm64_rsi_init(void)
 {
 	if (arm_smccc_1_1_get_conduit() != SMCCC_CONDUIT_SMC)
Signature · 1 line
2.43.0
maintainer Reviewed-by on v11 4/7
#17 lore raw

Re: [PATCH v11 4/7] arm64: realm: Move Realm memory encryption ops to RSI code

Quoted 6 lines · Aneesh Kumar K.V (Arm)

Realm memory encryption callbacks are CCA-specific. Keep the Realm callback registration with the RSI initialization code instead of pageattr.c, which only needs to provide the low-level page-attribute transition helper.

Export __set_memory_enc_dec() within arm64 so the RSI code can wrap it with the Realm-specific encrypt/decrypt callbacks and warning policy.

Suzuki commented on v9 I think not to expose this function but I don't see a nice way around since we now moved the realm_crypt_ops out of pageattr.c (so we'd have to export something out of that file).

#18 lore raw

Re: [PATCH v11 4/7] arm64: realm: Move Realm memory encryption ops to RSI code

Quoted 11 lines · Catalin Marinas
Quoted 6 lines · Aneesh Kumar K.V (Arm)

Realm memory encryption callbacks are CCA-specific. Keep the Realm callback registration with the RSI initialization code instead of pageattr.c, which only needs to provide the low-level page-attribute transition helper.

Export __set_memory_enc_dec() within arm64 so the RSI code can wrap it with the Realm-specific encrypt/decrypt callbacks and warning policy.

Suzuki commented on v9 I think not to expose this function but I don't see a nice way around since we now moved the realm_crypt_ops out of pageattr.c (so we'd have to export something out of that file).

Yep, you are right. Thats the conclusion we reached to.

Quoted 2 lines

Thanks
Suzuki

Reviewed-by on v11 4/7
#19 lore raw

Re: [PATCH v11 4/7] arm64: realm: Move Realm memory encryption ops to RSI code

In reply to Aneesh Kumar K.V (Arm)
Quoted 11 lines · Aneesh Kumar K.V (Arm)

Realm memory encryption callbacks are CCA-specific. Keep the Realm callback registration with the RSI initialization code instead of pageattr.c, which only needs to provide the low-level page-attribute transition helper.

Export __set_memory_enc_dec() within arm64 so the RSI code can wrap it with the Realm-specific encrypt/decrypt callbacks and warning policy.

No functional changes in this patch.

#20 lore raw

PATCH v11 5/7 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 main.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 ++
 drivers/virt/coco/arm-cca-guest/{arm-cca-guest.c => main.c} | 6 +++---
 2 files changed, 5 insertions(+), 3 deletions(-)
 rename drivers/virt/coco/arm-cca-guest/{arm-cca-guest.c => main.c} (97%)
drivers/virt/coco/arm-cca-guest/Makefile +2 -0
index 69eeba08e98a..7564f4fcc4a4 100644
@@ -1,2 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_ARM_CCA_GUEST) += arm-cca-guest.o
+
+arm-cca-guest-y += main.o
drivers/virt/coco/arm-cca-guest/main.c renamed from drivers/virt/coco/arm-cca-guest/arm-cca-guest.c +3 -3
similarity index 97%
rename from drivers/virt/coco/arm-cca-guest/arm-cca-guest.c
rename to drivers/virt/coco/arm-cca-guest/main.c
index b741643d1364..80659f0885e9 100644
@@ -156,7 +156,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,
 };
@@ -177,7 +177,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);
 
@@ -191,7 +191,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
maintainer Reviewed-by on v11 5/7
#21 lore raw

Re: [PATCH v11 5/7] virt: coco: arm-cca-guest: Rename TSM report source file

Quoted 10 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.c to main.c and build it as an object of the arm-cca-guest module. This leaves room for the module to grow additional source files.

Reviewed-by on v11 5/7
#22 lore raw

Re: [PATCH v11 5/7] virt: coco: arm-cca-guest: Rename TSM report source file

In reply to Aneesh Kumar K.V (Arm)
Quoted 10 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.c to main.c and build it as an object of the arm-cca-guest module. This leaves room for the module to grow additional source files.

#23 lore raw

Re: [PATCH v11 5/7] virt: coco: arm-cca-guest: Rename TSM report source file

In reply to Aneesh Kumar K.V (Arm)
Quoted 7 lines · On Mon, 14 Sep 2026 11:35:09 +0530 "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 main.c and build it as an object of the arm-cca-guest module. This leaves room for the module to grow additional source files.

Should probably mention the structure renames that you have in here. I wasn't expecting to see anything other than build system changes and a file rename.

Jonathan

Quoted 52 lines
---
 drivers/virt/coco/arm-cca-guest/Makefile                    | 2 ++
 drivers/virt/coco/arm-cca-guest/{arm-cca-guest.c => main.c} | 6 +++---
 2 files changed, 5 insertions(+), 3 deletions(-)
 rename drivers/virt/coco/arm-cca-guest/{arm-cca-guest.c => main.c} (97%)
drivers/virt/coco/arm-cca-guest/Makefile +2 -0
index 69eeba08e98a..7564f4fcc4a4 100644
@@ -1,2 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_ARM_CCA_GUEST) += arm-cca-guest.o
+
+arm-cca-guest-y += main.o
drivers/virt/coco/arm-cca-guest/main.c renamed from drivers/virt/coco/arm-cca-guest/arm-cca-guest.c +3 -3
similarity index 97%
rename from drivers/virt/coco/arm-cca-guest/arm-cca-guest.c
rename to drivers/virt/coco/arm-cca-guest/main.c
index b741643d1364..80659f0885e9 100644
@@ -156,7 +156,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,
 };
@@ -177,7 +177,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);
 
@@ -191,7 +191,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);
 
#24 lore raw

PATCH v11 6/7 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.

---
 drivers/firmware/arm_rmm/rsi.c          |  2 +-
 drivers/firmware/smccc/smccc.c          |  6 ++++
 drivers/virt/coco/arm-cca-guest/Kconfig |  1 +
 drivers/virt/coco/arm-cca-guest/main.c  | 44 +++++++++++--------------
 include/linux/arm-rsi-cmds.h            |  1 -
 5 files changed, 27 insertions(+), 27 deletions(-)
drivers/firmware/arm_rmm/rsi.c +1 -1
index ada139d0e344..2dd69febedbd 100644
@@ -183,7 +183,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 +6 -0
index 756c79204e44..e1b16a09a265 100644
@@ -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,11 @@ 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    = "arm-rsi",
+	},
 };
 
 static bool __init smccc_probe_smccc_device(const struct smccc_device_info *smccc_dev)
drivers/virt/coco/arm-cca-guest/Kconfig +1 -0
index 2582ebb36922..0d4ce72e2d86 100644
@@ -1,6 +1,7 @@
 config ARM_CCA_GUEST
 	tristate "Arm CCA Guest driver"
 	depends on ARM_RMM_RSI
+	depends on HAVE_ARM_SMCCC_DISCOVERY
 	select TSM_REPORTS
 	help
 	  The driver provides userspace interface to request and
drivers/virt/coco/arm-cca-guest/main.c +19 -25

71 lines not on this page · raw message

include/linux/arm-rsi-cmds.h +0 -1
index 9e8a8c189ca1..3f7a6a833993 100644
@@ -11,7 +11,6 @@
 #include <linux/string.h>
 #include <asm/memory.h>
 
-#define RSI_PDEV_NAME "arm-cca-dev"
 #ifdef CONFIG_ARM_RMM_RSI
 DECLARE_STATIC_KEY_FALSE(rsi_present);
 
Signature · 1 line
2.43.0
maintainer Reviewed-by on v11 6/7
#25 lore raw

Re: [PATCH v11 6/7] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device

Quoted 7 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

Nit: "arm-rsi". Or did you mean to actually user "arm-rsi-dev" below?

Quoted 9 lines

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.

[...]

drivers/firmware/smccc/smccc.c static const struct smccc_device_info smccc_devices[] __initconst = { · line 103

Quoted 10 lines
drivers/firmware/smccc/smccc.c +5 -0
@@ -94,6 +95,11 @@ 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    = "arm-rsi",
+	},
 };
Reviewed-by on v11 6/7
#26 lore raw

Re: [PATCH v11 6/7] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device

In reply to Aneesh Kumar K.V (Arm)
Quoted 11 lines · On Mon, 14 Sep 2026 11:35:10 +0530 "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.

One minor thing inline.

drivers/virt/coco/arm-cca-guest/main.c

Quoted 4 lines
drivers/virt/coco/arm-cca-guest/main.c +0 -0
index 80659f0885e9..7b1fa008a8f4 100644

d)

drivers/virt/coco/arm-cca-guest/main.c static int __init arm_cca_guest_init(void) · line 175

Quoted 13 lines
drivers/virt/coco/arm-cca-guest/main.c +4 -2
+static int cca_tsm_probe(struct arm_smccc_device *sdev)
 {
 	int ret;
@@ -178,30 +170,32 @@ 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 dev_err_probe();

Having that on one line is one of the nicest things about dev_err_probe()

Quoted 6 lines
drivers/virt/coco/arm-cca-guest/main.c +2 -2
+	}
 
-	return ret;
+	return 0;
 }
-module_init(arm_cca_guest_init);
Reviewed-by on v11 6/7
#27 lore raw

Re: [PATCH v11 6/7] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device

In reply to Aneesh Kumar K.V (Arm)
Quoted 5 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.

Quoted 7 lines

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.

[...]

Signature · 1 line
Jason
maintainer Reviewed-by on v11 6/7
#28 lore raw

Re: [PATCH v11 6/7] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device

In reply to Aneesh Kumar K.V (Arm)
Quoted 17 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.

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.

---

[...]

Quoted 1 line
 drivers/firmware/smccc/smccc.c          |  6 ++++
Signature · 2 lines
Regards,
Sudeep
#29 lore raw

PATCH v11 7/7 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 +++++
 drivers/firmware/arm_rmm/rsi.c               | 42 +++++++++++++++-----
 2 files changed, 42 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-firmware-cca
Documentation/ABI/testing/sysfs-firmware-cca new file +10 -0
new file mode 100644
index 000000000000..bf177d636b92
@@ -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
drivers/firmware/arm_rmm/rsi.c +32 -10

61 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer Reviewed-by on v11 7/7
#30 lore raw

Re: [PATCH v11 7/7] coco: guest: arm64: Replace dummy CCA device with sysfs ABI

Quoted 1 line · Aneesh Kumar K.V (Arm)

The SMCCC firmware driver now creates the arm-smccc platform device and

Nit: we now have devices on an arm_smccc bus, so this first line doesn't make sense.

Quoted 8 lines

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.

Well, removing it would break the ABI even if you replace it with something else. But I think we agreed it wasn't great for systemd to depend on the old interface either. Assuming systemd can be fixed (and the fix backported) and no production deployments are affected, I'm fine with this.

Reviewed-by on v11 7/7
#31 lore raw

Re: [PATCH v11 7/7] coco: guest: arm64: Replace dummy CCA device with sysfs ABI

In reply to Aneesh Kumar K.V (Arm)
Quoted 16 lines · On Mon, 14 Sep 2026 11:35:11 +0530 "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.

Quoted 3 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.

My gut feeling would be to split this in to the new stuff in first patch and the removal in second. That would make a revert simpler should it turn out that someone has userspace that will actually notice and can't be easily updated. I'm not that bothered though as it will be your problem not mine (hopefully!) ;)

Quoted 2 lines

[1] https://lore.kernel.org/all/[email protected]

Could make that a link tag.

Quoted 2 lines

One trivial thing inline.

Quoted 26 lines
---
 Documentation/ABI/testing/sysfs-firmware-cca | 10 +++++
 drivers/firmware/arm_rmm/rsi.c               | 42 +++++++++++++++-----
 2 files changed, 42 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-firmware-cca
Documentation/ABI/testing/sysfs-firmware-cca new file +10 -0
new file mode 100644
index 000000000000..bf177d636b92
@@ -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
drivers/firmware/arm_rmm/rsi.c +0 -0
index 2dd69febedbd..52f40256bd78 100644

drivers/firmware/arm_rmm/rsi.c void __init arm64_rsi_init(void) · line 199

Quoted 4 lines
drivers/firmware/arm_rmm/rsi.c +3 -0
 
+static const struct attribute *cca_realm_attrs[] = {
+	&cca_realm_guest.attr,
+	NULL,

Given we don't want anything added after this, no comma ideally.

Quoted 1 line

};

maintainer
#32 lore raw

Re: [PATCH v11 7/7] coco: guest: arm64: Replace dummy CCA device with sysfs ABI

In reply to Aneesh Kumar K.V (Arm)
Quoted 6 lines · Aneesh Kumar K.V (Arm)
Documentation/ABI/testing/sysfs-firmware-cca new file +0 -0
new file mode 100644
index 000000000000..bf177d636b92

Documentation/ABI/testing/sysfs-firmware-cca line 10

Quoted 10 lines
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

Does this file ever read as 0? It is created only if rsi_present and always reads as 1. That's fine by me but we shouldn't document 0 as a value. More like if present, it always reads 1 and RSI is present.

drivers/firmware/arm_rmm/rsi.c line 10

Quoted 7 lines
drivers/firmware/arm_rmm/rsi.c +0 -0
index 2dd69febedbd..52f40256bd78 100644
@@ -9,12 +9,15 @@
 #include <linux/swiotlb.h>
 #include <linux/platform_device.h>

Nit: I think we can drop this include.

Signature · 1 line
Catalin
#33 lore raw

Re: [PATCH v11 7/7] coco: guest: arm64: Replace dummy CCA device with sysfs ABI

Quoted 13 lines · Catalin Marinas
Quoted 12 lines · Aneesh Kumar K.V (Arm)
Documentation/ABI/testing/sysfs-firmware-cca new file +6 -0
new file mode 100644
index 000000000000..bf177d636b92
@@ -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.
+
Quoted 9 lines

Documentation/ABI/testing/sysfs-firmware-cca line 10

Quoted 4 lines
Documentation/ABI/testing/sysfs-firmware-cca new file +4 -0
+		The value is one of:
+
+		0: the kernel is not running as a Realm guest
+		1: the kernel is running as a Realm guest

Does this file ever read as 0? It is created only if rsi_present and always reads as 1. That's fine by me but we shouldn't document 0 as a value. More like if present, it always reads 1 and RSI is present.

For now, that is correct. However, the two checks could diverge if Realm guest support is enabled only after additional checks, such as version compatibility.

In that case, is_realm_world() and static_branch_unlikely(&rsi_present) could return different results.

I assume that any error when reading the file, including -ENOENT, can be treated as indicating that the kernel is not running as a Realm guest. Do we need to document that?

-aneesh

maintainer
#34 lore raw

Re: [PATCH v11 7/7] coco: guest: arm64: Replace dummy CCA device with sysfs ABI

Quoted 24 lines · Aneesh Kumar K.V
Quoted 13 lines · Catalin Marinas
Quoted 12 lines · Aneesh Kumar K.V (Arm)
Documentation/ABI/testing/sysfs-firmware-cca new file +6 -0
new file mode 100644
index 000000000000..bf177d636b92
@@ -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.
+
Quoted 9 lines

Documentation/ABI/testing/sysfs-firmware-cca line 10

Quoted 4 lines
Documentation/ABI/testing/sysfs-firmware-cca new file +4 -0
+		The value is one of:
+
+		0: the kernel is not running as a Realm guest
+		1: the kernel is running as a Realm guest

Does this file ever read as 0? It is created only if rsi_present and always reads as 1. That's fine by me but we shouldn't document 0 as a value. More like if present, it always reads 1 and RSI is present.

Quoted 6 lines

For now, that is correct. However, the two checks could diverge if Realm guest support is enabled only after additional checks, such as version compatibility.

In that case, is_realm_world() and static_branch_unlikely(&rsi_present) could return different results.

They can indeed diverge in either direction but would we ever end up reporting 0? I also think we should gate realm_sysfs_init() on is_realm_world() rather than rsi_present. I know it's the same at the moment but it would read better if we just did:

	if (!is_realm_world())
		return 0;

and realm_guest_show() just return 1.

The file description could be (without any values 0 or 1):

Description: Read-only. Present only when the kernel is running as an
Arm Confidential Compute Architecture (CCA) Realm guest, in which case it reads 1. If the file does not exist, the kernel is not running as a Realm guest.

or something along these lines, no description of value 0 (well, you could say if "if the file does not exist or reads 0..." but only if we envisage a use-case for this.

Signature · 1 line
Catalin