Blame SOURCES/kvm-apic-Use-32bit-APIC-ID-for-migration-instance-ID.patch

ddf19c
From 0d5a09173eb75b7e56122c2aefb2646a2be58400 Mon Sep 17 00:00:00 2001
ddf19c
From: Peter Xu <peterx@redhat.com>
ddf19c
Date: Fri, 31 Jan 2020 17:12:57 +0000
ddf19c
Subject: [PATCH 15/15] apic: Use 32bit APIC ID for migration instance ID
ddf19c
ddf19c
RH-Author: Peter Xu <peterx@redhat.com>
ddf19c
Message-id: <20200131171257.1066593-4-peterx@redhat.com>
ddf19c
Patchwork-id: 93628
ddf19c
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH 3/3] apic: Use 32bit APIC ID for migration instance ID
ddf19c
Bugzilla: 1529231
ddf19c
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
ddf19c
RH-Acked-by: Juan Quintela <quintela@redhat.com>
ddf19c
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
ddf19c
Migration is silently broken now with x2apic config like this:
ddf19c
ddf19c
     -smp 200,maxcpus=288,sockets=2,cores=72,threads=2 \
ddf19c
     -device intel-iommu,intremap=on,eim=on
ddf19c
ddf19c
After migration, the guest kernel could hang at anything, due to
ddf19c
x2apic bit not migrated correctly in IA32_APIC_BASE on some vcpus, so
ddf19c
any operations related to x2apic could be broken then (e.g., RDMSR on
ddf19c
x2apic MSRs could fail because KVM would think that the vcpu hasn't
ddf19c
enabled x2apic at all).
ddf19c
ddf19c
The issue is that the x2apic bit was never applied correctly for vcpus
ddf19c
whose ID > 255 when migrate completes, and that's because when we
ddf19c
migrate APIC we use the APICCommonState.id as instance ID of the
ddf19c
migration stream, while that's too short for x2apic.
ddf19c
ddf19c
Let's use the newly introduced initial_apic_id for that.
ddf19c
ddf19c
Signed-off-by: Peter Xu <peterx@redhat.com>
ddf19c
Reviewed-by: Juan Quintela <quintela@redhat.com>
ddf19c
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
ddf19c
Signed-off-by: Juan Quintela <quintela@redhat.com>
ddf19c
(cherry picked from commit 0ab994867c365db21e15f9503922c79234d8e40e)
ddf19c
Signed-off-by: Peter Xu <peterx@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 hw/intc/apic_common.c | 5 ++++-
ddf19c
 1 file changed, 4 insertions(+), 1 deletion(-)
ddf19c
ddf19c
diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
ddf19c
index 54b8731..b5dbeb6 100644
ddf19c
--- a/hw/intc/apic_common.c
ddf19c
+++ b/hw/intc/apic_common.c
ddf19c
@@ -268,7 +268,10 @@ static void apic_common_realize(DeviceState *dev, Error **errp)
ddf19c
     APICCommonState *s = APIC_COMMON(dev);
ddf19c
     APICCommonClass *info;
ddf19c
     static DeviceState *vapic;
ddf19c
-    uint32_t instance_id = s->id;
ddf19c
+    uint32_t instance_id = s->initial_apic_id;
ddf19c
+
ddf19c
+    /* Normally initial APIC ID should be no more than hundreds */
ddf19c
+    assert(instance_id != VMSTATE_INSTANCE_ID_ANY);
ddf19c
 
ddf19c
     info = APIC_COMMON_GET_CLASS(s);
ddf19c
     info->realize(dev, errp);
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c