Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 45 additions & 12 deletions io/iommu/amd/iommu_v2pgmode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,30 @@
Validate 5 level page table support in v2 iommu page table mode
"""

import os
import platform
from avocado import Test
from avocado import skipUnless
from avocado.utils import cpu, process, linux_modules
from avocado.utils import cpu, process


def check_kernelconf_5lvl():
'''
Check 5-Level page table support at kernel.
'''
cfg_param = "CONFIG_X86_5LEVEL"
result = linux_modules.check_kernel_config(cfg_param)
if result == linux_modules.ModuleConfig.NOT_SET:
return False
return True
def check_kernelconf(config_file, config):
"""
check if kernel config 'config' is enable on not in 'config_file'

:config_file: kernel config file path to check
:config: kernel config to check if builtin or not
return: bool
"""
with open(config_file, "r") as kernel_config:
for line in kernel_config:
line = line.split("=")
if len(line) != 2:
continue
if line[0].strip() == f"{config}":
if line[1].strip() == 'y':
return True
return False


def check_dmesg(string):
Expand All @@ -40,7 +50,12 @@ def check_dmesg(string):
"""
cmd = f'dmesg | grep -i "{string}"'
output = process.run(cmd, ignore_status=True, shell=True).stdout_text
if output != "":
if output == "":
cmd = f'journalctl -k -b | grep -i "{string}"'
output = process.run(cmd, ignore_status=True, shell=True).stdout_text
if output != "":
return True
else:
return True
return False

Expand Down Expand Up @@ -74,12 +89,30 @@ def setUp(self):
else:
self.cancel("IOMMU is not enabled")

def check_kernelconf_5lvl(self):
"""
Check if kernel config 'CONFIG_X86_5LEVEL' enabled or not
return: bool
"""

kernel_version = platform.uname()[2]
config_file = "/boot/config-" + kernel_version
if os.path.exists(config_file):
return check_kernelconf(config_file, "CONFIG_X86_5LEVEL")

config_file = "/lib/modules/" + kernel_version + "/build/.config"
if os.path.exists(config_file):
return check_kernelconf(config_file, "CONFIG_X86_5LEVEL")

self.cancel("Kernel config not found in '/boot/' and '/lib/modules/<uname -r>/build/'")
return False

def test(self):
'''
Test if host page table mode matches with iommu v2 page table mode
'''
if check_dmesg('V2 page table enabled'):
if (cpu.cpu_has_flags(["la57"]) and check_kernelconf_5lvl()):
if (cpu.cpu_has_flags(["la57"]) and self.check_kernelconf_5lvl()):
if check_v2pgtbl_mode("5"):
self.log.info("Host page table mode (5lvl) match with IOMMU V2 Page mode")
else:
Expand Down
Loading