Skip to content

Commit 6497521

Browse files
committed
Add a highmem mmio size case for aarch64
This PR adds VIRT-304413 - Various highmem mmio size test Signed-off-by: Yingshun Cui <[email protected]>
1 parent 49f7bbf commit 6497521

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- pci_highmem_mmio_size:
2+
type = pci_highmem_mmio_size
3+
start_vm = "no"
4+
hostdev_dict = {'mode': 'subsystem', 'type': 'pci', 'source': {'untyped_address': gpu_pci_addr}, 'managed': 'yes'}
5+
6+
only aarch64
7+
variants:
8+
- hotplug:
9+
hotplug = "yes"
10+
- start_vm:
11+
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
2+
import time
3+
4+
from virttest import utils_test
5+
6+
from virttest import virsh
7+
8+
from virttest.libvirt_xml import vm_xml
9+
from virttest.utils_libvirt import libvirt_vmxml
10+
11+
from provider.gpu import gpu_base
12+
13+
14+
def run(test, params, env):
15+
"""
16+
Various highmem mmio size tests
17+
"""
18+
def attach_gpu():
19+
"""
20+
Attach a gpu device to vm
21+
22+
:return: session to the vm
23+
"""
24+
if hotplug:
25+
vm.start()
26+
vm_session = vm.wait_for_login()
27+
test.log.info("TEST_STEP: Hotplug a gpu device to vm")
28+
gpu_dev = libvirt_vmxml.create_vm_device_by_type("hostdev", hostdev_dict)
29+
virsh.attach_device(vm.name, gpu_dev.xml, **virsh_args)
30+
time.sleep(20)
31+
else:
32+
libvirt_vmxml.modify_vm_device(
33+
vm_xml.VMXML.new_from_dumpxml(vm.name), "hostdev",
34+
hostdev_dict)
35+
test.log.info("TEST_STEP: Start the VM with a gpu device")
36+
vm.start()
37+
vm_session = vm.wait_for_login()
38+
39+
test.log.debug(f'VMXML of {vm_name}:\n{virsh.dumpxml(vm_name).stdout_text}')
40+
return vm_session
41+
42+
def check_memory(vm_session, hostdev_pci, status_error=False):
43+
"""
44+
Check the memory of a GPU device
45+
46+
:param hostdev_pci: the pci address of the GPU device
47+
:param status_error: True if expect not existing, otherwise False
48+
:raises: TestFail if the result is not expected
49+
"""
50+
s, o = vm_session.cmd_status_output(f"lspci -vs {hostdev_pci} |grep prefetchable")
51+
test.log.debug(f"The memory at device: {o}")
52+
msg = "Memory info should %sbe in lspci's output" % ("not " if status_error else "")
53+
if s ^ status_error:
54+
test.fail(msg)
55+
56+
def prepare_controller_with_pcihole64(value, controller_idx):
57+
"""
58+
Prepare the controller with a PCI hole64
59+
60+
:param value: the PCI hole64 size
61+
:param controller_idx: the index of the controller to modify
62+
"""
63+
controller_dict = {"pcihole64": value}
64+
libvirt_vmxml.modify_vm_device(
65+
vm_xml.VMXML.new_from_dumpxml(vm.name), "controller",
66+
controller_dict, controller_idx)
67+
test.log.debug(f'VMXML of {vm_name}:\n{virsh.dumpxml(vm_name).stdout_text}')
68+
69+
hotplug = params.get("hotplug", "no") == "yes"
70+
vm_name = params.get("main_vm", "avocado-vt-vm1")
71+
vm = env.get_vm(vm_name)
72+
virsh_args = {'ignore_status': False, 'debug': True}
73+
74+
gpu_test = gpu_base.GPUTest(vm, test, params)
75+
hostdev_dict = gpu_test.parse_hostdev_dict()
76+
77+
try:
78+
gpu_test.setup_default()
79+
vm_session = attach_gpu()
80+
81+
s, o = vm_session.cmd_status_output("lspci |awk '/3D/ {print $1}'")
82+
hostdev_pci = o.strip()
83+
test.log.debug(f"The pci of hostdev device: {hostdev_pci}")
84+
if s:
85+
test.fail("Unable to get the gpu device in vm, output: %s" % o)
86+
87+
check_memory(vm_session, hostdev_pci)
88+
89+
if hotplug:
90+
test.log.info("TEST_STEP: Unplug a gpu device from vm")
91+
vm_hostdev = vm_xml.VMXML.new_from_dumpxml(vm.name)\
92+
.devices.by_device_tag("hostdev")[0]
93+
virsh.detach_device(vm.name, vm_hostdev.xml,
94+
wait_for_event=True, event_timeout=30,
95+
**virsh_args)
96+
utils_test.update_boot_option(
97+
vm,
98+
args_added=f"pci=resource_alignment=38@0000:{hostdev_pci}",
99+
)
100+
101+
vm_session.close()
102+
vm.destroy()
103+
vm_controllers = vm_xml.VMXML.new_from_dumpxml(vm.name)\
104+
.devices.by_device_tag("controller")
105+
for i in range(len(vm_controllers)):
106+
if vm_controllers[i].model == "pcie-root":
107+
controller_idx = i
108+
break
109+
110+
test.log.info("TEST_STEP: Set pcihole64 to 512G")
111+
prepare_controller_with_pcihole64("536870912", controller_idx)
112+
113+
vm_session = attach_gpu()
114+
check_memory(vm_session, hostdev_pci, status_error=True)
115+
116+
vm_session.close()
117+
vm.destroy()
118+
119+
test.log.info("TEST_STEP: Set pcihole64 to 1T")
120+
prepare_controller_with_pcihole64("1073741824", controller_idx)
121+
vm_session = attach_gpu()
122+
check_memory(vm_session, hostdev_pci, status_error=False)
123+
finally:
124+
gpu_test.teardown_default()

0 commit comments

Comments
 (0)