diff mbox

[v2] kvm: add set_one_reg/get_one_reg helpers

Message ID 1379556520-4563-1-git-send-email-aik@ozlabs.ru
State New
Headers show

Commit Message

Alexey Kardashevskiy Sept. 19, 2013, 2:08 a.m. UTC
This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
Changes:
v2:
* added Doc Comments
* removed error_print
---
 include/sysemu/kvm.h |  4 ++++
 kvm-all.c            | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

Comments

Peter Maydell Sept. 19, 2013, 2:15 a.m. UTC | #1
On 19 September 2013 11:08, Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
> This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.
>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
> Changes:
> v2:
> * added Doc Comments
> * removed error_print

Thanks. The doc comments should go in the header file, not
the .c file, though.

> @@ -2049,3 +2050,35 @@ int kvm_on_sigbus(int code, void *addr)
>  {
>      return kvm_arch_on_sigbus(code, addr);
>  }
> +
> +/**
> + * kvm_set_one_reg - set a register value in KVM via KVM_SET_ONE_REG ioctl
> + * @id: The register ID
> + * @addr: The pointer to a value

"(must point to a variable of the correct type/size for the
register being accessed)". That is, you can't put the value
in a uint64_t if the register is 32 bits wide, the kernel
will only read/write 32 bits (and the wrong 32 bits if
big-endian...)

> + *
> + * Returns 0 if succeded and negative value if failed.

"0 on success, or a negative errno on failure"

thanks
-- PMM
diff mbox

Patch

diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index c7bc07b..b2d61e9 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -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
diff --git a/kvm-all.c b/kvm-all.c
index ded7fc8..da02c96 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -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,35 @@  int kvm_on_sigbus(int code, void *addr)
 {
     return kvm_arch_on_sigbus(code, addr);
 }
+
+/**
+ * kvm_set_one_reg - set a register value in KVM via KVM_SET_ONE_REG ioctl
+ * @id: The register ID
+ * @addr: The pointer to a value
+ *
+ * Returns 0 if succeded and negative value if failed.
+ */
+int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr)
+{
+    struct kvm_one_reg reg = {
+        .id = id,
+        .addr = (uintptr_t)addr,
+    };
+    return kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
+}
+
+/**
+ * kvm_get_one_reg - get a register value from KVM via KVM_GET_ONE_REG ioctl
+ * @id: The register ID
+ * @addr: The pointer to a value
+ *
+ * Returns 0 if succeded and negative value if failed.
+ */
+int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr)
+{
+    struct kvm_one_reg reg = {
+        .id = id,
+        .addr = (uintptr_t)addr,
+    };
+    return kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &reg);
+}