* [RFC v2 1/5] [Placeholder] headers: Partial headers update for NV2 enablement
2024-02-09 15:59 [RFC v2 0/5] ARM Nested Virt Support Eric Auger
@ 2024-02-09 15:59 ` Eric Auger
2024-02-09 15:59 ` [RFC v2 2/5] hw/arm: Allow setting KVM vGIC maintenance IRQ Eric Auger
` (5 subsequent siblings)
6 siblings, 0 replies; 17+ messages in thread
From: Eric Auger @ 2024-02-09 15:59 UTC (permalink / raw)
To: eric.auger.pro, eric.auger, qemu-devel, qemu-arm, miguel.luis,
haibo.xu, peter.maydell, richard.henderson, maz, gkulkarni
From: Haibo Xu <haibo.xu@linaro.org>
For now let's only import the pieces needed to run NV on KVM.
Later on this will be replaced by a standard and comprehensive
linux header update using scripts/update-linux-headers.sh.
For now the changes are taken from
https://github.com/eauger/linux/tree/nv-6.8-nv2-v11
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
Signed-off-by: Miguel Luis <miguel.luis@oracle.com>
---
| 1 +
| 1 +
2 files changed, 2 insertions(+)
--git a/linux-headers/asm-arm64/kvm.h b/linux-headers/asm-arm64/kvm.h
index c59ea55cd8..d46839f1d9 100644
--- a/linux-headers/asm-arm64/kvm.h
+++ b/linux-headers/asm-arm64/kvm.h
@@ -394,6 +394,7 @@ enum {
#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6
#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7
#define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8
+#define KVM_DEV_ARM_VGIC_GRP_MAINT_IRQ 9
#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10
#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \
(0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)
--git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index 549fea3a97..5af601d7b8 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -1197,6 +1197,7 @@ struct kvm_ppc_resize_hpt {
#define KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE 228
#define KVM_CAP_ARM_SUPPORTED_BLOCK_SIZES 229
#define KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES 230
+#define KVM_CAP_ARM_EL2 231
#ifdef KVM_CAP_IRQ_ROUTING
--
2.41.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [RFC v2 2/5] hw/arm: Allow setting KVM vGIC maintenance IRQ
2024-02-09 15:59 [RFC v2 0/5] ARM Nested Virt Support Eric Auger
2024-02-09 15:59 ` [RFC v2 1/5] [Placeholder] headers: Partial headers update for NV2 enablement Eric Auger
@ 2024-02-09 15:59 ` Eric Auger
2024-03-05 16:46 ` Peter Maydell
2024-02-09 15:59 ` [RFC v2 3/5] target/arm/kvm: Add helper to detect EL2 when using KVM Eric Auger
` (4 subsequent siblings)
6 siblings, 1 reply; 17+ messages in thread
From: Eric Auger @ 2024-02-09 15:59 UTC (permalink / raw)
To: eric.auger.pro, eric.auger, qemu-devel, qemu-arm, miguel.luis,
haibo.xu, peter.maydell, richard.henderson, maz, gkulkarni
From: Haibo Xu <haibo.xu@linaro.org>
Allow virt arm machine to set the intid for the KVM GIC maintenance
interrupt.
Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
Signed-off-by: Miguel Luis <miguel.luis@oracle.com>
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v1 -> v2:
- [Miguel] replaced the has_virt_extensions by the maintenance irq
intid property. [Eric] restored kvm_device_check_attr and
kvm_device_access standard usage and conditionally call those
if the prop is set.
---
hw/arm/virt.c | 3 +++
hw/intc/arm_gicv3_common.c | 1 +
hw/intc/arm_gicv3_kvm.c | 21 +++++++++++++++++++++
include/hw/intc/arm_gicv3_common.h | 1 +
4 files changed, 26 insertions(+)
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 368c2a415a..5214aca898 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -750,6 +750,9 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem)
OBJECT(mem), &error_fatal);
qdev_prop_set_bit(vms->gic, "has-lpi", true);
}
+ } else {
+ qdev_prop_set_uint32(vms->gic, "maintenance-interrupt-id",
+ ARCH_GIC_MAINT_IRQ);
}
} else {
if (!kvm_irqchip_in_kernel()) {
diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c
index cb55c72681..df056dc35c 100644
--- a/hw/intc/arm_gicv3_common.c
+++ b/hw/intc/arm_gicv3_common.c
@@ -564,6 +564,7 @@ static Property arm_gicv3_common_properties[] = {
DEFINE_PROP_UINT32("revision", GICv3State, revision, 3),
DEFINE_PROP_BOOL("has-lpi", GICv3State, lpi_enable, 0),
DEFINE_PROP_BOOL("has-security-extensions", GICv3State, security_extn, 0),
+ DEFINE_PROP_UINT32("maintenance-interrupt-id", GICv3State, maint_irq, 0),
/*
* Compatibility property: force 8 bits of physical priority, even
* if the CPU being emulated should have fewer.
diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c
index 77eb37e131..23fad60515 100644
--- a/hw/intc/arm_gicv3_kvm.c
+++ b/hw/intc/arm_gicv3_kvm.c
@@ -22,6 +22,7 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "hw/intc/arm_gicv3_common.h"
+#include "hw/arm/virt.h"
#include "qemu/error-report.h"
#include "qemu/module.h"
#include "sysemu/kvm.h"
@@ -820,6 +821,26 @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp)
return;
}
+ if (s->maint_irq) {
+ int ret;
+
+ ret = kvm_device_check_attr(s->dev_fd,
+ KVM_DEV_ARM_VGIC_GRP_MAINT_IRQ, 0);
+ if (!ret) {
+ error_setg_errno(errp, errno,
+ "VGICv3 setting maintenance IRQ is not "
+ "supported by this host kernel");
+ return;
+ }
+
+ ret = kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_MAINT_IRQ, 0,
+ &s->maint_irq, true, errp);
+ if (ret) {
+ error_setg_errno(errp, errno, "Failed to set VGIC maintenance IRQ");
+ return;
+ }
+ }
+
multiple_redist_region_allowed =
kvm_device_check_attr(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION);
diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3_common.h
index 4e2fb518e7..4ff421a165 100644
--- a/include/hw/intc/arm_gicv3_common.h
+++ b/include/hw/intc/arm_gicv3_common.h
@@ -246,6 +246,7 @@ struct GICv3State {
uint32_t num_cpu;
uint32_t num_irq;
uint32_t revision;
+ uint32_t maint_irq;
bool lpi_enable;
bool security_extn;
bool force_8bit_prio;
--
2.41.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [RFC v2 2/5] hw/arm: Allow setting KVM vGIC maintenance IRQ
2024-02-09 15:59 ` [RFC v2 2/5] hw/arm: Allow setting KVM vGIC maintenance IRQ Eric Auger
@ 2024-03-05 16:46 ` Peter Maydell
2024-03-25 17:50 ` Eric Auger
2024-03-26 11:04 ` Eric Auger
0 siblings, 2 replies; 17+ messages in thread
From: Peter Maydell @ 2024-03-05 16:46 UTC (permalink / raw)
To: Eric Auger
Cc: eric.auger.pro, qemu-devel, qemu-arm, miguel.luis, haibo.xu,
richard.henderson, maz, gkulkarni
On Fri, 9 Feb 2024 at 16:00, Eric Auger <eric.auger@redhat.com> wrote:
>
> From: Haibo Xu <haibo.xu@linaro.org>
>
> Allow virt arm machine to set the intid for the KVM GIC maintenance
> interrupt.
>
> Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
> Signed-off-by: Miguel Luis <miguel.luis@oracle.com>
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>
> ---
> v1 -> v2:
> - [Miguel] replaced the has_virt_extensions by the maintenance irq
> intid property. [Eric] restored kvm_device_check_attr and
> kvm_device_access standard usage and conditionally call those
> if the prop is set
This seems reasonable, but it's not the same way we opted to
handle telling the kernel the IRQ number for the PMU interrupt
(where we use kvm_arm_pmu_set_irq()). I guess we have to do
it this way because it's a device attr so we need to set it
in gic realize, though?
By the way, does the kernel automatically complain and fail
if we try to enable nested-virt with a GICv2 or with a
userspace GIC, or do we need to catch and produce error
messages for those (invalid) combinations ourselves?
thanks
-- PMM
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC v2 2/5] hw/arm: Allow setting KVM vGIC maintenance IRQ
2024-03-05 16:46 ` Peter Maydell
@ 2024-03-25 17:50 ` Eric Auger
2024-03-26 11:04 ` Eric Auger
1 sibling, 0 replies; 17+ messages in thread
From: Eric Auger @ 2024-03-25 17:50 UTC (permalink / raw)
To: Peter Maydell
Cc: eric.auger.pro, qemu-devel, qemu-arm, miguel.luis, haibo.xu,
richard.henderson, maz, gkulkarni
Hi Peter,
On 3/5/24 17:46, Peter Maydell wrote:
> On Fri, 9 Feb 2024 at 16:00, Eric Auger <eric.auger@redhat.com> wrote:
>> From: Haibo Xu <haibo.xu@linaro.org>
>>
>> Allow virt arm machine to set the intid for the KVM GIC maintenance
>> interrupt.
>>
>> Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
>> Signed-off-by: Miguel Luis <miguel.luis@oracle.com>
>> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>>
>> ---
>> v1 -> v2:
>> - [Miguel] replaced the has_virt_extensions by the maintenance irq
>> intid property. [Eric] restored kvm_device_check_attr and
>> kvm_device_access standard usage and conditionally call those
>> if the prop is set
Please forgive me for the delay
> This seems reasonable, but it's not the same way we opted to
> handle telling the kernel the IRQ number for the PMU interrupt
> (where we use kvm_arm_pmu_set_irq()). I guess we have to do
> it this way because it's a device attr so we need to set it
> in gic realize, though?
This cannot follow the same pattern as the
kvm_arm_pmu_set_irq() because the maintenance irq must be set between before the GICv3 KVM device creation and the
KVM_DEV_ARM_VGIC_CTRL_INIT. The GICv3 realize function calls both so I cannot set the maintenance after the realize. It would fail
with -EBUSY. Hope this helps.
Thanks
Eric
>
> By the way, does the kernel automatically complain and fail
> if we try to enable nested-virt with a GICv2 or with a
> userspace GIC, or do we need to catch and produce error
> messages for those (invalid) combinations ourselves?
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC v2 2/5] hw/arm: Allow setting KVM vGIC maintenance IRQ
2024-03-05 16:46 ` Peter Maydell
2024-03-25 17:50 ` Eric Auger
@ 2024-03-26 11:04 ` Eric Auger
1 sibling, 0 replies; 17+ messages in thread
From: Eric Auger @ 2024-03-26 11:04 UTC (permalink / raw)
To: Peter Maydell
Cc: eric.auger.pro, qemu-devel, qemu-arm, miguel.luis, haibo.xu,
richard.henderson, maz, gkulkarni
Hi Peter,
On 3/5/24 17:46, Peter Maydell wrote:
> On Fri, 9 Feb 2024 at 16:00, Eric Auger <eric.auger@redhat.com> wrote:
>> From: Haibo Xu <haibo.xu@linaro.org>
>>
>> Allow virt arm machine to set the intid for the KVM GIC maintenance
>> interrupt.
>>
>> Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
>> Signed-off-by: Miguel Luis <miguel.luis@oracle.com>
>> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>>
>> ---
>> v1 -> v2:
>> - [Miguel] replaced the has_virt_extensions by the maintenance irq
>> intid property. [Eric] restored kvm_device_check_attr and
>> kvm_device_access standard usage and conditionally call those
>> if the prop is set
> This seems reasonable, but it's not the same way we opted to
> handle telling the kernel the IRQ number for the PMU interrupt
> (where we use kvm_arm_pmu_set_irq()). I guess we have to do
> it this way because it's a device attr so we need to set it
> in gic realize, though?
>
> By the way, does the kernel automatically complain and fail
> if we try to enable nested-virt with a GICv2 or with a
> userspace GIC, or do we need to catch and produce error
> messages for those (invalid) combinations ourselves?
I don't think there is any check of that kind in Marc's series yet.
This may be added if GICv2 KVM device is created while kvm_mode is set
to KVM_MODE_NV.
Wrt userspace irqchip compat, KVM_CAP_ARM_USER_IRQ extension may not be
exposed in case of nested virt.
Marc, is that something you would like to integrate into the kernel series?
Thanks
Eric
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [RFC v2 3/5] target/arm/kvm: Add helper to detect EL2 when using KVM
2024-02-09 15:59 [RFC v2 0/5] ARM Nested Virt Support Eric Auger
2024-02-09 15:59 ` [RFC v2 1/5] [Placeholder] headers: Partial headers update for NV2 enablement Eric Auger
2024-02-09 15:59 ` [RFC v2 2/5] hw/arm: Allow setting KVM vGIC maintenance IRQ Eric Auger
@ 2024-02-09 15:59 ` Eric Auger
2024-02-09 18:54 ` Philippe Mathieu-Daudé
2024-02-09 15:59 ` [RFC v2 4/5] target/arm: Enable feature ARM_FEATURE_EL2 if EL2 is supported Eric Auger
` (3 subsequent siblings)
6 siblings, 1 reply; 17+ messages in thread
From: Eric Auger @ 2024-02-09 15:59 UTC (permalink / raw)
To: eric.auger.pro, eric.auger, qemu-devel, qemu-arm, miguel.luis,
haibo.xu, peter.maydell, richard.henderson, maz, gkulkarni
From: Haibo Xu <haibo.xu@linaro.org>
Introduce query support for KVM_CAP_ARM_EL2.
Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
Signed-off-by: Miguel Luis <miguel.luis@oracle.com>
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
target/arm/kvm.c | 5 +++++
target/arm/kvm_arm.h | 12 ++++++++++++
2 files changed, 17 insertions(+)
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index 81813030a5..0996866afe 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -1791,6 +1791,11 @@ bool kvm_arm_aarch32_supported(void)
return kvm_check_extension(kvm_state, KVM_CAP_ARM_EL1_32BIT);
}
+bool kvm_arm_el2_supported(void)
+{
+ return kvm_check_extension(kvm_state, KVM_CAP_ARM_EL2);
+}
+
bool kvm_arm_sve_supported(void)
{
return kvm_check_extension(kvm_state, KVM_CAP_ARM_SVE);
diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
index cfaa0d9bc7..36e4b37ec0 100644
--- a/target/arm/kvm_arm.h
+++ b/target/arm/kvm_arm.h
@@ -188,6 +188,13 @@ bool kvm_arm_pmu_supported(void);
*/
bool kvm_arm_sve_supported(void);
+/**
+ * kvm_arm_el2_supported:
+ *
+ * Returns true if KVM can enable EL2 and false otherwise.
+ */
+bool kvm_arm_el2_supported(void);
+
/**
* kvm_arm_get_max_vm_ipa_size:
* @ms: Machine state handle
@@ -235,6 +242,11 @@ static inline bool kvm_arm_sve_supported(void)
return false;
}
+static inline bool kvm_arm_el2_supported(void)
+{
+ return false;
+}
+
/*
* These functions should never actually be called without KVM support.
*/
--
2.41.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [RFC v2 3/5] target/arm/kvm: Add helper to detect EL2 when using KVM
2024-02-09 15:59 ` [RFC v2 3/5] target/arm/kvm: Add helper to detect EL2 when using KVM Eric Auger
@ 2024-02-09 18:54 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-09 18:54 UTC (permalink / raw)
To: Eric Auger, eric.auger.pro, qemu-devel, qemu-arm, miguel.luis,
haibo.xu, peter.maydell, richard.henderson, maz, gkulkarni
On 9/2/24 16:59, Eric Auger wrote:
> From: Haibo Xu <haibo.xu@linaro.org>
>
> Introduce query support for KVM_CAP_ARM_EL2.
>
> Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
> Signed-off-by: Miguel Luis <miguel.luis@oracle.com>
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> target/arm/kvm.c | 5 +++++
> target/arm/kvm_arm.h | 12 ++++++++++++
> 2 files changed, 17 insertions(+)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [RFC v2 4/5] target/arm: Enable feature ARM_FEATURE_EL2 if EL2 is supported
2024-02-09 15:59 [RFC v2 0/5] ARM Nested Virt Support Eric Auger
` (2 preceding siblings ...)
2024-02-09 15:59 ` [RFC v2 3/5] target/arm/kvm: Add helper to detect EL2 when using KVM Eric Auger
@ 2024-02-09 15:59 ` Eric Auger
2024-03-05 16:49 ` Peter Maydell
2024-02-09 15:59 ` [RFC v2 5/5] hw/arm/virt: Allow virt extensions with KVM Eric Auger
` (2 subsequent siblings)
6 siblings, 1 reply; 17+ messages in thread
From: Eric Auger @ 2024-02-09 15:59 UTC (permalink / raw)
To: eric.auger.pro, eric.auger, qemu-devel, qemu-arm, miguel.luis,
haibo.xu, peter.maydell, richard.henderson, maz, gkulkarni
From: Haibo Xu <haibo.xu@linaro.org>
KVM_CAP_ARM_EL2 must be supported by the cpu to enable ARM_FEATURE_EL2.
In case the host does support NV, expose the feature.
Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
Signed-off-by: Miguel Luis <miguel.luis@oracle.com>
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v1 -> v2:
- remove isar_feature_aa64_aa32_el2 modif in target/arm/cpu.h
[Richard] and use el2_supported in kvm_arch_init_vcpu
---
target/arm/kvm.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index 0996866afe..a08bc68a3f 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -238,6 +238,7 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
*/
int fdarray[3];
bool sve_supported;
+ bool el2_supported;
bool pmu_supported = false;
uint64_t features = 0;
int err;
@@ -268,6 +269,14 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
init.features[0] |= 1 << KVM_ARM_VCPU_SVE;
}
+ /*
+ * Ask for EL2 if supported.
+ */
+ el2_supported = kvm_arm_el2_supported();
+ if (el2_supported) {
+ init.features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
+ }
+
/*
* Ask for Pointer Authentication if supported, so that we get
* the unsanitized field values for AA64ISAR1_EL1.
@@ -449,6 +458,10 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
features |= 1ULL << ARM_FEATURE_PMU;
features |= 1ULL << ARM_FEATURE_GENERIC_TIMER;
+ if (el2_supported) {
+ features |= 1ULL << ARM_FEATURE_EL2;
+ }
+
ahcf->features = features;
return true;
@@ -1912,6 +1925,9 @@ int kvm_arch_init_vcpu(CPUState *cs)
cpu->kvm_init_features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
}
+ if (kvm_arm_el2_supported()) {
+ cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
+ }
/* Do KVM_ARM_VCPU_INIT ioctl */
ret = kvm_arm_vcpu_init(cpu);
--
2.41.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [RFC v2 4/5] target/arm: Enable feature ARM_FEATURE_EL2 if EL2 is supported
2024-02-09 15:59 ` [RFC v2 4/5] target/arm: Enable feature ARM_FEATURE_EL2 if EL2 is supported Eric Auger
@ 2024-03-05 16:49 ` Peter Maydell
2024-03-25 18:42 ` Eric Auger
0 siblings, 1 reply; 17+ messages in thread
From: Peter Maydell @ 2024-03-05 16:49 UTC (permalink / raw)
To: Eric Auger
Cc: eric.auger.pro, qemu-devel, qemu-arm, miguel.luis, haibo.xu,
richard.henderson, maz, gkulkarni
On Fri, 9 Feb 2024 at 16:00, Eric Auger <eric.auger@redhat.com> wrote:
>
> From: Haibo Xu <haibo.xu@linaro.org>
>
> KVM_CAP_ARM_EL2 must be supported by the cpu to enable ARM_FEATURE_EL2.
> In case the host does support NV, expose the feature.
>
> Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
> Signed-off-by: Miguel Luis <miguel.luis@oracle.com>
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>
> ---
>
> v1 -> v2:
> - remove isar_feature_aa64_aa32_el2 modif in target/arm/cpu.h
> [Richard] and use el2_supported in kvm_arch_init_vcpu
> ---
> target/arm/kvm.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/target/arm/kvm.c b/target/arm/kvm.c
> index 0996866afe..a08bc68a3f 100644
> --- a/target/arm/kvm.c
> +++ b/target/arm/kvm.c
> @@ -238,6 +238,7 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
> */
> int fdarray[3];
> bool sve_supported;
> + bool el2_supported;
> bool pmu_supported = false;
> uint64_t features = 0;
> int err;
> @@ -268,6 +269,14 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
> init.features[0] |= 1 << KVM_ARM_VCPU_SVE;
> }
>
> + /*
> + * Ask for EL2 if supported.
> + */
> + el2_supported = kvm_arm_el2_supported();
> + if (el2_supported) {
> + init.features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
> + }
> +
> /*
> * Ask for Pointer Authentication if supported, so that we get
> * the unsanitized field values for AA64ISAR1_EL1.
> @@ -449,6 +458,10 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
> features |= 1ULL << ARM_FEATURE_PMU;
> features |= 1ULL << ARM_FEATURE_GENERIC_TIMER;
>
> + if (el2_supported) {
> + features |= 1ULL << ARM_FEATURE_EL2;
> + }
> +
> ahcf->features = features;
>
> return true;
> @@ -1912,6 +1925,9 @@ int kvm_arch_init_vcpu(CPUState *cs)
> cpu->kvm_init_features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
> 1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
> }
> + if (kvm_arm_el2_supported()) {
> + cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
> + }
>
> /* Do KVM_ARM_VCPU_INIT ioctl */
> ret = kvm_arm_vcpu_init(cpu);
Am I reading this right that if the kernel supports FEAT_NV
then we will always ask for a vCPU with that feature?
Is that a good idea, or should we arrange to only do it if
the user uses the 'virtualization=on' option to -M virt ?
(Or does that happen already in some way I'm not seeing?)
thanks
-- PMM
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC v2 4/5] target/arm: Enable feature ARM_FEATURE_EL2 if EL2 is supported
2024-03-05 16:49 ` Peter Maydell
@ 2024-03-25 18:42 ` Eric Auger
0 siblings, 0 replies; 17+ messages in thread
From: Eric Auger @ 2024-03-25 18:42 UTC (permalink / raw)
To: Peter Maydell
Cc: eric.auger.pro, qemu-devel, qemu-arm, miguel.luis, haibo.xu,
richard.henderson, maz, gkulkarni
Hi Peter,
On 3/5/24 17:49, Peter Maydell wrote:
> On Fri, 9 Feb 2024 at 16:00, Eric Auger <eric.auger@redhat.com> wrote:
>> From: Haibo Xu <haibo.xu@linaro.org>
>>
>> KVM_CAP_ARM_EL2 must be supported by the cpu to enable ARM_FEATURE_EL2.
>> In case the host does support NV, expose the feature.
>>
>> Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
>> Signed-off-by: Miguel Luis <miguel.luis@oracle.com>
>> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>>
>> ---
>>
>> v1 -> v2:
>> - remove isar_feature_aa64_aa32_el2 modif in target/arm/cpu.h
>> [Richard] and use el2_supported in kvm_arch_init_vcpu
>> ---
>> target/arm/kvm.c | 16 ++++++++++++++++
>> 1 file changed, 16 insertions(+)
>>
>> diff --git a/target/arm/kvm.c b/target/arm/kvm.c
>> index 0996866afe..a08bc68a3f 100644
>> --- a/target/arm/kvm.c
>> +++ b/target/arm/kvm.c
>> @@ -238,6 +238,7 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
>> */
>> int fdarray[3];
>> bool sve_supported;
>> + bool el2_supported;
>> bool pmu_supported = false;
>> uint64_t features = 0;
>> int err;
>> @@ -268,6 +269,14 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
>> init.features[0] |= 1 << KVM_ARM_VCPU_SVE;
>> }
>>
>> + /*
>> + * Ask for EL2 if supported.
>> + */
>> + el2_supported = kvm_arm_el2_supported();
>> + if (el2_supported) {
>> + init.features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
>> + }
>> +
>> /*
>> * Ask for Pointer Authentication if supported, so that we get
>> * the unsanitized field values for AA64ISAR1_EL1.
>> @@ -449,6 +458,10 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
>> features |= 1ULL << ARM_FEATURE_PMU;
>> features |= 1ULL << ARM_FEATURE_GENERIC_TIMER;
>>
>> + if (el2_supported) {
>> + features |= 1ULL << ARM_FEATURE_EL2;
>> + }
>> +
>> ahcf->features = features;
>>
>> return true;
>> @@ -1912,6 +1925,9 @@ int kvm_arch_init_vcpu(CPUState *cs)
>> cpu->kvm_init_features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
>> 1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
>> }
>> + if (kvm_arm_el2_supported()) {
>> + cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
>> + }
>>
>> /* Do KVM_ARM_VCPU_INIT ioctl */
>> ret = kvm_arm_vcpu_init(cpu);
> Am I reading this right that if the kernel supports FEAT_NV
> then we will always ask for a vCPU with that feature?
> Is that a good idea, or should we arrange to only do it if
> the user uses the 'virtualization=on' option to -M virt ?
> (Or does that happen already in some way I'm not seeing?)
yes you're right, if the host supports it, the feature is currently set
on the vcpu. I am not totaly clear under which conditions the features
shall be instantiated in the scratch VM and when the host passthrough
model shall be altered by machine option.
Thanks
Eric
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [RFC v2 5/5] hw/arm/virt: Allow virt extensions with KVM
2024-02-09 15:59 [RFC v2 0/5] ARM Nested Virt Support Eric Auger
` (3 preceding siblings ...)
2024-02-09 15:59 ` [RFC v2 4/5] target/arm: Enable feature ARM_FEATURE_EL2 if EL2 is supported Eric Auger
@ 2024-02-09 15:59 ` Eric Auger
2024-02-09 18:57 ` [RFC v2 0/5] ARM Nested Virt Support Peter Maydell
2024-03-05 16:57 ` Peter Maydell
6 siblings, 0 replies; 17+ messages in thread
From: Eric Auger @ 2024-02-09 15:59 UTC (permalink / raw)
To: eric.auger.pro, eric.auger, qemu-devel, qemu-arm, miguel.luis,
haibo.xu, peter.maydell, richard.henderson, maz, gkulkarni
From: Haibo Xu <haibo.xu@linaro.org>
Up to now virt support on guest has been only supported with TCG.
Now it becomes feasible to use it with KVM acceleration.
Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
Signed-off-by: Miguel Luis <miguel.luis@oracle.com>
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v1 -> v2:
- fixed test ordering: virt && ((kvm && !kvm_el2) || hvf) [Richard]
- tweeked the commit title & message
---
hw/arm/virt.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 5214aca898..ae7ac07301 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -2109,7 +2109,8 @@ static void machvirt_init(MachineState *machine)
exit(1);
}
- if (vms->virt && (kvm_enabled() || hvf_enabled())) {
+ if (vms->virt &&
+ ((kvm_enabled() && !kvm_arm_el2_supported()) || hvf_enabled())) {
error_report("mach-virt: %s does not support providing "
"Virtualization extensions to the guest CPU",
current_accel_name());
--
2.41.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [RFC v2 0/5] ARM Nested Virt Support
2024-02-09 15:59 [RFC v2 0/5] ARM Nested Virt Support Eric Auger
` (4 preceding siblings ...)
2024-02-09 15:59 ` [RFC v2 5/5] hw/arm/virt: Allow virt extensions with KVM Eric Auger
@ 2024-02-09 18:57 ` Peter Maydell
2024-02-12 17:15 ` Eric Auger
2024-02-12 17:18 ` Marc Zyngier
2024-03-05 16:57 ` Peter Maydell
6 siblings, 2 replies; 17+ messages in thread
From: Peter Maydell @ 2024-02-09 18:57 UTC (permalink / raw)
To: Eric Auger
Cc: eric.auger.pro, qemu-devel, qemu-arm, miguel.luis, haibo.xu,
richard.henderson, maz, gkulkarni
On Fri, 9 Feb 2024 at 16:00, Eric Auger <eric.auger@redhat.com> wrote:
>
> This series adds ARM Nested Virtualization support in KVM mode.
> This is a respin of previous contributions from Miguel [1] and Haibo [2].
>
> This was tested with Marc's v11 [3] on Ampere HW with fedora L1 guest and
> L2 guests booted without EDK2. However it does not work yet with
> EDK2 but it looks unrelated to this qemu integration (host hard lockups).
>
> The host needs to be booted with "kvm-arm.mode=nested" option and
> qemu needs to be invoked with :
>
> -machine virt,virtualization=on
>
> There is a known issue with hosts supporting SVE. Kernel does not support both
> SVE and NV2 and the current qemu integration has an issue with the
> scratch_host_vcpu startup because both are enabled if exposed by the kernel.
> This is independent on whether sve is disabled on the command line. Unfortunately
> I lost access to the HW that expose that issue so I couldn't fix it in this
> version.
You can probably repro that by running the whole setup under
QEMU's FEAT_NV emulation, which will be able to give you a CPU
with both FEAT_NV and SVE.
Personally I think that this is a kernel missing-feature that
should really be fixed as part of getting the kernel patches
upstreamed. There's no cause to force every userspace VMM to
develop extra complications for this.
thanks
-- PMM
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC v2 0/5] ARM Nested Virt Support
2024-02-09 18:57 ` [RFC v2 0/5] ARM Nested Virt Support Peter Maydell
@ 2024-02-12 17:15 ` Eric Auger
2024-02-12 17:18 ` Marc Zyngier
1 sibling, 0 replies; 17+ messages in thread
From: Eric Auger @ 2024-02-12 17:15 UTC (permalink / raw)
To: Peter Maydell
Cc: eric.auger.pro, qemu-devel, qemu-arm, miguel.luis, haibo.xu,
richard.henderson, maz, gkulkarni
Hi Peter,
On 2/9/24 19:57, Peter Maydell wrote:
> On Fri, 9 Feb 2024 at 16:00, Eric Auger <eric.auger@redhat.com> wrote:
>> This series adds ARM Nested Virtualization support in KVM mode.
>> This is a respin of previous contributions from Miguel [1] and Haibo [2].
>>
>> This was tested with Marc's v11 [3] on Ampere HW with fedora L1 guest and
>> L2 guests booted without EDK2. However it does not work yet with
>> EDK2 but it looks unrelated to this qemu integration (host hard lockups).
>>
>> The host needs to be booted with "kvm-arm.mode=nested" option and
>> qemu needs to be invoked with :
>>
>> -machine virt,virtualization=on
>>
>> There is a known issue with hosts supporting SVE. Kernel does not support both
>> SVE and NV2 and the current qemu integration has an issue with the
>> scratch_host_vcpu startup because both are enabled if exposed by the kernel.
>> This is independent on whether sve is disabled on the command line. Unfortunately
>> I lost access to the HW that expose that issue so I couldn't fix it in this
>> version.
> You can probably repro that by running the whole setup under
> QEMU's FEAT_NV emulation, which will be able to give you a CPU
> with both FEAT_NV and SVE.
indeed, this should work now we have FEAT_NV.
>
> Personally I think that this is a kernel missing-feature that
> should really be fixed as part of getting the kernel patches
> upstreamed. There's no cause to force every userspace VMM to
> develop extra complications for this.
yes maybe this will be fixed later on.
Thanks!
Eric
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC v2 0/5] ARM Nested Virt Support
2024-02-09 18:57 ` [RFC v2 0/5] ARM Nested Virt Support Peter Maydell
2024-02-12 17:15 ` Eric Auger
@ 2024-02-12 17:18 ` Marc Zyngier
1 sibling, 0 replies; 17+ messages in thread
From: Marc Zyngier @ 2024-02-12 17:18 UTC (permalink / raw)
To: Peter Maydell
Cc: Eric Auger, eric.auger.pro, qemu-devel, qemu-arm, miguel.luis,
haibo.xu, richard.henderson, gkulkarni
On 2024-02-09 18:57, Peter Maydell wrote:
> On Fri, 9 Feb 2024 at 16:00, Eric Auger <eric.auger@redhat.com> wrote:
>>
>> This series adds ARM Nested Virtualization support in KVM mode.
>> This is a respin of previous contributions from Miguel [1] and Haibo
>> [2].
>>
>> This was tested with Marc's v11 [3] on Ampere HW with fedora L1 guest
>> and
>> L2 guests booted without EDK2. However it does not work yet with
>> EDK2 but it looks unrelated to this qemu integration (host hard
>> lockups).
>>
>> The host needs to be booted with "kvm-arm.mode=nested" option and
>> qemu needs to be invoked with :
>>
>> -machine virt,virtualization=on
>>
>> There is a known issue with hosts supporting SVE. Kernel does not
>> support both
>> SVE and NV2 and the current qemu integration has an issue with the
>> scratch_host_vcpu startup because both are enabled if exposed by the
>> kernel.
>> This is independent on whether sve is disabled on the command line.
>> Unfortunately
>> I lost access to the HW that expose that issue so I couldn't fix it in
>> this
>> version.
>
> You can probably repro that by running the whole setup under
> QEMU's FEAT_NV emulation, which will be able to give you a CPU
> with both FEAT_NV and SVE.
>
> Personally I think that this is a kernel missing-feature that
> should really be fixed as part of getting the kernel patches
> upstreamed. There's no cause to force every userspace VMM to
> develop extra complications for this.
I don't plan to make NV visible to userspace before this is fixed.
Which may delay KVM NV by another year or five, but I don't think
anyone is really waiting for it anyway.
M.
--
Jazz is not dead. It just smells funny...
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC v2 0/5] ARM Nested Virt Support
2024-02-09 15:59 [RFC v2 0/5] ARM Nested Virt Support Eric Auger
` (5 preceding siblings ...)
2024-02-09 18:57 ` [RFC v2 0/5] ARM Nested Virt Support Peter Maydell
@ 2024-03-05 16:57 ` Peter Maydell
2024-03-26 10:09 ` Eric Auger
6 siblings, 1 reply; 17+ messages in thread
From: Peter Maydell @ 2024-03-05 16:57 UTC (permalink / raw)
To: Eric Auger
Cc: eric.auger.pro, qemu-devel, qemu-arm, miguel.luis, haibo.xu,
richard.henderson, maz, gkulkarni
On Fri, 9 Feb 2024 at 16:00, Eric Auger <eric.auger@redhat.com> wrote:
>
> This series adds ARM Nested Virtualization support in KVM mode.
> This is a respin of previous contributions from Miguel [1] and Haibo [2].
>
> This was tested with Marc's v11 [3] on Ampere HW with fedora L1 guest and
> L2 guests booted without EDK2. However it does not work yet with
> EDK2 but it looks unrelated to this qemu integration (host hard lockups).
>
> The host needs to be booted with "kvm-arm.mode=nested" option and
> qemu needs to be invoked with :
>
> -machine virt,virtualization=on
>
> There is a known issue with hosts supporting SVE. Kernel does not support both
> SVE and NV2 and the current qemu integration has an issue with the
> scratch_host_vcpu startup because both are enabled if exposed by the kernel.
> This is independent on whether sve is disabled on the command line. Unfortunately
> I lost access to the HW that expose that issue so I couldn't fix it in this
> version.
>
> This series can be found at:
> https://github.com/eauger/qemu/tree/v8.2-nv-rfcv2
>
> Previous version from Miguel:
> [1] https://lore.kernel.org/all/20230227163718.62003-1-miguel.luis@oracle.com/
> Previous version from Haibo:
> [2] https://lore.kernel.org/qemu-devel/cover.1617281290.git.haibo.xu@linaro.org/
> [3] Marc's kernel v11 series:
> [PATCH v11 00/43] KVM: arm64: Nested Virtualization support (FEAT_NV2 only)
> https://lore.kernel.org/linux-arm-kernel/20231120131027.854038-1-maz@kernel.org/T/
> available at: https://github.com/eauger/linux/tree/nv-6.8-nv2-v11
>
> Haibo Xu (5):
> [Placeholder] headers: Partial headers update for NV2 enablement
> hw/arm: Allow setting KVM vGIC maintenance IRQ
> target/arm/kvm: Add helper to detect EL2 when using KVM
> target/arm: Enable feature ARM_FEATURE_EL2 if EL2 is supported
> hw/arm/virt: Allow virt extensions with KVM
>
> hw/arm/virt.c | 6 +++++-
> hw/intc/arm_gicv3_common.c | 1 +
> hw/intc/arm_gicv3_kvm.c | 21 +++++++++++++++++++++
> include/hw/intc/arm_gicv3_common.h | 1 +
> linux-headers/asm-arm64/kvm.h | 1 +
> linux-headers/linux/kvm.h | 1 +
> target/arm/kvm.c | 21 +++++++++++++++++++++
> target/arm/kvm_arm.h | 12 ++++++++++++
> 8 files changed, 63 insertions(+), 1 deletion(-)
All the patches in this series seem reasonable, but the series
as a whole is so short I wonder if we're missing something :-)
Does migration Just Work? (I guess as long as the kernel exposes
all the EL2 sysregs via the ONE_REG ioctl interface it ought to...)
Anyway, I don't think there's anything that stood out as needing
major changes, so for now I guess we just wait for whenever the
KVM side patches eventually land.
thanks
-- PMM
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC v2 0/5] ARM Nested Virt Support
2024-03-05 16:57 ` Peter Maydell
@ 2024-03-26 10:09 ` Eric Auger
0 siblings, 0 replies; 17+ messages in thread
From: Eric Auger @ 2024-03-26 10:09 UTC (permalink / raw)
To: Peter Maydell
Cc: eric.auger.pro, qemu-devel, qemu-arm, miguel.luis, haibo.xu,
richard.henderson, maz, gkulkarni
Hi Peter,
On 3/5/24 17:57, Peter Maydell wrote:
> On Fri, 9 Feb 2024 at 16:00, Eric Auger <eric.auger@redhat.com> wrote:
>> This series adds ARM Nested Virtualization support in KVM mode.
>> This is a respin of previous contributions from Miguel [1] and Haibo [2].
>>
>> This was tested with Marc's v11 [3] on Ampere HW with fedora L1 guest and
>> L2 guests booted without EDK2. However it does not work yet with
>> EDK2 but it looks unrelated to this qemu integration (host hard lockups).
>>
>> The host needs to be booted with "kvm-arm.mode=nested" option and
>> qemu needs to be invoked with :
>>
>> -machine virt,virtualization=on
>>
>> There is a known issue with hosts supporting SVE. Kernel does not support both
>> SVE and NV2 and the current qemu integration has an issue with the
>> scratch_host_vcpu startup because both are enabled if exposed by the kernel.
>> This is independent on whether sve is disabled on the command line. Unfortunately
>> I lost access to the HW that expose that issue so I couldn't fix it in this
>> version.
>>
>> This series can be found at:
>> https://github.com/eauger/qemu/tree/v8.2-nv-rfcv2
>>
>> Previous version from Miguel:
>> [1] https://lore.kernel.org/all/20230227163718.62003-1-miguel.luis@oracle.com/
>> Previous version from Haibo:
>> [2] https://lore.kernel.org/qemu-devel/cover.1617281290.git.haibo.xu@linaro.org/
>> [3] Marc's kernel v11 series:
>> [PATCH v11 00/43] KVM: arm64: Nested Virtualization support (FEAT_NV2 only)
>> https://lore.kernel.org/linux-arm-kernel/20231120131027.854038-1-maz@kernel.org/T/
>> available at: https://github.com/eauger/linux/tree/nv-6.8-nv2-v11
>>
>> Haibo Xu (5):
>> [Placeholder] headers: Partial headers update for NV2 enablement
>> hw/arm: Allow setting KVM vGIC maintenance IRQ
>> target/arm/kvm: Add helper to detect EL2 when using KVM
>> target/arm: Enable feature ARM_FEATURE_EL2 if EL2 is supported
>> hw/arm/virt: Allow virt extensions with KVM
>>
>> hw/arm/virt.c | 6 +++++-
>> hw/intc/arm_gicv3_common.c | 1 +
>> hw/intc/arm_gicv3_kvm.c | 21 +++++++++++++++++++++
>> include/hw/intc/arm_gicv3_common.h | 1 +
>> linux-headers/asm-arm64/kvm.h | 1 +
>> linux-headers/linux/kvm.h | 1 +
>> target/arm/kvm.c | 21 +++++++++++++++++++++
>> target/arm/kvm_arm.h | 12 ++++++++++++
>> 8 files changed, 63 insertions(+), 1 deletion(-)
> All the patches in this series seem reasonable, but the series
> as a whole is so short I wonder if we're missing something :-)
> Does migration Just Work? (I guess as long as the kernel exposes
> all the EL2 sysregs via the ONE_REG ioctl interface it ought to...)
To be honest I have not tested yet. I would also guess there is no mig
blocker but that definitively deserves some testing. I will check before
sending the next version.
>
> Anyway, I don't think there's anything that stood out as needing
> major changes, so for now I guess we just wait for whenever the
> KVM side patches eventually land.
yup
Thanks
Eric
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 17+ messages in thread