]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
LoongArch: KVM: Add paravirt vcpu_is_preempted() support in guest side
authorBibo Mao <maobibo@loongson.cn>
Fri, 6 Feb 2026 01:28:01 +0000 (09:28 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Fri, 6 Feb 2026 01:28:01 +0000 (09:28 +0800)
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>
arch/loongarch/include/asm/qspinlock.h
arch/loongarch/kernel/paravirt.c

index e76d3aa1e1ebe7dcae953bf6dc89d55802e05cfc..66244801db67d23a8882844fd96bdd8df352d525 100644 (file)
@@ -34,6 +34,10 @@ __retry:
        return true;
 }
 
+#define vcpu_is_preempted vcpu_is_preempted
+
+bool vcpu_is_preempted(int cpu);
+
 #endif /* CONFIG_PARAVIRT */
 
 #include <asm-generic/qspinlock.h>
index b1b51f920b2319ba622ab83a7e191e2b51e33ba8..7f1561906e10b4a7daf47fd05cc829353c1ec865 100644 (file)
@@ -12,6 +12,7 @@ static int has_steal_clock;
 struct static_key paravirt_steal_enabled;
 struct static_key paravirt_steal_rq_enabled;
 static DEFINE_PER_CPU(struct kvm_steal_time, steal_time) __aligned(64);
+static DEFINE_STATIC_KEY_FALSE(virt_preempt_key);
 DEFINE_STATIC_KEY_FALSE(virt_spin_lock_key);
 
 static u64 native_steal_clock(int cpu)
@@ -267,6 +268,18 @@ static int pv_time_cpu_down_prepare(unsigned int cpu)
 
        return 0;
 }
+
+bool vcpu_is_preempted(int cpu)
+{
+       struct kvm_steal_time *src;
+
+       if (!static_branch_unlikely(&virt_preempt_key))
+               return false;
+
+       src = &per_cpu(steal_time, cpu);
+       return !!(src->preempted & KVM_VCPU_PREEMPTED);
+}
+EXPORT_SYMBOL(vcpu_is_preempted);
 #endif
 
 static void pv_cpu_reboot(void *unused)
@@ -308,6 +321,9 @@ int __init pv_time_init(void)
                pr_err("Failed to install cpu hotplug callbacks\n");
                return r;
        }
+
+       if (kvm_para_has_feature(KVM_FEATURE_PREEMPT))
+               static_branch_enable(&virt_preempt_key);
 #endif
 
        static_call_update(pv_steal_clock, paravt_steal_clock);
@@ -318,7 +334,10 @@ int __init pv_time_init(void)
                static_key_slow_inc(&paravirt_steal_rq_enabled);
 #endif
 
-       pr_info("Using paravirt steal-time\n");
+       if (static_key_enabled(&virt_preempt_key))
+               pr_info("Using paravirt steal-time with preempt enabled\n");
+       else
+               pr_info("Using paravirt steal-time with preempt disabled\n");
 
        return 0;
 }