From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AE3D606A32E for ; Wed, 2 Dec 2026 00:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=1qxxw1iE; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=LzTvBpPy DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Unsubscribe-Post:List-Owner; bh=DCfvezA2HLZawsptKqy5PKOqtEhhrj4xQlyywYZ8TQo=; b=1qxxw1iEDPurFzN8eVkpLUCAgr CLBL5yFVTKOx124SwcXuMiyUXmwqhvaFfBsGxPqOvjDDODrz5ZmXLEEBCqADKWzwftUE/dpG+EoY7 anc3uo9pjeSEj+hBMr26Zvq5h8127GRB7LbjQ4JM6iVwY8agrbDiO1QNQQKdV0gc7ojOGnVQT0fw2 Zqe3UJFYuz+9hljBWt/P1U9yd5Xs5c7aSgOcqPrMuUpj0uoQa5GedhVBHaOmDlZr+gO8IJEmOz14J cdZdtYs3neV6rFswCg3oeXEieHA5DH2VvveAzeX4+IIpRRXf63ISsGw9f+tabtRvIo+oI+Ia0Uw5/ RJIy5jRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYYOV-00000009mPP-0sFs; Wed, 02 Dec 2026 00:40:23 +0000 Received: from mail-ot1-x345.google.com ([2607:f8b0:4864:20::345]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYYOM-00000009m4G-0gHm for linux-riscv@lists.infradead.org; Wed, 02 Dec 2026 00:40:17 +0000 Received: by mail-ot1-x345.google.com with SMTP id 46e09a7af769-862a5ad18d0so12802006a34.3 for ; Tue, 01 Dec 2026 16:40:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796172012; x=1796776812; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GLXQDl3CXf8A6BS6Hl00FDYfoB7H7cV/gEBVvXCU5DQ=; b=LzTvBpPy8+HAdnORr5jHLRNDJqEmF5SwVH21/9Je8zi9CFwFBuqlf2kaSOm+JVWgu0 h1q/qKYCYAYVmtLk351a/11xQhtw5XjwUJ1bi7igh2rm4ehpmt1VAvOqCUGfQmX+2Owc 7c1GNYi8wHyegCNmXA2VhWsippts+0u9usxHnxGkFz5mBWjITaL9Lx0DXmmWN9eh2y1M /WXvFt5Ij8p6m9aU7951gqfDr/h/1B6jHUkpw5C+G7afZK4P0q9+QDd9aoqKnIOmGZ1S XyzqSSzAjPWlxWuPwvXrgxjt+btj7u0wWgdVm9Yi6TAcUD77RdTdJpZXKCvB26QZGKr+ jpAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796172012; x=1796776812; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GLXQDl3CXf8A6BS6Hl00FDYfoB7H7cV/gEBVvXCU5DQ=; b=CIS7zCcNOYQm1jIKfOl16Pwii4vAsHx172/pz0r000sEyhV2SKE4Ud9UCx626euTQW XbG8PqqPlVA+oC70Ulxhd0rNu1XBoiaZrNB29Rx7Lgfm5JfbjnrTkvFSB0YjpxMal6Iz 5hKjbBYQmVQH2VlNWx6ERlXF6eBtp8L2twyuf7Scadv6vaYlcg9NgLT3nEP5InxY+6UO Cio7ECpBfzwC7BbaRwAKoS3OQ+dRTQHx/RK79VIhTPpclsG2HQ/tvDwo6ssDDX8iZsz5 Z02fKBoNzVBYycnLITkhMJnsc/i71p7/YFZAHZJNFrkS6nUDJjVnTz+YurnrKc0ppk2w kFfw== X-Forwarded-Encrypted: i=1; AL+hErEdg1c0c1lescBeNEoxTHS4DgmoU8zOhxFQGevgCwUE8zTIoSLHQ1HlCNJCN9qhfJ14f7aYpbOAZ8fd+Q==@lists.infradead.org X-Gm-Message-State: APuU4Z+HrIKBqyF0hVJMFPCQiQSNxcV0Dip1qcIBwJ1iGqNNTiXzVH1A Juzi68cw72X9+TuWpKQDZuGLh42fTuy0w1ph8ycBraWN4HtKD4/BsxWvPwSgrH2tPOtuCkmTPMS RwLqydADGsMZ+8w== X-Received: from iobdk9.prod.google.com ([2002:a05:6602:1b09:b0:9c4:c2b7:385f]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:3503:b0:576:4595:9837 with SMTP id 5614622812f47-57a0ae277f1mr41905938b6e.46.1796172012176; Tue, 01 Dec 2026 16:40:12 -0800 (PST) Date: Wed, 2 Dec 2026 00:39:49 +0000 In-Reply-To: <20261202003955.3607156-1-dmatlack@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261202003955.3607156-1-dmatlack@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202003955.3607156-13-dmatlack@google.com> Subject: [PATCH 12/18] selftests/liveupdate: pci: Check PCI config writes with QEMU tracing From: David Matlack To: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-pci@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Albert Ou , Alexandre Ghiti , Alex Williamson , Bjorn Helgaas , David Matlack , Jacob Pan , Jason Gunthorpe , Josh Hilke , Lukas Wunner , Mike Rapoport , Palmer Dabbelt , Parav Pandit , Pasha Tatashin , Paul Walmsley , Pranjal Shrivastava , Pratyush Yadav , Samiullah Khawaja , Shuah Khan , Vipin Sharma X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_164014_314371_BB5BC590 X-CRM114-Status: GOOD ( 28.23 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Trace PCI config writes in QEMU, and check that none of them disrupts a preserved device, or a bridge above it, between the end of stage 1 and the end of stage 2, i.e. while the previous kernel shuts down, the next kernel enumerates PCI, and the test driver probes and finishes the device. The checks in the next kernel only see the end state. The trace also catches transient changes, e.g. Bus Master Enable being cleared and set again, and resets that leave no trace in the end state, e.g. a Secondary Bus Reset or Function Level Reset. The test binary prints a manifest of the preserved and control endpoints and the bridges above them to the console, and marks the phases of the test by writing to the config space of a pci-testdev device, which shows up in the trace. A new script, check_cfg_trace.py, checks the trace against the manifest. As a positive control, it also requires the trace to show Bus Master Enable being cleared on the control endpoint during kexec, which shows that it is looking at the right devices and phase. Skip the PCI tests if python3 is not installed, and allow *.py in .gitignore. Signed-off-by: David Matlack --- tools/testing/selftests/liveupdate/.gitignore | 1 + .../liveupdate/pci/check_cfg_trace.py | 238 ++++++++++++++++++ .../selftests/liveupdate/pci/luo_pci_test.c | 54 +++- .../liveupdate/pci/pci_vmtest_lib.sh | 26 +- 4 files changed, 314 insertions(+), 5 deletions(-) create mode 100755 tools/testing/selftests/liveupdate/pci/check_cfg_trace.py diff --git a/tools/testing/selftests/liveupdate/.gitignore b/tools/testing/selftests/liveupdate/.gitignore index 9bf744e4f138..bdd6bfad9cc9 100644 --- a/tools/testing/selftests/liveupdate/.gitignore +++ b/tools/testing/selftests/liveupdate/.gitignore @@ -4,6 +4,7 @@ !*.c !*.h !*.mk +!*.py !*.sh !.gitignore !config diff --git a/tools/testing/selftests/liveupdate/pci/check_cfg_trace.py b/tools/testing/selftests/liveupdate/pci/check_cfg_trace.py new file mode 100755 index 000000000000..4000cc63f346 --- /dev/null +++ b/tools/testing/selftests/liveupdate/pci/check_cfg_trace.py @@ -0,0 +1,238 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2026, Google LLC. +# David Matlack +"""Check PCI config writes against the devices preserved by luo_pci_test. + +QEMU records every PCI config write with the pci_cfg_write trace event: + + pci_cfg_write igb 01:00.0 @0x4 <- 0x407 + +luo_pci_test prints a manifest of the preserved and control endpoints and the +bridges above them in stage 1, and writes markers to the config space of a +marker device: + + A: end of stage 1 (devices preserved, about to kexec) + B: start of the stage 2 test binary + C: end of stage 2 (devices finished) + +Between A and C, i.e. during kexec, the next kernel's enumeration and the +driver's probe, no config write may disrupt a preserved device: + + - Bus Master Enable must not be cleared + - The secondary and subordinate bus numbers of bridges must not change + - Secondary Bus Reset must not be set on bridges + - Function Level Reset must not be initiated + - ARI Forwarding Enable on bridges must not change + - The ACS controls must not change + +The trace only records the offset and value of each write, not its size. The +checks assume naturally aligned writes of the sizes the PCI core uses for +these registers. + +As a positive control, each control endpoint (bound to the test driver but not +preserved) must have Bus Master Enable cleared between A and B, by the +previous kernel during kexec. +""" + +import argparse +import re +import sys + +MANIFEST_PREFIX = "LUPCI-MANIFEST: " +MARKER_OFFSET = 0x40 +MARKERS = {0x4C550001: "A", 0x4C550002: "B", 0x4C550003: "C"} + +PCI_COMMAND = 0x04 +PCI_COMMAND_MASTER = 0x4 +PCI_PRIMARY_BUS = 0x18 +PCI_SECONDARY_BUS = 0x19 +PCI_SUBORDINATE_BUS = 0x1A +PCI_INTERRUPT_LINE = 0x3C +PCI_BRIDGE_CONTROL = 0x3E +PCI_BRIDGE_CTL_BUS_RESET = 0x40 +PCI_EXP_DEVCTL = 0x08 +PCI_EXP_DEVCTL_BCR_FLR = 0x8000 +PCI_EXP_DEVCTL2 = 0x28 +PCI_EXP_DEVCTL2_ARI = 0x20 +PCI_ACS_CAP = 0x04 +PCI_ACS_CTRL = 0x06 + +TRACE_RE = re.compile( + r"pci_cfg_write (\S+) ([0-9a-f]{2}):([0-9a-f]{2})\.([0-7]) " + r"@0x([0-9a-f]+) <- 0x([0-9a-f]+)" +) + + +class Device: + def __init__(self, fields): + self.bdf = fields["bdf"] + domain, bus, devfn = self.bdf.split(":") + slot, func = devfn.split(".") + if int(domain, 16) != 0: + raise ValueError(f"{self.bdf}: only domain 0 is supported") + self.key = (int(bus, 16), int(slot, 16), int(func, 16)) + self.role = fields["role"] + self.endpoint = int(fields["endpoint"]) != 0 + self.bridge = int(fields["bridge"]) != 0 + self.secondary = int(fields["sec"], 0) + self.subordinate = int(fields["sub"], 0) + self.pcie = int(fields["pcie"], 0) + self.acs = int(fields["acs"], 0) + self.devctl2 = int(fields["devctl2"], 0) + self.acs_ctrl = int(fields["acsctrl"], 0) + self.nr_writes = 0 + self.cleared_master = False + + +def parse_manifest(path): + devices = {} + with open(path, errors="replace") as f: + for line in f: + idx = line.find(MANIFEST_PREFIX) + if idx < 0: + continue + fields = dict( + kv.split("=", 1) + for kv in line[idx + len(MANIFEST_PREFIX):].split() + if "=" in kv + ) + dev = Device(fields) + devices[dev.key] = dev + return devices + + +def parse_trace(path): + writes = [] + with open(path, errors="replace") as f: + for line in f: + m = TRACE_RE.search(line) + if not m: + continue + name, bus, slot, func, offset, value = m.groups() + writes.append( + ( + name, + (int(bus, 16), int(slot, 16), int(func, 16)), + int(offset, 16), + int(value, 16), + ) + ) + return writes + + +def check_write(dev, offset, value): + """Return a description of how the write disrupts dev, or None.""" + if offset == PCI_COMMAND and not value & PCI_COMMAND_MASTER: + return "clears Bus Master Enable" + + if dev.bridge: + if offset == PCI_PRIMARY_BUS: + secondary = (value >> 8) & 0xFF + subordinate = (value >> 16) & 0xFF + elif offset == PCI_SECONDARY_BUS: + secondary, subordinate = value & 0xFF, dev.subordinate + elif offset == PCI_SUBORDINATE_BUS: + secondary, subordinate = dev.secondary, value & 0xFF + else: + secondary, subordinate = dev.secondary, dev.subordinate + + if (secondary, subordinate) != (dev.secondary, dev.subordinate): + return ( + f"changes bus numbers from [{dev.secondary:02x}-{dev.subordinate:02x}] " + f"to [{secondary:02x}-{subordinate:02x}]" + ) + + if offset == PCI_BRIDGE_CONTROL and value & PCI_BRIDGE_CTL_BUS_RESET: + return "sets Secondary Bus Reset" + if offset == PCI_INTERRUPT_LINE and (value >> 16) & PCI_BRIDGE_CTL_BUS_RESET: + return "sets Secondary Bus Reset" + + if dev.pcie: + if offset == dev.pcie + PCI_EXP_DEVCTL and value & PCI_EXP_DEVCTL_BCR_FLR: + return "initiates Function Level Reset" + if ( + dev.bridge + and offset == dev.pcie + PCI_EXP_DEVCTL2 + and (value ^ dev.devctl2) & PCI_EXP_DEVCTL2_ARI + ): + return "changes ARI Forwarding Enable" + + if dev.acs: + if offset == dev.acs + PCI_ACS_CTRL: + acs_ctrl = value & 0xFFFF + elif offset == dev.acs + PCI_ACS_CAP: + acs_ctrl = value >> 16 + else: + acs_ctrl = dev.acs_ctrl + if acs_ctrl != dev.acs_ctrl: + return f"changes ACS controls from 0x{dev.acs_ctrl:04x} to 0x{acs_ctrl:04x}" + + return None + + +def main(): + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("--serial", required=True, help="Serial console log") + parser.add_argument("--trace", required=True, help="QEMU pci_cfg_write trace") + args = parser.parse_args() + + devices = parse_manifest(args.serial) + if not devices: + print("# No device manifest found in the serial log") + return 1 + + phase = None + seen = set() + failures = [] + + for name, key, offset, value in parse_trace(args.trace): + if offset == MARKER_OFFSET and value in MARKERS: + phase = MARKERS[value] + seen.add(phase) + continue + + if phase not in ("A", "B") or key not in devices: + continue + + dev = devices[key] + if dev.role == "control": + if ( + phase == "A" + and dev.endpoint + and offset == PCI_COMMAND + and not value & PCI_COMMAND_MASTER + ): + dev.cleared_master = True + continue + + dev.nr_writes += 1 + problem = check_write(dev, offset, value) + if problem: + failures.append( + f"{dev.bdf} ({name}): write 0x{value:x} @0x{offset:x} " + f"in phase {phase} {problem}" + ) + + for marker in MARKERS.values(): + if marker not in seen: + failures.append(f"Marker {marker} not found in the trace") + + for dev in devices.values(): + if dev.role == "preserved": + print(f"# {dev.bdf}: checked {dev.nr_writes} config write(s)") + elif dev.endpoint and not dev.cleared_master: + failures.append( + f"{dev.bdf}: control device did not have Bus Master cleared " + "during kexec (is the trace being checked correctly?)" + ) + + for failure in failures: + print(f"# FAIL: {failure}") + + return 1 if failures else 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/testing/selftests/liveupdate/pci/luo_pci_test.c b/tools/testing/selftests/liveupdate/pci/luo_pci_test.c index 7995c9e4252b..177562d65e64 100644 --- a/tools/testing/selftests/liveupdate/pci/luo_pci_test.c +++ b/tools/testing/selftests/liveupdate/pci/luo_pci_test.c @@ -10,14 +10,17 @@ * -p Endpoint to preserve. * -c Optional. Endpoint to bind to the test driver but not * preserve. + * -m Optional device whose config space is written to mark the + * phases of the test in a QEMU trace of config writes. * * A identifies a device independently of bus numbers: a device on the * root bus followed by the device.function of each device below it, e.g. * 0000:00:02.0/00.0 is function 0 of device 0 below the bridge at 0000:00:02.0. * * Stage 1 snapshots the config space of the endpoints and of all bridges - * above them, and preserves the endpoint. Stage 2 checks the devices - * against the snapshot before and after the driver retrieves and + * above them, prints the snapshot so that a host-side checker can validate + * the QEMU trace, and preserves the endpoint. Stage 2 checks the + * devices against the snapshot before and after the driver retrieves and * finishes them. * * Copyright (c) 2026, Google LLC. @@ -49,6 +52,14 @@ #define DEVICE_SESSION_NAME "lupci_devices" #define DEVICE_TOKEN 1 +/* Values written to the marker device. Keep in sync with check_cfg_trace.py. */ +#define MARKER_OFFSET 0x40 +#define MARKER_STAGE1_DONE 0x4c550001 +#define MARKER_STAGE2_START 0x4c550002 +#define MARKER_STAGE2_DONE 0x4c550003 + +#define MANIFEST_PREFIX "LUPCI-MANIFEST: " + #define CONFIG_SIZE 4096 #define MAX_DEVICES 32 #define BDF_LEN 12 /* DDDD:BB:dd.f */ @@ -83,6 +94,7 @@ static int nr_before; static const char *opt_preserve = ""; static const char *opt_control = ""; +static const char *opt_marker = ""; /* strcspn(), which nolibc lacks. */ static size_t span_until(const char *s, const char *reject) @@ -100,7 +112,7 @@ static int parse_args(int argc, char *argv[]) int stage = 1; int opt; - while ((opt = getopt(argc, argv, "s:p:c:")) != -1) { + while ((opt = getopt(argc, argv, "s:p:c:m:")) != -1) { switch (opt) { case 's': stage = atoi(optarg); @@ -111,6 +123,9 @@ static int parse_args(int argc, char *argv[]) case 'c': opt_control = optarg; break; + case 'm': + opt_marker = optarg; + break; default: ksft_exit_fail_msg("Unknown option\n"); } @@ -146,6 +161,26 @@ static void load_module(void) close(fd); } +static void write_marker(uint32_t value) +{ + char path[64]; + int fd; + + if (!opt_marker[0]) + return; + + snprintf(path, sizeof(path), "/sys/bus/pci/devices/%.*s/config", BDF_LEN, opt_marker); + fd = open(path, O_WRONLY); + if (fd < 0) + fail_exit("open %s", path); + + if (lseek(fd, MARKER_OFFSET, SEEK_SET) != MARKER_OFFSET || + write(fd, &value, sizeof(value)) != sizeof(value)) + fail_exit("write marker 0x%x to %s", value, path); + + close(fd); +} + static int read_config(const char *bdf, uint8_t *cfg) { char path[64]; @@ -535,6 +570,14 @@ static void run_stage_1(int luo_fd) fail_exit("Snapshot is too large"); } + /* Print the snapshot for the host-side checker. */ + for (i = 0; i < nr_devices; i++) { + char line[512]; + + format_snapshot(&devices[i], line, sizeof(line)); + ksft_print_msg(MANIFEST_PREFIX "%s", line); + } + create_state_file(luo_fd, STATE_SESSION_NAME, STATE_MEMFD_TOKEN, 2); session_fd = luo_create_session(luo_fd, DATA_SESSION_NAME); @@ -565,6 +608,7 @@ static void run_stage_1(int luo_fd) } close(ctl_fd); + write_marker(MARKER_STAGE1_DONE); close(luo_fd); daemonize_and_wait(); @@ -660,6 +704,7 @@ static void run_stage_2(int luo_fd, int state_session_fd) if (luo_session_finish(state_session_fd) < 0) fail_exit("luo_session_finish %s", STATE_SESSION_NAME); + write_marker(MARKER_STAGE2_DONE); ksft_print_msg("\n--- PCI LIVE UPDATE TEST PASSED ---\n"); } @@ -672,6 +717,9 @@ int main(int argc, char *argv[]) mount_sysfs(); + if (stage == 2) + write_marker(MARKER_STAGE2_START); + add_path(opt_preserve, ROLE_PRESERVED); if (opt_control[0]) add_path(opt_control, ROLE_CONTROL); diff --git a/tools/testing/selftests/liveupdate/pci/pci_vmtest_lib.sh b/tools/testing/selftests/liveupdate/pci/pci_vmtest_lib.sh index ebed414510f4..5babeb19fbc1 100644 --- a/tools/testing/selftests/liveupdate/pci/pci_vmtest_lib.sh +++ b/tools/testing/selftests/liveupdate/pci/pci_vmtest_lib.sh @@ -10,20 +10,36 @@ # "igb" device as the endpoint, and names the endpoints to preserve and the # control endpoints (bound to the test driver but not preserved) by their path # from the root bus. See luo_pci_test.c for the path format. +# +# QEMU traces every PCI config write, and check_cfg_trace.py checks that none +# of them disrupts a preserved device between the end of stage 1 and the end +# of stage 2. +PCI_TRACE="$workspace_dir/qemu-pci-trace.log" +PCI_MARKER_ADDR=1e PCI_CHASSIS=0 TEST_BINARY=pci/luo_pci_test TEST_MODULES=(luo_pci_test_driver) TEST_TIMEOUT="180s" -TEST_QEMU_ARGS=() +# The marker device lets the test binary mark the phases of the test in the +# trace by writing to its config space. +TEST_QEMU_ARGS=( + -device "pci-testdev,bus=pcie.0,addr=0x$PCI_MARKER_ADDR" + -trace "enable=pci_cfg_write,file=$PCI_TRACE" +) +TEST_ARGS=(-m "0000:00:$PCI_MARKER_ADDR.0") # The default x86 machine (pc) does not support PCIe. if [[ "$arch" == "x86" ]]; then TEST_QEMU_ARGS+=(-M q35) fi +if ! command -v python3 &> /dev/null; then + skip "python3 is required to check the QEMU trace" +fi + # pci_root_port # Add a root port at device on the root bus. function pci_root_port() { @@ -45,7 +61,8 @@ function pci_preserve() { # pci_control # Bind the endpoint at to the test driver, but don't preserve it. -# Bus Master must be cleared on it during kexec. +# Bus Master must be cleared on it during kexec. The trace check also uses +# this to confirm that it is looking at the right devices and phase. function pci_control() { TEST_ARGS+=(-c "$1") } @@ -62,3 +79,8 @@ function pci_topology_root_ports() { pci_preserve 0000:00:02.0/00.0 pci_control 0000:00:03.0/00.0 } + +function test_check() { + python3 "$test_dir/pci/check_cfg_trace.py" \ + --serial "$workspace_dir/qemu.serial" --trace "$PCI_TRACE" +} -- 2.56.1.911.g883d8bcb20-goog _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv