[RFC kvmtool 10/31] arm64: Create a realm virtual machine

From: Suzuki K Poulose
Date: Fri Jan 27 2023 - 06:41:37 EST


From: Christoffer Dall <christoffer.dall@xxxxxxx>

Set the machine type to realm when creating a VM via the KVM_CREATE_VM
ioctl.

Signed-off-by: Christoffer Dall <christoffer.dall@xxxxxxx>
[ Alex E: Reworked patch, split the command line option into a different
patch ]
Signed-off-by: Alexandru Elisei <alexandru.elisei@xxxxxxx>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@xxxxxxx>
---
arm/aarch64/kvm.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c
index 25be2f2d..5db4c572 100644
--- a/arm/aarch64/kvm.c
+++ b/arm/aarch64/kvm.c
@@ -131,12 +131,15 @@ int kvm__arch_get_ipa_limit(struct kvm *kvm)
int kvm__get_vm_type(struct kvm *kvm)
{
unsigned int ipa_bits, max_ipa_bits;
- unsigned long max_ipa;
+ unsigned long max_ipa, vm_type;

- /* If we're running on an old kernel, use 0 as the VM type */
+ vm_type = kvm->cfg.arch.is_realm ? \
+ KVM_VM_TYPE_ARM_REALM : KVM_VM_TYPE_ARM_NORMAL;
+
+ /* If we're running on an old kernel, use 0 as the IPA bits */
max_ipa_bits = kvm__arch_get_ipa_limit(kvm);
if (!max_ipa_bits)
- return 0;
+ return vm_type;

/* Otherwise, compute the minimal required IPA size */
max_ipa = kvm->cfg.ram_addr + kvm->cfg.ram_size - 1;
@@ -147,7 +150,8 @@ int kvm__get_vm_type(struct kvm *kvm)
if (ipa_bits > max_ipa_bits)
die("Memory too large for this system (needs %d bits, %d available)", ipa_bits, max_ipa_bits);

- return KVM_VM_TYPE_ARM_IPA_SIZE(ipa_bits);
+ vm_type |= KVM_VM_TYPE_ARM_IPA_SIZE(ipa_bits);
+ return vm_type;
}

void kvm__arch_enable_mte(struct kvm *kvm)
--
2.34.1