Skip to contentSkip to conversation

Arm CCA planes support

RFC PATCH New Steven Price 1 participant 6 messages Sep 26, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Arm CCA planes support

The Arm CCA (Confidential Compute Architecture) RMM version 1.1 specification[1] adds support for a concept of "planes". This allows a realm to be divided into multiple execution environments with memory separation between them (while still sharing the same IPA to PA translations). There's an overview on the Arm website[2].

The TF-RMM project[3] recently merged support for planes to their "main" branch and this an early preview of the corresponding Linux changes to support the feature. Note you need to enable the (experimental) RMM_V1_1 configuration option to enable this feature.

This series is based on the v10 posting of the CCA host support series[4] and is also available as a git tree:

https://gitlab.arm.com/linux-arm/linux-cca.git/ cca/planes/rfc-v1

A hacked up version of kvmtool to launch a realm guest with an extra plan is available here:

https://gitlab.arm.com/linux-arm/kvmtool-cca.git/ cca/planes/rfc-v1

Note:
The kvmtool support is a hack - it simply (unconditionally) enables a single extra plane (for a total of two planes: P0 and P1). This should obviously be a configuration option and should support other numbers of planes. But it gives an easy way of testing the support for auxiliary RTTs while running a single guest image (i.e. leaving P1 empty).

This series was written against the RMM v1.1 alp14 specification. Those who are following things closely will know we're up to alp16, however there are no major changes affecting planes between these two versions. The spec is still alpha, so there may well be changes in the future.

[1] https://developer.arm.com/-/cdn-downloads/permalink/Architectures/Armv9/DEN0137_1.1-alp14.zip
[2] https://developer.arm.com/documentation/den0125/400/Arm-CCA-Extensions#md239-arm-cca-extensions__realm-planes
[3] https://www.trustedfirmware.org/projects/tf-rmm/
[4] https://lore.kernel.org/r/20250820145606.180644-1-steven.price%40arm.com

Steven Price (5):
arm64: RME: Add SMC definitions introduced in RMM v1.1
arm64: RME: Handle auxiliary RTT trees
arm64: RME: Support RMI_EXIT_S2AP_CHANGE
arm64: rme: Allocate AUX RTT PGDs and VMIDs
arm64: RME: Support num_aux_places & rtt_tree_pp realm parameters

 arch/arm64/include/asm/kvm_rme.h  |   13 +-
 arch/arm64/include/asm/rmi_cmds.h | 1104 +++++++++++++++++++++++++++--
 arch/arm64/include/asm/rmi_smc.h  |  121 +++-
 arch/arm64/include/uapi/asm/kvm.h |   12 +
 arch/arm64/kvm/mmu.c              |   15 +-
 arch/arm64/kvm/rme-exit.c         |   33 +-
 arch/arm64/kvm/rme.c              |  441 +++++++++++-
 7 files changed, 1618 insertions(+), 121 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/5 arm64: RME: Add SMC definitions introduced in RMM v1.1

RMM v1.1 adds a bunch of new SMCs for planes and device assignment. Add the new SMC definitions including wrapper functions.

The definitions are based on DEN0137 version 1.1-alp14.

---
 arch/arm64/include/asm/rmi_cmds.h | 1104 +++++++++++++++++++++++++++--
 arch/arm64/include/asm/rmi_smc.h  |  121 +++-
 2 files changed, 1146 insertions(+), 79 deletions(-)
arch/arm64/include/asm/rmi_cmds.h +1033 -71
index ef53147c1984..cfeddf4a6ed1 100644
@@ -142,6 +142,244 @@ static inline int rmi_granule_undelegate(unsigned long phys)
 	return res.a0;
 }
 
