[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 48/60] tests/qtest: ahci-test: add test exposing reset issue with
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 48/60] tests/qtest: ahci-test: add test exposing reset issue with pending callback |
Date: |
Mon, 6 Nov 2023 12:03:20 +0100 |
From: Fiona Ebner <f.ebner@proxmox.com>
Before commit "hw/ide: reset: cancel async DMA operation before
resetting state", this test would fail, because a reset with a
pending write operation would lead to an unsolicited write to the
first sector of the disk.
The test writes a pattern to the beginning of the disk and verifies
that it is still intact after a reset with a pending operation. It
also checks that the pending operation actually completes correctly.
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Message-ID: <20230906130922.142845-2-f.ebner@proxmox.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
tests/qtest/ahci-test.c | 86 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 85 insertions(+), 1 deletion(-)
diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index eea8b5f77b..5a1923f721 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -1424,6 +1424,89 @@ static void test_reset(void)
ahci_shutdown(ahci);
}
+static void test_reset_pending_callback(void)
+{
+ AHCIQState *ahci;
+ AHCICommand *cmd;
+ uint8_t port;
+ uint64_t ptr1;
+ uint64_t ptr2;
+
+ int bufsize = 4 * 1024;
+ int speed = bufsize + (bufsize / 2);
+ int offset1 = 0;
+ int offset2 = bufsize / AHCI_SECTOR_SIZE;
+
+ g_autofree unsigned char *tx1 = g_malloc(bufsize);
+ g_autofree unsigned char *tx2 = g_malloc(bufsize);
+ g_autofree unsigned char *rx1 = g_malloc0(bufsize);
+ g_autofree unsigned char *rx2 = g_malloc0(bufsize);
+
+ /* Uses throttling to make test independent of specific environment. */
+ ahci = ahci_boot_and_enable("-drive if=none,id=drive0,file=%s,"
+ "cache=writeback,format=%s,"
+ "throttling.bps-write=%d "
+ "-M q35 "
+ "-device ide-hd,drive=drive0 ",
+ tmp_path, imgfmt, speed);
+
+ port = ahci_port_select(ahci);
+ ahci_port_clear(ahci, port);
+
+ ptr1 = ahci_alloc(ahci, bufsize);
+ ptr2 = ahci_alloc(ahci, bufsize);
+
+ g_assert(ptr1 && ptr2);
+
+ /* Need two different patterns. */
+ do {
+ generate_pattern(tx1, bufsize, AHCI_SECTOR_SIZE);
+ generate_pattern(tx2, bufsize, AHCI_SECTOR_SIZE);
+ } while (memcmp(tx1, tx2, bufsize) == 0);
+
+ qtest_bufwrite(ahci->parent->qts, ptr1, tx1, bufsize);
+ qtest_bufwrite(ahci->parent->qts, ptr2, tx2, bufsize);
+
+ /* Write to beginning of disk to check it wasn't overwritten later. */
+ ahci_guest_io(ahci, port, CMD_WRITE_DMA_EXT, ptr1, bufsize, offset1);
+
+ /* Issue asynchronously to get a pending callback during reset. */
+ cmd = ahci_command_create(CMD_WRITE_DMA_EXT);
+ ahci_command_adjust(cmd, offset2, ptr2, bufsize, 0);
+ ahci_command_commit(ahci, cmd, port);
+ ahci_command_issue_async(ahci, cmd);
+
+ ahci_set(ahci, AHCI_GHC, AHCI_GHC_HR);
+
+ ahci_command_free(cmd);
+
+ /* Wait for throttled write to finish. */
+ sleep(1);
+
+ /* Start again. */
+ ahci_clean_mem(ahci);
+ ahci_pci_enable(ahci);
+ ahci_hba_enable(ahci);
+ port = ahci_port_select(ahci);
+ ahci_port_clear(ahci, port);
+
+ /* Read and verify. */
+ ahci_guest_io(ahci, port, CMD_READ_DMA_EXT, ptr1, bufsize, offset1);
+ qtest_bufread(ahci->parent->qts, ptr1, rx1, bufsize);
+ g_assert_cmphex(memcmp(tx1, rx1, bufsize), ==, 0);
+
+ ahci_guest_io(ahci, port, CMD_READ_DMA_EXT, ptr2, bufsize, offset2);
+ qtest_bufread(ahci->parent->qts, ptr2, rx2, bufsize);
+ g_assert_cmphex(memcmp(tx2, rx2, bufsize), ==, 0);
+
+ ahci_free(ahci, ptr1);
+ ahci_free(ahci, ptr2);
+
+ ahci_clean_mem(ahci);
+
+ ahci_shutdown(ahci);
+}
+
static void test_ncq_simple(void)
{
AHCIQState *ahci;
@@ -1945,7 +2028,8 @@ int main(int argc, char **argv)
qtest_add_func("/ahci/migrate/dma/halted", test_migrate_halted_dma);
qtest_add_func("/ahci/max", test_max);
- qtest_add_func("/ahci/reset", test_reset);
+ qtest_add_func("/ahci/reset/simple", test_reset);
+ qtest_add_func("/ahci/reset/pending_callback",
test_reset_pending_callback);
qtest_add_func("/ahci/io/ncq/simple", test_ncq_simple);
qtest_add_func("/ahci/migrate/ncq/simple", test_migrate_ncq);
--
2.41.0
- [PULL 39/60] exec/cpu: Have cpu_exec_realize() return a boolean, (continued)
- [PULL 39/60] exec/cpu: Have cpu_exec_realize() return a boolean, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 40/60] hw/cpu: Clean up global variable shadowing, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 41/60] hw/loader: Clean up global variable shadowing in rom_add_file(), Philippe Mathieu-Daudé, 2023/11/06
- [PULL 42/60] hw/isa/i82378: Propagate error if PC_SPEAKER device creation failed, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 43/60] hw/i386: Fix comment style in topology.h, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 44/60] tests/unit: Rename test-x86-cpuid.c to test-x86-topo.c, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 45/60] system/cpus: Fix CPUState.nr_cores' calculation, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 46/60] hw/cpu: Update the comments of nr_cores and nr_dies, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 47/60] hw/ide: reset: cancel async DMA operation before resetting state, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 49/60] hw/i2c: pmbus add support for block receive, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 48/60] tests/qtest: ahci-test: add test exposing reset issue with pending callback,
Philippe Mathieu-Daudé <=
- [PULL 50/60] hw/i2c: pmbus: add vout mode bitfields, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 51/60] hw/i2c: pmbus: add fan support, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 52/60] hw/i2c: pmbus: add VCAP register, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 53/60] hw/sensor: add ADM1266 device model, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 58/60] MAINTAINERS: Add the CAN documentation file to the CAN section, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 57/60] MAINTAINERS: Add include/hw/timer/tmu012.h to the SH4 R2D section, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 55/60] hw/i2c: pmbus: immediately clear faults on request, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 59/60] MAINTAINERS: update libvirt devel mailing list address, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 54/60] tests/qtest: add tests for ADM1266, Philippe Mathieu-Daudé, 2023/11/06
- [PULL 56/60] hw/i2c: pmbus: reset page register for out of range reads, Philippe Mathieu-Daudé, 2023/11/06