1818Validate 5 level page table support in v2 iommu page table mode
1919"""
2020
21+ import os
22+ import platform
2123from avocado import Test
2224from 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
3747def check_dmesg (string ):
@@ -40,7 +50,12 @@ def check_dmesg(string):
4050 """
4151 cmd = f'dmesg | grep -i "{ string } "'
4252 output = process .run (cmd , ignore_status = True , shell = True ).stdout_text
43- if output != "" :
53+ if output == "" :
54+ cmd = f'journalctl -k -b | grep -i "{ string } "'
55+ output = process .run (cmd , ignore_status = True , shell = True ).stdout_text
56+ if output != "" :
57+ return True
58+ else :
4459 return True
4560 return False
4661
@@ -74,12 +89,30 @@ def setUp(self):
7489 else :
7590 self .cancel ("IOMMU is not enabled" )
7691
92+ def check_kernelconf_5lvl (self ):
93+ """
94+ Check if kernel config 'CONFIG_X86_5LEVEL' enabled or not
95+ return: bool
96+ """
97+
98+ kernel_version = platform .uname ()[2 ]
99+ config_file = "/boot/config-" + kernel_version
100+ if os .path .exists (config_file ):
101+ return check_kernelconf (config_file , "CONFIG_X86_5LEVEL" )
102+
103+ config_file = "/lib/modules/" + kernel_version + "/build/.config"
104+ if os .path .exists (config_file ):
105+ return check_kernelconf (config_file , "CONFIG_X86_5LEVEL" )
106+
107+ self .cancel ("Kernel config not found in '/boot/' and '/lib/modules/<uname -r>/build/'" )
108+ return False
109+
77110 def test (self ):
78111 '''
79112 Test if host page table mode matches with iommu v2 page table mode
80113 '''
81114 if check_dmesg ('V2 page table enabled' ):
82- if (cpu .cpu_has_flags (["la57" ]) and check_kernelconf_5lvl ()):
115+ if (cpu .cpu_has_flags (["la57" ]) and self . check_kernelconf_5lvl ()):
83116 if check_v2pgtbl_mode ("5" ):
84117 self .log .info ("Host page table mode (5lvl) match with IOMMU V2 Page mode" )
85118 else :
0 commit comments