| 
 | 1 | +# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.  | 
 | 2 | +# SPDX-License-Identifier: Apache-2.0  | 
 | 3 | +"""Test swiotlb related functionality."""  | 
 | 4 | +import re  | 
 | 5 | + | 
 | 6 | +import pytest  | 
 | 7 | + | 
 | 8 | +from framework.properties import global_props  | 
 | 9 | + | 
 | 10 | +pytestmark = pytest.mark.skipif(  | 
 | 11 | +    global_props.cpu_architecture != "aarch64", reason="swiotlb only supported on ARM"  | 
 | 12 | +)  | 
 | 13 | + | 
 | 14 | + | 
 | 15 | +def test_swiotlb_boot(microvm_factory, guest_kernel_linux_6_1, rootfs):  | 
 | 16 | +    """Tests that a VM can boot if all virtio devices are bound to a swiotlb region, and  | 
 | 17 | +    that this swiotlb region is actually discovered by the guest."""  | 
 | 18 | +    vm = microvm_factory.build(guest_kernel_linux_6_1, rootfs)  | 
 | 19 | +    vm.spawn()  | 
 | 20 | +    vm.basic_config(memory_config={"initial_swiotlb_size": 64})  | 
 | 21 | +    vm.add_net_iface()  | 
 | 22 | +    vm.start()  | 
 | 23 | + | 
 | 24 | +    _, dmesg, _ = vm.ssh.check_output("dmesg")  | 
 | 25 | + | 
 | 26 | +    assert (  | 
 | 27 | +        "OF: reserved mem: initialized node bouncy_boi, compatible id restricted-dma-pool"  | 
 | 28 | +        in dmesg  | 
 | 29 | +    )  | 
 | 30 | + | 
 | 31 | +    match = re.search(r"Placed swiotlb region at \[(\d+), (\d+)\)", vm.log_data)  | 
 | 32 | + | 
 | 33 | +    assert match is not None, "Firecracker did not print swiotlb region placement"  | 
 | 34 | + | 
 | 35 | +    swiotlb_start, swiotlb_end = match.group(1, 2)  | 
 | 36 | + | 
 | 37 | +    found_any = False  | 
 | 38 | + | 
 | 39 | +    for match in re.finditer(  | 
 | 40 | +        r"Placed virt queue ([a-zA-Z ]+) at \[(\d+), (\d+)\)", vm.log_data  | 
 | 41 | +    ):  | 
 | 42 | +        found_any = True  | 
 | 43 | +        component, start, end = match.group(1, 2, 3)  | 
 | 44 | + | 
 | 45 | +        assert (  | 
 | 46 | +            start >= swiotlb_start and end <= swiotlb_end  | 
 | 47 | +        ), f"Guest placed virtio queue component {component} outside of swiotlb region!"  | 
 | 48 | + | 
 | 49 | +    assert found_any, "Did not find any virtio devices in Firecracker logs"  | 
 | 50 | + | 
 | 51 | + | 
 | 52 | +def test_swiotlb_snapshot(microvm_factory, guest_kernel_linux_6_1, rootfs):  | 
 | 53 | +    """Tests that a VM with swiotlb regions attached can be snapshotted and restored  | 
 | 54 | +    again, and that the restored VM can still do I/O."""  | 
 | 55 | +    vm = microvm_factory.build(guest_kernel_linux_6_1, rootfs)  | 
 | 56 | +    vm.spawn()  | 
 | 57 | +    vm.basic_config(memory_config={"initial_swiotlb_size": 64})  | 
 | 58 | +    vm.add_net_iface()  | 
 | 59 | +    vm.start()  | 
 | 60 | +    snapshot = vm.snapshot_full()  | 
 | 61 | +    vm.kill()  | 
 | 62 | + | 
 | 63 | +    vm = microvm_factory.build_from_snapshot(snapshot)  | 
 | 64 | + | 
 | 65 | +    vm.ssh.check_output("true")  | 
0 commit comments