cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
eb5a2f
From c878c42b892a18de84888766f14107005b4c4466 Mon Sep 17 00:00:00 2001
eb5a2f
From: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Date: Mon, 19 May 2014 09:57:37 +0200
eb5a2f
Subject: [PATCH 1/2] kvm: zero-initialize KVM_SET_GSI_ROUTING input
eb5a2f
eb5a2f
RH-Author: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Message-id: <1400493448-29146-2-git-send-email-mst@redhat.com>
eb5a2f
Patchwork-id: 58948
eb5a2f
O-Subject: [PATCH qemu-kvm RHEL7.1 1/2] kvm: zero-initialize KVM_SET_GSI_ROUTING input
eb5a2f
Bugzilla: 1110693
eb5a2f
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
eb5a2f
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
eb5a2f
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
eb5a2f
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
eb5a2f
eb5a2f
kvm_add_routing_entry makes an attempt to
eb5a2f
zero-initialize any new routing entry.
eb5a2f
However, it fails to initialize padding
eb5a2f
within the u field of the structure
eb5a2f
kvm_irq_routing_entry.
eb5a2f
eb5a2f
Other functions like kvm_irqchip_update_msi_route
eb5a2f
also fail to initialize the padding field in
eb5a2f
kvm_irq_routing_entry.
eb5a2f
eb5a2f
It's better to just make sure all input is initialized.
eb5a2f
eb5a2f
Once it is, we can also drop complex field by field assignment and just
eb5a2f
do the simple *a = *b to update a route entry.
eb5a2f
eb5a2f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Signed-off-by: Gleb Natapov <gleb@redhat.com>
eb5a2f
(cherry picked from commit 0fbc20740342713f282b118b4a446c4c43df3f4a)
eb5a2f
---
eb5a2f
 kvm-all.c | 19 +++++++------------
eb5a2f
 1 file changed, 7 insertions(+), 12 deletions(-)
eb5a2f
eb5a2f
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
eb5a2f
---
eb5a2f
 kvm-all.c |   19 +++++++------------
eb5a2f
 1 files changed, 7 insertions(+), 12 deletions(-)
eb5a2f
eb5a2f
diff --git a/kvm-all.c b/kvm-all.c
eb5a2f
index adc0a8e..592301a 100644
eb5a2f
--- a/kvm-all.c
eb5a2f
+++ b/kvm-all.c
eb5a2f
@@ -988,11 +988,8 @@ static void kvm_add_routing_entry(KVMState *s,
eb5a2f
     }
eb5a2f
     n = s->irq_routes->nr++;
eb5a2f
     new = &s->irq_routes->entries[n];
eb5a2f
-    memset(new, 0, sizeof(*new));
eb5a2f
-    new->gsi = entry->gsi;
eb5a2f
-    new->type = entry->type;
eb5a2f
-    new->flags = entry->flags;
eb5a2f
-    new->u = entry->u;
eb5a2f
+
eb5a2f
+    *new = *entry;
eb5a2f
 
eb5a2f
     set_gsi(s, entry->gsi);
eb5a2f
 
eb5a2f
@@ -1011,9 +1008,7 @@ static int kvm_update_routing_entry(KVMState *s,
eb5a2f
             continue;
eb5a2f
         }
eb5a2f
 
eb5a2f
-        entry->type = new_entry->type;
eb5a2f
-        entry->flags = new_entry->flags;
eb5a2f
-        entry->u = new_entry->u;
eb5a2f
+        *entry = *new_entry;
eb5a2f
 
eb5a2f
         kvm_irqchip_commit_routes(s);
eb5a2f
 
eb5a2f
@@ -1025,7 +1020,7 @@ static int kvm_update_routing_entry(KVMState *s,
eb5a2f
 
eb5a2f
 void kvm_irqchip_add_irq_route(KVMState *s, int irq, int irqchip, int pin)
eb5a2f
 {
eb5a2f
-    struct kvm_irq_routing_entry e;
eb5a2f
+    struct kvm_irq_routing_entry e = {};
eb5a2f
 
eb5a2f
     assert(pin < s->gsi_count);
eb5a2f
 
eb5a2f
@@ -1138,7 +1133,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg)
eb5a2f
             return virq;
eb5a2f
         }
eb5a2f
 
eb5a2f
-        route = g_malloc(sizeof(KVMMSIRoute));
eb5a2f
+        route = g_malloc0(sizeof(KVMMSIRoute));
eb5a2f
         route->kroute.gsi = virq;
eb5a2f
         route->kroute.type = KVM_IRQ_ROUTING_MSI;
eb5a2f
         route->kroute.flags = 0;
eb5a2f
@@ -1159,7 +1154,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg)
eb5a2f
 
eb5a2f
 int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
eb5a2f
 {
eb5a2f
-    struct kvm_irq_routing_entry kroute;
eb5a2f
+    struct kvm_irq_routing_entry kroute = {};
eb5a2f
     int virq;
eb5a2f
 
eb5a2f
     if (!kvm_gsi_routing_enabled()) {
eb5a2f
@@ -1185,7 +1180,7 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
eb5a2f
 
eb5a2f
 int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg)
eb5a2f
 {
eb5a2f
-    struct kvm_irq_routing_entry kroute;
eb5a2f
+    struct kvm_irq_routing_entry kroute = {};
eb5a2f
 
eb5a2f
     if (!kvm_irqchip_in_kernel()) {
eb5a2f
         return -ENOSYS;
eb5a2f
-- 
eb5a2f
1.7.1
eb5a2f