Skip to contentSkip to conversation

ARM: add query-gic-capabilities SMP command

PATCH Superseded Peter Xu 5 participants 35 messages Mar 18, 2016 – Mar 24, 2016

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

v5 cover ARM: add query-gic-capabilities SMP command

v5 changes:
- patch 2: moved to target-arm/monitor.c (from target-arm/machine.c)

           [Peter]

- patch 3: splitted into three patches: [all from Peter's comments]
- patch 3 (new): leverage kvm_arm_create_scratch_host_vcpu(), tiny enhancement of old one to suite our need
- patch 4: introduce kvm_support_device() in kvm-all.c
- patch 5: do the implementation.

v4 changes:
- all: rename query-gic-capability to query-gic-capabilities [Andrea]
- patch 3: rename helper function to kvm_support_device, make it inline and lighter. [Drew]

v3 changes:
- patch 2: remove func declaration, add qmp header [Drew]
- patch 3: being able to detect KVM GIC capabilities even without kvm enabled [Andrea]: this is a little bit hacky, need some more review on this.

v2 changes:
- result layout change: use array and dict for the capability bits rather than a single array of strings [Andrea/Markus]
- spelling out what GIC is in doc [Eric]

This patch is to add ARM-specific command "query-gic-capability".

The new command can report which kind of GIC device the host/QEMU support. The returned result is in the form of array.

Sample command and output:

{"execute": "query-gic-capability"}
{"return": [{"emulated": false, "version": 3, "kernel": false},

            {"emulated": true, "version": 2, "kernel": true}]}

Testing:

Smoke tests on both x86 (emulated) and another moonshot ARM server.

Peter Xu (5):
arm: qmp: add GICCapability struct
arm: qmp: add query-gic-capabilities interface
arm: enhance kvm_arm_create_scratch_host_vcpu
kvm: add kvm_support_device() helper function
arm: implement query-gic-capabilities

 include/sysemu/kvm.h     |  9 +++++
 kvm-all.c                | 15 +++++++++
 monitor.c                |  8 +++++
 qapi-schema.json         | 33 +++++++++++++++++++
 qmp-commands.hx          | 26 +++++++++++++++
 scripts/qapi.py          |  1 +
 target-arm/Makefile.objs |  2 +-
 target-arm/kvm.c         | 10 +++++-
 target-arm/kvm_arm.h     |  6 ++--
 target-arm/monitor.c     | 86 ++++++++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 192 insertions(+), 4 deletions(-)
 create mode 100644 target-arm/monitor.c
Signature · 1 line
2.4.3
author
#1 lore raw

PATCH v5 1/5 arm: qmp: add GICCapability struct

Define new struct to describe whether we support specific GIC version.

---
 qapi-schema.json | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
qapi-schema.json +22 -0
index f253a37..da9671a 100644
@@ -4134,3 +4134,25 @@
 ##
 { 'enum': 'ReplayMode',
   'data': [ 'none', 'record', 'play' ] }
+
+##
+# @GICCapability:
+#
+# This struct describes capability for a specific GIC version. These
+# bits are not only decided by QEMU/KVM software version, but also
+# decided by the hardware that the program is running upon.
+#
+# @version:  version of GIC to be described.
+#
+# @emulated: whether current QEMU/hardware supports emulated GIC
+#            device in user space.
+#
+# @kernel:   whether current QEMU/hardware supports hardware
+#            accelerated GIC device in kernel.
+#
+# Since: 2.6
+##
+{ 'struct': 'GICCapability',
+  'data': { 'version': 'int',
+            'emulated': 'bool',
+            'kernel': 'bool' } }
Signature · 1 line
2.4.3
#2 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 1/5] arm: qmp: add GICCapability struct

Quoted 27 lines · Peter Xu

Define new struct to describe whether we support specific GIC version.

---
 qapi-schema.json | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
qapi-schema.json +12 -0
index f253a37..da9671a 100644
@@ -4134,3 +4134,25 @@
 ##
 { 'enum': 'ReplayMode',
   'data': [ 'none', 'record', 'play' ] }
+
+##
+# @GICCapability:
+#
+# This struct describes capability for a specific GIC version. These
+# bits are not only decided by QEMU/KVM software version, but also
+# decided by the hardware that the program is running upon.
+#
+# @version:  version of GIC to be described.
+#
+# @emulated: whether current QEMU/hardware supports emulated GIC
+#            device in user space.

qapi-schema.json line 4158

Quoted 10 lines
qapi-schema.json +10 -0
+#
+# @kernel:   whether current QEMU/hardware supports hardware
+#            accelerated GIC device in kernel.
+#
+# Since: 2.6
+##
+{ 'struct': 'GICCapability',
+  'data': { 'version': 'int',
+            'emulated': 'bool',
+            'kernel': 'bool' } }

Are all four combinations of (emulated, kernel) possible?

#3 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 1/5] arm: qmp: add GICCapability struct

Quoted 33 lines · Markus Armbruster
Quoted 31 lines · Peter Xu

Define new struct to describe whether we support specific GIC version.

---
 qapi-schema.json | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
qapi-schema.json +16 -0
index f253a37..da9671a 100644
@@ -4134,3 +4134,25 @@
 ##
 { 'enum': 'ReplayMode',
   'data': [ 'none', 'record', 'play' ] }
+
+##
+# @GICCapability:
+#
+# This struct describes capability for a specific GIC version. These
+# bits are not only decided by QEMU/KVM software version, but also
+# decided by the hardware that the program is running upon.
+#
+# @version:  version of GIC to be described.
+#
+# @emulated: whether current QEMU/hardware supports emulated GIC
+#            device in user space.
+#
+# @kernel:   whether current QEMU/hardware supports hardware
+#            accelerated GIC device in kernel.
+#
Quoted 8 lines

qapi-schema.json line 4158

Quoted 6 lines
qapi-schema.json +6 -0
+# Since: 2.6
+##
+{ 'struct': 'GICCapability',
+  'data': { 'version': 'int',
+            'emulated': 'bool',
+            'kernel': 'bool' } }

Are all four combinations of (emulated, kernel) possible?

Moreover, what do the combinations mean from a practical point of view? What would a management application do with the information?

author
#4 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 1/5] arm: qmp: add GICCapability struct

Quoted 16 lines · Markus Armbruster
Quoted 15 lines · Markus Armbruster
Quoted 15 lines
qapi-schema.json +15 -0
+##
+# @GICCapability:
+#
+# This struct describes capability for a specific GIC version. These
+# bits are not only decided by QEMU/KVM software version, but also
+# decided by the hardware that the program is running upon.
+#
+# @version:  version of GIC to be described.
+#
+# @emulated: whether current QEMU/hardware supports emulated GIC
+#            device in user space.
+#
+# @kernel:   whether current QEMU/hardware supports hardware
+#            accelerated GIC device in kernel.
+#
Quoted 8 lines
Quoted 8 lines

qapi-schema.json line 4158

Quoted 6 lines
qapi-schema.json +6 -0
+# Since: 2.6
+##
+{ 'struct': 'GICCapability',
+  'data': { 'version': 'int',
+            'emulated': 'bool',
+            'kernel': 'bool' } }

Are all four combinations of (emulated, kernel) possible?

Currently, version can only be 2 or 3. And for now, we should only support:

- emulated/kernel support for v2
- kernel support for v3

and emulated v3 is still not supported.

Quoted 2 lines

Moreover, what do the combinations mean from a practical point of view? What would a management application do with the information?

AFAIU, this command will mostly be used by libvirt. E.g., on ARM host, user can choose which kind of GIC device he/she uses. However, not all of them are supported, and it is decided by both the ARM hardware and the software (here software should include at least QEMU and the kernel version). With this command, libvirt can easily know what is supported, and what is not.

So it can: warn the user before-hand during configuration like "GIC emulated/kvm-accelerated version X is/isn't supported",

rather than: firstly, configuration success. After that, QEMU boot failed with ambiguous error.

I can add more explainations into the commit message (some can be added to the schema directly possibly) about why we need this command, and what does every entry mean.

Thanks!

-- peterx

#5 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 1/5] arm: qmp: add GICCapability struct

Quoted 47 lines · Peter Xu
Quoted 16 lines · Markus Armbruster
Quoted 15 lines · Markus Armbruster
Quoted 15 lines
qapi-schema.json +15 -0
+##
+# @GICCapability:
+#
+# This struct describes capability for a specific GIC version. These
+# bits are not only decided by QEMU/KVM software version, but also
+# decided by the hardware that the program is running upon.
+#
+# @version:  version of GIC to be described.
+#
+# @emulated: whether current QEMU/hardware supports emulated GIC
+#            device in user space.
+#
+# @kernel:   whether current QEMU/hardware supports hardware
+#            accelerated GIC device in kernel.
+#
Quoted 8 lines
Quoted 8 lines

qapi-schema.json line 4158

Quoted 6 lines
qapi-schema.json +6 -0
+# Since: 2.6
+##
+{ 'struct': 'GICCapability',
+  'data': { 'version': 'int',
+            'emulated': 'bool',
+            'kernel': 'bool' } }

Are all four combinations of (emulated, kernel) possible?

Currently, version can only be 2 or 3. And for now, we should only support:

- emulated/kernel support for v2
- kernel support for v3

and emulated v3 is still not supported.

Quoted 2 lines

Moreover, what do the combinations mean from a practical point of view? What would a management application do with the information?

AFAIU, this command will mostly be used by libvirt. E.g., on ARM host, user can choose which kind of GIC device he/she uses. However, not all of them are supported, and it is decided by both the ARM hardware and the software (here software should include at least QEMU and the kernel version). With this command, libvirt can easily know what is supported, and what is not.

So it can: warn the user before-hand during configuration like "GIC emulated/kvm-accelerated version X is/isn't supported",

Quoted 6 lines

rather than: firstly, configuration success. After that, QEMU boot failed with ambiguous error.

I can add more explainations into the commit message (some can be added to the schema directly possibly) about why we need this command, and what does every entry mean.

So GICCapability essentially tells its users whether certain configurations have a chance to work.

I think what's missing in your patch is the connection from GICCapability to the actual configuration options. As is, you just have to know what options the presence of each possible GICCapability value unlocks. It needs to be documented instead.

author
#6 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 1/5] arm: qmp: add GICCapability struct

Quoted 17 lines · Markus Armbruster
Quoted 15 lines · Peter Xu
Quoted 14 lines · Markus Armbruster
Quoted 13 lines · Markus Armbruster
Quoted 13 lines
qapi-schema.json +13 -0
+##
+# @GICCapability:
+#
+# This struct describes capability for a specific GIC version. These
+# bits are not only decided by QEMU/KVM software version, but also
+# decided by the hardware that the program is running upon.
+#
+# @version:  version of GIC to be described.
+#
+# @emulated: whether current QEMU/hardware supports emulated GIC
+#            device in user space.
+#
+# @kernel:   whether current QEMU/hardware supports hardware
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

qapi-schema.json line 4158

Quoted 8 lines
qapi-schema.json +8 -0
+#            accelerated GIC device in kernel.
+#
+# Since: 2.6
+##
+{ 'struct': 'GICCapability',
+  'data': { 'version': 'int',
+            'emulated': 'bool',
+            'kernel': 'bool' } }

[*] Marking here...

Quoted 7 lines

So GICCapability essentially tells its users whether certain configurations have a chance to work.

I think what's missing in your patch is the connection from GICCapability to the actual configuration options. As is, you just have to know what options the presence of each possible GICCapability value unlocks. It needs to be documented instead.

What I understand is that, above [*] should have explained what does each entry mean. E.g., as mentioned in the qapi-schema, there are explainations about "version", "emulated" and "kernel" key words. If we go deeper into e.g., "emulated" key word, we will got:

"whether current QEMU/hardware supports emulated GIC device in user
space."

So this boolean will tell just as it is explained.

Maybe I failed to get the point of your review comment... :( Would you please give an example on how should I better express this relationship?

(btw, I have updated the commit message in v6 for current patch, to tell more about why we need this, and why we decided to add this ad hoc command. I'd be glad if we can continue the discussion based on that one. Thanks!)

-- peterx

#7 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 1/5] arm: qmp: add GICCapability struct

Quoted 42 lines · Peter Xu
Quoted 17 lines · Markus Armbruster
Quoted 15 lines · Peter Xu
Quoted 14 lines · Markus Armbruster
Quoted 13 lines · Markus Armbruster
Quoted 13 lines
qapi-schema.json +13 -0
+##
+# @GICCapability:
+#
+# This struct describes capability for a specific GIC version. These
+# bits are not only decided by QEMU/KVM software version, but also
+# decided by the hardware that the program is running upon.
+#
+# @version:  version of GIC to be described.
+#
+# @emulated: whether current QEMU/hardware supports emulated GIC
+#            device in user space.
+#
+# @kernel:   whether current QEMU/hardware supports hardware
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

qapi-schema.json line 4158

Quoted 8 lines
qapi-schema.json +8 -0
+#            accelerated GIC device in kernel.
+#
+# Since: 2.6
+##
+{ 'struct': 'GICCapability',
+  'data': { 'version': 'int',
+            'emulated': 'bool',
+            'kernel': 'bool' } }

[*] Marking here...

Quoted 7 lines

So GICCapability essentially tells its users whether certain configurations have a chance to work.

I think what's missing in your patch is the connection from GICCapability to the actual configuration options. As is, you just have to know what options the presence of each possible GICCapability value unlocks. It needs to be documented instead.

What I understand is that, above [*] should have explained what does each entry mean. E.g., as mentioned in the qapi-schema, there are explainations about "version", "emulated" and "kernel" key words. If we go deeper into e.g., "emulated" key word, we will got:

Quoted 8 lines

"whether current QEMU/hardware supports emulated GIC device in user
space."

So this boolean will tell just as it is explained.

Maybe I failed to get the point of your review comment... :( Would you please give an example on how should I better express this relationship?

Can you tell me what a management application is supposed to do with the information returned by query-gic-capabilities? Not just in general terms, like "using this information, libvirt can warn the user during configuration of guests when specified GIC device type is not supported, but specifics. Something like "-frobnicate mutter=mumble won't work unless query-gic-capabilities reports emulated version 2 is supported" for every piece of configuration that should be vetted against query-gic-capabilities.

Quoted 4 lines

(btw, I have updated the commit message in v6 for current patch, to tell more about why we need this, and why we decided to add this ad hoc command. I'd be glad if we can continue the discussion based on that one. Thanks!)

author
#8 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 1/5] arm: qmp: add GICCapability struct

Quoted 8 lines · Markus Armbruster

Can you tell me what a management application is supposed to do with the information returned by query-gic-capabilities? Not just in general terms, like "using this information, libvirt can warn the user during configuration of guests when specified GIC device type is not supported, but specifics. Something like "-frobnicate mutter=mumble won't work unless query-gic-capabilities reports emulated version 2 is supported" for every piece of configuration that should be vetted against query-gic-capabilities.

I suppose that won't be a very big problem since possibly only libvirt will use it... I agree that it's better to explain it more clearly though. How about adding these lines into patch 1 commit message:

"""
For example, if we got the query result:

{"return": {"capabilities":
[ {"emulated": false, "version": 3, "kernel": true},

    {"emulated": true, "version": 2, "kernel": false} ] } }

Then it means that we support emulated GIC version 2 using:

qemu-system-aarch64 -M virt,gic-version=2 ...

or kvm-accelerated GIC version 3 using:

qemu-system-aarch64 -enable-kvm -M virt,gic-version=3 ...

If we specify other explicit GIC version rather than the above, QEMU will not be able to boot.
"""

Thanks.

-- peterx

#9 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 1/5] arm: qmp: add GICCapability struct

Quoted 22 lines · Peter Xu
Quoted 8 lines · Markus Armbruster

Can you tell me what a management application is supposed to do with the information returned by query-gic-capabilities? Not just in general terms, like "using this information, libvirt can warn the user during configuration of guests when specified GIC device type is not supported, but specifics. Something like "-frobnicate mutter=mumble won't work unless query-gic-capabilities reports emulated version 2 is supported" for every piece of configuration that should be vetted against query-gic-capabilities.

I suppose that won't be a very big problem since possibly only libvirt will use it... I agree that it's better to explain it more clearly though. How about adding these lines into patch 1 commit message:

"""
For example, if we got the query result:

{"return": {"capabilities":
[ {"emulated": false, "version": 3, "kernel": true},

    {"emulated": true, "version": 2, "kernel": false} ] } }
Quoted 7 lines

Then it means that we support emulated GIC version 2 using:

qemu-system-aarch64 -M virt,gic-version=2 ...

or kvm-accelerated GIC version 3 using:

qemu-system-aarch64 -enable-kvm -M virt,gic-version=3 ...

I'd say "qemu-system-aarch64 -M virt,accel=kvm,gic=version=3"

Quoted 3 lines

If we specify other explicit GIC version rather than the above, QEMU will not be able to boot.
"""

Works for me.

author
#10 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 1/5] arm: qmp: add GICCapability struct

Quoted 32 lines · Markus Armbruster
Quoted 22 lines · Peter Xu
Quoted 8 lines · Markus Armbruster

Can you tell me what a management application is supposed to do with the information returned by query-gic-capabilities? Not just in general terms, like "using this information, libvirt can warn the user during configuration of guests when specified GIC device type is not supported, but specifics. Something like "-frobnicate mutter=mumble won't work unless query-gic-capabilities reports emulated version 2 is supported" for every piece of configuration that should be vetted against query-gic-capabilities.

I suppose that won't be a very big problem since possibly only libvirt will use it... I agree that it's better to explain it more clearly though. How about adding these lines into patch 1 commit message:

"""
For example, if we got the query result:

{"return": {"capabilities":
[ {"emulated": false, "version": 3, "kernel": true},

    {"emulated": true, "version": 2, "kernel": false} ] } }
Quoted 7 lines

Then it means that we support emulated GIC version 2 using:

qemu-system-aarch64 -M virt,gic-version=2 ...

or kvm-accelerated GIC version 3 using:

qemu-system-aarch64 -enable-kvm -M virt,gic-version=3 ...

Quoted 7 lines

I'd say "qemu-system-aarch64 -M virt,accel=kvm,gic=version=3"

Quoted 3 lines

If we specify other explicit GIC version rather than the above, QEMU will not be able to boot.
"""

Works for me.

Thanks, will include this in v7.

-- peterx

Reviewed-by on v5 1/5
#11 lore raw

Re: [Qemu-arm] [PATCH v5 1/5] arm: qmp: add GICCapability struct

In reply to Peter Xu
Quoted 12 lines · Peter Xu

Define new struct to describe whether we support specific GIC version.

---
 qapi-schema.json | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
qapi-schema.json +0 -0
index f253a37..da9671a 100644

qapi-schema.json line 4141

Quoted 8 lines
qapi-schema.json +5 -0
@@ -4134,3 +4134,25 @@
 ##
 { 'enum': 'ReplayMode',
   'data': [ 'none', 'record', 'play' ] }
+
+##
+# @GICCapability:
+#
+# This struct describes capability for a specific GIC version. These

Might be nice to spell out what the acronym GIC means, but that's cosmetic.

Quoted 8 lines
qapi-schema.json +7 -0
+# bits are not only decided by QEMU/KVM software version, but also
+# decided by the hardware that the program is running upon.
+#
+# @version:  version of GIC to be described.
+#
+# @emulated: whether current QEMU/hardware supports emulated GIC
+#            device in user space.

qapi-schema.json line 4158

Quoted 10 lines
qapi-schema.json +10 -0
+#
+# @kernel:   whether current QEMU/hardware supports hardware
+#            accelerated GIC device in kernel.
+#
+# Since: 2.6
+##
+{ 'struct': 'GICCapability',
+  'data': { 'version': 'int',
+            'emulated': 'bool',
+            'kernel': 'bool' } }

I might have squashed this with the patch that first uses GICCapability, as defining a type in isolation doesn't do much.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#12 lore raw

Re: [Qemu-arm] [PATCH v5 1/5] arm: qmp: add GICCapability struct

Quoted 7 lines · Eric Blake

qapi-schema.json line 4141

Quoted 4 lines · Peter Xu
qapi-schema.json +4 -0
+##
+# @GICCapability:
+#
+# This struct describes capability for a specific GIC version. These

Might be nice to spell out what the acronym GIC means, but that's cosmetic.

Ah! I thought I have added that... It's missing again. Will do in next spin.

Quoted 14 lines
Quoted 14 lines
qapi-schema.json +13 -0
+# bits are not only decided by QEMU/KVM software version, but also
+# decided by the hardware that the program is running upon.
+#
+# @version:  version of GIC to be described.
+#
+# @emulated: whether current QEMU/hardware supports emulated GIC
+#            device in user space.
+#
+# @kernel:   whether current QEMU/hardware supports hardware
+#            accelerated GIC device in kernel.
+#
+# Since: 2.6
+##
Quoted 8 lines

qapi-schema.json line 4158

Quoted 5 lines
qapi-schema.json +4 -0
+{ 'struct': 'GICCapability',
+  'data': { 'version': 'int',
+            'emulated': 'bool',
+            'kernel': 'bool' } }

I might have squashed this with the patch that first uses GICCapability, as defining a type in isolation doesn't do much.

I can do the squash in next spin if you prefer that one. Actually I got this question before, about when I should split and when to squash. E.g., shall I make sure that I should have no "definition only" patches in the future?

-- peterx

#13 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 1/5] arm: qmp: add GICCapability struct

Quoted 35 lines · Peter Xu
Quoted 7 lines · Eric Blake

qapi-schema.json line 4141

Quoted 4 lines · Peter Xu
qapi-schema.json +4 -0
+##
+# @GICCapability:
+#
+# This struct describes capability for a specific GIC version. These

Might be nice to spell out what the acronym GIC means, but that's cosmetic.

Ah! I thought I have added that... It's missing again. Will do in next spin.

Quoted 14 lines
Quoted 14 lines
qapi-schema.json +13 -0
+# bits are not only decided by QEMU/KVM software version, but also
+# decided by the hardware that the program is running upon.
+#
+# @version:  version of GIC to be described.
+#
+# @emulated: whether current QEMU/hardware supports emulated GIC
+#            device in user space.
+#
+# @kernel:   whether current QEMU/hardware supports hardware
+#            accelerated GIC device in kernel.
+#
+# Since: 2.6
+##
Quoted 8 lines

qapi-schema.json line 4158

Quoted 5 lines
qapi-schema.json +4 -0
+{ 'struct': 'GICCapability',
+  'data': { 'version': 'int',
+            'emulated': 'bool',
+            'kernel': 'bool' } }

I might have squashed this with the patch that first uses GICCapability, as defining a type in isolation doesn't do much.

Quoted 4 lines

I can do the squash in next spin if you prefer that one. Actually I got this question before, about when I should split and when to squash. E.g., shall I make sure that I should have no "definition only" patches in the future?

Depends.

The general rule is to keep separate things separate, and patches self-contained. The narrow sense of self-contained is each patch compiles and works. The wider sense is each patch makes sense to its readers on its own. You can't always have a perfect score on the latter, but you should try.

Adding a definition without a user is generally not advised, because you generally need to see the user to make sense of it.

For a complex feature, adding its abstract interface before its concrete implementation may help liberate interface review from implementation details.

Note that your interface consists of type GICCapability and command query-gic-capabilities. You could add just the interface with a stub implementation first, then flesh out the implementation. But I doubt the thing is complex enough to justify that.

author
#14 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 1/5] arm: qmp: add GICCapability struct

Quoted 11 lines · Markus Armbruster

Depends.

The general rule is to keep separate things separate, and patches self-contained. The narrow sense of self-contained is each patch compiles and works. The wider sense is each patch makes sense to its readers on its own. You can't always have a perfect score on the latter, but you should try.

Adding a definition without a user is generally not advised, because you generally need to see the user to make sense of it.

Quoted 8 lines

For a complex feature, adding its abstract interface before its concrete implementation may help liberate interface review from implementation details.

Note that your interface consists of type GICCapability and command query-gic-capabilities. You could add just the interface with a stub implementation first, then flesh out the implementation. But I doubt the thing is complex enough to justify that.

Thanks for the thorough explaination on this.

It's indeed not easy to figure out the best way every time for me... Now I do feel it strange to split the first patch alone from the 2nd one. Anyway, it's squashed into the 2nd patch in v6.

-- peterx

author
#15 lore raw

PATCH v5 2/5 arm: qmp: add query-gic-capabilities interface

In reply to Peter Xu

This patch adds the command "query-gic-capabilities" but not implemnet it. The command is ARM-only. Return of the command is a list of GICCapability struct that describes all GIC versions that current QEMU and system support.

---
 monitor.c                |  8 ++++++++
 qapi-schema.json         | 11 +++++++++++
 qmp-commands.hx          | 26 ++++++++++++++++++++++++++
 scripts/qapi.py          |  1 +
 target-arm/Makefile.objs |  2 +-
 target-arm/monitor.c     | 31 +++++++++++++++++++++++++++++++
 6 files changed, 78 insertions(+), 1 deletion(-)
 create mode 100644 target-arm/monitor.c
monitor.c +8 -0
index 894f862..d463dc4 100644
@@ -4257,3 +4257,11 @@ void qmp_dump_skeys(const char *filename, Error **errp)
     error_setg(errp, QERR_FEATURE_DISABLED, "dump-skeys");
 }
 #endif
+
+#ifndef TARGET_ARM
+GICCapabilityList *qmp_query_gic_capabilities(Error **errp)
+{
+    error_setg(errp, QERR_FEATURE_DISABLED, "query-gic-capabilities");
+    return NULL;
+}
+#endif
qapi-schema.json +11 -0
index da9671a..b2ef149 100644
@@ -4156,3 +4156,14 @@
   'data': { 'version': 'int',
             'emulated': 'bool',
             'kernel': 'bool' } }
+
+##
+# @query-gic-capabilities:
+#
+# Return a list of supported GIC version capabilities.
+#
+# Returns: a list of GICCapability.
+#
+# Since: 2.6
+##
+{ 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] }
qmp-commands.hx +26 -0
index 9e05365..a124ea8 100644
@@ -4853,3 +4853,29 @@ Example:
                  {"type": 0, "out-pport": 0, "pport": 0, "vlan-id": 3840,
                   "pop-vlan": 1, "id": 251658240}
    ]}
