@@ -136,70 +136,21 @@ TST_TEST_TCONF("Test supported only on x86_64");
136
136
137
137
#else /* COMPILE_PAYLOAD */
138
138
139
- #include <ctype.h>
140
- #include <stdio.h>
141
- #include <unistd.h>
142
139
#include "tst_module.h"
143
140
144
141
#define TDP_MMU_SYSFILE "/sys/module/kvm/parameters/tdp_mmu"
145
142
#define TDP_AMD_SYSFILE "/sys/module/kvm_amd/parameters/npt"
146
143
#define TDP_INTEL_SYSFILE "/sys/module/kvm_intel/parameters/ept"
147
144
148
- #define BUF_SIZE 64
149
-
150
- static int read_bool_sys_param (const char * filename )
151
- {
152
- char buf [BUF_SIZE ];
153
- int i , fd , ret ;
154
-
155
- fd = open (filename , O_RDONLY );
156
-
157
- if (fd < 0 )
158
- return -1 ;
159
-
160
- ret = read (fd , buf , BUF_SIZE - 1 );
161
- SAFE_CLOSE (fd );
162
-
163
- if (ret < 1 )
164
- return -1 ;
165
-
166
- buf [ret ] = '\0' ;
167
-
168
- for (i = 0 ; buf [i ] && !isspace (buf [i ]); i ++ )
169
- ;
170
-
171
- buf [i ] = '\0' ;
172
-
173
- if (isdigit (buf [0 ])) {
174
- tst_parse_int (buf , & ret , INT_MIN , INT_MAX );
175
- return ret ;
176
- }
177
-
178
- if (!strcasecmp (buf , "N" ))
179
- return 0 ;
180
-
181
- /* Assume that any other value than 0 or N means the param is enabled */
182
- return 1 ;
183
- }
184
-
185
- static void reload_module (const char * module , char * arg )
186
- {
187
- const char * const argv [] = {"modprobe" , module , arg , NULL };
188
-
189
- tst_res (TINFO , "Reloading module %s with parameter %s" , module , arg );
190
- tst_module_unload (module );
191
- tst_cmd (argv , NULL , NULL , 0 );
192
- }
193
-
194
145
static void disable_tdp (void )
195
146
{
196
- if (read_bool_sys_param (TDP_AMD_SYSFILE ) > 0 )
197
- reload_module ("kvm_amd" , "npt=0" );
147
+ if (tst_read_bool_sys_param (TDP_AMD_SYSFILE ) > 0 )
148
+ tst_module_reload ("kvm_amd" , ( char * const []){ "npt=0" , NULL } );
198
149
199
- if (read_bool_sys_param (TDP_INTEL_SYSFILE ) > 0 )
200
- reload_module ("kvm_intel" , "ept=0" );
150
+ if (tst_read_bool_sys_param (TDP_INTEL_SYSFILE ) > 0 )
151
+ tst_module_reload ("kvm_intel" , ( char * const []){ "ept=0" , NULL } );
201
152
202
- if (read_bool_sys_param (TDP_MMU_SYSFILE ) > 0 )
153
+ if (tst_read_bool_sys_param (TDP_MMU_SYSFILE ) > 0 )
203
154
tst_res (TINFO , "WARNING: tdp_mmu is enabled, beware of false negatives" );
204
155
}
205
156
0 commit comments