All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Philippe Brucker <jean-philippe@linaro.org>
To: peter.maydell@linaro.org
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, pbonzini@redhat.com,
	eblake@redhat.com, armbru@redhat.com, berrange@redhat.com,
	eduardo@habkost.net, alex.bennee@linaro.org,
	richard.henderson@linaro.org,
	Jean-Philippe Brucker <jean-philippe@linaro.org>
Subject: [RFC PATCH 04/16] hw/arm/virt: Add support for Arm RME
Date: Fri, 27 Jan 2023 15:07:17 +0000	[thread overview]
Message-ID: <20230127150727.612594-5-jean-philippe@linaro.org> (raw)
In-Reply-To: <20230127150727.612594-1-jean-philippe@linaro.org>

When confidential-guest-support is enabled for the virt machine, call
the RME init function, and add the RME flag to the VM type.

* The Realm differentiates non-secure from realm memory using the upper
  GPA bit. Reserve that bit when creating the memory map, to make sure
  that device MMIO located in high memory can still fit.

* pvtime is disabled for the moment. Since the hypervisor has to write
  into the shared pvtime page before scheduling a vcpu, it seems
  incompatible with confidential guests.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
 hw/arm/virt.c | 48 ++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index b871350856..df613e634a 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -210,6 +210,11 @@ static const char *valid_cpus[] = {
     ARM_CPU_TYPE_NAME("max"),
 };
 
+static bool virt_machine_is_confidential(VirtMachineState *vms)
+{
+    return MACHINE(vms)->cgs;
+}
+
 static bool cpu_type_valid(const char *cpu)
 {
     int i;
@@ -247,6 +252,14 @@ static void create_fdt(VirtMachineState *vms)
         exit(1);
     }
 
+    /*
+     * Since the devicetree is included in the initial measurement, it must
+     * not contain random data.
+     */
+    if (virt_machine_is_confidential(vms)) {
+        vms->dtb_randomness = false;
+    }
+
     ms->fdt = fdt;
 
     /* Header */
@@ -1924,6 +1937,15 @@ static void virt_cpu_post_init(VirtMachineState *vms, MemoryRegion *sysmem)
     steal_time = object_property_get_bool(OBJECT(first_cpu),
                                           "kvm-steal-time", NULL);
 
