From nobody Sun Jul 26 11:54:36 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=1782451723; cv=none; d=zohomail.com; s=zohoarc; b=KZKqIaUDliXUz/FAaasdiKCbrkkjePfc2SeKLhUu6wCSWmPWRo36jvsrY2RZvJgEB6RO9s3aB0MIWQpogUy6pKkC3xx3nSrjIX0hpAH0PjhYJsOryRFz/W00UCrwWLUPHkCE6V6POUi8oIBEgzY2DXs03gpd9vkqqQ0/12IWx5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782451723; 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=olZcp+sfhOZfnkeyC8n/H+bCw+HZ7klG+g1jcmaTShQ=; b=T8R/W6rOwlvrjCdJxFKgut5azwpE+vhtxiuKH/wTpllY4S3JJS2vvt/koGEh7b4KQfxY/cq6wmttVfeCryTT2RXPy7QQTLEGEeOHLwfxGalCclB5nbhmAaDu/xmXlvjoKxH0qGcUBYjUOPC0lMe0Nl0rx7/CL8yViv0TinhlEv4= 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 1782451723008264.52041669971493; Thu, 25 Jun 2026 22:28:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcz6i-0004e9-Tl; Fri, 26 Jun 2026 01:28:04 -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 1wcz6h-0004dv-6f for qemu-devel@nongnu.org; Fri, 26 Jun 2026 01:28:03 -0400 Received: from out-189.mta0.migadu.com ([2001:41d0:1004:224b::bd]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcz6f-0005rD-1q for qemu-devel@nongnu.org; Fri, 26 Jun 2026 01:28:02 -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=1782451677; 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=olZcp+sfhOZfnkeyC8n/H+bCw+HZ7klG+g1jcmaTShQ=; b=BtjZ0/xuuYFbKjxfT6lf3+ZdfMVL2OwC188jOTGbolDEKzWbR4rL50muwZPojQID4MRC8/ 1xX60crsXyn1DaNEGf2OXWZ4nlMjavXYREnJwJe+lz1G+5hgsPGhS0YqQ0uY3dbctK+EX+ 3m8wfzPWQPRshZhexQWdpGy5dbPNwv8= From: Tao Cui To: qemu-devel@nongnu.org Cc: Song Gao , Bibo Mao , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Qiang Ma , Tao Cui Subject: [PATCH v2 1/4] target/loongarch/kvm: fix uninitialized val and unchecked GET in cpucfg2 check Date: Fri, 26 Jun 2026 13:27:39 +0800 Message-ID: <20260626052742.810726-2-cui.tao@linux.dev> In-Reply-To: <20260626052742.810726-1-cui.tao@linux.dev> References: <20260626052742.810726-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::bd; envelope-from=cui.tao@linux.dev; helo=out-189.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: 1782451727312158500 Content-Type: text/plain; charset="utf-8" From: Tao Cui kvm_check_cpucfg2() discards the return value of KVM_GET_DEVICE_ATTR and uses the local val (the host cpucfg2 mask) without checking whether the read succeeded. val is also declared without an initializer, so on a GET failure env->cpucfg[2] &=3D val reads an uninitialized value. The &=3D mask is best-effort feature negotiation: if KVM_HAS_DEVICE_ATTR succeeds, a GET failure is most likely a copy_{from,to}_user issue, not a reason to fail the whole register sync. Check the GET return value, warn and skip the mask on failure (the guest keeps the cpucfg2 it already has), and initialize val to 0. Signed-off-by: Tao Cui Reviewed-by: Bibo Mao --- target/loongarch/kvm/kvm.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c index d6539c12ac..5bd5e268b9 100644 --- a/target/loongarch/kvm/kvm.c +++ b/target/loongarch/kvm/kvm.c @@ -725,7 +725,7 @@ static int kvm_loongarch_get_cpucfg(CPUState *cs) static int kvm_check_cpucfg2(CPUState *cs) { int ret; - uint64_t val; + uint64_t val =3D 0; struct kvm_device_attr attr =3D { .group =3D KVM_LOONGARCH_VCPU_CPUCFG, .attr =3D 2, @@ -736,8 +736,17 @@ static int kvm_check_cpucfg2(CPUState *cs) ret =3D kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, &attr); =20 if (!ret) { - kvm_vcpu_ioctl(cs, KVM_GET_DEVICE_ATTR, &attr); - env->cpucfg[2] &=3D val; + /* + * The &=3D mask is best-effort feature negotiation. If HAS succee= ded, + * a GET failure is most likely a copy_{from,to}_user issue; warn = and + * keep the cpucfg2 the guest already has rather than failing the = sync. + */ + int r =3D kvm_vcpu_ioctl(cs, KVM_GET_DEVICE_ATTR, &attr); + if (r) { + warn_report("CPUCFG2: KVM_GET_DEVICE_ATTR: %s", strerror(errno= )); + } else { + env->cpucfg[2] &=3D val; + } =20 if (FIELD_EX32(env->cpucfg[2], CPUCFG2, FP)) { /* The FP minimal version is 1. */ --=20 2.43.0 From nobody Sun Jul 26 11:54:36 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=1782451723; cv=none; d=zohomail.com; s=zohoarc; b=fMF6vUmKy+RdHil4QXYRRCvm/jYQcPctTR7J0mX53UW99bgwan07E0LiHHNDigFeniCLrGclqDaVrZo3UtouZjVISlH5u3BXuWqM0QFD53eVozcZp21jxpQPIBciYlBs907qvAxQQ0G+XNmPaEnW1ouJjwCfqOx1Ukc5F2WQjAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782451723; 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=9BoiSycFuCoOKAkQfGbs2PFQAnjPqz4ydnB0FhHeozw=; b=GAFV81BZZRBkdj2dHoRL+VRrCDG30AxIiZ+64snyomrCEEoKPp44Cgl8Xmg4w1tlociV+iapWfjZfaNAzHrcsglRLJsgXBFDW+tlL93xQKLFzUicDaY/uohAEvEFhQoUL8wFFmvkmzRPwwIDtrNnOWfHasLrnGEhOHEZbLoUhYQ= 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 1782451722972426.1979049318021; Thu, 25 Jun 2026 22:28:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcz6j-0004eT-M6; Fri, 26 Jun 2026 01:28:05 -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 1wcz6i-0004e5-Hy for qemu-devel@nongnu.org; Fri, 26 Jun 2026 01:28:04 -0400 Received: from out-179.mta0.migadu.com ([2001:41d0:1004:224b::b3]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcz6g-0005rk-St for qemu-devel@nongnu.org; Fri, 26 Jun 2026 01:28:04 -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=1782451680; 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=9BoiSycFuCoOKAkQfGbs2PFQAnjPqz4ydnB0FhHeozw=; b=mHZPz3JY4nX+6TgQJ6bok4vM++lHU9pkEo6jqQwnrs+kCXB+gRSTVDftDgbHo3KCk0GR6o XfQivc6A4Xue4TjwtOQsvy5ni68H6te8EJO10+LMt4F81vOBqmj0et+QbIehXQJJXE9BUk kuHCdszNz2Ry/6D7BIkke28kV2ZoBjM= From: Tao Cui To: qemu-devel@nongnu.org Cc: Song Gao , Bibo Mao , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Qiang Ma , Tao Cui Subject: [PATCH v2 2/4] target/loongarch/kvm: pass device attr by reference to kvm_vcpu_ioctl Date: Fri, 26 Jun 2026 13:27:40 +0800 Message-ID: <20260626052742.810726-3-cui.tao@linux.dev> In-Reply-To: <20260626052742.810726-1-cui.tao@linux.dev> References: <20260626052742.810726-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::b3; envelope-from=cui.tao@linux.dev; helo=out-179.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: 1782451727484158500 Content-Type: text/plain; charset="utf-8" From: Tao Cui kvm_vcpu_ioctl() is variadic and reads its argument as a pointer, but kvm_get_stealtime(), kvm_set_stealtime() and kvm_set_pv_features() pass the local struct kvm_device_attr by value. It currently works because of how the calling convention passes large structs; pass &attr so the argument is passed as intended. Reviewed-by: Bibo Mao Signed-off-by: Tao Cui --- target/loongarch/kvm/kvm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c index 5bd5e268b9..4bb5be6864 100644 --- a/target/loongarch/kvm/kvm.c +++ b/target/loongarch/kvm/kvm.c @@ -46,12 +46,12 @@ static int kvm_get_stealtime(CPUState *cs) .addr =3D (uint64_t)&env->stealtime.guest_addr, }; =20 - err =3D kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr); + err =3D kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, &attr); if (err) { return 0; } =20 - err =3D kvm_vcpu_ioctl(cs, KVM_GET_DEVICE_ATTR, attr); + err =3D kvm_vcpu_ioctl(cs, KVM_GET_DEVICE_ATTR, &attr); if (err) { error_report("PVTIME: KVM_GET_DEVICE_ATTR: %s", strerror(errno)); return err; @@ -70,12 +70,12 @@ static int kvm_set_stealtime(CPUState *cs) .addr =3D (uint64_t)&env->stealtime.guest_addr, }; =20 - err =3D kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr); + err =3D kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, &attr); if (err) { return 0; } =20 - err =3D kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, attr); + err =3D kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, &attr); if (err) { error_report("PVTIME: KVM_SET_DEVICE_ATTR %s with gpa "TARGET_FMT_= lx, strerror(errno), env->stealtime.guest_addr); @@ -96,13 +96,13 @@ static int kvm_set_pv_features(CPUState *cs) .addr =3D (uint64_t)&val, }; =20 - err =3D kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr); + err =3D kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, &attr); if (err) { return 0; } =20 val =3D env->pv_features; - err =3D kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, attr); + err =3D kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, &attr); if (err) { error_report("Fail to set pv feature "TARGET_FMT_lx " with error %= s", val, strerror(errno)); --=20 2.43.0 From nobody Sun Jul 26 11:54:36 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=1782451732; cv=none; d=zohomail.com; s=zohoarc; b=IL8TDn0ZFQ0s5gv77q0tFgJCyJn1R9kZSwZ4rIpwsJN7lOIlF3D8+0wyHA+8FEfZd+4SdUAqtyk5OXzkuD+ZKrsLh+Yxs8OtfbBetGQ+TorDzrp0W6dtnOQHtIcfD0d3kz8Y6FutRV1yYm9u5soOu487Jp8DsNUXT5DUxA6OHYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782451732; 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=TxTZUdCW6q4WC90uZ3+/hnAWbIGD9ch+ubW2pdJ3x0c=; b=dqR4nfKIlm4fdExWQihgeVFBldTA3xdS+dEtZ5WTC03wYBVzKTxSiEHI5VdR991D/v5oDwa9n5AtgY8eO/f/pXCZXkeMNt6rQqzLweCfAcEM8dT9weEeXiNzglnp6MbOuGI+9BIJmrir9Pgyzd3fNN5R1FQPUlzZ/EwhQrs7L6o= 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 1782451732043906.26486507711; Thu, 25 Jun 2026 22:28:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcz6m-0004ex-IA; Fri, 26 Jun 2026 01:28:08 -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 1wcz6l-0004ep-6X for qemu-devel@nongnu.org; Fri, 26 Jun 2026 01:28:07 -0400 Received: from out-179.mta0.migadu.com ([2001:41d0:1004:224b::b3]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcz6j-0005ub-Oi for qemu-devel@nongnu.org; Fri, 26 Jun 2026 01:28:06 -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=1782451684; 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=TxTZUdCW6q4WC90uZ3+/hnAWbIGD9ch+ubW2pdJ3x0c=; b=Fe6RATKTV8hyGoveRiyE8al9eBuYGKG0V1GLu6P0ftyKEO7cLM3TdmEEv/aHYwGNIvF9la /Tx1MdMn7tiyADe9xhrXIFFsfsN/Nm4PqSHOId+2CJ2vGU+N+yOOwqGaMZjG15AQnTlWH4 sxN9W94XL1u3jFhuFqieFW/xdExP4ns= From: Tao Cui To: qemu-devel@nongnu.org Cc: Song Gao , Bibo Mao , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Qiang Ma , Tao Cui Subject: [PATCH v2 3/4] target/loongarch/kvm: remove redundant cpucfg failure traces Date: Fri, 26 Jun 2026 13:27:41 +0800 Message-ID: <20260626052742.810726-4-cui.tao@linux.dev> In-Reply-To: <20260626052742.810726-1-cui.tao@linux.dev> References: <20260626052742.810726-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::b3; envelope-from=cui.tao@linux.dev; helo=out-179.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: 1782451736195158500 Content-Type: text/plain; charset="utf-8" From: Tao Cui kvm_get_one_reg() and kvm_set_one_reg() already trace on failure, so the trace_kvm_failed_get_cpucfg()/trace_kvm_failed_put_cpucfg() calls in kvm_loongarch_get_cpucfg() and kvm_loongarch_put_cpucfg() duplicate that. Remove the calls and the now-unused trace events. Signed-off-by: Tao Cui Reviewed-by: Bibo Mao --- target/loongarch/kvm/kvm.c | 6 ------ target/loongarch/trace-events | 2 -- 2 files changed, 8 deletions(-) diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c index 4bb5be6864..a504cfaaf7 100644 --- a/target/loongarch/kvm/kvm.c +++ b/target/loongarch/kvm/kvm.c @@ -714,9 +714,6 @@ static int kvm_loongarch_get_cpucfg(CPUState *cs) =20 for (i =3D 0; i < 21; i++) { ret =3D kvm_get_one_reg(cs, KVM_IOC_CPUCFG(i), &val); - if (ret < 0) { - trace_kvm_failed_get_cpucfg(strerror(errno)); - } env->cpucfg[i] =3D (uint32_t)val; } return ret; @@ -777,9 +774,6 @@ static int kvm_loongarch_put_cpucfg(CPUState *cs) } val =3D env->cpucfg[i]; ret =3D kvm_set_one_reg(cs, KVM_IOC_CPUCFG(i), &val); - if (ret < 0) { - trace_kvm_failed_put_cpucfg(strerror(errno)); - } } return ret; } diff --git a/target/loongarch/trace-events b/target/loongarch/trace-events index dea11edc0f..829d8e0f53 100644 --- a/target/loongarch/trace-events +++ b/target/loongarch/trace-events @@ -9,7 +9,5 @@ kvm_failed_get_mpstate(const char *msg) "Failed to get mp_s= tate from KVM: %s" kvm_failed_put_mpstate(const char *msg) "Failed to put mp_state into KVM: = %s" kvm_failed_get_counter(const char *msg) "Failed to get counter from KVM: %= s" kvm_failed_put_counter(const char *msg) "Failed to put counter into KVM: %= s" -kvm_failed_get_cpucfg(const char *msg) "Failed to get cpucfg from KVM: %s" -kvm_failed_put_cpucfg(const char *msg) "Failed to put cpucfg into KVM: %s" kvm_arch_handle_exit(int num) "kvm arch handle exit, the reason number: %d" kvm_set_intr(int irq, int level) "kvm set interrupt, irq num: %d, level: %= d" --=20 2.43.0 From nobody Sun Jul 26 11:54:36 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=1782451709; cv=none; d=zohomail.com; s=zohoarc; b=dGkNnOa0uW+T5Qe1fkH88B+4Aqv93BmgKW7pne2wKlDu2+sDZzgJHBCKmFbqcF/ri48UjPkWoXl7wCcKA1gHpWbdcQVwJGQYccw2ETP4Ht87fzvmZlZGUzCFG79xrV+Uye5IUDg81xZnCtdHf0w5PnBqyce3voSdHu0Otyljrts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782451709; 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=Nr2zSsNGrXzFQ1+5UlolMhYIxbSmmhdZyOj5h2llqCQ=; b=L13xCM3Ty7AgsjPvfRJx0K6vv6l0ZENRe1rjd52cVLP6RB4rmekNHH3gZzfZJmZtCz9rNP8O5dIz25splOwirFLWx1MHBV1S/ynueadKdDn4cDykOPmktyhM+IJkkpxCFFeiYF3PWOYmDpkWsjAQP2T+HHlJ19o1WK5+5JEVrvg= 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 1782451709481911.1092767087666; Thu, 25 Jun 2026 22:28:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcz6r-0004fb-UH; Fri, 26 Jun 2026 01:28:13 -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 1wcz6p-0004fS-W7 for qemu-devel@nongnu.org; Fri, 26 Jun 2026 01:28:12 -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 1wcz6o-0005vt-7z for qemu-devel@nongnu.org; Fri, 26 Jun 2026 01:28:11 -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=1782451688; 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=Nr2zSsNGrXzFQ1+5UlolMhYIxbSmmhdZyOj5h2llqCQ=; b=PTHQ4GOIT91Vlgte7sHs30nm3M3j04maj5b3w73e0D75qjj2gDExq4gji6XlMFUEp8ZrJU juoY8C+wI7NyWKSraY5++gGZ4IimxiyQE2esmqzBF3s8SAYqP8w8noesua6cDxSJqtbx78 IsLQXoLLrA6AUL4AEx7ah1Xptdy9EWY= From: Tao Cui To: qemu-devel@nongnu.org Cc: Song Gao , Bibo Mao , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Qiang Ma , Tao Cui Subject: [PATCH v2 4/4] target/loongarch/kvm: fix cpucfg sync error handling Date: Fri, 26 Jun 2026 13:27:42 +0800 Message-ID: <20260626052742.810726-5-cui.tao@linux.dev> In-Reply-To: <20260626052742.810726-1-cui.tao@linux.dev> References: <20260626052742.810726-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-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: 1782451712493158500 Content-Type: text/plain; charset="utf-8" From: Tao Cui In kvm_loongarch_get_cpucfg() and kvm_loongarch_put_cpucfg(), ret is overwritten on each iteration, so only the last register's result is returned and earlier failures are lost. On a failed read, env->cpucfg[i] is stored from a stale or uninitialized val. Accumulate errors with ret |=3D, matching kvm_loongarch_get_csr()/put_csr(), and only update env->cpucfg[i] on a successful read. Keep the cpucfg2 negotiation check in put_cpucfg() on a separate variable so its early return does not overwrite the accumulated result. Signed-off-by: Tao Cui Reviewed-by: Bibo Mao --- target/loongarch/kvm/kvm.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c index a504cfaaf7..9f1ee41ef6 100644 --- a/target/loongarch/kvm/kvm.c +++ b/target/loongarch/kvm/kvm.c @@ -713,8 +713,11 @@ static int kvm_loongarch_get_cpucfg(CPUState *cs) CPULoongArchState *env =3D cpu_env(cs); =20 for (i =3D 0; i < 21; i++) { - ret =3D kvm_get_one_reg(cs, KVM_IOC_CPUCFG(i), &val); - env->cpucfg[i] =3D (uint32_t)val; + int r =3D kvm_get_one_reg(cs, KVM_IOC_CPUCFG(i), &val); + ret |=3D r; + if (!r) { + env->cpucfg[i] =3D (uint32_t)val; + } } return ret; } @@ -767,13 +770,13 @@ static int kvm_loongarch_put_cpucfg(CPUState *cs) =20 for (i =3D 0; i < 21; i++) { if (i =3D=3D 2) { - ret =3D kvm_check_cpucfg2(cs); - if (ret) { - return ret; + int r =3D kvm_check_cpucfg2(cs); + if (r) { + return r; } } val =3D env->cpucfg[i]; - ret =3D kvm_set_one_reg(cs, KVM_IOC_CPUCFG(i), &val); + ret |=3D kvm_set_one_reg(cs, KVM_IOC_CPUCFG(i), &val); } return ret; } --=20 2.43.0