76daa3
From 32fb43910b25c19261f4c3153a7442713cbc4de3 Mon Sep 17 00:00:00 2001
76daa3
From: Laurent Vivier <lvivier@redhat.com>
76daa3
Date: Fri, 4 Aug 2017 16:50:30 +0200
76daa3
Subject: [PATCH 2/4] cpu: don't allow negative core id
76daa3
76daa3
RH-Author: Laurent Vivier <lvivier@redhat.com>
76daa3
Message-id: <20170804165030.26586-1-lvivier@redhat.com>
76daa3
Patchwork-id: 75897
76daa3
O-Subject: [RHEL-ALT-7.4 qemu-kvm PATCH] cpu: don't allow negative core id
76daa3
Bugzilla: 1476181
76daa3
RH-Acked-by: David Gibson <dgibson@redhat.com>
76daa3
RH-Acked-by: Thomas Huth <thuth@redhat.com>
76daa3
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
76daa3
76daa3
With pseries machine type a negative core-id is not managed properly:
76daa3
-1 gives an inaccurate error message ("core -1 already populated"),
76daa3
-2 crashes QEMU (core dump)
76daa3
76daa3
As it seems a negative value is invalid for any architecture,
76daa3
instead of checking this in spapr_core_pre_plug() I think it's better
76daa3
to check this in the generic part, core_prop_set_core_id()
76daa3
76daa3
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
76daa3
Message-Id: <20170802103259.25940-1-lvivier@redhat.com>
76daa3
Reviewed-by: Greg Kurz <groug@kaod.org>
76daa3
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
76daa3
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
76daa3
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
76daa3
(cherry picked from commit be2960baae07e5257cde8c814cbd91647e235147)
76daa3
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
76daa3
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
76daa3
---
76daa3
 hw/cpu/core.c | 5 +++++
76daa3
 1 file changed, 5 insertions(+)
76daa3
76daa3
diff --git a/hw/cpu/core.c b/hw/cpu/core.c
76daa3
index 2bf960d..bd578ab 100644
76daa3
--- a/hw/cpu/core.c
76daa3
+++ b/hw/cpu/core.c
76daa3
@@ -33,6 +33,11 @@ static void core_prop_set_core_id(Object *obj, Visitor *v, const char *name,
76daa3
         return;
76daa3
     }
76daa3
 
76daa3
+    if (value < 0) {
76daa3
+        error_setg(errp, "Invalid core id %"PRId64, value);
76daa3
+        return;
76daa3
+    }
76daa3
+
76daa3
     core->core_id = value;
76daa3
 }
76daa3
 
76daa3
-- 
76daa3
1.8.3.1
76daa3