From nobody Sun Jul 26 11:54:38 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=1782352789; cv=none; d=zohomail.com; s=zohoarc; b=bD7H8e6jyBI0UlJwl2J/w2Ocmyis+M5vQeqPKYNg8L4m5demhbdvJHik1MxeDrG6Co7TyQs9OnlQha6cLt3/dFJdLMpj0ISQv4dLnosMIO4/4kAjuqM9QX0riPOhrEyFxRcuVISLHbkxkPbFZFG9NXDHQ4ld4ykCDpckRClCcQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782352789; 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=dk7oadZcgF+1XSO7Jj977XnWSnpVjH6Bjtz61AXKqIE=; b=iAfeuMxyYcTQ78pJbQsDoR49fvE5Zg30p4OZ2vvBeoKhfqvR9LjyDPuXd7HQi91MtfRZOhqzEDR1TaXRiwLtAPmz4QIfVhHLSTSa7sBnzfap3uQ+Hl4QvXJqFCgLpw9YjiS1lSo2SndZRJWNW+CEJ2HLDS3jdqVKcn1ftttvJjg= 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 1782352789402377.52978382135984; Wed, 24 Jun 2026 18:59:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcZND-0004sJ-Pl; Wed, 24 Jun 2026 21:59:23 -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 1wcZNC-0004sA-3m for qemu-devel@nongnu.org; Wed, 24 Jun 2026 21:59:22 -0400 Received: from out-179.mta0.migadu.com ([91.218.175.179]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcZNA-0002P1-Kx for qemu-devel@nongnu.org; Wed, 24 Jun 2026 21:59:21 -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=1782352758; 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=dk7oadZcgF+1XSO7Jj977XnWSnpVjH6Bjtz61AXKqIE=; b=uPLLho1Sot7vVKnFDb509tiuiyfKraO7lgyWgy9aibKI+1nHakRK9wYxa4q/T+KYLw6sP8 17QxCMg44Xo5zSdUVM1ItPV/AHq9VZ2SsbPCLlKBIPgwuzh/n2Bwe7cONgONxZ1ohTfEXf ATTn68nohTS9Pqg8YMvyGgwTA31TUKw= 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 1/4] target/loongarch/kvm: fix uninitialized val and unchecked GET in cpucfg2 check Date: Thu, 25 Jun 2026 09:58:31 +0800 Message-ID: <20260625015835.678819-2-cui.tao@linux.dev> In-Reply-To: <20260625015835.678819-1-cui.tao@linux.dev> References: <20260625015835.678819-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.179; envelope-from=cui.tao@linux.dev; helo=out-179.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: 1782352793080158500 Content-Type: text/plain; charset="utf-8" From: Tao Cui kvm_check_cpucfg2() discards the return value of KVM_GET_DEVICE_ATTR and then uses the local val (the host cpucfg2 mask) without checking whether the read succeeded. val is also declared without an initializer. If GET fails, env->cpucfg[2] &=3D val uses an uninitialized value and can silently clear feature bits (FP / LLFTP / LSX / LASX), since bitwise-AND can only turn bits off. Check the GET return value, report the failure with error_report(), and initialize val to 0. Signed-off-by: Tao Cui --- target/loongarch/kvm/kvm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c index d6539c12ac..b7176ce53a 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,7 +736,11 @@ 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); + ret =3D kvm_vcpu_ioctl(cs, KVM_GET_DEVICE_ATTR, &attr); + if (ret) { + error_report("CPUCFG2: KVM_GET_DEVICE_ATTR: %s", strerror(errn= o)); + return ret; + } env->cpucfg[2] &=3D val; =20 if (FIELD_EX32(env->cpucfg[2], CPUCFG2, FP)) { --=20 2.43.0 From nobody Sun Jul 26 11:54:38 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=1782352795; cv=none; d=zohomail.com; s=zohoarc; b=MiIPnn6avEd9nixY9aiFCNzWG4N7Trc8watPVOv4gciDwreek9hjiKo863RLX9B2PbK7jKFIOq7m4qtXymn6AXUnDFQAbuuKk1mnpgAxp7s5l9VBBjcamhJayTm4FwgUMayOHjJ8Xg1a1jBpuYVtDZhmv/y3dsiVRfy1tfi6Lgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782352795; 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=4JvVPf1yBQBsCJPX90lCIhhbrNWsbCYEamF0PT4hQXM=; b=WpeYmQQSNMAq1da5OseEn/o4EvEglZPFziVk+B0z+mo9olEGk6nUGv3VB3Z59HHmzEdgF5QTzGrHPJb8EwCPUTQyOVh1j4viyha/BuaeExUuypqUGKud4uOuZE7m/TPV4CcgFKaJYMWb4ggjz0QeCo9f4Pq0Xk/QbUBmGeNknjQ= 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 1782352795256767.6213755767712; Wed, 24 Jun 2026 18:59:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcZNM-0004t5-Ea; Wed, 24 Jun 2026 21:59:32 -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 1wcZNK-0004su-R9 for qemu-devel@nongnu.org; Wed, 24 Jun 2026 21:59:30 -0400 Received: from out-184.mta0.migadu.com ([91.218.175.184]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcZNJ-0002Pg-BV for qemu-devel@nongnu.org; Wed, 24 Jun 2026 21:59:30 -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=1782352767; 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=4JvVPf1yBQBsCJPX90lCIhhbrNWsbCYEamF0PT4hQXM=; b=o6L+e+1DMjy9XRciuZZJRKaBqRFmh2A34U5hw6RFuV4eRAnA2levyhUyCQ+cBzAOtUjhEO 9p2zZT1yLdr/QkVtivDVVQA3/5kwVCPp9LE6zBma3yyd5PGCikkkrYUyhwNgYj+uApTqAO br8VhD1ZbBAXMJBXB79UctJMvbmwoaM= 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 2/4] target/loongarch/kvm: pass device attr by reference to kvm_vcpu_ioctl Date: Thu, 25 Jun 2026 09:58:32 +0800 Message-ID: <20260625015835.678819-3-cui.tao@linux.dev> In-Reply-To: <20260625015835.678819-1-cui.tao@linux.dev> References: <20260625015835.678819-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.184; envelope-from=cui.tao@linux.dev; helo=out-184.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: 1782352796772158500 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. Signed-off-by: Tao Cui Reviewed-by: Bibo Mao --- 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 b7176ce53a..fffb2d431a 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:38 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=1782352789; cv=none; d=zohomail.com; s=zohoarc; b=E9jFOxRAK0fbgiuRXaaBCoqvAx6qvRNxdoqmMDaL++CuZx4BYlf7LY+sEdyH5kHFLTVldW8WvKTa7tY39lnSMyFeDedAnouOqTZMNa6nidRPUbscMePfY9N1OMDDu9DAvw5FW5RpVqZptFjn8TS8wMfuYotrGyZzQIYiHCtqqac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782352789; 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=ZlskRYzf2HplYCB7Pwgr+QRAoLyxFrwTDSxOWjdGvgk=; b=CMKxocMFE74vWSScueRSM/kACEiViJTcVpFFLtwnhtdD0JPMVbQLasGuy4kehvNeVafJhVyF1QRZUezQfU93HvZj/b2+XoVTpnbZKX2rPkYX//eBZokOjIW39Nux1IcA3JApwJULoZP54t9jm844Ap8Za1enN+Jbd/msqw5TKIA= 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 1782352789269472.9071629975896; Wed, 24 Jun 2026 18:59:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcZNT-00056O-Os; Wed, 24 Jun 2026 21:59:39 -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 1wcZNS-0004y2-6K for qemu-devel@nongnu.org; Wed, 24 Jun 2026 21:59:38 -0400 Received: from out-173.mta0.migadu.com ([91.218.175.173]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcZNQ-0002Q4-Kx for qemu-devel@nongnu.org; Wed, 24 Jun 2026 21:59:37 -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=1782352772; 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=ZlskRYzf2HplYCB7Pwgr+QRAoLyxFrwTDSxOWjdGvgk=; b=XEsZxY/0I2DYocQpZN7usU/+O/jTVdKNWfSD3bjyUfFIiCeUSM2ZfB/nbtWE/9KkZKqWLe N2piDcfevstQDx9AvGKso8ijBZrnL5ngN21T8RPlZCFl7OkcounVKWCBHhKArCiSuWCbEP Yli1T+OYVFoS/oDXOGfAAQNRMRmFYBk= 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 3/4] target/loongarch/kvm: remove redundant cpucfg failure traces Date: Thu, 25 Jun 2026 09:58:33 +0800 Message-ID: <20260625015835.678819-4-cui.tao@linux.dev> In-Reply-To: <20260625015835.678819-1-cui.tao@linux.dev> References: <20260625015835.678819-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.173; envelope-from=cui.tao@linux.dev; helo=out-173.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: 1782352793081158500 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 --- 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 fffb2d431a..6c3eea87b0 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; @@ -772,9 +769,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:38 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=1782352810; cv=none; d=zohomail.com; s=zohoarc; b=F9cmUOICxdOuaZzmfe5D+7hr2RcAgUR2EHO5S3/CMxoW+oAON1kB4tHg2xIU4wYEh2Slw7PYNIvOCL5YvGFb6vDYq2rr7N8JiSJFJBpmhKvek4vagf2xrdpOogIDh2JBKimJrf2KKszxGc9z4ngXLrnNWx+D4zOhLJIJSfKPyq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782352810; 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=4nJlkRv21mHq5T6N1v8u6I+6uC06vcKDMbrKXIs0KEQ=; b=lF4HAGzhAYiGTpWfAMEuaBONtLpr/7MzpONU/x59ut7qg2zgvZrkr/I2JeNM5Oic4OjndSbGuaJivAM1vg2tviIzPQmpxybSeDaRPV/DtwHhFgj0oaVghHPG1yMYP/0b6g1PkgNXr66M09msDgX0Jwnd803FMB3FLGUco7ZnB98= 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 1782352809996503.1216386518349; Wed, 24 Jun 2026 19:00:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcZNX-0005QJ-7p; Wed, 24 Jun 2026 21:59:43 -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 1wcZNW-0005Mp-4r for qemu-devel@nongnu.org; Wed, 24 Jun 2026 21:59:42 -0400 Received: from out-172.mta0.migadu.com ([2001:41d0:1004:224b::ac]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcZNT-0002Qu-MQ for qemu-devel@nongnu.org; Wed, 24 Jun 2026 21:59:41 -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=1782352777; 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=4nJlkRv21mHq5T6N1v8u6I+6uC06vcKDMbrKXIs0KEQ=; b=ZI35xIkAFXr7enL4zOObd38qagzTKfQ8sOVTRHUdmh+YocOsj65KywNPc8AiUZ/sMjHsjh mhfcFdYc1p7Zb3YHVniyXl1nJDFKpfoNeGYiNKKbDqVCTZCP/jrA4ewMhtioYZVLUmXEDZ 3bDYvI6nC0Ix76wNCr5C6BSEDTfIQco= 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 4/4] target/loongarch/kvm: fix cpucfg sync error handling Date: Thu, 25 Jun 2026 09:58:34 +0800 Message-ID: <20260625015835.678819-5-cui.tao@linux.dev> In-Reply-To: <20260625015835.678819-1-cui.tao@linux.dev> References: <20260625015835.678819-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::ac; envelope-from=cui.tao@linux.dev; helo=out-172.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: 1782352812521158500 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 --- 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 6c3eea87b0..a60c99227f 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; } @@ -762,13 +765,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