diff mbox series

[V6,1/4] hw/mips: Implement the kvm_type() hook in MachineClass

Message ID 1592995531-32600-2-git-send-email-chenhc@lemote.com
State New
Headers show
Series mips: Add Loongson-3 machine support (with KVM) | expand

Commit Message

chen huacai June 24, 2020, 10:45 a.m. UTC
MIPS has two types of KVM: TE & VZ, and TE is the default type. Now we
can't create a VZ guest in QEMU because it lacks the kvm_type() hook in
MachineClass. This patch add the the kvm_type() hook to support both of
the two types.

Reviewed-by: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>
Signed-off-by: Huacai Chen <chenhc@lemote.com>
Co-developed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 target/mips/kvm.c      | 20 ++++++++++++++++++++
 target/mips/kvm_mips.h | 11 +++++++++++
 2 files changed, 31 insertions(+)

Comments

Aleksandar Markovic June 25, 2020, 12:31 p.m. UTC | #1
сре, 24. јун 2020. у 12:44 Huacai Chen <zltjiangshi@gmail.com> је написао/ла:
>
> MIPS has two types of KVM: TE & VZ, and TE is the default type. Now we
> can't create a VZ guest in QEMU because it lacks the kvm_type() hook in
> MachineClass. This patch add the the kvm_type() hook to support both of
> the two types.
>
> Reviewed-by: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>
> Signed-off-by: Huacai Chen <chenhc@lemote.com>
> Co-developed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
>  target/mips/kvm.c      | 20 ++++++++++++++++++++
>  target/mips/kvm_mips.h | 11 +++++++++++
>  2 files changed, 31 insertions(+)
>
> diff --git a/target/mips/kvm.c b/target/mips/kvm.c
> index 96cfa10..373f582 100644
> --- a/target/mips/kvm.c
> +++ b/target/mips/kvm.c
> @@ -21,10 +21,12 @@
>  #include "qemu/main-loop.h"
>  #include "qemu/timer.h"
>  #include "sysemu/kvm.h"
> +#include "sysemu/kvm_int.h"
>  #include "sysemu/runstate.h"
>  #include "sysemu/cpus.h"
>  #include "kvm_mips.h"
>  #include "exec/memattrs.h"
> +#include "hw/boards.h"
>
>  #define DEBUG_KVM 0
>
> @@ -1270,3 +1272,21 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)
>  {
>      abort();
>  }
> +
> +int mips_kvm_type(MachineState *machine, const char *vm_type)
> +{
> +    int r;
> +    KVMState *s = KVM_STATE(machine->accelerator);
> +
> +    r = kvm_check_extension(s, KVM_CAP_MIPS_VZ);

This will not work for build systems with kernel < 4.12. You need to
provide fallback solution for that case.

> +    if (r > 0) {
> +        return KVM_VM_MIPS_VZ;
> +    }
> +
> +    r = kvm_check_extension(s, KVM_CAP_MIPS_TE);
> +    if (r > 0) {
> +        return KVM_VM_MIPS_TE;
> +    }
> +
> +    return -1;
> +}
> diff --git a/target/mips/kvm_mips.h b/target/mips/kvm_mips.h
> index 1e40147..171d53d 100644
> --- a/target/mips/kvm_mips.h
> +++ b/target/mips/kvm_mips.h
> @@ -12,6 +12,8 @@
>  #ifndef KVM_MIPS_H
>  #define KVM_MIPS_H
>
> +#include "cpu.h"
> +
>  /**
>   * kvm_mips_reset_vcpu:
>   * @cpu: MIPSCPU
> @@ -23,4 +25,13 @@ void kvm_mips_reset_vcpu(MIPSCPU *cpu);
>  int kvm_mips_set_interrupt(MIPSCPU *cpu, int irq, int level);
>  int kvm_mips_set_ipi_interrupt(MIPSCPU *cpu, int irq, int level);
>
> +#ifdef CONFIG_KVM
> +int mips_kvm_type(MachineState *machine, const char *vm_type);
> +#else
> +static inline int mips_kvm_type(MachineState *machine, const char *vm_type)
> +{
> +    return 0;
> +}
> +#endif
> +
>  #endif /* KVM_MIPS_H */
> --
> 2.7.0
>
Aleksandar Markovic June 25, 2020, 1:25 p.m. UTC | #2
чет, 25. јун 2020. у 14:31 Aleksandar Markovic
<aleksandar.qemu.devel@gmail.com> је написао/ла:
>
> сре, 24. јун 2020. у 12:44 Huacai Chen <zltjiangshi@gmail.com> је написао/ла:
> >
> > MIPS has two types of KVM: TE & VZ, and TE is the default type. Now we
> > can't create a VZ guest in QEMU because it lacks the kvm_type() hook in
> > MachineClass. This patch add the the kvm_type() hook to support both of
> > the two types.
> >
> > Reviewed-by: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>
> > Signed-off-by: Huacai Chen <chenhc@lemote.com>
> > Co-developed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> > ---
> >  target/mips/kvm.c      | 20 ++++++++++++++++++++
> >  target/mips/kvm_mips.h | 11 +++++++++++
> >  2 files changed, 31 insertions(+)
> >
> > diff --git a/target/mips/kvm.c b/target/mips/kvm.c
> > index 96cfa10..373f582 100644
> > --- a/target/mips/kvm.c
> > +++ b/target/mips/kvm.c
> > @@ -21,10 +21,12 @@
> >  #include "qemu/main-loop.h"
> >  #include "qemu/timer.h"
> >  #include "sysemu/kvm.h"
> > +#include "sysemu/kvm_int.h"
> >  #include "sysemu/runstate.h"
> >  #include "sysemu/cpus.h"
> >  #include "kvm_mips.h"
> >  #include "exec/memattrs.h"
> > +#include "hw/boards.h"
> >
> >  #define DEBUG_KVM 0
> >
> > @@ -1270,3 +1272,21 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)
> >  {
> >      abort();
> >  }
> > +
> > +int mips_kvm_type(MachineState *machine, const char *vm_type)
> > +{
> > +    int r;
> > +    KVMState *s = KVM_STATE(machine->accelerator);
> > +
> > +    r = kvm_check_extension(s, KVM_CAP_MIPS_VZ);
>
> This will not work for build systems with kernel < 4.12. You need to
> provide fallback solution for that case.
>

I am perhaps wrong here. If we pull the preprocessor constants from
imported Linux headers, than we don;t need host kernel headers
supporting KVM_CAP_MIPS_VZ. I will doublecheck.

Thanks, Aleksandar

> > +    if (r > 0) {
> > +        return KVM_VM_MIPS_VZ;
> > +    }
> > +
> > +    r = kvm_check_extension(s, KVM_CAP_MIPS_TE);
> > +    if (r > 0) {
> > +        return KVM_VM_MIPS_TE;
> > +    }
> > +
> > +    return -1;
> > +}
> > diff --git a/target/mips/kvm_mips.h b/target/mips/kvm_mips.h
> > index 1e40147..171d53d 100644
> > --- a/target/mips/kvm_mips.h
> > +++ b/target/mips/kvm_mips.h
> > @@ -12,6 +12,8 @@
> >  #ifndef KVM_MIPS_H
> >  #define KVM_MIPS_H
> >
> > +#include "cpu.h"
> > +
> >  /**
> >   * kvm_mips_reset_vcpu:
> >   * @cpu: MIPSCPU
> > @@ -23,4 +25,13 @@ void kvm_mips_reset_vcpu(MIPSCPU *cpu);
> >  int kvm_mips_set_interrupt(MIPSCPU *cpu, int irq, int level);
> >  int kvm_mips_set_ipi_interrupt(MIPSCPU *cpu, int irq, int level);
> >
> > +#ifdef CONFIG_KVM
> > +int mips_kvm_type(MachineState *machine, const char *vm_type);
> > +#else
> > +static inline int mips_kvm_type(MachineState *machine, const char *vm_type)
> > +{
> > +    return 0;
> > +}
> > +#endif
> > +
> >  #endif /* KVM_MIPS_H */
> > --
> > 2.7.0
> >
Aleksandar Markovic June 27, 2020, 5:51 p.m. UTC | #3
On Wed, Jun 24, 2020 at 12:44 PM Huacai Chen <zltjiangshi@gmail.com> wrote:
>
> MIPS has two types of KVM: TE & VZ, and TE is the default type. Now we
> can't create a VZ guest in QEMU because it lacks the kvm_type() hook in
> MachineClass. This patch add the the kvm_type() hook to support both of
> the two types.
>
> Reviewed-by: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>
> Signed-off-by: Huacai Chen <chenhc@lemote.com>
> Co-developed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---

