From: Thomas Huth <thuth@redhat.com>
To: chen huacai <zltjiangshi@gmail.com>
Cc: "Laurent Vivier" <lvivier@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
"Huacai Chen" <chenhuacai@gmail.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
qemu-level <qemu-devel@nongnu.org>,
"Aleksandar Markovic" <aleksandar.qemu.devel@gmail.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"David Gibson" <dgibson@redhat.com>,
"Huacai Chen" <chenhc@lemote.com>,
"Aurelien Jarno" <aurelien@aurel32.net>
Subject: Re: [PATCH V2 for-5.2] hw/null-machine: Add the kvm_type() hook for MIPS
Date: Wed, 9 Sep 2020 09:20:34 +0200 [thread overview]
Message-ID: <e3c09cb0-1cc5-2fb3-8dc7-d2a1aed74c04@redhat.com> (raw)
In-Reply-To: <CABDp7VoRCMsW6b17XEek3-EJLHgY=bCXnx5B1ZWCOkHq0aasxw@mail.gmail.com>
On 09/09/2020 04.57, chen huacai wrote:
> Hi, all,
>
> On Wed, Sep 9, 2020 at 1:25 AM Thomas Huth <thuth@redhat.com> wrote:
>>
>> On 24/08/2020 10.11, Huacai Chen wrote:
>>> MIPS has two types of KVM: TE & VZ, and TE is the default type. Now,
>>> libvirt uses a null-machine to detect the kvm capability. In the MIPS
>>> case, it will return "KVM not supported" on a VZ platform by default.
>>> So, add the kvm_type() hook to the null-machine.
>>>
>>> This seems not a very good solution, but I cannot do it better now.
>>
>> This is still ugly. Why do the other architectures do not have the
>> same problem? Let's see... in kvm-all.c, we have:
>>
>> int type = 0;
>> [...]
>> kvm_type = qemu_opt_get(qemu_get_machine_opts(), "kvm-type");
>> if (mc->kvm_type) {
>> type = mc->kvm_type(ms, kvm_type);
>> } else if (kvm_type) {
>> ret = -EINVAL;
>> fprintf(stderr, "Invalid argument kvm-type=%s\n", kvm_type);
>> goto err;
>> }
>>
>> do {
>> ret = kvm_ioctl(s, KVM_CREATE_VM, type);
>> } while (ret == -EINTR);
>>
>> Thus the KVM_CREATE_VM ioctl is likely called with type = 0 in this
>> case (i.e. when libvirt probes with the "null"-machine).
>>
>> Now let's have a look at the kernel. The "type" parameter is passed
>> there to the architecture specific function kvm_arch_init_vm().
>> For powerpc, this looks like:
>>
>> if (type == 0) {
>> if (kvmppc_hv_ops)
>> kvm_ops = kvmppc_hv_ops;
>> else
>> kvm_ops = kvmppc_pr_ops;
>> if (!kvm_ops)
>> goto err_out;
>> } else if (type == KVM_VM_PPC_HV) {
>> if (!kvmppc_hv_ops)
>> goto err_out;
>> kvm_ops = kvmppc_hv_ops;
>> } else if (type == KVM_VM_PPC_PR) {
>> if (!kvmppc_pr_ops)
>> goto err_out;
>> kvm_ops = kvmppc_pr_ops;
>> } else
>> goto err_out;
>>
>> That means for type == 0, it automatically detects the best
>> kvm-type.
>>
>> For mips, this function looks like this:
>>
>> switch (type) {
>> #ifdef CONFIG_KVM_MIPS_VZ
>> case KVM_VM_MIPS_VZ:
>> #else
>> case KVM_VM_MIPS_TE:
>> #endif
>> break;
>> default:
>> /* Unsupported KVM type */
>> return -EINVAL;
>> };
>>
>> That means, for type == 0, it returns -EINVAL here!
>>
>> Looking at the API docu in Documentation/virt/kvm/api.rst
>> the description of the type parameter is quite sparse, but it
>> says:
>>
>> "You probably want to use 0 as machine type."
>>
>> So I think this is a bug in the implementation of KVM in the
>> mips kernel code. The kvm_arch_init_vm() in the mips code should
>> do the same as on powerpc, and use the best available KVM type
>> there instead of returning EINVAL. Once that is fixed there,
>> you don't need this patch here for QEMU anymore.
> Yes, PPC use a good method, because it can use 0 as "automatic"
> #define KVM_VM_PPC_HV 1
> #define KVM_VM_PPC_PR 2
>
> Unfortunately, MIPS cannot do like this because it define 0 as "TE":
> #define KVM_VM_MIPS_TE 0
> #define KVM_VM_MIPS_VZ 1
>
> So, it cannot be solved in kernel side, unless changing the definition
> of TE/VZ, but I think changing their definition is also unacceptable.
Ouch, ok, now I understood the problem. That sounds like a really bad
decision on the kernel side.
But I think you could at least try to get it fixed on the kernel side:
Propose a patch to rename KVM_VM_MIPS_TE to KVM_VM_MIPS_DEFAULT and use
2 as new value for TE. The code that handles the default 0 case should
then prefer TE over VZ, so that old userspace applications that provide
0 will continue to work as they did before, so I hope that the change is
acceptable by the kernel folks. You should add a remark to the patch
description that 0 is the established default value for probing in the
QEMU/libvirt stack and that your patch is required on the kernel side to
avoid ugly hacks in QEMU userspace code.
If they still reject your patch, I guess we have to bite the bullet and
add your patch here...
Thanks,
Thomas
next prev parent reply other threads:[~2020-09-09 7:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-24 8:11 [PATCH V2 for-5.2] hw/null-machine: Add the kvm_type() hook for MIPS Huacai Chen
2020-09-02 13:55 ` Philippe Mathieu-Daudé
2020-09-03 0:58 ` Huacai Chen
2020-09-07 3:39 ` Philippe Mathieu-Daudé
2020-09-08 0:41 ` Huacai Chen
2020-09-08 17:25 ` Thomas Huth
2020-09-08 17:59 ` Eduardo Habkost
2020-09-08 18:12 ` Philippe Mathieu-Daudé
2020-09-09 2:57 ` chen huacai
2020-09-09 7:20 ` Thomas Huth [this message]
2020-09-10 1:31 ` Huacai Chen
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=e3c09cb0-1cc5-2fb3-8dc7-d2a1aed74c04@redhat.com \
--to=thuth@redhat.com \
--cc=aleksandar.qemu.devel@gmail.com \
--cc=aleksandar.rikalo@syrmia.com \
--cc=aurelien@aurel32.net \
--cc=chenhc@lemote.com \
--cc=chenhuacai@gmail.com \
--cc=dgibson@redhat.com \
--cc=f4bug@amsat.org \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=zltjiangshi@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).