Blame SOURCES/kvm-all-Pass-an-error-object-to-kvm_device_access.patch

76daa3
From 9c4152bb3eec460be32ab6704753f61edf9f8472 Mon Sep 17 00:00:00 2001
76daa3
From: Auger Eric <eric.auger@redhat.com>
76daa3
Date: Fri, 16 Jun 2017 15:17:53 +0200
76daa3
Subject: [PATCH 2/5] kvm-all: Pass an error object to kvm_device_access
76daa3
76daa3
RH-Author: Auger Eric <eric.auger@redhat.com>
76daa3
Message-id: <1497626276-18221-3-git-send-email-eric.auger@redhat.com>
76daa3
Patchwork-id: 75638
76daa3
O-Subject: [Pegas-1.0 qemu-kvm PATCH v2 2/5] kvm-all: Pass an error object to kvm_device_access
76daa3
Bugzilla: 1462061
76daa3
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
76daa3
RH-Acked-by: Peter Xu <peterx@redhat.com>
76daa3
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
76daa3
76daa3
In some circumstances, we don't want to abort if the
76daa3
kvm_device_access fails. This will be the case during ITS
76daa3
migration, in case the ITS table save/restore fails because
76daa3
the guest did not program the vITS correctly. So let's pass an
76daa3
error object to the function and return the ioctl value. New
76daa3
callers will be able to make a decision upon this returned
76daa3
value.
76daa3
76daa3
Existing callers pass &error_abort which will cause the
76daa3
function to abort on failure.
76daa3
76daa3
Signed-off-by: Eric Auger <eric.auger@redhat.com>
76daa3
Reviewed-by: Juan Quintela <quintela@redhat.com>
76daa3
Reviewed-by: Peter Xu <peterx@redhat.com>
76daa3
Message-id: 1497023553-18411-2-git-send-email-eric.auger@redhat.com
76daa3
[PMM: wrapped long line]
76daa3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
76daa3
76daa3
(cherry picked from commit 556969e938a97e98eec9df039944741ed74ce049)
76daa3
Signed-off-by: Eric Auger <eric.auger@redhat.com>
76daa3
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
76daa3
---
76daa3
 hw/intc/arm_gic_kvm.c       |  9 +++++----
76daa3
 hw/intc/arm_gicv3_its_kvm.c |  2 +-
76daa3
 hw/intc/arm_gicv3_kvm.c     | 14 +++++++-------
76daa3
 include/sysemu/kvm.h        | 11 +++++++----
76daa3
 kvm-all.c                   | 14 ++++++++------
76daa3
 5 files changed, 28 insertions(+), 22 deletions(-)
76daa3
76daa3
diff --git a/hw/intc/arm_gic_kvm.c b/hw/intc/arm_gic_kvm.c
76daa3
index ec952ec..98fbe98 100644
76daa3
--- a/hw/intc/arm_gic_kvm.c
76daa3
+++ b/hw/intc/arm_gic_kvm.c
76daa3
@@ -100,14 +100,14 @@ static void kvm_gicd_access(GICState *s, int offset, int cpu,
76daa3
                             uint32_t *val, bool write)
76daa3
 {
76daa3
     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
76daa3
-                      KVM_VGIC_ATTR(offset, cpu), val, write);
76daa3
+                      KVM_VGIC_ATTR(offset, cpu), val, write, &error_abort);
76daa3
 }
76daa3
 
76daa3
 static void kvm_gicc_access(GICState *s, int offset, int cpu,
76daa3
                             uint32_t *val, bool write)
76daa3
 {
76daa3
     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CPU_REGS,
76daa3
-                      KVM_VGIC_ATTR(offset, cpu), val, write);
76daa3
+                      KVM_VGIC_ATTR(offset, cpu), val, write, &error_abort);
76daa3
 }
76daa3
 
76daa3
 #define for_each_irq_reg(_ctr, _max_irq, _field_width) \
76daa3
@@ -538,13 +538,14 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)
76daa3
         if (kvm_device_check_attr(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS, 0)) {
76daa3
             uint32_t numirqs = s->num_irq;
76daa3
             kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS, 0,
76daa3
-                              &numirqs, true);
76daa3
+                              &numirqs, true, &error_abort);
76daa3
         }
76daa3
         /* Tell the kernel to complete VGIC initialization now */