+/**
+ * rmi_mec_set_private() - Change state of a MEC to private
+ * @mecid: Memory Encryption Context Idenifier
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_mec_set_private(unsigned long mecid)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_MEC_SET_PRIVATE, mecid, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_mec_set_shared() - Change state of a MEC to shared
+ * @mecid: Memory Encryption Context Identifier
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_mec_set_shared(unsigned long mecid)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_MEC_SET_SHARED, mecid, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_pdev_abort() - Abort device communication associated with a PDEV
+ * @pdev_ptr: PA of the PDEV
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_pdev_abort(unsigned long pdev_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PDEV_ABORT, pdev_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_pdev_aux_count() - Get number of auxiliary granules required for a PDEV
+ * @flags: PDEV flags
+ * @out_aux_count: Number of auxiliary granules required
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_pdev_aux_count(unsigned long flags,
+				     unsigned long *out_aux_count)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PDEV_AUX_COUNT, flags, &res);
+
+	*out_aux_count = res.a1;
+	return res.a0;
+}
+
+/**
+ * rmi_pdev_communicate() - Perform device communication associated with a PDEV
+ * @pdev_ptr: PA of the PDEV
+ * @data_ptr: PA of the communication data structure
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_pdev_communicate(unsigned long pdev_ptr,
+				       unsigned long data_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PDEV_COMMUNICATE, pdev_ptr, data_ptr,
+			     &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_pdev_create() - Create a PDEV
+ * @pdev_ptr: PA of the PDEV
+ * @params_ptr: PA of PDEV parameters
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_pdev_create(unsigned long pdev_ptr,
+				  unsigned long params_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PDEV_CREATE, pdev_ptr, params_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_pdev_destroy() - Destroy a PDEV
+ * @pdev_ptr: PA of the PDEV
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_pdev_destroy(unsigned long pdev_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PDEV_DESTROY, pdev_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_pdev_get_state() - Get state of a PDEV
+ * @pdev_ptr: PA of the PDEV
+ * @out_state: PDEV state
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_pdev_get_state(unsigned long pdev_ptr,
+				     unsigned long *out_state)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PDEV_GET_STATE, pdev_ptr, &res);
+
+	*out_state = res.a1;
+	return res.a0;
+}
+
+/**
+ * rmi_pdev_ide_key_refresh() - Refresh keys ina n IDE connection
+ * @pdev_ptr: PA of the PDEV
+ * @coh: Select coherent or non-coherent IDE stream
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_pdev_ide_key_refresh(unsigned long pdev_ptr,
+					   unsigned long coh)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PDEV_IDE_KEY_REFRESH, pdev_ptr, coh, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_pdev_ide_reset() - Reset the IDE link of a PDEV
+ * @pdev_ptr: PA of the PDEV
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_pdev_ide_reset(unsigned long pdev_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PDEV_IDE_RESET, pdev_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_pdev_p2p_connect() - Create a P2P stream between two PDEVs
+ * @stream_ptr: PA of the P2P_STREAM object
+ * @pdev_1_ptr: PA of the first PDEV object
+ * @pdev_2_ptr: PA of the second PDEV object
+ * @ide_sid: IDE stream ID
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_pdev_p2p_connect(unsigned long stream_ptr,
+				       unsigned long pdev_1_ptr,
+				       unsigned long pdev_2_ptr,
+				       unsigned long ide_sid)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PDEV_P2P_CONNECT, stream_ptr,
+			     pdev_1_ptr, pdev_2_ptr, ide_sid, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_pdev_p2p_disconnect() - Destroy a P2P stream between two PDEVs
+ * @stream_ptr: PA of the P2P_STREAM object
+ * @pdev_1_ptr: PA of the first PDEV object
+ * @pdev_2_ptr: PA of the second PDEV object
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_pdev_p2p_disconnect(unsigned long stream_ptr,
+					  unsigned long pdev_1_ptr,
+					  unsigned long pdev_2_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PDEV_P2P_DISCONNECT, stream_ptr,
+			     pdev_1_ptr, pdev_2_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_pdev_set_pubkey() - Provide public key associated with a PDEV
+ * @pdev_ptr: PA of the PDEV
+ * @params_ptr: PA of the key parameters
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_pdev_set_pubkey(unsigned long pdev_ptr,
+				      unsigned long params_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PDEV_SET_PUBKEY, pdev_ptr, params_ptr,
+			     &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_pdev_stop() - Stop a PDEV
+ * @pdev_ptr: PA of the PDEV
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_pdev_stop(unsigned long pdev_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PDEV_STOP, pdev_ptr, &res);
+
+	return res.a0;
+}
+
 /**
  * rmi_psci_complete() - Complete pending PSCI command
  * @calling_rec: PA of the calling REC
@@ -165,6 +403,76 @@ static inline int rmi_psci_complete(unsigned long calling_rec,
 	return res.a0;
 }
 
+/**
+ * rmi_psmmu_irq_notify() - Notify the RM of an SMMU interrupt
+ * @psmmu: PA of the PSMMU
+ * @irq: SMMU IRQ
+ * @out_action: Action required by host
+ * @out_rd: PA of RD
+ * @out_vsmmu: PA of VSMMU
+ * @out_msi_addr: MSI address
+ * @out_msi_data: MSI data
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_psmmu_irq_notify(unsigned long psmmu,
+				       unsigned long irq,
+				       unsigned long *out_action,
+				       unsigned long *out_rd,
+				       unsigned long *out_vsmmu,
+				       unsigned long *out_msi_addr,
+				       unsigned long *out_msi_data)
+{
+	struct arm_smccc_1_2_regs regs = {
+		SMC_RMI_PSMMU_IRQ_NOTIFY,
+		psmmu,
+		irq
+	};
+
+	arm_smccc_1_2_smc(&regs, &regs);
+
+	*out_action = regs.a1;
+	*out_rd = regs.a2;
+	*out_vsmmu = regs.a3;
+	*out_msi_addr = regs.a4;
+	*out_msi_data = regs.a5;
+
+	return regs.a0;
+}
+
+/**
+ * rmi_psmmu_msi_config() - Program the MSI config for SMMU
+ * @psmmu: PA of PSMMU
+ * @gerr_addr: MSI address of the GERROR interrupt
+ * @gerr_data: MSI data of the GERROR interrupt
+ * @eventq_addr: MSI address of the EVENTQ interrupt
+ * @eventq_data: MSI data of the EVENTQ interrupt
+ * @priq_addr: MSI address of the PRIQ interrupt
+ * @priq_data: MSI data of the PRIQ interrupt
+ *
+ * Programs the MSI configuration for the realm side of the physical SMMU.
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_psmmu_msi_config(unsigned long psmmu,
+				       unsigned long gerr_addr,
+				       unsigned long gerr_data,
+				       unsigned long eventq_addr,
+				       unsigned long eventq_data,
+				       unsigned long priq_addr,
+				       unsigned long priq_data)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_PSMMU_MSI_CONFIG, psmmu,
+			     gerr_data, gerr_data,
+			     eventq_addr, eventq_data,
+			     priq_addr, priq_data,
+			     &res);
+
+	return res.a0;
+}
+
 /**
  * rmi_realm_activate() - Active a realm
  * @rd: PA of the RD
@@ -297,49 +605,51 @@ static inline int rmi_rec_enter(unsigned long rec, unsigned long run_ptr)
 }
 
 /**
- * rmi_rtt_create() - Creates an RTT
+ * rmi_rtt_aux_create() - Creates an auxiliary RTT
  * @rd: PA of the RD
  * @rtt: PA of the target RTT
  * @ipa: Base of the IPA range described by the RTT
- * @level: Depth of the RTT within the tree
- *
- * Creates an RTT (Realm Translation Table) at the specified level for the
- * translation of the specified address within the realm.
+ * @level: RTT level
+ * @index: RTT tree index
  *
  * Return: RMI return code
  */
-static inline int rmi_rtt_create(unsigned long rd, unsigned long rtt,
-				 unsigned long ipa, long level)
+static inline int rmi_rtt_aux_create(unsigned long rd,
+				     unsigned long rtt,
+				     unsigned long ipa,
+				     long level,
+				     unsigned long index)
 {
 	struct arm_smccc_res res;
 
-	arm_smccc_1_1_invoke(SMC_RMI_RTT_CREATE, rd, rtt, ipa, level, &res);
+	arm_smccc_1_1_invoke(SMC_RMI_RTT_AUX_CREATE, rd, rtt, ipa, level, index,
+			     &res);
 
 	return res.a0;
 }
 
 /**
- * rmi_rtt_destroy() - Destroy an RTT
+ * rmi_rtt_aux_destroy() - Destroys an auxiliary RTT
  * @rd: PA of the RD
- * @ipa: Base of the IPA range described by the RTT
- * @level: Depth of the RTT within the tree
- * @out_rtt: Pointer to write the PA of the RTT which was destroyed
- * @out_top: Pointer to write the top IPA of non-live RTT entries
+ * @ipa: Base of the IPA range describe dby the RTT
+ * @level: RTT level
+ * @index: RTT tree index
+ * @out_rtt: PA of the RTT which was destroyed
+ * @out_top: Top IPA of non-live RTT entries
  *
- * Destroys an RTT. The RTT must be non-live, i.e. none of the entries in the
- * table are in ASSIGNED or TABLE state.
- *
- * Return: RMI return code.
+ * Return: RMI return code
  */
