Switch Arm SMCCC firmware services to an SMCCC bus
Subsystems (5)
v9 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 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
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 | 18 ++
drivers/firmware/arm_rmm/Makefile | 2 +
.../kernel => drivers/firmware/arm_rmm}/rsi.c | 75 ++++++--
drivers/firmware/smccc/Makefile | 2 +-
drivers/firmware/smccc/bus.c | 166 ++++++++++++++++++
drivers/firmware/smccc/smccc.c | 65 ++++++-
drivers/virt/coco/arm-cca-guest/Kconfig | 3 +-
drivers/virt/coco/arm-cca-guest/Makefile | 2 +
.../{arm-cca-guest.c => arm-cca.c} | 65 ++++---
.../linux/arm-rsi-cmds.h | 76 +++++++-
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 +
31 files changed, 541 insertions(+), 191 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 (71%)
create mode 100644 drivers/firmware/smccc/bus.c
rename drivers/virt/coco/arm-cca-guest/{arm-cca-guest.c => arm-cca.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 (97%)
create mode 100644 include/linux/device-id/arm_smccc.hbase-commit: df386fe6be46dce460d9366066a277ec8b45a01c
Signature · 1 line
2.43.0
PATCH v9 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 | 166 ++++++++++++++++++++++++++++ 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, 244 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 +166 -0
166 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
PATCH v9 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 | 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 v9 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 | 18 +++++
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, 109 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -322,5 +322,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
@@ -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 +18 -0
@@ -0,0 +1,18 @@ + +config ARCH_SUPPORTS_RMM + bool + +config ARM_RMM + bool "Realm Management Monitor (RMM) Support" + depends on ARCH_SUPPORTS_RMM + default y + help + Support the Realm Management Monitor (RMM) on Arm systems that + implement the Realm Management Extension (RME), as defined by the + Arm Confidential Compute Architecture. + + The RMM provides the Realm Management Interface (RMI) for use by + the Normal World host and the Realm Service Interface (RSI) for + use by Realm guests. The RSI is used to negotiate the RSI version + and Realm configuration with the RMM and manage the protected + state of memory.
drivers/firmware/arm_rmm/Makefile new file +2 -0
@@ -0,0 +1,2 @@ + +obj-$(CONFIG_ARM_RMM) = rsi.o
drivers/firmware/arm_rmm/rsi.c renamed from arch/arm64/kernel/rsi.c +1 -1
@@ -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
@@ -1,6 +1,6 @@ config ARM_CCA_GUEST tristate "Arm CCA Guest driver" - depends on ARM64 + depends on ARM_RMM select TSM_REPORTS help The driver provides userspace interface to request and
drivers/virt/coco/arm-cca-guest/arm-cca-guest.c +2 -3
@@ -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
@@ -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 v9 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
@@ -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
@@ -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
@@ -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
PATCH v9 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 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
@@ -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
PATCH v9 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 | 7 +++ drivers/virt/coco/arm-cca-guest/Kconfig | 1 + drivers/virt/coco/arm-cca-guest/arm-cca.c | 56 +++++++++++------------ include/linux/arm-rsi-cmds.h | 1 - include/linux/arm-smccc-rsi.h | 2 + 6 files changed, 39 insertions(+), 30 deletions(-)
drivers/firmware/arm_rmm/rsi.c +1 -1
@@ -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 +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 ARM_RMM + 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-rsi-cmds.h +0 -1
@@ -11,7 +11,6 @@#include <linux/string.h> #include <asm/memory.h> -#define RSI_PDEV_NAME "arm-cca-dev"#ifdef CONFIG_ARM_RMM DECLARE_STATIC_KEY_FALSE (rsi_present);
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
PATCH v9 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 | 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
drivers/firmware/arm_rmm/rsi.c +29 -10
@@ -9,12 +9,15 @@#include <linux/swiotlb.h> #include <linux/platform_device.h> #include <linux/arm-rsi-cmds.h> +#include <linux/kobject.h> +#include <linux/sysfs.h> #include <asm/io.h> #include <asm/mem_encrypt.h> #include <asm/pgtable.h> static struct realm_config config; +static struct kobject *cca_kobj;unsigned long prot_ns_shared;EXPORT_SYMBOL (prot_ns_shared);
@@ -182,17 +185,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 ; + + ret =sysfs_create_files (cca_kobj, cca_realm_attrs); +if (!ret) +return 0 ; -arch_initcall (arm64_create_dummy_rsi_dev) +kobject_put (cca_kobj); +return ret; +} +device_initcall (realm_sysfs_init);
Signature · 1 line
2.43.0
Catalin Marinas
maintainerQuoted 3 lines · Aneesh Kumar K.V (Arm)
Changes from v8:
https://lore.kernel.org/all/[email protected]
* Rebase onto the arm64 for-next/core branch.
Was there a dependency on anything in for-next/core? We normally apply series on their own branch on top of the vanilla kernel (e.g. 7.2-rc3) and merge everything together in for-next/core. We (and many other maintainers) strongly prefer series posted on top of an -rc kernel (typically -rc1 to -rc3) unless there's a dependency on a different branch. Never based on -next or -next like branches (which is what for-next/core is, as the name implies).
Quoted 1 line
* Move the RSI code from
arch/arm64todrivers/firmware/arm_rmmin patch 3.
Thanks for this.
Signature · 1 line
Catalin
Catalin Marinas
maintainerRe: [PATCH v9 2/7] firmware: hwrng: arm_smccc_trng: Register as an SMCCC device
In reply to Aneesh Kumar K.V (Arm)+ Herbert, Olivia for the drivers/char/hw_random/ changes
Quoted 5 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.
Quoted 7 lines
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_trngplatform-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.
This looks fine to me, autoload still works unless we mismatch old modules with newer kernel. It's on the 'arm_smccc' bus rather than 'platform'.
Quoted 179 lines
Tested-by Andre Przywara <[email protected]>Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>--- 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@@ -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,55 @@ 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; + +arm_smccc_1_1_invoke (smccc_dev->func_id, &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); +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
Catalin Marinas
maintainerRe: [PATCH v9 3/7] firmware: arm_rmm: Move RSI support out of arch/arm64
In reply to Aneesh Kumar K.V (Arm)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/smcccand the Arm CCA guest driver.Move the complete Realm Service Interface (RSI) implementation from
arch/arm64todrivers/firmware/arm_rmm. The RSI SMCCC definitions and command helpers are also moved toinclude/linuxso 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 3 lines
[1] https://lore.kernel.org/all/agsNO9cc7H-b0H8L@willie-the-truck
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>
I haven't checked but Sashiko has some points that it may break the build on other architectures with COMPILE_TEST.
https://sashiko.dev/#/patchset/[email protected]
(for some reason I get error 502 above; hopefully it's temporary)
Signature · 1 line
Catalin
Quoted 5 lines · Catalin Marinas
Quoted 3 lines · Aneesh Kumar K.V (Arm)
Changes from v8:
https://lore.kernel.org/all/[email protected]
* Rebase onto the arm64 for-next/core branch.
Quoted 8 lines
Was there a dependency on anything in for-next/core? We normally apply series on their own branch on top of the vanilla kernel (e.g. 7.2-rc3) and merge everything together in for-next/core. We (and many other maintainers) strongly prefer series posted on top of an -rc kernel (typically -rc1 to -rc3) unless there's a dependency on a different branch. Never based on -next or -next like branches (which is what for-next/core is, as the name implies).
The reason is that these two patches create conflicts. Since this series involves file movement, resolving those conflicts was not straightforward. Therefore, I rebased the series on top of both of the following commits:
commit 24f55f511b9e ("virt: arm-cca-guest: use migrate_disable() for attestation token requests") commit e62decaf98e7 ("arm64/coco: Add pKVM as a CC platform")
-aneesh
Re: [PATCH v9 3/7] firmware: arm_rmm: Move RSI support out of arch/arm64
In reply to Catalin MarinasQuoted 14 lines · Catalin Marinas
Quoted 13 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/smcccand the Arm CCA guest driver.Move the complete Realm Service Interface (RSI) implementation from
arch/arm64todrivers/firmware/arm_rmm. The RSI SMCCC definitions and command helpers are also moved toinclude/linuxso 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
Quoted 9 lines
Quoted 1 line
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>I haven't checked but Sashiko has some points that it may break the build on other architectures with
COMPILE_TEST.https://sashiko.dev/#/patchset/[email protected]
(for some reason I get error 502 above; hopefully it's temporary)
Below is the sashiko output
Quoted 5 lines
include/linux/arm-rsi-cmds.h static inline unsigned long rsi_attestation_token_continue(phys_addr_t granule, · line 240
Quoted 2 lines
include/linux/arm-rsi-cmds.h renamed from arch/arm64/include/asm/rsi_cmds.h +1
-1-#endif /* __ASM_RSI_CMDS_H */ +#endif /* __LINUX_ARM_RSI_CMDS_H_ */ Now that this header is moved to
include/linux/to be shared by cross architecture code, will it break non-ARM64 builds?
Looking atrsi_attestation_token_init()further up in this file:
Quoted 8 lines
struct arm_smccc_1_2_regs regs; ... arm_smccc_1_2_smc(&args.regs, &args.regs);Both struct
arm_smccc_1_2_regsandarm_smccc_1_2_smc()are guarded byCONFIG_ARM64ininclude/linux/arm-smccc.h. If a generic firmware driver usingCOMPILE_TESTincludes this header on a different architecture, it seems compilation will fail.
Only arm64 code is including that header for now.
arch/arm64/mm/init.c:37:#include <linux/arm-rsi-cmds.h> arch/arm64/include/asm/mem_encrypt.h:5:#include <linux/arm-rsi-cmds.h> arch/arm64/include/asm/pgtable-prot.h:69:#include <linux/arm-rsi-cmds.h> arch/arm64/include/asm/io.h:11:#include <linux/arm-rsi-cmds.h> arch/arm64/kernel/setup.c:10:#include <linux/arm-rsi-cmds.h> drivers/virt/coco/arm-cca-guest/arm-cca.c:6:#include <linux/arm-rsi-cmds.h> drivers/firmware/arm_rmm/rsi.c:11:#include <linux/arm-rsi-cmds.h>
-aneesh
Quoted 16 lines · Aneesh Kumar K.V
Quoted 5 lines · Catalin Marinas
Quoted 3 lines · Aneesh Kumar K.V (Arm)
Changes from v8:
https://lore.kernel.org/all/[email protected]
* Rebase onto the arm64 for-next/core branch.Quoted 8 lines
Was there a dependency on anything in for-next/core? We normally apply series on their own branch on top of the vanilla kernel (e.g. 7.2-rc3) and merge everything together in for-next/core. We (and many other maintainers) strongly prefer series posted on top of an -rc kernel (typically -rc1 to -rc3) unless there's a dependency on a different branch. Never based on -next or -next like branches (which is what for-next/core is, as the name implies).
Quoted 8 lines
The reason is that these two patches create conflicts. Since this series involves file movement, resolving those conflicts was not straightforward. Therefore, I rebased the series on top of both of the following commits:
commit
24f55f511b9e("virt: arm-cca-guest: usemigrate_disable()for attestation token requests") commite62decaf98e7("arm64/coco: Add pKVM as a CC platform")
Any chance of getting this picked up for the next merge window?
A few patch series depend on this patch:
1. The rest of the CCA DA series
2. LFA: https://lore.kernel.org/all/[email protected]
3. Realm support for Hyper-V: https://lore.kernel.org/all/[email protected]
-aneesh
Re: [PATCH v9 3/7] firmware: arm_rmm: Move RSI support out of arch/arm64
In reply to Aneesh Kumar K.V (Arm)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/smcccand the Arm CCA guest driver.Move the complete Realm Service Interface (RSI) implementation from
arch/arm64todrivers/firmware/arm_rmm. The RSI SMCCC definitions and command helpers are also moved toinclude/linuxso 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 3 lines
[1] https://lore.kernel.org/all/agsNO9cc7H-b0H8L@willie-the-truck
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>
Re: [PATCH v9 4/7] arm64: realm: Move Realm memory encryption ops to RSI code
In reply to Aneesh Kumar K.V (Arm)Quoted 46 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.
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>--- 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@@ -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
-3@@ -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;
arch/arm64/mm/pageattr.c static int __set_memory_enc_dec(unsigned long addr, · line 320
Quoted 2 lines
arch/arm64/mm/pageattr.c +0
-0@@ -321,40 +319,6 @@ static int __set_memory_enc_dec(unsigned long addr, __pgprot(PTE_PRESENT_INVALID)); }
This calls "rsi_set_memory_range_protected/shared(). Should we add call backs for those too in the arm64_mem_crypt_ops and take those away too ?
something like :
pre_enc_dec_phys_range(start, end, bool encrypt) ?
and implement that in firmware/arm_rmm/rsi.c ?
Suzuki
Quoted 83 lines
arch/arm64/mm/pageattr.c +0
-34-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@@ -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 )
Will Deacon
maintainerQuoted 23 lines · Aneesh Kumar K.V
Quoted 21 lines · Aneesh Kumar K.V
Quoted 5 lines · Catalin Marinas
Quoted 3 lines · Aneesh Kumar K.V (Arm)
Changes from v8:
https://lore.kernel.org/all/[email protected]
* Rebase onto the arm64 for-next/core branch.Quoted 8 lines
Was there a dependency on anything in for-next/core? We normally apply series on their own branch on top of the vanilla kernel (e.g. 7.2-rc3) and merge everything together in for-next/core. We (and many other maintainers) strongly prefer series posted on top of an -rc kernel (typically -rc1 to -rc3) unless there's a dependency on a different branch. Never based on -next or -next like branches (which is what for-next/core is, as the name implies).
The reason is that these two patches create conflicts. Since this series involves file movement, resolving those conflicts was not straightforward. Therefore, I rebased the series on top of both of the following commits:
Quoted 5 lines
Quoted 3 lines
commit
24f55f511b9e("virt: arm-cca-guest: usemigrate_disable()for attestation token requests") commite62decaf98e7("arm64/coco: Add pKVM as a CC platform")Any chance of getting this picked up for the next merge window?
No, we're at -rc7 and you sent this half-way through -rc6. Regression fixes only at this point, I'm afraid.
Will
Re: [PATCH v9 4/7] arm64: realm: Move Realm memory encryption ops to RSI code
In reply to Suzuki K PouloseQuoted 53 lines · Suzuki K Poulose
Quoted 46 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.
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>--- 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@@ -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
-3@@ -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;arch/arm64/mm/pageattr.c static int __set_memory_enc_dec(unsigned long addr, · line 320
Quoted 2 lines
arch/arm64/mm/pageattr.c +0
-0@@ -321,40 +319,6 @@ static int __set_memory_enc_dec(unsigned long addr, __pgprot(PTE_PRESENT_INVALID)); }This calls "rsi_set_memory_range_protected/shared(). Should we add call backs for those too in the
arm64_mem_crypt_opsand take those away too ?
Quoted 6 lines
something like :
pre_enc_dec_phys_range(start, end, bool encrypt)?and implement that in
firmware/arm_rmm/rsi.c?
__set_memory_enc_dec() is a helper that is only used for realms. We do have a check:
if (!is_realm_world())
return 0;
(We should probably change the return value to -EINVAL.)
The only reason it is in arch/arm64/mm/pageattr.c is that it calls __change_memory_common(). That function is more of an internal helper for the page table update routines. I wasn't sure whether we want to expose this API which can also be used for updating linear map attributes.
Currently, we restrict such updates to vmap mappings, with the only exception being the Realm use case through __set_memory_enc_dec().
-aneesh
Re: [PATCH v9 5/7] virt: coco: arm-cca-guest: Rename TSM report source file
In reply to Aneesh Kumar K.V (Arm)Quoted 7 lines
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.
That's pretty confusing, the module is called arm-cc-guest.ko but it has host items too?
I would have more expected the module to be named arm-cca and this file to be guest and a future file to be host or something like that?
It is annoying to change module names but we do it, and I think it should be no problem in this case since there are no users..
But maybe this patch should be in another series..
Signature · 1 line
Jason
Re: [PATCH v9 2/7] firmware: hwrng: arm_smccc_trng: Register as an SMCCC device
In reply to Aneesh Kumar K.V (Arm)Quoted 4 lines
[ ... 58 lines skipped ... ]
drivers/char/hw_random/arm_smccc_trng.c +0
-0@@ -94,29 +96,37 @@ static int smccc_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)return copied; }
drivers/char/hw_random/arm_smccc_trng.c static int smccc_trng_read(struct hwrng *rng, void *data, size_t max, bool wait) · line 105
Quoted 10 lines
drivers/char/hw_random/arm_smccc_trng.c +4
-2-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 ;
It feels like slightly poor practice to do this.. It is doing three things:
1) ARM32 disables this entirely for some reason, shouldn't the bus do it? Maybe it already does?
2) Checks the API exists and checks but the bus already did this.
3) Checks the version number
Maybe the bus should capture the version output and pass it in as an argument to probe so the driver can do the min version check directly?
It is very minor anyhow, it looks OK
Signature · 1 line
Jason
Re: [PATCH v9 7/7] coco: guest: arm64: Replace dummy CCA device with sysfs ABI
In reply to Aneesh Kumar K.V (Arm)Quoted 6 lines
[ ... 10 lines skipped ... ]
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.
Is this the case? the uv code is blocked by:
if (!test_facility(158)) return 0;
Which AI is telling me means the FW supports "ultravisor", so I think that would be broadly equivilent on ARM to FW supporting RMM.
ie don't create a firmware/cca unconditionally, look for some sign that RMM is present first?
The rest makes sense to me.
Signature · 1 line
Jason
Re: [PATCH v9 6/7] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
In reply to Aneesh Kumar K.V (Arm)drivers/firmware/smccc/smccc.c static const struct smccc_device_info smccc_devices[] __initconst = { · line 100
Quoted 8 lines
[ ... 43 lines skipped ... ]
drivers/firmware/smccc/smccc.c +3
-0@@ -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,
[Severity: High]
Does this new entry cause uninitialized registers to be passed to the firmware?
Looking at smccc_probe_smccc_device():
arm_smccc_1_1_invoke(smccc_dev->func_id, &res);
The invocation only passes the func_id, leaving r1 uninitialized. Since the SMC_RSI_ABI_VERSION ABI requires r1 to hold the requested version parameter, does this leak uninitialized kernel register state to the firmware and pass a garbage ABI version?
This seems like a good point.. Several other APIs had this 'pass a thing in' as part of their version contract too.
There is ABI incompatabilitiy here right? It would make sense to break up the really different versions into different device strings if possible. eg v1 and v2?
...
[Severity: High]
Could this also execute an SMC64 call on 32-bit ARM (AArch32) systems?
The smccc_devices array unconditionally includes SMC_RSI_ABI_VERSION, which is an SMC64 call. Executing an SMC64 function identifier from an AArch32 execution state is architecturally unpredictable and could cause a crash or hang on 32-bit hardware.
No idea if sashiko is right , but it is what I was wondering about in the rng patch...
Quoted 15 lines
[ ... 44 lines skipped ... ]
drivers/virt/coco/arm-cca-guest/arm-cca.c +6
-1+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;@@ -178,30 +175,33 @@ static int __init arm_cca_guest_init(void)return -ENODEV ; ret =tsm_report_register (&arm_cca_tsm_report_ops,NULL ); -if (ret <0 )
drivers/virt/coco/arm-cca-guest/arm-cca.c static int __init arm_cca_guest_init(void) · line 185
Quoted 10 lines
drivers/virt/coco/arm-cca-guest/arm-cca.c +7
-2-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; + ret =devm_add_action_or_reset (&sdev->dev, unregister_cca_tsm_report, +NULL ); +if (ret <0 ) {
Can just make unregister the remove function. Don't need to use devm for everything.
Signature · 1 line
Jason
Re: [PATCH v9 3/7] firmware: arm_rmm: Move RSI support out of arch/arm64
In reply to Aneesh Kumar K.V (Arm)Quoted 11 lines
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/smcccand the Arm CCA guest driver.Move the complete Realm Service Interface (RSI) implementation from
arch/arm64todrivers/firmware/arm_rmm. The RSI SMCCC definitions and command helpers are also moved toinclude/linuxso 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 3 lines
[1] https://lore.kernel.org/all/agsNO9cc7H-b0H8L@willie-the-truck
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>
The sashiko remarks don't look useful
include/linux/arm-rsi-cmds.h line 14
Quoted 3 lines
[ ... 321 lines skipped ... ]
include/linux/arm-rsi-cmds.h renamed from arch/arm64/include/asm/rsi_cmds.h +1
-1-#include <asm/rsi_smc.h> +#define RSI_PDEV_NAME "arm-cca-dev"
This name shows up on the smccc bus as a device, '-dev' doesn't seem to make sense as a device name to me, I'd drop it.
And is this arm-cca or should it be called arm-rsi with a different SMCC device for arm-rmi ?
Signature · 1 line
Jason
Re: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
In reply to Aneesh Kumar K.V (Arm)Quoted 19 lines
[ ... 143 lines skipped ... ]
drivers/firmware/smccc/bus.c new file +18
-0+struct arm_smccc_device *arm_smccc_device_register (const char *name) +{ +int id, ret; +struct arm_smccc_device *smccc_dev; + +if (!name) +return ERR_PTR (-EINVAL ); + + id =ida_alloc_min (&arm_smccc_bus_id,1 ,GFP_KERNEL ); +if (id <0 ) +return ERR_PTR (id); + + smccc_dev =kzalloc_obj (*smccc_dev); +if (!smccc_dev) { +ida_free (&arm_smccc_bus_id, id); +return ERR_PTR (-ENOMEM ); + } +
drivers/firmware/smccc/bus.c line 136
Quoted 10 lines
drivers/firmware/smccc/bus.c new file +10
-0+ smccc_dev->id = id; +if (strscpy (smccc_dev->name, name) <0 ) { +kfree (smccc_dev); +ida_free (&arm_smccc_bus_id, id); +return ERR_PTR (-EINVAL ); + } + smccc_dev->dev.bus = &arm_smccc_bus_type; + smccc_dev->dev.release = arm_smccc_release_device; + + ret =dev_set_name (&smccc_dev->dev,"%s-%d" , smccc_dev->name, id);
The bus seems well constructed, but this is a little bit odd, was it deliberate?
For identifying the module alias and labeling the bus devices it is typical to use a fixed HW value, because it tends to turn into uAPI. So the hex func_id would have been a logical choice:
.func_id = SMC_RSI_ABI_VERSION,
Ie 0xc4000190 as the device label.
For example lets imagine that ARM defines a call to give a list of (func_id, version) for everything the FW supports. This would be great, then no need to probe every item in the table anymore. However if you define strings here then it doesn't work so well, the string table all has to be built in..
Though handling ARM's version scheme could be tricky.
Not opposed to this, but think about it carefully since this is basically making a uABI decision that probably cannot be taken back. comment about that above the table at least.
What is this idr and name mangling doing? The names have to be unique because they are 1:1 with func_id, which must be unique by how SMCCC works, so what is the purpose of the IDR?
Now instead of getting a machine stable device name like c4000190 or even arm-rsi-dev we get arm-rsi-dev.X where X is unpredictable and might change on kernel upgrades. That's not cool.
smccc_dev->id isn't used for anything else. Drop it?
include/linux/arm-smccc-bus.h line 16
Quoted 6 lines
[ ... 47 lines skipped ... ]
include/linux/arm-smccc-bus.h new file +5
-0+struct arm_smccc_device { +int id; +char name[ARM_SMCCC_NAME_SIZE ]; +struct device dev; +};
It is common practice to put the containing struct at the top and is a micro optimization since container_of becomes a NOP. Same for the driver below.
Why have two copies of name? dev->name is already enough?
Signature · 1 line
Jason
Re: [PATCH v9 2/7] firmware: hwrng: arm_smccc_trng: Register as an SMCCC device
In reply to Jason GunthorpeQuoted 18 lines · Jason Gunthorpe
Quoted 4 lines
[ ... 58 lines skipped ... ]
drivers/char/hw_random/arm_smccc_trng.c +0
-0@@ -94,29 +96,37 @@ static int smccc_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)return copied; }drivers/char/hw_random/arm_smccc_trng.c static int smccc_trng_read(struct hwrng *rng, void *data, size_t max, bool wait) · line 105
Quoted 10 lines
drivers/char/hw_random/arm_smccc_trng.c +4
-2-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 ;It feels like slightly poor practice to do this.. It is doing three things:
Quoted 3 lines
1) ARM32 disables this entirely for some reason, shouldn't the bus do it? Maybe it already does?
Why? The bus only checks whether the firmware function is supported and creates the device if it is. Further validation should be the driver's responsibility, shouldn't it?
Quoted 3 lines
2) Checks the API exists and checks but the bus already did this.
This checks that the firmware supports the minimum ABI version required by the driver.
Quoted 6 lines
3) Checks the version number
Maybe the bus should capture the version output and pass it in as an argument to probe so the driver can do the min version check directly?
One of the earlier discussions suggested that the bus should only check whether the function ID is supported, rather than checking for an expected version or anything similar. This keeps the bus code generic.
arm_smccc_1_1_invoke(smccc_dev->func_id, &res); ret = res.a0; if (ret == SMCCC_RET_NOT_SUPPORTED) return false;
The other alternative discussed was a device-specific callback that would perform additional validation and create the device only when those conditions were met. It was dropped in favor of the simpler bus code above.
Quoted 7 lines
It is very minor anyhow, it looks OK
Reviewed-by Jason Gunthorpe <[email protected]>Signature · 1 line
Jason
-aneesh
Re: [PATCH v9 3/7] firmware: arm_rmm: Move RSI support out of arch/arm64
In reply to Jason GunthorpeQuoted 17 lines · Jason Gunthorpe
Quoted 11 lines
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/smcccand the Arm CCA guest driver.Move the complete Realm Service Interface (RSI) implementation from
arch/arm64todrivers/firmware/arm_rmm. The RSI SMCCC definitions and command helpers are also moved toinclude/linuxso 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 3 lines
[1] https://lore.kernel.org/all/agsNO9cc7H-b0H8L@willie-the-truck
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>The sashiko remarks don't look useful
Quoted 9 lines
Reviewed-by Jason Gunthorpe <[email protected]>include/linux/arm-rsi-cmds.h line 14
Quoted 3 lines
[ ... 321 lines skipped ... ]
include/linux/arm-rsi-cmds.h renamed from arch/arm64/include/asm/rsi_cmds.h +1
-1-#include <asm/rsi_smc.h> +#define RSI_PDEV_NAME "arm-cca-dev"This name shows up on the smccc bus as a device, '-dev' doesn't seem to make sense as a device name to me, I'd drop it.
I will drop the -dev from the name. The final name is "arm-rsi"
Quoted 4 lines
And is this arm-cca or should it be called arm-rsi with a different SMCC device for arm-rmi ?
We do that in patch 6. This patch deals with only code movement.
+++ b/include/linux/arm-smccc-rsi.h
@@ -8,6 +8,8 @@
#include <linux/arm-smccc.h>
+#define RSI_DEV_NAME "arm-rsi-dev"
+
-aneesh
Re: [PATCH v9 5/7] virt: coco: arm-cca-guest: Rename TSM report source file
In reply to Jason GunthorpeQuoted 11 lines · Jason Gunthorpe
Quoted 7 lines
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.That's pretty confusing, the module is called arm-cc-guest.ko but it has host items too?
Quoted 8 lines
I would have more expected the module to be named arm-cca and this file to be guest and a future file to be host or something like that?
It is annoying to change module names but we do it, and I think it should be no problem in this case since there are no users..
But maybe this patch should be in another series..
We have two modules, arm-cca-guest.ko and arm-cca-host.ko, located in their respective directories:
drivers/virt/coco/arm-cca-guest/drivers/virt/coco/arm-cca-host/
They also have separate Kconfig symbols, ARM_CCA_GUEST and ARM_CCA_HOST.
-aneesh
Re: [PATCH v9 6/7] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
In reply to Jason GunthorpeQuoted 12 lines · Jason Gunthorpe
drivers/firmware/smccc/smccc.c static const struct smccc_device_info smccc_devices[] __initconst = { · line 100
Quoted 8 lines
[ ... 43 lines skipped ... ]
drivers/firmware/smccc/smccc.c +3
-0@@ -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,[Severity: High]
Does this new entry cause uninitialized registers to be passed to the firmware?
Quoted 9 lines
Looking at
smccc_probe_smccc_device():
arm_smccc_1_1_invoke(smccc_dev->func_id, &res);The invocation only passes the
func_id, leaving r1 uninitialized. Since theSMC_RSI_ABI_VERSIONABI requires r1 to hold the requested version parameter, does this leak uninitialized kernel register state to the firmware and pass a garbage ABI version?
Yes. This even can result in error return from firmware like
[ rmm ] SMC_RMI_VERSION 6 > RMI_RMI_ERROR_INPUT
Quoted 8 lines
This seems like a good point.. Several other APIs had this 'pass a thing in' as part of their version contract too.
There is ABI incompatabilitiy here right? It would make sense to break up the really different versions into different device strings if possible. eg v1 and v2?
The goal is only to check whether the firmware function is supported, hence the explicit check for SMCCC_RET_NOT_SUPPORTED.
arm_smccc_1_1_invoke(smccc_dev->func_id, &res); ret = res.a0; if (ret == SMCCC_RET_NOT_SUPPORTED) return false;
Quoted 6 lines
...
[Severity: High]
Could this also execute an SMC64 call on 32-bit ARM (AArch32) systems?
Quoted 8 lines
The
smccc_devicesarray unconditionally includesSMC_RSI_ABI_VERSION, which is an SMC64 call. Executing an SMC64 function identifier from an AArch32 execution state is architecturally unpredictable and could cause a crash or hang on 32-bit hardware.No idea if sashiko is right , but it is what I was wondering about in the rng patch...
I will check whether issuing an SMC64 call on 32-bit ARM is a problem.
Quoted 22 lines
Quoted 22 lines
[ ... 44 lines skipped ... ]
drivers/virt/coco/arm-cca-guest/arm-cca.c +10
-2+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;@@ -178,30 +175,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; + }
Quoted 8 lines
drivers/virt/coco/arm-cca-guest/arm-cca.c static int __init arm_cca_guest_init(void) · line 185
Quoted 4 lines
drivers/virt/coco/arm-cca-guest/arm-cca.c +3
-1-return ret; + ret =devm_add_action_or_reset (&sdev->dev, unregister_cca_tsm_report, +NULL ); +if (ret <0 ) {Can just make unregister the remove function. Don't need to use devm for everything.
IIUC, you are suggesting to do the below?
static void cca_tsm_remove(struct arm_smccc_device *sdev)
{
tsm_report_unregister(&arm_cca_tsm_report_ops);
}static struct arm_smccc_driver cca_tsm_driver = {
.driver_name = "arm_cca_tsm",
.probe = cca_tsm_probe,
.remove = cca_tsm_remove,
...
-aneesh
Re: [PATCH v9 5/7] virt: coco: arm-cca-guest: Rename TSM report source file
In reply to Aneesh Kumar K.VQuoted 22 lines · Aneesh Kumar K.V
Quoted 11 lines · Jason Gunthorpe
Quoted 7 lines
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.That's pretty confusing, the module is called arm-cc-guest.ko but it has host items too?
Quoted 8 lines
I would have more expected the module to be named arm-cca and this file to be guest and a future file to be host or something like that?
It is annoying to change module names but we do it, and I think it should be no problem in this case since there are no users..
But maybe this patch should be in another series..
Quoted 7 lines
We have two modules, arm-cca-guest.ko and arm-cca-host.ko, located in their respective directories:
drivers/virt/coco/arm-cca-guest/drivers/virt/coco/arm-cca-host/They also have separate
Kconfigsymbols,ARM_CCA_GUESTandARM_CCA_HOST.
So this is about renaming the .c file so you can have a multi .c file module then? The usual kbuild problem. I'd call it guest-main or similar. Linus has disliked suttering the directory name into the file name in the past
Jason
Re: [PATCH v9 2/7] firmware: hwrng: arm_smccc_trng: Register as an SMCCC device
In reply to Aneesh Kumar K.VQuoted 20 lines · Aneesh Kumar K.V
Quoted 18 lines · Jason Gunthorpe
Quoted 4 lines
[ ... 58 lines skipped ... ]
drivers/char/hw_random/arm_smccc_trng.c +0
-0@@ -94,29 +96,37 @@ static int smccc_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)return copied; }drivers/char/hw_random/arm_smccc_trng.c static int smccc_trng_read(struct hwrng *rng, void *data, size_t max, bool wait) · line 105
Quoted 10 lines
drivers/char/hw_random/arm_smccc_trng.c +4
-2-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 ;It feels like slightly poor practice to do this.. It is doing three things:
Quoted 7 lines
Quoted 3 lines
1) ARM32 disables this entirely for some reason, shouldn't the bus do it? Maybe it already does?
Why? The bus only checks whether the firmware function is supported and creates the device if it is. Further validation should be the driver's responsibility, shouldn't it?
I assume the reason is because the SMCCC call can't work at all on ARM64? Like sashiko suggested perhaps? If so that is definately bus code responsibility to filter out uncallable SMCCC's.
Quoted 8 lines
Quoted 4 lines
3) Checks the version number
Maybe the bus should capture the version output and pass it in as an argument to probe so the driver can do the min version check directly?
One of the earlier discussions suggested that the bus should only check whether the function ID is supported, rather than checking for an expected version or anything similar.
I'm not sure about that. If the versions are actually so different that you want different drivers then having -v1/-v2 in the device match is a reasonable design. ARM has made major ABI breakages before like RMM v1/v2 that could motivate a two driver design like that.
Quoted 4 lines
The other alternative discussed was a device-specific callback that would perform additional validation and create the device only when those conditions were met. It was dropped in favor of the simpler bus code above.
I wouldn't do that.. If the API allows capturing generically the suported version then it could be passed in so it doesn't have to be queried again. And maybe it could be used in a match someday if necessary.
But it is no big deal, something to think about.
Jason
Re: [PATCH v9 6/7] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
In reply to Aneesh Kumar K.VQuoted 24 lines · Aneesh Kumar K.V
Quoted 12 lines · Jason Gunthorpe
drivers/firmware/smccc/smccc.c static const struct smccc_device_info smccc_devices[] __initconst = { · line 100
Quoted 8 lines
[ ... 43 lines skipped ... ]
drivers/firmware/smccc/smccc.c +3
-0@@ -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,[Severity: High]
Does this new entry cause uninitialized registers to be passed to the firmware?Quoted 9 lines
Looking at
smccc_probe_smccc_device():
arm_smccc_1_1_invoke(smccc_dev->func_id, &res);The invocation only passes the
func_id, leaving r1 uninitialized. Since theSMC_RSI_ABI_VERSIONABI requires r1 to hold the requested version parameter, does this leak uninitialized kernel register state to the firmware and pass a garbage ABI version?
Quoted 3 lines
Yes. This even can result in error return from firmware like
[ rmm ]
SMC_RMI_VERSION6 >RMI_RMI_ERROR_INPUT
Yeah, it strikes me that the RSI handshake is quite a different discovery protocol than the rng. That's unfortunate that it isn't standardized for this bus design. Still it shouldn't be a big deal for this code to deal with it, but unfortunate.
Quoted 16 lines
Quoted 8 lines
drivers/virt/coco/arm-cca-guest/arm-cca.c static int __init arm_cca_guest_init(void) · line 185
Quoted 4 lines
drivers/virt/coco/arm-cca-guest/arm-cca.c +3
-1-return ret; + ret =devm_add_action_or_reset (&sdev->dev, unregister_cca_tsm_report, +NULL ); +if (ret <0 ) {Can just make unregister the remove function. Don't need to use devm for everything.
IIUC, you are suggesting to do the below?
static void
cca_tsm_remove(struct arm_smccc_device *sdev){ tsm_report_unregister(&arm_cca_tsm_report_ops); }
Quoted 5 lines
static struct
arm_smccc_drivercca_tsm_driver= {
.driver_name = "arm_cca_tsm",
.probe =cca_tsm_probe,
.remove =cca_tsm_remove,
...
Yeah
Jason
Re: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
In reply to Jason GunthorpeQuoted 74 lines · Jason Gunthorpe
Quoted 19 lines
[ ... 143 lines skipped ... ]
drivers/firmware/smccc/bus.c new file +18
-0+struct arm_smccc_device *arm_smccc_device_register (const char *name) +{ +int id, ret; +struct arm_smccc_device *smccc_dev; + +if (!name) +return ERR_PTR (-EINVAL ); + + id =ida_alloc_min (&arm_smccc_bus_id,1 ,GFP_KERNEL ); +if (id <0 ) +return ERR_PTR (id); + + smccc_dev =kzalloc_obj (*smccc_dev); +if (!smccc_dev) { +ida_free (&arm_smccc_bus_id, id); +return ERR_PTR (-ENOMEM ); + } +drivers/firmware/smccc/bus.c line 136
Quoted 10 lines
drivers/firmware/smccc/bus.c new file +10
-0+ smccc_dev->id = id; +if (strscpy (smccc_dev->name, name) <0 ) { +kfree (smccc_dev); +ida_free (&arm_smccc_bus_id, id); +return ERR_PTR (-EINVAL ); + } + smccc_dev->dev.bus = &arm_smccc_bus_type; + smccc_dev->dev.release = arm_smccc_release_device; + + ret =dev_set_name (&smccc_dev->dev,"%s-%d" , smccc_dev->name, id);The bus seems well constructed, but this is a little bit odd, was it deliberate?
For identifying the module alias and labeling the bus devices it is typical to use a fixed HW value, because it tends to turn into uAPI. So the hex
func_idwould have been a logical choice:.func_id =
SMC_RSI_ABI_VERSION,Ie
0xc4000190as the device label.For example lets imagine that ARM defines a call to give a list of (
func_id, version) for everything the FW supports. This would be great, then no need to probe every item in the table anymore. However if you define strings here then it doesn't work so well, the string table all has to be built in..Though handling ARM's version scheme could be tricky.
Not opposed to this, but think about it carefully since this is basically making a uABI decision that probably cannot be taken back. comment about that above the table at least.
What is this idr and name mangling doing? The names have to be unique because they are 1:1 with
func_id, which must be unique by how SMCCC works, so what is the purpose of the IDR?Now instead of getting a machine stable device name like
c4000190or even arm-rsi-dev we get arm-rsi-dev.X where X is unpredictable and might change on kernel upgrades. That's not cool.
smccc_dev->idisn't used for anything else. Drop it?include/linux/arm-smccc-bus.h line 16
Quoted 6 lines
[ ... 47 lines skipped ... ]
include/linux/arm-smccc-bus.h new file +5
-0+struct arm_smccc_device { +int id; +char name[ARM_SMCCC_NAME_SIZE ]; +struct device dev; +};It is common practice to put the containing struct at the top and is a micro optimization since
container_ofbecomes a NOP. Same for the driver below.
Quoted 2 lines
Why have two copies of name?
dev->nameis already enough?
I have updated the bus to match devices using func_id.
static int arm_smccc_bus_match(struct device *dev,
const struct device_driver *drv)
{
....
id_table = to_arm_smccc_driver(drv)->id_table;
if (!id_table)
return 0;
while (id_table->func_id) {
if (smccc_dev->func_id == id_table->func_id)
return 1;
id_table++;
}...
file2alias.c now have
modified scripts/mod/file2alias.c
@@ -1351,9 +1351,9 @@
static void do_arm_smccc_entry(struct module *mod, void *symval) {
- DEF_FIELD_ADDR(symval, arm_smccc_device_id, name);
+ DEF_FIELD(symval, arm_smccc_device_id, func_id);
- module_alias_printf(mod, false, ARM_SMCCC_MODULE_PREFIX "%s", *name);
+ module_alias_printf(mod, false, ARM_SMCCC_MODULE_PREFIX "f%08X", func_id);
}
/*
Re: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
Quoted 1 line · Aneesh Kumar K.V
I have updated the bus to match devices using
func_id.
Did you have any thoughts on how to handle ARM's versioning scheme too?
I'm not sure what the rules are but it seems like if the major changes then the API is incompatible? So shouldn't every driver advertise a supported major, and the major be in the modalias and checked by match too?
Jason
Sudeep Holla
maintainerRe: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
Quoted 4 lines · Jason Gunthorpe
Quoted 1 line · Aneesh Kumar K.V
I have updated the bus to match devices using
func_id.
Quoted 8 lines
Did you have any thoughts on how to handle ARM's versioning scheme too?
I'm not sure what the rules are but it seems like if the major changes then the API is incompatible? So shouldn't every driver advertise a supported major, and the major be in the modalias and checked by match too?
Just curious as how this should work with any v1.x firmwares in the wild once the driver updates the supported major version to say v2.0
Is there a way to set the supported major version in the driver via some module parameter that the old systems then can make use of. Just random thoughts/queries to understand how they all fit it eventually for the wild variety of f/w we need to support irrespective of what is the supported max major version the driver advertises.
Signature · 2 lines
Regards, Sudeep
Re: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
Quoted 8 lines · Sudeep Holla
Quoted 7 lines · Jason Gunthorpe
Quoted 1 line · Aneesh Kumar K.V
I have updated the bus to match devices using
func_id.Did you have any thoughts on how to handle ARM's versioning scheme too?
Quoted 8 lines
Quoted 5 lines
I'm not sure what the rules are but it seems like if the major changes then the API is incompatible? So shouldn't every driver advertise a supported major, and the major be in the modalias and checked by match too?
Just curious as how this should work with any v1.x firmwares in the wild once the driver updates the supported major version to say v2.0
You'd end up with two match lines, one for ABI v1 and one for ABI v2. Maybe they are the same driver, maybe they are not.
Jason
Re: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
In reply to Jason GunthorpeQuoted 11 lines · Jason Gunthorpe
Quoted 1 line · Aneesh Kumar K.V
I have updated the bus to match devices using
func_id.Did you have any thoughts on how to handle ARM's versioning scheme too?
I'm not sure what the rules are but it seems like if the major changes then the API is incompatible? So shouldn't every driver advertise a supported major, and the major be in the modalias and checked by match too?
I expect a single driver to handle the RSI features and determine the version range it supports. I don't think we want multiple drivers, each handling a different major version of the RMM release. Given that, wouldn't it be sufficient for the driver's probe routine to check the supported version range and return -ENODEV if it is unsupported?
-aneesh
Re: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
Quoted 9 lines · Aneesh Kumar K.V
Quoted 7 lines · Jason Gunthorpe
Quoted 1 line · Aneesh Kumar K.V
I have updated the bus to match devices using
func_id.Did you have any thoughts on how to handle ARM's versioning scheme too?
Quoted 8 lines
Quoted 4 lines
I'm not sure what the rules are but it seems like if the major changes then the API is incompatible? So shouldn't every driver advertise a supported major, and the major be in the modalias and checked by match too?
I expect a single driver to handle the RSI features and determine the version range it supports. I don't think we want multiple drivers, each handling a different major version of the RMM release.
I thought the plan was we are only going to support RMM V2 and there will, never, ever be a V3. :) So RMM is maybe a bit different..
Quoted 3 lines
Given that, wouldn't it be sufficient for the driver's probe routine to check the supported version range and return
-ENODEVif it is unsupported?
It is sufficient, but is that what you want? Every driver needs to manually check these version things, do they? Do we want this duplication? Missing a check means FW upgrades might become Linux breaking.
Jason
Sudeep Holla
maintainerRe: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
Quoted 22 lines · Jason Gunthorpe
Quoted 9 lines · Aneesh Kumar K.V
Quoted 7 lines · Jason Gunthorpe
Quoted 1 line · Aneesh Kumar K.V
I have updated the bus to match devices using
func_id.Did you have any thoughts on how to handle ARM's versioning scheme too?
Quoted 8 lines
Quoted 4 lines
I'm not sure what the rules are but it seems like if the major changes then the API is incompatible? So shouldn't every driver advertise a supported major, and the major be in the modalias and checked by match too?
I expect a single driver to handle the RSI features and determine the version range it supports. I don't think we want multiple drivers, each handling a different major version of the RMM release.
I thought the plan was we are only going to support RMM V2 and there will, never, ever be a V3. :) So RMM is maybe a bit different..
Quoted 7 lines
Quoted 3 lines
Given that, wouldn't it be sufficient for the driver's probe routine to check the supported version range and return
-ENODEVif it is unsupported?It is sufficient, but is that what you want? Every driver needs to manually check these version things, do they? Do we want this duplication?
Oh yes, we need this whatever you term as "duplication". I would argue against terming it as duplications as if you look at the various SMCCC based specification, we have zero consistency in how the VERSION command is expected to work. The only consistency is returning SMCCC_RET_NOT_SUPPORTED if not supported and that's the max a generic SMCCC bus code can check. All other details need to be deferred to the individual SMCCC drivers.
Quoted 2 lines
Missing a check means FW upgrades might become Linux breaking.
Are you referring to the SMCCC bus code or RSI in particular above. I don't see any issue with SMCCC bus code check as that is the least we can do and must not change with future versions of the firmware as well.
If it is specific to RSI and the driver supports v2.0 and the firmware is upgraded to v3.0, it really depends on what the v3.0 firmware returns in these 2 values:
Lower RsiInterfaceVersion : Lower supported interface revision Higher RsiInterfaceVersion : Higher supported interface revision
If lower is also set at v3.0, then I would argue it is firmware upgrade issue expecting old kernel with old RSI version supported to work. If that returns v2.0, the driver must work IIUC. Aneesh, hopefully I got this right ?
Signature · 2 lines
Regards, Sudeep
Re: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
Quoted 4 lines · Sudeep Holla
Oh yes, we need this whatever you term as "duplication". I would argue against terming it as duplications as if you look at the various SMCCC based specification, we have zero consistency in how the VERSION command is expected to work.
Okay, then that pretty much settles it. Nothing to do
Quoted 5 lines
Quoted 1 line
Missing a check means FW upgrades might become Linux breaking.
Are you referring to the SMCCC bus code or RSI in particular above. I don't see any issue with SMCCC bus code check as that is the least we can do and must not change with future versions of the firmware as well.
Just in general, SMCCC drivers have to do something smart with the version.
Like, is this OK:
#define ARM_SMCCC_TRNG_MIN_VERSION 0x10000UL
static inline bool smccc_probe_trng(void)
{
struct arm_smccc_res res;
arm_smccc_1_1_invoke(ARM_SMCCC_TRNG_VERSION, &res);
if ((s32)res.a0 < 0)
return false;
return res.a0 >= ARM_SMCCC_TRNG_MIN_VERSION;
}?
It means you can never publish a version 2 that is ABI breaking because linux doesn't check for that. Was that ARM's intention with the version API? It's basically a completely pointless check that doesn't effectively do anything.
My broader, more general point is that if SMCC is being made into a discoverable bus, that's great, but it would be even better if ARM could find a way to progmatically enumerate all the ABIs present on the SMCC interface to populate the bus. That would necessarily include some consistent treatment of versioning for consistent interoperability.
Quoted 4 lines
If lower is also set at v3.0, then I would argue it is firmware upgrade issue expecting old kernel with old RSI version supported to work. If that returns v2.0, the driver must work IIUC. Aneesh, hopefully I got this right ?
There was many long conversations about this and I think the conclusion was RSI will broadly not use versions for any kind of ABI control. It is too coarse to really work in the real world and we must have strong forward/backwards interoperability inside VMs forever.
Jason
Re: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
Quoted 52 lines · Jason Gunthorpe
Quoted 4 lines · Sudeep Holla
Oh yes, we need this whatever you term as "duplication". I would argue against terming it as duplications as if you look at the various SMCCC based specification, we have zero consistency in how the VERSION command is expected to work.
Okay, then that pretty much settles it. Nothing to do
Quoted 5 lines
Quoted 1 line
Missing a check means FW upgrades might become Linux breaking.
Are you referring to the SMCCC bus code or RSI in particular above. I don't see any issue with SMCCC bus code check as that is the least we can do and must not change with future versions of the firmware as well.
Just in general, SMCCC drivers have to do something smart with the version.
Like, is this OK:
#define
ARM_SMCCC_TRNG_MIN_VERSION0x10000ULstatic inline bool
smccc_probe_trng(void){ struct arm_smccc_res res; arm_smccc_1_1_invoke(ARM_SMCCC_TRNG_VERSION, &res); if ((s32)res.a0 < 0) return false; return res.a0 >= ARM_SMCCC_TRNG_MIN_VERSION; }?
It means you can never publish a version 2 that is ABI breaking because linux doesn't check for that. Was that ARM's intention with the version API? It's basically a completely pointless check that doesn't effectively do anything.
My broader, more general point is that if SMCC is being made into a discoverable bus, that's great, but it would be even better if ARM could find a way to progmatically enumerate all the ABIs present on the SMCC interface to populate the bus. That would necessarily include some consistent treatment of versioning for consistent interoperability.
Quoted 4 lines
If lower is also set at v3.0, then I would argue it is firmware upgrade issue expecting old kernel with old RSI version supported to work. If that returns v2.0, the driver must work IIUC. Aneesh, hopefully I got this right ?
Quoted 4 lines
There was many long conversations about this and I think the conclusion was RSI will broadly not use versions for any kind of ABI control. It is too coarse to really work in the real world and we must have strong forward/backwards interoperability inside VMs forever.
Even if we take RMI as an example, SMC_RMI_ABI_VERSION returns the lowest and highest supported interface versions.
After a firmware upgrade, either value can change. Unless the existing kernel supports an interface version within the advertised range, the upgrade will break compatibility. Including the major version in the modalias does not help with this.
Even with separate kernel drivers for versions 1 and 2, we still face the same issue. If the firmware initially supports version 1 and an upgrade raises the lowest supported version to 2, the version 2 driver can handle it. However, that is functionally equivalent to a single driver supporting both interface versions. If the current kernel does not support version 2, either through a single driver or a separate driver, the firmware upgrade will break compatibility.
-aneesh
Sudeep Holla
maintainerRe: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
In reply to Jason GunthorpeQuoted 33 lines · Jason Gunthorpe
Quoted 4 lines · Sudeep Holla
Oh yes, we need this whatever you term as "duplication". I would argue against terming it as duplications as if you look at the various SMCCC based specification, we have zero consistency in how the VERSION command is expected to work.
Okay, then that pretty much settles it. Nothing to do
Quoted 5 lines
Quoted 1 line
Missing a check means FW upgrades might become Linux breaking.
Are you referring to the SMCCC bus code or RSI in particular above. I don't see any issue with SMCCC bus code check as that is the least we can do and must not change with future versions of the firmware as well.
Just in general, SMCCC drivers have to do something smart with the version.
Like, is this OK:
#define
ARM_SMCCC_TRNG_MIN_VERSION0x10000ULstatic inline bool
smccc_probe_trng(void){ struct arm_smccc_res res; arm_smccc_1_1_invoke(ARM_SMCCC_TRNG_VERSION, &res); if ((s32)res.a0 < 0) return false; return res.a0 >= ARM_SMCCC_TRNG_MIN_VERSION; }
Quoted 2 lines
?
So it will be specific to each FID range, then what is smart about generic SMCCC logic then ?
We already have
if (ret != SMCCC_RET_NOT_SUPPORTED) arm_smccc_device_register(..)
Not sure what else can be done.
Quoted 4 lines
It means you can never publish a version 2 that is ABI breaking because linux doesn't check for that. Was that ARM's intention with the version API? It's basically a completely pointless check that doesn't effectively do anything.
I didn't get that. The example above checks for minimum TRNG version, so it won't break in any way for v2. What am I missing ?
Quoted 7 lines
My broader, more general point is that if SMCC is being made into a discoverable bus, that's great, but it would be even better if ARM could find a way to progmatically enumerate all the ABIs present on the SMCC interface to populate the bus. That would necessarily include some consistent treatment of versioning for consistent interoperability.
Sure, it can be tried for future SMCCC based specs. We can't ignore the inconsistency that exists in the currently used SMCCC based specs. So it can't be ideal as you prefer I am afraid.
Quoted 11 lines
Quoted 5 lines
If lower is also set at v3.0, then I would argue it is firmware upgrade issue expecting old kernel with old RSI version supported to work. If that returns v2.0, the driver must work IIUC. Aneesh, hopefully I got this right ?
There was many long conversations about this and I think the conclusion was RSI will broadly not use versions for any kind of ABI control. It is too coarse to really work in the real world and we must have strong forward/backwards interoperability inside VMs forever.
OK, I wasn't ware of that.
Signature · 2 lines
Regards, Sudeep
Re: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
Quoted 7 lines · Sudeep Holla
Quoted 4 lines
It means you can never publish a version 2 that is ABI breaking because linux doesn't check for that. Was that ARM's intention with the version API? It's basically a completely pointless check that doesn't effectively do anything.
I didn't get that. The example above checks for minimum TRNG version, so it won't break in any way for v2. What am I missing ?
If ARM sticks to what they have done in other specs, a V2 could define ABI that is not compatible with V1 at all. (semantic versioning and all)
So the kernel check above will happily pass a v2 interface and then send garbage into the incompatible ABI.
The ecosystem couldn't accept this. An ABI breaking V2 can never exist, so the versioning is much less useful that a normal semver scheme.
If it was MAJOR(version) == 1 then it might make a little more sense.
I'm saying that broadly none of this version stuff seems to be doing much useful work. Even the more complicated RSI lower/uppper stuff was not good enough and they are going to follow a new scheme.
I think the bus is a nice idea! If you keep going down that logical path the next stop is to have a SMCCC that discovers the FW ABIs available. That would be a good moment to take a pause and try to set a versioning system standard that actually works consistently for the entire ecosystem.
IMHO to lean into the bus design I would have a discovery SMCCC that returns a list of supported ABIs, something like (spec, spec version, ABI, FID, feature supported bitmap). There could be overlaps if the FW supports several ABI incompatible versions, like RSI v1 and RSI v2.
Then you do a driver search and the strongest match sees the bus code issue a "set SMCCC" that says 'I picked index #3 behave like that please' and then the actual SMCC driver would use a features scheme to further fine tune things.
Instead of versions you have ABI's and feature bits describing what is supported. This is far closer to how the HW interfaces ARM designs tend to work, and is much more aligned to how I understand RMM is going.
It could be consistent and layer on top of what you have now without ABI breaking anything.
Regards,
Jason
Sudeep Holla
maintainerRe: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
Quoted 6 lines · Jason Gunthorpe
Quoted 5 lines · Sudeep Holla
Quoted 4 lines
It means you can never publish a version 2 that is ABI breaking because linux doesn't check for that. Was that ARM's intention with the version API? It's basically a completely pointless check that doesn't effectively do anything.
Quoted 6 lines
Quoted 2 lines
I didn't get that. The example above checks for minimum TRNG version, so it won't break in any way for v2. What am I missing ?
If ARM sticks to what they have done in other specs, a V2 could define ABI that is not compatible with V1 at all. (semantic versioning and all)
Ah got it. I agree with you on their pattern of breaking compatibility but things are improving, I won't say we are there yet.
Quoted 3 lines
So the kernel check above will happily pass a v2 interface and then send garbage into the incompatible ABI.
Ah that is possible, yes I can't disagree.
But I must say it is improving as the firmware teams implementing newer versions run the existing kernel and spot the issues quickly if anything is incompatible if the spec hadn't broken it intentionally.
Quoted 4 lines
The ecosystem couldn't accept this. An ABI breaking V2 can never exist, so the versioning is much less useful that a normal semver scheme.
Completely understood.
Quoted 6 lines
If it was MAJOR(version) == 1 then it might make a little more sense.
I'm saying that broadly none of this version stuff seems to be doing much useful work. Even the more complicated RSI lower/uppper stuff was not good enough and they are going to follow a new scheme.
Really, that's news to me.
Quoted 6 lines
I think the bus is a nice idea! If you keep going down that logical path the next stop is to have a SMCCC that discovers the FW ABIs available. That would be a good moment to take a pause and try to set a versioning system standard that actually works consistently for the entire ecosystem.
Yes agreed. The only argument I had is for the existing users whom we are fitting into the SMCCC bus like TRNG. But we need some agreement on the spec consistency if we need to do anything more smart in the core SMCCC bus code.
Quoted 5 lines
IMHO to lean into the bus design I would have a discovery SMCCC that returns a list of supported ABIs, something like (spec, spec version, ABI, FID, feature supported bitmap). There could be overlaps if the FW supports several ABI incompatible versions, like RSI v1 and RSI v2.
But then we will have to wait for that discovery SMCCC ABI first and that mean how will it work on existing deployed systems ? But I like the idea.
Quoted 5 lines
Then you do a driver search and the strongest match sees the bus code issue a "set SMCCC" that says 'I picked index #3 behave like that please' and then the actual SMCC driver would use a features scheme to further fine tune things.
I don't know if I got the details right but I get the overall idea here.
Quoted 5 lines
Instead of versions you have ABI's and feature bits describing what is supported. This is far closer to how the HW interfaces ARM designs tend to work, and is much more aligned to how I understand RMM is going.
Indeed, I prefer this and get mad if new features are added without feature bits. Version for me is just for rough indication that ideally these features must be 0 on a version X but it shouldn't matter for the software that purely relies on feature bits. So a big yes for that idea and I think some specs and in some form are doing it. I can't recall specific but I have seen it. We just need push only for that in future specs.
Quoted 3 lines
It could be consistent and layer on top of what you have now without ABI breaking anything.
Completely agreed!
Signature · 2 lines
Regards, Sudeep
Re: [PATCH v9 1/7] firmware: smccc: Add an Arm SMCCC bus
Quoted 8 lines · Sudeep Holla
Quoted 5 lines
IMHO to lean into the bus design I would have a discovery SMCCC that returns a list of supported ABIs, something like (spec, spec version, ABI, FID, feature supported bitmap). There could be overlaps if the FW supports several ABI incompatible versions, like RSI v1 and RSI v2.
But then we will have to wait for that discovery SMCCC ABI first and that mean how will it work on existing deployed systems ? But I like the idea.
Oh, I wasn't saying to wait for anything. This is good enough as is.
I was suggesting a next step to make this even better and solve some of the real problem the ecosystem feels with the FW/kernel ABI.
Quoted 4 lines
the software that purely relies on feature bits. So a big yes for that idea and I think some specs and in some form are doing it. I can't recall specific but I have seen it. We just need push only for that in future specs.
I was advocating the approach of a discovery spec that codifies exactly how all this should work. So each team writing a new spec doesn't have to reinvent it.
Jason