+
+EQMP
+
+#if defined TARGET_ARM
+    {
+        .name       = "query-gic-capabilities",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_query_gic_capabilities,
+    },
+#endif
+
+SQMP
+query-gic-capabilities
+---------------
+
+Return a list of supported ARM GIC versions and their capabilities.
+
+Arguments: None
+
+Example:
+
+-> { "execute": "query-gic-capabilities" }
+<- { "return": [{ "version": 2, "emulated": true, "kernel": false },
+                { "version": 3, "emulated": false, "kernel": true } ] }
+
+EQMP
scripts/qapi.py +1 -0
index 6b2aa6e..716474e 100644
@@ -46,6 +46,7 @@ returns_whitelist = [
     'query-tpm-models',
     'query-tpm-types',
     'ringbuf-read',
+    'query-gic-capability',
 
     # From QGA:
     'guest-file-open',
target-arm/Makefile.objs +1 -1
index a80eb39..334074c 100644
@@ -8,4 +8,4 @@ obj-y += translate.o op_helper.o helper.o cpu.o
 obj-y += neon_helper.o iwmmxt_helper.o
 obj-y += gdbstub.o
 obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o
-obj-y += crypto_helper.o
+obj-y += crypto_helper.o monitor.o
target-arm/monitor.c new file +31 -0
new file mode 100644
index 0000000..5678eb8
@@ -0,0 +1,31 @@
+/*
+ * QEMU monitor.c for ARM.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "qemu/osdep.h"
+#include "hw/boards.h"
+#include "qemu/error-report.h"
+#include "sysemu/kvm.h"
+#include "qmp-commands.h"
+
+GICCapabilityList *qmp_query_gic_capabilities(Error **errp)
+{
+    return NULL;
+}
Signature · 1 line
2.4.3
#16 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 2/5] arm: qmp: add query-gic-capabilities interface

Copying Eric in case further review is needed in my absence.

scripts/qapi.py returns_whitelist = [

Quoted 90 lines · Peter Xu

This patch adds the command "query-gic-capabilities" but not implemnet it. The command is ARM-only. Return of the command is a list of GICCapability struct that describes all GIC versions that current QEMU and system support.

---
 monitor.c                |  8 ++++++++
 qapi-schema.json         | 11 +++++++++++
 qmp-commands.hx          | 26 ++++++++++++++++++++++++++
 scripts/qapi.py          |  1 +
 target-arm/Makefile.objs |  2 +-
 target-arm/monitor.c     | 31 +++++++++++++++++++++++++++++++
 6 files changed, 78 insertions(+), 1 deletion(-)
 create mode 100644 target-arm/monitor.c
monitor.c +8 -0
index 894f862..d463dc4 100644
@@ -4257,3 +4257,11 @@ void qmp_dump_skeys(const char *filename, Error **errp)
     error_setg(errp, QERR_FEATURE_DISABLED, "dump-skeys");
 }
 #endif
+
+#ifndef TARGET_ARM
+GICCapabilityList *qmp_query_gic_capabilities(Error **errp)
+{
+    error_setg(errp, QERR_FEATURE_DISABLED, "query-gic-capabilities");
+    return NULL;
+}
+#endif
qapi-schema.json +11 -0
index da9671a..b2ef149 100644
@@ -4156,3 +4156,14 @@
   'data': { 'version': 'int',
             'emulated': 'bool',
             'kernel': 'bool' } }
+
+##
+# @query-gic-capabilities:
+#
+# Return a list of supported GIC version capabilities.
+#
+# Returns: a list of GICCapability.
+#
+# Since: 2.6
+##
+{ 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] }
qmp-commands.hx +26 -0
index 9e05365..a124ea8 100644
@@ -4853,3 +4853,29 @@ Example:
                  {"type": 0, "out-pport": 0, "pport": 0, "vlan-id": 3840,
                   "pop-vlan": 1, "id": 251658240}
    ]}
+
+EQMP
+
+#if defined TARGET_ARM
+    {
+        .name       = "query-gic-capabilities",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_query_gic_capabilities,
+    },
+#endif
+
+SQMP
+query-gic-capabilities
+---------------
+
+Return a list of supported ARM GIC versions and their capabilities.
+
+Arguments: None
+
+Example:
+
+-> { "execute": "query-gic-capabilities" }
+<- { "return": [{ "version": 2, "emulated": true, "kernel": false },
+                { "version": 3, "emulated": false, "kernel": true } ] }
+
+EQMP
scripts/qapi.py +0 -0
index 6b2aa6e..716474e 100644
@@ -46,6 +46,7 @@ returns_whitelist = [

# Whitelist of commands allowed to return a non-dictionary returns_whitelist = [

       'human-monitor-command',
       'qom-get',
       'query-migrate-cache-size',

scripts/qapi.py returns_whitelist = [ · line 52

Quoted 7 lines
scripts/qapi.py +1 -0
     'query-tpm-models',
     'query-tpm-types',
     'ringbuf-read',
+    'query-gic-capability',
 
     # From QGA:
     'guest-file-open',

The whitelist exists to except existing commands from design rules on return types. New commands don't get to violate the rules without a really, really compelling reason.

Do you actually need this?

If yes, why should your command be permitted to violate the design rules?

Quoted 32 lines
target-arm/Makefile.objs +1 -1
index a80eb39..334074c 100644
@@ -8,4 +8,4 @@ obj-y += translate.o op_helper.o helper.o cpu.o
 obj-y += neon_helper.o iwmmxt_helper.o
 obj-y += gdbstub.o
 obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o
-obj-y += crypto_helper.o
+obj-y += crypto_helper.o monitor.o
target-arm/monitor.c new file +16 -0
new file mode 100644
index 0000000..5678eb8
@@ -0,0 +1,31 @@
+/*
+ * QEMU monitor.c for ARM.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

target-arm/monitor.c line 26

Quoted 10 lines
target-arm/monitor.c new file +10 -0
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "qemu/osdep.h"
+#include "hw/boards.h"
+#include "qemu/error-report.h"
+#include "sysemu/kvm.h"
+#include "qmp-commands.h"

I very much doubt you need all these includes. Try dropping all but the first and the last one.

Quoted 5 lines
target-arm/monitor.c new file +5 -0
+
+GICCapabilityList *qmp_query_gic_capabilities(Error **errp)
+{
+    return NULL;
+}
author
#17 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 2/5] arm: qmp: add query-gic-capabilities interface

Quoted 19 lines · Markus Armbruster

scripts/qapi.py returns_whitelist = [

Quoted 5 lines · Peter Xu
scripts/qapi.py +0 -0
index 6b2aa6e..716474e 100644
@@ -46,6 +46,7 @@ returns_whitelist = [

# Whitelist of commands allowed to return a non-dictionary returns_whitelist = [

       'human-monitor-command',
       'qom-get',
       'query-migrate-cache-size',

scripts/qapi.py returns_whitelist = [ · line 52

Quoted 7 lines
scripts/qapi.py +1 -0
     'query-tpm-models',
     'query-tpm-types',
     'ringbuf-read',
+    'query-gic-capability',
 
     # From QGA:
     'guest-file-open',
Quoted 8 lines

The whitelist exists to except existing commands from design rules on return types. New commands don't get to violate the rules without a really, really compelling reason.

Do you actually need this?

If yes, why should your command be permitted to violate the design rules?

This might not be required. Agree with you and Eric. Will use a hash instead with single key.

Quoted 8 lines

scripts/qapi.py

Quoted 5 lines
scripts/qapi.py +5 -0
+#include "qemu/osdep.h"
+#include "hw/boards.h"
+#include "qemu/error-report.h"
+#include "sysemu/kvm.h"
+#include "qmp-commands.h"

I very much doubt you need all these includes. Try dropping all but the first and the last one.

I just copied them from machine.c and dropped lots, seems still redundant... Will keep it a minimum subset in next version. Thanks!

-- peterx

#18 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 2/5] arm: qmp: add query-gic-capabilities interface

Quoted 17 lines · Peter Xu
Quoted 16 lines · Markus Armbruster

scripts/qapi.py returns_whitelist = [

Quoted 5 lines · Peter Xu
scripts/qapi.py +0 -0
index 6b2aa6e..716474e 100644
@@ -46,6 +46,7 @@ returns_whitelist = [

# Whitelist of commands allowed to return a non-dictionary returns_whitelist = [

       'human-monitor-command',
       'qom-get',
       'query-migrate-cache-size',
Quoted 5 lines
scripts/qapi.py +1 -0
     'query-tpm-models',
     'query-tpm-types',
     'ringbuf-read',
+    'query-gic-capability',
 
Quoted 8 lines
Quoted 8 lines

scripts/qapi.py returns_whitelist = [ · line 52

Quoted 2 lines
scripts/qapi.py +0 -0
     # From QGA:
     'guest-file-open',

The whitelist exists to except existing commands from design rules on return types. New commands don't get to violate the rules without a really, really compelling reason.

Do you actually need this?

I've since tested it and double-checked the code: you don't need this.

Quoted 5 lines
Quoted 2 lines

If yes, why should your command be permitted to violate the design rules?

This might not be required. Agree with you and Eric. Will use a hash instead with single key.

The rule against returning non-dictionaries exists to avoid interfaces that cannot evolve. With a dictionary, you can evolve by adding members.

The rule does *not* forbid returning lists of dictionaries. When a command fundamentally returns a list of things, being able to evolve the things suffices.

query-gic-capabilities looks like it fundamentally returns a list of capabilities. Returning ['GICCapability'] is just fine then.

Only if query-gic-capabilities doesn't have this list nature should you complicate its return value by wrapping it in another object type.

In either case, drop the change to returns_whitelist.

[...]

author
#19 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 2/5] arm: qmp: add query-gic-capabilities interface

Quoted 7 lines · Markus Armbruster

The rule against returning non-dictionaries exists to avoid interfaces that cannot evolve. With a dictionary, you can evolve by adding members.

The rule does *not* forbid returning lists of dictionaries. When a command fundamentally returns a list of things, being able to evolve the things suffices.

Ok.

Quoted 3 lines

query-gic-capabilities looks like it fundamentally returns a list of capabilities. Returning ['GICCapability'] is just fine then.

I have posted v6 just as Eric has suggested. At least one advantage is that it is easier to be extended (if needed) in the future, also to follow the more-generic format to use dicts rather than arrays. If you would not mind, I'll keep the dict interface there.

[...]

Quoted 1 line

In either case, drop the change to returns_whitelist.

Yep. Dropped in v6.

Thanks.

-- peterx

#20 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 2/5] arm: qmp: add query-gic-capabilities interface

Quoted 12 lines · Peter Xu
Quoted 7 lines · Markus Armbruster

The rule against returning non-dictionaries exists to avoid interfaces that cannot evolve. With a dictionary, you can evolve by adding members.

The rule does *not* forbid returning lists of dictionaries. When a command fundamentally returns a list of things, being able to evolve the things suffices.

Ok.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

query-gic-capabilities looks like it fundamentally returns a list of capabilities. Returning ['GICCapability'] is just fine then.

I have posted v6 just as Eric has suggested. At least one advantage is that it is easier to be extended (if needed) in the future, also to follow the more-generic format to use dicts rather than arrays. If you would not mind, I'll keep the dict interface there.

Returning such a list of a structured type is a well-established convention by now --- qmp-introspect.c shows 28 commands doing it, most of them named query-FOO. I'd rather not start a different convention now, just because we got temporarily confused about our own rules. So, unless there's something about query-gic-capabilities that makes it more likely to need extension outside its list element type, let's stick to returning the list.

Eric?

Quoted 10 lines

[...]

Quoted 1 line

In either case, drop the change to returns_whitelist.

Yep. Dropped in v6.

Thanks.

-- peterx

#21 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 2/5] arm: qmp: add query-gic-capabilities interface

Quoted 16 lines · Markus Armbruster
Quoted 7 lines
Quoted 2 lines

query-gic-capabilities looks like it fundamentally returns a list of capabilities. Returning ['GICCapability'] is just fine then.

I have posted v6 just as Eric has suggested. At least one advantage is that it is easier to be extended (if needed) in the future, also to follow the more-generic format to use dicts rather than arrays. If you would not mind, I'll keep the dict interface there.

Returning such a list of a structured type is a well-established convention by now --- qmp-introspect.c shows 28 commands doing it, most of them named query-FOO. I'd rather not start a different convention now, just because we got temporarily confused about our own rules. So, unless there's something about query-gic-capabilities that makes it more likely to need extension outside its list element type, let's stick to returning the list.

Quoted 1 line

Eric?

Makes sense to me, and perhaps my own fault for getting confused by not even trying to delete just the whitelist line and seeing what would happen. Having a consistent style of query-* returning an array type is reasonable to continue.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#22 lore raw

Re: [Qemu-arm] [PATCH v5 2/5] arm: qmp: add query-gic-capabilities interface

In reply to Peter Xu
Quoted 1 line · Peter Xu

This patch adds the command "query-gic-capabilities" but not implemnet

s/not implemnet/does not implement/

Quoted 13 lines

it. The command is ARM-only. Return of the command is a list of GICCapability struct that describes all GIC versions that current QEMU and system support.

---

+++ b/qapi-schema.json

qapi-schema.json +1 -0
@@ -4156,3 +4156,14 @@
   'data': { 'version': 'int',
             'emulated': 'bool',
             'kernel': 'bool' } }
+

qapi-schema.json line 4169

Quoted 10 lines
qapi-schema.json +10 -0
+##
+# @query-gic-capabilities:
+#
+# Return a list of supported GIC version capabilities.
+#
+# Returns: a list of GICCapability.
+#
+# Since: 2.6
+##
+{ 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] }

On the surface, this seems okay. As mentioned before, I would have squashed 1 and 2 into a single patch. The GICCapability type is extensible, and introspection is sufficient at seeing what the type is currently capable of exposing.

On the other hand...

scripts/qapi.py returns_whitelist = [ · line 49

Quoted 6 lines

+++ b/scripts/qapi.py

scripts/qapi.py +1 -0
@@ -46,6 +46,7 @@ returns_whitelist = [
     'query-tpm-models',
     'query-tpm-types',
     'ringbuf-read',
+    'query-gic-capability',

...it required a whitelist, because you are violating the usual convention of returning a dict. If you DO need the whitelist, your addition should have been kept sorted. But you don't need it, if you would modify your QAPI to return a dict:

{ 'struct': 'GICCapabilitiesReturn',
'data': { 'capabilities': ['GICCapability'] } }
{ 'command': 'query-gic-capabilities',
'returns': 'GICCapabilitiesReturn' }

Yes, the dict has only a single key, and that key points to the same list; but now you have future extensibility: in the future, we could return any future global data as a sibling to the array, without having to modify every element of the array to repeat redundant information.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#23 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 2/5] arm: qmp: add query-gic-capabilities interface

Quoted 53 lines · Eric Blake
Quoted 1 line · Peter Xu

This patch adds the command "query-gic-capabilities" but not implemnet

s/not implemnet/does not implement/

Quoted 13 lines

it. The command is ARM-only. Return of the command is a list of GICCapability struct that describes all GIC versions that current QEMU and system support.

---

+++ b/qapi-schema.json

qapi-schema.json +1 -0
@@ -4156,3 +4156,14 @@
   'data': { 'version': 'int',
             'emulated': 'bool',
             'kernel': 'bool' } }
+

qapi-schema.json line 4169

Quoted 10 lines
qapi-schema.json +10 -0
+##
+# @query-gic-capabilities:
+#
+# Return a list of supported GIC version capabilities.
+#
+# Returns: a list of GICCapability.
+#
+# Since: 2.6
+##
+{ 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] }

On the surface, this seems okay. As mentioned before, I would have squashed 1 and 2 into a single patch. The GICCapability type is extensible, and introspection is sufficient at seeing what the type is currently capable of exposing.

On the other hand...

scripts/qapi.py returns_whitelist = [ · line 49

Quoted 6 lines

+++ b/scripts/qapi.py

scripts/qapi.py +1 -0
@@ -46,6 +46,7 @@ returns_whitelist = [
     'query-tpm-models',
     'query-tpm-types',
     'ringbuf-read',
+    'query-gic-capability',

...it required a whitelist, because you are violating the usual convention of returning a dict. If you DO need the whitelist, your addition should have been kept sorted. But you don't need it, if you would modify your QAPI to return a dict:

{ 'struct': 'GICCapabilitiesReturn',
'data': { 'capabilities': ['GICCapability'] } }
{ 'command': 'query-gic-capabilities',
'returns': 'GICCapabilitiesReturn' }

Quoted 4 lines

Yes, the dict has only a single key, and that key points to the same list; but now you have future extensibility: in the future, we could return any future global data as a sibling to the array, without having to modify every element of the array to repeat redundant information.

I just tested it, the whitelist entry is superfluous, check_command() accepts a list of dicts just fine.

author
#24 lore raw

Re: [Qemu-arm] [PATCH v5 2/5] arm: qmp: add query-gic-capabilities interface

In reply to Eric Blake
Quoted 4 lines · Eric Blake
Quoted 1 line · Peter Xu

This patch adds the command "query-gic-capabilities" but not implemnet

s/not implemnet/does not implement/

Yep, again. Thanks.

Quoted 49 lines
Quoted 14 lines

it. The command is ARM-only. Return of the command is a list of GICCapability struct that describes all GIC versions that current QEMU and system support.

---

+++ b/qapi-schema.json

qapi-schema.json +1 -0
@@ -4156,3 +4156,14 @@
   'data': { 'version': 'int',
             'emulated': 'bool',
             'kernel': 'bool' } }
+

qapi-schema.json line 4169

Quoted 10 lines
qapi-schema.json +10 -0
+##
+# @query-gic-capabilities:
+#
+# Return a list of supported GIC version capabilities.
+#
+# Returns: a list of GICCapability.
+#
+# Since: 2.6
+##
+{ 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] }

On the surface, this seems okay. As mentioned before, I would have squashed 1 and 2 into a single patch. The GICCapability type is extensible, and introspection is sufficient at seeing what the type is currently capable of exposing.

On the other hand...

scripts/qapi.py returns_whitelist = [ · line 49

Quoted 6 lines

+++ b/scripts/qapi.py

scripts/qapi.py +1 -0
@@ -46,6 +46,7 @@ returns_whitelist = [
     'query-tpm-models',
     'query-tpm-types',
     'ringbuf-read',
+    'query-gic-capability',

...it required a whitelist, because you are violating the usual convention of returning a dict. If you DO need the whitelist, your addition should have been kept sorted. But you don't need it, if you would modify your QAPI to return a dict:

{ 'struct': 'GICCapabilitiesReturn',
'data': { 'capabilities': ['GICCapability'] } }
{ 'command': 'query-gic-capabilities',
'returns': 'GICCapabilitiesReturn' }

Quoted 4 lines

Yes, the dict has only a single key, and that key points to the same list; but now you have future extensibility: in the future, we could return any future global data as a sibling to the array, without having to modify every element of the array to repeat redundant information.

Yes, I think this is better solution. Will adopt this in next version.

Thanks for the comments!

-- peterx

#25 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v5 2/5] arm: qmp: add query-gic-capabilities interface

Quoted 48 lines · Peter Xu
Quoted 4 lines · Eric Blake
Quoted 1 line · Peter Xu

This patch adds the command "query-gic-capabilities" but not implemnet

s/not implemnet/does not implement/

Yep, again. Thanks.

Quoted 40 lines
Quoted 14 lines

it. The command is ARM-only. Return of the command is a list of GICCapability struct that describes all GIC versions that current QEMU and system support.

---

+++ b/qapi-schema.json

qapi-schema.json +1 -0
@@ -4156,3 +4156,14 @@
   'data': { 'version': 'int',
             'emulated': 'bool',
             'kernel': 'bool' } }
+

qapi-schema.json line 4169

Quoted 10 lines
qapi-schema.json +10 -0
+##
+# @query-gic-capabilities:
+#
+# Return a list of supported GIC version capabilities.
+#
+# Returns: a list of GICCapability.
+#
+# Since: 2.6
+##
+{ 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] }

On the surface, this seems okay. As mentioned before, I would have squashed 1 and 2 into a single patch. The GICCapability type is extensible, and introspection is sufficient at seeing what the type is currently capable of exposing.

On the other hand...

scripts/qapi.py returns_whitelist = [ · line 49

Quoted 6 lines

+++ b/scripts/qapi.py

scripts/qapi.py +1 -0
@@ -46,6 +46,7 @@ returns_whitelist = [
     'query-tpm-models',
     'query-tpm-types',
     'ringbuf-read',
+    'query-gic-capability',

...it required a whitelist, because you are violating the usual

It doesn't :)

Quoted 9 lines
Quoted 9 lines

convention of returning a dict. If you DO need the whitelist, your addition should have been kept sorted. But you don't need it, if you would modify your QAPI to return a dict:

{ 'struct': 'GICCapabilitiesReturn',
'data': { 'capabilities': ['GICCapability'] } }
{ 'command': 'query-gic-capabilities',
'returns': 'GICCapabilitiesReturn' }

Quoted 6 lines
Quoted 4 lines

Yes, the dict has only a single key, and that key points to the same list; but now you have future extensibility: in the future, we could return any future global data as a sibling to the array, without having to modify every element of the array to repeat redundant information.

Yes, I think this is better solution. Will adopt this in next version.

As explained in my other message, do this only if query-gic-capabilities truly needs it. There's plenty of precedence for returning a list of a structured type.

Quoted 3 lines

Thanks for the comments!

-- peterx

author
#26 lore raw

PATCH v5 3/5 arm: enhance kvm_arm_create_scratch_host_vcpu

In reply to Peter Xu

Some more lines to make sure we allow NULL for 1st/3rd parameter.

---
 target-arm/kvm.c     | 10 +++++++++-
 target-arm/kvm_arm.h |  6 ++++--
 2 files changed, 13 insertions(+), 3 deletions(-)
target-arm/kvm.c +9 -1
index 969ab0b..0a7f9a6 100644
@@ -62,13 +62,17 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
         goto err;
     }
 
+    if (!init) {
+        goto finish;
+    }
+
     ret = ioctl(vmfd, KVM_ARM_PREFERRED_TARGET, init);
     if (ret >= 0) {
         ret = ioctl(cpufd, KVM_ARM_VCPU_INIT, init);
         if (ret < 0) {
             goto err;
         }
-    } else {
+    } else if (cpus_to_try) {
         /* Old kernel which doesn't know about the
          * PREFERRED_TARGET ioctl: we know it will only support
          * creating one kind of guest CPU which is its preferred
@@ -85,8 +89,12 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
         if (ret < 0) {
             goto err;
         }
+    } else {
+        /* Not providing cpus_to_try, do nothing. */
+        ;
     }
 