-static inline int rmi_rtt_destroy(unsigned long rd,
-				  unsigned long ipa,
-				  long level,
-				  unsigned long *out_rtt,
-				  unsigned long *out_top)
+static inline int rmi_rtt_aux_destroy(unsigned long rd,
+				      unsigned long ipa,
+				      long level,
+				      unsigned long index,
+				      unsigned long *out_rtt,
+				      unsigned long *out_top)
 {
 	struct arm_smccc_res res;
 
-	arm_smccc_1_1_invoke(SMC_RMI_RTT_DESTROY, rd, ipa, level, &res);
+	arm_smccc_1_1_invoke(SMC_RMI_RTT_AUX_DESTROY, rd, ipa, level, index,
+			     &res);
 
 	if (out_rtt)
 		*out_rtt = res.a1;
@@ -350,23 +660,24 @@ static inline int rmi_rtt_destroy(unsigned long rd,
 }
 
 /**
- * rmi_rtt_fold() - Fold an RTT
+ * rmi_rtt_aux_fold() - Destroy a homogeneous auxility RTT
  * @rd: PA of the RD
  * @ipa: Base of the IPA range described by the RTT
- * @level: Depth of the RTT within the tree
- * @out_rtt: Pointer to write the PA of the RTT which was destroyed
- *
- * Folds an RTT. If all entries with the RTT are 'homogeneous' the RTT can be
- * folded into the parent and the RTT destroyed.
+ * @level: RTT level
+ * @index: RTT tree index
+ * @out_rtt: PA of the RTT which was destroyed
  *
  * Return: RMI return code
  */
-static inline int rmi_rtt_fold(unsigned long rd, unsigned long ipa,
-			       long level, unsigned long *out_rtt)
+static inline int rmi_rtt_aux_fold(unsigned long rd,
+				   unsigned long ipa,
+				   long level,
+				   unsigned long index,
+				   unsigned long *out_rtt)
 {
 	struct arm_smccc_res res;
 
-	arm_smccc_1_1_invoke(SMC_RMI_RTT_FOLD, rd, ipa, level, &res);
+	arm_smccc_1_1_invoke(SMC_RMI_RTT_AUX_FOLD, rd, ipa, level, index, &res);
 
 	if (out_rtt)
 		*out_rtt = res.a1;
@@ -375,75 +686,254 @@ static inline int rmi_rtt_fold(unsigned long rd, unsigned long ipa,
 }
 
 /**
- * rmi_rtt_init_ripas() - Set RIPAS for new realm
+ * rmi_rtt_aux_map_protected() - Create a protected mapping in an aux RTT
  * @rd: PA of the RD
- * @base: Base of target IPA region
- * @top: Top of target IPA region
- * @out_top: Top IPA of range whose RIPAS was modified
- *
- * Sets the RIPAS of a target IPA range to RAM, for a realm in the NEW state.
+ * @ipa: IPA in the target realm
+ * @index: RTT tree index
+ * @out_state: State of RTT entry which caused command to fail
+ * @out_ripas: RIPAS of RTT entry which caused command to fail
  *
  * Return: RMI return code
  */
-static inline int rmi_rtt_init_ripas(unsigned long rd, unsigned long base,
-				     unsigned long top, unsigned long *out_top)
+static inline int rmi_rtt_aux_map_protected(unsigned long rd,
+					    unsigned long ipa,
+					    unsigned long index,
+					    unsigned long *out_state,
+					    unsigned long *out_ripas)
 {
-	struct arm_smccc_res res;
+	struct arm_smccc_1_2_regs regs = {
+		SMC_RMI_RTT_AUX_MAP_PROTECTED,
+		rd, ipa, index
+	};
 
-	arm_smccc_1_1_invoke(SMC_RMI_RTT_INIT_RIPAS, rd, base, top, &res);
+	arm_smccc_1_2_smc(&regs, &regs);
 
-	if (out_top)
-		*out_top = res.a1;
+	if (out_state)
+		*out_state = regs.a1;
+	if (out_ripas)
+		*out_ripas = regs.a2;
 
-	return res.a0;
+	return regs.a0;
 }
 
 /**
- * rmi_rtt_map_unprotected() - Map NS granules into a realm
+ * rmi_rtt_aux_map_unprotected() - Create an unprotected mapping in an aux RTT
  * @rd: PA of the RD
- * @ipa: Base IPA of the mapping
- * @level: Depth within the RTT tree
- * @desc: RTTE descriptor
- *
- * Create a mapping from an Unprotected IPA to a Non-secure PA.
+ * @ipa: IPA in the target realm
+ * @index: RTT tree index
  *
  * Return: RMI return code
  */
-static inline int rmi_rtt_map_unprotected(unsigned long rd,
-					  unsigned long ipa,
-					  long level,
-					  unsigned long desc)
+static inline int rmi_rtt_aux_map_unprotected(unsigned long rd,
+					      unsigned long ipa,
+					      unsigned long index)
 {
 	struct arm_smccc_res res;
 
-	arm_smccc_1_1_invoke(SMC_RMI_RTT_MAP_UNPROTECTED, rd, ipa, level,
-			     desc, &res);
+	arm_smccc_1_1_invoke(SMC_RMI_RTT_AUX_MAP_UNPROTECTED, rd, ipa, index,
+			     &res);
 
 	return res.a0;
 }
 
 /**
- * rmi_rtt_read_entry() - Read an RTTE
+ * rmi_rtt_aux_unmap_protected() - Remove a protected mapping in an aux RTT
  * @rd: PA of the RD
- * @ipa: IPA for which to read the RTTE
- * @level: RTT level at which to read the RTTE
- * @rtt: Output structure describing the RTTE
- *
- * Reads a RTTE (Realm Translation Table Entry).
+ * @ipa: IPA in the target realm
+ * @index: RTT tree index
+ * @out_top: Top IPA of non-live RTT entry
  *
  * Return: RMI return code
  */
-static inline int rmi_rtt_read_entry(unsigned long rd, unsigned long ipa,
-				     long level, struct rtt_entry *rtt)
+static inline int rmi_rtt_aux_unmap_protected(unsigned long rd,
+					      unsigned long ipa,
+					      unsigned long index,
+					      unsigned long *out_top)
 {
-	struct arm_smccc_1_2_regs regs = {
-		SMC_RMI_RTT_READ_ENTRY,
-		rd, ipa, level
-	};
+	struct arm_smccc_res res;
 
-	arm_smccc_1_2_invoke(&regs, &regs);
+	arm_smccc_1_1_invoke(SMC_RMI_RTT_AUX_UNMAP_PROTECTED, rd, ipa, index,
+			     &res);
 
-	rtt->walk_level = regs.a1;
+	if (out_top)
+		*out_top = res.a1;
+
+	return res.a0;
+}
+
+/**
+ * rmi_rtt_aux_unmap_unprotected() - Remove an unprotected mapping in an aux RTT
+ * @rd: PA of the RD
+ * @ipa: IPA in the target realm
+ * @index: RTT tree index
+ * @out_top: Top IPA of non-live RTT entry
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_rtt_aux_unmap_unprotected(unsigned long rd,
+						unsigned long ipa,
+						unsigned long index,
+						unsigned long *out_top)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_RTT_AUX_UNMAP_UNPROTECTED, rd, ipa, index,
+			     &res);
+
+	if (out_top)
+		*out_top = res.a1;
+
+	return res.a0;
+}
+
+/**
+ * rmi_rtt_create() - Creates an RTT
+ * @rd: PA of the RD
+ * @rtt: PA of the target RTT
+ * @ipa: Base of the IPA range described by the RTT
+ * @level: Depth of the RTT within the tree
+ *
+ * Creates an RTT (Realm Translation Table) at the specified level for the
+ * translation of the specified address within the realm.
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_rtt_create(unsigned long rd, unsigned long rtt,
+				 unsigned long ipa, long level)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_RTT_CREATE, rd, rtt, ipa, level, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_rtt_destroy() - Destroy an RTT
+ * @rd: PA of the RD
+ * @ipa: Base of the IPA range described by the RTT
+ * @level: Depth of the RTT within the tree
+ * @out_rtt: Pointer to write the PA of the RTT which was destroyed
+ * @out_top: Pointer to write the top IPA of non-live RTT entries
+ *
+ * Destroys an RTT. The RTT must be non-live, i.e. none of the entries in the
+ * table are in ASSIGNED or TABLE state.
+ *
+ * Return: RMI return code.
+ */
+static inline int rmi_rtt_destroy(unsigned long rd,
+				  unsigned long ipa,
+				  long level,
+				  unsigned long *out_rtt,
+				  unsigned long *out_top)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_RTT_DESTROY, rd, ipa, level, &res);
+
+	if (out_rtt)
+		*out_rtt = res.a1;
+	if (out_top)
+		*out_top = res.a2;
+
+	return res.a0;
+}
+
+/**
+ * rmi_rtt_fold() - Fold an RTT
+ * @rd: PA of the RD
+ * @ipa: Base of the IPA range described by the RTT
+ * @level: Depth of the RTT within the tree
+ * @out_rtt: Pointer to write the PA of the RTT which was destroyed
+ *
+ * Folds an RTT. If all entries with the RTT are 'homogeneous' the RTT can be
+ * folded into the parent and the RTT destroyed.
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_rtt_fold(unsigned long rd, unsigned long ipa,
+			       long level, unsigned long *out_rtt)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_RTT_FOLD, rd, ipa, level, &res);
+
+	if (out_rtt)
+		*out_rtt = res.a1;
+
+	return res.a0;
+}
+
+/**
+ * rmi_rtt_init_ripas() - Set RIPAS for new realm
+ * @rd: PA of the RD
+ * @base: Base of target IPA region
+ * @top: Top of target IPA region
+ * @out_top: Top IPA of range whose RIPAS was modified
+ *
+ * Sets the RIPAS of a target IPA range to RAM, for a realm in the NEW state.
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_rtt_init_ripas(unsigned long rd, unsigned long base,
+				     unsigned long top, unsigned long *out_top)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_RTT_INIT_RIPAS, rd, base, top, &res);
+
+	if (out_top)
+		*out_top = res.a1;
+
+	return res.a0;
+}
+
+/**
+ * rmi_rtt_map_unprotected() - Map NS granules into a realm
+ * @rd: PA of the RD
+ * @ipa: Base IPA of the mapping
+ * @level: Depth within the RTT tree
+ * @desc: RTTE descriptor
+ *
+ * Create a mapping from an Unprotected IPA to a Non-secure PA.
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_rtt_map_unprotected(unsigned long rd,
+					  unsigned long ipa,
+					  long level,
+					  unsigned long desc)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_RTT_MAP_UNPROTECTED, rd, ipa, level,
+			     desc, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_rtt_read_entry() - Read an RTTE
+ * @rd: PA of the RD
+ * @ipa: IPA for which to read the RTTE
+ * @level: RTT level at which to read the RTTE
+ * @rtt: Output structure describing the RTTE
+ *
+ * Reads a RTTE (Realm Translation Table Entry).
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_rtt_read_entry(unsigned long rd, unsigned long ipa,
+				     long level, struct rtt_entry *rtt)
+{
+	struct arm_smccc_1_2_regs regs = {
+		SMC_RMI_RTT_READ_ENTRY,
+		rd, ipa, level
+	};
+
+	arm_smccc_1_2_invoke(&regs, &regs);
+
+	rtt->walk_level = regs.a1;
 	rtt->state = regs.a2 & 0xFF;
 	rtt->desc = regs.a3;
 	rtt->ripas = regs.a4 & 0xFF;
@@ -478,6 +968,38 @@ static inline int rmi_rtt_set_ripas(unsigned long rd, unsigned long rec,
 	return res.a0;
 }
 
+/**
+ * rmi_rtt_set_s2ap() - Change the S2AP of a target IPA range
+ * @rd: PA of the RD
+ * @rec_ptr: PA of the target REC
+ * @base: Base of target IPA region
+ * @top: Top of target IPA region
+ * @out_top: Top IPA of range whose S2AP was modified
+ * @out_rtt_tree: Index of RTT tree in which base alignment check failed
+ *
+ * Completes a request made by the realm to change the S2AP of a target IPA
+ * range.
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_rtt_set_s2ap(unsigned long rd, unsigned long rec_ptr,
+				   unsigned long base, unsigned long top,
+				   unsigned long *out_top,
+				   unsigned long *out_rtt_tree)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_RTT_SET_S2AP, rd, rec_ptr, base, top,
+			     &res);
+
+	if (out_top)
+		*out_top = res.a1;
+	if (out_rtt_tree)
+		*out_rtt_tree = res.a2;
+
+	return res.a0;
+}
+
 /**
  * rmi_rtt_unmap_unprotected() - Remove a NS mapping
  * @rd: PA of the RD
@@ -505,4 +1027,444 @@ static inline int rmi_rtt_unmap_unprotected(unsigned long rd,
 	return res.a0;
 }
 
+/**
+ * rmi_vdev_abort() - Abort device communication associated with a VDEV
+ * @vdev_ptr: PA of the VDEV
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_abort(unsigned long vdev_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_ABORT, vdev_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_aux_count() - Get number of aux granules required for a VDEV
+ * @pdev_flags: PDEV flags
+ * @vdev_flags: VDEV flags
+ * @out_aux_count: Number of auxiliary granules required
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_aux_count(unsigned long pdev_flags,
+				     unsigned long vdev_flags,
+				     unsigned long *out_aux_count)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_AUX_COUNT, pdev_flags, vdev_flags,
+			     &res);
+
+	*out_aux_count = res.a1;
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_communicate() - Perform device communication with a VDEV
+ * @pdev_ptr: PA of the PDEV
+ * @vdev_ptr: PA of the VDEV
+ * @data_ptr: PA of the comms data structure
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_communicate(unsigned long pdev_ptr,
+				       unsigned long vdev_ptr,
+				       unsigned long data_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_COMMUNICATE, pdev_ptr, vdev_ptr,
+			     data_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_complete() - Complete a pending VDEV request
+ * @rec_ptr: PA of the REC
+ * @vdev_ptr: PA of the VDEV
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_complete(unsigned long rec_ptr,
+				    unsigned long vdev_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_COMPLETE, rec_ptr, vdev_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_create() - Create a VDEV
+ * @rd: PA of the RD
+ * @pdev_ptr: PA of the PDEV
+ * @vdev_ptr: PA of the VDEV
+ * @params_ptr: PA of VDEV parameters
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_create(unsigned long rd,
+				  unsigned long pdev_ptr,
+				  unsigned long vdev_ptr,
+				  unsigned long params_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_CREATE, rd, pdev_ptr, vdev_ptr,
+			     params_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_destroy() - Destroy a VDEV
+ * @rd: PA of the RD
+ * @pdev_ptr: PA of the PDEV
+ * @vdev_ptr: PA of the VDEV
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_destroy(unsigned long rd,
+				   unsigned long pdev_ptr,
+				   unsigned long vdev_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_DESTROY, rd, pdev_ptr, vdev_ptr,
+			     &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_get_interface_report() - Get VDEV interface report
+ * @rd: PA of the RD
+ * @vdev_ptr: PA of the VDEV
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_get_interface_report(unsigned long rd,
+						unsigned long vdev_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_GET_INTERFACE_REPORT, rd, vdev_ptr,
+			     &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_get_measurements() - Get VDEV measurements
+ * @rd: PA of the RD
+ * @vdev_ptr: PA of the VDEV
+ * @params_ptr: PA of VDEV parameters
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_get_measurements(unsigned long rd,
+					    unsigned long vdev_ptr,
+					    unsigned long params_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_GET_MEASUREMENTS, rd, vdev_ptr,
+			     params_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_get_state() - Get state of a VDEV
+ * @vdev_ptr: PA of the VDEV
+ * @out_state: VDEV state
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_get_state(unsigned long vdev_ptr,
+				     unsigned long *out_state)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_GET_STATE, vdev_ptr, &res);
+
+	*out_state = res.a1;
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_lock() - Lock VDEV
+ * @rd: PA of the RD
+ * @vdev_ptr: PA of the VDEV
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_lock(unsigned long rd,
+				unsigned long vdev_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_LOCK, rd, vdev_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_map() - Maps device memory
+ * @rd: PA of the RD for the target realm
+ * @vdev_ptr: PA of the VDEV
+ * @ipa: IPA at which the memory will be mapped in the target realm
+ * @level: RTT level
+ * @addr: PA of the target device memory
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_map(unsigned long rd, unsigned long vdev_ptr,
+			       unsigned long ipa, long level,
+			       unsigned long addr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_MAP, rd, vdev_ptr, ipa, level, addr,
+			     &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_p2p_bind() - Create a P2P binding between two VDEVs
+ * @stream_ptr: PA of the P2P_STREAM object
+ * @rd: PA of the RD
+ * @rec_ptr: PA of the target REC
+ * @pdev_1_ptr: PA of the first PDEV object
+ * @pdev_2_ptr: PA of the second PDEV object
+ * @vdev_1_ptr: PA of the first VDEV object
+ * @vdev_2_ptr: PA of the second VDEV object
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_p2p_bind(unsigned long stream_ptr,
+				    unsigned long rd,
+				    unsigned long rec_ptr,
+				    unsigned long pdev_1_ptr,
+				    unsigned long pdev_2_ptr,
+				    unsigned long vdev_1_ptr,
+				    unsigned long vdev_2_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_P2P_BIND, stream_ptr, rd, rec_ptr,
+			     pdev_1_ptr, pdev_2_ptr,
+			     vdev_1_ptr, vdev_2_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_p2p_unbind() - Remove a P2P binding between two VDEVs
+ * @stream_ptr: PA of the P2P_STREAM object
+ * @rd: PA of the RD
+ * @rec_ptr: PA of the target REC
+ * @pdev_1_ptr: PA of the first PDEV object
+ * @pdev_2_ptr: PA of the second PDEV object
+ * @vdev_1_ptr: PA of the first VDEV object
+ * @vdev_2_ptr: PA of the second VDEV object
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_p2p_unbind(unsigned long stream_ptr,
+				      unsigned long rd,
+				      unsigned long rec_ptr,
+				      unsigned long pdev_1_ptr,
+				      unsigned long pdev_2_ptr,
+				      unsigned long vdev_1_ptr,
+				      unsigned long vdev_2_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_P2P_UNBIND, stream_ptr, rd, rec_ptr,
+			     pdev_1_ptr, pdev_2_ptr,
+			     vdev_1_ptr, vdev_2_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_start() - Start a VDEV
+ * @rd: PA of the RD
+ * @vdev_ptr: PA of the VDEV
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_start(unsigned long rd, unsigned long vdev_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_START, rd, vdev_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_unlock() - Unlock a VDEV
+ * @rd: PA of the RD
+ * @vdev_ptr: PA of the VDEV
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_unlock(unsigned long rd, unsigned long vdev_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_UNLOCK, rd, vdev_ptr, &res);
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_unmap() - Unmap device memory
+ * @rd: PA of the RD which owns the target device memory
+ * @vdev_ptr: PA of the VDEV
+ * @ipa: IPA at which the memory is mapped in the target realm
+ * @level: RTT level
+ * @out_pa: PA of the device memory which was unmapped
+ * @out_top: Top IPA of non-live RTT entries
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_unmap(unsigned long rd, unsigned long vdev_ptr,
+				 unsigned long ipa, long level,
+				 unsigned long *out_pa, unsigned long *out_top)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_UNMAP, rd, vdev_ptr, ipa, level,
+			     &res);
+
+	if (out_pa)
+		*out_pa = res.a1;
+	if (out_top)
+		*out_top = res.a2;
+
+	return res.a0;
+}
+
+/**
+ * rmi_vdev_validate_mapping() - Complete a request to valid mappings
+ * @rd: PA of the RD for the target realm
+ * @rec_ptr: PA of the target REC
+ * @pdev_ptr: PA of the PDEV
+ * @vdev_ptr: PA of the VDEV
+ * @base: Base of target IPA region
+ * @top: Top of target IPA region
+ * @out_top: Top IPA of range whose RIPAS was modified
+ *
+ * Completes a request made by the realm to validate mappings to device memory
+ * from a target IPA range.
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vdev_validate_mapping(unsigned long rd,
+					    unsigned long rec_ptr,
+					    unsigned long pdev_ptr,
+					    unsigned long vdev_ptr,
+					    unsigned long base,
+					    unsigned long top,
+					    unsigned long *out_top)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VDEV_VALIDATE_MAPPING, rd, rec_ptr,
+			     pdev_ptr, vdev_ptr, base, top, &res);
+
+	if (out_top)
+		*out_top = res.a1;
+
+	return res.a0;
+}
+
+/** rmi_vsmmu_create() - Create a VSMMU
+ * @rd: PA of the RD
+ * @vsmmu_ptr: PA of the VSMMU
+ * @params_ptr: PA of VSMMU parameters
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vsmmu_create(unsigned long rd,
+				   unsigned long vsmmu_ptr,
+				   unsigned long params_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VSMMU_CREATE, rd, vsmmu_ptr,
+			     params_ptr, &res);
+
+	return res.a0;
+}
+
+/** rmi_vsmmu_destroy() - Destroy a VSMMU
+ * @rd: PA of the RD
+ * @vsmmu_ptr: PA of the VSMMU
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vsmmu_destroy(unsigned long rd,
+				    unsigned long vsmmu_ptr)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VSMMU_DESTROY, rd, vsmmu_ptr, &res);
+
+	return res.a0;
+}
+
+/** rmi_vsmmu_map() - Create a VSMMU mapping
+ * @rd: PA of the RD
+ * @vsmmu_ptr: PA of the VSMMU
+ * @ipa: IPA at which to create the mapping
+ * @level: RTT level
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vsmmu_map(unsigned long rd,
+				unsigned long vsmmu_ptr,
+				unsigned long ipa,
+				long level)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VSMMU_MAP, rd, vsmmu_ptr, ipa, level,
+			     &res);
+
+	return res.a0;
+}
+
+/** rmi_vsmmu_unmap() - Remove a VSMMU mapping
+ * @rd: PA of the RD
+ * @ipa: IPA at which to remove the mapping
+ * @vsmmu_ptr: PA of the VSMMU
+ * @out_top: Top IPA of non-live RTT entries
+ *
+ * Return: RMI return code
+ */
+static inline int rmi_vsmmu_unmap(unsigned long rd,
+				  unsigned long ipa,
+				  unsigned long vsmmu_ptr,
+				  unsigned long *out_top)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_1_1_invoke(SMC_RMI_VSMMU_UNMAP, rd, ipa, vsmmu_ptr, &res);
+
+	if (out_top)
+		*out_top = res.a1;
+	return res.a0;
+}
+
 #endif /* __ASM_RMI_CMDS_H */
