Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796172013; b=jDOWYNN+vbUSvTKgBZbPrinnO49D98YKikgBWvWV+7LmiZ0lNJFBDqK3QG75rIYGCIC2 1oCFx0E+K+ERillU7XhQv4UXtqHgS4vH2vW8bJDR6/a/rLfFyHBGYSN3gHAUVMDwHprNZ MHx84JeOK6VPCIom2xNhhbHS2swDwOQ+AzUXwDuyaz7q3wLn83A8KTyvUs+X6uRo12QR1 Pu2a0h+lsdmMcLyDrXvwWW+f2+py1FvPbL7T4+6KZqmQNGaUr+sAjQ8ztuMYVfJ742fm1 xq50g4cB4PEIS0U7WXVmRxQ+8C2f/qmPiu0OmQS21DxSv3aRRBF8cQYBqcn7LbfkzBw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796172013; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=GLXQDl3CXf8A6BS6Hl00FDYfoB7H7cV/gEBVvXCU5DQ=; b=Tumd3eMZo9rPladSylYjqy0RGx0F+P3PIyMILs/sGhmu1hRnNZcZ1lg5uKP3jNWyVr7l sNHyHRzvu3oaJqaT3VyEEj4yDpriimS6vgZP7Oxv8pQXN/N9wXGDsdeuOR/DHXlG82j4M bsi7PrRufYKmmkSlIuBwUsJJzRWSm9MJP1ry6HVrrubgttYljOWirtEWZrxhQykaPc7Ed AUdskAgflanWiWIhCZhuqd0JI/3D60hZQPm8y+HtNPOEBzQf2Lwj5lTfKp8m9RCRSbwtC 6nTe50euW6kGHtuyT71BeDbPc++MqKwnQ3Lp3elBY4AmVttEUfQeaUfNRkSknzBJVkw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=JMQRHZXv; arc=none smtp.remote-ip=209.85.167.200 Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51FCC606A6A9 for ; Wed, 2 Dec 2026 00:40:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 51FCC606A6A9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=JMQRHZXv Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-4b37620eb73so15948449b6e.1 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=vger.kernel.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=JMQRHZXvAAv2QlyDH58hOH5M6UKw4tVyzWaCflR60K4cIoIe9SRCz+KnNcvUcUtjMM EZ7l3vXwuya+U4gPzk3Zh26V+6utx7/O3sqlgScmBZE10iVvy+TWPflTRhkV8opH1PtI KX25WTy/UvnAcO5sNoW5Rg62p6PJctnA0/LZKS82XDymv8vrTonKLUjYkavksn4ri3+H uij7Eav1XnEFLihbttSoG97xOxD7cI7p8EPNCKMV5RYz+X4m1byDKDvJ9ptpqxOj3/Pi bNsoSFAXsBsFIJQnXLFL9I27IkaD4s8lqGbmnuELSa4avpYfuxwQPm/c3XMNpy/HBQw2 i44Q== 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=cuaF1KHHZOIcx4quh62V1I5EOyayfoiGOTe2P9UpnGr1h4MXx0dQPeupVFmGxoODG0 zXguobHz4HF4KnrXNfUb17W3zB0CG5jXrB7rxAEQJeJHxS8e8NotRhx5AZgCztMVm/uQ 3AKVrmKCartbzR1VLryzPxWfEu5gA+h4irGqlA+AMOy177tIJxEUIJQa9kfsLpppGZB1 F7VWJotNLRcWyRn8+p8LU16JuoJm1BEZDaFf6Ny2oGfJUoH5KwSw0lsStLhSGo/WR+pa f9eOum/HjLwlta3gVaDfhpKlcYDBU50i2XigZJcfMwVWaPLsYH/pbiTthtIJSHgd21KZ M4AA== X-Forwarded-Encrypted: i=1; AL+hErEespfd+HKA7torAIqYCm+01J8hjxxWMNPiigmORXyODSCm9jrcXt8cWzZbpop3YywlkhdZ+ftJ/zd195sGdNc=@vger.kernel.org X-Gm-Message-State: APuU4Z+Mz/wBGqROYmnyaUR+7MlltKubANvfWXwSGNpJZAWrKX682C6n K0kkVzkIojpjP33bzmih1cDVumpKSqWPpPGP3O2EXM/yaJDUjNIjnnx7PZKmDZ6dsxBAMrcElPz XtrdMRVsxVp76mg== 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-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 Content-Type: text/plain; charset="UTF-8" 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