Skip to content

Commit 872d277

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Add paravirt vcpu_is_preempted() support in guest side
Function vcpu_is_preempted() is used to check whether vCPU is preempted or not. Here add the implementation with vcpu_is_preempted() when option CONFIG_PARAVIRT is enabled. Acked-by: Juergen Gross <jgross@suse.com> Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 9b486cd commit 872d277

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

arch/loongarch/include/asm/qspinlock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ static inline bool virt_spin_lock(struct qspinlock *lock)
3434
return true;
3535
}
3636

37+
#define vcpu_is_preempted vcpu_is_preempted
38+
39+
bool vcpu_is_preempted(int cpu);
40+
3741
#endif /* CONFIG_PARAVIRT */
3842

3943
#include <asm-generic/qspinlock.h>

arch/loongarch/kernel/paravirt.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ static int has_steal_clock;
1212
struct static_key paravirt_steal_enabled;
1313
struct static_key paravirt_steal_rq_enabled;
1414
static DEFINE_PER_CPU(struct kvm_steal_time, steal_time) __aligned(64);
15+
static DEFINE_STATIC_KEY_FALSE(virt_preempt_key);
1516
DEFINE_STATIC_KEY_FALSE(virt_spin_lock_key);
1617

1718
static u64 native_steal_clock(int cpu)
@@ -267,6 +268,18 @@ static int pv_time_cpu_down_prepare(unsigned int cpu)
267268

268269
return 0;
269270
}
271+
272+
bool vcpu_is_preempted(int cpu)
273+
{
274+
struct kvm_steal_time *src;
275+
276+
if (!static_branch_unlikely(&virt_preempt_key))
277+
return false;
278+
279+
src = &per_cpu(steal_time, cpu);
280+
return !!(src->preempted & KVM_VCPU_PREEMPTED);
281+
}
282+
EXPORT_SYMBOL(vcpu_is_preempted);
270283
#endif
271284

272285
static void pv_cpu_reboot(void *unused)
@@ -308,6 +321,9 @@ int __init pv_time_init(void)
308321
pr_err("Failed to install cpu hotplug callbacks\n");
309322
return r;
310323
}
324+
325+
if (kvm_para_has_feature(KVM_FEATURE_PREEMPT))
326+
static_branch_enable(&virt_preempt_key);
311327
#endif
312328

313329
static_call_update(pv_steal_clock, paravt_steal_clock);
@@ -318,7 +334,10 @@ int __init pv_time_init(void)
318334
static_key_slow_inc(&paravirt_steal_rq_enabled);
319335
#endif
320336

321-
pr_info("Using paravirt steal-time\n");
337+
if (static_key_enabled(&virt_preempt_key))
338+
pr_info("Using paravirt steal-time with preempt enabled\n");
339+
else
340+
pr_info("Using paravirt steal-time with preempt disabled\n");
322341

323342
return 0;
324343
}

0 commit comments

Comments
 (0)