Skip to content

Commit e2bcf62

Browse files
committed
KVM: selftests: Move Intel and AMD module param helpers to x86/processor.h
Move the x86 specific helpers for getting kvm_{amd,intel} module params to x86 where they belong. Expose the module-agnostic helpers globally, there is nothing secret about the logic. Link: https://lore.kernel.org/r/20250806225159.1687326-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent a585b87 commit e2bcf62

3 files changed

Lines changed: 33 additions & 38 deletions

File tree

tools/testing/selftests/kvm/include/kvm_util.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,18 @@ int __open_path_or_exit(const char *path, int flags, const char *enoent_help);
260260
int open_path_or_exit(const char *path, int flags);
261261
int open_kvm_dev_path_or_exit(void);
262262

263-
bool get_kvm_param_bool(const char *param);
264-
bool get_kvm_intel_param_bool(const char *param);
265-
bool get_kvm_amd_param_bool(const char *param);
263+
int kvm_get_module_param_integer(const char *module_name, const char *param);
264+
bool kvm_get_module_param_bool(const char *module_name, const char *param);
266265

267-
int get_kvm_param_integer(const char *param);
268-
int get_kvm_intel_param_integer(const char *param);
269-
int get_kvm_amd_param_integer(const char *param);
266+
static inline bool get_kvm_param_bool(const char *param)
267+
{
268+
return kvm_get_module_param_bool("kvm", param);
269+
}
270+
271+
static inline int get_kvm_param_integer(const char *param)
272+
{
273+
return kvm_get_module_param_integer("kvm", param);
274+
}
270275

271276
unsigned int kvm_check_cap(long cap);
272277

tools/testing/selftests/kvm/include/x86/processor.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,26 @@ static inline uint8_t xsetbv_safe(uint32_t index, uint64_t value)
13141314

13151315
bool kvm_is_tdp_enabled(void);
13161316

1317+
static inline bool get_kvm_intel_param_bool(const char *param)
1318+
{
1319+
return kvm_get_module_param_bool("kvm_intel", param);
1320+
}
1321+
1322+
static inline bool get_kvm_amd_param_bool(const char *param)
1323+
{
1324+
return kvm_get_module_param_bool("kvm_amd", param);
1325+
}
1326+
1327+
static inline int get_kvm_intel_param_integer(const char *param)
1328+
{
1329+
return kvm_get_module_param_integer("kvm_intel", param);
1330+
}
1331+
1332+
static inline int get_kvm_amd_param_integer(const char *param)
1333+
{
1334+
return kvm_get_module_param_integer("kvm_amd", param);
1335+
}
1336+
13171337
static inline bool kvm_is_pmu_enabled(void)
13181338
{
13191339
return get_kvm_param_bool("enable_pmu");

tools/testing/selftests/kvm/lib/kvm_util.c

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static ssize_t get_module_param(const char *module_name, const char *param,
9595
return bytes_read;
9696
}
9797

98-
static int get_module_param_integer(const char *module_name, const char *param)
98+
int kvm_get_module_param_integer(const char *module_name, const char *param)
9999
{
100100
/*
101101
* 16 bytes to hold a 64-bit value (1 byte per char), 1 byte for the
@@ -119,7 +119,7 @@ static int get_module_param_integer(const char *module_name, const char *param)
119119
return atoi_paranoid(value);
120120
}
121121

122-
static bool get_module_param_bool(const char *module_name, const char *param)
122+
bool kvm_get_module_param_bool(const char *module_name, const char *param)
123123
{
124124
char value;
125125
ssize_t r;
@@ -135,36 +135,6 @@ static bool get_module_param_bool(const char *module_name, const char *param)
135135
TEST_FAIL("Unrecognized value '%c' for boolean module param", value);
136136
}
137137

138-
bool get_kvm_param_bool(const char *param)
139-
{
140-
return get_module_param_bool("kvm", param);
141-
}
142-
143-
bool get_kvm_intel_param_bool(const char *param)
144-
{
145-
return get_module_param_bool("kvm_intel", param);
146-
}
147-
148-
bool get_kvm_amd_param_bool(const char *param)
149-
{
150-
return get_module_param_bool("kvm_amd", param);
151-
}
152-
153-
int get_kvm_param_integer(const char *param)
154-
{
155-
return get_module_param_integer("kvm", param);
156-
}
157-
158-
int get_kvm_intel_param_integer(const char *param)
159-
{
160-
return get_module_param_integer("kvm_intel", param);
161-
}
162-
163-
int get_kvm_amd_param_integer(const char *param)
164-
{
165-
return get_module_param_integer("kvm_amd", param);
166-
}
167-
168138
/*
169139
* Capability
170140
*

0 commit comments

Comments
 (0)