yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-s390x-cpumodel-fix-segmentation-fault-when-baselinin.patch

ae23c9
From 10cd7878be0501be1e27b7b00c14958efcdb3d9b Mon Sep 17 00:00:00 2001
ae23c9
From: Cornelia Huck <cohuck@redhat.com>
ae23c9
Date: Wed, 17 Apr 2019 13:57:22 +0100
ae23c9
Subject: [PATCH 05/24] s390x/cpumodel: fix segmentation fault when baselining
ae23c9
 models
ae23c9
MIME-Version: 1.0
ae23c9
Content-Type: text/plain; charset=UTF-8
ae23c9
Content-Transfer-Encoding: 8bit
ae23c9
ae23c9
RH-Author: Cornelia Huck <cohuck@redhat.com>
ae23c9
Message-id: <20190417135741.25297-6-cohuck@redhat.com>
ae23c9
Patchwork-id: 85784
ae23c9
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH v2 05/24] s390x/cpumodel: fix segmentation fault when baselining models
ae23c9
Bugzilla: 1699070
ae23c9
RH-Acked-by: David Hildenbrand <david@redhat.com>
ae23c9
RH-Acked-by: Thomas Huth <thuth@redhat.com>
ae23c9
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ae23c9
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
ae23c9
ae23c9
From: David Hildenbrand <david@redhat.com>
ae23c9
ae23c9
Usually, when baselining two CPU models, whereby one of them has base
ae23c9
CPU features disabled (e.g. z14-base,msa=off), we fallback to an older
ae23c9
model that did not have these features in the base model. We always try to
ae23c9
create a "sane" CPU model (as far as possible), and one part of it is that
ae23c9
removing base features is no good and to be avoided.
ae23c9
ae23c9
Now, if we disable base features that were part of a z900, we're out of
ae23c9
luck. We won't find a CPU model and QEMU will segfault. This is a
ae23c9
scenario that should never happen in real life, but it can be used to
ae23c9
crash QEMU.
ae23c9
ae23c9
So let's properly report an error if we baseline e.g.:
ae23c9
ae23c9
{ "execute": "query-cpu-model-baseline",
ae23c9
  "arguments" : { "modela": { "name": "z14-base", "props": {"esan3" : false}},
ae23c9
                  "modelb": { "name": "z14"}} }
ae23c9
ae23c9
Instead of segfaulting.
ae23c9
ae23c9
Signed-off-by: David Hildenbrand <david@redhat.com>
ae23c9
Message-Id: <20180718092330.19465-1-david@redhat.com>
ae23c9
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
ae23c9
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
ae23c9
(cherry picked from commit 677ff32db12bcd1bca3a3df733d2478896d6df96)
ae23c9
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 target/s390x/cpu_models.c | 8 ++++++++
ae23c9
 1 file changed, 8 insertions(+)
ae23c9
ae23c9
diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
ae23c9
index 5e9b716..d2c16b8 100644
ae23c9
--- a/target/s390x/cpu_models.c
ae23c9
+++ b/target/s390x/cpu_models.c
ae23c9
@@ -720,6 +720,14 @@ CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *infoa,
ae23c9
 
ae23c9
     model.def = s390_find_cpu_def(cpu_type, max_gen, max_gen_ga,
ae23c9
                                   model.features);
ae23c9
+
ae23c9
+    /* models without early base features (esan3) are bad */
ae23c9
+    if (!model.def) {
ae23c9
+        error_setg(errp, "No compatible CPU model could be created as"
ae23c9
+                   " important base features are disabled");
ae23c9
+        return NULL;
ae23c9
+    }
ae23c9
+
ae23c9
     /* strip off features not part of the max model */
ae23c9
     bitmap_and(model.features, model.features, model.def->full_feat,
ae23c9
                S390_FEAT_MAX);
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9