From: Tao Cui <cui.tao@linux.dev>
To: maobibo@loongson.cn, zhaotianrui@loongson.cn,
chenhuacai@kernel.org, loongarch@lists.linux.dev
Cc: kernel@xen0n.name, kvm@vger.kernel.org, Tao Cui <cuitao@kylinos.cn>
Subject: [PATCH v3 1/4] LoongArch: KVM: Preserve auto-enabled PV features on userspace override
Date: Tue, 2 Jun 2026 10:18:16 +0800 [thread overview]
Message-ID: <20260602021819.2373404-2-cui.tao@linux.dev> (raw)
In-Reply-To: <20260602021819.2373404-1-cui.tao@linux.dev>
From: Tao Cui <cuitao@kylinos.cn>
When userspace (e.g., QEMU) sets PV features via KVM_SET_DEVICE_ATTR
with CPUCFG_KVM_FEATURE, it completely replaces the kernel-default
pv_features. This causes features auto-enabled by the kernel (such as
KVM_FEATURE_STEAL_TIME) to be lost if userspace doesn't explicitly
include them.
Add a pv_auto_features field to struct kvm_arch that saves the
kernel-default PV features set during kvm_vm_init_features(). When
userspace overrides pv_features, OR the saved auto features back
to preserve them.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
arch/loongarch/include/asm/kvm_host.h | 2 ++
arch/loongarch/kvm/vcpu.c | 7 +++++++
arch/loongarch/kvm/vm.c | 1 +
3 files changed, 10 insertions(+)
diff --git a/arch/loongarch/include/asm/kvm_host.h b/arch/loongarch/include/asm/kvm_host.h
index 776bc487a705..903cb67ca817 100644
--- a/arch/loongarch/include/asm/kvm_host.h
+++ b/arch/loongarch/include/asm/kvm_host.h
@@ -127,6 +127,8 @@ struct kvm_arch {
struct kvm_phyid_map *phyid_map;
/* Enabled PV features */
unsigned long pv_features;
+ /* PV features auto-enabled by kernel */
+ unsigned long pv_auto_features;
/* Supported KVM features */
unsigned long kvm_features;
diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
index e28084c49e68..47a59ce9e561 100644
--- a/arch/loongarch/kvm/vcpu.c
+++ b/arch/loongarch/kvm/vcpu.c
@@ -1165,6 +1165,13 @@ static int kvm_loongarch_cpucfg_set_attr(struct kvm_vcpu *vcpu,
if (val & ~valid)
return -EINVAL;
+ /*
+ * Auto-enabled features (e.g. PV TLB flush) that userspace
+ * is not aware of are preserved so that no QEMU changes are
+ * needed for pure kernel-internal optimisations.
+ */
+ val = (val | kvm->arch.pv_auto_features) & valid;
+
/* All vCPUs need set the same PV features */
if ((kvm->arch.pv_features & LOONGARCH_PV_FEAT_UPDATED)
&& ((kvm->arch.pv_features & valid) != val))
diff --git a/arch/loongarch/kvm/vm.c b/arch/loongarch/kvm/vm.c
index 1317c718f896..8af874e0b36b 100644
--- a/arch/loongarch/kvm/vm.c
+++ b/arch/loongarch/kvm/vm.c
@@ -57,6 +57,7 @@ static void kvm_vm_init_features(struct kvm *kvm)
kvm->arch.kvm_features |= BIT(KVM_LOONGARCH_VM_FEAT_PV_PREEMPT);
kvm->arch.kvm_features |= BIT(KVM_LOONGARCH_VM_FEAT_PV_STEALTIME);
}
+ kvm->arch.pv_auto_features = kvm->arch.pv_features;
}
int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
--
2.43.0
next prev parent reply other threads:[~2026-06-02 2:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-02 2:18 [PATCH v3 0/4] LoongArch: KVM: Add PV TLB flush support Tao Cui
2026-06-02 2:18 ` Tao Cui [this message]
2026-06-02 2:26 ` [PATCH v3 1/4] LoongArch: KVM: Preserve auto-enabled PV features on userspace override sashiko-bot
2026-06-02 2:18 ` [PATCH v3 2/4] LoongArch: KVM: Add PV TLB flush support via steal-time shared memory Tao Cui
2026-06-02 2:37 ` sashiko-bot
2026-06-02 2:18 ` [PATCH v3 3/4] LoongArch: KVM: Implement guest-side PV TLB flush Tao Cui
2026-06-02 2:46 ` sashiko-bot
2026-06-02 2:18 ` [PATCH v3 4/4] KVM: selftests: loongarch: Add PV TLB flush performance test Tao Cui
2026-06-02 2:52 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260602021819.2373404-2-cui.tao@linux.dev \
--to=cui.tao@linux.dev \
--cc=chenhuacai@kernel.org \
--cc=cuitao@kylinos.cn \
--cc=kernel@xen0n.name \
--cc=kvm@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=maobibo@loongson.cn \
--cc=zhaotianrui@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox