From: Andrew Jones <drjones@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: peter.maydell@linaro.org, mdroth@linux.vnet.ibm.com,
armbru@redhat.com, abologna@redhat.com, qemu-devel@nongnu.org,
qemu-arm@nongnu.org
Subject: Re: [Qemu-arm] [Qemu-devel] [PATCH v3 3/3] arm: implement query-gic-capability
Date: Mon, 7 Mar 2016 06:12:38 +0100 [thread overview]
Message-ID: <20160307051025.GB2885@localhost.redhat.com> (raw)
In-Reply-To: <1457324608-11434-4-git-send-email-peterx@redhat.com>
On Mon, Mar 07, 2016 at 12:23:28PM +0800, Peter Xu wrote:
> For emulated GIC capabilities, currently only gicv2 is supported. We
> need to add gicv3 in when emulated gicv3 ready. For KVM accelerated ARM
> VM, we detect the capability bits using ioctls.
>
> When probing the KVM capabilities, we cannot leverage existing helper
> functions like kvm_create_device() since QEMU might be using TCG while
> probing (actually this is the case for libvirt probing). So, one
> temporary VM is created to do the probing.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> target-arm/machine.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 104 insertions(+), 1 deletion(-)
>
> diff --git a/target-arm/machine.c b/target-arm/machine.c
> index 60bd5c1..ff50411 100644
> --- a/target-arm/machine.c
> +++ b/target-arm/machine.c
> @@ -1,3 +1,5 @@
> +#include <linux/kvm.h>
> +#include <sys/ioctl.h>
> #include "qemu/osdep.h"
> #include "hw/hw.h"
> #include "hw/boards.h"
> @@ -347,7 +349,108 @@ const char *gicv3_class_name(void)
> exit(1);
> }
>
> +static GICCapability *gic_cap_new(int version)
> +{
> + GICCapability *cap = g_new0(GICCapability, 1);
> + cap->version = version;
> + /* by default, support none */
> + cap->emulated = false;
> + cap->kernel = false;
> + return cap;
> +}
> +
> +static GICCapabilityList *gic_cap_list_add(GICCapabilityList *head,
> + GICCapability *cap)
> +{
> + GICCapabilityList *item = g_new0(GICCapabilityList, 1);
> + item->value = cap;
> + item->next = head;
> + return item;
> +}
> +
> +#ifdef CONFIG_KVM
> +/*
> + * This is merely the same as kvm_create_device(). The only
> + * difference is we are using raw fds rather than KVMState, so that
> + * we can use it even without kvm_state initialized.
> + */
> +static int kvm_create_device_fds(int kvm_fd, int vmfd,
> + uint64_t type, bool test)
I don't think we need this helper function. Who else will call it?
Particularly without test==true? Anyway, I think three ioctls directly
called from qmp_query_gic_capability should be OK.
> +{
> + int ret;
> + struct kvm_create_device create_dev;
> +
> + create_dev.type = type;
> + create_dev.fd = -1;
> + create_dev.flags = test ? KVM_CREATE_DEVICE_TEST : 0;
> +
> + if (ioctl(kvm_fd, KVM_CHECK_EXTENSION, KVM_CAP_DEVICE_CTRL) <= 0) {
> + return -ENOTSUP;
> + }
> +
> + ret = ioctl(vmfd, KVM_CREATE_DEVICE, &create_dev);
> + if (ret) {
> + return ret;
> + }
> +
> + return test ? 0 : create_dev.fd;
> +}
> +#endif
> +
> GICCapabilityList *qmp_query_gic_capability(Error **errp)
> {
> - return NULL;
> + GICCapabilityList *head = NULL;
> + GICCapability *v2 = gic_cap_new(2), *v3 = gic_cap_new(3);
> +
> + v2->emulated = true;
> + /* FIXME: we'd change to true after we get emulated GICv3. */
> + v3->emulated = false;
> +
> +#ifdef CONFIG_KVM
> + {
> + /*
> + * HACK: here we create one temporary VM, do the probing,
> + * then release it properly.
> + */
> + int kvm_fd = -1;
> + int vmfd = -1;
> +
> + kvm_fd = qemu_open("/dev/kvm", O_RDWR);
> + if (kvm_fd == -1) {
> + /* KVM may not enabled on host, which is fine. */
> + goto out;
> + }
> +
> + do {
> + /* For ARM, VM type could only be zero now. */
> + vmfd = ioctl(kvm_fd, KVM_CREATE_VM, 0);
> + } while (vmfd == -EINTR);
> +
> + if (vmfd < 0) {
> + goto kvm_fd_close;
> + }
> +
> + /* Test KVM GICv2 */
> + if (kvm_create_device_fds(kvm_fd, vmfd, KVM_DEV_TYPE_ARM_VGIC_V2,
> + true) >= 0) {
> + v2->kernel = true;
> + }
> +
> + /* Test KVM GICv3 */
> + if (kvm_create_device_fds(kvm_fd, vmfd, KVM_DEV_TYPE_ARM_VGIC_V3,
> + true) >= 0) {
> + v3->kernel = true;
> + }
> +
> + close(vmfd);
> +kvm_fd_close:
> + close(kvm_fd);
> + }
> +#endif
> +
> +out:
> + head = gic_cap_list_add(head, v2);
> + head = gic_cap_list_add(head, v3);
> +
> + return head;
> }
> --
> 2.4.3
>
>
WARNING: multiple messages have this Message-ID (diff)
From: Andrew Jones <drjones@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: wei@redhat.com, peter.maydell@linaro.org,
mdroth@linux.vnet.ibm.com, armbru@redhat.com,
abologna@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 3/3] arm: implement query-gic-capability
Date: Mon, 7 Mar 2016 06:12:38 +0100 [thread overview]
Message-ID: <20160307051025.GB2885@localhost.redhat.com> (raw)
In-Reply-To: <1457324608-11434-4-git-send-email-peterx@redhat.com>
On Mon, Mar 07, 2016 at 12:23:28PM +0800, Peter Xu wrote:
> For emulated GIC capabilities, currently only gicv2 is supported. We
> need to add gicv3 in when emulated gicv3 ready. For KVM accelerated ARM
> VM, we detect the capability bits using ioctls.
>
> When probing the KVM capabilities, we cannot leverage existing helper
> functions like kvm_create_device() since QEMU might be using TCG while
> probing (actually this is the case for libvirt probing). So, one
> temporary VM is created to do the probing.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> target-arm/machine.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 104 insertions(+), 1 deletion(-)
>
> diff --git a/target-arm/machine.c b/target-arm/machine.c
> index 60bd5c1..ff50411 100644
> --- a/target-arm/machine.c
> +++ b/target-arm/machine.c
> @@ -1,3 +1,5 @@
> +#include <linux/kvm.h>
> +#include <sys/ioctl.h>
> #include "qemu/osdep.h"
> #include "hw/hw.h"
> #include "hw/boards.h"
> @@ -347,7 +349,108 @@ const char *gicv3_class_name(void)
> exit(1);
> }
>
> +static GICCapability *gic_cap_new(int version)
> +{
> + GICCapability *cap = g_new0(GICCapability, 1);
> + cap->version = version;
> + /* by default, support none */
> + cap->emulated = false;
> + cap->kernel = false;
> + return cap;
> +}
> +
> +static GICCapabilityList *gic_cap_list_add(GICCapabilityList *head,
> + GICCapability *cap)
> +{
> + GICCapabilityList *item = g_new0(GICCapabilityList, 1);
> + item->value = cap;
> + item->next = head;
> + return item;
> +}
> +
> +#ifdef CONFIG_KVM
> +/*
> + * This is merely the same as kvm_create_device(). The only
> + * difference is we are using raw fds rather than KVMState, so that
> + * we can use it even without kvm_state initialized.
> + */
> +static int kvm_create_device_fds(int kvm_fd, int vmfd,
> + uint64_t type, bool test)
I don't think we need this helper function. Who else will call it?
Particularly without test==true? Anyway, I think three ioctls directly
called from qmp_query_gic_capability should be OK.
> +{
> + int ret;
> + struct kvm_create_device create_dev;
> +
> + create_dev.type = type;
> + create_dev.fd = -1;
> + create_dev.flags = test ? KVM_CREATE_DEVICE_TEST : 0;
> +
> + if (ioctl(kvm_fd, KVM_CHECK_EXTENSION, KVM_CAP_DEVICE_CTRL) <= 0) {
> + return -ENOTSUP;
> + }
> +
> + ret = ioctl(vmfd, KVM_CREATE_DEVICE, &create_dev);
> + if (ret) {
> + return ret;
> + }
> +
> + return test ? 0 : create_dev.fd;
> +}
> +#endif
> +
> GICCapabilityList *qmp_query_gic_capability(Error **errp)
> {
> - return NULL;
> + GICCapabilityList *head = NULL;
> + GICCapability *v2 = gic_cap_new(2), *v3 = gic_cap_new(3);
> +
> + v2->emulated = true;
> + /* FIXME: we'd change to true after we get emulated GICv3. */
> + v3->emulated = false;
> +
> +#ifdef CONFIG_KVM
> + {
> + /*
> + * HACK: here we create one temporary VM, do the probing,
> + * then release it properly.
> + */
> + int kvm_fd = -1;
> + int vmfd = -1;
> +
> + kvm_fd = qemu_open("/dev/kvm", O_RDWR);
> + if (kvm_fd == -1) {
> + /* KVM may not enabled on host, which is fine. */
> + goto out;
> + }
> +
> + do {
> + /* For ARM, VM type could only be zero now. */
> + vmfd = ioctl(kvm_fd, KVM_CREATE_VM, 0);
> + } while (vmfd == -EINTR);
> +
> + if (vmfd < 0) {
> + goto kvm_fd_close;
> + }
> +
> + /* Test KVM GICv2 */
> + if (kvm_create_device_fds(kvm_fd, vmfd, KVM_DEV_TYPE_ARM_VGIC_V2,
> + true) >= 0) {
> + v2->kernel = true;
> + }
> +
> + /* Test KVM GICv3 */
> + if (kvm_create_device_fds(kvm_fd, vmfd, KVM_DEV_TYPE_ARM_VGIC_V3,
> + true) >= 0) {
> + v3->kernel = true;
> + }
> +
> + close(vmfd);
> +kvm_fd_close:
> + close(kvm_fd);
> + }
> +#endif
> +
> +out:
> + head = gic_cap_list_add(head, v2);
> + head = gic_cap_list_add(head, v3);
> +
> + return head;
> }
> --
> 2.4.3
>
>
next prev parent reply other threads:[~2016-03-07 5:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-07 4:23 [Qemu-arm] [PATCH v3 0/3] ARM: add query-gic-capability SMP command Peter Xu
2016-03-07 4:23 ` [Qemu-devel] " Peter Xu
2016-03-07 4:23 ` [Qemu-arm] [PATCH v3 1/3] arm: qmp: add GICCapability struct Peter Xu
2016-03-07 4:23 ` [Qemu-devel] " Peter Xu
2016-03-07 4:23 ` [Qemu-arm] [PATCH v3 2/3] arm: qmp: add query-gic-capability interface Peter Xu
2016-03-07 4:23 ` [Qemu-devel] " Peter Xu
2016-03-07 4:23 ` [Qemu-arm] [PATCH v3 3/3] arm: implement query-gic-capability Peter Xu
2016-03-07 4:23 ` [Qemu-devel] " Peter Xu
2016-03-07 5:12 ` Andrew Jones [this message]
2016-03-07 5:12 ` Andrew Jones
2016-03-07 5:38 ` [Qemu-arm] " Peter Xu
2016-03-07 5:38 ` Peter Xu
2016-03-07 7:38 ` [Qemu-arm] " Andrew Jones
2016-03-07 7:38 ` Andrew Jones
2016-03-07 9:55 ` [Qemu-arm] [PATCH v3 0/3] ARM: add query-gic-capability SMP command Andrea Bolognani
2016-03-07 9:55 ` [Qemu-devel] " Andrea Bolognani
2016-03-08 5:20 ` [Qemu-arm] " Peter Xu
2016-03-08 5:20 ` [Qemu-devel] " Peter Xu
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=20160307051025.GB2885@localhost.redhat.com \
--to=drjones@redhat.com \
--cc=abologna@redhat.com \
--cc=armbru@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.