diff --git a/SOURCES/libvirt-conf-Introduce-virCPUDefFindFeature.patch b/SOURCES/libvirt-conf-Introduce-virCPUDefFindFeature.patch
new file mode 100644
index 0000000..2ffc775
--- /dev/null
+++ b/SOURCES/libvirt-conf-Introduce-virCPUDefFindFeature.patch
@@ -0,0 +1,114 @@
+From 2d9d40cfec0aa5db556ca62395671dc340b6bf93 Mon Sep 17 00:00:00 2001
+Message-Id: <2d9d40cfec0aa5db556ca62395671dc340b6bf93@dist-git>
+From: Jiri Denemark <jdenemar@redhat.com>
+Date: Mon, 9 Oct 2017 16:20:43 +0200
+Subject: [PATCH] conf: Introduce virCPUDefFindFeature
+
+Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
+Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
+(cherry picked from commit 3276416904393a06df664c5d849ee805d07688d8)
+
+Conflicts:
+	src/conf/cpu_conf.h - context, two more new function prototypes
+            in the header file upstream
+
+https://bugzilla.redhat.com/show_bug.cgi?id=1508549
+
+Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
+---
+ src/conf/cpu_conf.c      | 40 +++++++++++++++++++++++++++-------------
+ src/conf/cpu_conf.h      |  4 ++++
+ src/libvirt_private.syms |  1 +
+ 3 files changed, 32 insertions(+), 13 deletions(-)
+
+diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
+index da40e9ba97..e570dffcd2 100644
+--- a/src/conf/cpu_conf.c
++++ b/src/conf/cpu_conf.c
+@@ -773,24 +773,22 @@ virCPUDefUpdateFeatureInternal(virCPUDefPtr def,
+                                int policy,
+                                bool update)
+ {
+-    size_t i;
++    virCPUFeatureDefPtr feat;
+ 
+     if (def->type == VIR_CPU_TYPE_HOST)
+         policy = -1;
+ 
+-    for (i = 0; i < def->nfeatures; i++) {
+-        if (STREQ(name, def->features[i].name)) {
+-            if (update) {
+-                def->features[i].policy = policy;
+-                return 0;
+-            }
+-
+-            virReportError(VIR_ERR_INTERNAL_ERROR,
+-                           _("CPU feature '%s' specified more than once"),
+-                           name);
+-
+-            return -1;
++    if ((feat = virCPUDefFindFeature(def, name))) {
++        if (update) {
++            feat->policy = policy;
++            return 0;
+         }
++
++        virReportError(VIR_ERR_INTERNAL_ERROR,
++                       _("CPU feature '%s' specified more than once"),
++                       name);
++
++        return -1;
+     }
+ 
+     if (VIR_RESIZE_N(def->features, def->nfeatures_max,
+@@ -822,6 +820,22 @@ virCPUDefAddFeature(virCPUDefPtr def,
+     return virCPUDefUpdateFeatureInternal(def, name, policy, false);
+ }
+ 
++
++virCPUFeatureDefPtr
++virCPUDefFindFeature(virCPUDefPtr def,
++                     const char *name)
++{
++    size_t i;
++
++    for (i = 0; i < def->nfeatures; i++) {
++        if (STREQ(name, def->features[i].name))
++            return def->features + i;
++    }
++
++    return NULL;
++}
++
++
+ bool
+ virCPUDefIsEqual(virCPUDefPtr src,
+                  virCPUDefPtr dst,
+diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
+index b44974f47e..1978814d36 100644
+--- a/src/conf/cpu_conf.h
++++ b/src/conf/cpu_conf.h
+@@ -218,4 +218,8 @@ virCPUDefUpdateFeature(virCPUDefPtr cpu,
+                        const char *name,
+                        int policy);
+ 
++virCPUFeatureDefPtr
++virCPUDefFindFeature(virCPUDefPtr def,
++                     const char *name);
++
+ #endif /* __VIR_CPU_CONF_H__ */
+diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
+index 9c596e3f1c..62ebb8180e 100644
+--- a/src/libvirt_private.syms
++++ b/src/libvirt_private.syms
+@@ -74,6 +74,7 @@ virCPUDefCopy;
+ virCPUDefCopyModel;
+ virCPUDefCopyModelFilter;
+ virCPUDefCopyWithoutModel;
++virCPUDefFindFeature;
+ virCPUDefFormat;
+ virCPUDefFormatBuf;
+ virCPUDefFormatBufFull;
+-- 
+2.15.0
+
diff --git a/SOURCES/libvirt-qemu-Filter-CPU-features-when-using-host-CPU.patch b/SOURCES/libvirt-qemu-Filter-CPU-features-when-using-host-CPU.patch
new file mode 100644
index 0000000..49a5404
--- /dev/null
+++ b/SOURCES/libvirt-qemu-Filter-CPU-features-when-using-host-CPU.patch
@@ -0,0 +1,71 @@
+From f05df8ca745a00a1c8bc783dcf25f648cbe5d508 Mon Sep 17 00:00:00 2001
+Message-Id: <f05df8ca745a00a1c8bc783dcf25f648cbe5d508@dist-git>
+From: Jiri Denemark <jdenemar@redhat.com>
+Date: Fri, 6 Oct 2017 13:23:36 +0200
+Subject: [PATCH] qemu: Filter CPU features when using host CPU
+
+When reconnecting to a domain started with a host-model CPU which was
+started by old libvirt that did not replace host-model with the real CPU
+definition, libvirt replaces the host-model CPU with the CPU from
+capabilities (because this is what the old libvirt did when it started
+the domain). Without this patch libvirt could use features unknown to
+QEMU in the CPU definition which replaced the original host-model CPU.
+Such domain would keep running just fine, but any attempt to migrate it
+will fail and once the domain is saved or snapshotted, restoring it
+would fail too.
+
+In other words whenever we want to use the CPU definition from host
+capabilities as a guest CPU definition, we have to filter the unknown
+features.
+
+https://bugzilla.redhat.com/show_bug.cgi?id=1495171
+
+Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
+Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
+(cherry picked from commit e26cc8f82ff346c9ec90409bac06581b64e42b20)
+
+https://bugzilla.redhat.com/show_bug.cgi?id=1508549
+
+Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
+---
+ src/qemu/qemu_process.c | 10 +++++++++-
+ 1 file changed, 9 insertions(+), 1 deletion(-)
+
+diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
+index 4a8c4421a3..0bed084381 100644
+--- a/src/qemu/qemu_process.c
++++ b/src/qemu/qemu_process.c
+@@ -6668,6 +6668,7 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver,
+ {
+     virCapsPtr caps = virQEMUDriverGetCapabilities(driver, false);
+     virCPUDefPtr host = NULL;
++    virCPUDefPtr cpu = NULL;
+     int ret = -1;
+ 
+     if (!caps)
+@@ -6689,7 +6690,13 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver,
+         if (!(host = virCPUCopyMigratable(caps->host.cpu->arch, caps->host.cpu)))
+             goto cleanup;
+ 
+-        if (virCPUUpdate(vm->def->os.arch, vm->def->cpu, host) < 0)
++        if (!(cpu = virCPUDefCopyWithoutModel(host)) ||
++            virCPUDefCopyModelFilter(cpu, host, false,
++                                     virQEMUCapsCPUFilterFeatures,
++                                     &caps->host.cpu->arch) < 0)
++            goto cleanup;
++
++        if (virCPUUpdate(vm->def->os.arch, vm->def->cpu, cpu) < 0)
+             goto cleanup;
+ 
+         if (qemuProcessUpdateCPU(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
+@@ -6699,6 +6706,7 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver,
+     ret = 0;
+ 
+  cleanup:
++    virCPUDefFree(cpu);
+     virCPUDefFree(host);
+     virObjectUnref(caps);
+     return ret;
+-- 
+2.15.0
+
diff --git a/SOURCES/libvirt-qemu-Fix-CPU-model-broken-by-older-libvirt.patch b/SOURCES/libvirt-qemu-Fix-CPU-model-broken-by-older-libvirt.patch
new file mode 100644
index 0000000..a67107f
--- /dev/null
+++ b/SOURCES/libvirt-qemu-Fix-CPU-model-broken-by-older-libvirt.patch
@@ -0,0 +1,194 @@
+From e7f6fc0ea19e73e1ecd9a54f12ac9f2df7cb30cf Mon Sep 17 00:00:00 2001
+Message-Id: <e7f6fc0ea19e73e1ecd9a54f12ac9f2df7cb30cf@dist-git>
+From: Jiri Denemark <jdenemar@redhat.com>
+Date: Fri, 6 Oct 2017 14:49:07 +0200
+Subject: [PATCH] qemu: Fix CPU model broken by older libvirt
+
+When libvirt older than 3.9.0 reconnected to a running domain started by
+old libvirt it could have messed up the expansion of host-model by
+adding features QEMU does not support (such as cmt). Thus whenever we
+reconnect to a running domain, revert to an active snapshot, or restore
+a saved domain we need to check the guest CPU model and remove the
+CPU features unknown to QEMU. We can do this because we know the domain
+was successfully started, which means the CPU did not contain the
+features when libvirt started the domain.
+
+https://bugzilla.redhat.com/show_bug.cgi?id=1495171
+
+Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
+Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
+(cherry picked from commit 6a6f6b91e0e76480ea961f83135efcb4faf3284a)
+
+Conflicts:
+	src/qemu/qemu_domain.c,
+	src/qemu/qemu_domain.h -- context, one more function new
+            function upstream
+
+https://bugzilla.redhat.com/show_bug.cgi?id=1508549
+
+Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
+---
+ src/qemu/qemu_domain.c  | 75 +++++++++++++++++++++++++++++++++++++++++++++++++
+ src/qemu/qemu_domain.h  |  4 +++
+ src/qemu/qemu_driver.c  | 14 +++++++++
+ src/qemu/qemu_process.c |  9 ++++++
+ 4 files changed, 102 insertions(+)
+
+diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
+index a41657099f..68c1f3b7c5 100644
+--- a/src/qemu/qemu_domain.c
++++ b/src/qemu/qemu_domain.c
+@@ -9324,3 +9324,78 @@ qemuDomainUpdateCPU(virDomainObjPtr vm,
+ 
+     return 0;
+ }
++
++
++/**
++ * qemuDomainFixupCPUS:
++ * @vm: domain object
++ * @origCPU: original CPU used when the domain was started
++ *
++ * Libvirt older than 3.9.0 could have messed up the expansion of host-model
++ * CPU when reconnecting to a running domain by adding features QEMU does not
++ * support (such as cmt). This API fixes both the actual CPU provided by QEMU
++ * (stored in the domain object) and the @origCPU used when starting the
++ * domain.
++ *
++ * This is safe even if the original CPU definition used mode='custom' (rather
++ * than host-model) since we know QEMU was able to start the domain and thus
++ * the CPU definitions do not contain any features unknown to QEMU.
++ *
++ * This function can only be used on an active domain or when restoring a
++ * domain which was running.
++ *
++ * Returns 0 on success, -1 on error.
++ */
++int
++qemuDomainFixupCPUs(virDomainObjPtr vm,
++                    virCPUDefPtr *origCPU)
++{
++    virCPUDefPtr fixedCPU = NULL;
++    virCPUDefPtr fixedOrig = NULL;
++    virArch arch = vm->def->os.arch;
++    int ret = 0;
++
++    if (!ARCH_IS_X86(arch))
++        return 0;
++
++    if (!vm->def->cpu ||
++        vm->def->cpu->mode != VIR_CPU_MODE_CUSTOM ||
++        !vm->def->cpu->model)
++        return 0;
++
++    /* Missing origCPU means QEMU created exactly the same virtual CPU which
++     * we asked for or libvirt was too old to mess up the translation from
++     * host-model.
++     */
++    if (!*origCPU)
++        return 0;
++
++    if (virCPUDefFindFeature(vm->def->cpu, "cmt") &&
++        (!(fixedCPU = virCPUDefCopyWithoutModel(vm->def->cpu)) ||
++         virCPUDefCopyModelFilter(fixedCPU, vm->def->cpu, false,
++                                  virQEMUCapsCPUFilterFeatures, &arch) < 0))
++        goto cleanup;
++
++    if (virCPUDefFindFeature(*origCPU, "cmt") &&
++        (!(fixedOrig = virCPUDefCopyWithoutModel(*origCPU)) ||
++         virCPUDefCopyModelFilter(fixedOrig, *origCPU, false,
++                                  virQEMUCapsCPUFilterFeatures, &arch) < 0))
++        goto cleanup;
++
++    if (fixedCPU) {
++        virCPUDefFree(vm->def->cpu);
++        VIR_STEAL_PTR(vm->def->cpu, fixedCPU);
++    }
++
++    if (fixedOrig) {
++        virCPUDefFree(*origCPU);
++        VIR_STEAL_PTR(*origCPU, fixedOrig);
++    }
++
++    ret = 0;
++
++ cleanup:
++    virCPUDefFree(fixedCPU);
++    virCPUDefFree(fixedOrig);
++    return ret;
++}
+diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
+index 7ad34e563e..1a658bcf7e 100644
+--- a/src/qemu/qemu_domain.h
++++ b/src/qemu/qemu_domain.h
+@@ -930,4 +930,8 @@ qemuDomainUpdateCPU(virDomainObjPtr vm,
+                     virCPUDefPtr cpu,
+                     virCPUDefPtr *origCPU);
+ 
++int
++qemuDomainFixupCPUs(virDomainObjPtr vm,
++                    virCPUDefPtr *origCPU);
++
+ #endif /* __QEMU_DOMAIN_H__ */
+diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
+index b6d72303ca..bfd7ff6c09 100644
+--- a/src/qemu/qemu_driver.c
++++ b/src/qemu/qemu_driver.c
+@@ -6500,6 +6500,13 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
+         }
+     }
+ 
++    /* No cookie means libvirt which saved the domain was too old to mess up
++     * the CPU definitions.
++     */
++    if (cookie &&
++        qemuDomainFixupCPUs(vm, &cookie->cpu) < 0)
++        goto cleanup;
++
+     if (qemuProcessStart(conn, driver, vm, cookie ? cookie->cpu : NULL,
+                          asyncJob, "stdio", *fd, path, NULL,
+                          VIR_NETDEV_VPORT_PROFILE_OP_RESTORE,
+@@ -15520,6 +15527,13 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
+             if (config)
+                 virDomainObjAssignDef(vm, config, false, NULL);
+ 
++            /* No cookie means libvirt which saved the domain was too old to
++             * mess up the CPU definitions.
++             */
++            if (cookie &&
++                qemuDomainFixupCPUs(vm, &cookie->cpu) < 0)
++                goto cleanup;
++
+             rc = qemuProcessStart(snapshot->domain->conn, driver, vm,
+                                   cookie ? cookie->cpu : NULL,
+                                   QEMU_ASYNC_JOB_START, NULL, -1, NULL, snap,
+diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
+index 0bed084381..5802a553cf 100644
+--- a/src/qemu/qemu_process.c
++++ b/src/qemu/qemu_process.c
+@@ -6667,6 +6667,7 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver,
+                       virDomainObjPtr vm)
+ {
+     virCapsPtr caps = virQEMUDriverGetCapabilities(driver, false);
++    qemuDomainObjPrivatePtr priv = vm->privateData;
+     virCPUDefPtr host = NULL;
+     virCPUDefPtr cpu = NULL;
+     int ret = -1;
+@@ -6701,6 +6702,14 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver,
+ 
+         if (qemuProcessUpdateCPU(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
+             goto cleanup;
++    } else if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION)) {
++        /* We only try to fix CPUs when the libvirt/QEMU combo used to start
++         * the domain did not know about query-cpu-model-expansion in which
++         * case the host-model is known to not contain features which QEMU
++         * doesn't know about.
++         */
++        if (qemuDomainFixupCPUs(vm, &priv->origCPU) < 0)
++            goto cleanup;
+     }
+ 
+     ret = 0;
+-- 
+2.15.0
+
diff --git a/SOURCES/libvirt-qemu-Pass-virArch-to-virQEMUCapsCPUFilterFeatures.patch b/SOURCES/libvirt-qemu-Pass-virArch-to-virQEMUCapsCPUFilterFeatures.patch
new file mode 100644
index 0000000..9677c31
--- /dev/null
+++ b/SOURCES/libvirt-qemu-Pass-virArch-to-virQEMUCapsCPUFilterFeatures.patch
@@ -0,0 +1,47 @@
+From cd16dea68be92cb8675d0fdd329be2cceb49b580 Mon Sep 17 00:00:00 2001
+Message-Id: <cd16dea68be92cb8675d0fdd329be2cceb49b580@dist-git>
+From: Jiri Denemark <jdenemar@redhat.com>
+Date: Wed, 13 Sep 2017 17:26:07 +0200
+Subject: [PATCH] qemu: Pass virArch * to virQEMUCapsCPUFilterFeatures
+
+The filter only needs to know the CPU architecture. Passing
+virQEMUCapsPtr as opaque is a bit overkill.
+
+Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
+(cherry picked from commit b0b5c9c620bbd6ca806ba39a67516a2d48854132)
+
+https://bugzilla.redhat.com/show_bug.cgi?id=1508549
+
+Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
+---
+ src/qemu/qemu_capabilities.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
+index 6f8b1ac735..3be56462d9 100644
+--- a/src/qemu/qemu_capabilities.c
++++ b/src/qemu/qemu_capabilities.c
+@@ -3239,9 +3239,9 @@ static bool
+ virQEMUCapsCPUFilterFeatures(const char *name,
+                              void *opaque)
+ {
+-    virQEMUCapsPtr qemuCaps = opaque;
++    virArch *arch = opaque;
+ 
+-    if (!ARCH_IS_X86(qemuCaps->arch))
++    if (!ARCH_IS_X86(*arch))
+         return true;
+ 
+     if (STREQ(name, "cmt") ||
+@@ -3453,7 +3453,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
+         if (!hostCPU ||
+             virCPUDefCopyModelFilter(cpu, hostCPU, true,
+                                      virQEMUCapsCPUFilterFeatures,
+-                                     qemuCaps) < 0)
++                                     &qemuCaps->arch) < 0)
+             goto error;
+     } else if (type == VIR_DOMAIN_VIRT_KVM &&
+                virCPUGetHostIsSupported(qemuCaps->arch)) {
+-- 
+2.15.0
+
diff --git a/SOURCES/libvirt-qemu-Publish-virQEMUCapsCPUFilterFeatures.patch b/SOURCES/libvirt-qemu-Publish-virQEMUCapsCPUFilterFeatures.patch
new file mode 100644
index 0000000..6e59334
--- /dev/null
+++ b/SOURCES/libvirt-qemu-Publish-virQEMUCapsCPUFilterFeatures.patch
@@ -0,0 +1,45 @@
+From 382aa0e08d2b12220506ca5522c6035c755e8acf Mon Sep 17 00:00:00 2001
+Message-Id: <382aa0e08d2b12220506ca5522c6035c755e8acf@dist-git>
+From: Jiri Denemark <jdenemar@redhat.com>
+Date: Wed, 13 Sep 2017 17:28:13 +0200
+Subject: [PATCH] qemu: Publish virQEMUCapsCPUFilterFeatures
+
+Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
+(cherry picked from commit 399f91694f6e3245c0f6c8f37968266749964f2d)
+
+https://bugzilla.redhat.com/show_bug.cgi?id=1508549
+
+Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
+---
+ src/qemu/qemu_capabilities.c | 2 +-
+ src/qemu/qemu_capabilities.h | 3 +++
+ 2 files changed, 4 insertions(+), 1 deletion(-)
+
+diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
+index 3be56462d9..a42f8d9988 100644
+--- a/src/qemu/qemu_capabilities.c
++++ b/src/qemu/qemu_capabilities.c
+@@ -3235,7 +3235,7 @@ virQEMUCapsProbeQMPGICCapabilities(virQEMUCapsPtr qemuCaps,
+ }
+ 
+ 
+-static bool
++bool
+ virQEMUCapsCPUFilterFeatures(const char *name,
+                              void *opaque)
+ {
+diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
+index 281fe7d483..bc4ad44496 100644
+--- a/src/qemu/qemu_capabilities.h
++++ b/src/qemu/qemu_capabilities.h
+@@ -573,4 +573,7 @@ int virQEMUCapsFillDomainCaps(virCapsPtr caps,
+ bool virQEMUCapsGuestIsNative(virArch host,
+                               virArch guest);
+ 
++bool virQEMUCapsCPUFilterFeatures(const char *name,
++                                  void *opaque);
++
+ #endif /* __QEMU_CAPABILITIES_H__*/
+-- 
+2.15.0
+
diff --git a/SOURCES/libvirt-qemu-Separate-CPU-updating-code-from-qemuProcessReconnect.patch b/SOURCES/libvirt-qemu-Separate-CPU-updating-code-from-qemuProcessReconnect.patch
new file mode 100644
index 0000000..0d1fd37
--- /dev/null
+++ b/SOURCES/libvirt-qemu-Separate-CPU-updating-code-from-qemuProcessReconnect.patch
@@ -0,0 +1,108 @@
+From 24d641eb1f8cf8b90e1276426c5e7889b7324807 Mon Sep 17 00:00:00 2001
+Message-Id: <24d641eb1f8cf8b90e1276426c5e7889b7324807@dist-git>
+From: Jiri Denemark <jdenemar@redhat.com>
+Date: Fri, 6 Oct 2017 12:57:15 +0200
+Subject: [PATCH] qemu: Separate CPU updating code from qemuProcessReconnect
+
+The new function is called qemuProcessRefreshCPU.
+
+Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
+Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
+(cherry picked from commit 4b87b3675ffd7794542de70da4391f3787ed76a2)
+
+https://bugzilla.redhat.com/show_bug.cgi?id=1508549
+
+Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
+---
+ src/qemu/qemu_process.c | 68 ++++++++++++++++++++++++++++++++-----------------
+ 1 file changed, 45 insertions(+), 23 deletions(-)
+
+diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
+index 8fe9ef36d7..4a8c4421a3 100644
+--- a/src/qemu/qemu_process.c
++++ b/src/qemu/qemu_process.c
+@@ -6662,6 +6662,49 @@ qemuProcessRefreshDisks(virQEMUDriverPtr driver,
+ }
+ 
+ 
++static int
++qemuProcessRefreshCPU(virQEMUDriverPtr driver,
++                      virDomainObjPtr vm)
++{
++    virCapsPtr caps = virQEMUDriverGetCapabilities(driver, false);
++    virCPUDefPtr host = NULL;
++    int ret = -1;
++
++    if (!caps)
++        return -1;
++
++    if (!virQEMUCapsGuestIsNative(caps->host.arch, vm->def->os.arch) ||
++        !caps->host.cpu ||
++        !vm->def->cpu) {
++        ret = 0;
++        goto cleanup;
++    }
++
++    /* If the domain with a host-model CPU was started by an old libvirt
++     * (< 2.3) which didn't replace the CPU with a custom one, let's do it now
++     * since the rest of our code does not really expect a host-model CPU in a
++     * running domain.
++     */
++    if (vm->def->cpu->mode == VIR_CPU_MODE_HOST_MODEL) {
++        if (!(host = virCPUCopyMigratable(caps->host.cpu->arch, caps->host.cpu)))
++            goto cleanup;
++
++        if (virCPUUpdate(vm->def->os.arch, vm->def->cpu, host) < 0)
++            goto cleanup;
++
++        if (qemuProcessUpdateCPU(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
++            goto cleanup;
++    }
++
++    ret = 0;
++
++ cleanup:
++    virCPUDefFree(host);
++    virObjectUnref(caps);
++    return ret;
++}
++
++
+ struct qemuProcessReconnectData {
+     virConnectPtr conn;
+     virQEMUDriverPtr driver;
+@@ -6820,29 +6863,8 @@ qemuProcessReconnect(void *opaque)
+     ignore_value(qemuSecurityCheckAllLabel(driver->securityManager,
+                                            obj->def));
+ 
+-    /* If the domain with a host-model CPU was started by an old libvirt
+-     * (< 2.3) which didn't replace the CPU with a custom one, let's do it now
+-     * since the rest of our code does not really expect a host-model CPU in a
+-     * running domain.
+-     */
+-    if (virQEMUCapsGuestIsNative(caps->host.arch, obj->def->os.arch) &&
+-        caps->host.cpu &&
+-        obj->def->cpu &&
+-        obj->def->cpu->mode == VIR_CPU_MODE_HOST_MODEL) {
+-        virCPUDefPtr host;
+-
+-        if (!(host = virCPUCopyMigratable(caps->host.cpu->arch, caps->host.cpu)))
+-            goto error;
+-
+-        if (virCPUUpdate(obj->def->os.arch, obj->def->cpu, host) < 0) {
+-            virCPUDefFree(host);
+-            goto error;
+-        }
+-        virCPUDefFree(host);
+-
+-        if (qemuProcessUpdateCPU(driver, obj, QEMU_ASYNC_JOB_NONE) < 0)
+-            goto error;
+-    }
++    if (qemuProcessRefreshCPU(driver, obj) < 0)
++        goto error;
+ 
+     if (qemuDomainRefreshVcpuInfo(driver, obj, QEMU_ASYNC_JOB_NONE, true) < 0)
+         goto error;
+-- 
+2.15.0
+
diff --git a/SPECS/libvirt.spec b/SPECS/libvirt.spec
index 0d1221d..73d1f1b 100644
--- a/SPECS/libvirt.spec
+++ b/SPECS/libvirt.spec
@@ -228,7 +228,7 @@
 Summary: Library providing a simple virtualization API
 Name: libvirt
 Version: 3.2.0
-Release: 14%{?dist}.3%{?extra_release}
+Release: 14%{?dist}.4%{?extra_release}
 License: LGPLv2+
 Group: Development/Libraries
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
@@ -482,6 +482,12 @@ Patch239: libvirt-qemu-Update-host-model-CPUs-on-reconnect.patch
 Patch240: libvirt-qemu-Fix-qemuDomainGetBlockInfo-allocation-value-setting.patch
 Patch241: libvirt-qemuDomainBuildNamespace-Handle-special-file-mount-points.patch
 Patch242: libvirt-Add-support-for-virtio-net.tx_queue_size.patch
+Patch243: libvirt-qemu-Pass-virArch-to-virQEMUCapsCPUFilterFeatures.patch
+Patch244: libvirt-qemu-Publish-virQEMUCapsCPUFilterFeatures.patch
+Patch245: libvirt-qemu-Separate-CPU-updating-code-from-qemuProcessReconnect.patch
+Patch246: libvirt-conf-Introduce-virCPUDefFindFeature.patch
+Patch247: libvirt-qemu-Filter-CPU-features-when-using-host-CPU.patch
+Patch248: libvirt-qemu-Fix-CPU-model-broken-by-older-libvirt.patch
 
 Requires: libvirt-daemon = %{version}-%{release}
 Requires: libvirt-daemon-config-network = %{version}-%{release}
@@ -2330,6 +2336,14 @@ exit 0
 
 
 %changelog
+* Mon Nov  6 2017 Jiri Denemark <jdenemar@redhat.com> - 3.2.0-14.el7_4.4
+- qemu: Pass virArch * to virQEMUCapsCPUFilterFeatures (rhbz#1508549)
+- qemu: Publish virQEMUCapsCPUFilterFeatures (rhbz#1508549)
+- qemu: Separate CPU updating code from qemuProcessReconnect (rhbz#1508549)
+- conf: Introduce virCPUDefFindFeature (rhbz#1508549)
+- qemu: Filter CPU features when using host CPU (rhbz#1508549)
+- qemu: Fix CPU model broken by older libvirt (rhbz#1508549)
+
 * Tue Aug 22 2017 Jiri Denemark <jdenemar@redhat.com> - 3.2.0-14.el7_4.3
 - Add support for virtio-net.tx_queue_size (rhbz#1482514)