arch/arm64/include/asm/rmi_smc.h +113 -8

209 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

RFC PATCH 2/5 arm64: RME: Handle auxiliary RTT trees

In reply to Steven Price

When a guest is executing with multiple planes, then faults from a plane other than a primary plane can indicate that there are missing entries in the auxiliary RTT trees that need to be populated. Handle this by allocating the necessary tables.

The auxiliary trees also need to be handled when tearing down realm resources, so in these cases iterate over the auxiliary trees to perform the same operations as in the primary tree.

---
 arch/arm64/include/asm/kvm_rme.h |   6 +
 arch/arm64/kvm/mmu.c             |  15 ++-
 arch/arm64/kvm/rme-exit.c        |   6 +-
 arch/arm64/kvm/rme.c             | 206 +++++++++++++++++++++++++++++--
 4 files changed, 213 insertions(+), 20 deletions(-)
arch/arm64/include/asm/kvm_rme.h +6 -0
index 3ed04b309cda..e5c0c8274bf8 100644
@@ -54,6 +54,8 @@ enum realm_state {
  * @num_aux: The number of auxiliary pages required by the RMM
  * @vmid: VMID to be used by the RMM for the realm
  * @ia_bits: Number of valid Input Address bits in the IPA
+ * @num_aux_planes: Number of auxiliary planes
+ * @rtt_tree_pp: True if each plane has its own RTT tree
  */
 struct realm {
 	enum realm_state state;
@@ -64,6 +66,8 @@ struct realm {
 	unsigned long num_aux;
 	unsigned int vmid;
 	unsigned int ia_bits;
+	unsigned int num_aux_planes;
+	bool rtt_tree_pp;
 };
 
 /**
@@ -107,6 +111,8 @@ int kvm_rec_enter(struct kvm_vcpu *vcpu);
 int kvm_rec_pre_enter(struct kvm_vcpu *vcpu);
 int handle_rec_exit(struct kvm_vcpu *vcpu, int rec_run_status);
 
+int realm_aux_map(struct kvm_vcpu *vcpu, phys_addr_t ipa);
+
 void kvm_realm_unmap_range(struct kvm *kvm,
 			   unsigned long ipa,
 			   unsigned long size,
arch/arm64/kvm/mmu.c +12 -3
index a36ece6c3bf2..a433926e214b 100644
@@ -1502,11 +1502,12 @@ static bool kvm_vma_mte_allowed(struct vm_area_struct *vma)
 	return vma->vm_flags & VM_MTE_ALLOWED;
 }
 
-static int realm_map_ipa(struct kvm *kvm, phys_addr_t ipa,
+static int realm_map_ipa(struct kvm_vcpu *vcpu, phys_addr_t ipa,
 			 kvm_pfn_t pfn, unsigned long map_size,
 			 enum kvm_pgtable_prot prot,
 			 struct kvm_mmu_memory_cache *memcache)
 {
+	struct kvm *kvm = vcpu->kvm;
 	struct realm *realm = &kvm->arch.realm;
 
 	/*
@@ -1517,6 +1518,14 @@ static int realm_map_ipa(struct kvm *kvm, phys_addr_t ipa,
 	if (WARN_ON(!(prot & KVM_PGTABLE_PROT_W)))
 		return -EFAULT;
 
+	if (vcpu->arch.rec.run->exit.rtt_tree > 0) {
+		int ret;
+
+		ret = realm_aux_map(vcpu, ipa);
+		if (ret <= 0)
+			return ret;
+	}
+
 	ipa = ALIGN_DOWN(ipa, PAGE_SIZE);
 	if (!kvm_realm_is_private_address(realm, ipa))
 		return realm_map_non_secure(realm, ipa, pfn, map_size,
@@ -1571,7 +1580,7 @@ static int private_memslot_fault(struct kvm_vcpu *vcpu,
 		return ret;
 
 	/* FIXME: Should be able to use bigger than PAGE_SIZE mappings */
-	ret = realm_map_ipa(kvm, fault_ipa, pfn, PAGE_SIZE, KVM_PGTABLE_PROT_W,
+	ret = realm_map_ipa(vcpu, fault_ipa, pfn, PAGE_SIZE, KVM_PGTABLE_PROT_W,
 			    memcache);
 	if (!ret)
 		return 1; /* Handled */
@@ -1917,7 +1926,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 		prot &= ~KVM_NV_GUEST_MAP_SZ;
 		ret = KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, fault_ipa, prot, flags);
 	} else if (kvm_is_realm(kvm)) {
-		ret = realm_map_ipa(kvm, fault_ipa, pfn, vma_pagesize,
+		ret = realm_map_ipa(vcpu, fault_ipa, pfn, vma_pagesize,
 				    prot, memcache);
 	} else {
 		ret = KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, fault_ipa, vma_pagesize,
arch/arm64/kvm/rme-exit.c +1 -5
index 1a8ca7526863..04c8af8642af 100644
@@ -44,11 +44,7 @@ static int rec_exit_sync_dabt(struct kvm_vcpu *vcpu)
 
 static int rec_exit_sync_iabt(struct kvm_vcpu *vcpu)
 {
-	struct realm_rec *rec = &vcpu->arch.rec;
-
-	vcpu_err(vcpu, "Unhandled instruction abort (ESR: %#llx).\n",
-		 rec->run->exit.esr);
-	return -ENXIO;
+	return kvm_handle_guest_abort(vcpu);
 }
 
 static int rec_exit_sys_reg(struct kvm_vcpu *vcpu)
arch/arm64/kvm/rme.c +194 -12

282 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

RFC PATCH 3/5 arm64: RME: Support RMI_EXIT_S2AP_CHANGE

In reply to Steven Price

If the primary plane of a realm wishes to change the access permissions of memory for the other planes then this causes an exit to the normal world. KVM then must complete the request using RMI_RTT_SET_S2AP which may fail if there are missing RTTs. In this case KVM must allocate the missing RTTs and retry.

---
 arch/arm64/include/asm/kvm_rme.h |  3 +++
 arch/arm64/kvm/rme-exit.c        | 27 +++++++++++++++++++++++++++
 arch/arm64/kvm/rme.c             | 25 +++++++++++++++++++++----
 3 files changed, 51 insertions(+), 4 deletions(-)
arch/arm64/include/asm/kvm_rme.h +3 -0
index e5c0c8274bf8..934b30a8e607 100644
@@ -112,6 +112,9 @@ int kvm_rec_pre_enter(struct kvm_vcpu *vcpu);
 int handle_rec_exit(struct kvm_vcpu *vcpu, int rec_run_status);
 
 int realm_aux_map(struct kvm_vcpu *vcpu, phys_addr_t ipa);
+int kvm_realm_set_s2ap(struct kvm_vcpu *vcpu,
+		       unsigned long start,
+		       unsigned long end);
 
 void kvm_realm_unmap_range(struct kvm *kvm,
 			   unsigned long ipa,
arch/arm64/kvm/rme-exit.c +27 -0
index 04c8af8642af..b7e615f7b3a9 100644
@@ -112,6 +112,31 @@ static int rec_exit_ripas_change(struct kvm_vcpu *vcpu)
 	return -EFAULT;
 }
 
+static int rec_exit_s2ap_change(struct kvm_vcpu *vcpu)
+{
+	struct kvm *kvm = vcpu->kvm;
+	struct realm *realm = &kvm->arch.realm;
+	struct realm_rec *rec = &vcpu->arch.rec;
+	unsigned long base = rec->run->exit.s2ap_base;
+	unsigned long top = rec->run->exit.s2ap_top;
+	int ret = -EINVAL;
+
+	if (kvm_realm_is_private_address(realm, base) &&
+	    kvm_realm_is_private_address(realm, top)) {
+		kvm_mmu_topup_memory_cache(&vcpu->arch.mmu_page_cache,
+					   kvm_mmu_cache_min_pages(vcpu->arch.hw_mmu));
+		write_lock(&kvm->mmu_lock);
+		ret = kvm_realm_set_s2ap(vcpu, base, top);
+		write_unlock(&kvm->mmu_lock);
+	}
+
+	WARN_RATELIMIT(ret && ret != -ENOMEM,
+		       "Unable to satisfy SET_S2AP for %#lx - %#lx\n",
+		       base, top);
+
+	return 1;
+}
+
 static int rec_exit_host_call(struct kvm_vcpu *vcpu)
 {
 	int i;
@@ -192,6 +217,8 @@ int handle_rec_exit(struct kvm_vcpu *vcpu, int rec_run_ret)
 		return rec_exit_psci(vcpu);
 	case RMI_EXIT_RIPAS_CHANGE:
 		return rec_exit_ripas_change(vcpu);
+	case RMI_EXIT_S2AP_CHANGE:
+		return rec_exit_s2ap_change(vcpu);
 	case RMI_EXIT_HOST_CALL:
 		return rec_exit_host_call(vcpu);
 	}
arch/arm64/kvm/rme.c +21 -4
index c420546d26f3..fa39a8393d53 100644
@@ -1329,6 +1329,7 @@ static int kvm_populate_realm(struct kvm *kvm,
 enum ripas_action {
 	RIPAS_INIT,
 	RIPAS_SET,
+	SET_S2AP,
 };
 
 static int ripas_change(struct kvm *kvm,
@@ -1348,12 +1349,13 @@ static int ripas_change(struct kvm *kvm,
 		rec_phys = virt_to_phys(vcpu->arch.rec.rec_page);
 		memcache = &vcpu->arch.mmu_page_cache;
 
-		WARN_ON(action != RIPAS_SET);
+		WARN_ON(action == RIPAS_INIT);
 	} else {
 		WARN_ON(action != RIPAS_INIT);
 	}
 
 	while (ipa < end) {
+		unsigned long rtt_tree_idx = 0;
 		unsigned long next;
 
 		switch (action) {
@@ -1364,21 +1366,27 @@ static int ripas_change(struct kvm *kvm,
 			ret = rmi_rtt_set_ripas(rd_phys, rec_phys, ipa, end,
 						&next);
 			break;
+		case SET_S2AP:
+			ret = rmi_rtt_set_s2ap(rd_phys, rec_phys, ipa, end,
+					       &next, &rtt_tree_idx);
+			break;
 		}
 
 		switch (RMI_RETURN_STATUS(ret)) {
 		case RMI_SUCCESS:
 			ipa = next;
 			break;
-		case RMI_ERROR_RTT: {
+		case RMI_ERROR_RTT:
+		case RMI_ERROR_RTT_AUX: {
 			int err_level = RMI_RETURN_INDEX(ret);
 			int level = find_map_level(realm, ipa, end);
 
 			if (err_level >= level)
 				return -EINVAL;
 
-			ret = realm_create_rtt_levels(realm, ipa, err_level,
-						      level, memcache);
+			ret = realm_create_rtt_aux_levels(realm, ipa, err_level,
+							  level, rtt_tree_idx,
+							  memcache);
 			if (ret)
 				return ret;
 			/* Retry with the RTT levels in place */
@@ -1396,6 +1404,15 @@ static int ripas_change(struct kvm *kvm,
 	return 0;
 }
 
+int kvm_realm_set_s2ap(struct kvm_vcpu *vcpu,
+		       unsigned long start,
+		       unsigned long end)
+{
+	struct kvm *kvm = vcpu->kvm;
+
+	return ripas_change(kvm, vcpu, start, end, SET_S2AP, NULL);
+}
+
 static int realm_set_ipa_state(struct kvm_vcpu *vcpu,
 			       unsigned long start,
 			       unsigned long end,
Signature · 1 line
2.43.0
#4 lore raw

RFC PATCH 4/5 arm64: rme: Allocate AUX RTT PGDs and VMIDs

In reply to Steven Price

If using multiple planes then the auxiliary trees also need PGDs allocating for them. Each plane also needs its own VMID.

---
 arch/arm64/include/asm/kvm_rme.h |   4 +-
 arch/arm64/kvm/rme.c             | 133 +++++++++++++++++++++++++++----
 2 files changed, 122 insertions(+), 15 deletions(-)
arch/arm64/include/asm/kvm_rme.h +3 -1
index 934b30a8e607..a9dc24a53c65 100644
@@ -53,6 +53,7 @@ enum realm_state {
  * @params: Parameters for the RMI_REALM_CREATE command
  * @num_aux: The number of auxiliary pages required by the RMM
  * @vmid: VMID to be used by the RMM for the realm
+ * @aux_pgd: The PGDs for the auxiliary planes
  * @ia_bits: Number of valid Input Address bits in the IPA
  * @num_aux_planes: Number of auxiliary planes
  * @rtt_tree_pp: True if each plane has its own RTT tree
@@ -64,7 +65,8 @@ struct realm {
 	struct realm_params *params;
 
 	unsigned long num_aux;
-	unsigned int vmid;
+	unsigned int vmid[4];
+	void *aux_pgd[3];
 	unsigned int ia_bits;
 	unsigned int num_aux_planes;
 	bool rtt_tree_pp;
arch/arm64/kvm/rme.c +119 -14

183 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

RFC PATCH 5/5 arm64: RME: Support num_aux_places & rtt_tree_pp realm parameters

In reply to Steven Price

CCA planes provides new parameters to the VMM:
- num_aux_planes defines the number of extra planes
- rtt_tree_pp controls whether each plane has it's own page table tree, of if they share one tree.

---
 arch/arm64/include/uapi/asm/kvm.h | 12 +++++
 arch/arm64/kvm/rme.c              | 77 +++++++++++++++++++++++++++++--
 2 files changed, 86 insertions(+), 3 deletions(-)
arch/arm64/include/uapi/asm/kvm.h +12 -0
index 9b5d67ecbc5e..1d83da0f3aaa 100644
@@ -440,6 +440,8 @@ enum {
 /* List of configuration items accepted for KVM_CAP_ARM_RME_CONFIG_REALM */
 #define ARM_RME_CONFIG_RPV			0
 #define ARM_RME_CONFIG_HASH_ALGO		1
+#define ARM_RME_CONFIG_NUM_AUX_PLANES		2
+#define ARM_RME_CONFIG_RTT_TREE_PP		3
 
 #define ARM_RME_CONFIG_HASH_ALGO_SHA256		0
 #define ARM_RME_CONFIG_HASH_ALGO_SHA512		1
@@ -459,6 +461,16 @@ struct arm_rme_config {
 			__u32	hash_algo;
 		};
 
+		/* cfg == ARM_RME_CONFIG_NUM_AUX_PLANES */
+		struct {
+			__u32	num_aux_planes;
+		};
+
+		/* cfg == ARM_RME_CONFIG_RTT_TREE_PP */
+		struct {
+			__u32	rtt_tree_pp;
+		};
+
 		/* Fix the size of the union */
 		__u8	reserved[256];
 	};
arch/arm64/kvm/rme.c +74 -3

107 lines not on this page · raw message

Signature · 1 line
2.43.0