From nobody Sun Jul 12 00:33:16 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=1783644684; cv=none; d=zohomail.com; s=zohoarc; b=Q7umIOZAaqY7EGSvKHXuFh6RHvQLJWCONsvVKL+DC2/5lob7K3a2oZZalOiZetlttdYaJlhZZAR+WIHXlemhwf6mwlBWDSt0mBbPntCqFznW95AaxwB2rNYAbYNzqJnwbRkij7mmGMepOdd0intD5wiV+G714RBNqY3tAcWfL4M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783644684; 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=LUHiRTEzLRpwzmfD7SzZnCzbVBBFP3DYHhGh4jI132s=; b=fjat+Tk8MIlNQFI8UosJSZ0NSozsbIIhPhXve9fl+xZS4b/L7RRVwMxKhZ+eBe5Hmf+LWkYqC9zE2Ib9XB3NWiLaYeXQCpo7pqsS0h7J2NBTjqJKmnPw8B0qBfWDEkzKSEAtsdyU09+aQP3wADVDSbxSMsuZd02arAkAPqIeIQ0= 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 1783644683486604.0981955437162; Thu, 9 Jul 2026 17:51:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whzS6-00009V-LR; Thu, 09 Jul 2026 20:50:50 -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 1whzS4-000094-0F for qemu-devel@nongnu.org; Thu, 09 Jul 2026 20:50:48 -0400 Received: from out-180.mta0.migadu.com ([91.218.175.180]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whzS2-0005dS-3u for qemu-devel@nongnu.org; Thu, 09 Jul 2026 20:50:47 -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=1783644643; 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=LUHiRTEzLRpwzmfD7SzZnCzbVBBFP3DYHhGh4jI132s=; b=GbH7GDbyE1SrwviAZVuNs8Sl6VGP5zorgeHuSriLGoBYNcmXLb/UDXooB/aVMJ8bujvf8j CcFBqWdqq3wUfuc9HzHyBUBkQIv+otamXYS2UZRpN/3cnIfReBsPqQ0gWuyP5Hde7JNW5r ZiRnTbYQPZkoBTrEr6nd9HC4pgoQMdE= From: Tao Cui To: qemu-devel@nongnu.org Cc: Song Gao , Bibo Mao , Jiaxun Yang , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Tao Cui Subject: [PATCH v2 1/3] target/loongarch/kvm: advertise pv features per vCPU Date: Fri, 10 Jul 2026 08:50:27 +0800 Message-ID: <20260710005029.345378-2-cui.tao@linux.dev> In-Reply-To: <20260710005029.345378-1-cui.tao@linux.dev> References: <20260710005029.345378-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.180; envelope-from=cui.tao@linux.dev; helo=out-180.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-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: 1783644689026158500 Content-Type: text/plain; charset="utf-8" From: Tao Cui kvm_set_pv_features() programs the KVM_FEATURE cpucfg attribute, which is a per-vCPU setting. It was called from kvm_arch_put_registers() under a function-local static guard, so it ran only once for the whole VM: only the first vCPU got its pv features pushed to KVM, and on SMP guests the others never saw KVM_FEATURE_IPI / KVM_FEATURE_STEAL_TIME. Drop the static guard and push pv features per vCPU under KVM_PUT_FULL_STATE, the same gate kvm_set_stealtime() already uses. Host feature detection stays in kvm_arch_init_vcpu(); the per-vCPU state write belongs in kvm_arch_put_registers(). Signed-off-by: Tao Cui --- target/loongarch/kvm/kvm.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c index d6539c12ac..c557ee3c3d 100644 --- a/target/loongarch/kvm/kvm.c +++ b/target/loongarch/kvm/kvm.c @@ -816,7 +816,6 @@ int kvm_arch_get_registers(CPUState *cs, Error **errp) int kvm_arch_put_registers(CPUState *cs, KvmPutState level, Error **errp) { int ret; - static int once; =20 ret =3D kvm_loongarch_put_regs_core(cs); if (ret) { @@ -843,19 +842,17 @@ int kvm_arch_put_registers(CPUState *cs, KvmPutState = level, Error **errp) return ret; } =20 - if (!once) { + if (level >=3D KVM_PUT_FULL_STATE) { + /* + * pv_features and steal time are per-vCPU state. Push them on + * full-state sync so every vCPU gets its own settings; the kernel + * clears the steal-time guest_addr on KVM_PUT_RESET_STATE. + */ ret =3D kvm_set_pv_features(cs); if (ret) { return ret; } - once =3D 1; - } =20 - if (level >=3D KVM_PUT_FULL_STATE) { - /* - * only KVM_PUT_FULL_STATE is required, kvm kernel will clear - * guest_addr for KVM_PUT_RESET_STATE - */ ret =3D kvm_set_stealtime(cs); if (ret) { return ret; --=20 2.43.0 From nobody Sun Jul 12 00:33:16 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=1783644684; cv=none; d=zohomail.com; s=zohoarc; b=eWMI9jDK6LE8F6JUfRnsaIQMv0EWLHknBcL7+Z2EePVKWtuqn1LIXs/i5C4VNZwW6d+Ws9NtrUmHiV4oaC3ycXcqzRLyVIV5JhxcxNLW5jwzIhP4TbFDApB1iqo5TxNT3uHK7sSXEiDEu5FD/vaQwHXemzzzwkRHMZkXvJxwxXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783644684; 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=pSFFtc8Qs7YopIepyDIhuXWQE/SNoI3BvDv19mqrZl0=; b=Kb5ImM6BbeUUgadc87UHdu1NGQjaVp1qG9d8kJYbLCeFQOBJzgRIfH3MizeIrK7VdtvTotLO0vHBcsVPO5wXLuitfyozsYn/XiLq/egJTBCIDds2EyrY/rRVwZSs7rOfjNTMuVBvzm3XHzJ8OTnNINcgoag0Zz6Uig/h6bpmDvQ= 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 1783644683484595.8712703927503; Thu, 9 Jul 2026 17:51:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whzS9-0000A2-S9; Thu, 09 Jul 2026 20:50:53 -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 1whzS8-00009o-9k for qemu-devel@nongnu.org; Thu, 09 Jul 2026 20:50:52 -0400 Received: from out-173.mta0.migadu.com ([2001:41d0:1004:224b::ad]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whzS4-0005dr-W8 for qemu-devel@nongnu.org; Thu, 09 Jul 2026 20:50:51 -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=1783644646; 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=pSFFtc8Qs7YopIepyDIhuXWQE/SNoI3BvDv19mqrZl0=; b=A6rgKkRs4fgBxHAE5a7hTlueHxJVq4a225Jd9ZuWJjpUWkMCH4sBjh8eeCw7Wtk2R9SQap wIn8hG+IbDR6VHOs2HXHfOGUS+sDlC+rPN+OGLEj9bgiDfbfG3tv8hhepF1cuFCgBWzJRY ixTyoY0V+uQjjL6ITIdgd79R533+zNQ= From: Tao Cui To: qemu-devel@nongnu.org Cc: Song Gao , Bibo Mao , Jiaxun Yang , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Tao Cui Subject: [PATCH v2 2/3] target/loongarch: migrate pv_features in the vCPU VMState Date: Fri, 10 Jul 2026 08:50:28 +0800 Message-ID: <20260710005029.345378-3-cui.tao@linux.dev> In-Reply-To: <20260710005029.345378-1-cui.tao@linux.dev> References: <20260710005029.345378-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=2001:41d0:1004:224b::ad; envelope-from=cui.tao@linux.dev; helo=out-173.mta0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: 1783644689332158500 Content-Type: text/plain; charset="utf-8" From: Tao Cui pv_features holds the value of pseudo-register CPUCFG_KVM_FEATURE and is now pushed per vCPU. Add it to the vCPU VMState as a subsection (sent when non-zero) so it travels with the vCPU across migration between host kernel versions. Signed-off-by: Tao Cui --- target/loongarch/machine.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/target/loongarch/machine.c b/target/loongarch/machine.c index 931a5ca5ba..b8819bd44d 100644 --- a/target/loongarch/machine.c +++ b/target/loongarch/machine.c @@ -65,6 +65,24 @@ static const VMStateDescription vmstate_msgint =3D { }, }; =20 +static bool pv_features_needed(void *opaque) +{ + LoongArchCPU *cpu =3D opaque; + + return cpu->env.pv_features !=3D 0; +} + +static const VMStateDescription vmstate_pv_features =3D { + .name =3D "cpu/pv_features", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D pv_features_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32(env.pv_features, LoongArchCPU), + VMSTATE_END_OF_LIST() + }, +}; + static const VMStateDescription vmstate_lsxh_reg =3D { .name =3D "lsxh_reg", .version_id =3D 1, @@ -289,6 +307,7 @@ const VMStateDescription vmstate_loongarch_cpu =3D { &vmstate_lbt, &vmstate_msgint, &vmstate_pmu, + &vmstate_pv_features, NULL } }; --=20 2.43.0 From nobody Sun Jul 12 00:33:16 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=1783644684; cv=none; d=zohomail.com; s=zohoarc; b=HlYek79j0BgObTFYHVyH8cC4mbq7IO7/H4znupwBZPxjEKA2CwLufczfuIYQG4zCy6i/fp/qx+XqQNaXBXxsgvBbF0T1Lf80A2IycsNmSO90eA8SBUnUjmsHLxmDzebER5+ajvJUWPEyCavNRoZUbsx9EjB05tbF78HRtZqzTjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783644684; 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=17veAsOjpBHNJ3+WJW+uxRGp+1ftuI3Nv8suHg2yNBs=; b=b9vqBb9aoL/I0AETymASZ0Ddbx9MC2jXbETP73nm8k3IVD9G1QkqSuGKU8pq27/dSISRv1PBSXzJOtOjpQjcpGGi1e4TcWrZi1cwL/Sui/zLwJbww/2FfL4h0SDQHGn86D/YE+t2b+JiVWlRlXcPgSlS/c2s13oMmAmApKuWrGg= 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 1783644683832452.2616960438678; Thu, 9 Jul 2026 17:51:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whzSB-0000Ag-Hp; Thu, 09 Jul 2026 20:50:55 -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 1whzS9-0000A3-TB for qemu-devel@nongnu.org; Thu, 09 Jul 2026 20:50:53 -0400 Received: from out-186.mta0.migadu.com ([2001:41d0:1004:224b::ba]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whzS8-0005e8-2d for qemu-devel@nongnu.org; Thu, 09 Jul 2026 20:50: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=1783644650; 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=17veAsOjpBHNJ3+WJW+uxRGp+1ftuI3Nv8suHg2yNBs=; b=FLKMagPVQ/2l3oZFqjLA2oJ5ETi458E1NC8KIfIwm0d70tXBdMwWTzBG+IP/nwiiB6rYIV +qgUAF3LmCSvZlV5Lc45nx+SqMQoD17Vn0/cGD+sQ0Vm04v9jLYGVfCHuoeuN5ydJyl8mx z4qFjtKeTkg2v1Fg++z5ZcqAupMN6hI= From: Tao Cui To: qemu-devel@nongnu.org Cc: Song Gao , Bibo Mao , Jiaxun Yang , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Tao Cui Subject: [PATCH v2 3/3] target/loongarch: add no_pv_feature compat flag Date: Fri, 10 Jul 2026 08:50:29 +0800 Message-ID: <20260710005029.345378-4-cui.tao@linux.dev> In-Reply-To: <20260710005029.345378-1-cui.tao@linux.dev> References: <20260710005029.345378-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=2001:41d0:1004:224b::ba; envelope-from=cui.tao@linux.dev; helo=out-186.mta0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: 1783644689516158500 Content-Type: text/plain; charset="utf-8" From: Tao Cui Advertising pv features to the guest affects the migration stream. Add a no_pv_feature compat flag so the behavior can be gated per machine version: LoongArchCPU gets a bool field, and the virt machine gains a LoongArchVirtMachineClass field that defaults the CPU flag per version. kvm_cpu_check_pv_features() skips populating pv features when the flag is set. The 11.1 machine type keeps pv advertisement off (no_pv_feature is true, preserving the previous behavior); from the new 11.2 machine type it is on by default. Signed-off-by: Tao Cui --- hw/loongarch/virt.c | 14 +++++++++++++- include/hw/loongarch/virt.h | 9 ++++++++- target/loongarch/cpu.h | 1 + target/loongarch/kvm/kvm.c | 5 +++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index 6693dea647..53c84c8def 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -955,6 +955,8 @@ static void virt_init(MachineState *machine) machine->cpu_type); exit(EXIT_FAILURE); } + LOONGARCH_CPU(cpuobj)->no_pv_feature =3D + LOONGARCH_VIRT_MACHINE_GET_CLASS(lvms)->no_pv_feature; qdev_realize_and_unref(DEVICE(cpuobj), NULL, &error_fatal); } virt_check_dmsi(machine); @@ -1584,6 +1586,7 @@ static const TypeInfo virt_machine_info =3D { .parent =3D TYPE_MACHINE, .abstract =3D true, .instance_size =3D sizeof(LoongArchVirtMachineState), + .class_size =3D sizeof(LoongArchVirtMachineClass), .class_init =3D virt_class_init, .instance_init =3D virt_initfn, .instance_finalize =3D virt_instance_finalize, @@ -1601,6 +1604,15 @@ static void machvirt_machine_init(void) type_init(machvirt_machine_init); =20 static void virt_machine_11_1_options(MachineClass *mc) +{ + LoongArchVirtMachineClass *vmc =3D LOONGARCH_VIRT_MACHINE_CLASS(mc); + + /* pv feature advertisement is enabled from 11.2; keep 11.1 unchanged = */ + vmc->no_pv_feature =3D true; +} +DEFINE_VIRT_MACHINE(11, 1) + +static void virt_machine_11_2_options(MachineClass *mc) { } -DEFINE_VIRT_MACHINE_AS_LATEST(11, 1) +DEFINE_VIRT_MACHINE_AS_LATEST(11, 2) diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h index d39a9bbf5d..cf8d9e1fd2 100644 --- a/include/hw/loongarch/virt.h +++ b/include/hw/loongarch/virt.h @@ -130,8 +130,15 @@ struct LoongArchVirtMachineState { bool highmem_mmio; }; =20 +struct LoongArchVirtMachineClass { + MachineClass parent_obj; + + bool no_pv_feature; /* compat: 11.1 and older do not advertise pv fe= atures */ +}; + #define TYPE_LOONGARCH_VIRT_MACHINE MACHINE_TYPE_NAME("virt") -OBJECT_DECLARE_SIMPLE_TYPE(LoongArchVirtMachineState, LOONGARCH_VIRT_MACHI= NE) +OBJECT_DECLARE_TYPE(LoongArchVirtMachineState, LoongArchVirtMachineClass, + LOONGARCH_VIRT_MACHINE) void virt_acpi_setup(LoongArchVirtMachineState *lvms); void virt_fdt_setup(LoongArchVirtMachineState *lvms); =20 diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h index ad30c73167..11bbb5f36e 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -447,6 +447,7 @@ struct ArchCPU { OnOffAuto msgint; OnOffAuto kvm_pv_ipi; OnOffAuto kvm_steal_time; + bool no_pv_feature; /* compat: do not advertise KVM pv features */ 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 c557ee3c3d..878914928b 100644 --- a/target/loongarch/kvm/kvm.c +++ b/target/loongarch/kvm/kvm.c @@ -1119,6 +1119,11 @@ static int kvm_cpu_check_pv_features(CPUState *cs, E= rror **errp) CPULoongArchState *env =3D cpu_env(cs); bool kvm_supported; =20 + /* compat: older machine types do not advertise pv features to the gue= st */ + if (cpu->no_pv_feature) { + return 0; + } + kvm_supported =3D kvm_feature_supported(cs, LOONGARCH_FEATURE_PV_IPI); if (cpu->kvm_pv_ipi =3D=3D ON_OFF_AUTO_ON) { if (!kvm_supported) { --=20 2.43.0