From c3bb66e65bc8d808a2261b3405438d7430e2b5b4 Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Sat, 26 Feb 2022 11:05:38 +0800 Subject: [PATCH 1/7] pl011: reset read FIFO when UARTTIMSC=0 & UARTICR=0xffff We can enable ACPI when AArch64 Linux is booted with QEMU and UEFI (AAVMF). When VM is booting and the SBSA driver has not initialized, writting data that exceds 32 bytes will cause the read FIFO full and proceeding data will be lost. The searil port appears to be stuck in this abnormal situation. A hack to reset read FIFO when UARTTIMSC=0 & UARTICR=0xffff appears to resolve the issue. The question is fully discussed at https://www.spinics.net/lists/linux-serial/msg23163.html Signed-off-by: Haibin Wang Reviewed-by: Shannon Zhao Reviewed-by: Ying Fang Signed-off-by: Yan Wang --- ...-FIFO-when-UARTTIMSC-0-UARTICR-0xfff.patch | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 pl011-reset-read-FIFO-when-UARTTIMSC-0-UARTICR-0xfff.patch diff --git a/pl011-reset-read-FIFO-when-UARTTIMSC-0-UARTICR-0xfff.patch b/pl011-reset-read-FIFO-when-UARTTIMSC-0-UARTICR-0xfff.patch new file mode 100644 index 0000000..a917143 --- /dev/null +++ b/pl011-reset-read-FIFO-when-UARTTIMSC-0-UARTICR-0xfff.patch @@ -0,0 +1,42 @@ +From 696abba190a0daad488d709d733f0d1f10df6f89 Mon Sep 17 00:00:00 2001 +From: Ying Fang +Date: Mon, 29 Jul 2019 16:16:35 +0800 +Subject: [PATCH 1/6] pl011: reset read FIFO when UARTTIMSC=0 & UARTICR=0xffff + +We can enable ACPI when AArch64 Linux is booted with QEMU and UEFI (AAVMF). +When VM is booting and the SBSA driver has not initialized, writting data +that exceds 32 bytes will cause the read FIFO full and proceeding data will +be lost. The searil port appears to be stuck in this abnormal situation. + +A hack to reset read FIFO when UARTTIMSC=0 & UARTICR=0xffff appears to +resolve the issue. + +The question is fully discussed at +https://www.spinics.net/lists/linux-serial/msg23163.html + +Signed-off-by: Haibin Wang +Reviewed-by: Shannon Zhao +Reviewed-by: Ying Fang +Signed-off-by: Yan Wang +--- + hw/char/pl011.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/hw/char/pl011.c b/hw/char/pl011.c +index 6e2d7f7..8ca2a4e 100644 +--- a/hw/char/pl011.c ++++ b/hw/char/pl011.c +@@ -255,6 +255,10 @@ static void pl011_write(void *opaque, hwaddr offset, + case 17: /* UARTICR */ + s->int_level &= ~value; + pl011_update(s); ++ if (!s->int_enabled && !s->int_level) { ++ s->read_count = 0; ++ s->read_pos = 0; ++ } + break; + case 18: /* UARTDMACR */ + s->dmacr = value; +-- +1.9.1 + -- Gitee From 17790cdc2f0899be77bf2cb8f15e6aa6c8b2c4ed Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Sat, 26 Feb 2022 11:06:47 +0800 Subject: [PATCH 2/7] qcow2: fix memory leak in qcow2_read_extensions Free feature_table if it is failed in bdrv_pread. Signed-off-by: fangyi Signed-off-by: Yan Wang --- ...memory-leak-in-qcow2_read_extensions.patch | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 qcow2-fix-memory-leak-in-qcow2_read_extensions.patch diff --git a/qcow2-fix-memory-leak-in-qcow2_read_extensions.patch b/qcow2-fix-memory-leak-in-qcow2_read_extensions.patch new file mode 100644 index 0000000..ae62942 --- /dev/null +++ b/qcow2-fix-memory-leak-in-qcow2_read_extensions.patch @@ -0,0 +1,28 @@ +From a999e010c6af90f0fc1ad9b998e2a9b760c40f1a Mon Sep 17 00:00:00 2001 +From: zhanghailiang +Date: Thu, 25 Jul 2019 16:05:11 +0800 +Subject: [PATCH 2/6] qcow2: fix memory leak in qcow2_read_extensions + +Free feature_table if it is failed in bdrv_pread. + +Signed-off-by: fangyi +Signed-off-by: Yan Wang +--- + block/qcow2.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/block/qcow2.c b/block/qcow2.c +index d509016..be90a89 100644 +--- a/block/qcow2.c ++++ b/block/qcow2.c +@@ -272,6 +272,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, + void *feature_table = g_malloc0(ext.len + 2 * sizeof(Qcow2Feature)); + ret = bdrv_pread(bs->file, offset , feature_table, ext.len); + if (ret < 0) { ++ g_free(feature_table); + error_setg_errno(errp, -ret, "ERROR: ext_feature_table: " + "Could not read table"); + return ret; +-- +1.9.1 + -- Gitee From 0c448ce33d783a2a79ee65aaa168becfad72c61c Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Sat, 26 Feb 2022 11:08:26 +0800 Subject: [PATCH 3/7] scsi-disk: define props in scsi_block_disk to avoid memleaks scsi_block_realize() use scsi_realize() to init some props, but these props is not defined in scsi_block_disk_properties, so they will not be freed. This patch defines these prop in scsi_block_disk_properties to avoid memleaks. Signed-off-by: Pan Nengyuan Signed-off-by: Yan Wang --- ...-props-in-scsi_block_disk-to-avoid-m.patch | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 scsi-disk-define-props-in-scsi_block_disk-to-avoid-m.patch diff --git a/scsi-disk-define-props-in-scsi_block_disk-to-avoid-m.patch b/scsi-disk-define-props-in-scsi_block_disk-to-avoid-m.patch new file mode 100644 index 0000000..f3befe7 --- /dev/null +++ b/scsi-disk-define-props-in-scsi_block_disk-to-avoid-m.patch @@ -0,0 +1,36 @@ +From e026850b32231abb97d7790a04d7c94515bd1081 Mon Sep 17 00:00:00 2001 +From: Pan Nengyuan +Date: Mon, 13 Jan 2020 15:53:32 +0800 +Subject: [PATCH 3/6] scsi-disk: define props in scsi_block_disk to avoid + memleaks + +scsi_block_realize() use scsi_realize() to init some props, but +these props is not defined in scsi_block_disk_properties, so they will +not be freed. + +This patch defines these prop in scsi_block_disk_properties to avoid memleaks. + +Signed-off-by: Pan Nengyuan +Signed-off-by: Yan Wang +--- + hw/scsi/scsi-disk.c | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c +index d491417..1d7799d 100644 +--- a/hw/scsi/scsi-disk.c ++++ b/hw/scsi/scsi-disk.c +@@ -3107,9 +3107,7 @@ static const TypeInfo scsi_cd_info = { + + #ifdef __linux__ + static Property scsi_block_properties[] = { +- DEFINE_BLOCK_ERROR_PROPERTIES(SCSIDiskState, qdev.conf), +- DEFINE_PROP_DRIVE("drive", SCSIDiskState, qdev.conf.blk), +- DEFINE_PROP_BOOL("share-rw", SCSIDiskState, qdev.conf.share_rw, false), ++ DEFINE_SCSI_DISK_PROPERTIES(), + DEFINE_PROP_UINT16("rotation_rate", SCSIDiskState, rotation_rate, 0), + DEFINE_PROP_UINT64("max_unmap_size", SCSIDiskState, max_unmap_size, + DEFAULT_MAX_UNMAP_SIZE), +-- +1.9.1 + -- Gitee From f908c5e710aeaaace0b84f9d76fe0187cb20e904 Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Sat, 26 Feb 2022 11:12:34 +0800 Subject: [PATCH 4/7] pcie: Add pcie-root-port fast plug/unplug feature If a device is plugged in the pcie-root-port when VM kernel is booting, the kernel may wrongly disable the device. This bug was brought in by two patches of the linux kernel: https://patchwork.kernel.org/patch/10575355/ https://patchwork.kernel.org/patch/10766219/ VM runtime like kata uses this feature to boot microVM, so we must fix it up. We hack into the pcie native hotplug patch so that hotplug/unplug will work under this circumstance. Signed-off-by: Ying Fang Signed-off-by: Yan Wang --- ...e-root-port-fast-plug-unplug-feature.patch | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 pcie-Add-pcie-root-port-fast-plug-unplug-feature.patch diff --git a/pcie-Add-pcie-root-port-fast-plug-unplug-feature.patch b/pcie-Add-pcie-root-port-fast-plug-unplug-feature.patch new file mode 100644 index 0000000..7822fb9 --- /dev/null +++ b/pcie-Add-pcie-root-port-fast-plug-unplug-feature.patch @@ -0,0 +1,99 @@ +From 2412c1968777a0fe77cb24dda935e3414e00ebb1 Mon Sep 17 00:00:00 2001 +From: Yan Wang +Date: Tue, 8 Feb 2022 16:10:31 +0800 +Subject: [PATCH 5/6] pcie: Add pcie-root-port fast plug/unplug feature + +If a device is plugged in the pcie-root-port when VM kernel is +booting, the kernel may wrongly disable the device. +This bug was brought in by two patches of the linux kernel: + +https://patchwork.kernel.org/patch/10575355/ +https://patchwork.kernel.org/patch/10766219/ + +VM runtime like kata uses this feature to boot microVM, +so we must fix it up. We hack into the pcie native hotplug +patch so that hotplug/unplug will work under this circumstance. + +Signed-off-by: Ying Fang +Signed-off-by: Yan Wang +--- + hw/core/machine.c | 2 ++ + hw/pci-bridge/gen_pcie_root_port.c | 2 ++ + hw/pci/pcie.c | 13 ++++++++++++- + include/hw/pci/pcie_port.h | 3 +++ + 4 files changed, 19 insertions(+), 1 deletion(-) + +diff --git a/hw/core/machine.c b/hw/core/machine.c +index 53a99ab..126e3e2 100644 +--- a/hw/core/machine.c ++++ b/hw/core/machine.c +@@ -121,6 +121,8 @@ const size_t hw_compat_4_0_len = G_N_ELEMENTS(hw_compat_4_0); + GlobalProperty hw_compat_3_1[] = { + { "pcie-root-port", "x-speed", "2_5" }, + { "pcie-root-port", "x-width", "1" }, ++ { "pcie-root-port", "fast-plug", "0" }, ++ { "pcie-root-port", "fast-unplug", "0" }, + { "memory-backend-file", "x-use-canonical-path-for-ramblock-id", "true" }, + { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" }, + { "tpm-crb", "ppi", "false" }, +diff --git a/hw/pci-bridge/gen_pcie_root_port.c b/hw/pci-bridge/gen_pcie_root_port.c +index 20099a8..0bf9df9 100644 +--- a/hw/pci-bridge/gen_pcie_root_port.c ++++ b/hw/pci-bridge/gen_pcie_root_port.c +@@ -140,6 +140,8 @@ static Property gen_rp_props[] = { + speed, PCIE_LINK_SPEED_16), + DEFINE_PROP_PCIE_LINK_WIDTH("x-width", PCIESlot, + width, PCIE_LINK_WIDTH_32), ++ DEFINE_PROP_UINT8("fast-plug", PCIESlot, fast_plug, 0), ++ DEFINE_PROP_UINT8("fast-unplug", PCIESlot, fast_unplug, 0), + DEFINE_PROP_END_OF_LIST() + }; + +diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c +index d7d73a3..d7d1504 100644 +--- a/hw/pci/pcie.c ++++ b/hw/pci/pcie.c +@@ -526,6 +526,7 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev, + uint8_t *exp_cap = hotplug_pdev->config + hotplug_pdev->exp.exp_cap; + uint32_t sltcap = pci_get_word(exp_cap + PCI_EXP_SLTCAP); + uint16_t sltctl = pci_get_word(exp_cap + PCI_EXP_SLTCTL); ++ PCIESlot *s = PCIE_SLOT(hotplug_pdev); + + /* Check if hot-unplug is disabled on the slot */ + if ((sltcap & PCI_EXP_SLTCAP_HPC) == 0) { +@@ -572,7 +573,17 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev, + return; + } + +- pcie_cap_slot_push_attention_button(hotplug_pdev); ++ if ((pci_dev->cap_present & QEMU_PCIE_LNKSTA_DLLLA) && s->fast_plug) { ++ pci_word_test_and_clear_mask(pci_dev->config + pci_dev->exp.exp_cap + PCI_EXP_LNKSTA, ++ PCI_EXP_LNKSTA_DLLLA); ++ } ++ ++ if (s->fast_unplug) { ++ pcie_cap_slot_event(hotplug_pdev, ++ PCI_EXP_HP_EV_PDC | PCI_EXP_HP_EV_ABP); ++ } else { ++ pcie_cap_slot_push_attention_button(hotplug_pdev); ++ } + } + + /* pci express slot for pci express root/downstream port +diff --git a/include/hw/pci/pcie_port.h b/include/hw/pci/pcie_port.h +index e25b289..5b80a13 100644 +--- a/include/hw/pci/pcie_port.h ++++ b/include/hw/pci/pcie_port.h +@@ -51,6 +51,9 @@ struct PCIESlot { + uint8_t chassis; + uint16_t slot; + ++ uint8_t fast_plug; ++ uint8_t fast_unplug; ++ + PCIExpLinkSpeed speed; + PCIExpLinkWidth width; + +-- +1.9.1 + -- Gitee From ecce9875ab0ae692c868adb851e5f2a00b88f9c0 Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Sat, 26 Feb 2022 11:13:19 +0800 Subject: [PATCH 5/7] pcie: Compat with devices which do not support Link Width, such as ioh3420 We hack into PCI_EXP_LNKCAP to support device fast plug/unplug for pcie-root-port. However some devices like ioh3420 does not suport it, so PCI_EXP_LNKCAP is not set for such devices. Signed-off-by: Ying Fang Signed-off-by: Yan Wang --- ...-devices-which-do-not-support-Link-W.patch | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 pcie-Compat-with-devices-which-do-not-support-Link-W.patch diff --git a/pcie-Compat-with-devices-which-do-not-support-Link-W.patch b/pcie-Compat-with-devices-which-do-not-support-Link-W.patch new file mode 100644 index 0000000..aeb31bb --- /dev/null +++ b/pcie-Compat-with-devices-which-do-not-support-Link-W.patch @@ -0,0 +1,50 @@ +From 14d1ad1309a1bd035250512368221088c2f83f32 Mon Sep 17 00:00:00 2001 +From: fangying +Date: Wed, 18 Mar 2020 12:51:33 +0800 +Subject: [PATCH 6/6] pcie: Compat with devices which do not support Link + Width, such as ioh3420 + +We hack into PCI_EXP_LNKCAP to support device fast plug/unplug +for pcie-root-port. However some devices like ioh3420 does not +suport it, so PCI_EXP_LNKCAP is not set for such devices. + +Signed-off-by: Ying Fang +Signed-off-by: Yan Wang +--- + hw/pci/pcie.c | 13 ++++++------- + 1 file changed, 6 insertions(+), 7 deletions(-) + +diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c +index d7d1504..30c09ed 100644 +--- a/hw/pci/pcie.c ++++ b/hw/pci/pcie.c +@@ -92,13 +92,6 @@ static void pcie_cap_fill_slot_lnk(PCIDevice *dev) + return; + } + +- /* Clear and fill LNKCAP from what was configured above */ +- pci_long_test_and_clear_mask(exp_cap + PCI_EXP_LNKCAP, +- PCI_EXP_LNKCAP_MLW | PCI_EXP_LNKCAP_SLS); +- pci_long_test_and_set_mask(exp_cap + PCI_EXP_LNKCAP, +- QEMU_PCI_EXP_LNKCAP_MLW(s->width) | +- QEMU_PCI_EXP_LNKCAP_MLS(s->speed)); +- + /* + * Link bandwidth notification is required for all root ports and + * downstream ports supporting links wider than x1 or multiple link +@@ -106,6 +99,12 @@ static void pcie_cap_fill_slot_lnk(PCIDevice *dev) + */ + if (s->width > QEMU_PCI_EXP_LNK_X1 || + s->speed > QEMU_PCI_EXP_LNK_2_5GT) { ++ /* Clear and fill LNKCAP from what was configured above */ ++ pci_long_test_and_clear_mask(exp_cap + PCI_EXP_LNKCAP, ++ PCI_EXP_LNKCAP_MLW | PCI_EXP_LNKCAP_SLS); ++ pci_long_test_and_set_mask(exp_cap + PCI_EXP_LNKCAP, ++ QEMU_PCI_EXP_LNKCAP_MLW(s->width) | ++ QEMU_PCI_EXP_LNKCAP_MLS(s->speed)); + pci_long_test_and_set_mask(exp_cap + PCI_EXP_LNKCAP, + PCI_EXP_LNKCAP_LBNC); + } +-- +1.9.1 + -- Gitee From 94fd281733eeed4a7962da71621b9c4ca012cb89 Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Sat, 26 Feb 2022 11:18:30 +0800 Subject: [PATCH 6/7] spec: Update patch and changelog with !220 pl011-reset-read-FIFO-when-UARTTIMSC-0-UARTICR-0xfff.patch qcow2-fix-memory-leak-in-qcow2_read_extensions.patch scsi-disk-define-props-in-scsi_block_disk-to-avoid-m.patch pcie-Add-pcie-root-port-fast-plug-unplug-feature.patch pcie-Compat-with-devices-which-do-not-support-Link-W.patch Signed-off-by: Yan Wang --- qemu.spec | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/qemu.spec b/qemu.spec index c18d51a..59dde05 100644 --- a/qemu.spec +++ b/qemu.spec @@ -227,6 +227,11 @@ Patch0213: arm-virt-Add-cpu_hotplug_enabled-field.patch Patch0214: arm-virt-acpi-Extend-cpufreq-to-support-max_cpus.patch Patch0215: arm-virt-Pre-sizing-MADT-GICC-GICv3-and-Pre-park-KVM.patch Patch0216: arm-virt-Start-up-CPU-hot-plug-and-cold-plug.patch +Patch0217: pl011-reset-read-FIFO-when-UARTTIMSC-0-UARTICR-0xfff.patch +Patch0218: qcow2-fix-memory-leak-in-qcow2_read_extensions.patch +Patch0219: scsi-disk-define-props-in-scsi_block_disk-to-avoid-m.patch +Patch0220: pcie-Add-pcie-root-port-fast-plug-unplug-feature.patch +Patch0221: pcie-Compat-with-devices-which-do-not-support-Link-W.patch BuildRequires: flex BuildRequires: gcc @@ -674,6 +679,13 @@ getent passwd qemu >/dev/null || \ %endif %changelog +* Sat Feb 26 2022 Yan Wang +- pl011-reset-read-FIFO-when-UARTTIMSC-0-UARTICR-0xfff.patch +- qcow2-fix-memory-leak-in-qcow2_read_extensions.patch +- scsi-disk-define-props-in-scsi_block_disk-to-avoid-m.patch +- pcie-Add-pcie-root-port-fast-plug-unplug-feature.patch +- pcie-Compat-with-devices-which-do-not-support-Link-W.patch + * Wed Feb 23 2022 Chen Qun - acpi/madt: Factor out the building of MADT GICC struct - hw/arm/virt: Assign virt_madt_cpu_entry to acpi_ged madt_cpu hook -- Gitee From d7f970e80ceeaaf0f8245a3338973a25482fee20 Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Sat, 26 Feb 2022 11:19:49 +0800 Subject: [PATCH 7/7] spec: Update release version with !220 increase release version by one Signed-off-by: Yan Wang --- qemu.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu.spec b/qemu.spec index 59dde05..dc47aff 100644 --- a/qemu.spec +++ b/qemu.spec @@ -1,6 +1,6 @@ Name: qemu Version: 6.2.0 -Release: 21 +Release: 22 Epoch: 2 Summary: QEMU is a generic and open source machine emulator and virtualizer License: GPLv2 and BSD and MIT and CC-BY-SA-4.0 -- Gitee