Skip to contentSkip to conversation

kvm: add set_one_reg/get_one_reg helpers

PATCH Superseded Alexey Kardashevskiy 2 participants 2 messages Sep 19, 2013

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kvm: add set_one_reg/get_one_reg helpers

This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.

---
Changes:
v2:
* added Doc Comments
* removed error_print

---
 include/sysemu/kvm.h |  4 ++++
 kvm-all.c            | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 37 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 +33 -0
index ded7fc8..da02c96 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,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);
+}
Signature · 1 line
1.8.4.rc4
#1 lore raw
Quoted 8 lines · Alexey Kardashevskiy

This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.

---
Changes:
v2:
* added Doc Comments
* removed error_print

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

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

Quoted 9 lines
kvm-all.c +5 -0
@@ -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...)

Review int kvm_on_sigbus(int code, void *addr) · line 2059

Quoted 2 lines
(quoted diff) +2 -0
+ *
+ * Returns 0 if succeded and negative value if failed.

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

thanks
-- PMM