From nobody Sat Nov 23 23:50:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730861451; cv=none; d=zohomail.com; s=zohoarc; b=KmHhtcX4fmPI8+9aJeOR7iMsvJJt723nV1Flhb3DLrOZTj4Od20ZIhv5QTBG/ADXI60zHKbdeZSNsDNqaxy7zm/VLVl61Ko+FAhFEhrQAlmXYURlXvUKa+EcQKGjt7xQzRz2H5hs11LcY3xdG8QFTXZODP49g2OVucMkpz8l4/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730861451; 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=M7wNSYWlDBsaJ0t4isfYyOQVNFrGiTM2YZzcRWYuKJ8=; b=LVl3gXi3/KBjGYhd75sbj2UUJ5g/8yT1MhXDcMDgkBduElMAxfc1rbMhFq3gi9TiAQ+cZQYjJIx5bzzKSjoVNYEZIM/SULqx3abCat7oSzQLLigHLrS2pWUccBdZR5nLBs4xpu/IHpv86y+hNbv5G4wM580WHQv0saifTGvWoo0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730861451704962.8149442642704; Tue, 5 Nov 2024 18:50:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8W7l-0007B7-TP; Tue, 05 Nov 2024 21:50:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8W7k-0007Ap-RQ for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:24 -0500 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8W7i-0003cN-BN for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:24 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2024 18:50:21 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa001.fm.intel.com with ESMTP; 05 Nov 2024 18:50:17 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861422; x=1762397422; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cDyoHsWzKph1fodDMEJqXgXb9rXZ334jDEhsYTPjqKQ=; b=AE9fowAwJ7HZZLLPR0T/w4DMePJzsvHIP9A0M0pk27UX95jvmSJ/xKxt BFn+ZcfoH0b7AwbkGEJ7YB9BcC0Mf2jtD5cSKSgPn4zfLfQEPlrImgZQJ xQJSXTwqRcKpsKW41XvzItCnY+gixb63jA93SZPiltWuhbv7RyU6wz4+T VG8c/T5oh1oJWIqrLjYHpHeYjzmuIWXe2rrWXyhHalI3iObWwBGwOyhxc Sn0LFVg/S5jjZSxCM3z0wCzTvvRXiYm/wQKvavcN9WbNvqiqPivCpg2ig oS+eSQ5CnJbycMAwHKxeC8HyCDpXJJTS7rFclc3dXPdyOEyo1xbs64RBq w==; X-CSE-ConnectionGUID: JA/98ZacSPKlO7RvjIIW+A== X-CSE-MsgGUID: lmAPGaOKSr2SlFCF0FEwuA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492322" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492322" X-CSE-ConnectionGUID: BgQ7aLUUSJ+cgTv2Y4xQFA== X-CSE-MsgGUID: OQfoaMsiS52eotCldTU9ww== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,261,1725346800"; d="scan'208";a="115078033" From: Zhao Liu To: Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S . Tsirkin" , Marcel Apfelbaum , Marcelo Tosatti , Tao Su Cc: Xiaoyao Li , Pankaj Gupta , Zide Chen , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu Subject: [PATCH v5 10/11] target/i386/kvm: Clean up error handling in kvm_arch_init() Date: Wed, 6 Nov 2024 11:07:27 +0800 Message-Id: <20241106030728.553238-11-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106030728.553238-1-zhao1.liu@intel.com> References: <20241106030728.553238-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -46 X-Spam_score: -4.7 X-Spam_bar: ---- X-Spam_report: (-4.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 @intel.com) X-ZM-MESSAGEID: 1730861453038116600 Content-Type: text/plain; charset="utf-8" Currently, there're following incorrect error handling cases in kvm_arch_init(): * Missed to handle failure of kvm_get_supported_feature_msrs(). * Missed to return when kvm_vm_enable_disable_exits() fails. * MSR filter related cases called exit() directly instead of returning to kvm_init(). (The caller of kvm_arch_init() - kvm_init() - needs to know if kvm_arch_init() fails in order to perform cleanup). Fix the above cases. Signed-off-by: Zhao Liu Reviewed-by: Zide Chen --- v5: cleaned up kvm_vm_enable_energy_msrs(). v3: new commit. --- target/i386/kvm/kvm.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 69825b53b6da..013c0359acbe 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3147,7 +3147,7 @@ static int kvm_vm_enable_userspace_msr(KVMState *s) return 0; } =20 -static void kvm_vm_enable_energy_msrs(KVMState *s) +static int kvm_vm_enable_energy_msrs(KVMState *s) { int ret; =20 @@ -3157,7 +3157,7 @@ static void kvm_vm_enable_energy_msrs(KVMState *s) if (ret < 0) { error_report("Could not install MSR_RAPL_POWER_UNIT handler: %= s", strerror(-ret)); - exit(1); + return ret; } =20 ret =3D kvm_filter_msr(s, MSR_PKG_POWER_LIMIT, @@ -3165,7 +3165,7 @@ static void kvm_vm_enable_energy_msrs(KVMState *s) if (ret < 0) { error_report("Could not install MSR_PKG_POWER_LIMIT handler: %= s", strerror(-ret)); - exit(1); + return ret; } =20 ret =3D kvm_filter_msr(s, MSR_PKG_POWER_INFO, @@ -3173,17 +3173,17 @@ static void kvm_vm_enable_energy_msrs(KVMState *s) if (ret < 0) { error_report("Could not install MSR_PKG_POWER_INFO handler: %s= ", strerror(-ret)); - exit(1); + return ret; } ret =3D kvm_filter_msr(s, MSR_PKG_ENERGY_STATUS, kvm_rdmsr_pkg_energy_status, NULL); if (ret < 0) { error_report("Could not install MSR_PKG_ENERGY_STATUS handler:= %s", strerror(-ret)); - exit(1); + return ret; } } - return; + return 0; } =20 int kvm_arch_init(MachineState *ms, KVMState *s) @@ -3250,7 +3250,10 @@ int kvm_arch_init(MachineState *ms, KVMState *s) return ret; } =20 - kvm_get_supported_feature_msrs(s); + ret =3D kvm_get_supported_feature_msrs(s); + if (ret < 0) { + return ret; + } =20 uname(&utsname); lm_capable_kernel =3D strcmp(utsname.machine, "x86_64") =3D=3D 0; @@ -3286,6 +3289,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) if (ret < 0) { error_report("kvm: guest stopping CPU not supported: %s", strerror(-ret)); + return ret; } } =20 @@ -3317,12 +3321,15 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } =20 if (s->msr_energy.enable =3D=3D true) { - kvm_vm_enable_energy_msrs(s); + ret =3D kvm_vm_enable_energy_msrs(s); + if (ret < 0) { + return ret; + } =20 ret =3D kvm_msr_energy_thread_init(s, ms); if (ret < 0) { error_report("kvm : error RAPL feature requirement not met= "); - exit(1); + return ret; } } } --=20 2.34.1