+finish:
     fdarray[0] = kvmfd;
     fdarray[1] = vmfd;
     fdarray[2] = cpufd;
target-arm/kvm_arm.h +4 -2
index 07f0c72..6bcfe6c 100644
@@ -124,9 +124,11 @@ void kvm_arm_reset_vcpu(ARMCPU *cpu);
  * kvm_arm_create_scratch_host_vcpu:
  * @cpus_to_try: array of QEMU_KVM_ARM_TARGET_* values (terminated with
  * QEMU_KVM_ARM_TARGET_NONE) to try as fallback if the kernel does not
- * know the PREFERRED_TARGET ioctl
+ * know the PREFERRED_TARGET ioctl. If NULL is provided, will try
+ * nothing.
  * @fdarray: filled in with kvmfd, vmfd, cpufd file descriptors in that order
- * @init: filled in with the necessary values for creating a host vcpu
+ * @init: filled in with the necessary values for creating a host
+ * vcpu. If NULL is provided, will not init the vCPU.
  *
  * Create a scratch vcpu in its own VM of the type preferred by the host
  * kernel (as would be used for '-cpu host'), for purposes of probing it
Signature · 1 line
2.4.3
author
#27 lore raw

PATCH v5 4/5 kvm: add kvm_support_device() helper function

In reply to Peter Xu