+    if (virt_machine_is_confidential(vms)) {
+        /*
+         * The host cannot write into a confidential guest's memory until the
+         * guest shares it. Since the host writes the pvtime region before the
+         * guest gets a chance to set it up, disable pvtime.
+         */
+        steal_time = false;
+    }
+
     if (kvm_enabled()) {
         hwaddr pvtime_reg_base = vms->memmap[VIRT_PVTIME].base;
         hwaddr pvtime_reg_size = vms->memmap[VIRT_PVTIME].size;
@@ -2053,10 +2075,11 @@ static void machvirt_init(MachineState *machine)
      * if the guest has EL2 then we will use SMC as the conduit,
      * and otherwise we will use HVC (for backwards compatibility and
      * because if we're using KVM then we must use HVC).
+     * Realm guests must also use SMC.
      */
     if (vms->secure && firmware_loaded) {
         vms->psci_conduit = QEMU_PSCI_CONDUIT_DISABLED;
-    } else if (vms->virt) {
+    } else if (vms->virt || virt_machine_is_confidential(vms)) {
         vms->psci_conduit = QEMU_PSCI_CONDUIT_SMC;
     } else {
         vms->psci_conduit = QEMU_PSCI_CONDUIT_HVC;
@@ -2102,6 +2125,8 @@ static void machvirt_init(MachineState *machine)
         exit(1);
     }
 
+    kvm_arm_rme_init(machine->cgs, &error_fatal);
+
     create_fdt(vms);
 
     assert(possible_cpus->len == max_cpus);
@@ -2854,15 +2879,26 @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine,
 static int virt_kvm_type(MachineState *ms, const char *type_str)
 {
     VirtMachineState *vms = VIRT_MACHINE(ms);
+    int rme_vm_type = kvm_arm_rme_vm_type(ms);
     int max_vm_pa_size, requested_pa_size;
+    int rme_reserve_bit = 0;
     bool fixed_ipa;
 
-    max_vm_pa_size = kvm_arm_get_max_vm_ipa_size(ms, &fixed_ipa);
+    if (rme_vm_type) {
+        /*
+         * With RME, the upper GPA bit differentiates Realm from NS memory.
+         * Reserve the upper bit to guarantee that highmem devices will fit.
+         */
+        rme_reserve_bit = 1;
+    }
+
+    max_vm_pa_size = kvm_arm_get_max_vm_ipa_size(ms, &fixed_ipa) -
+                     rme_reserve_bit;
 
     /* we freeze the memory map to compute the highest gpa */
     virt_set_memmap(vms, max_vm_pa_size);
 
-    requested_pa_size = 64 - clz64(vms->highest_gpa);
+    requested_pa_size = 64 - clz64(vms->highest_gpa) + rme_reserve_bit;
 
     /*
      * KVM requires the IPA size to be at least 32 bits.
@@ -2883,7 +2919,11 @@ static int virt_kvm_type(MachineState *ms, const char *type_str)
      * the implicit legacy 40b IPA setting, in which case the kvm_type
      * must be 0.
      */
-    return fixed_ipa ? 0 : requested_pa_size;
+    if (fixed_ipa) {
+        return 0;
+    }
+
+    return requested_pa_size | rme_vm_type;
 }
 
 static void virt_machine_class_init(ObjectClass *oc, void *data)
-- 
2.39.0



  parent reply	other threads:[~2023-01-27 15:18 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-27 15:07 [RFC PATCH 00/16] arm: Run Arm CCA VMs with KVM Jean-Philippe Brucker
2023-01-27 15:07 ` [RFC PATCH 01/16] NOMERGE: Add KVM Arm RME definitions to Linux headers Jean-Philippe Brucker
2023-01-27 15:07 ` [RFC PATCH 02/16] target/arm: Add confidential guest support Jean-Philippe Brucker
2023-01-27 19:50   ` Richard Henderson
2023-01-28  0:03   ` Philippe Mathieu-Daudé
2023-01-27 15:07 ` [RFC PATCH 03/16] target/arm/kvm-rme: Initialize realm Jean-Philippe Brucker
2023-01-27 20:37   ` Richard Henderson
2023-02-08 12:07     ` Jean-Philippe Brucker
2023-01-27 15:07 ` Jean-Philippe Brucker [this message]
2023-01-27 21:07   ` [RFC PATCH 04/16] hw/arm/virt: Add support for Arm RME Richard Henderson
2023-02-08 12:08     ` Jean-Philippe Brucker
2023-01-27 15:07 ` [RFC PATCH 05/16] target/arm/kvm: Split kvm_arch_get/put_registers Jean-Philippe Brucker
2023-01-27 22:16   ` Richard Henderson
2023-01-27 15:07 ` [RFC PATCH 06/16] target/arm/kvm-rme: Initialize vCPU Jean-Philippe Brucker
2023-01-27 22:19   ` Richard Henderson
2023-01-27 22:37   ` Richard Henderson
2023-02-08 12:09     ` Jean-Philippe Brucker
2023-01-27 23:04   ` Richard Henderson
2023-01-27 15:07 ` [RFC PATCH 07/16] target/arm/kvm: Select RME VM type for the scratch VM Jean-Philippe Brucker
2023-01-27 22:39   ` Richard Henderson
2023-01-27 15:07 ` [RFC PATCH 08/16] target/arm/kvm-rme: Populate the realm with boot images Jean-Philippe Brucker
2023-01-27 23:54   ` Richard Henderson
2023-02-08 12:10     ` Jean-Philippe Brucker
2023-01-27 15:07 ` [RFC PATCH 09/16] hw/arm/boot: Populate realm memory " Jean-Philippe Brucker
2023-01-27 15:07 ` [RFC PATCH 10/16] target/arm/kvm-rme: Add measurement algorithm property Jean-Philippe Brucker
2023-01-28  0:04   ` Richard Henderson
2023-01-27 15:07 ` [RFC PATCH 11/16] target/arm/kvm-rme: Add Realm Personalization Value parameter Jean-Philippe Brucker
2023-01-28  0:07   ` Richard Henderson
2023-01-27 15:07 ` [RFC PATCH 12/16] target/arm/kvm-rme: Add Realm SVE vector length Jean-Philippe Brucker
2023-01-28  0:22   ` Richard Henderson
2023-01-28  0:31   ` Richard Henderson
2023-01-27 15:07 ` [RFC PATCH 13/16] target/arm/kvm-rme: Add breakpoints and watchpoints parameters Jean-Philippe Brucker
2023-01-28  0:33   ` Richard Henderson
2023-01-27 15:07 ` [RFC PATCH 14/16] target/arm/kvm-rme: Add PMU num counters parameters Jean-Philippe Brucker
2023-01-28  0:34   ` Richard Henderson
2023-01-27 15:07 ` [RFC PATCH 15/16] target/arm/kvm: Disable Realm reboot Jean-Philippe Brucker
2023-01-28  0:35   ` Richard Henderson
2023-01-27 15:07 ` [RFC PATCH 16/16] target/arm/kvm-rme: Disable readonly mappings Jean-Philippe Brucker
2023-01-28  0:54   ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230127150727.612594-5-jean-philippe@linaro.org \
    --to=jean-philippe@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.