Skip to content

Commit edda668

Browse files
committed
io/iommu/amd: Update check_kernelconf_5lvl() to extend support to rhel
Currently "check_kernelconf_5lvl()" checks "/boot/" directory for kernel config files. Ubuntu based system have config files for distro as well as custom build kernel in "/boot/" directory. But on rhel based systems, custom build kernel's config are not present in /boot/ directory. Use /lib/modules/<kernel_version>/build/.config to check for kernel config file making test work for both ubuntu and rhel. Signed-off-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
1 parent bdb918b commit edda668

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

io/iommu/amd/iommu_v2pgmode_test.py

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,30 @@
1818
Validate 5 level page table support in v2 iommu page table mode
1919
"""
2020

21+
import os
22+
import platform
2123
from avocado import Test
2224
from avocado import skipUnless
23-
from avocado.utils import cpu, process, linux_modules
25+
from avocado.utils import cpu, process
2426

2527

26-
def check_kernelconf_5lvl():
27-
'''
28-
Check 5-Level page table support at kernel.
29-
'''
30-
cfg_param = "CONFIG_X86_5LEVEL"
31-
result = linux_modules.check_kernel_config(cfg_param)
32-
if result == linux_modules.ModuleConfig.NOT_SET:
33-
return False
34-
return True
28+
def check_kernelconf(config_file, config):
29+
"""
30+
check if kernel config 'config' is enable on not in 'config_file'
31+
32+
:config_file: kernel config file path to check
33+
:config: kernel config to check if builtin or not
34+
return: bool
35+
"""
36+
with open(config_file, "r") as kernel_config:
37+
for line in kernel_config:
38+
line = line.split("=")
39+
if len(line) != 2:
40+
continue
41+
if line[0].strip() == f"{config}":
42+
if line[1].strip() == 'y':
43+
return True
44+
return False
3545

3646

3747
def check_dmesg(string):
@@ -74,12 +84,30 @@ def setUp(self):
7484
else:
7585
self.cancel("IOMMU is not enabled")
7686

87+
def check_kernelconf_5lvl(self):
88+
"""
89+
Check if kernel config 'CONFIG_X86_5LEVEL' enabled or not
90+
return: bool
91+
"""
92+
93+
kernel_version = platform.uname()[2]
94+
config_file = "/boot/config-" + kernel_version
95+
if os.path.exists(config_file):
96+
return check_kernelconf(config_file, "CONFIG_X86_5LEVEL")
97+
98+
config_file = "/lib/modules/" + kernel_version + "/build/.config"
99+
if os.path.exists(config_file):
100+
return check_kernelconf(config_file, "CONFIG_X86_5LEVEL")
101+
102+
self.cancel("Kernel config not found in '/boot/' and '/lib/modules/<uname -r>/build/'")
103+
return False
104+
77105
def test(self):
78106
'''
79107
Test if host page table mode matches with iommu v2 page table mode
80108
'''
81109
if check_dmesg('V2 page table enabled'):
82-
if (cpu.cpu_has_flags(["la57"]) and check_kernelconf_5lvl()):
110+
if (cpu.cpu_has_flags(["la57"]) and self.check_kernelconf_5lvl()):
83111
if check_v2pgtbl_mode("5"):
84112
self.log.info("Host page table mode (5lvl) match with IOMMU V2 Page mode")
85113
else:

0 commit comments

Comments
 (0)