Message ID | 20190911155125.11932-4-eric.auger@redhat.com |
---|---|
State | New |
Headers | show |
Series | KVM/ARM: Fix >256 vcpus | expand |
On Wed, Sep 11, 2019 at 05:51:25PM +0200, Eric Auger wrote: > Host kernel within [4.18, 5.3] report an erroneous KVM_MAX_VCPUS=512 > for ARM. The actual capability to instantiate more than 256 vcpus > was fixed in 5.4 with the upgrade of the KVM_IRQ_LINE ABI to support > vcpu id encoded on 12 bits instead of 8 and a redistributor consuming > a single KVM IO device instead of 2. > > So let's check this capability when attempting to use more than 256 > vcpus. > > Signed-off-by: Eric Auger <eric.auger@redhat.com> > --- > hw/arm/virt.c | 4 ++++ > target/arm/kvm.c | 21 +++++++++++++++++++++ > target/arm/kvm_arm.h | 15 +++++++++++++++ > 3 files changed, 40 insertions(+) > > diff --git a/hw/arm/virt.c b/hw/arm/virt.c > index 0d1629ccb3..465e3140f7 100644 > --- a/hw/arm/virt.c > +++ b/hw/arm/virt.c > @@ -1575,6 +1575,10 @@ static void machvirt_init(MachineState *machine) > virt_max_cpus = GIC_NCPU; > } > > + if (kvm_arm_irq_line_layout_mismatch(MACHINE(vms), max_cpus)) { > + exit(1); > + } > + > if (max_cpus > virt_max_cpus) { > error_report("Number of SMP CPUs requested (%d) exceeds max CPUs " > "supported by machine 'mach-virt' (%d)", > diff --git a/target/arm/kvm.c b/target/arm/kvm.c > index 6cdfa2204f..b601e2f35a 100644 > --- a/target/arm/kvm.c > +++ b/target/arm/kvm.c > @@ -171,6 +171,27 @@ bool kvm_arm_pmu_supported(CPUState *cpu) > return kvm_check_extension(s, KVM_CAP_ARM_PMU_V3); > } > > +bool kvm_arm_irq_line_layout_mismatch(MachineState *ms, int vcpus) > +{ > + KVMState *s; > + bool ret; > + > + if (!kvm_enabled()) { > + return false; > + } > + > + s = KVM_STATE(ms->accelerator); > + > + ret = vcpus > 256 && > + !kvm_check_extension(s, KVM_CAP_ARM_IRQ_LINE_LAYOUT_2); > + > + if (ret) { > + error_report("Using more than 256 vcpus requires a host kernel " > + "with KVM_CAP_ARM_IRQ_LINE_LAYOUT_2"); > + } > + return ret; > +} > + > int kvm_arm_get_max_vm_ipa_size(MachineState *ms) > { > KVMState *s = KVM_STATE(ms->accelerator); > diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h > index b4e19457a0..d893d950d8 100644 > --- a/target/arm/kvm_arm.h > +++ b/target/arm/kvm_arm.h > @@ -233,6 +233,16 @@ bool kvm_arm_pmu_supported(CPUState *cs); > */ > int kvm_arm_get_max_vm_ipa_size(MachineState *ms); > > +/** > + * kvm_arm_irq_line_layout_mismatch - Returns whether the number of vcpus > + * exceeds the limit imposed by the legacy KVM_IRQ_LINE ARM layout > + * (without the vcpu2_index field). > + * > + * @ms: Machine state handle > + * @vcpus: number of vcpus > + */ > +bool kvm_arm_irq_line_layout_mismatch(MachineState *ms, int vcpus); > + > /** > * kvm_arm_sync_mpstate_to_kvm > * @cpu: ARMCPU > @@ -281,6 +291,11 @@ static inline int kvm_arm_get_max_vm_ipa_size(MachineState *ms) > return -ENOENT; > } > > +static inline bool kvm_arm_irq_line_layout_mismatch(MachineState *ms, int vcpus) > +{ > + return false; > +} > + > static inline int kvm_arm_vgic_probe(void) > { > return 0; > -- > 2.20.1 > > Reviewed-by: Andrew Jones <drjones@redhat.com>
On Wed, 11 Sep 2019 at 16:51, Eric Auger <eric.auger@redhat.com> wrote: > > Host kernel within [4.18, 5.3] report an erroneous KVM_MAX_VCPUS=512 > for ARM. The actual capability to instantiate more than 256 vcpus > was fixed in 5.4 with the upgrade of the KVM_IRQ_LINE ABI to support > vcpu id encoded on 12 bits instead of 8 and a redistributor consuming > a single KVM IO device instead of 2. > > So let's check this capability when attempting to use more than 256 > vcpus. > > Signed-off-by: Eric Auger <eric.auger@redhat.com> > --- > hw/arm/virt.c | 4 ++++ > target/arm/kvm.c | 21 +++++++++++++++++++++ > target/arm/kvm_arm.h | 15 +++++++++++++++ > 3 files changed, 40 insertions(+) > > diff --git a/hw/arm/virt.c b/hw/arm/virt.c > index 0d1629ccb3..465e3140f7 100644 > --- a/hw/arm/virt.c > +++ b/hw/arm/virt.c > @@ -1575,6 +1575,10 @@ static void machvirt_init(MachineState *machine) > virt_max_cpus = GIC_NCPU; > } > > + if (kvm_arm_irq_line_layout_mismatch(MACHINE(vms), max_cpus)) { > + exit(1); > + } > + Is there really no place to put this check in common code? thanks -- PMM
Hi Peter, On 9/12/19 10:42 AM, Peter Maydell wrote: > On Wed, 11 Sep 2019 at 16:51, Eric Auger <eric.auger@redhat.com> wrote: >> >> Host kernel within [4.18, 5.3] report an erroneous KVM_MAX_VCPUS=512 >> for ARM. The actual capability to instantiate more than 256 vcpus >> was fixed in 5.4 with the upgrade of the KVM_IRQ_LINE ABI to support >> vcpu id encoded on 12 bits instead of 8 and a redistributor consuming >> a single KVM IO device instead of 2. >> >> So let's check this capability when attempting to use more than 256 >> vcpus. >> >> Signed-off-by: Eric Auger <eric.auger@redhat.com> >> --- >> hw/arm/virt.c | 4 ++++ >> target/arm/kvm.c | 21 +++++++++++++++++++++ >> target/arm/kvm_arm.h | 15 +++++++++++++++ >> 3 files changed, 40 insertions(+) >> >> diff --git a/hw/arm/virt.c b/hw/arm/virt.c >> index 0d1629ccb3..465e3140f7 100644 >> --- a/hw/arm/virt.c >> +++ b/hw/arm/virt.c >> @@ -1575,6 +1575,10 @@ static void machvirt_init(MachineState *machine) >> virt_max_cpus = GIC_NCPU; >> } >> >> + if (kvm_arm_irq_line_layout_mismatch(MACHINE(vms), max_cpus)) { >> + exit(1); >> + } >> + > > Is there really no place to put this check in common code? Not sure what you mean by common code here? Do you mean in a common code for ARM machines (I don't think we have any atm) or directly in kvm_init(). I did not want to pollute this latter with this ARM specific fix. Thanks Eric > > thanks > -- PMM >
On Thu, 12 Sep 2019 at 09:57, Auger Eric <eric.auger@redhat.com> wrote: > > Hi Peter, > On 9/12/19 10:42 AM, Peter Maydell wrote: > > Is there really no place to put this check in common code? > Not sure what you mean by common code here? Do you mean in a common code > for ARM machines (I don't think we have any atm) or directly in > kvm_init(). I did not want to pollute this latter with this ARM specific > fix. I'd just rather we didn't have to have the same "if ..." check in every arm board that supports KVM. If kvm_init() happens at a point where we have enough info to make the check, then you can put the check in kvm_arch_init(), which is the architecture-specific hook that kvm_init() calls. thanks -- PMM
Hi Peter, On 9/12/19 11:00 AM, Peter Maydell wrote: > On Thu, 12 Sep 2019 at 09:57, Auger Eric <eric.auger@redhat.com> wrote: >> >> Hi Peter, >> On 9/12/19 10:42 AM, Peter Maydell wrote: > >>> Is there really no place to put this check in common code? > >> Not sure what you mean by common code here? Do you mean in a common code >> for ARM machines (I don't think we have any atm) or directly in >> kvm_init(). I did not want to pollute this latter with this ARM specific >> fix. > > I'd just rather we didn't have to have the same "if ..." check > in every arm board that supports KVM. > > If kvm_init() happens at a point where we have enough info to > make the check, then you can put the check in kvm_arch_init(), > which is the architecture-specific hook that kvm_init() calls. OK Thank you for the hint. It should be OK. Thanks! Eric > > thanks > -- PMM >
diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 0d1629ccb3..465e3140f7 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1575,6 +1575,10 @@ static void machvirt_init(MachineState *machine) virt_max_cpus = GIC_NCPU; } + if (kvm_arm_irq_line_layout_mismatch(MACHINE(vms), max_cpus)) { + exit(1); + } + if (max_cpus > virt_max_cpus) { error_report("Number of SMP CPUs requested (%d) exceeds max CPUs " "supported by machine 'mach-virt' (%d)", diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 6cdfa2204f..b601e2f35a 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -171,6 +171,27 @@ bool kvm_arm_pmu_supported(CPUState *cpu) return kvm_check_extension(s, KVM_CAP_ARM_PMU_V3); } +bool kvm_arm_irq_line_layout_mismatch(MachineState *ms, int vcpus) +{ + KVMState *s; + bool ret; + + if (!kvm_enabled()) { + return false; + } + + s = KVM_STATE(ms->accelerator); + + ret = vcpus > 256 && + !kvm_check_extension(s, KVM_CAP_ARM_IRQ_LINE_LAYOUT_2); + + if (ret) { + error_report("Using more than 256 vcpus requires a host kernel " + "with KVM_CAP_ARM_IRQ_LINE_LAYOUT_2"); + } + return ret; +} + int kvm_arm_get_max_vm_ipa_size(MachineState *ms) { KVMState *s = KVM_STATE(ms->accelerator); diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h index b4e19457a0..d893d950d8 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -233,6 +233,16 @@ bool kvm_arm_pmu_supported(CPUState *cs); */ int kvm_arm_get_max_vm_ipa_size(MachineState *ms); +/** + * kvm_arm_irq_line_layout_mismatch - Returns whether the number of vcpus + * exceeds the limit imposed by the legacy KVM_IRQ_LINE ARM layout + * (without the vcpu2_index field). + * + * @ms: Machine state handle + * @vcpus: number of vcpus + */ +bool kvm_arm_irq_line_layout_mismatch(MachineState *ms, int vcpus); + /** * kvm_arm_sync_mpstate_to_kvm * @cpu: ARMCPU @@ -281,6 +291,11 @@ static inline int kvm_arm_get_max_vm_ipa_size(MachineState *ms) return -ENOENT; } +static inline bool kvm_arm_irq_line_layout_mismatch(MachineState *ms, int vcpus) +{ + return false; +} + static inline int kvm_arm_vgic_probe(void) { return 0;
Host kernel within [4.18, 5.3] report an erroneous KVM_MAX_VCPUS=512 for ARM. The actual capability to instantiate more than 256 vcpus was fixed in 5.4 with the upgrade of the KVM_IRQ_LINE ABI to support vcpu id encoded on 12 bits instead of 8 and a redistributor consuming a single KVM IO device instead of 2. So let's check this capability when attempting to use more than 256 vcpus. Signed-off-by: Eric Auger <eric.auger@redhat.com> --- hw/arm/virt.c | 4 ++++ target/arm/kvm.c | 21 +++++++++++++++++++++ target/arm/kvm_arm.h | 15 +++++++++++++++ 3 files changed, 40 insertions(+)