diff mbox series

KVM: MIPS: Change the definition of kvm type

Message ID 1599734031-28746-1-git-send-email-chenhc@lemote.com
State New
Headers show
Series KVM: MIPS: Change the definition of kvm type | expand

Commit Message

Huacai Chen Sept. 10, 2020, 10:33 a.m. UTC
MIPS defines two kvm types:

 #define KVM_VM_MIPS_TE          0
 #define KVM_VM_MIPS_VZ          1

In Documentation/virt/kvm/api.rst it is said that "You probably want to
use 0 as machine type", which implies that type 0 be the "automatic" or
"default" type. And, in user-space libvirt use the null-machine (with
type 0) to detect the kvm capability, which returns "KVM not supported"
on a VZ platform.

I try to fix it in QEMU but it is ugly:
https://lists.nongnu.org/archive/html/qemu-devel/2020-08/msg05629.html

And Thomas Huth suggests me to change the definition of kvm type:
https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg03281.html

So I define like this:

 #define KVM_VM_MIPS_AUTO        0
 #define KVM_VM_MIPS_VZ          1
 #define KVM_VM_MIPS_TE          2

Since VZ and TE cannot co-exists, using type 0 on a TE platform will
still return success (so old user-space tools have no problems on new
kernels); the advantage is that using type 0 on a VZ platform will not
return failure. So, the only problem is "new user-space tools use type
2 on old kernels", but if we treat this as a kernel bug, we can backport
this patch to old stable kernels.

Cc: stable@vger.kernel.org
Signed-off-by: Huacai Chen <chenhc@lemote.com>
---
 arch/mips/kvm/mips.c     | 2 ++
 include/uapi/linux/kvm.h | 5 +++--
 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Thomas Huth Sept. 19, 2020, 9:18 a.m. UTC | #1
On 11/09/2020 19.22, Paolo Bonzini wrote:
> On 10/09/20 12:33, Huacai Chen wrote:

>> MIPS defines two kvm types:

>>

>>  #define KVM_VM_MIPS_TE          0

>>  #define KVM_VM_MIPS_VZ          1

>>

>> In Documentation/virt/kvm/api.rst it is said that "You probably want to

>> use 0 as machine type", which implies that type 0 be the "automatic" or

>> "default" type. And, in user-space libvirt use the null-machine (with

>> type 0) to detect the kvm capability, which returns "KVM not supported"

>> on a VZ platform.

>>

>> I try to fix it in QEMU but it is ugly:

>> https://lists.nongnu.org/archive/html/qemu-devel/2020-08/msg05629.html

>>

>> And Thomas Huth suggests me to change the definition of kvm type:

>> https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg03281.html

>>

>> So I define like this:

>>

>>  #define KVM_VM_MIPS_AUTO        0

>>  #define KVM_VM_MIPS_VZ          1

>>  #define KVM_VM_MIPS_TE          2

>>

>> Since VZ and TE cannot co-exists, using type 0 on a TE platform will

>> still return success (so old user-space tools have no problems on new

>> kernels); the advantage is that using type 0 on a VZ platform will not

>> return failure. So, the only problem is "new user-space tools use type

>> 2 on old kernels", but if we treat this as a kernel bug, we can backport

>> this patch to old stable kernels.

> 

> I'm a bit wary to do that.  However it's not an issue for QEMU since it

> generally updates the kernel headers.


Are there any other userspace programs beside QEMU that use KVM on MIPS?
If there aren't any other serious userspace programs, I think we should
go ahead with this patch here. Otherwise, what are the other programs
that could be affected?

 Thomas
Paolo Bonzini Sept. 19, 2020, 3:36 p.m. UTC | #2
On 19/09/20 11:18, Thomas Huth wrote:
>>>

>>> So I define like this:

>>>

>>>  #define KVM_VM_MIPS_AUTO        0

>>>  #define KVM_VM_MIPS_VZ          1

>>>  #define KVM_VM_MIPS_TE          2

>>>

>>> Since VZ and TE cannot co-exists, using type 0 on a TE platform will

>>> still return success (so old user-space tools have no problems on new

>>> kernels); the advantage is that using type 0 on a VZ platform will not

>>> return failure. So, the only problem is "new user-space tools use type

>>> 2 on old kernels", but if we treat this as a kernel bug, we can backport

>>> this patch to old stable kernels.

>> I'm a bit wary to do that.  However it's not an issue for QEMU since it

>> generally updates the kernel headers.

> Are there any other userspace programs beside QEMU that use KVM on MIPS?

> If there aren't any other serious userspace programs, I think we should

> go ahead with this patch here. Otherwise, what are the other programs

> that could be affected?


kvmtool (aka lkvm) I guess.  I don't know if it is affected but I
wouldn't be worried.

Paolo
diff mbox series

Patch

diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index d7ba3f9..9efeb67 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -138,6 +138,8 @@  extern void kvm_init_loongson_ipi(struct kvm *kvm);
 int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 {
 	switch (type) {
+	case KVM_VM_MIPS_AUTO:
+		break;
 #ifdef CONFIG_KVM_MIPS_VZ
 	case KVM_VM_MIPS_VZ:
 #else
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 29ba8e8..cfc1ae2 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -790,9 +790,10 @@  struct kvm_ppc_resize_hpt {
 #define KVM_VM_PPC_HV 1
 #define KVM_VM_PPC_PR 2
 
-/* on MIPS, 0 forces trap & emulate, 1 forces VZ ASE */
-#define KVM_VM_MIPS_TE		0
+/* on MIPS, 0 indicates auto, 1 forces VZ ASE, 2 forces trap & emulate */
+#define KVM_VM_MIPS_AUTO	0
 #define KVM_VM_MIPS_VZ		1
+#define KVM_VM_MIPS_TE		2
 
 #define KVM_S390_SIE_PAGE_OFFSET 1