Skip to contentSkip to conversation

kvm: add set_one_reg/get_one_reg

PATCH Superseded Alexey Kardashevskiy 3 participants 7 messages Sep 18, 2013

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: add set_one_reg/get_one_reg

This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.

---
 include/sysemu/kvm.h |  4 ++++
 kvm-all.c            | 31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
include/sysemu/kvm.h +4 -0
index c7bc07b..b2d61e9 100644
@@ -319,4 +319,8 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
 void kvm_pc_gsi_handler(void *opaque, int n, int level);
 void kvm_pc_setup_irq_routing(bool pci_enabled);
 void kvm_init_irq_routing(KVMState *s);
+
+int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr);
+int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr);
+
 #endif
kvm-all.c +31 -0
index ded7fc8..c24ab76 100644
@@ -34,6 +34,7 @@
 #include "exec/address-spaces.h"
 #include "qemu/event_notifier.h"
 #include "trace.h"
+#include "qemu/error-report.h"
 
 /* This check must be after config-host.h is included */
 #ifdef CONFIG_EVENTFD
@@ -2049,3 +2050,33 @@ int kvm_on_sigbus(int code, void *addr)
 {
     return kvm_arch_on_sigbus(code, addr);
 }
+
+int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr)
+{
+    struct kvm_one_reg reg = {
+        .id = id,
+        .addr = (uintptr_t)addr,
+    };
+    int ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
+
+    if (ret) {
+        error_report("Unable to set reg#0x%"PRIx64" to KVM: %m\n", id);
+    }
+
+    return ret;
+}
+
+int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr)
+{
+    struct kvm_one_reg reg = {
+        .id = id,
+        .addr = (uintptr_t)addr,
+    };
+    int ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &reg);
+
+    if (ret) {
+        error_report("Unable to get reg#0x%"PRIx64" from KVM: %m\n", id);
+    }
+
+    return ret;
+}
Signature · 1 line
1.8.4.rc4
#1 lore raw
Quoted 13 lines · Alexey Kardashevskiy

This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.

---
 include/sysemu/kvm.h |  4 ++++
 kvm-all.c            | 31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
include/sysemu/kvm.h +0 -0
index c7bc07b..b2d61e9 100644

include/sysemu/kvm.h int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq); · line 324

Quoted 6 lines
include/sysemu/kvm.h +3 -0
@@ -319,4 +319,8 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
 void kvm_pc_gsi_handler(void *opaque, int n, int level);
 void kvm_pc_setup_irq_routing(bool pci_enabled);
 void kvm_init_irq_routing(KVMState *s);
+
+int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr);
+int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr);

Doc comments, please.

Quoted 20 lines
include/sysemu/kvm.h +1 -0
+
 #endif
kvm-all.c +3 -0
index ded7fc8..c24ab76 100644
@@ -34,6 +34,7 @@
 #include "exec/address-spaces.h"
 #include "qemu/event_notifier.h"
 #include "trace.h"
+#include "qemu/error-report.h"
 
 /* This check must be after config-host.h is included */
 #ifdef CONFIG_EVENTFD
@@ -2049,3 +2050,33 @@ int kvm_on_sigbus(int code, void *addr)
 {
     return kvm_arch_on_sigbus(code, addr);
 }
+
+int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr)

kvm-all.c int kvm_on_sigbus(int code, void *addr) · line 2064

Quoted 10 lines
kvm-all.c +10 -0
+{
+    struct kvm_one_reg reg = {
+        .id = id,
+        .addr = (uintptr_t)addr,
+    };
+    int ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
+
+    if (ret) {
+        error_report("Unable to set reg#0x%"PRIx64" to KVM: %m\n", id);
+    }

This makes these functions useless for cases where you expect that they might fail (of which we have a number in target-arm). Please just return the error and leave the reporting/handling to the caller.

Incidentally, %m isn't portable -- it's a glibc extension and we have to work with non-glibc libc on some platforms. Also your error at this point isn't in errno, it's in ret (negated).

thanks
-- PMM

#2 lore raw
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Alexey Kardashevskiy

This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.

---
 include/sysemu/kvm.h |  4 ++++
 kvm-all.c            | 31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
Quoted 13 lines

include/sysemu/kvm.h int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq); · line 324

Quoted 11 lines
include/sysemu/kvm.h +3 -0
index c7bc07b..b2d61e9 100644
@@ -319,4 +319,8 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
 void kvm_pc_gsi_handler(void *opaque, int n, int level);
 void kvm_pc_setup_irq_routing(bool pci_enabled);
 void kvm_init_irq_routing(KVMState *s);
+
+int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr);
+int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr);

Doc comments, please.

What comments? Do not the function names speak for themselves already?

Signature · 1 line
Alexey
#3 lore raw
Quoted 24 lines · Alexey Kardashevskiy
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Alexey Kardashevskiy

This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.

---
 include/sysemu/kvm.h |  4 ++++
 kvm-all.c            | 31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
