Merge ~paelzer/ubuntu/+source/qemu:lp-1867519-stabilize-4.2 into ubuntu/+source/qemu:ubuntu/focal-devel

Proposed by Christian Ehrhardt 
Status: Merged
Merge reported by: Christian Ehrhardt 
Merged at revision: 9f5874b0fa11c6738c4629273527d8b216f297e3
Proposed branch: ~paelzer/ubuntu/+source/qemu:lp-1867519-stabilize-4.2
Merge into: ubuntu/+source/qemu:ubuntu/focal-devel
Diff against target: 3765 lines (+3470/-0)
43 files modified
debian/changelog (+21/-0)
debian/patches/lp-1867519-block-nbd-extract-the-common-cleanup-code.patch (+78/-0)
debian/patches/series (+38/-0)
debian/patches/stable/lp-1867519-arm-arm-powerctl-rebuild-hflags-after-setting-CP15-b.patch (+48/-0)
debian/patches/stable/lp-1867519-arm-arm-powerctl-set-NSACR.-CP11-CP10-bits-in-arm_se.patch (+49/-0)
debian/patches/stable/lp-1867519-backup-top-Begin-drain-earlier.patch (+46/-0)
debian/patches/stable/lp-1867519-block-Activate-recursively-even-for-already-active-n.patch (+108/-0)
debian/patches/stable/lp-1867519-block-backup-top-fix-failure-path.patch (+97/-0)
debian/patches/stable/lp-1867519-block-block-copy-fix-progress-calculation.patch (+201/-0)
debian/patches/stable/lp-1867519-block-fix-crash-on-zero-length-unaligned-write-and-r.patch (+107/-0)
debian/patches/stable/lp-1867519-block-io-fix-bdrv_co_do_copy_on_readv.patch (+44/-0)
debian/patches/stable/lp-1867519-block-nbd-fix-memory-leak-in-nbd_open.patch (+76/-0)
debian/patches/stable/lp-1867519-block-qcow2-threads-fix-qcow2_decompress.patch (+79/-0)
debian/patches/stable/lp-1867519-hw-i386-pc-fix-regression-in-parsing-vga-cmdline-par.patch (+58/-0)
debian/patches/stable/lp-1867519-intel_iommu-a-fix-to-vtd_find_as_from_bus_num.patch (+44/-0)
debian/patches/stable/lp-1867519-intel_iommu-add-present-bit-check-for-pasid-table-en.patch (+202/-0)
debian/patches/stable/lp-1867519-iotests-add-test-for-backup-top-failure-on-permissio.patch (+138/-0)
debian/patches/stable/lp-1867519-job-refactor-progress-to-separate-object.patch (+230/-0)
debian/patches/stable/lp-1867519-plugins-core-add-missing-break-in-cb_to_tcg_flags.patch (+41/-0)
debian/patches/stable/lp-1867519-qcow2-Fix-alloc_cluster_abort-for-pre-existing-clust.patch (+39/-0)
debian/patches/stable/lp-1867519-qcow2-Fix-qcow2_alloc_cluster_abort-for-external-dat.patch (+44/-0)
debian/patches/stable/lp-1867519-qcow2-bitmaps-fix-qcow2_can_store_new_dirty_bitmap.patch (+102/-0)
debian/patches/stable/lp-1867519-qemu-img-Fix-convert-n-B-for-backing-less-targets.patch (+54/-0)
debian/patches/stable/lp-1867519-s390-sclp-improve-special-wait-psw-logic.patch (+40/-0)
debian/patches/stable/lp-1867519-target-arm-Return-correct-IL-bit-in-merge_syn_data_a.patch (+46/-0)
debian/patches/stable/lp-1867519-target-arm-Set-ISSIs16Bit-in-make_issinfo.patch (+42/-0)
debian/patches/stable/lp-1867519-target-arm-arm-semi-fix-SYS_OPEN-to-return-nonzero-f.patch (+79/-0)
debian/patches/stable/lp-1867519-target-arm-ensure-we-use-current-exception-state-aft.patch (+127/-0)
debian/patches/stable/lp-1867519-target-i386-kvm-initialize-feature-MSRs-very-early.patch (+169/-0)
debian/patches/stable/lp-1867519-tcg-save-vaddr-temp-for-plugin-usage.patch (+98/-0)
debian/patches/stable/lp-1867519-tpm-ppi-page-align-PPI-RAM.patch (+47/-0)
debian/patches/stable/lp-1867519-vfio-pci-Don-t-remove-irqchip-notifier-if-not-regist.patch (+50/-0)
debian/patches/stable/lp-1867519-virtio-gracefully-handle-invalid-region-caches.patch (+331/-0)
debian/patches/stable/lp-1867519-virtio-mmio-update-queue-size-on-guest-write.patch (+40/-0)
debian/patches/stable/lp-1867519-virtio-net-delete-also-control-queue-when-TX-RX-dele.patch (+41/-0)
debian/patches/stable/lp-1867519-virtio-update-queue-size-on-guest-write.patch (+40/-0)
debian/patches/ubuntu/lp-1847361-modules-load-upgrade.patch (+125/-0)
debian/patches/ubuntu/lp-1847361-vhost-correctly-turn-on-VIRTIO_F_IOMMU_PLATFORM.patch (+61/-0)
debian/qemu-block-extra.postrm.in (+43/-0)
debian/qemu-block-extra.prerm.in (+45/-0)
debian/qemu-system-gui.postrm.in (+44/-0)
debian/qemu-system-gui.prerm.in (+46/-0)
debian/rules (+12/-0)
Reviewer Review Type Date Requested Status
Andreas Hasenack Approve
Canonical Server Pending
git-ubuntu developers Pending
Review via email: mp+380874@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

We know qemu had git-ubuntu import errors recently.
Probably it is best to just look at my proposed branch - that has a proper upload/1%4.2-3ubuntu2 in history and this MP is only for the coming upload/1%4.2-3ubuntu3.

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Holy 33 patches, batman :)

I wonder if qemu shouldn't do more point releases, more often :)

+1 from a packaging viewpoint, and I don't think this warrants an FFe.

review: Approve
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Thanks I did some quick checks (given it is only minor fixes).
But we accrued enough changes that after the next coming known big qmeu change I'll do a full virt-regression-test again ...

To ssh://git.launchpad.net/~usd-import-team/ubuntu/+source/qemu
 * [new tag] upload/1%4.2-3ubuntu3 -> upload/1%4.2-3ubuntu3

Uploading to ubuntu (via ftp to upload.ubuntu.com):
  Uploading qemu_4.2-3ubuntu3.dsc: done.
  Uploading qemu_4.2-3ubuntu3.debian.tar.xz: done.
  Uploading qemu_4.2-3ubuntu3_source.buildinfo: done.
  Uploading qemu_4.2-3ubuntu3_source.changes: done.