76daa3
         if (kvm_device_check_attr(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
76daa3
                                   KVM_DEV_ARM_VGIC_CTRL_INIT)) {
76daa3
             kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
76daa3
-                              KVM_DEV_ARM_VGIC_CTRL_INIT, NULL, true);
76daa3
+                              KVM_DEV_ARM_VGIC_CTRL_INIT, NULL, true,
76daa3
+                              &error_abort);
76daa3
         }
76daa3
     } else if (ret != -ENODEV && ret != -ENOTSUP) {
76daa3
         error_setg_errno(errp, -ret, "error creating in-kernel VGIC");
76daa3
diff --git a/hw/intc/arm_gicv3_its_kvm.c b/hw/intc/arm_gicv3_its_kvm.c
76daa3
index bd4f3aa..ad2a1db 100644
76daa3
--- a/hw/intc/arm_gicv3_its_kvm.c
76daa3
+++ b/hw/intc/arm_gicv3_its_kvm.c
76daa3
@@ -78,7 +78,7 @@ static void kvm_arm_its_realize(DeviceState *dev, Error **errp)
76daa3
 
76daa3
     /* explicit init of the ITS */
76daa3
     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
76daa3
-                      KVM_DEV_ARM_VGIC_CTRL_INIT, NULL, true);
76daa3
+                      KVM_DEV_ARM_VGIC_CTRL_INIT, NULL, true, &error_abort);
76daa3
 
76daa3
     /* register the base address */
76daa3
     kvm_arm_register_device(&s->iomem_its_cntrl, -1, KVM_DEV_ARM_VGIC_GRP_ADDR,
76daa3
diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c
76daa3
index 19aab56..824475f 100644
76daa3
--- a/hw/intc/arm_gicv3_kvm.c
76daa3
+++ b/hw/intc/arm_gicv3_kvm.c
76daa3
@@ -93,7 +93,7 @@ static inline void kvm_gicd_access(GICv3State *s, int offset,
76daa3
 {
76daa3
     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
76daa3
                       KVM_VGIC_ATTR(offset, 0),
76daa3
-                      val, write);
76daa3
+                      val, write, &error_abort);
76daa3
 }
76daa3
 
76daa3
 static inline void kvm_gicr_access(GICv3State *s, int offset, int cpu,
76daa3
@@ -101,7 +101,7 @@ static inline void kvm_gicr_access(GICv3State *s, int offset, int cpu,
76daa3
 {
76daa3
     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_REDIST_REGS,
76daa3
                       KVM_VGIC_ATTR(offset, s->cpu[cpu].gicr_typer),
76daa3
-                      val, write);
76daa3
+                      val, write, &error_abort);
76daa3
 }
76daa3
 
76daa3
 static inline void kvm_gicc_access(GICv3State *s, uint64_t reg, int cpu,
76daa3
@@ -109,7 +109,7 @@ static inline void kvm_gicc_access(GICv3State *s, uint64_t reg, int cpu,
76daa3
 {
76daa3
     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS,
76daa3
                       KVM_VGIC_ATTR(reg, s->cpu[cpu].gicr_typer),
76daa3
-                      val, write);
76daa3
+                      val, write, &error_abort);
76daa3
 }
76daa3
 
76daa3
 static inline void kvm_gic_line_level_access(GICv3State *s, int irq, int cpu,
76daa3
@@ -119,7 +119,7 @@ static inline void kvm_gic_line_level_access(GICv3State *s, int irq, int cpu,
76daa3
                       KVM_VGIC_ATTR(irq, s->cpu[cpu].gicr_typer) |
76daa3
                       (VGIC_LEVEL_INFO_LINE_LEVEL <<
76daa3
                        KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT),
76daa3
-                      val, write);
76daa3
+                      val, write, &error_abort);
76daa3
 }
76daa3
 
76daa3
 /* Loop through each distributor IRQ related register; since bits
76daa3
@@ -630,7 +630,7 @@ static void arm_gicv3_icc_reset(CPUARMState *env, const ARMCPRegInfo *ri)
76daa3
     /* Initialize to actual HW supported configuration */
76daa3
     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS,
76daa3
                       KVM_VGIC_ATTR(ICC_CTLR_EL1, cpu->mp_affinity),
76daa3
-                      &c->icc_ctlr_el1[GICV3_NS], false);
76daa3
+                      &c->icc_ctlr_el1[GICV3_NS], false, &error_abort);
76daa3
 
76daa3
     c->icc_ctlr_el1[GICV3_S] = c->icc_ctlr_el1[GICV3_NS];