Quoted 13 lines

include/sysemu/kvm.h int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq); · line 324

Quoted 11 lines
include/sysemu/kvm.h +3 -0
index c7bc07b..b2d61e9 100644
@@ -319,4 +319,8 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
 void kvm_pc_gsi_handler(void *opaque, int n, int level);
 void kvm_pc_setup_irq_routing(bool pci_enabled);
 void kvm_init_irq_routing(KVMState *s);
+
+int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr);
+int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr);

Doc comments, please.

Quoted 1 line

What comments? Do not the function names speak for themselves already?

It's a new public function, it should have a comment in the standard format saying what it does and what the input parameters and output are. Just to pick some examples at random, the fact that the return value is 0-on-success-or-negative-errno should be documented, and we should refer the user to the ioctl docs for valid id values. It doesn't need to be a long essay, but we should be documenting new functions as we add them.

-- PMM

#4 lore raw
Quoted 25 lines · Peter Maydell
Quoted 24 lines · Alexey Kardashevskiy
Quoted 22 lines · Peter Maydell
Quoted 13 lines · Alexey Kardashevskiy

This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.

---
 include/sysemu/kvm.h |  4 ++++
 kvm-all.c            | 31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
include/sysemu/kvm.h +0 -0
index c7bc07b..b2d61e9 100644

include/sysemu/kvm.h int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq); · line 324

Quoted 6 lines
include/sysemu/kvm.h +3 -0
@@ -319,4 +319,8 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
 void kvm_pc_gsi_handler(void *opaque, int n, int level);
 void kvm_pc_setup_irq_routing(bool pci_enabled);
 void kvm_init_irq_routing(KVMState *s);
+
+int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr);
+int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr);

Doc comments, please.

Quoted 8 lines
Quoted 1 line

What comments? Do not the function names speak for themselves already?

It's a new public function, it should have a comment in the standard format saying what it does and what the input parameters and output are. Just to pick some examples at random, the fact that the return value is 0-on-success-or-negative-errno should be documented, and we should refer the user to the ioctl docs for valid id values. It doesn't need to be a long essay, but we should be documenting new functions as we add them.

It would be awesome if you just gave me any really good example of what you expect from such a comment as kvm-all.c does not have any whatsoever. And pci.c does not. And exec.c does not. But I am sure there is some as it cannot possibly be me who starts making such comments in qemu. Thanks.

Signature · 1 line
Alexey
#5 lore raw
Quoted 5 lines · Alexey Kardashevskiy

On 09/18/2013 05:59 PM, Peter Maydell wrote:
It would be awesome if you just gave me any really good example of what you expect from such a comment as kvm-all.c does not have any whatsoever. And pci.c does not. And exec.c does not. But I am sure there is some as it cannot possibly be me who starts making such comments in qemu. Thanks.

Yes, we have a lot of preexisting undocumented functions. It's very common in QEMU for existing code not to be up to preferred standards; you can't use current code as a yardstick for "good enough to pass code review".

The example I usually crib from for formatting is the extract/deposit APIs in include/qemu/bitops.h. include/exec/memory.h is also well documented.

-- PMM

#6 lore raw
In reply to Alexey Kardashevskiy

Il 18/09/2013 10:08, Alexey Kardashevskiy ha scritto:

Quoted 36 lines · Peter Maydell
Quoted 25 lines · Alexey Kardashevskiy
Quoted 24 lines · Peter Maydell
Quoted 22 lines · Alexey Kardashevskiy
Quoted 13 lines

This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.

---
 include/sysemu/kvm.h |  4 ++++
 kvm-all.c            | 31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
include/sysemu/kvm.h +0 -0
index c7bc07b..b2d61e9 100644

include/sysemu/kvm.h int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq); · line 324

Quoted 6 lines
include/sysemu/kvm.h +3 -0
@@ -319,4 +319,8 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
 void kvm_pc_gsi_handler(void *opaque, int n, int level);
 void kvm_pc_setup_irq_routing(bool pci_enabled);
 void kvm_init_irq_routing(KVMState *s);
+
+int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr);
+int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr);

Doc comments, please.

Quoted 8 lines
Quoted 1 line

What comments? Do not the function names speak for themselves already?

It's a new public function, it should have a comment in the standard format saying what it does and what the input parameters and output are. Just to pick some examples at random, the fact that the return value is 0-on-success-or-negative-errno should be documented, and we should refer the user to the ioctl docs for valid id values. It doesn't need to be a long essay, but we should be documenting new functions as we add them.

Quoted 4 lines

It would be awesome if you just gave me any really good example of what you expect from such a comment as kvm-all.c does not have any whatsoever. And pci.c does not. And exec.c does not. But I am sure there is some as it cannot possibly be me who starts making such comments in qemu. Thanks.

include/exec/memory.h, include/qom/object.h, include/block/blockjob.h, include/qemu/main-loop.h, include/block/aio.h have many, thankfully.

Paolo