From nobody Sun Jul 26 13:25:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.dev ARC-Seal: i=1; a=rsa-sha256; t=1781525098; cv=none; d=zohomail.com; s=zohoarc; b=APf51/fE0aNt3dbtpDxciwJIBlaTM2c4Ev0ve40Wbwl4vu4a3hPnB7HFbG12y5bFnqgY4uONaH0S7aHWsWxOF81mmZkDyAMSRLEQnVWMLaWcgEXyA+FdsY3cY8MhAYUcPSV4dwxms/dfwi258AyfwLSX8yKlC3xZomUAdzfU6KI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781525098; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gKsRpz1I0PRfQSc7rC4V93zNNuRaBw7cvpNExO+4siI=; b=DXKjjTrxP+8Q+KJOh15X/RgevvsxS74dRzvm9aPXV7qSLb2ArU+43K9Irjna8DJpCHgNH+fE6HNBUpUDXpFH7bE2Zr5HhH3pEIpd/9OJzXvozL2QWpgvjj6t9l8lF9C5fgr3XbN/2aiAwGwIcEqHJWUwWY5hLr5lT4/v81g4s1A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1781525098777443.4141237377264; Mon, 15 Jun 2026 05:04:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wZ63U-000577-Hw; Mon, 15 Jun 2026 08:04:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wZ33l-0006lz-CH for qemu-devel@nongnu.org; Mon, 15 Jun 2026 04:52:45 -0400 Received: from out-188.mta0.migadu.com ([91.218.175.188]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wZ33j-0005Qi-Hx for qemu-devel@nongnu.org; Mon, 15 Jun 2026 04:52:45 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781513561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gKsRpz1I0PRfQSc7rC4V93zNNuRaBw7cvpNExO+4siI=; b=ixcp704aMcx7Gllce9NGNoWaYWZVZBbHSTD55HPWckaZQMPcpE/L6vFuuPsWGtm6ViARjs oGLabsQXWj57Nzcf7Bxd8f+zM/VdrlT8kcIyKK5TnEKe/Zx8TrED5UmDnNVapN4IgRPUps tpcxetXmCpxrWNnr1vkkNF9BIHcF4iU= From: Tao Cui To: qemu-devel@nongnu.org Cc: Song Gao , Paolo Bonzini , "Michael S . Tsirkin" , Cornelia Huck , kvm@vger.kernel.org, Tao Cui Subject: [PATCH 1/2] linux-headers: Add LoongArch PV TLB flush definitions Date: Mon, 15 Jun 2026 16:52:13 +0800 Message-ID: <20260615085214.44526-2-cui.tao@linux.dev> In-Reply-To: <20260615085214.44526-1-cui.tao@linux.dev> References: <20260615085214.44526-1-cui.tao@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=91.218.175.188; envelope-from=cui.tao@linux.dev; helo=out-188.mta0.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 15 Jun 2026 08:04:28 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.dev) X-ZM-MESSAGEID: 1781525102484158500 Content-Type: text/plain; charset="utf-8" From: Tao Cui Sync the LoongArch PV TLB flush definitions from the kernel: KVM_LOONGARCH_VM_FEAT_PV_TLB_FLUSH VM feature and KVM_FEATURE_PV_TLB_FLUSH guest feature. Signed-off-by: Tao Cui --- linux-headers/asm-loongarch/kvm.h | 1 + linux-headers/asm-loongarch/kvm_para.h | 1 + 2 files changed, 2 insertions(+) diff --git a/linux-headers/asm-loongarch/kvm.h b/linux-headers/asm-loongarc= h/kvm.h index cd0b5c11ca..e4cd4bbf89 100644 --- a/linux-headers/asm-loongarch/kvm.h +++ b/linux-headers/asm-loongarch/kvm.h @@ -106,6 +106,7 @@ struct kvm_fpu { #define KVM_LOONGARCH_VM_FEAT_PTW 8 #define KVM_LOONGARCH_VM_FEAT_MSGINT 9 #define KVM_LOONGARCH_VM_FEAT_PV_PREEMPT 10 +#define KVM_LOONGARCH_VM_FEAT_PV_TLB_FLUSH 11 =20 /* Device Control API on vcpu fd */ #define KVM_LOONGARCH_VCPU_CPUCFG 0 diff --git a/linux-headers/asm-loongarch/kvm_para.h b/linux-headers/asm-loo= ngarch/kvm_para.h index 3fd87a096b..98494784ed 100644 --- a/linux-headers/asm-loongarch/kvm_para.h +++ b/linux-headers/asm-loongarch/kvm_para.h @@ -16,6 +16,7 @@ #define KVM_FEATURE_IPI 1 #define KVM_FEATURE_STEAL_TIME 2 #define KVM_FEATURE_PREEMPT 3 +#define KVM_FEATURE_PV_TLB_FLUSH 4 /* BIT 24 - 31 are features configurable by user space vmm */ #define KVM_FEATURE_VIRT_EXTIOI 24 #define KVM_FEATURE_USER_HCALL 25 --=20 2.43.0 From nobody Sun Jul 26 13:25:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.dev ARC-Seal: i=1; a=rsa-sha256; t=1781525130; cv=none; d=zohomail.com; s=zohoarc; b=bAP9fV8/uoqwroQBzAcCDYL+SYbqE8lczDcam/eBccASh7vwsAjAXbJewmyCyfZmoH0SKomg2e9uRPqS9ZgyG35gYPQ2ozCrpGV+DNziog1SnaoJMnxDdoffMUtDx3iPdU3dLGivaa9mMxQ44mY2gjEUNGLEiUzaL0YNgte0Tsg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781525130; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zmGJOFjPLK/OVWREwAr5PuAPfPwrzXxVlFOvZAt5ZpA=; b=lVNaDHr4sssDu2yfCNL3rDZHpeIVK2h8Hy6o4dr/4LglLPmICXUYsGjnau3rgq7dIUgCPvzwVdfArNPC64pM53xfGE+9AqRZN2ZtKHCSsRjZadY84iLo0EhTqUOGl2yBJs998t3NyyImBxkggTPKe+DkS062niygi3A/dWvwptQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1781525130968699.8326579075377; Mon, 15 Jun 2026 05:05:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wZ63a-0005EZ-2P; Mon, 15 Jun 2026 08:04:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wZ33u-0006n5-7Z for qemu-devel@nongnu.org; Mon, 15 Jun 2026 04:52:54 -0400 Received: from out-181.mta0.migadu.com ([91.218.175.181]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wZ33s-0005Rd-AJ for qemu-devel@nongnu.org; Mon, 15 Jun 2026 04:52:53 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781513569; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zmGJOFjPLK/OVWREwAr5PuAPfPwrzXxVlFOvZAt5ZpA=; b=hBw5UvjIZGbg0tBdizXfLTe82aPBJscjJqgC8ZW/lBL6mPgp32PXsYEgwHRmE27KHcdbtv LjczFf+mNyIOWf4cFvsiFKUSb1hn9fqsD3o/p03Mqwdbv97HJSTIWEjezUEWawpTCfTFa1 MyajRfmFF6yZPPHO813nzVuiLD9a71E= From: Tao Cui To: qemu-devel@nongnu.org Cc: Song Gao , Paolo Bonzini , "Michael S . Tsirkin" , Cornelia Huck , kvm@vger.kernel.org, Tao Cui Subject: [PATCH 2/2] target/loongarch: Enable PV TLB flush advertisement to the guest Date: Mon, 15 Jun 2026 16:52:14 +0800 Message-ID: <20260615085214.44526-3-cui.tao@linux.dev> In-Reply-To: <20260615085214.44526-1-cui.tao@linux.dev> References: <20260615085214.44526-1-cui.tao@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=91.218.175.181; envelope-from=cui.tao@linux.dev; helo=out-181.mta0.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 15 Jun 2026 08:04:32 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.dev) X-ZM-MESSAGEID: 1781525133053158500 Content-Type: text/plain; charset="utf-8" From: Tao Cui Probe the KVM_LOONGARCH_VM_FEAT_PV_TLB_FLUSH VM-level capability and, when the host supports it, advertise KVM_FEATURE_PV_TLB_FLUSH to the guest by including it in the CPUCFG_KVM_FEATURE feature mask handed to the kernel. This mirrors the existing PV IPI / steal-time enablement. A new kvm-pv-tlb-flush CPU property (on/off/auto, default auto) lets users disable the feature, e.g. when migrating to a host that lacks it. The feature is only advertised when the host actually supports it, so a guest never observes KVM_FEATURE_PV_TLB_FLUSH on a host that cannot service PV TLB flush requests (which would otherwise lead to stale TLBs). Signed-off-by: Tao Cui --- target/loongarch/cpu.h | 2 ++ target/loongarch/kvm/kvm.c | 38 +++++++++++++++++++++++++++ target/loongarch/loongarch-qmp-cmds.c | 4 +-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h index ad30c73167..94e8f176f4 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -300,6 +300,7 @@ enum loongarch_features { LOONGARCH_FEATURE_PMU, LOONGARCH_FEATURE_PV_IPI, LOONGARCH_FEATURE_STEALTIME, + LOONGARCH_FEATURE_PV_TLB_FLUSH, LOONGARCH_FEATURE_PTW, }; =20 @@ -447,6 +448,7 @@ struct ArchCPU { OnOffAuto msgint; OnOffAuto kvm_pv_ipi; OnOffAuto kvm_steal_time; + OnOffAuto kvm_pv_tlb_flush; int32_t socket_id; /* socket-id of this CPU */ int32_t core_id; /* core-id of this CPU */ int32_t thread_id; /* thread-id of this CPU */ diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c index d6539c12ac..f91c388bf3 100644 --- a/target/loongarch/kvm/kvm.c +++ b/target/loongarch/kvm/kvm.c @@ -981,6 +981,12 @@ static bool kvm_feature_supported(CPUState *cs, enum l= oongarch_features feature) ret =3D kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr); return (ret =3D=3D 0); =20 + case LOONGARCH_FEATURE_PV_TLB_FLUSH: + attr.group =3D KVM_LOONGARCH_VM_FEAT_CTRL; + attr.attr =3D KVM_LOONGARCH_VM_FEAT_PV_TLB_FLUSH; + ret =3D kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr); + return (ret =3D=3D 0); + case LOONGARCH_FEATURE_PTW: attr.group =3D KVM_LOONGARCH_VM_FEAT_CTRL; attr.attr =3D KVM_LOONGARCH_VM_FEAT_PTW; @@ -1150,6 +1156,20 @@ static int kvm_cpu_check_pv_features(CPUState *cs, E= rror **errp) env->pv_features |=3D BIT(KVM_FEATURE_STEAL_TIME); } =20 + kvm_supported =3D kvm_feature_supported(cs, LOONGARCH_FEATURE_PV_TLB_F= LUSH); + if (cpu->kvm_pv_tlb_flush =3D=3D ON_OFF_AUTO_ON) { + if (!kvm_supported) { + error_setg(errp, "'pv_tlb_flush' not supported by KVM host"); + return -ENOTSUP; + } + } else if (cpu->kvm_pv_tlb_flush !=3D ON_OFF_AUTO_AUTO) { + kvm_supported =3D false; + } + + if (kvm_supported) { + env->pv_features |=3D BIT(KVM_FEATURE_PV_TLB_FLUSH); + } + if (object_dynamic_cast(OBJECT(ms), TYPE_LOONGARCH_VIRT_MACHINE)) { LoongArchVirtMachineState *lvms =3D LOONGARCH_VIRT_MACHINE(ms); =20 @@ -1266,6 +1286,18 @@ static void kvm_steal_time_set(Object *obj, bool val= ue, Error **errp) cpu->kvm_steal_time =3D value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF; } =20 +static bool kvm_pv_tlb_flush_get(Object *obj, Error **errp) +{ + return LOONGARCH_CPU(obj)->kvm_pv_tlb_flush !=3D ON_OFF_AUTO_OFF; +} + +static void kvm_pv_tlb_flush_set(Object *obj, bool value, Error **errp) +{ + LoongArchCPU *cpu =3D LOONGARCH_CPU(obj); + + cpu->kvm_pv_tlb_flush =3D value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF; +} + void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu) { cpu->lbt =3D ON_OFF_AUTO_AUTO; @@ -1291,6 +1323,12 @@ void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu) kvm_steal_time_set); object_property_set_description(OBJECT(cpu), "kvm-steal-time", "Set off to disable KVM steal time."); + + cpu->kvm_pv_tlb_flush =3D ON_OFF_AUTO_AUTO; + object_property_add_bool(OBJECT(cpu), "kvm-pv-tlb-flush", + kvm_pv_tlb_flush_get, kvm_pv_tlb_flush_set); + object_property_set_description(OBJECT(cpu), "kvm-pv-tlb-flush", + "Set off to disable KVM PV TLB flush."= ); } =20 int kvm_arch_destroy_vcpu(CPUState *cs) diff --git a/target/loongarch/loongarch-qmp-cmds.c b/target/loongarch/loong= arch-qmp-cmds.c index f053f22bb8..5f372d85a9 100644 --- a/target/loongarch/loongarch-qmp-cmds.c +++ b/target/loongarch/loongarch-qmp-cmds.c @@ -41,8 +41,8 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **= errp) } =20 static const char *cpu_model_advertised_features[] =3D { - "lsx", "lasx", "lbt", "pmu", "kvm-pv-ipi", "kvm-steal-time", "msgint", - "ptw", NULL + "lsx", "lasx", "lbt", "pmu", "kvm-pv-ipi", "kvm-steal-time", + "kvm-pv-tlb-flush", "msgint", "ptw", NULL }; =20 CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType= type, --=20 2.43.0