This can be used when probing whether KVM support specific device. Here, a raw vmfd is used.

---
 include/sysemu/kvm.h |  9 +++++++++
 kvm-all.c            | 15 +++++++++++++++
 2 files changed, 24 insertions(+)
include/sysemu/kvm.h +9 -0
index 6695fa7..8738fa1 100644
@@ -306,6 +306,15 @@ void kvm_device_access(int fd, int group, uint64_t attr,
  */
 int kvm_create_device(KVMState *s, uint64_t type, bool test);
 
+/**
+ * kvm_support_device - probe whether KVM support specific device
+ *
+ * @vmfd: The fd handler for VM
+ * @type: type of device
+ *
+ * @return: true if supported, otherwise false.
+ */
+bool kvm_support_device(int vmfd, uint64_t type);
 
 /* Arch specific hooks */
 
kvm-all.c +15 -0
index 44c0464..77deccc 100644
@@ -2339,6 +2339,21 @@ int kvm_create_device(KVMState *s, uint64_t type, bool test)
     return test ? 0 : create_dev.fd;
 }
 
+bool kvm_support_device(int vmfd, uint64_t type)
+{
+    struct kvm_create_device create_dev = {
+        .type = type,
+        .fd = -1,
+        .flags = KVM_CREATE_DEVICE_TEST,
+    };
+
+    if (ioctl(vmfd, KVM_CHECK_EXTENSION, KVM_CAP_DEVICE_CTRL) <= 0) {
+        return false;
+    }
+
+    return (ioctl(vmfd, KVM_CREATE_DEVICE, &create_dev) >= 0);
+}
+
 int kvm_set_one_reg(CPUState *cs, uint64_t id, void *source)
 {
     struct kvm_one_reg reg;
Signature · 1 line
2.4.3
author
#28 lore raw

PATCH v5 5/5 arm: implement query-gic-capabilities

In reply to Peter Xu

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 by creating a scratch VM.

---
 target-arm/monitor.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)