Applied to MIPS queue, with some minor changes.

>  target/mips/kvm.c      | 20 ++++++++++++++++++++
>  target/mips/kvm_mips.h | 11 +++++++++++
>  2 files changed, 31 insertions(+)
>
> diff --git a/target/mips/kvm.c b/target/mips/kvm.c
> index 96cfa10..373f582 100644
> --- a/target/mips/kvm.c
> +++ b/target/mips/kvm.c
> @@ -21,10 +21,12 @@
>  #include "qemu/main-loop.h"
>  #include "qemu/timer.h"
>  #include "sysemu/kvm.h"
> +#include "sysemu/kvm_int.h"
>  #include "sysemu/runstate.h"
>  #include "sysemu/cpus.h"
>  #include "kvm_mips.h"
>  #include "exec/memattrs.h"
> +#include "hw/boards.h"
>
>  #define DEBUG_KVM 0
>
> @@ -1270,3 +1272,21 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)
>  {
>      abort();
>  }
> +
> +int mips_kvm_type(MachineState *machine, const char *vm_type)
> +{
> +    int r;
> +    KVMState *s = KVM_STATE(machine->accelerator);
> +
> +    r = kvm_check_extension(s, KVM_CAP_MIPS_VZ);
> +    if (r > 0) {
> +        return KVM_VM_MIPS_VZ;
> +    }
> +
> +    r = kvm_check_extension(s, KVM_CAP_MIPS_TE);
> +    if (r > 0) {
> +        return KVM_VM_MIPS_TE;
> +    }
> +
> +    return -1;
> +}
> diff --git a/target/mips/kvm_mips.h b/target/mips/kvm_mips.h
> index 1e40147..171d53d 100644
> --- a/target/mips/kvm_mips.h
> +++ b/target/mips/kvm_mips.h
> @@ -12,6 +12,8 @@
>  #ifndef KVM_MIPS_H
>  #define KVM_MIPS_H
>
> +#include "cpu.h"
> +
>  /**
>   * kvm_mips_reset_vcpu:
>   * @cpu: MIPSCPU
> @@ -23,4 +25,13 @@ void kvm_mips_reset_vcpu(MIPSCPU *cpu);
>  int kvm_mips_set_interrupt(MIPSCPU *cpu, int irq, int level);
>  int kvm_mips_set_ipi_interrupt(MIPSCPU *cpu, int irq, int level);
>
> +#ifdef CONFIG_KVM
> +int mips_kvm_type(MachineState *machine, const char *vm_type);
> +#else
> +static inline int mips_kvm_type(MachineState *machine, const char *vm_type)
> +{
> +    return 0;
> +}
> +#endif
> +
>  #endif /* KVM_MIPS_H */
> --
> 2.7.0
>
>
diff mbox series

