From nobody Tue Dec 2 01:07:41 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98CC6D271; Mon, 24 Nov 2025 03:54:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763956460; cv=none; b=CAinwtfD4YW+Y6ABMlclS4vTU3wzs4w91O1iCsbjfmPc7iaHLPBJBSQsoaH/PrKlSNqZMkSVDRGaBym2kOwi+Fm4EnwlzdQe7pIVTO1yvgBpbs5Sy5xHyIVDeBPPh1x+br+tiTZxz3DKqTc9I+aASuX8M27vs6PPWvzs3mbUwUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763956460; c=relaxed/simple; bh=ozldes7sXHK5/MYLDu0oEhNYtVTl8elUPIrO8YO8r0k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LrMrEq9n1oTsWzmPxHSKtyWx7VCOiSz0N6ZeidZGIAoK6QB7SN/u3iEuL6NdZ70KUtpP95TkUykv7ByLQ68Pl3WndQxK/qPOGU87pAne2eNvEsvtk/eA9MbcB5WGgYQWty3urfWM3fmvQ/CwhR18COUGZzFNs7hq+JUHgyhmVVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8CxrtPh1iNpylonAA--.14330S3; Mon, 24 Nov 2025 11:54:09 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJAxusDa1iNp4WE9AQ--.13468S4; Mon, 24 Nov 2025 11:54:09 +0800 (CST) From: Bibo Mao To: Paolo Bonzini , Huacai Chen , WANG Xuerui , Juergen Gross , Ajay Kaher , Alexey Makhalov , Broadcom internal kernel review list Cc: kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, x86@kernel.org Subject: [PATCH v2 2/3] LoongArch: Add paravirt support with vcpu_is_preempted() in guest side Date: Mon, 24 Nov 2025 11:54:00 +0800 Message-Id: <20251124035402.3817179-3-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20251124035402.3817179-1-maobibo@loongson.cn> References: <20251124035402.3817179-1-maobibo@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJAxusDa1iNp4WE9AQ--.13468S4 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Content-Type: text/plain; charset="utf-8" Function vcpu_is_preempted() is used to check whether vCPU is preempted or not. Here add implementation with vcpu_is_preempted() when option CONFIG_PARAVIRT is enabled. Signed-off-by: Bibo Mao --- arch/loongarch/include/asm/qspinlock.h | 5 +++++ arch/loongarch/kernel/paravirt.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/loongarch/include/asm/qspinlock.h b/arch/loongarch/includ= e/asm/qspinlock.h index e76d3aa1e1eb..9a5b7ba1f4cb 100644 --- a/arch/loongarch/include/asm/qspinlock.h +++ b/arch/loongarch/include/asm/qspinlock.h @@ -34,6 +34,11 @@ static inline bool virt_spin_lock(struct qspinlock *lock) return true; } =20 +#ifdef CONFIG_SMP +#define vcpu_is_preempted vcpu_is_preempted +bool vcpu_is_preempted(int cpu); +#endif + #endif /* CONFIG_PARAVIRT */ =20 #include diff --git a/arch/loongarch/kernel/paravirt.c b/arch/loongarch/kernel/parav= irt.c index b1b51f920b23..d4163679adc4 100644 --- a/arch/loongarch/kernel/paravirt.c +++ b/arch/loongarch/kernel/paravirt.c @@ -246,6 +246,7 @@ static void pv_disable_steal_time(void) } =20 #ifdef CONFIG_SMP +DEFINE_STATIC_KEY_FALSE(virt_preempt_key); static int pv_time_cpu_online(unsigned int cpu) { unsigned long flags; @@ -267,6 +268,18 @@ static int pv_time_cpu_down_prepare(unsigned int cpu) =20 return 0; } + +bool notrace vcpu_is_preempted(int cpu) +{ + struct kvm_steal_time *src; + + if (!static_branch_unlikely(&virt_preempt_key)) + return false; + + src =3D &per_cpu(steal_time, cpu); + return !!(src->preempted & KVM_VCPU_PREEMPTED); +} +EXPORT_SYMBOL(vcpu_is_preempted); #endif =20 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 =20 static_call_update(pv_steal_clock, paravt_steal_clock); --=20 2.39.3