Successfully uploaded packages.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/debian/changelog b/debian/changelog
index 89089bb..11efbaa 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,24 @@
1qemu (1:4.2-3ubuntu3) focal; urgency=medium
2
3 * d/p/stable/lp-1867519-*: Stabilize qemu 4.2 with upstream
4 patches @qemu-stable (LP: #1867519)
5
6 -- Christian Ehrhardt <christian.ehrhardt@canonical.com> Wed, 18 Mar 2020 13:57:57 +0100
7
8qemu (1:4.2-3ubuntu2) focal; urgency=medium
9
10 * allow qemu to load old modules post upgrade (LP: #1847361)
11 - d/p/ubuntu/lp-1847361-modules-load-upgrade.patch: to fallback module
12 load to a versioned path
13 - d/qemu-block-extra.*.in, d/qemu-system-gui.*.in: save shared objects on
14 upgrade
15 - d/rules: generate maintainer scripts matching package version on build
16 - d/rules: enable --enable-module-upgrades where --enable-modules is set
17 * d/p/ubuntu/lp-1847361-vhost-correctly-turn-on-VIRTIO_F_IOMMU_PLATFORM.patch:
18 avoid unnecessary IOTLB transactions (LP: #1866207)
19
20 -- Christian Ehrhardt <christian.ehrhardt@canonical.com> Mon, 02 Mar 2020 15:21:27 +0100
21
1qemu (1:4.2-3ubuntu1) focal; urgency=medium22qemu (1:4.2-3ubuntu1) focal; urgency=medium
223
3 * Merge with Debian testing, remaining changes:24 * Merge with Debian testing, remaining changes:
diff --git a/debian/patches/lp-1867519-block-nbd-extract-the-common-cleanup-code.patch b/debian/patches/lp-1867519-block-nbd-extract-the-common-cleanup-code.patch
4new file mode 10064425new file mode 100644
index 0000000..8dc2409
--- /dev/null
+++ b/debian/patches/lp-1867519-block-nbd-extract-the-common-cleanup-code.patch
@@ -0,0 +1,78 @@
1From 7f493662be4045146a8f45119d8834c9088a0ad6 Mon Sep 17 00:00:00 2001
2From: Pan Nengyuan <pannengyuan@huawei.com>
3Date: Thu, 5 Dec 2019 11:45:27 +0800
4Subject: [PATCH] block/nbd: extract the common cleanup code
5
6The BDRVNBDState cleanup code is common in two places, add
7nbd_clear_bdrvstate() function to do these cleanups.
8
9Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
10Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
11Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
12Message-Id: <1575517528-44312-2-git-send-email-pannengyuan@huawei.com>
13Reviewed-by: Eric Blake <eblake@redhat.com>
14[eblake: fix compilation error and commit message]
15Signed-off-by: Eric Blake <eblake@redhat.com>
16
17Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=7f493662be4045146a8f45119d8834c9088a0ad6
18Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
19Last-Update: 2020-03-18
20
21---
22 block/nbd.c | 26 +++++++++++++++-----------
23 1 file changed, 15 insertions(+), 11 deletions(-)
24
25diff --git a/block/nbd.c b/block/nbd.c
26index f69e61e68a..ed0f93ab27 100644
27--- a/block/nbd.c
28+++ b/block/nbd.c
29@@ -95,6 +95,19 @@ typedef struct BDRVNBDState {
30
31 static int nbd_client_connect(BlockDriverState *bs, Error **errp);
32
33+static void nbd_clear_bdrvstate(BDRVNBDState *s)
34+{
35+ object_unref(OBJECT(s->tlscreds));
36+ qapi_free_SocketAddress(s->saddr);
37+ s->saddr = NULL;
38+ g_free(s->export);
39+ s->export = NULL;
40+ g_free(s->tlscredsid);
41+ s->tlscredsid = NULL;
42+ g_free(s->x_dirty_bitmap);
43+ s->x_dirty_bitmap = NULL;
44+}
45+
46 static void nbd_channel_error(BDRVNBDState *s, int ret)
47 {
48 if (ret == -EIO) {
49@@ -1879,11 +1892,7 @@ static int nbd_process_options(BlockDriverState *bs, QDict *options,
50
51 error:
52 if (ret < 0) {
53- object_unref(OBJECT(s->tlscreds));
54- qapi_free_SocketAddress(s->saddr);
55- g_free(s->export);
56- g_free(s->tlscredsid);
57- g_free(s->x_dirty_bitmap);
58+ nbd_clear_bdrvstate(s);
59 }
60 qemu_opts_del(opts);
61 return ret;
62@@ -1962,12 +1971,7 @@ static void nbd_close(BlockDriverState *bs)
63 BDRVNBDState *s = bs->opaque;
64
65 nbd_client_close(bs);
66-
67- object_unref(OBJECT(s->tlscreds));
68- qapi_free_SocketAddress(s->saddr);
69- g_free(s->export);
70- g_free(s->tlscredsid);
71- g_free(s->x_dirty_bitmap);
72+ nbd_clear_bdrvstate(s);
73 }
74
75 static int64_t nbd_getlength(BlockDriverState *bs)
76--
772.25.1
78
diff --git a/debian/patches/series b/debian/patches/series
index c9fce99..f01fa16 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -13,3 +13,41 @@ ubuntu/lp-1857033-i386-Add-macro-for-stibp.patch
13ubuntu/lp-1857033-i386-Add-new-CPU-model-Cooperlake.patch13ubuntu/lp-1857033-i386-Add-new-CPU-model-Cooperlake.patch
14lp-1859527-virtio-blk-fix-out-of-bounds-access-to-bitmap-in-not.patch14lp-1859527-virtio-blk-fix-out-of-bounds-access-to-bitmap-in-not.patch
15ubuntu/vhost-user-gpu-Drop-trailing-json-comma.patch15ubuntu/vhost-user-gpu-Drop-trailing-json-comma.patch
16ubuntu/lp-1847361-modules-load-upgrade.patch
17ubuntu/lp-1847361-vhost-correctly-turn-on-VIRTIO_F_IOMMU_PLATFORM.patch
18
19# stabilize 4.2 with patches sent to qemu-stable since 4.2 released
20stable/lp-1867519-arm-arm-powerctl-set-NSACR.-CP11-CP10-bits-in-arm_se.patch
21stable/lp-1867519-target-arm-ensure-we-use-current-exception-state-aft.patch
22stable/lp-1867519-block-Activate-recursively-even-for-already-active-n.patch
23stable/lp-1867519-arm-arm-powerctl-rebuild-hflags-after-setting-CP15-b.patch
24stable/lp-1867519-virtio-update-queue-size-on-guest-write.patch
25stable/lp-1867519-qcow2-bitmaps-fix-qcow2_can_store_new_dirty_bitmap.patch
26stable/lp-1867519-backup-top-Begin-drain-earlier.patch
27stable/lp-1867519-virtio-mmio-update-queue-size-on-guest-write.patch
28stable/lp-1867519-virtio-net-delete-also-control-queue-when-TX-RX-dele.patch
29stable/lp-1867519-intel_iommu-a-fix-to-vtd_find_as_from_bus_num.patch
30stable/lp-1867519-intel_iommu-add-present-bit-check-for-pasid-table-en.patch
31stable/lp-1867519-vfio-pci-Don-t-remove-irqchip-notifier-if-not-regist.patch
32stable/lp-1867519-hw-i386-pc-fix-regression-in-parsing-vga-cmdline-par.patch
33stable/lp-1867519-target-arm-arm-semi-fix-SYS_OPEN-to-return-nonzero-f.patch
34stable/lp-1867519-target-arm-Return-correct-IL-bit-in-merge_syn_data_a.patch
35stable/lp-1867519-target-arm-Set-ISSIs16Bit-in-make_issinfo.patch
36stable/lp-1867519-target-i386-kvm-initialize-feature-MSRs-very-early.patch
37stable/lp-1867519-tpm-ppi-page-align-PPI-RAM.patch
38stable/lp-1867519-block-backup-top-fix-failure-path.patch
39stable/lp-1867519-iotests-add-test-for-backup-top-failure-on-permissio.patch
40stable/lp-1867519-block-fix-crash-on-zero-length-unaligned-write-and-r.patch
41stable/lp-1867519-qemu-img-Fix-convert-n-B-for-backing-less-targets.patch
42stable/lp-1867519-plugins-core-add-missing-break-in-cb_to_tcg_flags.patch
43stable/lp-1867519-tcg-save-vaddr-temp-for-plugin-usage.patch
44stable/lp-1867519-s390-sclp-improve-special-wait-psw-logic.patch
45stable/lp-1867519-block-nbd-fix-memory-leak-in-nbd_open.patch
46stable/lp-1867519-virtio-gracefully-handle-invalid-region-caches.patch
47stable/lp-1867519-qcow2-Fix-qcow2_alloc_cluster_abort-for-external-dat.patch
48stable/lp-1867519-qcow2-Fix-alloc_cluster_abort-for-pre-existing-clust.patch
49stable/lp-1867519-block-qcow2-threads-fix-qcow2_decompress.patch
50stable/lp-1867519-job-refactor-progress-to-separate-object.patch
51stable/lp-1867519-block-block-copy-fix-progress-calculation.patch
52stable/lp-1867519-block-io-fix-bdrv_co_do_copy_on_readv.patch
53lp-1867519-block-nbd-extract-the-common-cleanup-code.patch
diff --git a/debian/patches/stable/lp-1867519-arm-arm-powerctl-rebuild-hflags-after-setting-CP15-b.patch b/debian/patches/stable/lp-1867519-arm-arm-powerctl-rebuild-hflags-after-setting-CP15-b.patch
16new file mode 10064454new file mode 100644
index 0000000..c980ed6
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-arm-arm-powerctl-rebuild-hflags-after-setting-CP15-b.patch
@@ -0,0 +1,48 @@
1From c8fa6079eb35888587f1be27c1590da4edcc5098 Mon Sep 17 00:00:00 2001
2From: Niek Linnenbank <nieklinnenbank@gmail.com>
3Date: Fri, 20 Dec 2019 14:03:00 +0000
4Subject: [PATCH] arm/arm-powerctl: rebuild hflags after setting CP15 bits in
5 arm_set_cpu_on()
6
7After setting CP15 bits in arm_set_cpu_on() the cached hflags must
8be rebuild to reflect the changed processor state. Without rebuilding,
9the cached hflags would be inconsistent until the next call to
10arm_rebuild_hflags(). When QEMU is compiled with debugging enabled
11(--enable-debug), this problem is captured shortly after the first
12call to arm_set_cpu_on() for CPUs running in ARM 32-bit non-secure mode:
13
14 qemu-system-arm: target/arm/helper.c:11359: cpu_get_tb_cpu_state:
15 Assertion `flags == rebuild_hflags_internal(env)' failed.
16 Aborted (core dumped)
17
18Fixes: 0c7f8c43daf65
19Cc: qemu-stable@nongnu.org
20Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
21Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
22Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
24Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=c8fa6079eb35888587f1be27c1590da4edcc5098
25Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
26Last-Update: 2020-03-18
27
28---
29 target/arm/arm-powerctl.c | 3 +++
30 1 file changed, 3 insertions(+)
31
32diff --git a/target/arm/arm-powerctl.c b/target/arm/arm-powerctl.c
33index b064513d44..b75f813b40 100644
34--- a/target/arm/arm-powerctl.c
35+++ b/target/arm/arm-powerctl.c
36@@ -127,6 +127,9 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state,
37 target_cpu->env.regs[0] = info->context_id;
38 }
39
40+ /* CP15 update requires rebuilding hflags */
41+ arm_rebuild_hflags(&target_cpu->env);
42+
43 /* Start the new CPU at the requested address */
44 cpu_set_pc(target_cpu_state, info->entry);
45
46--
472.25.1
48
diff --git a/debian/patches/stable/lp-1867519-arm-arm-powerctl-set-NSACR.-CP11-CP10-bits-in-arm_se.patch b/debian/patches/stable/lp-1867519-arm-arm-powerctl-set-NSACR.-CP11-CP10-bits-in-arm_se.patch
0new file mode 10064449new file mode 100644
index 0000000..b2fa47c
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-arm-arm-powerctl-set-NSACR.-CP11-CP10-bits-in-arm_se.patch
@@ -0,0 +1,49 @@
1From 0c7f8c43daf6556078e51de98aa13f069e505985 Mon Sep 17 00:00:00 2001
2From: Niek Linnenbank <nieklinnenbank@gmail.com>
3Date: Mon, 2 Dec 2019 22:09:43 +0100
4Subject: [PATCH] arm/arm-powerctl: set NSACR.{CP11, CP10} bits in
5 arm_set_cpu_on()
6
7This change ensures that the FPU can be accessed in Non-Secure mode
8when the CPU core is reset using the arm_set_cpu_on() function call.
9The NSACR.{CP11,CP10} bits define the exception level required to
10access the FPU in Non-Secure mode. Without these bits set, the CPU
11will give an undefined exception trap on the first FPU access for the
12secondary cores under Linux.
13
14This is necessary because in this power-control codepath QEMU
15is effectively emulating a bit of EL3 firmware, and has to set
16the CPU up as the EL3 firmware would.
17
18Fixes: fc1120a7f5
19Cc: qemu-stable@nongnu.org
20Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
21[PMM: added clarifying para to commit message]
22Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
23Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
24
25Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=0c7f8c43daf6556078e51de98aa13f069e505985
26Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
27Last-Update: 2020-03-18
28
29---
30 target/arm/arm-powerctl.c | 3 +++
31 1 file changed, 3 insertions(+)
32
33diff --git a/target/arm/arm-powerctl.c b/target/arm/arm-powerctl.c
34index f77a950db6..b064513d44 100644
35--- a/target/arm/arm-powerctl.c
36+++ b/target/arm/arm-powerctl.c
37@@ -104,6 +104,9 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state,
38 /* Processor is not in secure mode */
39 target_cpu->env.cp15.scr_el3 |= SCR_NS;
40
41+ /* Set NSACR.{CP11,CP10} so NS can access the FPU */
42+ target_cpu->env.cp15.nsacr |= 3 << 10;
43+
44 /*
45 * If QEMU is providing the equivalent of EL3 firmware, then we need
46 * to make sure a CPU targeting EL2 comes out of reset with a
47--
482.25.1
49
diff --git a/debian/patches/stable/lp-1867519-backup-top-Begin-drain-earlier.patch b/debian/patches/stable/lp-1867519-backup-top-Begin-drain-earlier.patch
0new file mode 10064450new file mode 100644
index 0000000..d534297
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-backup-top-Begin-drain-earlier.patch
@@ -0,0 +1,46 @@
1From 503ca1262bab2c11c533a4816d1ff4297d4f58a6 Mon Sep 17 00:00:00 2001
2From: Max Reitz <mreitz@redhat.com>
3Date: Thu, 19 Dec 2019 19:26:38 +0100
4Subject: [PATCH] backup-top: Begin drain earlier
5
6When dropping backup-top, we need to drain the node before freeing the
7BlockCopyState. Otherwise, requests may still be in flight and then the
8assertion in shres_destroy() will fail.
9
10(This becomes visible in intermittent failure of 056.)
11
12Cc: qemu-stable@nongnu.org
13Signed-off-by: Max Reitz <mreitz@redhat.com>
14Message-id: 20191219182638.104621-1-mreitz@redhat.com
15Signed-off-by: Max Reitz <mreitz@redhat.com>
16
17Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=503ca1262bab2c11c533a4816d1ff4297d4f58a6
18Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
19Last-Update: 2020-03-18
20
21---
22 block/backup-top.c | 4 ++--
23 1 file changed, 2 insertions(+), 2 deletions(-)
24
25diff --git a/block/backup-top.c b/block/backup-top.c
26index 7cdb1f8eba..818d3f26b4 100644
27--- a/block/backup-top.c
28+++ b/block/backup-top.c
29@@ -257,12 +257,12 @@ void bdrv_backup_top_drop(BlockDriverState *bs)
30 BDRVBackupTopState *s = bs->opaque;
31 AioContext *aio_context = bdrv_get_aio_context(bs);
32
33- block_copy_state_free(s->bcs);
34-
35 aio_context_acquire(aio_context);
36
37 bdrv_drained_begin(bs);
38
39+ block_copy_state_free(s->bcs);
40+
41 s->active = false;
42 bdrv_child_refresh_perms(bs, bs->backing, &error_abort);
43 bdrv_replace_node(bs, backing_bs(bs), &error_abort);
44--
452.25.1
46
diff --git a/debian/patches/stable/lp-1867519-block-Activate-recursively-even-for-already-active-n.patch b/debian/patches/stable/lp-1867519-block-Activate-recursively-even-for-already-active-n.patch
0new file mode 10064447new file mode 100644
index 0000000..0a9d490
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-block-Activate-recursively-even-for-already-active-n.patch
@@ -0,0 +1,108 @@
1From 7bb4941ace471fc7dd6ded4749b95b9622baa6ed Mon Sep 17 00:00:00 2001
2From: Kevin Wolf <kwolf@redhat.com>
3Date: Tue, 17 Dec 2019 15:06:38 +0100
4Subject: [PATCH] block: Activate recursively even for already active nodes
5
6bdrv_invalidate_cache_all() assumes that all nodes in a given subtree
7are either active or inactive when it starts. Therefore, as soon as it
8arrives at an already active node, it stops.
9
10However, this assumption is wrong. For example, it's possible to take a
11snapshot of an inactive node, which results in an active overlay over an
12inactive backing file. The active overlay is probably also the root node
13of an inactive BlockBackend (blk->disable_perm == true).
14
15In this case, bdrv_invalidate_cache_all() does not need to do anything
16to activate the overlay node, but it still needs to recurse into the
17children and the parents to make sure that after returning success,
18really everything is activated.
19
20Cc: qemu-stable@nongnu.org
21Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22Reviewed-by: Max Reitz <mreitz@redhat.com>
23
24Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=7bb4941ace471fc7dd6ded4749b95b9622baa6ed
25Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
26Last-Update: 2020-03-18
27
28---
29 block.c | 50 ++++++++++++++++++++++++--------------------------
30 1 file changed, 24 insertions(+), 26 deletions(-)
31
32diff --git a/block.c b/block.c
33index 73029fad64..1b6f7c86e8 100644
34--- a/block.c
35+++ b/block.c
36@@ -5335,10 +5335,6 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
37 return;
38 }
39
40- if (!(bs->open_flags & BDRV_O_INACTIVE)) {
41- return;
42- }
43-
44 QLIST_FOREACH(child, &bs->children, next) {
45 bdrv_co_invalidate_cache(child->bs, &local_err);
46 if (local_err) {
47@@ -5360,34 +5356,36 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
48 * just keep the extended permissions for the next time that an activation
49 * of the image is tried.
50 */
51- bs->open_flags &= ~BDRV_O_INACTIVE;
52- bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
53- ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, &local_err);
54- if (ret < 0) {
55- bs->open_flags |= BDRV_O_INACTIVE;
56- error_propagate(errp, local_err);
57- return;
58- }
59- bdrv_set_perm(bs, perm, shared_perm);
60-
61- if (bs->drv->bdrv_co_invalidate_cache) {
62- bs->drv->bdrv_co_invalidate_cache(bs, &local_err);
63- if (local_err) {
64+ if (bs->open_flags & BDRV_O_INACTIVE) {
65+ bs->open_flags &= ~BDRV_O_INACTIVE;
66+ bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
67+ ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, &local_err);
68+ if (ret < 0) {
69 bs->open_flags |= BDRV_O_INACTIVE;
70 error_propagate(errp, local_err);
71 return;
72 }
73- }
74+ bdrv_set_perm(bs, perm, shared_perm);
75
76- FOR_EACH_DIRTY_BITMAP(bs, bm) {
77- bdrv_dirty_bitmap_skip_store(bm, false);
78- }
79+ if (bs->drv->bdrv_co_invalidate_cache) {
80+ bs->drv->bdrv_co_invalidate_cache(bs, &local_err);
81+ if (local_err) {
82+ bs->open_flags |= BDRV_O_INACTIVE;
83+ error_propagate(errp, local_err);
84+ return;
85+ }
86+ }
87
88- ret = refresh_total_sectors(bs, bs->total_sectors);
89- if (ret < 0) {
90- bs->open_flags |= BDRV_O_INACTIVE;
91- error_setg_errno(errp, -ret, "Could not refresh total sector count");
92- return;
93+ FOR_EACH_DIRTY_BITMAP(bs, bm) {
94+ bdrv_dirty_bitmap_skip_store(bm, false);
95+ }
96+
97+ ret = refresh_total_sectors(bs, bs->total_sectors);
98+ if (ret < 0) {
99+ bs->open_flags |= BDRV_O_INACTIVE;
100+ error_setg_errno(errp, -ret, "Could not refresh total sector count");
101+ return;
102+ }
103 }
104
105 QLIST_FOREACH(parent, &bs->parents, next_parent) {
106--
1072.25.1
108
diff --git a/debian/patches/stable/lp-1867519-block-backup-top-fix-failure-path.patch b/debian/patches/stable/lp-1867519-block-backup-top-fix-failure-path.patch
0new file mode 100644109new file mode 100644
index 0000000..0ea91e8
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-block-backup-top-fix-failure-path.patch
@@ -0,0 +1,97 @@
1From 0df62f45c1de6c020f1e6fba4eeafd248209b003 Mon Sep 17 00:00:00 2001
2From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
3Date: Tue, 21 Jan 2020 17:28:01 +0300
4Subject: [PATCH] block/backup-top: fix failure path
5
6We can't access top after call bdrv_backup_top_drop, as it is already
7freed at this time.
8
9Also, no needs to unref target child by hand, it will be unrefed on
10bdrv_close() automatically.
11
12So, just do bdrv_backup_top_drop if append succeed and one bdrv_unref
13otherwise.
14
15Note, that in !appended case bdrv_unref(top) moved into drained section
16on source. It doesn't really matter, but just for code simplicity.
17
18Fixes: 7df7868b96404
19Cc: qemu-stable@nongnu.org # v4.2.0
20Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
21Reviewed-by: Max Reitz <mreitz@redhat.com>
22Message-id: 20200121142802.21467-2-vsementsov@virtuozzo.com
23Signed-off-by: Max Reitz <mreitz@redhat.com>
24
25Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=0df62f45c1de6c020f1e6fba4eeafd248209b003
26Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
27Last-Update: 2020-03-18
28
29---
30 block/backup-top.c | 21 ++++++++++++---------
31 1 file changed, 12 insertions(+), 9 deletions(-)
32
33diff --git a/block/backup-top.c b/block/backup-top.c
34index 9aed2eb4c0..fa78f3256d 100644
35--- a/block/backup-top.c
36+++ b/block/backup-top.c
37@@ -190,6 +190,7 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,
38 BlockDriverState *top = bdrv_new_open_driver(&bdrv_backup_top_filter,
39 filter_node_name,
40 BDRV_O_RDWR, errp);
41+ bool appended = false;
42
43 if (!top) {
44 return NULL;
45@@ -212,8 +213,9 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,
46 bdrv_append(top, source, &local_err);
47 if (local_err) {
48 error_prepend(&local_err, "Cannot append backup-top filter: ");
49- goto append_failed;
50+ goto fail;
51 }
52+ appended = true;
53
54 /*
55 * bdrv_append() finished successfully, now we can require permissions
56@@ -224,14 +226,14 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,
57 if (local_err) {
58 error_prepend(&local_err,
59 "Cannot set permissions for backup-top filter: ");
60- goto failed_after_append;
61+ goto fail;
62 }
63
64 state->bcs = block_copy_state_new(top->backing, state->target,
65 cluster_size, write_flags, &local_err);
66 if (local_err) {
67 error_prepend(&local_err, "Cannot create block-copy-state: ");
68- goto failed_after_append;
69+ goto fail;
70 }
71 *bcs = state->bcs;
72
73@@ -239,14 +241,15 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,
74
75 return top;
76
77-failed_after_append:
78- state->active = false;
79- bdrv_backup_top_drop(top);
80+fail:
81+ if (appended) {
82+ state->active = false;
83+ bdrv_backup_top_drop(top);
84+ } else {
85+ bdrv_unref(top);
86+ }
87
88-append_failed:
89 bdrv_drained_end(source);
90- bdrv_unref_child(top, state->target);
91- bdrv_unref(top);
92 error_propagate(errp, local_err);
93
94 return NULL;
95--
962.25.1
97
diff --git a/debian/patches/stable/lp-1867519-block-block-copy-fix-progress-calculation.patch b/debian/patches/stable/lp-1867519-block-block-copy-fix-progress-calculation.patch
0new file mode 10064498new file mode 100644
index 0000000..6eb7652
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-block-block-copy-fix-progress-calculation.patch
@@ -0,0 +1,201 @@
1From d0ebeca14a585f352938062ef8ddde47fe4d39f9 Mon Sep 17 00:00:00 2001
2From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
3Date: Wed, 11 Mar 2020 13:29:57 +0300
4Subject: [PATCH] block/block-copy: fix progress calculation
5
6Assume we have two regions, A and B, and region B is in-flight now,
7region A is not yet touched, but it is unallocated and should be
8skipped.
9
10Correspondingly, as progress we have
11
12 total = A + B
13 current = 0
14
15If we reset unallocated region A and call progress_reset_callback,
16it will calculate 0 bytes dirty in the bitmap and call
17job_progress_set_remaining, which will set
18
19 total = current + 0 = 0 + 0 = 0
20
21So, B bytes are actually removed from total accounting. When job
22finishes we'll have
23
24 total = 0
25 current = B
26
27, which doesn't sound good.
28
29This is because we didn't considered in-flight bytes, actually when
30calculating remaining, we should have set (in_flight + dirty_bytes)
31as remaining, not only dirty_bytes.
32
33To fix it, let's refactor progress calculation, moving it to block-copy
34itself instead of fixing callback. And, of course, track in_flight
35bytes count.
36
37We still have to keep one callback, to maintain backup job bytes_read
38calculation, but it will go on soon, when we turn the whole backup
39process into one block_copy call.
40
41Cc: qemu-stable@nongnu.org
42Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
43Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
44Message-Id: <20200311103004.7649-3-vsementsov@virtuozzo.com>
45Signed-off-by: Max Reitz <mreitz@redhat.com>
46
47Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=d0ebeca14a585f352938062ef8ddde47fe4d39f9
48Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
49Last-Update: 2020-03-18
50
51---
52 block/backup.c | 13 ++-----------
53 block/block-copy.c | 16 ++++++++++++----
54 include/block/block-copy.h | 15 +++++----------
55 3 files changed, 19 insertions(+), 25 deletions(-)
56
57diff --git a/block/backup.c b/block/backup.c
58index 1383e219f5..8694e0394b 100644
59--- a/block/backup.c
60+++ b/block/backup.c
61@@ -57,15 +57,6 @@ static void backup_progress_bytes_callback(int64_t bytes, void *opaque)
62 BackupBlockJob *s = opaque;
63
64 s->bytes_read += bytes;
65- job_progress_update(&s->common.job, bytes);
66-}
67-
68-static void backup_progress_reset_callback(void *opaque)
69-{
70- BackupBlockJob *s = opaque;
71- uint64_t estimate = bdrv_get_dirty_count(s->bcs->copy_bitmap);
72-
73- job_progress_set_remaining(&s->common.job, estimate);
74 }
75
76 static int coroutine_fn backup_do_cow(BackupBlockJob *job,
77@@ -464,8 +455,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
78 job->cluster_size = cluster_size;
79 job->len = len;
80
81- block_copy_set_callbacks(bcs, backup_progress_bytes_callback,
82- backup_progress_reset_callback, job);
83+ block_copy_set_progress_callback(bcs, backup_progress_bytes_callback, job);
84+ block_copy_set_progress_meter(bcs, &job->common.job.progress);
85
86 /* Required permissions are already taken by backup-top target */
87 block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL,
88diff --git a/block/block-copy.c b/block/block-copy.c
89index 79798a1567..e2d7b3b887 100644
90--- a/block/block-copy.c
91+++ b/block/block-copy.c
92@@ -127,17 +127,20 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
93 return s;
94 }
95
96-void block_copy_set_callbacks(
97+void block_copy_set_progress_callback(
98 BlockCopyState *s,
99 ProgressBytesCallbackFunc progress_bytes_callback,
100- ProgressResetCallbackFunc progress_reset_callback,
101 void *progress_opaque)
102 {
103 s->progress_bytes_callback = progress_bytes_callback;
104- s->progress_reset_callback = progress_reset_callback;
105 s->progress_opaque = progress_opaque;
106 }
107
108+void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm)
109+{
110+ s->progress = pm;
111+}
112+
113 /*
114 * block_copy_do_copy
115 *
116@@ -269,7 +272,9 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s,
117
118 if (!ret) {
119 bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes);
120- s->progress_reset_callback(s->progress_opaque);
121+ progress_set_remaining(s->progress,
122+ bdrv_get_dirty_count(s->copy_bitmap) +
123+ s->in_flight_bytes);
124 }
125
126 *count = bytes;
127@@ -331,15 +336,18 @@ int coroutine_fn block_copy(BlockCopyState *s,
128 trace_block_copy_process(s, start);
129
130 bdrv_reset_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
131+ s->in_flight_bytes += chunk_end - start;
132
133 co_get_from_shres(s->mem, chunk_end - start);
134 ret = block_copy_do_copy(s, start, chunk_end, error_is_read);
135 co_put_to_shres(s->mem, chunk_end - start);
136+ s->in_flight_bytes -= chunk_end - start;
137 if (ret < 0) {
138 bdrv_set_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
139 break;
140 }
141
142+ progress_work_done(s->progress, chunk_end - start);
143 s->progress_bytes_callback(chunk_end - start, s->progress_opaque);
144 start = chunk_end;
145 ret = 0;
146diff --git a/include/block/block-copy.h b/include/block/block-copy.h
147index 0a161724d7..9def00068c 100644
148--- a/include/block/block-copy.h
149+++ b/include/block/block-copy.h
150@@ -26,7 +26,6 @@ typedef struct BlockCopyInFlightReq {
151 } BlockCopyInFlightReq;
152
153 typedef void (*ProgressBytesCallbackFunc)(int64_t bytes, void *opaque);
154-typedef void (*ProgressResetCallbackFunc)(void *opaque);
155 typedef struct BlockCopyState {
156 /*
157 * BdrvChild objects are not owned or managed by block-copy. They are
158@@ -36,6 +35,7 @@ typedef struct BlockCopyState {
159 BdrvChild *source;
160 BdrvChild *target;
161 BdrvDirtyBitmap *copy_bitmap;
162+ int64_t in_flight_bytes;
163 int64_t cluster_size;
164 bool use_copy_range;
165 int64_t copy_size;
166@@ -60,15 +60,9 @@ typedef struct BlockCopyState {
167 */
168 bool skip_unallocated;
169
170+ ProgressMeter *progress;
171 /* progress_bytes_callback: called when some copying progress is done. */
172 ProgressBytesCallbackFunc progress_bytes_callback;
173-
174- /*
175- * progress_reset_callback: called when some bytes reset from copy_bitmap
176- * (see @skip_unallocated above). The callee is assumed to recalculate how
177- * many bytes remain based on the dirty bit count of copy_bitmap.
178- */
179- ProgressResetCallbackFunc progress_reset_callback;
180 void *progress_opaque;
181
182 SharedResource *mem;
183@@ -79,12 +73,13 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
184 BdrvRequestFlags write_flags,
185 Error **errp);
186
187-void block_copy_set_callbacks(
188+void block_copy_set_progress_callback(
189 BlockCopyState *s,
190 ProgressBytesCallbackFunc progress_bytes_callback,
191- ProgressResetCallbackFunc progress_reset_callback,
192 void *progress_opaque);
193
194+void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm);
195+
196 void block_copy_state_free(BlockCopyState *s);
197
198 int64_t block_copy_reset_unallocated(BlockCopyState *s,
199--
2002.25.1
201
diff --git a/debian/patches/stable/lp-1867519-block-fix-crash-on-zero-length-unaligned-write-and-r.patch b/debian/patches/stable/lp-1867519-block-fix-crash-on-zero-length-unaligned-write-and-r.patch
0new file mode 100644202new file mode 100644
index 0000000..a84fdd7
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-block-fix-crash-on-zero-length-unaligned-write-and-r.patch
@@ -0,0 +1,107 @@
1From ac9d00bf7b47acae6b0e42910d9ed55fef3af5b8 Mon Sep 17 00:00:00 2001
2From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
3Date: Thu, 6 Feb 2020 19:42:45 +0300
4Subject: [PATCH] block: fix crash on zero-length unaligned write and read
5
6Commit 7a3f542fbd "block/io: refactor padding" occasionally dropped
7aligning for zero-length request: bdrv_init_padding() blindly return
8false if bytes == 0, like there is nothing to align.
9
10This leads the following command to crash:
11
12./qemu-io --image-opts -c 'write 1 0' \
13 driver=blkdebug,align=512,image.driver=null-co,image.size=512
14
15>> qemu-io: block/io.c:1955: bdrv_aligned_pwritev: Assertion
16 `(offset & (align - 1)) == 0' failed.
17>> Aborted (core dumped)
18
19Prior to 7a3f542fbd we does aligning of such zero requests. Instead of
20recovering this behavior let's just do nothing on such requests as it
21is useless.
22
23Note that driver may have special meaning of zero-length reqeusts, like
24qcow2_co_pwritev_compressed_part, so we can't skip any zero-length
25operation. But for unaligned ones, we can't pass it to driver anyway.
26
27This commit also fixes crash in iotest 80 running with -nocache:
28
29./check -nocache -qcow2 80
30
31which crashes on same assertion due to trying to read empty extra data
32in qcow2_do_read_snapshots().
33
34Cc: qemu-stable@nongnu.org # v4.2
35Fixes: 7a3f542fbd
36Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
37Reviewed-by: Max Reitz <mreitz@redhat.com>
38Message-id: 20200206164245.17781-1-vsementsov@virtuozzo.com
39Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
40
41Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=ac9d00bf7b47acae6b0e42910d9ed55fef3af5b8
42Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
43Last-Update: 2020-03-18
44
45---
46 block/io.c | 28 +++++++++++++++++++++++++++-
47 1 file changed, 27 insertions(+), 1 deletion(-)
48
49diff --git a/block/io.c b/block/io.c
50index 1eb2b2bddc..7e4cb74cf4 100644
51--- a/block/io.c
52+++ b/block/io.c
53@@ -1565,10 +1565,12 @@ static bool bdrv_init_padding(BlockDriverState *bs,
54 pad->tail = align - pad->tail;
55 }
56
57- if ((!pad->head && !pad->tail) || !bytes) {
58+ if (!pad->head && !pad->tail) {
59 return false;
60 }
61
62+ assert(bytes); /* Nothing good in aligning zero-length requests */
63+
64 sum = pad->head + bytes + pad->tail;
65 pad->buf_len = (sum > align && pad->head && pad->tail) ? 2 * align : align;
66 pad->buf = qemu_blockalign(bs, pad->buf_len);
67@@ -1706,6 +1708,18 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child,
68 return ret;
69 }
70
71+ if (bytes == 0 && !QEMU_IS_ALIGNED(offset, bs->bl.request_alignment)) {
72+ /*
73+ * Aligning zero request is nonsense. Even if driver has special meaning
74+ * of zero-length (like qcow2_co_pwritev_compressed_part), we can't pass
75+ * it to driver due to request_alignment.
76+ *
77+ * Still, no reason to return an error if someone do unaligned
78+ * zero-length read occasionally.
79+ */
80+ return 0;
81+ }
82+
83 bdrv_inc_in_flight(bs);
84
85 /* Don't do copy-on-read if we read data before write operation */
86@@ -2116,6 +2130,18 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child,
87 return -ENOTSUP;
88 }
89
90+ if (bytes == 0 && !QEMU_IS_ALIGNED(offset, bs->bl.request_alignment)) {
91+ /*
92+ * Aligning zero request is nonsense. Even if driver has special meaning
93+ * of zero-length (like qcow2_co_pwritev_compressed_part), we can't pass
94+ * it to driver due to request_alignment.
95+ *
96+ * Still, no reason to return an error if someone do unaligned
97+ * zero-length write occasionally.
98+ */
99+ return 0;
100+ }
101+
102 bdrv_inc_in_flight(bs);
103 /*
104 * Align write if necessary by performing a read-modify-write cycle.
105--
1062.25.1
107
diff --git a/debian/patches/stable/lp-1867519-block-io-fix-bdrv_co_do_copy_on_readv.patch b/debian/patches/stable/lp-1867519-block-io-fix-bdrv_co_do_copy_on_readv.patch
0new file mode 100644108new file mode 100644
index 0000000..84335eb
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-block-io-fix-bdrv_co_do_copy_on_readv.patch
@@ -0,0 +1,44 @@
1From 4ab78b19189a81038e744728ed949d09aa477550 Mon Sep 17 00:00:00 2001
2From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
3Date: Thu, 12 Mar 2020 11:19:49 +0300
4Subject: [PATCH] block/io: fix bdrv_co_do_copy_on_readv
5
6Prior to 1143ec5ebf4 it was OK to qemu_iovec_from_buf() from aligned-up
7buffer to original qiov, as qemu_iovec_from_buf() will stop at qiov end
8anyway.
9
10But after 1143ec5ebf4 we assume that bdrv_co_do_copy_on_readv works on
11part of original qiov, defined by qiov_offset and bytes. So we must not
12touch qiov behind qiov_offset+bytes bound. Fix it.
13
14Cc: qemu-stable@nongnu.org # v4.2
15Fixes: 1143ec5ebf4
16Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
17Reviewed-by: John Snow <jsnow@redhat.com>
18Message-id: 20200312081949.5350-1-vsementsov@virtuozzo.com
19Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
20
21Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=4ab78b19189a81038e744728ed949d09aa477550
22Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
23Last-Update: 2020-03-18
24
25---
26 block/io.c | 2 +-
27 1 file changed, 1 insertion(+), 1 deletion(-)
28
29diff --git a/block/io.c b/block/io.c
30index 7e4cb74cf4..aba67f66b9 100644
31--- a/block/io.c
32+++ b/block/io.c
33@@ -1399,7 +1399,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
34 if (!(flags & BDRV_REQ_PREFETCH)) {
35 qemu_iovec_from_buf(qiov, qiov_offset + progress,
36 bounce_buffer + skip_bytes,
37- pnum - skip_bytes);
38+ MIN(pnum - skip_bytes, bytes - progress));
39 }
40 } else if (!(flags & BDRV_REQ_PREFETCH)) {
41 /* Read directly into the destination */
42--
432.25.1
44
diff --git a/debian/patches/stable/lp-1867519-block-nbd-fix-memory-leak-in-nbd_open.patch b/debian/patches/stable/lp-1867519-block-nbd-fix-memory-leak-in-nbd_open.patch
0new file mode 10064445new file mode 100644
index 0000000..dde008d
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-block-nbd-fix-memory-leak-in-nbd_open.patch
@@ -0,0 +1,76 @@
1From 8198cf5ef0ef98118b4176970d1cd998d93ec849 Mon Sep 17 00:00:00 2001
2From: Pan Nengyuan <pannengyuan@huawei.com>
3Date: Thu, 5 Dec 2019 11:45:28 +0800
4Subject: [PATCH] block/nbd: fix memory leak in nbd_open()
5
6In currently implementation there will be a memory leak when
7nbd_client_connect() returns error status. Here is an easy way to
8reproduce:
9
101. run qemu-iotests as follow and check the result with asan:
11 ./check -raw 143
12
13Following is the asan output backtrack:
14Direct leak of 40 byte(s) in 1 object(s) allocated from:
15 #0 0x7f629688a560 in calloc (/usr/lib64/libasan.so.3+0xc7560)
16 #1 0x7f6295e7e015 in g_malloc0 (/usr/lib64/libglib-2.0.so.0+0x50015)
17 #2 0x56281dab4642 in qobject_input_start_struct /mnt/sdb/qemu-4.2.0-rc0/qapi/qobject-input-visitor.c:295
18 #3 0x56281dab1a04 in visit_start_struct /mnt/sdb/qemu-4.2.0-rc0/qapi/qapi-visit-core.c:49
19 #4 0x56281dad1827 in visit_type_SocketAddress qapi/qapi-visit-sockets.c:386
20 #5 0x56281da8062f in nbd_config /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1716
21 #6 0x56281da8062f in nbd_process_options /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1829
22 #7 0x56281da8062f in nbd_open /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1873
23
24Direct leak of 15 byte(s) in 1 object(s) allocated from:
25 #0 0x7f629688a3a0 in malloc (/usr/lib64/libasan.so.3+0xc73a0)
26 #1 0x7f6295e7dfbd in g_malloc (/usr/lib64/libglib-2.0.so.0+0x4ffbd)
27 #2 0x7f6295e96ace in g_strdup (/usr/lib64/libglib-2.0.so.0+0x68ace)
28 #3 0x56281da804ac in nbd_process_options /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1834
29 #4 0x56281da804ac in nbd_open /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1873
30
31Indirect leak of 24 byte(s) in 1 object(s) allocated from:
32 #0 0x7f629688a3a0 in malloc (/usr/lib64/libasan.so.3+0xc73a0)
33 #1 0x7f6295e7dfbd in g_malloc (/usr/lib64/libglib-2.0.so.0+0x4ffbd)
34 #2 0x7f6295e96ace in g_strdup (/usr/lib64/libglib-2.0.so.0+0x68ace)
35 #3 0x56281dab41a3 in qobject_input_type_str_keyval /mnt/sdb/qemu-4.2.0-rc0/qapi/qobject-input-visitor.c:536
36 #4 0x56281dab2ee9 in visit_type_str /mnt/sdb/qemu-4.2.0-rc0/qapi/qapi-visit-core.c:297
37 #5 0x56281dad0fa1 in visit_type_UnixSocketAddress_members qapi/qapi-visit-sockets.c:141
38 #6 0x56281dad17b6 in visit_type_SocketAddress_members qapi/qapi-visit-sockets.c:366
39 #7 0x56281dad186a in visit_type_SocketAddress qapi/qapi-visit-sockets.c:393
40 #8 0x56281da8062f in nbd_config /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1716
41 #9 0x56281da8062f in nbd_process_options /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1829
42 #10 0x56281da8062f in nbd_open /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1873
43
44Fixes: 8f071c9db506e03ab
45Reported-by: Euler Robot <euler.robot@huawei.com>
46Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
47Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
48Cc: qemu-stable <qemu-stable@nongnu.org>
49Cc: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
50Message-Id: <1575517528-44312-3-git-send-email-pannengyuan@huawei.com>
51Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
52Signed-off-by: Eric Blake <eblake@redhat.com>
53
54Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=8198cf5ef0ef98118b4176970d1cd998d93ec849
55Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
56Last-Update: 2020-03-18
57
58---
59 block/nbd.c | 1 +
60 1 file changed, 1 insertion(+)
61
62diff --git a/block/nbd.c b/block/nbd.c
63index ed0f93ab27..976be76647 100644
64--- a/block/nbd.c
65+++ b/block/nbd.c
66@@ -1915,6 +1915,7 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
67
68 ret = nbd_client_connect(bs, errp);
69 if (ret < 0) {
70+ nbd_clear_bdrvstate(s);
71 return ret;
72 }
73 /* successfully connected */
74--
752.25.1
76
diff --git a/debian/patches/stable/lp-1867519-block-qcow2-threads-fix-qcow2_decompress.patch b/debian/patches/stable/lp-1867519-block-qcow2-threads-fix-qcow2_decompress.patch
0new file mode 10064477new file mode 100644
index 0000000..bf4169e
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-block-qcow2-threads-fix-qcow2_decompress.patch
@@ -0,0 +1,79 @@
1From e7266570f2cf7b3ca2a156c677ee0a59d563458b Mon Sep 17 00:00:00 2001
2From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
3Date: Mon, 2 Mar 2020 18:09:30 +0300
4Subject: [PATCH] block/qcow2-threads: fix qcow2_decompress
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9On success path we return what inflate() returns instead of 0. And it
10most probably works for Z_STREAM_END as it is positive, but is
11definitely broken for Z_BUF_ERROR.
12
13While being here, switch to errno return code, to be closer to
14qcow2_compress API (and usual expectations).
15
16Revert condition in if to be more positive. Drop dead initialization of
17ret.
18
19Cc: qemu-stable@nongnu.org # v4.0
20Fixes: 341926ab83e2b
21Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
22Message-Id: <20200302150930.16218-1-vsementsov@virtuozzo.com>
23Reviewed-by: Alberto Garcia <berto@igalia.com>
24Reviewed-by: Ján Tomko <jtomko@redhat.com>
25Signed-off-by: Max Reitz <mreitz@redhat.com>
26
27Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=e7266570f2cf7b3ca2a156c677ee0a59d563458b
28Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
29Last-Update: 2020-03-18
30
31---
32 block/qcow2-threads.c | 12 +++++++-----
33 1 file changed, 7 insertions(+), 5 deletions(-)
34
35diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c
36index 77bb578cdf..a68126f291 100644
37--- a/block/qcow2-threads.c
38+++ b/block/qcow2-threads.c
39@@ -128,12 +128,12 @@ static ssize_t qcow2_compress(void *dest, size_t dest_size,
40 * @src - source buffer, @src_size bytes
41 *
42 * Returns: 0 on success
43- * -1 on fail
44+ * -EIO on fail
45 */
46 static ssize_t qcow2_decompress(void *dest, size_t dest_size,
47 const void *src, size_t src_size)
48 {
49- int ret = 0;
50+ int ret;
51 z_stream strm;
52
53 memset(&strm, 0, sizeof(strm));
54@@ -144,17 +144,19 @@ static ssize_t qcow2_decompress(void *dest, size_t dest_size,
55
56 ret = inflateInit2(&strm, -12);
57 if (ret != Z_OK) {
58- return -1;
59+ return -EIO;
60 }
61
62 ret = inflate(&strm, Z_FINISH);
63- if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) || strm.avail_out != 0) {
64+ if ((ret == Z_STREAM_END || ret == Z_BUF_ERROR) && strm.avail_out == 0) {
65 /*
66 * We approve Z_BUF_ERROR because we need @dest buffer to be filled, but
67 * @src buffer may be processed partly (because in qcow2 we know size of
68 * compressed data with precision of one sector)
69 */
70- ret = -1;
71+ ret = 0;
72+ } else {
73+ ret = -EIO;
74 }
75
76 inflateEnd(&strm);
77--
782.25.1
79
diff --git a/debian/patches/stable/lp-1867519-hw-i386-pc-fix-regression-in-parsing-vga-cmdline-par.patch b/debian/patches/stable/lp-1867519-hw-i386-pc-fix-regression-in-parsing-vga-cmdline-par.patch
0new file mode 10064480new file mode 100644
index 0000000..c6aa3a3
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-hw-i386-pc-fix-regression-in-parsing-vga-cmdline-par.patch
@@ -0,0 +1,58 @@
1From a88c40f02ace88f09b2a85a64831b277b2ebc88c Mon Sep 17 00:00:00 2001
2From: Peter Wu <peter@lekensteyn.nl>
3Date: Sat, 21 Dec 2019 17:21:24 +0100
4Subject: [PATCH] hw/i386/pc: fix regression in parsing vga cmdline parameter
5
6When the 'vga=' parameter is succeeded by another parameter, QEMU 4.2.0
7would refuse to start with a rather cryptic message:
8
9 $ qemu-system-x86_64 -kernel /boot/vmlinuz-linux -append 'vga=792 quiet'
10 qemu: can't parse 'vga' parameter: Invalid argument
11
12It was not clear whether this applied to the '-vga std' parameter or the
13'-append' one. Fix the parsing regression and clarify the error.
14
15Fixes: 133ef074bd ("hw/i386/pc: replace use of strtol with qemu_strtoui in x86_load_linux()")
16Cc: Sergio Lopez <slp@redhat.com>
17Signed-off-by: Peter Wu <peter@lekensteyn.nl>
18Message-Id: <20191221162124.1159291-1-peter@lekensteyn.nl>
19Cc: qemu-stable@nongnu.org
20Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
21
22Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=a88c40f02ace88f09b2a85a64831b277b2ebc88c
23Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
24Last-Update: 2020-03-18
25
26---
27 hw/i386/x86.c | 8 ++++----
28 1 file changed, 4 insertions(+), 4 deletions(-)
29
30diff --git a/hw/i386/x86.c b/hw/i386/x86.c
31index d8bb5c2a96..9b9a4d5837 100644
32--- a/hw/i386/x86.c
33+++ b/hw/i386/x86.c
34@@ -612,6 +612,7 @@ void x86_load_linux(X86MachineState *x86ms,
35 vmode = strstr(kernel_cmdline, "vga=");
36 if (vmode) {
37 unsigned int video_mode;
38+ const char *end;
39 int ret;
40 /* skip "vga=" */
41 vmode += 4;
42@@ -622,10 +623,9 @@ void x86_load_linux(X86MachineState *x86ms,
43 } else if (!strncmp(vmode, "ask", 3)) {
44 video_mode = 0xfffd;
45 } else {
46- ret = qemu_strtoui(vmode, NULL, 0, &video_mode);
47- if (ret != 0) {
48- fprintf(stderr, "qemu: can't parse 'vga' parameter: %s\n",
49- strerror(-ret));
50+ ret = qemu_strtoui(vmode, &end, 0, &video_mode);
51+ if (ret != 0 || (*end && *end != ' ')) {
52+ fprintf(stderr, "qemu: invalid 'vga=' kernel parameter.\n");
53 exit(1);
54 }
55 }
56--
572.25.1
58
diff --git a/debian/patches/stable/lp-1867519-intel_iommu-a-fix-to-vtd_find_as_from_bus_num.patch b/debian/patches/stable/lp-1867519-intel_iommu-a-fix-to-vtd_find_as_from_bus_num.patch
0new file mode 10064459new file mode 100644
index 0000000..4d13d20
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-intel_iommu-a-fix-to-vtd_find_as_from_bus_num.patch
@@ -0,0 +1,44 @@
1From a2e1cd41ccfe796529abfd1b6aeb1dd4393762a2 Mon Sep 17 00:00:00 2001
2From: Liu Yi L <yi.l.liu@intel.com>
3Date: Fri, 3 Jan 2020 21:28:05 +0800
4Subject: [PATCH] intel_iommu: a fix to vtd_find_as_from_bus_num()
5
6Ensure the return value of vtd_find_as_from_bus_num() is NULL by
7enforcing vtd_bus=NULL. This would help caller of vtd_find_as_from_bus_num()
8to decide if any further operation on the returned vtd_bus.
9
10Cc: qemu-stable@nongnu.org
11Cc: Kevin Tian <kevin.tian@intel.com>
12Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
13Cc: Peter Xu <peterx@redhat.com>
14Cc: Yi Sun <yi.y.sun@linux.intel.com>
15Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
16Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
17Message-Id: <1578058086-4288-2-git-send-email-yi.l.liu@intel.com>
18Reviewed-by: Peter Xu <peterx@redhat.com>
19Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
20Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
21
22Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=a2e1cd41ccfe796529abfd1b6aeb1dd4393762a2
23Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
24Last-Update: 2020-03-18
25
26---
27 hw/i386/intel_iommu.c | 1 +
28 1 file changed, 1 insertion(+)
29
30diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
31index ee06993675..609b80750a 100644
32--- a/hw/i386/intel_iommu.c
33+++ b/hw/i386/intel_iommu.c
34@@ -948,6 +948,7 @@ static VTDBus *vtd_find_as_from_bus_num(IntelIOMMUState *s, uint8_t bus_num)
35 return vtd_bus;
36 }
37 }
38+ vtd_bus = NULL;
39 }
40 return vtd_bus;
41 }
42--
432.25.1
44
diff --git a/debian/patches/stable/lp-1867519-intel_iommu-add-present-bit-check-for-pasid-table-en.patch b/debian/patches/stable/lp-1867519-intel_iommu-add-present-bit-check-for-pasid-table-en.patch
0new file mode 10064445new file mode 100644
index 0000000..02548a2
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-intel_iommu-add-present-bit-check-for-pasid-table-en.patch
@@ -0,0 +1,202 @@
1From 56fc1e6ac6bde95bc0369d358587f2234d4dddad Mon Sep 17 00:00:00 2001
2From: Liu Yi L <yi.l.liu@intel.com>
3Date: Fri, 3 Jan 2020 21:28:06 +0800
4Subject: [PATCH] intel_iommu: add present bit check for pasid table entries
5
6The present bit check for pasid entry (pe) and pasid directory
7entry (pdire) were missed in previous commits as fpd bit check
8doesn't require present bit as "Set". This patch adds the present
9bit check for callers which wants to get a valid pe/pdire.
10
11Cc: qemu-stable@nongnu.org
12Cc: Kevin Tian <kevin.tian@intel.com>
13Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
14Cc: Peter Xu <peterx@redhat.com>
15Cc: Yi Sun <yi.y.sun@linux.intel.com>
16Reviewed-by: Peter Xu <peterx@redhat.com>
17Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
18Message-Id: <1578058086-4288-3-git-send-email-yi.l.liu@intel.com>
19Reviewed-by: Peter Xu <peterx@redhat.com>
20Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
21Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
22
23Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=56fc1e6ac6bde95bc0369d358587f2234d4dddad
24Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
25Last-Update: 2020-03-18
26
27---
28 hw/i386/intel_iommu.c | 92 +++++++++++++++++++++++++++-------
29 hw/i386/intel_iommu_internal.h | 1 +
30 2 files changed, 74 insertions(+), 19 deletions(-)
31
32diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
33index 609b80750a..a523ef0e65 100644
34--- a/hw/i386/intel_iommu.c
35+++ b/hw/i386/intel_iommu.c
36@@ -686,9 +686,18 @@ static inline bool vtd_pe_type_check(X86IOMMUState *x86_iommu,
37 return true;
38 }
39
40-static int vtd_get_pasid_dire(dma_addr_t pasid_dir_base,
41- uint32_t pasid,
42- VTDPASIDDirEntry *pdire)
43+static inline bool vtd_pdire_present(VTDPASIDDirEntry *pdire)
44+{
45+ return pdire->val & 1;
46+}
47+
48+/**
49+ * Caller of this function should check present bit if wants
50+ * to use pdir entry for futher usage except for fpd bit check.
51+ */
52+static int vtd_get_pdire_from_pdir_table(dma_addr_t pasid_dir_base,
53+ uint32_t pasid,
54+ VTDPASIDDirEntry *pdire)
55 {
56 uint32_t index;
57 dma_addr_t addr, entry_size;
58@@ -703,18 +712,22 @@ static int vtd_get_pasid_dire(dma_addr_t pasid_dir_base,
59 return 0;
60 }
61
62-static int vtd_get_pasid_entry(IntelIOMMUState *s,
63- uint32_t pasid,
64- VTDPASIDDirEntry *pdire,
65- VTDPASIDEntry *pe)
66+static inline bool vtd_pe_present(VTDPASIDEntry *pe)
67+{
68+ return pe->val[0] & VTD_PASID_ENTRY_P;
69+}
70+
71+static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUState *s,
72+ uint32_t pasid,
73+ dma_addr_t addr,
74+ VTDPASIDEntry *pe)
75 {
76 uint32_t index;
77- dma_addr_t addr, entry_size;
78+ dma_addr_t entry_size;
79 X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s);
80
81 index = VTD_PASID_TABLE_INDEX(pasid);
82 entry_size = VTD_PASID_ENTRY_SIZE;
83- addr = pdire->val & VTD_PASID_TABLE_BASE_ADDR_MASK;
84 addr = addr + index * entry_size;
85 if (dma_memory_read(&address_space_memory, addr, pe, entry_size)) {
86 return -VTD_FR_PASID_TABLE_INV;
87@@ -732,25 +745,54 @@ static int vtd_get_pasid_entry(IntelIOMMUState *s,
88 return 0;
89 }
90
91-static int vtd_get_pasid_entry_from_pasid(IntelIOMMUState *s,
92- dma_addr_t pasid_dir_base,
93- uint32_t pasid,
94- VTDPASIDEntry *pe)
95+/**
96+ * Caller of this function should check present bit if wants
97+ * to use pasid entry for futher usage except for fpd bit check.
98+ */
99+static int vtd_get_pe_from_pdire(IntelIOMMUState *s,
100+ uint32_t pasid,
101+ VTDPASIDDirEntry *pdire,
102+ VTDPASIDEntry *pe)
103+{
104+ dma_addr_t addr = pdire->val & VTD_PASID_TABLE_BASE_ADDR_MASK;
105+
106+ return vtd_get_pe_in_pasid_leaf_table(s, pasid, addr, pe);
107+}
108+
109+/**
110+ * This function gets a pasid entry from a specified pasid
111+ * table (includes dir and leaf table) with a specified pasid.
112+ * Sanity check should be done to ensure return a present
113+ * pasid entry to caller.
114+ */
115+static int vtd_get_pe_from_pasid_table(IntelIOMMUState *s,
116+ dma_addr_t pasid_dir_base,
117+ uint32_t pasid,
118+ VTDPASIDEntry *pe)
119 {
120 int ret;
121 VTDPASIDDirEntry pdire;
122
123- ret = vtd_get_pasid_dire(pasid_dir_base, pasid, &pdire);
124+ ret = vtd_get_pdire_from_pdir_table(pasid_dir_base,
125+ pasid, &pdire);
126 if (ret) {
127 return ret;
128 }
129
130- ret = vtd_get_pasid_entry(s, pasid, &pdire, pe);
131+ if (!vtd_pdire_present(&pdire)) {
132+ return -VTD_FR_PASID_TABLE_INV;
133+ }
134+
135+ ret = vtd_get_pe_from_pdire(s, pasid, &pdire, pe);
136 if (ret) {
137 return ret;
138 }
139
140- return ret;
141+ if (!vtd_pe_present(pe)) {
142+ return -VTD_FR_PASID_TABLE_INV;
143+ }
144+
145+ return 0;
146 }
147
148 static int vtd_ce_get_rid2pasid_entry(IntelIOMMUState *s,
149@@ -763,7 +805,7 @@ static int vtd_ce_get_rid2pasid_entry(IntelIOMMUState *s,
150
151 pasid = VTD_CE_GET_RID2PASID(ce);
152 pasid_dir_base = VTD_CE_GET_PASID_DIR_TABLE(ce);
153- ret = vtd_get_pasid_entry_from_pasid(s, pasid_dir_base, pasid, pe);
154+ ret = vtd_get_pe_from_pasid_table(s, pasid_dir_base, pasid, pe);
155
156 return ret;
157 }
158@@ -781,7 +823,11 @@ static int vtd_ce_get_pasid_fpd(IntelIOMMUState *s,
159 pasid = VTD_CE_GET_RID2PASID(ce);
160 pasid_dir_base = VTD_CE_GET_PASID_DIR_TABLE(ce);
161
162- ret = vtd_get_pasid_dire(pasid_dir_base, pasid, &pdire);
163+ /*
164+ * No present bit check since fpd is meaningful even
165+ * if the present bit is clear.
166+ */
167+ ret = vtd_get_pdire_from_pdir_table(pasid_dir_base, pasid, &pdire);
168 if (ret) {
169 return ret;
170 }
171@@ -791,7 +837,15 @@ static int vtd_ce_get_pasid_fpd(IntelIOMMUState *s,
172 return 0;
173 }
174
175- ret = vtd_get_pasid_entry(s, pasid, &pdire, &pe);
176+ if (!vtd_pdire_present(&pdire)) {
177+ return -VTD_FR_PASID_TABLE_INV;
178+ }
179+
180+ /*
181+ * No present bit check since fpd is meaningful even
182+ * if the present bit is clear.
183+ */
184+ ret = vtd_get_pe_from_pdire(s, pasid, &pdire, &pe);
185 if (ret) {
186 return ret;
187 }
188diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h
189index edcf9fc9bb..862033ebe6 100644
190--- a/hw/i386/intel_iommu_internal.h
191+++ b/hw/i386/intel_iommu_internal.h
192@@ -479,6 +479,7 @@ typedef struct VTDRootEntry VTDRootEntry;
193 #define VTD_PASID_ENTRY_FPD (1ULL << 1) /* Fault Processing Disable */
194
195 /* PASID Granular Translation Type Mask */
196+#define VTD_PASID_ENTRY_P 1ULL
197 #define VTD_SM_PASID_ENTRY_PGTT (7ULL << 6)
198 #define VTD_SM_PASID_ENTRY_FLT (1ULL << 6)
199 #define VTD_SM_PASID_ENTRY_SLT (2ULL << 6)
200--
2012.25.1
202
diff --git a/debian/patches/stable/lp-1867519-iotests-add-test-for-backup-top-failure-on-permissio.patch b/debian/patches/stable/lp-1867519-iotests-add-test-for-backup-top-failure-on-permissio.patch
0new file mode 100644203new file mode 100644
index 0000000..790c5d4
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-iotests-add-test-for-backup-top-failure-on-permissio.patch
@@ -0,0 +1,138 @@
1From a541fcc27c98b96da187c7d4573f3270f3ddd283 Mon Sep 17 00:00:00 2001
2From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
3Date: Tue, 21 Jan 2020 17:28:02 +0300
4Subject: [PATCH] iotests: add test for backup-top failure on permission
5 activation
6
7This test checks that bug is really fixed by previous commit.
8
9Cc: qemu-stable@nongnu.org # v4.2.0
10Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
11Message-id: 20200121142802.21467-3-vsementsov@virtuozzo.com
12Signed-off-by: Max Reitz <mreitz@redhat.com>
13
14Origin: backport, https://git.qemu.org/?p=qemu.git;a=commit;h=a541fcc27c98b96da187c7d4573f3270f3ddd283
15Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
16Last-Update: 2020-03-18
17
18---
19 tests/qemu-iotests/283 | 92 ++++++++++++++++++++++++++++++++++++++
20 tests/qemu-iotests/283.out | 8 ++++
21 tests/qemu-iotests/group | 1 +
22 3 files changed, 101 insertions(+)
23 create mode 100644 tests/qemu-iotests/283
24 create mode 100644 tests/qemu-iotests/283.out
25
26--- /dev/null
27+++ b/tests/qemu-iotests/283
28@@ -0,0 +1,92 @@
29+#!/usr/bin/env python
30+#
31+# Test for backup-top filter permission activation failure
32+#
33+# Copyright (c) 2019 Virtuozzo International GmbH.
34+#
35+# This program is free software; you can redistribute it and/or modify
36+# it under the terms of the GNU General Public License as published by
37+# the Free Software Foundation; either version 2 of the License, or
38+# (at your option) any later version.
39+#
40+# This program is distributed in the hope that it will be useful,
41+# but WITHOUT ANY WARRANTY; without even the implied warranty of
42+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43+# GNU General Public License for more details.
44+#
45+# You should have received a copy of the GNU General Public License
46+# along with this program. If not, see <http://www.gnu.org/licenses/>.
47+#
48+
49+import iotests
50+
51+# The test is unrelated to formats, restrict it to qcow2 to avoid extra runs
52+iotests.verify_image_format(supported_fmts=['qcow2'])
53+
54+size = 1024 * 1024
55+
56+""" Test description
57+
58+When performing a backup, all writes on the source subtree must go through the
59+backup-top filter so it can copy all data to the target before it is changed.
60+backup-top filter is appended above source node, to achieve this thing, so all
61+parents of source node are handled. A configuration with side parents of source
62+sub-tree with write permission is unsupported (we'd have append several
63+backup-top filter like nodes to handle such parents). The test create an
64+example of such configuration and checks that a backup is then not allowed
65+(blockdev-backup command should fail).
66+
67+The configuration:
68+
69+ ┌────────┐ target ┌─────────────┐
70+ │ target │ ◀─────── │ backup_top │
71+ └────────┘ └─────────────┘
72+ │
73+ │ backing
74+ ▼
75+ ┌─────────────┐
76+ │ source │
77+ └─────────────┘
78+ │
79+ │ file
80+ ▼
81+ ┌─────────────┐ write perm ┌───────┐
82+ │ base │ ◀──────────── │ other │
83+ └─────────────┘ └───────┘
84+
85+On activation (see .active field of backup-top state in block/backup-top.c),
86+backup-top is going to unshare write permission on its source child. Write
87+unsharing will be propagated to the "source->base" link and will conflict with
88+other node write permission. So permission update will fail and backup job will
89+not be started.
90+
91+Note, that the only thing which prevents backup of running on such
92+configuration is default permission propagation scheme. It may be altered by
93+different block drivers, so backup will run in invalid configuration. But
94+something is better than nothing. Also, before the previous commit (commit
95+preceding this test creation), starting backup on such configuration led to
96+crash, so current "something" is a lot better, and this test actual goal is
97+to check that crash is fixed :)
98+"""
99+
100+vm = iotests.VM()
101+vm.launch()
102+
103+vm.qmp_log('blockdev-add', **{'node-name': 'target', 'driver': 'null-co'})
104+
105+vm.qmp_log('blockdev-add', **{
106+ 'node-name': 'source',
107+ 'driver': 'blkdebug',
108+ 'image': {'node-name': 'base', 'driver': 'null-co', 'size': size}
109+})
110+
111+vm.qmp_log('blockdev-add', **{
112+ 'node-name': 'other',
113+ 'driver': 'blkdebug',
114+ 'image': 'base',
115+ 'take-child-perms': ['write']
116+})
117+
118+vm.qmp_log('blockdev-backup', sync='full', device='source', target='target')
119+
120+vm.shutdown()
121--- /dev/null
122+++ b/tests/qemu-iotests/283.out
123@@ -0,0 +1,8 @@
124+{"execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "target"}}
125+{"return": {}}
126+{"execute": "blockdev-add", "arguments": {"driver": "blkdebug", "image": {"driver": "null-co", "node-name": "base", "size": 1048576}, "node-name": "source"}}
127+{"return": {}}
128+{"execute": "blockdev-add", "arguments": {"driver": "blkdebug", "image": "base", "node-name": "other", "take-child-perms": ["write"]}}
129+{"return": {}}
130+{"execute": "blockdev-backup", "arguments": {"device": "source", "sync": "full", "target": "target"}}
131+{"error": {"class": "GenericError", "desc": "Cannot set permissions for backup-top filter: Conflicts with use by other as 'image', which uses 'write' on base"}}
132--- a/tests/qemu-iotests/group
133+++ b/tests/qemu-iotests/group
134@@ -286,3 +286,4 @@
135 272 rw
136 273 backing quick
137 277 rw quick
138+283 auto quick
diff --git a/debian/patches/stable/lp-1867519-job-refactor-progress-to-separate-object.patch b/debian/patches/stable/lp-1867519-job-refactor-progress-to-separate-object.patch
0new file mode 100644139new file mode 100644
index 0000000..a31cf9f
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-job-refactor-progress-to-separate-object.patch
@@ -0,0 +1,230 @@
1From 01fe1ca945345d3dc420d70c69488143dc0451b1 Mon Sep 17 00:00:00 2001
2From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
3Date: Wed, 11 Mar 2020 13:29:56 +0300
4Subject: [PATCH] job: refactor progress to separate object
5
6We need it in separate to pass to the block-copy object in the next
7commit.
8
9Cc: qemu-stable@nongnu.org
10Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
11Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
12Reviewed-by: Max Reitz <mreitz@redhat.com>
13Message-Id: <20200311103004.7649-2-vsementsov@virtuozzo.com>
14Signed-off-by: Max Reitz <mreitz@redhat.com>
15
16Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=01fe1ca945345d3dc420d70c69488143dc0451b1
17Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
18Last-Update: 2020-03-18
19
20---
21 blockjob.c | 16 +++++-----
22 include/qemu/job.h | 11 ++-----
23 include/qemu/progress_meter.h | 58 +++++++++++++++++++++++++++++++++++
24 job-qmp.c | 4 +--
25 job.c | 6 ++--
26 qemu-img.c | 6 ++--
27 6 files changed, 76 insertions(+), 25 deletions(-)
28 create mode 100644 include/qemu/progress_meter.h
29
30diff --git a/blockjob.c b/blockjob.c
31index 5d63b1e89d..fc850312c1 100644
32--- a/blockjob.c
33+++ b/blockjob.c
34@@ -299,8 +299,8 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **errp)
35 info->device = g_strdup(job->job.id);
36 info->busy = atomic_read(&job->job.busy);
37 info->paused = job->job.pause_count > 0;
38- info->offset = job->job.progress_current;
39- info->len = job->job.progress_total;
40+ info->offset = job->job.progress.current;
41+ info->len = job->job.progress.total;
42 info->speed = job->speed;
43 info->io_status = job->iostatus;
44 info->ready = job_is_ready(&job->job),
45@@ -330,8 +330,8 @@ static void block_job_event_cancelled(Notifier *n, void *opaque)
46
47 qapi_event_send_block_job_cancelled(job_type(&job->job),
48 job->job.id,
49- job->job.progress_total,
50- job->job.progress_current,
51+ job->job.progress.total,
52+ job->job.progress.current,
53 job->speed);
54 }
55
56@@ -350,8 +350,8 @@ static void block_job_event_completed(Notifier *n, void *opaque)
57
58 qapi_event_send_block_job_completed(job_type(&job->job),
59 job->job.id,
60- job->job.progress_total,
61- job->job.progress_current,
62+ job->job.progress.total,
63+ job->job.progress.current,
64 job->speed,
65 !!msg,
66 msg);
67@@ -379,8 +379,8 @@ static void block_job_event_ready(Notifier *n, void *opaque)
68
69 qapi_event_send_block_job_ready(job_type(&job->job),
70 job->job.id,
71- job->job.progress_total,
72- job->job.progress_current,
73+ job->job.progress.total,
74+ job->job.progress.current,
75 job->speed);
76 }
77
78diff --git a/include/qemu/job.h b/include/qemu/job.h
79index bd59cd8944..32aabb1c60 100644
80--- a/include/qemu/job.h
81+++ b/include/qemu/job.h
82@@ -28,6 +28,7 @@
83
84 #include "qapi/qapi-types-job.h"
85 #include "qemu/queue.h"
86+#include "qemu/progress_meter.h"
87 #include "qemu/coroutine.h"
88 #include "block/aio.h"
89
90@@ -117,15 +118,7 @@ typedef struct Job {
91 /** True if this job should automatically dismiss itself */
92 bool auto_dismiss;
93
94- /**
95- * Current progress. The unit is arbitrary as long as the ratio between
96- * progress_current and progress_total represents the estimated percentage
97- * of work already done.
98- */
99- int64_t progress_current;
100-
101- /** Estimated progress_current value at the completion of the job */
102- int64_t progress_total;
103+ ProgressMeter progress;
104
105 /**
106 * Return code from @run and/or @prepare callback(s).
107diff --git a/include/qemu/progress_meter.h b/include/qemu/progress_meter.h
108new file mode 100644
109index 0000000000..9a23ff071c
110--- /dev/null
111+++ b/include/qemu/progress_meter.h
112@@ -0,0 +1,58 @@
113+/*
114+ * Helper functionality for some process progress tracking.
115+ *
116+ * Copyright (c) 2011 IBM Corp.
117+ * Copyright (c) 2012, 2018 Red Hat, Inc.
118+ * Copyright (c) 2020 Virtuozzo International GmbH
119+ *
120+ * Permission is hereby granted, free of charge, to any person obtaining a copy
121+ * of this software and associated documentation files (the "Software"), to deal
122+ * in the Software without restriction, including without limitation the rights
123+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
124+ * copies of the Software, and to permit persons to whom the Software is
125+ * furnished to do so, subject to the following conditions:
126+ *
127+ * The above copyright notice and this permission notice shall be included in
128+ * all copies or substantial portions of the Software.
129+ *
130+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
131+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
132+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
133+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
134+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
135+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
136+ * THE SOFTWARE.
137+ */
138+
139+#ifndef QEMU_PROGRESS_METER_H
140+#define QEMU_PROGRESS_METER_H
141+
142+typedef struct ProgressMeter {
143+ /**
144+ * Current progress. The unit is arbitrary as long as the ratio between
145+ * current and total represents the estimated percentage
146+ * of work already done.
147+ */
148+ uint64_t current;
149+
150+ /** Estimated current value at the completion of the process */
151+ uint64_t total;
152+} ProgressMeter;
153+
154+static inline void progress_work_done(ProgressMeter *pm, uint64_t done)
155+{
156+ pm->current += done;
157+}
158+
159+static inline void progress_set_remaining(ProgressMeter *pm, uint64_t remaining)
160+{
161+ pm->total = pm->current + remaining;
162+}
163+
164+static inline void progress_increase_remaining(ProgressMeter *pm,
165+ uint64_t delta)
166+{
167+ pm->total += delta;
168+}
169+
170+#endif /* QEMU_PROGRESS_METER_H */
171diff --git a/job-qmp.c b/job-qmp.c
172index fbfed25a00..fecc939ebd 100644
173--- a/job-qmp.c
174+++ b/job-qmp.c
175@@ -143,8 +143,8 @@ static JobInfo *job_query_single(Job *job, Error **errp)
176 .id = g_strdup(job->id),
177 .type = job_type(job),
178 .status = job->status,
179- .current_progress = job->progress_current,
180- .total_progress = job->progress_total,
181+ .current_progress = job->progress.current,
182+ .total_progress = job->progress.total,
183 .has_error = !!job->err,
184 .error = job->err ? \
185 g_strdup(error_get_pretty(job->err)) : NULL,
186diff --git a/job.c b/job.c
187index 04409b40aa..134a07b92e 100644
188--- a/job.c
189+++ b/job.c
190@@ -369,17 +369,17 @@ void job_unref(Job *job)
191
192 void job_progress_update(Job *job, uint64_t done)
193 {
194- job->progress_current += done;
195+ progress_work_done(&job->progress, done);
196 }
197
198 void job_progress_set_remaining(Job *job, uint64_t remaining)
199 {
200- job->progress_total = job->progress_current + remaining;
201+ progress_set_remaining(&job->progress, remaining);
202 }
203
204 void job_progress_increase_remaining(Job *job, uint64_t delta)
205 {
206- job->progress_total += delta;
207+ progress_increase_remaining(&job->progress, delta);
208 }
209
210 void job_event_cancelled(Job *job)
211diff --git a/qemu-img.c b/qemu-img.c
212index 7b7087dd60..afddf33f08 100644
213--- a/qemu-img.c
214+++ b/qemu-img.c
215@@ -884,9 +884,9 @@ static void run_block_job(BlockJob *job, Error **errp)
216 do {
217 float progress = 0.0f;
218 aio_poll(aio_context, true);
219- if (job->job.progress_total) {
220- progress = (float)job->job.progress_current /
221- job->job.progress_total * 100.f;
222+ if (job->job.progress.total) {
223+ progress = (float)job->job.progress.current /
224+ job->job.progress.total * 100.f;
225 }
226 qemu_progress_print(progress, 0);
227 } while (!job_is_ready(&job->job) && !job_is_completed(&job->job));
228--
2292.25.1
230
diff --git a/debian/patches/stable/lp-1867519-plugins-core-add-missing-break-in-cb_to_tcg_flags.patch b/debian/patches/stable/lp-1867519-plugins-core-add-missing-break-in-cb_to_tcg_flags.patch
0new file mode 100644231new file mode 100644
index 0000000..5047c62
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-plugins-core-add-missing-break-in-cb_to_tcg_flags.patch
@@ -0,0 +1,41 @@
1From dcc474c69e6a59044b9bb54624bd636cbfd98aa9 Mon Sep 17 00:00:00 2001
2From: "Emilio G. Cota" <cota@braap.org>
3Date: Tue, 25 Feb 2020 12:47:02 +0000
4Subject: [PATCH] plugins/core: add missing break in cb_to_tcg_flags
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Fixes: 54cb65d8588
10Reported-by: Robert Henry <robhenry@microsoft.com>
11Signed-off-by: Emilio G. Cota <cota@braap.org>
12Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
13Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15Message-Id: <20200105072940.32204-1-cota@braap.org>
16Cc: qemu-stable@nongnu.org
17Message-Id: <20200225124710.14152-12-alex.bennee@linaro.org>
18
19Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=dcc474c69e6a59044b9bb54624bd636cbfd98aa9
20Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
21Last-Update: 2020-03-18
22
23---
24 plugins/core.c | 1 +
25 1 file changed, 1 insertion(+)
26
27diff --git a/plugins/core.c b/plugins/core.c
28index 9e1b9e7a91..ed863011ba 100644
29--- a/plugins/core.c
30+++ b/plugins/core.c
31@@ -286,6 +286,7 @@ static inline uint32_t cb_to_tcg_flags(enum qemu_plugin_cb_flags flags)
32 switch (flags) {
33 case QEMU_PLUGIN_CB_RW_REGS:
34 ret = 0;
35+ break;
36 case QEMU_PLUGIN_CB_R_REGS:
37 ret = TCG_CALL_NO_WG;
38 break;
39--
402.25.1
41
diff --git a/debian/patches/stable/lp-1867519-qcow2-Fix-alloc_cluster_abort-for-pre-existing-clust.patch b/debian/patches/stable/lp-1867519-qcow2-Fix-alloc_cluster_abort-for-pre-existing-clust.patch
0new file mode 10064442new file mode 100644
index 0000000..ed7560a
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-qcow2-Fix-alloc_cluster_abort-for-pre-existing-clust.patch
@@ -0,0 +1,39 @@
1From 3ede935fdbbd5f7b24b4724bbfb8938acb5956d8 Mon Sep 17 00:00:00 2001
2From: Max Reitz <mreitz@redhat.com>
3Date: Tue, 25 Feb 2020 15:31:28 +0100
4Subject: [PATCH] qcow2: Fix alloc_cluster_abort() for pre-existing clusters
5
6handle_alloc() reuses preallocated zero clusters. If anything goes
7wrong during the data write, we do not change their L2 entry, so we
8must not let qcow2_alloc_cluster_abort() free them.
9
10Fixes: 8b24cd141549b5b264baeddd4e72902cfb5de23b
11Cc: qemu-stable@nongnu.org
12Signed-off-by: Max Reitz <mreitz@redhat.com>
13Message-Id: <20200225143130.111267-2-mreitz@redhat.com>
14Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15
16Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=3ede935fdbbd5f7b24b4724bbfb8938acb5956d8
17Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
18Last-Update: 2020-03-18
19
20---
21 block/qcow2-cluster.c | 2 +-
22 1 file changed, 1 insertion(+), 1 deletion(-)
23
24diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
25index 78c95dfa16..17f1363279 100644
26--- a/block/qcow2-cluster.c
27+++ b/block/qcow2-cluster.c
28@@ -1026,7 +1026,7 @@ err:
29 void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m)
30 {
31 BDRVQcow2State *s = bs->opaque;
32- if (!has_data_file(bs)) {
33+ if (!has_data_file(bs) && !m->keep_old_clusters) {
34 qcow2_free_clusters(bs, m->alloc_offset,
35 m->nb_clusters << s->cluster_bits,
36 QCOW2_DISCARD_NEVER);
37--
382.25.1
39
diff --git a/debian/patches/stable/lp-1867519-qcow2-Fix-qcow2_alloc_cluster_abort-for-external-dat.patch b/debian/patches/stable/lp-1867519-qcow2-Fix-qcow2_alloc_cluster_abort-for-external-dat.patch
0new file mode 10064440new file mode 100644
index 0000000..b7acd5b
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-qcow2-Fix-qcow2_alloc_cluster_abort-for-external-dat.patch
@@ -0,0 +1,44 @@
1From c3b6658c1a5a3fb24d6c27b2594cf86146f75b22 Mon Sep 17 00:00:00 2001
2From: Kevin Wolf <kwolf@redhat.com>
3Date: Tue, 11 Feb 2020 10:48:59 +0100
4Subject: [PATCH] qcow2: Fix qcow2_alloc_cluster_abort() for external data file
5
6For external data file, cluster allocations return an offset in the data
7file and are not refcounted. In this case, there is nothing to do for
8qcow2_alloc_cluster_abort(). Freeing the same offset in the qcow2 file
9is wrong and causes crashes in the better case or image corruption in
10the worse case.
11
12Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13Message-Id: <20200211094900.17315-3-kwolf@redhat.com>
14Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15
16Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=c3b6658c1a5a3fb24d6c27b2594cf86146f75b22
17Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
18Last-Update: 2020-03-18
19
20---
21 block/qcow2-cluster.c | 7 +++++--
22 1 file changed, 5 insertions(+), 2 deletions(-)
23
24diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
25index 1947f13a2d..78c95dfa16 100644
26--- a/block/qcow2-cluster.c
27+++ b/block/qcow2-cluster.c
28@@ -1026,8 +1026,11 @@ err:
29 void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m)
30 {
31 BDRVQcow2State *s = bs->opaque;
32- qcow2_free_clusters(bs, m->alloc_offset, m->nb_clusters << s->cluster_bits,
33- QCOW2_DISCARD_NEVER);
34+ if (!has_data_file(bs)) {
35+ qcow2_free_clusters(bs, m->alloc_offset,
36+ m->nb_clusters << s->cluster_bits,
37+ QCOW2_DISCARD_NEVER);
38+ }
39 }
40
41 /*
42--
432.25.1
44
diff --git a/debian/patches/stable/lp-1867519-qcow2-bitmaps-fix-qcow2_can_store_new_dirty_bitmap.patch b/debian/patches/stable/lp-1867519-qcow2-bitmaps-fix-qcow2_can_store_new_dirty_bitmap.patch
0new file mode 10064445new file mode 100644
index 0000000..b1b1869
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-qcow2-bitmaps-fix-qcow2_can_store_new_dirty_bitmap.patch
@@ -0,0 +1,102 @@
1From a1db8733d28d615bc0daeada6c406a6dd5c5d5ef Mon Sep 17 00:00:00 2001
2From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
3Date: Mon, 14 Oct 2019 14:51:25 +0300
4Subject: [PATCH] qcow2-bitmaps: fix qcow2_can_store_new_dirty_bitmap
5
6qcow2_can_store_new_dirty_bitmap works wrong, as it considers only
7bitmaps already stored in the qcow2 image and ignores persistent
8BdrvDirtyBitmap objects.
9
10So, let's instead count persistent BdrvDirtyBitmaps. We load all qcow2
11bitmaps on open, so there should not be any bitmap in the image for
12which we don't have BdrvDirtyBitmaps version. If it is - it's a kind of
13corruption, and no reason to check for corruptions here (open() and
14close() are better places for it).
15
16Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
17Message-id: 20191014115126.15360-2-vsementsov@virtuozzo.com
18Reviewed-by: Max Reitz <mreitz@redhat.com>
19Cc: qemu-stable@nongnu.org
20Signed-off-by: Max Reitz <mreitz@redhat.com>
21
22Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=a1db8733d28d615bc0daeada6c406a6dd5c5d5ef
23Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
24Last-Update: 2020-03-18
25
26---
27 block/qcow2-bitmap.c | 41 ++++++++++++++++++-----------------------
28 1 file changed, 18 insertions(+), 23 deletions(-)
29
30diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
31index c6c8ebbe89..d41f5d049b 100644
32--- a/block/qcow2-bitmap.c
33+++ b/block/qcow2-bitmap.c
34@@ -1703,8 +1703,14 @@ bool coroutine_fn qcow2_co_can_store_new_dirty_bitmap(BlockDriverState *bs,
35 Error **errp)
36 {
37 BDRVQcow2State *s = bs->opaque;
38- bool found;
39- Qcow2BitmapList *bm_list;
40+ BdrvDirtyBitmap *bitmap;
41+ uint64_t bitmap_directory_size = 0;
42+ uint32_t nb_bitmaps = 0;
43+
44+ if (bdrv_find_dirty_bitmap(bs, name)) {
45+ error_setg(errp, "Bitmap already exists: %s", name);
46+ return false;
47+ }
48
49 if (s->qcow_version < 3) {
50 /* Without autoclear_features, we would always have to assume
51@@ -1720,38 +1726,27 @@ bool coroutine_fn qcow2_co_can_store_new_dirty_bitmap(BlockDriverState *bs,
52 goto fail;
53 }
54
55- if (s->nb_bitmaps == 0) {
56- return true;
57+ FOR_EACH_DIRTY_BITMAP(bs, bitmap) {
58+ if (bdrv_dirty_bitmap_get_persistence(bitmap)) {
59+ nb_bitmaps++;
60+ bitmap_directory_size +=
61+ calc_dir_entry_size(strlen(bdrv_dirty_bitmap_name(bitmap)), 0);
62+ }
63 }
64+ nb_bitmaps++;
65+ bitmap_directory_size += calc_dir_entry_size(strlen(name), 0);
66
67- if (s->nb_bitmaps >= QCOW2_MAX_BITMAPS) {
68+ if (nb_bitmaps > QCOW2_MAX_BITMAPS) {
69 error_setg(errp,
70 "Maximum number of persistent bitmaps is already reached");
71 goto fail;
72 }
73
74- if (s->bitmap_directory_size + calc_dir_entry_size(strlen(name), 0) >
75- QCOW2_MAX_BITMAP_DIRECTORY_SIZE)
76- {
77+ if (bitmap_directory_size > QCOW2_MAX_BITMAP_DIRECTORY_SIZE) {
78 error_setg(errp, "Not enough space in the bitmap directory");
79 goto fail;
80 }
81
82- qemu_co_mutex_lock(&s->lock);
83- bm_list = bitmap_list_load(bs, s->bitmap_directory_offset,
84- s->bitmap_directory_size, errp);
85- qemu_co_mutex_unlock(&s->lock);
86- if (bm_list == NULL) {
87- goto fail;
88- }
89-
90- found = find_bitmap_by_name(bm_list, name);
91- bitmap_list_free(bm_list);
92- if (found) {
93- error_setg(errp, "Bitmap with the same name is already stored");
94- goto fail;
95- }
96-
97 return true;
98
99 fail:
100--
1012.25.1
102
diff --git a/debian/patches/stable/lp-1867519-qemu-img-Fix-convert-n-B-for-backing-less-targets.patch b/debian/patches/stable/lp-1867519-qemu-img-Fix-convert-n-B-for-backing-less-targets.patch
0new file mode 100644103new file mode 100644
index 0000000..ed8ab96
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-qemu-img-Fix-convert-n-B-for-backing-less-targets.patch
@@ -0,0 +1,54 @@
1From c69291e712ae4ef95f628424db6586473da61d43 Mon Sep 17 00:00:00 2001
2From: Max Reitz <mreitz@redhat.com>
3Date: Tue, 21 Jan 2020 16:59:14 +0100
4Subject: [PATCH] qemu-img: Fix convert -n -B for backing-less targets
5
6s.target_has_backing does not reflect whether the target BDS has a
7backing file; it only tells whether we should use a backing file during
8conversion (specified by -B).
9
10As such, if you use convert -n, the target does not necessarily actually
11have a backing file, and then dereferencing out_bs->backing fails here.
12
13When converting to an existing file, we should set
14target_backing_sectors to a negative value, because first, as the
15comment explains, this value is only used for optimization, so it is
16always fine to do that.
17
18Second, we use this value to determine where the target must be
19initialized to zeroes (overlays are initialized to zero after the end of
20their backing file). When converting to an existing file, we cannot
21assume that to be true.
22
23Cc: qemu-stable@nongnu.org
24Fixes: 351c8efff9ad809c822d55620df54d575d536f68
25 ("qemu-img: Special post-backing convert handling")
26Signed-off-by: Max Reitz <mreitz@redhat.com>
27Message-Id: <20200121155915.98232-2-mreitz@redhat.com>
28Reviewed-by: John Snow <jsnow@redhat.com>
29Signed-off-by: Max Reitz <mreitz@redhat.com>
30
31Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=c69291e712ae4ef95f628424db6586473da61d43
32Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
33Last-Update: 2020-03-18
34
35---
36 qemu-img.c | 2 +-
37 1 file changed, 1 insertion(+), 1 deletion(-)
38
39diff --git a/qemu-img.c b/qemu-img.c
40index 0faf2cd2f5..804630a368 100644
41--- a/qemu-img.c
42+++ b/qemu-img.c
43@@ -2523,7 +2523,7 @@ static int img_convert(int argc, char **argv)
44 }
45 }
46
47- if (s.target_has_backing) {
48+ if (s.target_has_backing && s.target_is_new) {
49 /* Errors are treated as "backing length unknown" (which means
50 * s.target_backing_sectors has to be negative, which it will
51 * be automatically). The backing file length is used only
52--
532.25.1
54
diff --git a/debian/patches/stable/lp-1867519-s390-sclp-improve-special-wait-psw-logic.patch b/debian/patches/stable/lp-1867519-s390-sclp-improve-special-wait-psw-logic.patch
0new file mode 10064455new file mode 100644
index 0000000..fb21432
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-s390-sclp-improve-special-wait-psw-logic.patch
@@ -0,0 +1,40 @@
1From 8b51c0961cc13e55b26bb6665ec3a341abdc7658 Mon Sep 17 00:00:00 2001
2From: Christian Borntraeger <borntraeger@de.ibm.com>
3Date: Thu, 20 Feb 2020 14:16:22 +0100
4Subject: [PATCH] s390/sclp: improve special wait psw logic
5
6There is a special quiesce PSW that we check for "shutdown". Otherwise disabled
7wait is detected as "crashed". Architecturally we must only check PSW bits
8116-127. Fix this.
9
10Cc: qemu-stable@nongnu.org
11Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
12Message-Id: <1582204582-22995-1-git-send-email-borntraeger@de.ibm.com>
13Reviewed-by: David Hildenbrand <david@redhat.com>
14Acked-by: Janosch Frank <frankja@linux.ibm.com>
15Signed-off-by: Cornelia Huck <cohuck@redhat.com>
16
17Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=8b51c0961cc13e55b26bb6665ec3a341abdc7658
18Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
19Last-Update: 2020-03-18
20
21---
22 target/s390x/helper.c | 2 +-
23 1 file changed, 1 insertion(+), 1 deletion(-)
24
25diff --git a/target/s390x/helper.c b/target/s390x/helper.c
26index b810ad431e..ed72684911 100644
27--- a/target/s390x/helper.c
28+++ b/target/s390x/helper.c
29@@ -89,7 +89,7 @@ hwaddr s390_cpu_get_phys_addr_debug(CPUState *cs, vaddr vaddr)
30 static inline bool is_special_wait_psw(uint64_t psw_addr)
31 {
32 /* signal quiesce */
33- return psw_addr == 0xfffUL;
34+ return (psw_addr & 0xfffUL) == 0xfffUL;
35 }
36
37 void s390_handle_wait(S390CPU *cpu)
38--
392.25.1
40
diff --git a/debian/patches/stable/lp-1867519-target-arm-Return-correct-IL-bit-in-merge_syn_data_a.patch b/debian/patches/stable/lp-1867519-target-arm-Return-correct-IL-bit-in-merge_syn_data_a.patch
0new file mode 10064441new file mode 100644
index 0000000..6c4bce9
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-target-arm-Return-correct-IL-bit-in-merge_syn_data_a.patch
@@ -0,0 +1,46 @@
1From 30d544839e278dc76017b9a42990c41e84a34377 Mon Sep 17 00:00:00 2001
2From: Jeff Kubascik <jeff.kubascik@dornerworks.com>
3Date: Fri, 17 Jan 2020 14:09:31 +0000
4Subject: [PATCH] target/arm: Return correct IL bit in merge_syn_data_abort
5
6The IL bit is set for 32-bit instructions, thus passing false
7with the is_16bit parameter to syn_data_abort_with_iss() makes
8a syn mask that always has the IL bit set.
9
10Pass is_16bit as true to make the initial syn mask have IL=0,
11so that the final IL value comes from or'ing template_syn.
12
13Cc: qemu-stable@nongnu.org
14Fixes: aaa1f954d4ca ("target-arm: A64: Create Instruction Syndromes for Data Aborts")
15Signed-off-by: Jeff Kubascik <jeff.kubascik@dornerworks.com>
16Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
17Message-id: 20200117004618.2742-2-richard.henderson@linaro.org
18[rth: Extracted this as a self-contained bug fix from a larger patch]
19Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
20Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
21Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
23Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=30d544839e278dc76017b9a42990c41e84a34377
24Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
25Last-Update: 2020-03-18
26
27---
28 target/arm/tlb_helper.c | 2 +-
29 1 file changed, 1 insertion(+), 1 deletion(-)
30
31diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c
32index 5feb312941..e63f8bda29 100644
33--- a/target/arm/tlb_helper.c
34+++ b/target/arm/tlb_helper.c
35@@ -44,7 +44,7 @@ static inline uint32_t merge_syn_data_abort(uint32_t template_syn,
36 syn = syn_data_abort_with_iss(same_el,
37 0, 0, 0, 0, 0,
38 ea, 0, s1ptw, is_write, fsc,
39- false);
40+ true);
41 /* Merge the runtime syndrome with the template syndrome. */
42 syn |= template_syn;
43 }
44--
452.25.1
46
diff --git a/debian/patches/stable/lp-1867519-target-arm-Set-ISSIs16Bit-in-make_issinfo.patch b/debian/patches/stable/lp-1867519-target-arm-Set-ISSIs16Bit-in-make_issinfo.patch
0new file mode 10064447new file mode 100644
index 0000000..46f0f6d
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-target-arm-Set-ISSIs16Bit-in-make_issinfo.patch
@@ -0,0 +1,42 @@
1From 1a1fbc6cbb34c26d43d8360c66c1d21681af14a9 Mon Sep 17 00:00:00 2001
2From: Richard Henderson <richard.henderson@linaro.org>
3Date: Fri, 17 Jan 2020 14:09:31 +0000
4Subject: [PATCH] target/arm: Set ISSIs16Bit in make_issinfo
5
6During the conversion to decodetree, the setting of
7ISSIs16Bit got lost. This causes the guest os to
8incorrectly adjust trapping memory operations.
9
10Cc: qemu-stable@nongnu.org
11Fixes: 46beb58efbb8a2a32 ("target/arm: Convert T16, load (literal)")
12Reported-by: Jeff Kubascik <jeff.kubascik@dornerworks.com>
13Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
14Message-id: 20200117004618.2742-3-richard.henderson@linaro.org
15Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
16Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
18Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=1a1fbc6cbb34c26d43d8360c66c1d21681af14a9
19Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
20Last-Update: 2020-03-18
21
22---
23 target/arm/translate.c | 3 +++
24 1 file changed, 3 insertions(+)
25
26diff --git a/target/arm/translate.c b/target/arm/translate.c
27index 0c8624fb42..2f4aea927f 100644
28--- a/target/arm/translate.c
29+++ b/target/arm/translate.c
30@@ -8556,6 +8556,9 @@ static ISSInfo make_issinfo(DisasContext *s, int rd, bool p, bool w)
31 /* ISS not valid if writeback */
32 if (p && !w) {
33 ret = rd;
34+ if (s->base.pc_next - s->pc_curr == 2) {
35+ ret |= ISSIs16Bit;
36+ }
37 } else {
38 ret = ISSInvalid;
39 }
40--
412.25.1
42
diff --git a/debian/patches/stable/lp-1867519-target-arm-arm-semi-fix-SYS_OPEN-to-return-nonzero-f.patch b/debian/patches/stable/lp-1867519-target-arm-arm-semi-fix-SYS_OPEN-to-return-nonzero-f.patch
0new file mode 10064443new file mode 100644
index 0000000..4f7a731
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-target-arm-arm-semi-fix-SYS_OPEN-to-return-nonzero-f.patch
@@ -0,0 +1,79 @@
1From 21bf9b06cb6d07c6cc437dfd47b47b28c2bb79db Mon Sep 17 00:00:00 2001
2From: Masahiro Yamada <masahiroy@kernel.org>
3Date: Fri, 17 Jan 2020 14:09:30 +0000
4Subject: [PATCH] target/arm/arm-semi: fix SYS_OPEN to return nonzero
5 filehandle
6
7According to the specification "Semihosting for AArch32 and Aarch64",
8the SYS_OPEN operation should return:
9
10 - A nonzero handle if the call is successful
11 - -1 if the call is not successful
12
13So, it should never return 0.
14
15Prior to commit 35e9a0a8ce4b ("target/arm/arm-semi: Make semihosting
16code hand out its own file descriptors"), the guest fd matched to the
17host fd. It returned a nonzero handle on success since the fd 0 is
18already used for stdin.
19
20Now that the guest fd is the index of guestfd_array, it starts from 0.
21
22I noticed this issue particularly because Trusted Firmware-A built with
23PLAT=qemu is no longer working. Its io_semihosting driver only handles
24a positive return value as a valid filehandle.
25
26Basically, there are two ways to fix this:
27
28 - Use (guestfd - 1) as the index of guestfs_arrary. We need to insert
29 increment/decrement to convert the guestfd and the array index back
30 and forth.
31
32 - Keep using guestfd as the index of guestfs_array. The first entry
33 of guestfs_array is left unused.
34
35I thought the latter is simpler. We end up with wasting a small piece
36of memory for the unused first entry of guestfd_array, but this is
37probably not a big deal.
38
39Fixes: 35e9a0a8ce4b ("target/arm/arm-semi: Make semihosting code hand out its own file descriptors")
40Cc: qemu-stable@nongnu.org
41Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
42Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
43Message-id: 20200109041228.10131-1-masahiroy@kernel.org
44Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
45
46Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=21bf9b06cb6d07c6cc437dfd47b47b28c2bb79db
47Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
48Last-Update: 2020-03-18
49
50---
51 target/arm/arm-semi.c | 5 +++--
52 1 file changed, 3 insertions(+), 2 deletions(-)
53
54diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
55index 47d61f6fe1..788fe61b51 100644
56--- a/target/arm/arm-semi.c
57+++ b/target/arm/arm-semi.c
58@@ -144,7 +144,8 @@ static int alloc_guestfd(void)
59 guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD));
60 }
61
62- for (i = 0; i < guestfd_array->len; i++) {
63+ /* SYS_OPEN should return nonzero handle on success. Start guestfd from 1 */
64+ for (i = 1; i < guestfd_array->len; i++) {
65 GuestFD *gf = &g_array_index(guestfd_array, GuestFD, i);
66
67 if (gf->type == GuestFDUnused) {
68@@ -168,7 +169,7 @@ static GuestFD *do_get_guestfd(int guestfd)
69 return NULL;
70 }
71
72- if (guestfd < 0 || guestfd >= guestfd_array->len) {
73+ if (guestfd <= 0 || guestfd >= guestfd_array->len) {
74 return NULL;
75 }
76
77--
782.25.1
79
diff --git a/debian/patches/stable/lp-1867519-target-arm-ensure-we-use-current-exception-state-aft.patch b/debian/patches/stable/lp-1867519-target-arm-ensure-we-use-current-exception-state-aft.patch
0new file mode 10064480new file mode 100644
index 0000000..896de43
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-target-arm-ensure-we-use-current-exception-state-aft.patch
@@ -0,0 +1,127 @@
1From f80741d107673f162e3b097fc76a1590036cc9d1 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Alex=20Benn=C3=A9e?= <alex.bennee@linaro.org>
3Date: Thu, 12 Dec 2019 11:47:34 +0000
4Subject: [PATCH] target/arm: ensure we use current exception state after SCR
5 update
6MIME-Version: 1.0
7Content-Type: text/plain; charset=UTF-8
8Content-Transfer-Encoding: 8bit
9
10A write to the SCR can change the effective EL by droppping the system
11from secure to non-secure mode. However if we use a cached current_el
12from before the change we'll rebuild the flags incorrectly. To fix
13this we introduce the ARM_CP_NEWEL CP flag to indicate the new EL
14should be used when recomputing the flags.
15
16Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
17Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
18Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
19Message-id: 20191212114734.6962-1-alex.bennee@linaro.org
20Cc: Richard Henderson <richard.henderson@linaro.org>
21Message-Id: <20191209143723.6368-1-alex.bennee@linaro.org>
22Cc: qemu-stable@nongnu.org
23Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
24
25Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=f80741d107673f162e3b097fc76a1590036cc9d1
26Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
27Last-Update: 2020-03-18
28
29---
30 target/arm/cpu.h | 8 ++++++--
31 target/arm/helper.c | 14 +++++++++++++-
32 target/arm/helper.h | 1 +
33 target/arm/translate.c | 6 +++++-
34 4 files changed, 25 insertions(+), 4 deletions(-)
35
36diff --git a/target/arm/cpu.h b/target/arm/cpu.h
37index 4106e4ae59..5f70e9e043 100644
38--- a/target/arm/cpu.h
39+++ b/target/arm/cpu.h
40@@ -2238,6 +2238,9 @@ static inline uint64_t cpreg_to_kvm_id(uint32_t cpregid)
41 * RAISES_EXC is for when the read or write hook might raise an exception;
42 * the generated code will synchronize the CPU state before calling the hook
43 * so that it is safe for the hook to call raise_exception().
44+ * NEWEL is for writes to registers that might change the exception
45+ * level - typically on older ARM chips. For those cases we need to
46+ * re-read the new el when recomputing the translation flags.
47 */
48 #define ARM_CP_SPECIAL 0x0001
49 #define ARM_CP_CONST 0x0002
50@@ -2257,10 +2260,11 @@ static inline uint64_t cpreg_to_kvm_id(uint32_t cpregid)
51 #define ARM_CP_SVE 0x2000
52 #define ARM_CP_NO_GDB 0x4000
53 #define ARM_CP_RAISES_EXC 0x8000
54+#define ARM_CP_NEWEL 0x10000
55 /* Used only as a terminator for ARMCPRegInfo lists */
56-#define ARM_CP_SENTINEL 0xffff
57+#define ARM_CP_SENTINEL 0xfffff
58 /* Mask of only the flag bits in a type field */
59-#define ARM_CP_FLAG_MASK 0xf0ff
60+#define ARM_CP_FLAG_MASK 0x1f0ff
61
62 /* Valid values for ARMCPRegInfo state field, indicating which of
63 * the AArch32 and AArch64 execution states this register is visible in.
64diff --git a/target/arm/helper.c b/target/arm/helper.c
65index 3a93844a3b..5074b5f69c 100644
66--- a/target/arm/helper.c
67+++ b/target/arm/helper.c
68@@ -5133,7 +5133,7 @@ static const ARMCPRegInfo el3_cp_reginfo[] = {
69 .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 1, .opc2 = 0,
70 .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.scr_el3),
71 .resetvalue = 0, .writefn = scr_write },
72- { .name = "SCR", .type = ARM_CP_ALIAS,
73+ { .name = "SCR", .type = ARM_CP_ALIAS | ARM_CP_NEWEL,
74 .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 0,
75 .access = PL1_RW, .accessfn = access_trap_aa32s_el1,
76 .fieldoffset = offsetoflow32(CPUARMState, cp15.scr_el3),
77@@ -11472,6 +11472,18 @@ void HELPER(rebuild_hflags_m32)(CPUARMState *env, int el)
78 env->hflags = rebuild_hflags_m32(env, fp_el, mmu_idx);
79 }
80
81+/*
82+ * If we have triggered a EL state change we can't rely on the
83+ * translator having passed it too us, we need to recompute.
84+ */
85+void HELPER(rebuild_hflags_a32_newel)(CPUARMState *env)
86+{
87+ int el = arm_current_el(env);
88+ int fp_el = fp_exception_el(env, el);
89+ ARMMMUIdx mmu_idx = arm_mmu_idx_el(env, el);
90+ env->hflags = rebuild_hflags_a32(env, fp_el, mmu_idx);
91+}
92+
93 void HELPER(rebuild_hflags_a32)(CPUARMState *env, int el)
94 {
95 int fp_el = fp_exception_el(env, el);
96diff --git a/target/arm/helper.h b/target/arm/helper.h
97index 7ce5169afb..aa3d8cd08f 100644
98--- a/target/arm/helper.h
99+++ b/target/arm/helper.h
100@@ -91,6 +91,7 @@ DEF_HELPER_2(get_user_reg, i32, env, i32)
101 DEF_HELPER_3(set_user_reg, void, env, i32, i32)
102
103 DEF_HELPER_FLAGS_2(rebuild_hflags_m32, TCG_CALL_NO_RWG, void, env, int)
104+DEF_HELPER_FLAGS_1(rebuild_hflags_a32_newel, TCG_CALL_NO_RWG, void, env)
105 DEF_HELPER_FLAGS_2(rebuild_hflags_a32, TCG_CALL_NO_RWG, void, env, int)
106 DEF_HELPER_FLAGS_2(rebuild_hflags_a64, TCG_CALL_NO_RWG, void, env, int)
107
108diff --git a/target/arm/translate.c b/target/arm/translate.c
109index f162be8434..2b6c1f91bf 100644
110--- a/target/arm/translate.c
111+++ b/target/arm/translate.c
112@@ -7083,7 +7083,11 @@ static int disas_coproc_insn(DisasContext *s, uint32_t insn)
113 if (arm_dc_feature(s, ARM_FEATURE_M)) {
114 gen_helper_rebuild_hflags_m32(cpu_env, tcg_el);
115 } else {
116- gen_helper_rebuild_hflags_a32(cpu_env, tcg_el);
117+ if (ri->type & ARM_CP_NEWEL) {
118+ gen_helper_rebuild_hflags_a32_newel(cpu_env);
119+ } else {
120+ gen_helper_rebuild_hflags_a32(cpu_env, tcg_el);
121+ }
122 }
123 tcg_temp_free_i32(tcg_el);
124 /*
125--
1262.25.1
127
diff --git a/debian/patches/stable/lp-1867519-target-i386-kvm-initialize-feature-MSRs-very-early.patch b/debian/patches/stable/lp-1867519-target-i386-kvm-initialize-feature-MSRs-very-early.patch
0new file mode 100644128new file mode 100644
index 0000000..9316575
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-target-i386-kvm-initialize-feature-MSRs-very-early.patch
@@ -0,0 +1,169 @@
1From 420ae1fc51c99abfd03b1c590f55617edd2a2bed Mon Sep 17 00:00:00 2001
2From: Paolo Bonzini <pbonzini@redhat.com>
3Date: Mon, 20 Jan 2020 19:21:42 +0100
4Subject: [PATCH] target/i386: kvm: initialize feature MSRs very early
5
6Some read-only MSRs affect the behavior of ioctls such as
7KVM_SET_NESTED_STATE. We can initialize them once and for all
8right after the CPU is realized, since they will never be modified
9by the guest.
10
11Reported-by: Qingua Cheng <qcheng@redhat.com>
12Cc: qemu-stable@nongnu.org
13Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
14Message-Id: <1579544504-3616-2-git-send-email-pbonzini@redhat.com>
15Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
16
17Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=420ae1fc51c99abfd03b1c590f55617edd2a2bed
18Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
19Last-Update: 2020-03-18
20
21---
22 target/i386/kvm.c | 81 +++++++++++++++++++++++++-----------------
23 target/i386/kvm_i386.h | 1 +
24 2 files changed, 49 insertions(+), 33 deletions(-)
25
26diff --git a/target/i386/kvm.c b/target/i386/kvm.c
27index 7ee3202634..f6dd6b790e 100644
28--- a/target/i386/kvm.c
29+++ b/target/i386/kvm.c
30@@ -67,6 +67,8 @@
31 * 255 kvm_msr_entry structs */
32 #define MSR_BUF_SIZE 4096
33
34+static void kvm_init_msrs(X86CPU *cpu);
35+
36 const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
37 KVM_CAP_INFO(SET_TSS_ADDR),
38 KVM_CAP_INFO(EXT_CPUID),
39@@ -1842,6 +1844,8 @@ int kvm_arch_init_vcpu(CPUState *cs)
40 has_msr_tsc_aux = false;
41 }
42
43+ kvm_init_msrs(cpu);
44+
45 r = hyperv_init_vcpu(cpu);
46 if (r) {
47 goto fail;
48@@ -2660,11 +2664,53 @@ static void kvm_msr_entry_add_vmx(X86CPU *cpu, FeatureWordArray f)
49 VMCS12_MAX_FIELD_INDEX << 1);
50 }
51
52+static int kvm_buf_set_msrs(X86CPU *cpu)
53+{
54+ int ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MSRS, cpu->kvm_msr_buf);
55+ if (ret < 0) {
56+ return ret;
57+ }
58+
59+ if (ret < cpu->kvm_msr_buf->nmsrs) {
60+ struct kvm_msr_entry *e = &cpu->kvm_msr_buf->entries[ret];
61+ error_report("error: failed to set MSR 0x%" PRIx32 " to 0x%" PRIx64,
62+ (uint32_t)e->index, (uint64_t)e->data);
63+ }
64+
65+ assert(ret == cpu->kvm_msr_buf->nmsrs);
66+ return 0;
67+}
68+
69+static void kvm_init_msrs(X86CPU *cpu)
70+{
71+ CPUX86State *env = &cpu->env;
72+
73+ kvm_msr_buf_reset(cpu);
74+ if (has_msr_arch_capabs) {
75+ kvm_msr_entry_add(cpu, MSR_IA32_ARCH_CAPABILITIES,
76+ env->features[FEAT_ARCH_CAPABILITIES]);
77+ }
78+
79+ if (has_msr_core_capabs) {
80+ kvm_msr_entry_add(cpu, MSR_IA32_CORE_CAPABILITY,
81+ env->features[FEAT_CORE_CAPABILITY]);
82+ }
83+
84+ /*
85+ * Older kernels do not include VMX MSRs in KVM_GET_MSR_INDEX_LIST, but
86+ * all kernels with MSR features should have them.
87+ */
88+ if (kvm_feature_msrs && cpu_has_vmx(env)) {
89+ kvm_msr_entry_add_vmx(cpu, env->features);
90+ }
91+
92+ assert(kvm_buf_set_msrs(cpu) == 0);
93+}
94+
95 static int kvm_put_msrs(X86CPU *cpu, int level)
96 {
97 CPUX86State *env = &cpu->env;
98 int i;
99- int ret;
100
101 kvm_msr_buf_reset(cpu);
102
103@@ -2722,17 +2768,6 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
104 }
105 #endif
106
107- /* If host supports feature MSR, write down. */
108- if (has_msr_arch_capabs) {
109- kvm_msr_entry_add(cpu, MSR_IA32_ARCH_CAPABILITIES,
110- env->features[FEAT_ARCH_CAPABILITIES]);
111- }
112-
113- if (has_msr_core_capabs) {
114- kvm_msr_entry_add(cpu, MSR_IA32_CORE_CAPABILITY,
115- env->features[FEAT_CORE_CAPABILITY]);
116- }
117-
118 /*
119 * The following MSRs have side effects on the guest or are too heavy
120 * for normal writeback. Limit them to reset or full state updates.
121@@ -2910,14 +2945,6 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
122
123 /* Note: MSR_IA32_FEATURE_CONTROL is written separately, see
124 * kvm_put_msr_feature_control. */
125-
126- /*
127- * Older kernels do not include VMX MSRs in KVM_GET_MSR_INDEX_LIST, but
128- * all kernels with MSR features should have them.
129- */
130- if (kvm_feature_msrs && cpu_has_vmx(env)) {
131- kvm_msr_entry_add_vmx(cpu, env->features);
132- }
133 }
134
135 if (env->mcg_cap) {
136@@ -2933,19 +2960,7 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
137 }
138 }
139
140- ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MSRS, cpu->kvm_msr_buf);
141- if (ret < 0) {
142- return ret;
143- }
144-
145- if (ret < cpu->kvm_msr_buf->nmsrs) {
146- struct kvm_msr_entry *e = &cpu->kvm_msr_buf->entries[ret];
147- error_report("error: failed to set MSR 0x%" PRIx32 " to 0x%" PRIx64,
148- (uint32_t)e->index, (uint64_t)e->data);
149- }
150-
151- assert(ret == cpu->kvm_msr_buf->nmsrs);
152- return 0;
153+ return kvm_buf_set_msrs(cpu);
154 }
155
156
157diff --git a/target/i386/kvm_i386.h b/target/i386/kvm_i386.h
158index 7d0242f5fb..00bde7acaf 100644
159--- a/target/i386/kvm_i386.h
160+++ b/target/i386/kvm_i386.h
161@@ -46,4 +46,5 @@ bool kvm_enable_x2apic(void);
162 bool kvm_has_x2apic_api(void);
163
164 bool kvm_hv_vpindex_settable(void);
165+
166 #endif
167--
1682.25.1
169
diff --git a/debian/patches/stable/lp-1867519-tcg-save-vaddr-temp-for-plugin-usage.patch b/debian/patches/stable/lp-1867519-tcg-save-vaddr-temp-for-plugin-usage.patch
0new file mode 100644170new file mode 100644
index 0000000..5d0bbf2
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-tcg-save-vaddr-temp-for-plugin-usage.patch
@@ -0,0 +1,98 @@
1From fcc54ab5c7ca84ae72e8bf3781c33c9193a911aa Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Alex=20Benn=C3=A9e?= <alex.bennee@linaro.org>
3Date: Tue, 25 Feb 2020 17:49:08 +0000
4Subject: [PATCH] tcg: save vaddr temp for plugin usage
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9While do_gen_mem_cb does copy (via extu_tl_i64) vaddr into a new temp
10this won't help if the vaddr temp gets clobbered by the actual
11load/store op. To avoid this clobbering we explicitly copy vaddr
12before the op to ensure it is live my the time we do the
13instrumentation.
14
15Suggested-by: Richard Henderson <richard.henderson@linaro.org>
16Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
17Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
18Reviewed-by: Emilio G. Cota <cota@braap.org>
19Cc: qemu-stable@nongnu.org
20Message-Id: <20200225124710.14152-18-alex.bennee@linaro.org>
21
22Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=fcc54ab5c7ca84ae72e8bf3781c33c9193a911aa
23Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
24Last-Update: 2020-03-18
25
26---
27 tcg/tcg-op.c | 23 ++++++++++++++++++++---
28 1 file changed, 20 insertions(+), 3 deletions(-)
29
30diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
31index 7d782002e3..e2e25ebf7d 100644
32--- a/tcg/tcg-op.c
33+++ b/tcg/tcg-op.c
34@@ -2794,13 +2794,26 @@ static void tcg_gen_req_mo(TCGBar type)
35 }
36 }
37
38+static inline TCGv plugin_prep_mem_callbacks(TCGv vaddr)
39+{
40+#ifdef CONFIG_PLUGIN
41+ if (tcg_ctx->plugin_insn != NULL) {
42+ /* Save a copy of the vaddr for use after a load. */
43+ TCGv temp = tcg_temp_new();
44+ tcg_gen_mov_tl(temp, vaddr);
45+ return temp;
46+ }
47+#endif
48+ return vaddr;
49+}
50+
51 static inline void plugin_gen_mem_callbacks(TCGv vaddr, uint16_t info)
52 {
53 #ifdef CONFIG_PLUGIN
54- if (tcg_ctx->plugin_insn == NULL) {
55- return;
56+ if (tcg_ctx->plugin_insn != NULL) {
57+ plugin_gen_empty_mem_callback(vaddr, info);
58+ tcg_temp_free(vaddr);
59 }
60- plugin_gen_empty_mem_callback(vaddr, info);
61 #endif
62 }
63
64@@ -2822,6 +2835,7 @@ void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, MemOp memop)
65 }
66 }
67
68+ addr = plugin_prep_mem_callbacks(addr);
69 gen_ldst_i32(INDEX_op_qemu_ld_i32, val, addr, memop, idx);
70 plugin_gen_mem_callbacks(addr, info);
71
72@@ -2868,6 +2882,7 @@ void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, MemOp memop)
73 memop &= ~MO_BSWAP;
74 }
75
76+ addr = plugin_prep_mem_callbacks(addr);
77 gen_ldst_i32(INDEX_op_qemu_st_i32, val, addr, memop, idx);
78 plugin_gen_mem_callbacks(addr, info);
79
80@@ -2905,6 +2920,7 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, MemOp memop)
81 }
82 }
83
84+ addr = plugin_prep_mem_callbacks(addr);
85 gen_ldst_i64(INDEX_op_qemu_ld_i64, val, addr, memop, idx);
86 plugin_gen_mem_callbacks(addr, info);
87
88@@ -2967,6 +2983,7 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, MemOp memop)
89 memop &= ~MO_BSWAP;
90 }
91
92+ addr = plugin_prep_mem_callbacks(addr);
93 gen_ldst_i64(INDEX_op_qemu_st_i64, val, addr, memop, idx);
94 plugin_gen_mem_callbacks(addr, info);
95
96--
972.25.1
98
diff --git a/debian/patches/stable/lp-1867519-tpm-ppi-page-align-PPI-RAM.patch b/debian/patches/stable/lp-1867519-tpm-ppi-page-align-PPI-RAM.patch
0new file mode 10064499new file mode 100644
index 0000000..209bd3e
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-tpm-ppi-page-align-PPI-RAM.patch
@@ -0,0 +1,47 @@
1From 71e415c8a75c130875f14d6b2136825789feb297 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
3Date: Fri, 3 Jan 2020 11:39:59 +0400
4Subject: [PATCH] tpm-ppi: page-align PPI RAM
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9post-copy migration fails on destination with error such as:
102019-12-26T10:22:44.714644Z qemu-kvm: ram_block_discard_range:
11Unaligned start address: 0x559d2afae9a0
12
13Use qemu_memalign() to constrain the PPI RAM memory alignment.
14
15Cc: qemu-stable@nongnu.org
16Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
17Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
18Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
19Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
20Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
21Message-id: 20200103074000.1006389-3-marcandre.lureau@redhat.com
22
23Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=71e415c8a75c130875f14d6b2136825789feb297
24Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
25Last-Update: 2020-03-18
26
27---
28 hw/tpm/tpm_ppi.c | 3 ++-
29 1 file changed, 2 insertions(+), 1 deletion(-)
30
31diff --git a/hw/tpm/tpm_ppi.c b/hw/tpm/tpm_ppi.c
32index ff314592b4..6d9c1a3e40 100644
33--- a/hw/tpm/tpm_ppi.c
34+++ b/hw/tpm/tpm_ppi.c
35@@ -43,7 +43,8 @@ void tpm_ppi_reset(TPMPPI *tpmppi)
36 void tpm_ppi_init(TPMPPI *tpmppi, struct MemoryRegion *m,
37 hwaddr addr, Object *obj)
38 {
39- tpmppi->buf = g_malloc0(HOST_PAGE_ALIGN(TPM_PPI_ADDR_SIZE));
40+ tpmppi->buf = qemu_memalign(qemu_real_host_page_size,
41+ HOST_PAGE_ALIGN(TPM_PPI_ADDR_SIZE));
42 memory_region_init_ram_device_ptr(&tpmppi->ram, obj, "tpm-ppi",
43 TPM_PPI_ADDR_SIZE, tpmppi->buf);
44 vmstate_register_ram(&tpmppi->ram, DEVICE(obj));
45--
462.25.1
47
diff --git a/debian/patches/stable/lp-1867519-vfio-pci-Don-t-remove-irqchip-notifier-if-not-regist.patch b/debian/patches/stable/lp-1867519-vfio-pci-Don-t-remove-irqchip-notifier-if-not-regist.patch
0new file mode 10064448new file mode 100644
index 0000000..f52b1bd
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-vfio-pci-Don-t-remove-irqchip-notifier-if-not-regist.patch
@@ -0,0 +1,50 @@
1From 0446f8121723b134ca1d1ed0b73e96d4a0a8689d Mon Sep 17 00:00:00 2001
2From: Peter Xu <peterx@redhat.com>
3Date: Mon, 6 Jan 2020 13:34:45 -0700
4Subject: [PATCH] vfio/pci: Don't remove irqchip notifier if not registered
5
6The kvm irqchip notifier is only registered if the device supports
7INTx, however it's unconditionally removed. If the assigned device
8does not support INTx, this will cause QEMU to crash when unplugging
9the device from the system. Change it to conditionally remove the
10notifier only if the notify hook is setup.
11
12CC: Eduardo Habkost <ehabkost@redhat.com>
13CC: David Gibson <david@gibson.dropbear.id.au>
14CC: Alex Williamson <alex.williamson@redhat.com>
15Cc: qemu-stable@nongnu.org # v4.2
16Reported-by: yanghliu@redhat.com
17Debugged-by: Eduardo Habkost <ehabkost@redhat.com>
18Fixes: c5478fea27ac ("vfio/pci: Respond to KVM irqchip change notifier")
19Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1782678
20Signed-off-by: Peter Xu <peterx@redhat.com>
21Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
22Reviewed-by: Greg Kurz <groug@kaod.org>
23Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
24
25Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=0446f8121723b134ca1d1ed0b73e96d4a0a8689d
26Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
27Last-Update: 2020-03-18
28
29---
30 hw/vfio/pci.c | 4 +++-
31 1 file changed, 3 insertions(+), 1 deletion(-)
32
33diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
34index 2d40b396f2..337a173ce7 100644
35--- a/hw/vfio/pci.c
36+++ b/hw/vfio/pci.c
37@@ -3076,7 +3076,9 @@ static void vfio_exitfn(PCIDevice *pdev)
38 vfio_unregister_req_notifier(vdev);
39 vfio_unregister_err_notifier(vdev);
40 pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
41- kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
42+ if (vdev->irqchip_change_notifier.notify) {
43+ kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
44+ }
45 vfio_disable_interrupts(vdev);
46 if (vdev->intx.mmap_timer) {
47 timer_free(vdev->intx.mmap_timer);
48--
492.25.1
50
diff --git a/debian/patches/stable/lp-1867519-virtio-gracefully-handle-invalid-region-caches.patch b/debian/patches/stable/lp-1867519-virtio-gracefully-handle-invalid-region-caches.patch
0new file mode 10064451new file mode 100644
index 0000000..177cafe
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-virtio-gracefully-handle-invalid-region-caches.patch
@@ -0,0 +1,331 @@
1From abdd16f4681cc4d6bf84990227b5c9b98e869ccd Mon Sep 17 00:00:00 2001
2From: Stefan Hajnoczi <stefanha@redhat.com>
3Date: Fri, 7 Feb 2020 10:46:19 +0000
4Subject: [PATCH] virtio: gracefully handle invalid region caches
5
6The virtqueue code sets up MemoryRegionCaches to access the virtqueue
7guest RAM data structures. The code currently assumes that
8VRingMemoryRegionCaches is initialized before device emulation code
9accesses the virtqueue. An assertion will fail in
10vring_get_region_caches() when this is not true. Device fuzzing found a
11case where this assumption is false (see below).
12
13Virtqueue guest RAM addresses can also be changed from a vCPU thread
14while an IOThread is accessing the virtqueue. This breaks the same
15assumption but this time the caches could become invalid partway through
16the virtqueue code. The code fetches the caches RCU pointer multiple
17times so we will need to validate the pointer every time it is fetched.
18
19Add checks each time we call vring_get_region_caches() and treat invalid
20caches as a nop: memory stores are ignored and memory reads return 0.
21
22The fuzz test failure is as follows:
23
24 $ qemu -M pc -device virtio-blk-pci,id=drv0,drive=drive0,addr=4.0 \
25 -drive if=none,id=drive0,file=null-co://,format=raw,auto-read-only=off \
26 -drive if=none,id=drive1,file=null-co://,file.read-zeroes=on,format=raw \
27 -display none \
28 -qtest stdio
29 endianness
30 outl 0xcf8 0x80002020
31 outl 0xcfc 0xe0000000
32 outl 0xcf8 0x80002004
33 outw 0xcfc 0x7
34 write 0xe0000000 0x24 0x00ffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffab5cffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffab0000000001
35 inb 0x4
36 writew 0xe000001c 0x1
37 write 0xe0000014 0x1 0x0d
38
39The following error message is produced:
40
41 qemu-system-x86_64: /home/stefanha/qemu/hw/virtio/virtio.c:286: vring_get_region_caches: Assertion `caches != NULL' failed.
42
43The backtrace looks like this:
44
45 #0 0x00007ffff5520625 in raise () at /lib64/libc.so.6
46 #1 0x00007ffff55098d9 in abort () at /lib64/libc.so.6
47 #2 0x00007ffff55097a9 in _nl_load_domain.cold () at /lib64/libc.so.6
48 #3 0x00007ffff5518a66 in annobin_assert.c_end () at /lib64/libc.so.6
49 #4 0x00005555559073da in vring_get_region_caches (vq=<optimized out>) at qemu/hw/virtio/virtio.c:286
50 #5 vring_get_region_caches (vq=<optimized out>) at qemu/hw/virtio/virtio.c:283
51 #6 0x000055555590818d in vring_used_flags_set_bit (mask=1, vq=0x5555575ceea0) at qemu/hw/virtio/virtio.c:398
52 #7 virtio_queue_split_set_notification (enable=0, vq=0x5555575ceea0) at qemu/hw/virtio/virtio.c:398
53 #8 virtio_queue_set_notification (vq=vq@entry=0x5555575ceea0, enable=enable@entry=0) at qemu/hw/virtio/virtio.c:451
54 #9 0x0000555555908512 in virtio_queue_set_notification (vq=vq@entry=0x5555575ceea0, enable=enable@entry=0) at qemu/hw/virtio/virtio.c:444
55 #10 0x00005555558c697a in virtio_blk_handle_vq (s=0x5555575c57e0, vq=0x5555575ceea0) at qemu/hw/block/virtio-blk.c:775
56 #11 0x0000555555907836 in virtio_queue_notify_aio_vq (vq=0x5555575ceea0) at qemu/hw/virtio/virtio.c:2244
57 #12 0x0000555555cb5dd7 in aio_dispatch_handlers (ctx=ctx@entry=0x55555671a420) at util/aio-posix.c:429
58 #13 0x0000555555cb67a8 in aio_dispatch (ctx=0x55555671a420) at util/aio-posix.c:460
59 #14 0x0000555555cb307e in aio_ctx_dispatch (source=<optimized out>, callback=<optimized out>, user_data=<optimized out>) at util/async.c:260
60 #15 0x00007ffff7bbc510 in g_main_context_dispatch () at /lib64/libglib-2.0.so.0
61 #16 0x0000555555cb5848 in glib_pollfds_poll () at util/main-loop.c:219
62 #17 os_host_main_loop_wait (timeout=<optimized out>) at util/main-loop.c:242
63 #18 main_loop_wait (nonblocking=<optimized out>) at util/main-loop.c:518
64 #19 0x00005555559b20c9 in main_loop () at vl.c:1683
65 #20 0x0000555555838115 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at vl.c:4441
66
67Reported-by: Alexander Bulekov <alxndr@bu.edu>
68Cc: Michael Tsirkin <mst@redhat.com>
69Cc: Cornelia Huck <cohuck@redhat.com>
70Cc: Paolo Bonzini <pbonzini@redhat.com>
71Cc: qemu-stable@nongnu.org
72Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
73Message-Id: <20200207104619.164892-1-stefanha@redhat.com>
74Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
75Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
76
77Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=abdd16f4681cc4d6bf84990227b5c9b98e869ccd
78Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
79Last-Update: 2020-03-18
80
81---
82 hw/virtio/virtio.c | 99 ++++++++++++++++++++++++++++++++++++++++++----
83 1 file changed, 91 insertions(+), 8 deletions(-)
84
85diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
86index 2c5410e981..00d444699d 100644
87--- a/hw/virtio/virtio.c
88+++ b/hw/virtio/virtio.c
89@@ -282,15 +282,19 @@ static void vring_packed_flags_write(VirtIODevice *vdev,
90 /* Called within rcu_read_lock(). */
91 static VRingMemoryRegionCaches *vring_get_region_caches(struct VirtQueue *vq)
92 {
93- VRingMemoryRegionCaches *caches = atomic_rcu_read(&vq->vring.caches);
94- assert(caches != NULL);
95- return caches;
96+ return atomic_rcu_read(&vq->vring.caches);
97 }
98+
99 /* Called within rcu_read_lock(). */
100 static inline uint16_t vring_avail_flags(VirtQueue *vq)
101 {
102 VRingMemoryRegionCaches *caches = vring_get_region_caches(vq);
103 hwaddr pa = offsetof(VRingAvail, flags);
104+
105+ if (!caches) {
106+ return 0;
107+ }
108+
109 return virtio_lduw_phys_cached(vq->vdev, &caches->avail, pa);
110 }
111
112@@ -299,6 +303,11 @@ static inline uint16_t vring_avail_idx(VirtQueue *vq)
113 {
114 VRingMemoryRegionCaches *caches = vring_get_region_caches(vq);
115 hwaddr pa = offsetof(VRingAvail, idx);
116+
117+ if (!caches) {
118+ return 0;
119+ }
120+
121 vq->shadow_avail_idx = virtio_lduw_phys_cached(vq->vdev, &caches->avail, pa);
122 return vq->shadow_avail_idx;
123 }
124@@ -308,6 +317,11 @@ static inline uint16_t vring_avail_ring(VirtQueue *vq, int i)
125 {
126 VRingMemoryRegionCaches *caches = vring_get_region_caches(vq);
127 hwaddr pa = offsetof(VRingAvail, ring[i]);
128+
129+ if (!caches) {
130+ return 0;
131+ }
132+
133 return virtio_lduw_phys_cached(vq->vdev, &caches->avail, pa);
134 }
135
136@@ -323,6 +337,11 @@ static inline void vring_used_write(VirtQueue *vq, VRingUsedElem *uelem,
137 {
138 VRingMemoryRegionCaches *caches = vring_get_region_caches(vq);
139 hwaddr pa = offsetof(VRingUsed, ring[i]);
140+
141+ if (!caches) {
142+ return;
143+ }
144+
145 virtio_tswap32s(vq->vdev, &uelem->id);
146 virtio_tswap32s(vq->vdev, &uelem->len);
147 address_space_write_cached(&caches->used, pa, uelem, sizeof(VRingUsedElem));
148@@ -334,6 +353,11 @@ static uint16_t vring_used_idx(VirtQueue *vq)
149 {
150 VRingMemoryRegionCaches *caches = vring_get_region_caches(vq);
151 hwaddr pa = offsetof(VRingUsed, idx);
152+
153+ if (!caches) {
154+ return 0;
155+ }
156+
157 return virtio_lduw_phys_cached(vq->vdev, &caches->used, pa);
158 }
159
160@@ -342,8 +366,12 @@ static inline void vring_used_idx_set(VirtQueue *vq, uint16_t val)
161 {
162 VRingMemoryRegionCaches *caches = vring_get_region_caches(vq);
163 hwaddr pa = offsetof(VRingUsed, idx);
164- virtio_stw_phys_cached(vq->vdev, &caches->used, pa, val);
165- address_space_cache_invalidate(&caches->used, pa, sizeof(val));
166+
167+ if (caches) {
168+ virtio_stw_phys_cached(vq->vdev, &caches->used, pa, val);
169+ address_space_cache_invalidate(&caches->used, pa, sizeof(val));
170+ }
171+
172 vq->used_idx = val;
173 }
174
175@@ -353,8 +381,13 @@ static inline void vring_used_flags_set_bit(VirtQueue *vq, int mask)
176 VRingMemoryRegionCaches *caches = vring_get_region_caches(vq);
177 VirtIODevice *vdev = vq->vdev;
178 hwaddr pa = offsetof(VRingUsed, flags);
179- uint16_t flags = virtio_lduw_phys_cached(vq->vdev, &caches->used, pa);
180+ uint16_t flags;
181
182+ if (!caches) {
183+ return;
184+ }
185+
186+ flags = virtio_lduw_phys_cached(vq->vdev, &caches->used, pa);
187 virtio_stw_phys_cached(vdev, &caches->used, pa, flags | mask);
188 address_space_cache_invalidate(&caches->used, pa, sizeof(flags));
189 }
190@@ -365,8 +398,13 @@ static inline void vring_used_flags_unset_bit(VirtQueue *vq, int mask)
191 VRingMemoryRegionCaches *caches = vring_get_region_caches(vq);
192 VirtIODevice *vdev = vq->vdev;
193 hwaddr pa = offsetof(VRingUsed, flags);
194- uint16_t flags = virtio_lduw_phys_cached(vq->vdev, &caches->used, pa);
195+ uint16_t flags;
196
197+ if (!caches) {
198+ return;
199+ }
200+
201+ flags = virtio_lduw_phys_cached(vq->vdev, &caches->used, pa);
202 virtio_stw_phys_cached(vdev, &caches->used, pa, flags & ~mask);
203 address_space_cache_invalidate(&caches->used, pa, sizeof(flags));
204 }
205@@ -381,6 +419,10 @@ static inline void vring_set_avail_event(VirtQueue *vq, uint16_t val)
206 }
207
208 caches = vring_get_region_caches(vq);
209+ if (!caches) {
210+ return;
211+ }
212+
213 pa = offsetof(VRingUsed, ring[vq->vring.num]);
214 virtio_stw_phys_cached(vq->vdev, &caches->used, pa, val);
215 address_space_cache_invalidate(&caches->used, pa, sizeof(val));
216@@ -410,7 +452,11 @@ static void virtio_queue_packed_set_notification(VirtQueue *vq, int enable)
217 VRingMemoryRegionCaches *caches;
218
219 RCU_READ_LOCK_GUARD();
220- caches = vring_get_region_caches(vq);
221+ caches = vring_get_region_caches(vq);
222+ if (!caches) {
223+ return;
224+ }
225+
226 vring_packed_event_read(vq->vdev, &caches->used, &e);
227
228 if (!enable) {
229@@ -597,6 +643,10 @@ static int virtio_queue_packed_empty_rcu(VirtQueue *vq)
230 }
231
232 cache = vring_get_region_caches(vq);
233+ if (!cache) {
234+ return 1;
235+ }
236+
237 vring_packed_desc_read_flags(vq->vdev, &desc.flags, &cache->desc,
238 vq->last_avail_idx);
239
240@@ -777,6 +827,10 @@ static void virtqueue_packed_fill_desc(VirtQueue *vq,
241 }
242
243 caches = vring_get_region_caches(vq);
244+ if (!caches) {
245+ return;
246+ }
247+
248 vring_packed_desc_write(vq->vdev, &desc, &caches->desc, head, strict_order);
249 }
250
251@@ -949,6 +1003,10 @@ static void virtqueue_split_get_avail_bytes(VirtQueue *vq,
252
253 max = vq->vring.num;
254 caches = vring_get_region_caches(vq);
255+ if (!caches) {
256+ goto err;
257+ }
258+
259 while ((rc = virtqueue_num_heads(vq, idx)) > 0) {
260 MemoryRegionCache *desc_cache = &caches->desc;
261 unsigned int num_bufs;
262@@ -1089,6 +1147,9 @@ static void virtqueue_packed_get_avail_bytes(VirtQueue *vq,
263
264 max = vq->vring.num;
265 caches = vring_get_region_caches(vq);
266+ if (!caches) {
267+ goto err;
268+ }
269
270 for (;;) {
271 unsigned int num_bufs = total_bufs;
272@@ -1194,6 +1255,10 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
273 }
274
275 caches = vring_get_region_caches(vq);
276+ if (!caches) {
277+ goto err;
278+ }
279+
280 desc_size = virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED) ?
281 sizeof(VRingPackedDesc) : sizeof(VRingDesc);
282 if (caches->desc.len < vq->vring.num * desc_size) {
283@@ -1387,6 +1452,11 @@ static void *virtqueue_split_pop(VirtQueue *vq, size_t sz)
284 i = head;
285
286 caches = vring_get_region_caches(vq);
287+ if (!caches) {
288+ virtio_error(vdev, "Region caches not initialized");
289+ goto done;
290+ }
291+
292 if (caches->desc.len < max * sizeof(VRingDesc)) {
293 virtio_error(vdev, "Cannot map descriptor ring");
294 goto done;
295@@ -1509,6 +1579,11 @@ static void *virtqueue_packed_pop(VirtQueue *vq, size_t sz)
296 i = vq->last_avail_idx;
297
298 caches = vring_get_region_caches(vq);
299+ if (!caches) {
300+ virtio_error(vdev, "Region caches not initialized");
301+ goto done;
302+ }
303+
304 if (caches->desc.len < max * sizeof(VRingDesc)) {
305 virtio_error(vdev, "Cannot map descriptor ring");
306 goto done;
307@@ -1628,6 +1703,10 @@ static unsigned int virtqueue_packed_drop_all(VirtQueue *vq)
308 VRingPackedDesc desc;
309
310 caches = vring_get_region_caches(vq);
311+ if (!caches) {
312+ return 0;
313+ }
314+
315 desc_cache = &caches->desc;
316
317 virtio_queue_set_notification(vq, 0);
318@@ -2412,6 +2491,10 @@ static bool virtio_packed_should_notify(VirtIODevice *vdev, VirtQueue *vq)
319 VRingMemoryRegionCaches *caches;
320
321 caches = vring_get_region_caches(vq);
322+ if (!caches) {
323+ return false;
324+ }
325+
326 vring_packed_event_read(vdev, &caches->avail, &e);
327
328 old = vq->signalled_used;
329--
3302.25.1
331
diff --git a/debian/patches/stable/lp-1867519-virtio-mmio-update-queue-size-on-guest-write.patch b/debian/patches/stable/lp-1867519-virtio-mmio-update-queue-size-on-guest-write.patch
0new file mode 100644332new file mode 100644
index 0000000..d18b0ee
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-virtio-mmio-update-queue-size-on-guest-write.patch
@@ -0,0 +1,40 @@
1From 1049f4c62c4070618cc5defc9963c6a17ae7a5ae Mon Sep 17 00:00:00 2001
2From: Denis Plotnikov <dplotnikov@virtuozzo.com>
3Date: Tue, 24 Dec 2019 11:14:46 +0300
4Subject: [PATCH] virtio-mmio: update queue size on guest write
5
6Some guests read back queue size after writing it.
7Always update the on size write otherwise they might be confused.
8
9Cc: qemu-stable@nongnu.org
10Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
11Message-Id: <20191224081446.17003-1-dplotnikov@virtuozzo.com>
12Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
13Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
14
15Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=1049f4c62c4070618cc5defc9963c6a17ae7a5ae
16Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
17Last-Update: 2020-03-18
18
19---
20 hw/virtio/virtio-mmio.c | 3 ++-
21 1 file changed, 2 insertions(+), 1 deletion(-)
22
23diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
24index ef40b7a9b2..872f2cd237 100644
25--- a/hw/virtio/virtio-mmio.c
26+++ b/hw/virtio/virtio-mmio.c
27@@ -308,8 +308,9 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value,
28 break;
29 case VIRTIO_MMIO_QUEUE_NUM:
30 trace_virtio_mmio_queue_write(value, VIRTQUEUE_MAX_SIZE);
31+ virtio_queue_set_num(vdev, vdev->queue_sel, value);
32+
33 if (proxy->legacy) {
34- virtio_queue_set_num(vdev, vdev->queue_sel, value);
35 virtio_queue_update_rings(vdev, vdev->queue_sel);
36 } else {
37 proxy->vqs[vdev->queue_sel].num = value;
38--
392.25.1
40
diff --git a/debian/patches/stable/lp-1867519-virtio-net-delete-also-control-queue-when-TX-RX-dele.patch b/debian/patches/stable/lp-1867519-virtio-net-delete-also-control-queue-when-TX-RX-dele.patch
0new file mode 10064441new file mode 100644
index 0000000..1db89ff
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-virtio-net-delete-also-control-queue-when-TX-RX-dele.patch
@@ -0,0 +1,41 @@
1From d945d9f1731244ef341f74ede93120fc9de35913 Mon Sep 17 00:00:00 2001
2From: Yuri Benditovich <yuri.benditovich@daynix.com>
3Date: Thu, 26 Dec 2019 06:36:49 +0200
4Subject: [PATCH] virtio-net: delete also control queue when TX/RX deleted
5
6https://bugzilla.redhat.com/show_bug.cgi?id=1708480
7If the control queue is not deleted together with TX/RX, it
8later will be ignored in freeing cache resources and hot
9unplug will not be completed.
10
11Cc: qemu-stable@nongnu.org
12Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
13Message-Id: <20191226043649.14481-3-yuri.benditovich@daynix.com>
14Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
15Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
16
17Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=d945d9f1731244ef341f74ede93120fc9de35913
18Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
19Last-Update: 2020-03-18
20
21---
22 hw/net/virtio-net.c | 3 ++-
23 1 file changed, 2 insertions(+), 1 deletion(-)
24
25diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
26index db3d7c38e6..f325440d01 100644
27--- a/hw/net/virtio-net.c
28+++ b/hw/net/virtio-net.c
29@@ -3101,7 +3101,8 @@ static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
30 for (i = 0; i < max_queues; i++) {
31 virtio_net_del_queue(n, i);
32 }
33-
34+ /* delete also control vq */
35+ virtio_del_queue(vdev, max_queues * 2);
36 qemu_announce_timer_del(&n->announce_timer, false);
37 g_free(n->vqs);
38 qemu_del_nic(n->nic);
39--
402.25.1
41
diff --git a/debian/patches/stable/lp-1867519-virtio-update-queue-size-on-guest-write.patch b/debian/patches/stable/lp-1867519-virtio-update-queue-size-on-guest-write.patch
0new file mode 10064442new file mode 100644
index 0000000..da81c2c
--- /dev/null
+++ b/debian/patches/stable/lp-1867519-virtio-update-queue-size-on-guest-write.patch
@@ -0,0 +1,40 @@
1From d0c5f643383b9e84316f148affff368ac33d75b9 Mon Sep 17 00:00:00 2001
2From: "Michael S. Tsirkin" <mst@redhat.com>
3Date: Fri, 13 Dec 2019 09:22:48 -0500
4Subject: [PATCH] virtio: update queue size on guest write
5
6Some guests read back queue size after writing it.
7Update the size immediatly upon write otherwise
8they get confused.
9
10In particular this is the case for seabios.
11
12Reported-by: Roman Kagan <rkagan@virtuozzo.com>
13Suggested-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
14Cc: qemu-stable@nongnu.org
15Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
16
17Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=d0c5f643383b9e84316f148affff368ac33d75b9
18Bug-Ubuntu: https://bugs.launchpad.net/bugs/1867519
19Last-Update: 2020-03-18
20
21---
22 hw/virtio/virtio-pci.c | 2 ++
23 1 file changed, 2 insertions(+)
24
25diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
26index c6b47a9c73..e5c759e19e 100644
27--- a/hw/virtio/virtio-pci.c
28+++ b/hw/virtio/virtio-pci.c
29@@ -1256,6 +1256,8 @@ static void virtio_pci_common_write(void *opaque, hwaddr addr,
30 break;
31 case VIRTIO_PCI_COMMON_Q_SIZE:
32 proxy->vqs[vdev->queue_sel].num = val;
33+ virtio_queue_set_num(vdev, vdev->queue_sel,
34+ proxy->vqs[vdev->queue_sel].num);
35 break;
36 case VIRTIO_PCI_COMMON_Q_MSIX:
37 msix_vector_unuse(&proxy->pci_dev,
38--
392.25.1
40
diff --git a/debian/patches/ubuntu/lp-1847361-modules-load-upgrade.patch b/debian/patches/ubuntu/lp-1847361-modules-load-upgrade.patch
0new file mode 10064441new file mode 100644
index 0000000..056f2e0
--- /dev/null
+++ b/debian/patches/ubuntu/lp-1847361-modules-load-upgrade.patch
@@ -0,0 +1,125 @@
1From ab7e28b0905b1e2daeb5d582cf0f0ce33ea47317 Mon Sep 17 00:00:00 2001
2From: Christian Ehrhardt <christian.ehrhardt@canonical.com>
3Date: Mon, 2 Mar 2020 15:12:53 +0100
4Subject: [PATCH] modules: load modules from versioned /var/run dir
5
6On upgrades the old .so files usually are replaced. But on the other
7hand since a qemu process represents a guest instance it is usually kept
8around.
9
10That makes late addition of dynamic features e.g. 'hot-attach of a ceph
11disk' fail by trying to load a new version of e.f. block-rbd.so into an
12old still running qemu binary.
13
14This adds a fallback to also load modules from a versioned directory in the
15temporary /var/run path. That way qemu is providing a way for packaging
16to store modules of an upgraded qemu package as needed until the next reboot.
17
18Fixes: https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1847361
19Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
20
21Forwarded: yes, https://lists.nongnu.org/archive/html/qemu-devel/2020-03/msg01593.html
22Bug-Ubuntu: https://bugs.launchpad.net/bugs/1847361
23Last-Update: 2020-03-02
24
25---
26 configure | 15 +++++++++++++++
27 util/module.c | 14 ++++++++++++++
28 2 files changed, 29 insertions(+)
29
30--- a/configure
31+++ b/configure
32@@ -404,6 +404,7 @@ EXESUF=""
33 DSOSUF=".so"
34 LDFLAGS_SHARED="-shared"
35 modules="no"
36+module_upgrades="no"
37 prefix="/usr/local"
38 mandir="\${prefix}/share/man"
39 datadir="\${prefix}/share"
40@@ -995,6 +996,10 @@ for opt do
41 --disable-modules)
42 modules="no"
43 ;;
44+ --disable-module-upgrades) module_upgrades="no"
45+ ;;
46+ --enable-module-upgrades) module_upgrades="yes"
47+ ;;
48 --cpu=*)
49 ;;
50 --target-list=*) target_list="$optarg"
51@@ -1735,6 +1740,7 @@ disabled with --disable-FEATURE, default
52 guest-agent-msi build guest agent Windows MSI installation package
53 pie Position Independent Executables
54 modules modules support (non-Windows)
55+ module-upgrades try to load modules from alternate paths for upgrades
56 debug-tcg TCG debugging (default is disabled)
57 debug-info debugging information
58 sparse sparse checker
59@@ -1995,6 +2001,11 @@ if test "$modules" = "yes" && test "$min
60 error_exit "Modules are not available for Windows"
61 fi
62
63+# module_upgrades is only reasonable if modules are enabled
64+if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
65+ error_exit "Can't enable module-upgrades as Modules are not enabled"
66+fi
67+
68 # Static linking is not possible with modules or PIE
69 if test "$static" = "yes" ; then
70 if test "$modules" = "yes" ; then
71@@ -6457,6 +6468,7 @@ if test "$slirp" != "no" ; then
72 echo "smbd $smbd"
73 fi
74 echo "module support $modules"
75+echo "alt path mod load $module_upgrades"
76 echo "host CPU $cpu"
77 echo "host big endian $bigendian"
78 echo "target list $target_list"
79@@ -6814,6 +6826,9 @@ if test "$modules" = "yes"; then
80 echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
81 echo "CONFIG_MODULES=y" >> $config_host_mak
82 fi
83+if test "$module_upgrades" = "yes"; then
84+ echo "CONFIG_MODULE_UPGRADES=y" >> $config_host_mak
85+fi
86 if test "$have_x11" = "yes" && test "$need_x11" = "yes"; then
87 echo "CONFIG_X11=y" >> $config_host_mak
88 echo "X11_CFLAGS=$x11_cflags" >> $config_host_mak
89--- a/util/module.c
90+++ b/util/module.c
91@@ -19,6 +19,9 @@
92 #endif
93 #include "qemu/queue.h"
94 #include "qemu/module.h"
95+#ifdef CONFIG_MODULE_UPGRADES
96+#include "qemu-version.h"
97+#endif
98
99 typedef struct ModuleEntry
100 {
101@@ -163,6 +166,9 @@ bool module_load_one(const char *prefix,
102 #ifdef CONFIG_MODULES
103 char *fname = NULL;
104 char *exec_dir;
105+#ifdef CONFIG_MODULE_UPGRADES
106+ char *version_dir;
107+#endif
108 const char *search_dir;
109 char *dirs[4];
110 char *module_name;
111@@ -194,6 +200,14 @@ bool module_load_one(const char *prefix,
112 dirs[n_dirs++] = g_strdup_printf("%s", CONFIG_QEMU_MODDIR);
113 dirs[n_dirs++] = g_strdup_printf("%s/..", exec_dir ? : "");
114 dirs[n_dirs++] = g_strdup_printf("%s", exec_dir ? : "");
115+
116+#ifdef CONFIG_MODULE_UPGRADES
117+ version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION),
118+ G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "+-.~",
119+ '_');
120+ dirs[n_dirs++] = g_strdup_printf("/var/run/qemu/%s", version_dir);
121+#endif
122+
123 assert(n_dirs <= ARRAY_SIZE(dirs));
124
125 g_free(exec_dir);
diff --git a/debian/patches/ubuntu/lp-1847361-vhost-correctly-turn-on-VIRTIO_F_IOMMU_PLATFORM.patch b/debian/patches/ubuntu/lp-1847361-vhost-correctly-turn-on-VIRTIO_F_IOMMU_PLATFORM.patch
0new file mode 100644126new file mode 100644
index 0000000..6ef5d49
--- /dev/null
+++ b/debian/patches/ubuntu/lp-1847361-vhost-correctly-turn-on-VIRTIO_F_IOMMU_PLATFORM.patch
@@ -0,0 +1,61 @@
1From f7ef7e6e3ba6e994e070cc609eb154339d1c4a11 Mon Sep 17 00:00:00 2001
2From: Jason Wang <jasowang@redhat.com>
3Date: Mon, 2 Mar 2020 12:24:54 +0800
4Subject: [PATCH] vhost: correctly turn on VIRTIO_F_IOMMU_PLATFORM
5
6We turn on device IOTLB via VIRTIO_F_IOMMU_PLATFORM unconditionally on
7platform without IOMMU support. This can lead unnecessary IOTLB
8transactions which will damage the performance.
9
10Fixing this by check whether the device is backed by IOMMU and disable
11device IOTLB.
12
13Reported-by: Halil Pasic <pasic@linux.ibm.com>
14Tested-by: Halil Pasic <pasic@linux.ibm.com>
15Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
16Signed-off-by: Jason Wang <jasowang@redhat.com>
17Message-Id: <20200302042454.24814-1-jasowang@redhat.com>
18Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
19Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
20
21Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=f7ef7e6e3ba6e994e070cc609eb154339d1c4a11
22Bug-Ubuntu: https://bugs.launchpad.net/bugs/1847361
23Last-Update: 2020-03-13
24
25---
26 hw/virtio/vhost.c | 12 +++++++++++-
27 1 file changed, 11 insertions(+), 1 deletion(-)
28
29diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
30index 0d226dae10..01ebe12f28 100644
31--- a/hw/virtio/vhost.c
32+++ b/hw/virtio/vhost.c
33@@ -290,7 +290,14 @@ static int vhost_dev_has_iommu(struct vhost_dev *dev)
34 {
35 VirtIODevice *vdev = dev->vdev;
36
37- return virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
38+ /*
39+ * For vhost, VIRTIO_F_IOMMU_PLATFORM means the backend support
40+ * incremental memory mapping API via IOTLB API. For platform that
41+ * does not have IOMMU, there's no need to enable this feature
42+ * which may cause unnecessary IOTLB miss/update trnasactions.
43+ */
44+ return vdev->dma_as != &address_space_memory &&
45+ virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
46 }
47
48 static void *vhost_memory_map(struct vhost_dev *dev, hwaddr addr,
49@@ -765,6 +772,9 @@ static int vhost_dev_set_features(struct vhost_dev *dev,
50 if (enable_log) {
51 features |= 0x1ULL << VHOST_F_LOG_ALL;
52 }
53+ if (!vhost_dev_has_iommu(dev)) {
54+ features &= ~(0x1ULL << VIRTIO_F_IOMMU_PLATFORM);
55+ }
56 r = dev->vhost_ops->vhost_set_features(dev, features);
57 if (r < 0) {
58 VHOST_OPS_DEBUG("vhost_set_features failed");
59--
602.25.1
61
diff --git a/debian/qemu-block-extra.postrm.in b/debian/qemu-block-extra.postrm.in
0new file mode 10064462new file mode 100644
index 0000000..ef2126a
--- /dev/null
+++ b/debian/qemu-block-extra.postrm.in
@@ -0,0 +1,43 @@
1#!/bin/sh
2# postrm script for brrr
3#
4# see: dh_installdeb(1)
5
6set -e
7
8# summary of how this script can be called:
9# * <postrm> `remove'
10# * <postrm> `purge'
11# * <old-postrm> `upgrade' <new-version>
12# * <new-postrm> `failed-upgrade' <old-version>
13# * <new-postrm> `abort-install'
14# * <new-postrm> `abort-install' <old-version>
15# * <new-postrm> `abort-upgrade' <old-version>
16# * <disappearer's-postrm> `disappear' <overwriter>
17# <overwriter-version>
18# for details, see https://www.debian.org/doc/debian-policy/ or
19# the debian-policy package
20
21
22case "$1" in
23 purge|remove)
24 # remove .so files for still running qemu instances in /var/run
25 # for details see bug LP: #1847361
26 rm -f /var/run/qemu/@PKGVERSION@/block-*.so
27 ;;
28
29 upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
30 ;;
31
32 *)
33 echo "postrm called with unknown argument \`$1'" >&2
34 exit 1
35 ;;
36esac
37
38# dh_installdeb will replace this with shell code automatically
39# generated by other debhelper scripts.
40
41#DEBHELPER#
42
43exit 0
diff --git a/debian/qemu-block-extra.prerm.in b/debian/qemu-block-extra.prerm.in
0new file mode 10064444new file mode 100644
index 0000000..dee25a8
--- /dev/null
+++ b/debian/qemu-block-extra.prerm.in
@@ -0,0 +1,45 @@
1#!/bin/sh
2# prerm script for qemu-block-extra
3#
4# see: dh_installdeb(1)
5
6set -e
7
8# summary of how this script can be called:
9# * <prerm> `remove'
10# * <old-prerm> `upgrade' <new-version>
11# * <new-prerm> `failed-upgrade' <old-version>
12# * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
13# * <deconfigured's-prerm> `deconfigure' `in-favour'
14# <package-being-installed> <version> `removing'
15# <conflicting-package> <version>
16# for details, see https://www.debian.org/doc/debian-policy/ or
17# the debian-policy package
18
19
20case "$1" in
21 remove)
22 ;;
23
24 upgrade|deconfigure)
25 # retain .so files for still running qemu instances in /var/run
26 # for details see bug LP: #1847361
27 mkdir -p /var/run/qemu/@PKGVERSION@
28 cp /usr/lib/@ARCH@/qemu/block-*.so /var/run/qemu/@PKGVERSION@/
29 ;;
30
31 failed-upgrade)
32 ;;
33
34 *)
35 echo "prerm called with unknown argument \`$1'" >&2
36 exit 1
37 ;;
38esac
39
40# dh_installdeb will replace this with shell code automatically
41# generated by other debhelper scripts.
42
43#DEBHELPER#
44
45exit 0
diff --git a/debian/qemu-system-gui.postrm.in b/debian/qemu-system-gui.postrm.in
0new file mode 10064446new file mode 100644
index 0000000..48c740a
--- /dev/null
+++ b/debian/qemu-system-gui.postrm.in
@@ -0,0 +1,44 @@
1#!/bin/sh
2# postrm script for brrr
3#
4# see: dh_installdeb(1)
5
6set -e
7
8# summary of how this script can be called:
9# * <postrm> `remove'
10# * <postrm> `purge'
11# * <old-postrm> `upgrade' <new-version>
12# * <new-postrm> `failed-upgrade' <old-version>
13# * <new-postrm> `abort-install'
14# * <new-postrm> `abort-install' <old-version>
15# * <new-postrm> `abort-upgrade' <old-version>
16# * <disappearer's-postrm> `disappear' <overwriter>
17# <overwriter-version>
18# for details, see https://www.debian.org/doc/debian-policy/ or
19# the debian-policy package
20
21
22case "$1" in
23 purge|remove)
24 # remove .so files for still running qemu instances in /var/run
25 # for details see bug LP: #1847361
26 rm -f /var/run/qemu/@PKGVERSION@/ui-gtk.so
27 rm -f /var/run/qemu/@PKGVERSION@/audio-*.so
28 ;;
29
30 upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
31 ;;
32
33 *)
34 echo "postrm called with unknown argument \`$1'" >&2
35 exit 1
36 ;;
37esac
38
39# dh_installdeb will replace this with shell code automatically
40# generated by other debhelper scripts.
41
42#DEBHELPER#
43
44exit 0
diff --git a/debian/qemu-system-gui.prerm.in b/debian/qemu-system-gui.prerm.in
0new file mode 10064445new file mode 100644
index 0000000..3624362
--- /dev/null
+++ b/debian/qemu-system-gui.prerm.in
@@ -0,0 +1,46 @@
1#!/bin/sh
2# prerm script for qemu-system-gui
3#
4# see: dh_installdeb(1)
5
6set -e
7
8# summary of how this script can be called:
9# * <prerm> `remove'
10# * <old-prerm> `upgrade' <new-version>
11# * <new-prerm> `failed-upgrade' <old-version>
12# * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
13# * <deconfigured's-prerm> `deconfigure' `in-favour'
14# <package-being-installed> <version> `removing'
15# <conflicting-package> <version>
16# for details, see https://www.debian.org/doc/debian-policy/ or
17# the debian-policy package
18
19
20case "$1" in
21 remove)
22 ;;
23
24 upgrade|deconfigure)
25 # retain .so files for still running qemu instances in /var/run
26 # for details see bug LP: #1847361
27 mkdir -p /var/run/qemu/@PKGVERSION@
28 cp /usr/lib/@ARCH@/qemu/ui-gtk.so /var/run/qemu/@PKGVERSION@/
29 cp /usr/lib/@ARCH@/qemu/audio-*.so /var/run/qemu/@PKGVERSION@/
30 ;;
31
32 failed-upgrade)
33 ;;
34
35 *)
36 echo "prerm called with unknown argument \`$1'" >&2
37 exit 1
38 ;;
39esac
40
41# dh_installdeb will replace this with shell code automatically
42# generated by other debhelper scripts.
43
44#DEBHELPER#
45
46exit 0
diff --git a/debian/rules b/debian/rules
index 1604d33..58ed6ea 100755
--- a/debian/rules
+++ b/debian/rules
@@ -15,6 +15,9 @@ else
15VENDOR := DEBIAN15VENDOR := DEBIAN
16endif16endif
1717
18AUTOGENERATED:= qemu-block-extra.prerm qemu-block-extra.postrm qemu-system-gui.prerm qemu-system-gui.postrm
19PKGVERSION := $(shell printf "Debian ${DEB_VERSION}" | tr --complement '[:alnum:]+-.~' '_')
20
18# support parallel build using DEB_BUILD_OPTIONS=parallel=N21# support parallel build using DEB_BUILD_OPTIONS=parallel=N
19ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))22ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
20 MAKEFLAGS += -j$(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))23 MAKEFLAGS += -j$(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
@@ -103,6 +106,12 @@ endif # enable_linux_user
103b/configure-stamp: configure106b/configure-stamp: configure
104 dh_testdir107 dh_testdir
105108
109 for f in ${AUTOGENERATED} ; do \
110 sed -e 's%@ARCH@%${DEB_HOST_MULTIARCH}%g' \
111 -e 's%@PKGVERSION@%${PKGVERSION}%g' \
112 < debian/$$f.in > debian/$$f ; \
113 done
114
106 # system build115 # system build
107 rm -rf b/qemu; mkdir -p b/qemu116 rm -rf b/qemu; mkdir -p b/qemu
108 cd b/qemu && \117 cd b/qemu && \
@@ -111,6 +120,7 @@ b/configure-stamp: configure
111 --${enable_linux_user}-linux-user \120 --${enable_linux_user}-linux-user \
112 --disable-xen \121 --disable-xen \
113 --enable-modules \122 --enable-modules \
123 --enable-module-upgrades \
114 $(shell sh debian/extract-config-opts \124 $(shell sh debian/extract-config-opts \
115 $(DEB_HOST_ARCH_OS)-$(DEB_HOST_ARCH) debian/control) \125 $(DEB_HOST_ARCH_OS)-$(DEB_HOST_ARCH) debian/control) \
116 $(QEMU_CONFIGURE_OPTIONS) || \126 $(QEMU_CONFIGURE_OPTIONS) || \
@@ -137,6 +147,7 @@ ifneq ($(filter $(DEB_HOST_ARCH),amd64 i386),)
137 --enable-xen \147 --enable-xen \
138 --target-list="aarch64-softmmu arm-softmmu i386-softmmu x86_64-softmmu"148 --target-list="aarch64-softmmu arm-softmmu i386-softmmu x86_64-softmmu"
139 --enable-modules \149 --enable-modules \
150 --enable-module-upgrades \
140 $(shell sh debian/extract-config-opts \151 $(shell sh debian/extract-config-opts \
141 $(DEB_HOST_ARCH_OS)-$(DEB_HOST_ARCH) debian/control) \152 $(DEB_HOST_ARCH_OS)-$(DEB_HOST_ARCH) debian/control) \
142 $(QEMU_CONFIGURE_OPTIONS) || \153 $(QEMU_CONFIGURE_OPTIONS) || \
@@ -489,6 +500,7 @@ clean: debian/control
489 rm -rf b500 rm -rf b
490 find scripts/ -name '*.pyc' -delete || :501 find scripts/ -name '*.pyc' -delete || :
491 rm -f debian/qemu-user.1502 rm -f debian/qemu-user.1
503 rm -f $(patsubst %, debian/%, ${AUTOGENERATED})
492 dh_clean504 dh_clean
493505
494.PHONY: build clean binary-arch binary-indep binary build-arch build-indep build506.PHONY: build clean binary-arch binary-indep binary build-arch build-indep build

Subscribers

People subscribed via source and target branches