Skip to content

Commit 3abb708

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Implement function kvm_para_has_feature()
Implement function kvm_para_has_feature() to detect supported paravirt features. It can be used by device driver to detect and enable paravirt features, such as the EIOINTC irqchip driver is able to detect feature KVM_FEATURE_VIRT_EXTIOI and do some optimization. Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent cdc118f commit 3abb708

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

arch/loongarch/include/asm/kvm_para.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,20 @@ static __always_inline long kvm_hypercall5(u64 fid,
156156
return ret;
157157
}
158158

159+
#ifdef CONFIG_PARAVIRT
160+
bool kvm_para_available(void);
161+
unsigned int kvm_arch_para_features(void);
162+
#else
163+
static inline bool kvm_para_available(void)
164+
{
165+
return false;
166+
}
167+
159168
static inline unsigned int kvm_arch_para_features(void)
160169
{
161170
return 0;
162171
}
172+
#endif
163173

164174
static inline unsigned int kvm_arch_para_hints(void)
165175
{

arch/loongarch/kernel/paravirt.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,14 @@ static void pv_init_ipi(void)
152152
}
153153
#endif
154154

155-
static bool kvm_para_available(void)
155+
bool kvm_para_available(void)
156156
{
157157
int config;
158158
static int hypervisor_type;
159159

160+
if (!cpu_has_hypervisor)
161+
return false;
162+
160163
if (!hypervisor_type) {
161164
config = read_cpucfg(CPUCFG_KVM_SIG);
162165
if (!memcmp(&config, KVM_SIGNATURE, 4))
@@ -166,17 +169,22 @@ static bool kvm_para_available(void)
166169
return hypervisor_type == HYPERVISOR_KVM;
167170
}
168171

169-
int __init pv_ipi_init(void)
172+
unsigned int kvm_arch_para_features(void)
170173
{
171-
int feature;
174+
static unsigned int feature;
172175

173-
if (!cpu_has_hypervisor)
174-
return 0;
175176
if (!kvm_para_available())
176177
return 0;
177178

178-
feature = read_cpucfg(CPUCFG_KVM_FEATURE);
179-
if (!(feature & BIT(KVM_FEATURE_IPI)))
179+
if (!feature)
180+
feature = read_cpucfg(CPUCFG_KVM_FEATURE);
181+
182+
return feature;
183+
}
184+
185+
int __init pv_ipi_init(void)
186+
{
187+
if (!kvm_para_has_feature(KVM_FEATURE_IPI))
180188
return 0;
181189

182190
#ifdef CONFIG_SMP
@@ -259,15 +267,9 @@ static struct notifier_block pv_reboot_nb = {
259267

260268
int __init pv_time_init(void)
261269
{
262-
int r, feature;
263-
264-
if (!cpu_has_hypervisor)
265-
return 0;
266-
if (!kvm_para_available())
267-
return 0;
270+
int r;
268271

269-
feature = read_cpucfg(CPUCFG_KVM_FEATURE);
270-
if (!(feature & BIT(KVM_FEATURE_STEAL_TIME)))
272+
if (!kvm_para_has_feature(KVM_FEATURE_STEAL_TIME))
271273
return 0;
272274

273275
has_steal_clock = 1;

0 commit comments

Comments
 (0)