target-arm/monitor.c +56 -1
index 5678eb8..5493ea6 100644
@@ -24,8 +24,63 @@
 #include "qemu/error-report.h"
 #include "sysemu/kvm.h"
 #include "qmp-commands.h"
+#include "kvm_arm.h"
+#include <sys/ioctl.h>
+
+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;
+}
 
 GICCapabilityList *qmp_query_gic_capabilities(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
+    {
+        int fdarray[3];
+
+        if (!kvm_arm_create_scratch_host_vcpu(NULL, fdarray, NULL)) {
+            goto out;
+        }
+
+        /* Test KVM GICv2 */
+        if (kvm_support_device(fdarray[1], KVM_DEV_TYPE_ARM_VGIC_V2)) {
+            v2->kernel = true;
+        }
+
+        /* Test KVM GICv3 */
+        if (kvm_support_device(fdarray[1], KVM_DEV_TYPE_ARM_VGIC_V3)) {
+            v3->kernel = true;
+        }
+
+        kvm_arm_destroy_scratch_host_vcpu(fdarray);
+out:
+        ;
+    }
+#endif
+
+    head = gic_cap_list_add(head, v2);
+    head = gic_cap_list_add(head, v3);
+
+    return head;
 }
Signature · 1 line
2.4.3
#29 lore raw
In reply to Peter Xu
Quoted 8 lines · Peter Xu