76daa3
 }
76daa3
@@ -717,11 +717,11 @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp)
76daa3
     }
76daa3
 
76daa3
     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS,
76daa3
-                      0, &s->num_irq, true);
76daa3
+                      0, &s->num_irq, true, &error_abort);
76daa3
 
76daa3
     /* Tell the kernel to complete VGIC initialization now */
76daa3
     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
76daa3
-                      KVM_DEV_ARM_VGIC_CTRL_INIT, NULL, true);
76daa3
+                      KVM_DEV_ARM_VGIC_CTRL_INIT, NULL, true, &error_abort);
76daa3
 
76daa3
     kvm_arm_register_device(&s->iomem_dist, -1, KVM_DEV_ARM_VGIC_GRP_ADDR,
76daa3
                             KVM_VGIC_V3_ADDR_TYPE_DIST, s->dev_fd);
76daa3
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
76daa3
index 5cc83f2..b4f52b0 100644
76daa3
--- a/include/sysemu/kvm.h
76daa3
+++ b/include/sysemu/kvm.h
76daa3
@@ -294,12 +294,15 @@ int kvm_device_check_attr(int fd, uint32_t group, uint64_t attr);
76daa3
  * @attr: the attribute of that group to set or get
76daa3
  * @val: pointer to a storage area for the value
76daa3
  * @write: true for set and false for get operation
76daa3
+ * @errp: error object handle
76daa3
  *
76daa3
- * This function is not allowed to fail. Use kvm_device_check_attr()
76daa3
- * in order to check for the availability of optional attributes.
76daa3
+ * Returns: 0 on success
76daa3
+ *          < 0 on error
76daa3
+ * Use kvm_device_check_attr() in order to check for the availability
76daa3
+ * of optional attributes.
76daa3
  */
76daa3
-void kvm_device_access(int fd, int group, uint64_t attr,
76daa3
-                       void *val, bool write);
76daa3
+int kvm_device_access(int fd, int group, uint64_t attr,
76daa3
+                      void *val, bool write, Error **errp);
76daa3
 
76daa3
 /**
76daa3
  * kvm_create_device - create a KVM device for the device control API
76daa3
diff --git a/kvm-all.c b/kvm-all.c
76daa3
index 128f5c8..bed0288 100644
76daa3
--- a/kvm-all.c
76daa3
+++ b/kvm-all.c
76daa3
@@ -23,6 +23,7 @@
76daa3
 #include "qemu/option.h"
76daa3
 #include "qemu/config-file.h"
76daa3
 #include "qemu/error-report.h"
76daa3
+#include "qapi/error.h"
76daa3
 #include "hw/hw.h"
76daa3
 #include "hw/pci/msi.h"
76daa3
 #include "hw/pci/msix.h"
76daa3
@@ -2228,8 +2229,8 @@ int kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr)
76daa3
     return kvm_device_ioctl(dev_fd, KVM_HAS_DEVICE_ATTR, &attribute) ? 0 : 1;
76daa3
 }
76daa3
 
76daa3
-void kvm_device_access(int fd, int group, uint64_t attr,
76daa3
-                       void *val, bool write)
76daa3
+int kvm_device_access(int fd, int group, uint64_t attr,
76daa3
+                      void *val, bool write, Error **errp)
76daa3
 {
76daa3
     struct kvm_device_attr kvmattr;
76daa3
     int err;
76daa3
@@ -2243,11 +2244,12 @@ void kvm_device_access(int fd, int group, uint64_t attr,
76daa3
                            write ? KVM_SET_DEVICE_ATTR : KVM_GET_DEVICE_ATTR,
76daa3
                            &kvmattr);
76daa3
     if (err < 0) {
76daa3
-        error_report("KVM_%s_DEVICE_ATTR failed: %s",
76daa3
-                     write ? "SET" : "GET", strerror(-err));
76daa3
-        error_printf("Group %d attr 0x%016" PRIx64 "\n", group, attr);
76daa3
-        abort();
76daa3
+        error_setg_errno(errp, -err,
76daa3
+                         "KVM_%s_DEVICE_ATTR failed: Group %d "
76daa3
+                         "attr 0x%016" PRIx64,
76daa3
+                         write ? "SET" : "GET", group, attr);
76daa3
     }
76daa3
+    return err;
76daa3
 }
76daa3
 
76daa3
 /* Return 1 on success, 0 on failure */
76daa3
-- 
76daa3
1.8.3.1
76daa3