Skip to content

Commit 3fa3b22

Browse files
mdouchapevik
authored andcommitted
kvm_pagefault01: Use library functions to reload KVM modules
Link: https://lore.kernel.org/ltp/[email protected]/ Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Martin Doucha <[email protected]>
1 parent 3eb2adb commit 3fa3b22

File tree

1 file changed

+5
-54
lines changed

1 file changed

+5
-54
lines changed

testcases/kernel/kvm/kvm_pagefault01.c

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -136,70 +136,21 @@ TST_TEST_TCONF("Test supported only on x86_64");
136136

137137
#else /* COMPILE_PAYLOAD */
138138

139-
#include <ctype.h>
140-
#include <stdio.h>
141-
#include <unistd.h>
142139
#include "tst_module.h"
143140

144141
#define TDP_MMU_SYSFILE "/sys/module/kvm/parameters/tdp_mmu"
145142
#define TDP_AMD_SYSFILE "/sys/module/kvm_amd/parameters/npt"
146143
#define TDP_INTEL_SYSFILE "/sys/module/kvm_intel/parameters/ept"
147144

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-
194145
static void disable_tdp(void)
195146
{
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});
198149

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});
201152

202-
if (read_bool_sys_param(TDP_MMU_SYSFILE) > 0)
153+
if (tst_read_bool_sys_param(TDP_MMU_SYSFILE) > 0)
203154
tst_res(TINFO, "WARNING: tdp_mmu is enabled, beware of false negatives");
204155
}
205156

0 commit comments

Comments
 (0)