v5 changes:
- patch 2: moved to target-arm/monitor.c (from target-arm/machine.c) [Peter]
- patch 3: splitted into three patches: [all from Peter's comments]
  - patch 3 (new): leverage kvm_arm_create_scratch_host_vcpu(), tiny enhancement of old one to suite our need
  - patch 4: introduce kvm_support_device() in kvm-all.c
  - patch 5: do the implementation.

Tested on two separate aarch64 hosts, seems to work fine.

Cheers.

Signature · 2 lines
Andrea Bolognani
Software Engineer - Virtualization Team
author
#30 lore raw
Quoted 11 lines · Andrea Bolognani
Quoted 8 lines · Peter Xu

v5 changes:
- patch 2: moved to target-arm/monitor.c (from target-arm/machine.c) [Peter]
- patch 3: splitted into three patches: [all from Peter's comments]
  - patch 3 (new): leverage kvm_arm_create_scratch_host_vcpu(), tiny enhancement of old one to suite our need
  - patch 4: introduce kvm_support_device() in kvm-all.c
  - patch 5: do the implementation.

Tested on two separate aarch64 hosts, seems to work fine.

Thanks Andrea!

Sorry I forgot to CC libvir-list. To avoid duplication, not re-sending but CCing in this reply. If anyone interested, please review in the following link:

https://lists.gnu.org/archive/html/qemu-devel/2016-03/msg04465.html

(which points to exactly current thread.)

Sorry for the inconvenience!

-- peterx

#31 lore raw
In reply to Peter Xu
Quoted 32 lines · Peter Xu

v5 changes:
- patch 2: moved to target-arm/monitor.c (from target-arm/machine.c)

           [Peter]

- patch 3: splitted into three patches: [all from Peter's comments]
- patch 3 (new): leverage kvm_arm_create_scratch_host_vcpu(), tiny enhancement of old one to suite our need
- patch 4: introduce kvm_support_device() in kvm-all.c
- patch 5: do the implementation.

v4 changes:
- all: rename query-gic-capability to query-gic-capabilities [Andrea]
- patch 3: rename helper function to kvm_support_device, make it inline and lighter. [Drew]

v3 changes:
- patch 2: remove func declaration, add qmp header [Drew]
- patch 3: being able to detect KVM GIC capabilities even without kvm enabled [Andrea]: this is a little bit hacky, need some more review on this.

v2 changes:
- result layout change: use array and dict for the capability bits rather than a single array of strings [Andrea/Markus]
- spelling out what GIC is in doc [Eric]

This patch is to add ARM-specific command "query-gic-capability".

The new command can report which kind of GIC device the host/QEMU support. The returned result is in the form of array.

Sample command and output:

Quoted 7 lines

{"execute": "query-gic-capability"}
{"return": [{"emulated": false, "version": 3, "kernel": false},

            {"emulated": true, "version": 2, "kernel": true}]}

Testing:

Smoke tests on both x86 (emulated) and another moonshot ARM server.

We discussed the need for a yet another ad hoc query command. Can you please summarize the discussion and its conclusion? Explaining *why* a feature is needed is always a good idea. Cover letter and commit messages are good places for it.

author
#32 lore raw
Quoted 4 lines · Markus Armbruster

We discussed the need for a yet another ad hoc query command. Can you please summarize the discussion and its conclusion? Explaining *why* a feature is needed is always a good idea. Cover letter and commit messages are good places for it.

Sure. I will mention that in commit message of patch 1 in the next spin. Thanks.

-- peterx

#33 lore raw
In reply to Peter Xu
Quoted 10 lines · Peter Xu

This patch is to add ARM-specific command "query-gic-capability".

The new command can report which kind of GIC device the host/QEMU support. The returned result is in the form of array.

Sample command and output:

{"execute": "query-gic-capability"}
{"return": [{"emulated": false, "version": 3, "kernel": false},

            {"emulated": true, "version": 2, "kernel": true}]}

Reminder: I still need confirmation from the libvirt folks that this API meets their needs, and review from somebody on the QEMU QMP protocol design side. This should go into 2.6 but we are getting closer to hardfreeze...

thanks
-- PMM

author
#34 lore raw
Quoted 8 lines · Peter Maydell
Quoted 7 lines · Peter Xu

This patch is to add ARM-specific command "query-gic-capability".

The new command can report which kind of GIC device the host/QEMU support. The returned result is in the form of array.

Sample command and output:

Quoted 8 lines
Quoted 3 lines

{"execute": "query-gic-capability"}
{"return": [{"emulated": false, "version": 3, "kernel": false},

            {"emulated": true, "version": 2, "kernel": true}]}

Reminder: I still need confirmation from the libvirt folks that this API meets their needs, and review from somebody on the QEMU QMP protocol design side. This should go into 2.6 but we are getting closer to hardfreeze...

Hi, Peter,

Regarding to QMP part, I have got review comments from Eric/Markus, and will do more spins if necessary (latest v6). For libvirt part, Andrea should be the one to finish the libvirt part of this feature, so I am considering him to be the libvirt guy. Do you think we need more review besides CCed, especially on libvirt part?

Thanks.

-- peterx