Patch

diff --git a/target/mips/kvm.c b/target/mips/kvm.c
index 96cfa10..373f582 100644
--- a/target/mips/kvm.c
+++ b/target/mips/kvm.c
@@ -21,10 +21,12 @@ 
 #include "qemu/main-loop.h"
 #include "qemu/timer.h"
 #include "sysemu/kvm.h"
+#include "sysemu/kvm_int.h"
 #include "sysemu/runstate.h"
 #include "sysemu/cpus.h"
 #include "kvm_mips.h"
 #include "exec/memattrs.h"
+#include "hw/boards.h"
 
 #define DEBUG_KVM 0
 
@@ -1270,3 +1272,21 @@  int kvm_arch_msi_data_to_gsi(uint32_t data)
 {
     abort();
 }
+
+int mips_kvm_type(MachineState *machine, const char *vm_type)
+{
+    int r;
+    KVMState *s = KVM_STATE(machine->accelerator);
+
+    r = kvm_check_extension(s, KVM_CAP_MIPS_VZ);
+    if (r > 0) {
+        return KVM_VM_MIPS_VZ;
+    }
+
+    r = kvm_check_extension(s, KVM_CAP_MIPS_TE);
+    if (r > 0) {
+        return KVM_VM_MIPS_TE;
+    }
+
+    return -1;
+}
diff --git a/target/mips/kvm_mips.h b/target/mips/kvm_mips.h
index 1e40147..171d53d 100644
--- a/target/mips/kvm_mips.h
+++ b/target/mips/kvm_mips.h
@@ -12,6 +12,8 @@ 
 #ifndef KVM_MIPS_H
 #define KVM_MIPS_H
 
+#include "cpu.h"
+
 /**
  * kvm_mips_reset_vcpu:
  * @cpu: MIPSCPU
@@ -23,4 +25,13 @@  void kvm_mips_reset_vcpu(MIPSCPU *cpu);
 int kvm_mips_set_interrupt(MIPSCPU *cpu, int irq, int level);
 int kvm_mips_set_ipi_interrupt(MIPSCPU *cpu, int irq, int level);
 
+#ifdef CONFIG_KVM
+int mips_kvm_type(MachineState *machine, const char *vm_type);
+#else
+static inline int mips_kvm_type(MachineState *machine, const char *vm_type)
+{
+    return 0;
+}
+#endif
+
 #endif /* KVM_MIPS_H */