From nobody Sat Nov 23 21:51:17 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=1730861491; cv=none; d=zohomail.com; s=zohoarc; b=h9yo6ek0tn7lTLyGU2PdKY/DUZT87w5jHSX26sNMb3Q9zQ2FR63ozqIRZe0RH0aHWlavze+h5cAXygYeyGoArWH3MHLlI5hX9+Vasrnw3B1F5jxkF06USCRrJ9PtgO8XYHcev3I035yEeGVyraFxgeVp3mAt5TEePzeh9gcQxbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730861491; 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=7+Pk3dAONsCdyGqk1RKD8QBhcHdx508E7nD9kp/1DQg=; b=bBT68TTJdTQDlcUlWG/6x0LJH6LMcPQKbdqD1nBix9q/9zN6ZRHv2FDBs5SBDv2jmyilP7nMcg7q9wZu6wk+17vaRB4aCeqGaJW8fp6ItXO6XarIyTEUssxUqGEF0qNJHLbkZ6b/wyAo7AucyEJ7XW9nFTKl/+YCfFaYMF3AAlI= 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 1730861491886449.2406441143818; Tue, 5 Nov 2024 18:51:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8W7L-0006w5-Vo; Tue, 05 Nov 2024 21:50:00 -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-0006vY-6q; Tue, 05 Nov 2024 21:49:58 -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-0003Mc-GX; Tue, 05 Nov 2024 21:49:57 -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:49:52 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa001.fm.intel.com with ESMTP; 05 Nov 2024 18:49:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861397; x=1762397397; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H7lerJmEuC7yP69gP6zV6WKJa2+lLUCqxp5WR8/LiAI=; b=V+9ST+T7Nel+B401LjcRsm127RuulMLJz+8CQl7MNby213cxpHyau21f 63PqadAI8r7sK9DM3BJcMfzpMLveTHoZIZR0k56aZXrRn1jVZJOypuLQo QJZwd7GH8Wp5glzNLii8GzHaUwIkWX1hxFE5OFFm137Ov2fzI7UH59DMA wBf13Sj8P0pJebyXa1DidPjE+d3xVqi0kzq62Kq0Qqggl0U+nUD0LJBth ztuOBZtfIQfWEVM4rzYiwtMiSmdHrpOGn0qq1Ioh0sN0SEVsDwApFVV1n 9WXaoq5eMulE5EP6FtnISTn4YD05jWA3X/1Xtug152aYJ1G44sRMgrsjT Q==; X-CSE-ConnectionGUID: H7SApJszSECp6q5E8UAlLA== X-CSE-MsgGUID: oAe0TYx3SoqCD7+TRt15hg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492202" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492202" X-CSE-ConnectionGUID: rnzAlqV1T02GOnI+LsiAtQ== X-CSE-MsgGUID: PiFYv1UARaawoXhgwXvjtg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,261,1725346800"; d="scan'208";a="115077975" 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 , qemu-stable@nongnu.org Subject: [PATCH v5 01/11 for v9.2?] i386/cpu: Mark avx10_version filtered when prefix is NULL Date: Wed, 6 Nov 2024 11:07:18 +0800 Message-Id: <20241106030728.553238-2-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: 1730861493008116600 Content-Type: text/plain; charset="utf-8" In x86_cpu_filter_features(), if host doesn't support AVX10, the configured avx10_version should be marked as filtered regardless of whether prefix is NULL or not. Check prefix before warn_report() instead of checking for have_filtered_features. Cc: qemu-stable@nongnu.org Fixes: commit bccfb846fd52 ("target/i386: add AVX10 feature and AVX10 versi= on property") Signed-off-by: Zhao Liu Reviewed-by: Tao Su --- v5: new commit. --- target/i386/cpu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 3baa95481fbc..77c1233daa13 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7711,8 +7711,10 @@ static bool x86_cpu_filter_features(X86CPU *cpu, boo= l verbose) env->avx10_version =3D version; have_filtered_features =3D true; } - } else if (env->avx10_version && prefix) { - warn_report("%s: avx10.%d.", prefix, env->avx10_version); + } else if (env->avx10_version) { + if (prefix) { + warn_report("%s: avx10.%d.", prefix, env->avx10_version); + } have_filtered_features =3D true; } =20 --=20 2.34.1 From nobody Sat Nov 23 21:51:17 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=1730861484; cv=none; d=zohomail.com; s=zohoarc; b=ae5o9a5klkeov/ylDa0duxMPl2umcf93yD1aMUvqW+p9fVIZ+KEitZa1yu+duAU6OftoEI6IQilWuPaQ7aAHwNcvyvX+Pn9jD0SBJPph9QtO7Co3/+1c+QcY2xKhDRgQSBaG9Zg40M39+5OSQUWh8eVaj0kOEHzCQZcmkB/UEOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730861484; 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=4U5Xd+7X+uneidLLq/LbYVw3P1YPQwJahuLD/igZa4c=; b=g1HgE3uNB3yo8BFcBbayMtXhzdavOGBdCgMCaAuFF0psH8zPdv42lThBvnnK/6/elOluMrC+65gEaOn8FSQbSoBIygMqBowIUJeWvdoZprZHmWT4p/w4x0DdF4f5djSmWFp1+7rITrt3d8Gxg9wTy0blO+2dAJoVGTuQIky8AUk= 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 1730861484962471.6374847038444; Tue, 5 Nov 2024 18:51:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8W7c-00075p-Pj; Tue, 05 Nov 2024 21:50:16 -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 1t8W7M-0006w6-Bj for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:00 -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 1t8W7K-0003Mt-AH for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:49:59 -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:49:56 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa001.fm.intel.com with ESMTP; 05 Nov 2024 18:49:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861398; x=1762397398; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8vl5rexe63k4nr+JznMOIYOBxZwKEHBFQriO22wJpks=; b=ddA4NK5iMonIr84FhxVgtMkyWYr53HJpCkjDHCII8tf1LqtyqOyZoaSg l7qYhcYAEQXtcImZIC1u5Mwj3/gjPCEEJbhVAvcgQDE+WJbgfF9/PoXda 5SMKz7y7syv7dd+32MezZ/8uPWZmrkxfI50hQxwb+coBAAD9Y2kjKb79i cia1TcWk8X5m8MBKTRl1ugefizZMN283WProFYCvaBOJksG7nN4gKxm30 yn13d6osFqcL7ZWivupnMaaITrIfYnKllmcZkcHLskAAiVAGQi5NJYLHM MU91Tb8Sl7CDdP0bcyVOduqc9Z8IJ+pLVLEuBTdCVblp8OSI1xDIIE/ou g==; X-CSE-ConnectionGUID: zhq6vOzyT3mNcKpEnLwhuQ== X-CSE-MsgGUID: H32QrRBKTpCNQseA00liqg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492212" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492212" X-CSE-ConnectionGUID: as78JoftRCmoSA3eagVTXw== X-CSE-MsgGUID: kVYjVzZ9QLe7VZLDMlfAxg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,261,1725346800"; d="scan'208";a="115077979" 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 02/11] target/i386/kvm: Add feature bit definitions for KVM CPUID Date: Wed, 6 Nov 2024 11:07:19 +0800 Message-Id: <20241106030728.553238-3-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: 1730861486924116600 Content-Type: text/plain; charset="utf-8" Add feature definitions for KVM_CPUID_FEATURES in CPUID ( CPUID[4000_0001].EAX and CPUID[4000_0001].EDX), to get rid of lots of offset calculations. Signed-off-by: Zhao Liu Reviewed-by: Zide Chen --- v3: Resolved a rebasing conflict. v2: Changed the prefix from CPUID_FEAT_KVM_* to CPUID_KVM_*. (Xiaoyao) --- hw/i386/kvm/clock.c | 5 ++--- target/i386/cpu.h | 23 +++++++++++++++++++++++ target/i386/kvm/kvm.c | 28 ++++++++++++++-------------- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c index 40aa9a32c32c..ce416c05a3d0 100644 --- a/hw/i386/kvm/clock.c +++ b/hw/i386/kvm/clock.c @@ -27,7 +27,6 @@ #include "qapi/error.h" =20 #include -#include "standard-headers/asm-x86/kvm_para.h" #include "qom/object.h" =20 #define TYPE_KVM_CLOCK "kvmclock" @@ -334,8 +333,8 @@ void kvmclock_create(bool create_always) =20 assert(kvm_enabled()); if (create_always || - cpu->env.features[FEAT_KVM] & ((1ULL << KVM_FEATURE_CLOCKSOURCE) | - (1ULL << KVM_FEATURE_CLOCKSOURCE2))= ) { + cpu->env.features[FEAT_KVM] & (CPUID_KVM_CLOCK | + CPUID_KVM_CLOCK2)) { sysbus_create_simple(TYPE_KVM_CLOCK, -1, NULL); } } diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 59959b8b7a4d..c4ec64e0078f 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -29,6 +29,7 @@ #include "qapi/qapi-types-common.h" #include "qemu/cpu-float.h" #include "qemu/timer.h" +#include "standard-headers/asm-x86/kvm_para.h" =20 #define XEN_NR_VIRQS 24 =20 @@ -1009,6 +1010,28 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *= cpu, FeatureWord w); #define CPUID_8000_0007_EBX_OVERFLOW_RECOV (1U << 0) #define CPUID_8000_0007_EBX_SUCCOR (1U << 1) =20 +/* (Old) KVM paravirtualized clocksource */ +#define CPUID_KVM_CLOCK (1U << KVM_FEATURE_CLOCKSOURCE) +/* (New) KVM specific paravirtualized clocksource */ +#define CPUID_KVM_CLOCK2 (1U << KVM_FEATURE_CLOCKSOURCE2) +/* KVM asynchronous page fault */ +#define CPUID_KVM_ASYNCPF (1U << KVM_FEATURE_ASYNC_PF) +/* KVM stolen (when guest vCPU is not running) time accounting */ +#define CPUID_KVM_STEAL_TIME (1U << KVM_FEATURE_STEAL_TIME) +/* KVM paravirtualized end-of-interrupt signaling */ +#define CPUID_KVM_PV_EOI (1U << KVM_FEATURE_PV_EOI) +/* KVM paravirtualized spinlocks support */ +#define CPUID_KVM_PV_UNHALT (1U << KVM_FEATURE_PV_UNHALT) +/* KVM host-side polling on HLT control from the guest */ +#define CPUID_KVM_POLL_CONTROL (1U << KVM_FEATURE_POLL_CONTROL) +/* KVM interrupt based asynchronous page fault*/ +#define CPUID_KVM_ASYNCPF_INT (1U << KVM_FEATURE_ASYNC_PF_INT) +/* KVM 'Extended Destination ID' support for external interrupts */ +#define CPUID_KVM_MSI_EXT_DEST_ID (1U << KVM_FEATURE_MSI_EXT_DEST_ID) + +/* Hint to KVM that vCPUs expect never preempted for an unlimited time */ +#define CPUID_KVM_HINTS_REALTIME (1U << KVM_HINTS_REALTIME) + /* CLZERO instruction */ #define CPUID_8000_0008_EBX_CLZERO (1U << 0) /* Always save/restore FP error pointers */ diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 8e17942c3ba1..4fb822511a12 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -564,13 +564,13 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, ui= nt32_t function, * be enabled without the in-kernel irqchip */ if (!kvm_irqchip_in_kernel()) { - ret &=3D ~(1U << KVM_FEATURE_PV_UNHALT); + ret &=3D ~CPUID_KVM_PV_UNHALT; } if (kvm_irqchip_is_split()) { - ret |=3D 1U << KVM_FEATURE_MSI_EXT_DEST_ID; + ret |=3D CPUID_KVM_MSI_EXT_DEST_ID; } } else if (function =3D=3D KVM_CPUID_FEATURES && reg =3D=3D R_EDX) { - ret |=3D 1U << KVM_HINTS_REALTIME; + ret |=3D CPUID_KVM_HINTS_REALTIME; } =20 if (current_machine->cgs) { @@ -3963,20 +3963,20 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_add(cpu, MSR_IA32_TSC, env->tsc); kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, env->system_time_msr); kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, env->wall_clock_msr); - if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_ASYNC_PF_INT)) { + if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF_INT) { kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_INT, env->async_pf_int= _msr); } - if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_ASYNC_PF)) { + if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF) { kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_EN, env->async_pf_en_m= sr); } - if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_PV_EOI)) { + if (env->features[FEAT_KVM] & CPUID_KVM_PV_EOI) { kvm_msr_entry_add(cpu, MSR_KVM_PV_EOI_EN, env->pv_eoi_en_msr); } - if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_STEAL_TIME)) { + if (env->features[FEAT_KVM] & CPUID_KVM_STEAL_TIME) { kvm_msr_entry_add(cpu, MSR_KVM_STEAL_TIME, env->steal_time_msr= ); } =20 - if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_POLL_CONTROL)) { + if (env->features[FEAT_KVM] & CPUID_KVM_POLL_CONTROL) { kvm_msr_entry_add(cpu, MSR_KVM_POLL_CONTROL, env->poll_control= _msr); } =20 @@ -4441,19 +4441,19 @@ static int kvm_get_msrs(X86CPU *cpu) #endif kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, 0); kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, 0); - if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_ASYNC_PF_INT)) { + if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF_INT) { kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_INT, 0); } - if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_ASYNC_PF)) { + if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF) { kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_EN, 0); } - if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_PV_EOI)) { + if (env->features[FEAT_KVM] & CPUID_KVM_PV_EOI) { kvm_msr_entry_add(cpu, MSR_KVM_PV_EOI_EN, 0); } - if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_STEAL_TIME)) { + if (env->features[FEAT_KVM] & CPUID_KVM_STEAL_TIME) { kvm_msr_entry_add(cpu, MSR_KVM_STEAL_TIME, 0); } - if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_POLL_CONTROL)) { + if (env->features[FEAT_KVM] & CPUID_KVM_POLL_CONTROL) { kvm_msr_entry_add(cpu, MSR_KVM_POLL_CONTROL, 1); } if (has_architectural_pmu_version > 0) { @@ -6180,7 +6180,7 @@ uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address) return address; } env =3D &X86_CPU(first_cpu)->env; - if (!(env->features[FEAT_KVM] & (1 << KVM_FEATURE_MSI_EXT_DEST_ID))) { + if (!(env->features[FEAT_KVM] & CPUID_KVM_MSI_EXT_DEST_ID)) { return address; } =20 --=20 2.34.1 From nobody Sat Nov 23 21:51:17 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=1730861496; cv=none; d=zohomail.com; s=zohoarc; b=IKW1HiDM4BY/jZUcLl0Uk6yxbTKb1aHze31M7OawC6OkePLbB1x4nivws/j/ye8cgZtdOp7bqbFRi4WLhrpdH7QFici7KLXU3O0pgR0p1xh7pn7sHjFhAyCqL5n20HqULMpUDmaUtkpP9r1NZFFB1zxb83mIx8WrlxoS+7xtmdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730861496; 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=QG4udfzKIpW+bV4nGEcx/b8R6ls+7OJkmjVQwjCfG/k=; b=IwQmnnmvhdZy/LGfTG0/p+dyDgNCTv0wQBik63lyPGHD1Rkk+gAwIEV+RXXTcrwx67zVUOK2rbnkgCqBiyj8EVAW9F+NAeMHQDEPJGyDUtHwkufIbL/MTV9NN4q9/a1Clee6m3tBZgMYXB62pd0jGiGAswiz6a4r+uwrflZFGmE= 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 173086149618627.08493914879682; Tue, 5 Nov 2024 18:51:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8W7Z-0006zs-Ad; Tue, 05 Nov 2024 21:50:14 -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 1t8W7N-0006xO-MI for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:01 -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 1t8W7L-0003NC-RE for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:01 -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:49:59 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa001.fm.intel.com with ESMTP; 05 Nov 2024 18:49:56 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861400; x=1762397400; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YCBXtXIe8Tj9CHWP8C3P1QBlVFRxdenXMtX2KpHHTFo=; b=Ze4+YdtO9N0dfN9y2QD7HYjtCmcFSOI2+HD9brJX6jroabdwoBZdiniF 7SsT9w00eifxg8yNWue+29aTAqTujsS7mcwww7g6G0lvUlcv4V1cV7T8o A1gjJ3ThYD3R3O0PbD3rq/e1OcioaCu54FW1wMBu7FJ+AVRWd3PXnJElp ye9WPYPqgFDKwPp1oso9BCxLjfqErtavNtX8uHNSXq8wyq6n1Cn7Pjtmc IFKo75u+O2xIKss4fZ9ivpTE7nebkDUotfv82yvBwgD8hos9BENrZCtYu KTs93Mb+9e9NOw8JUWvdXkjg+XBNhX68u1RDpJZ266nmFh1RzzJdc3Pe/ A==; X-CSE-ConnectionGUID: rtcEW8W+SO6iB/jVwLxEDg== X-CSE-MsgGUID: Bl965tskQ8GHIFMJSKzLZg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492222" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492222" X-CSE-ConnectionGUID: LtXUEkcQS06dIeJkGeBUoQ== X-CSE-MsgGUID: G2sgJd0QRS+Risb+wHwD5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,261,1725346800"; d="scan'208";a="115077984" 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 03/11] target/i386/kvm: Remove local MSR_KVM_WALL_CLOCK and MSR_KVM_SYSTEM_TIME definitions Date: Wed, 6 Nov 2024 11:07:20 +0800 Message-Id: <20241106030728.553238-4-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: 1730861497040116600 Content-Type: text/plain; charset="utf-8" These 2 MSRs have been already defined in kvm_para.h (standard-headers/ asm-x86/kvm_para.h). Remove QEMU local definitions to avoid duplication. Signed-off-by: Zhao Liu Reviewed-by: Xiaoyao Li Reviewed-by: Zide Chen --- target/i386/kvm/kvm.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 4fb822511a12..54520a77d6af 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -95,9 +95,6 @@ #define KVM_APIC_BUS_CYCLE_NS 1 #define KVM_APIC_BUS_FREQUENCY (1000000000ULL / KVM_APIC_BUS_CYCLE_NS) =20 -#define MSR_KVM_WALL_CLOCK 0x11 -#define MSR_KVM_SYSTEM_TIME 0x12 - /* A 4096-byte buffer can hold the 8-byte kvm_msrs header, plus * 255 kvm_msr_entry structs */ #define MSR_BUF_SIZE 4096 --=20 2.34.1 From nobody Sat Nov 23 21:51:17 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=1730861543; cv=none; d=zohomail.com; s=zohoarc; b=ME1lvZvz2obku/TS+h9a4oMlIkmkoc9mYqQVXgH0yx+al2PXKEBD3R8R7nTbr3pLLawPRXtUnfGEXJ0IfcCuQIJQmwqxmR3MsjcyjMwVmrgesWC2nxc+MGop48gA2eAcLqhSJ0e6Ja88AwAmyQzHHxzKcbhNlAM9s94wu2ul63w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730861543; 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=qch0Gbjw57glVwcX/kJPNPMBSofWOgQWdzijp42rhw0=; b=h6LZhwzspYknb8G8dvSTeNxrVstlmySnnSC+/MFHrWquyki69uyVP7qx/c/cYDN9Bvst4rTHhlFECSWsNg4CeLeTKajHzr4zXB+8FBI57TXtxJ/352RNP9o6gyQacS3Vsfzgo0kmRx0uQBDGdYbVi1TwYXfel7G8JwaoQpxhq+M= 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 1730861543377492.75685718937666; Tue, 5 Nov 2024 18:52:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8W7e-00076d-KZ; Tue, 05 Nov 2024 21:50:18 -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 1t8W7Q-0006zA-IX for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:04 -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 1t8W7O-0003OA-Uh for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:04 -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:02 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa001.fm.intel.com with ESMTP; 05 Nov 2024 18:49:59 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861403; x=1762397403; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tKBwJL6L5EVOtxNNwMzd9GyrmnhuJhfCstxsPM8l8TE=; b=eie6X9xWogQbD7ippqWaWltRTLmxqvgAoKRYtQ5HgDiF0jTpmlQ6nT0h J3aP4zkRn/KHe0gyd+XgD88s2ZtEUtCJFAFUzTO/Bu5twmgzkn3Zk87b0 9s3XxZMnOa8ZmL+UUfPzD1lfTwRWhWg+u39yUD++2MJ3nsz7rXaUh6892 GWx3et6//gTFtCX/WYGd3YvYc43HriSMqNvtkP0JC5TYwZw4A3EKQcDTD xMmJZYlAR/ywMYOKSY7VCQsoQWThs4RTvbvCjzxYxvy7iBq6naHxLyxl1 M9FlASLL5R0PG0CgxTSSZoMO2smQf4kO36MwrPYar03tpeFsDHqiOBkvL w==; X-CSE-ConnectionGUID: M3OH33BnQt+ntSKdt7wywg== X-CSE-MsgGUID: /550gIvnTtq3ACJMj/qWdw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492261" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492261" X-CSE-ConnectionGUID: n4o6EjOYSaOcQW9cKuHglg== X-CSE-MsgGUID: CdhKrCipQJKvoj2CIIJ/Sw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,261,1725346800"; d="scan'208";a="115077990" 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 04/11] target/i386/kvm: Only save/load kvmclock MSRs when kvmclock enabled Date: Wed, 6 Nov 2024 11:07:21 +0800 Message-Id: <20241106030728.553238-5-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: 1730861545218116600 Content-Type: text/plain; charset="utf-8" MSR_KVM_SYSTEM_TIME and MSR_KVM_WALL_CLOCK are attached with the (old) kvmclock feature (KVM_FEATURE_CLOCKSOURCE). So, just save/load them only when kvmclock (KVM_FEATURE_CLOCKSOURCE) is enabled. Signed-off-by: Zhao Liu Reviewed-by: Zide Chen --- target/i386/kvm/kvm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 54520a77d6af..4aba034865bb 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3958,8 +3958,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level) */ if (level >=3D KVM_PUT_RESET_STATE) { kvm_msr_entry_add(cpu, MSR_IA32_TSC, env->tsc); - kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, env->system_time_msr); - kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, env->wall_clock_msr); + if (env->features[FEAT_KVM] & CPUID_KVM_CLOCK) { + kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, env->system_time_m= sr); + kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, env->wall_clock_msr= ); + } if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF_INT) { kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_INT, env->async_pf_int= _msr); } @@ -4436,8 +4438,10 @@ static int kvm_get_msrs(X86CPU *cpu) } } #endif - kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, 0); - kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, 0); + if (env->features[FEAT_KVM] & CPUID_KVM_CLOCK) { + kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, 0); + kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, 0); + } if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF_INT) { kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_INT, 0); } --=20 2.34.1 From nobody Sat Nov 23 21:51:17 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=1730861454; cv=none; d=zohomail.com; s=zohoarc; b=gf8C8KMuEOnvwmVL2YuxdotQQeZG5hPCc8uKzHYc4aEdJSBpjw503Oully9+8LixyLSJA9EX1B0wcSO4X1ken/zVMf2zn9634zVjtF6uX9fppX0ydsKI90ec+XYBrFk2EyEupkJK1tRDAvf345BrDu+TqijBUqP48GG/5o2J6Fs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730861454; 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=oW8UVFk6VNqiglxGC+V9ZfJdQqv2L4EMDv7c2WfY5f0=; b=ZSVrrgP46b2PbFD3bBxeq93iGlc7D2Q7CXO7lFxkaFKMUjXKu4enGarNbbDjUhXt9aXEoRJiqcKSVKq1VmOzac1P0uGsomb9ardqTqtqEObkJkUy5peyyVHi26k3UCxaO9f4gXDSJPjsiC3cGDRUlqB9kMITn5YZLo12xzmt7WY= 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 17308614540221.226645677815668; Tue, 5 Nov 2024 18:50:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8W7d-00076T-C7; Tue, 05 Nov 2024 21:50:17 -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 1t8W7T-00071K-8L for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:11 -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 1t8W7R-0003OA-Hk for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:07 -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:05 -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:02 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861406; x=1762397406; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JcVwYkgHmlLrfByBJgICNQrNbswie+WUwEU7n23xvn8=; b=e4vprRTVDRh1eGfGCpsGg51FxVivho78uArRoghZYd6HbyfM1LT5gFyR 38GwwRmww/uNZe/1R91pi6pGJNromznYeZqrDTuJvJZSD7j0h2a0HDfkw nhCVTPkdskC4mv1Z6w3nMhC2ZbTr7y3ioySQzVd1RyXn070C5dBQNF46c +D99O6rc4w/pG8c0j46ZglW715Hu7zl6LsJ+MartGGacGhYMTdk4T1R7d KDg8WNsNWu3P7p/1/2DJdeSU/R3SU0zK6YizqLipoL2CeanM/9Yigj9zU 48uajstJEzb1/Y446b1epRFNEqGWYJnoctgb3Digk2lN1IzFTottPdOqS A==; X-CSE-ConnectionGUID: t2q2nvOISXaTSIBS114ovw== X-CSE-MsgGUID: R0K1VOrvRKqP6Zqb3kaIKw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492271" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492271" X-CSE-ConnectionGUID: T5TLU2G+Su6PkrVLoalTGw== X-CSE-MsgGUID: YSLwJp0WSqyljdTgl/zOVA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,261,1725346800"; d="scan'208";a="115077998" 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 05/11] target/i386/kvm: Save/load MSRs of kvmclock2 (KVM_FEATURE_CLOCKSOURCE2) Date: Wed, 6 Nov 2024 11:07:22 +0800 Message-Id: <20241106030728.553238-6-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: 1730861454734116600 Content-Type: text/plain; charset="utf-8" MSR_KVM_SYSTEM_TIME_NEW and MSR_KVM_WALL_CLOCK_NEW are bound to kvmclock2 (KVM_FEATURE_CLOCKSOURCE2). Add the save/load support for these 2 MSRs just like kvmclock MSRs. Signed-off-by: Zhao Liu Reviewed-by: Zide Chen --- target/i386/cpu.h | 2 ++ target/i386/kvm/kvm.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index c4ec64e0078f..79c28a48eb70 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1886,6 +1886,8 @@ typedef struct CPUArchState { =20 uint64_t system_time_msr; uint64_t wall_clock_msr; + uint64_t system_time_new_msr; + uint64_t wall_clock_new_msr; uint64_t steal_time_msr; uint64_t async_pf_en_msr; uint64_t async_pf_int_msr; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 4aba034865bb..b175cd4a4bcb 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3962,6 +3962,12 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, env->system_time_m= sr); kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, env->wall_clock_msr= ); } + if (env->features[FEAT_KVM] & CPUID_KVM_CLOCK2) { + kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME_NEW, + env->system_time_new_msr); + kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK_NEW, + env->wall_clock_new_msr); + } if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF_INT) { kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_INT, env->async_pf_int= _msr); } @@ -4442,6 +4448,10 @@ static int kvm_get_msrs(X86CPU *cpu) kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, 0); kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, 0); } + if (env->features[FEAT_KVM] & CPUID_KVM_CLOCK2) { + kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME_NEW, 0); + kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK_NEW, 0); + } if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF_INT) { kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_INT, 0); } @@ -4708,6 +4718,12 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_KVM_WALL_CLOCK: env->wall_clock_msr =3D msrs[i].data; break; + case MSR_KVM_SYSTEM_TIME_NEW: + env->system_time_new_msr =3D msrs[i].data; + break; + case MSR_KVM_WALL_CLOCK_NEW: + env->wall_clock_new_msr =3D msrs[i].data; + break; case MSR_MCG_STATUS: env->mcg_status =3D msrs[i].data; break; --=20 2.34.1 From nobody Sat Nov 23 21:51:17 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=1730861493; cv=none; d=zohomail.com; s=zohoarc; b=d6k8+VsKKI7pMCs0ipAWI748HOIwHXyaxgbQVtYyOCBGpy2yjSKBdHBlhex9mQnS1Hby8LfyUsPbHZkqIKis1sCT0zOhY4Sr2LTFeKufe5DnDknCkZbTnDQqIIsrA7viE15ZcOQ1TPGjnwFbJNuy1bMyg3ZsezcMH4wNj1OH1i4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730861493; 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=gxio1K8iBJBIjnbHTAfbfhAmIk+VQsvfHC0tc8PM1GA=; b=SWwoOZroFZhb94DWr57F2fYOrxsdzQ+qUxzYTvOu9Hb62lxpXSbHnw8ZfOV3bpOg+CXvUHMG6ktlyqnZDTqFTV4XosVv87tw9EHhSEOwUcIBYKEARYpfjFhB1J/nzZYHn0rB9j44f6c9nMvSFsF1M/x6GNZ9i9rx3hqJd05N1/I= 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 173086149330983.36612953079646; Tue, 5 Nov 2024 18:51:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8W7f-00077M-Me; Tue, 05 Nov 2024 21:50:19 -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 1t8W7W-00073n-Ny for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:11 -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 1t8W7U-0003OA-DN for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:09 -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:08 -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:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861409; x=1762397409; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=M4sDt9QkECcSbT07XJdCv1wUJiDP78YRHjt03Sbegi4=; b=PBan4D1SFHGJqtNk545ZGjXuA+Qt6a6AO9KA4y6QOW1wBmS39M4o2e+Y kK+YgceX2Pjq1qCnX0aK+XA97z35qGMyWxj0Or5yqWVI+LyrWg7CUuJHW /qpXFyk+XseKJeCHNJykHS/3kj4mvk4q4g9qQs6tTyJiIjJY+Qu1u3oVN 7ZLua78s/7yvklbi8sZJA6gKfrWpJleOv3SrhFiR1b826Mx1U2o9uxZph 8NnLOpSAUC2Kub/HTO6bWHhSMQ1L3JGbEXe101txXwH/WnDCNTiSja9Wh OStVsBnndWA8Dc7l/lDg+sqKaAcIufJZ536d9MfTM4jKLesIqGUPcWwlU A==; X-CSE-ConnectionGUID: 5uQBzY+sTFiDMCJuQFfC1g== X-CSE-MsgGUID: mErn08xcR3yr0dpHjyUPkA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492281" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492281" X-CSE-ConnectionGUID: Ynv9OBZpTo6N0P/HesUs/Q== X-CSE-MsgGUID: +GUGd9ljSzuNoTo1fYV/8A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,261,1725346800"; d="scan'208";a="115078006" 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 06/11] target/i386/kvm: Drop workaround for KVM_X86_DISABLE_EXITS_HTL typo Date: Wed, 6 Nov 2024 11:07:23 +0800 Message-Id: <20241106030728.553238-7-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: 1730861495002116600 Content-Type: text/plain; charset="utf-8" The KVM_X86_DISABLE_EXITS_HTL typo has been fixed in commit 77d361b13c19 ("linux-headers: Update to kernel mainline commit b357bf602"). Drop the related workaround. Signed-off-by: Zhao Liu Reviewed-by: Zide Chen --- target/i386/kvm/kvm.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index b175cd4a4bcb..1fb4bd19fcf7 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3085,10 +3085,7 @@ static int kvm_vm_set_tss_addr(KVMState *s, uint64_t= tss_base) static int kvm_vm_enable_disable_exits(KVMState *s) { int disable_exits =3D kvm_check_extension(s, KVM_CAP_X86_DISABLE_EXITS= ); -/* Work around for kernel header with a typo. TODO: fix header and drop. */ -#if defined(KVM_X86_DISABLE_EXITS_HTL) && !defined(KVM_X86_DISABLE_EXITS_H= LT) -#define KVM_X86_DISABLE_EXITS_HLT KVM_X86_DISABLE_EXITS_HTL -#endif + if (disable_exits) { disable_exits &=3D (KVM_X86_DISABLE_EXITS_MWAIT | KVM_X86_DISABLE_EXITS_HLT | --=20 2.34.1 From nobody Sat Nov 23 21:51:17 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=1730861474; cv=none; d=zohomail.com; s=zohoarc; b=Qa+TB+B3/+/CqfljqQ4DT6SgYx2remYNEJddHMQKe1noAlwxXzQ1gPYZw6BlRRKyR4LhrsLywj4lFb7+4w6bHYMworZlLxDYad2ET+XxBePx8PSv9cIOSWZqr0Djxhaodugr1qt3B75q8tfj0C2nBSYvmMIZwdLNtd1sZtemQIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730861474; 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=kq64m4JXyS0DmMB98bR/HW3/1JgeCkNMBNYoYjEg+io=; b=KwCQncM6Buj26aS4rGtNGFS6A6zLX9mQhLUjeXRKIwN8ds5wYFmjnbtRQAR3lkiC2vDeTtoesHfvuGYaW6a4fMWFFRvKzgfc/U9Si85eCa1A8COMxz7PDO+GWZ0kKViQYGYBgsfZONIDKE7kk3wteH76z+kXrkdlcdFRspBmJ60= 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 17308614746371019.7087038081847; Tue, 5 Nov 2024 18:51:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8W7g-00078R-DW; Tue, 05 Nov 2024 21:50:20 -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 1t8W7a-00075d-Io for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:15 -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 1t8W7Y-0003OA-UN for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:14 -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:11 -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:08 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861413; x=1762397413; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HwNeX5BRFdrce3Z7AoO6W2SxOR4OlRNekMyhln01fPU=; b=i4sZ09ZxGvTuAkTEopwpn1+T93PgQKyWUBKNAHZ/EJVZeSXXb/VXAL9Q lYj4Dt+uYJYiaSdlyMuLxi5pmaUEzEdjTW4kRP3HcP4hZ+o81e7TTD/gO u/0yd63r2P4iBcA+vqUIlRqAJI9x72To2rDMiH6XCe5kJ6UGVFK4JVHGz P6SamlfEAroeqqhekxOrL6G5donOl76KKIQoyAS8BR+8eozurulBf6X1Q rnlOeyWvgaidNQPQdejBncAU3D1XVKYxEdKkaafiAVJZHNawGykIajJso YyQu9V7fnTF68wjciQ17pO91xZD27ZCltKM947FOyc4cY67RFIO3zElT8 w==; X-CSE-ConnectionGUID: 7iFg5O6nRMWlz/Uag4nHzA== X-CSE-MsgGUID: g2yQ4wJxQZewJuzfleUsxQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492291" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492291" X-CSE-ConnectionGUID: vozJa8rjS9qsShoUlaABqQ== X-CSE-MsgGUID: C5vwVy8DQBCqiUKnZ6DHjA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,261,1725346800"; d="scan'208";a="115078013" 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 07/11] target/i386/confidential-guest: Fix comment of x86_confidential_guest_kvm_type() Date: Wed, 6 Nov 2024 11:07:24 +0800 Message-Id: <20241106030728.553238-8-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: 1730861474874116600 Content-Type: text/plain; charset="utf-8" Update the comment to match the X86ConfidentialGuestClass implementation. Reported-by: Xiaoyao Li Signed-off-by: Zhao Liu Reviewed-by: Pankaj Gupta Reviewed-by: Zide Chen --- target/i386/confidential-guest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/confidential-guest.h b/target/i386/confidential-gu= est.h index 7342d2843aa5..c90a59bac41a 100644 --- a/target/i386/confidential-guest.h +++ b/target/i386/confidential-guest.h @@ -46,7 +46,7 @@ struct X86ConfidentialGuestClass { /** * x86_confidential_guest_kvm_type: * - * Calls #X86ConfidentialGuestClass.unplug callback of @plug_handler. + * Calls #X86ConfidentialGuestClass.kvm_type() callback. */ static inline int x86_confidential_guest_kvm_type(X86ConfidentialGuest *cg) { --=20 2.34.1 From nobody Sat Nov 23 21:51:17 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=1730861484; cv=none; d=zohomail.com; s=zohoarc; b=eNidixBAKfYQfSWKEmf2oHt8yfLm352r/+WeeyOmGox/nDjoSYrHmrfcE2QjjqTqVKRvHkV9bUoWEjfJTySs8hpa4MhX2D8YcIvoptFL8q1z/uMm1hlD6hhCQe3BUfrkpPpQqrITJpa6t6V+BqywjsvbaWmf1/nXbbztNdGCLMo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730861484; 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=uCagfg6V9fCzraF8/BG6Ht5J/JgT1nr0FdzxxwPEO/E=; b=n4JaNE9xT9tiZR2mK9FZ0ZKAUKcnjn2rIT/BremIbXXT+6ado7mif6CICOXxEusvzTvq11KEzy+KyeEqZTeX01bJcpgVGc04y/KR6FjPyUSpxRCkfjQNz6VNJoH5VZf4JDgchuI7nwLOe2ZV6j6TzM6MCdKjm43WGYyBJ1K1Fys= 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 173086148428424.317522484923984; Tue, 5 Nov 2024 18:51:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8W7h-00079M-3U; Tue, 05 Nov 2024 21:50:21 -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 1t8W7c-00075s-MU for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:16 -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 1t8W7a-0003OA-Sr for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:16 -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:14 -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:11 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861415; x=1762397415; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jFWGnz+suDCZpSQMmtwVwuQ2yns3DjY1J2pGL1AK0/Y=; b=OVha51k+VVAIDX6ZS1nXqRo9MEi6bvtGSgSZNCbrFRb4D1Z4Stl9NN65 jLjg6l12MvKhP2Cu8apkM+iO3mEZz40VKBtgdAifaTA3N4dHJAJVxkRsc UGNNtVKb2ZcnTil/0Fx3UK8jljIjz/ceyu5x2BeFNCWF8GrHhbPXP4zn8 6PGCj7jU0Ybq5uPdgAasiEnrnH3LhJjyy0/7VXtwzNt4MZwhMNo19TSq5 OI5VY946AQ/zWeyYw4ycR2qBisHIQ6ZP63Ee6JwAVD4w9Hurm4tMtRdgi 8ruCTlv8Ww89tl/xZN4J144k8T8MADdSBslvmt3P289Sxrhajj7m7eqPU Q==; X-CSE-ConnectionGUID: vf63t9kdRBC9sNDKganeBw== X-CSE-MsgGUID: dNWXsMa+RwCibbBiwsbb3g== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492302" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492302" X-CSE-ConnectionGUID: BHcOIsNZSFyg2LleDmVUXA== X-CSE-MsgGUID: 0Rm8CO5uTTevGQiWAwOa4w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,261,1725346800"; d="scan'208";a="115078022" 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 08/11] target/i386/kvm: Clean up return values of MSR filter related functions Date: Wed, 6 Nov 2024 11:07:25 +0800 Message-Id: <20241106030728.553238-9-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: 1730861484973116600 Content-Type: text/plain; charset="utf-8" Before commit 0cc42e63bb54 ("kvm/i386: refactor kvm_arch_init and split it into smaller functions"), error_report() attempts to print the error code from kvm_filter_msr(). However, printing error code does not work due to kvm_filter_msr() returns bool instead int. 0cc42e63bb54 fixed the error by removing error code printing, but this lost useful error messages. Bring it back by making kvm_filter_msr() return int. This also makes the function call chain processing clearer, allowing for better handling of error result propagation from kvm_filter_msr() to kvm_arch_init(), preparing for the subsequent cleanup work of error handling in kvm_arch_init(). Signed-off-by: Zhao Liu Reviewed-by: Zide Chen --- v5: Rebased and cleaned up kvm_vm_enable_energy_msrs() as well. v4: Returned kvm_vm_ioctl() directly. (Zide) v3: new commit. --- target/i386/kvm/kvm.c | 87 ++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 1fb4bd19fcf7..9993382fb40e 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -108,8 +108,8 @@ typedef struct { } KVMMSRHandlers; =20 static void kvm_init_msrs(X86CPU *cpu); -static bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rd= msr, - QEMUWRMSRHandler *wrmsr); +static int kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdm= sr, + QEMUWRMSRHandler *wrmsr); =20 const KVMCapabilityInfo kvm_arch_required_capabilities[] =3D { KVM_CAP_INFO(SET_TSS_ADDR), @@ -3135,17 +3135,21 @@ static int kvm_vm_enable_notify_vmexit(KVMState *s) =20 static int kvm_vm_enable_userspace_msr(KVMState *s) { - int ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_USER_SPACE_MSR, 0, - KVM_MSR_EXIT_REASON_FILTER); + int ret; + + ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_USER_SPACE_MSR, 0, + KVM_MSR_EXIT_REASON_FILTER); if (ret < 0) { error_report("Could not enable user space MSRs: %s", strerror(-ret)); exit(1); } =20 - if (!kvm_filter_msr(s, MSR_CORE_THREAD_COUNT, - kvm_rdmsr_core_thread_count, NULL)) { - error_report("Could not install MSR_CORE_THREAD_COUNT handler!"); + ret =3D kvm_filter_msr(s, MSR_CORE_THREAD_COUNT, + kvm_rdmsr_core_thread_count, NULL); + if (ret < 0) { + error_report("Could not install MSR_CORE_THREAD_COUNT handler: %s", + strerror(-ret)); exit(1); } =20 @@ -3154,36 +3158,37 @@ static int kvm_vm_enable_userspace_msr(KVMState *s) =20 static void kvm_vm_enable_energy_msrs(KVMState *s) { - bool r; + int ret; + if (s->msr_energy.enable =3D=3D true) { - r =3D kvm_filter_msr(s, MSR_RAPL_POWER_UNIT, - kvm_rdmsr_rapl_power_unit, NULL); - if (!r) { - error_report("Could not install MSR_RAPL_POWER_UNIT \ - handler"); + ret =3D kvm_filter_msr(s, MSR_RAPL_POWER_UNIT, + kvm_rdmsr_rapl_power_unit, NULL); + if (ret < 0) { + error_report("Could not install MSR_RAPL_POWER_UNIT handler: %= s", + strerror(-ret)); exit(1); } =20 - r =3D kvm_filter_msr(s, MSR_PKG_POWER_LIMIT, - kvm_rdmsr_pkg_power_limit, NULL); - if (!r) { - error_report("Could not install MSR_PKG_POWER_LIMIT \ - handler"); + ret =3D kvm_filter_msr(s, MSR_PKG_POWER_LIMIT, + kvm_rdmsr_pkg_power_limit, NULL); + if (ret < 0) { + error_report("Could not install MSR_PKG_POWER_LIMIT handler: %= s", + strerror(-ret)); exit(1); } =20 - r =3D kvm_filter_msr(s, MSR_PKG_POWER_INFO, - kvm_rdmsr_pkg_power_info, NULL); - if (!r) { - error_report("Could not install MSR_PKG_POWER_INFO \ - handler"); + ret =3D kvm_filter_msr(s, MSR_PKG_POWER_INFO, + kvm_rdmsr_pkg_power_info, NULL); + if (ret < 0) { + error_report("Could not install MSR_PKG_POWER_INFO handler: %s= ", + strerror(-ret)); exit(1); } - r =3D kvm_filter_msr(s, MSR_PKG_ENERGY_STATUS, - kvm_rdmsr_pkg_energy_status, NULL); - if (!r) { - error_report("Could not install MSR_PKG_ENERGY_STATUS \ - handler"); + 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); } } @@ -5842,13 +5847,13 @@ void kvm_arch_update_guest_debug(CPUState *cpu, str= uct kvm_guest_debug *dbg) } } =20 -static bool kvm_install_msr_filters(KVMState *s) +static int kvm_install_msr_filters(KVMState *s) { uint64_t zero =3D 0; struct kvm_msr_filter filter =3D { .flags =3D KVM_MSR_FILTER_DEFAULT_ALLOW, }; - int r, i, j =3D 0; + int i, j =3D 0; =20 for (i =3D 0; i < KVM_MSR_FILTER_MAX_RANGES; i++) { KVMMSRHandlers *handler =3D &msr_handlers[i]; @@ -5872,18 +5877,13 @@ static bool kvm_install_msr_filters(KVMState *s) } } =20 - r =3D kvm_vm_ioctl(s, KVM_X86_SET_MSR_FILTER, &filter); - if (r) { - return false; - } - - return true; + return kvm_vm_ioctl(s, KVM_X86_SET_MSR_FILTER, &filter); } =20 -static bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rd= msr, - QEMUWRMSRHandler *wrmsr) +static int kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdm= sr, + QEMUWRMSRHandler *wrmsr) { - int i; + int i, ret; =20 for (i =3D 0; i < ARRAY_SIZE(msr_handlers); i++) { if (!msr_handlers[i].msr) { @@ -5893,16 +5893,17 @@ static bool kvm_filter_msr(KVMState *s, uint32_t ms= r, QEMURDMSRHandler *rdmsr, .wrmsr =3D wrmsr, }; =20 - if (!kvm_install_msr_filters(s)) { + ret =3D kvm_install_msr_filters(s); + if (ret) { msr_handlers[i] =3D (KVMMSRHandlers) { }; - return false; + return ret; } =20 - return true; + return 0; } } =20 - return false; + return -EINVAL; } =20 static int kvm_handle_rdmsr(X86CPU *cpu, struct kvm_run *run) --=20 2.34.1 From nobody Sat Nov 23 21:51:17 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=1730861433; cv=none; d=zohomail.com; s=zohoarc; b=WrZ2xNzqOthlaIUWHbMuaQlHLHC6nSPLCV2PzL9h/P12mmXX6Lx+tuG7ZOqUNXVMqZXcSlBaQ6L+kd4AaY8zoxUlzXxoWYnKmSzcMGBnqWL3v6SRBUzHV8blASnS/wlJQqrmCl1mnFIzF1MwcCAWpJGiRi7YrmWKd29wI2X/DIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730861433; 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=+7OQGRRMVGM0LQKZVZ5aHvg935cDb/TdL9Y4JyBEJRo=; b=ntpD4fGLgg4dYLQArz389r2UelYTGtKdCYbGqvxhV7Ih2QMmZdBzePcwqteoOckhDX5LAgo1LV+yy592wRwymBVSp17lOmUWHn1t/YaQ3PsIU7ljAtzolerr6CLgomC1sMaJafq7jY58/9zZm2vWo50VsuSsUBgkU+i/28dt5MQ= 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 1730861433919263.2959107744523; Tue, 5 Nov 2024 18:50:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8W7i-00079i-CF; Tue, 05 Nov 2024 21:50:22 -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 1t8W7g-00078Q-B0 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:20 -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 1t8W7e-0003cN-Kd for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:20 -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:17 -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:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861419; x=1762397419; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W73DxTAKGKDwOxIP+UEa3mm04Ri1kkHN13Gfy8Im22A=; b=EKm3CdB6YGkg/3fIyvwg9wDE7j8ZUj5vqTzA/z9SA8y3/t2hsniixpRf pVE9ejeXngKQQzSOstkblvW5eXE20vLeZgKU9wNjCaJ1apHe6Zb5h0DoT t2Lp8ZO1dqFWHA3Y2l0HHfIdsDSbK9V1Cpibz0LL7p3fdeUkyTfzBep98 uYFrYVxgeapFNEePGWZSOtm8MpeLz+96OQ9fvqv7E17DVS3JGRfrRJijm +IQndhNNgYTaZ572zAm14uIg2/Z51AOKBCOqApyT6rCvFGFMjuIpd8P9e nKp/NWmghk76MAMi2VJUBDitcRoP/2ZRgYrAggoV0Uoc3Wkz14s0HKKpV w==; X-CSE-ConnectionGUID: Yr4Qp6ctTfCzL9AirMb+vg== X-CSE-MsgGUID: 0yhaZxALQ5aoJxzCkBO/2w== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492312" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492312" X-CSE-ConnectionGUID: u6UjNTUoTaahh0D0ORPZLQ== X-CSE-MsgGUID: u1ZDVdxyTCW2KTSVmr2mUw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,261,1725346800"; d="scan'208";a="115078027" 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 09/11] target/i386/kvm: Return -1 when kvm_msr_energy_thread_init() fails Date: Wed, 6 Nov 2024 11:07:26 +0800 Message-Id: <20241106030728.553238-10-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: 1730861434739116600 Content-Type: text/plain; charset="utf-8" It is common practice to return a negative value (like -1) to indicate an error, and other functions in kvm_arch_init() follow this style. To avoid confusion (sometimes returned -1 indicates failure, and sometimes -1, in a same function), return -1 when kvm_msr_energy_thread_init() fails. Signed-off-by: Zhao Liu --- v5: new commit. --- target/i386/kvm/kvm.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 9993382fb40e..69825b53b6da 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -2921,7 +2921,6 @@ static int kvm_msr_energy_thread_init(KVMState *s, Ma= chineState *ms) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); struct KVMMsrEnergy *r =3D &s->msr_energy; - int ret =3D 0; =20 /* * Sanity check @@ -2931,13 +2930,11 @@ static int kvm_msr_energy_thread_init(KVMState *s, = MachineState *ms) if (!is_host_cpu_intel()) { error_report("The RAPL feature can only be enabled on hosts " "with Intel CPU models"); - ret =3D 1; - goto out; + return -1; } =20 if (!is_rapl_enabled()) { - ret =3D 1; - goto out; + return -1; } =20 /* Retrieve the virtual topology */ @@ -2959,16 +2956,14 @@ static int kvm_msr_energy_thread_init(KVMState *s, = MachineState *ms) r->host_topo.maxcpus =3D vmsr_get_maxcpus(); if (r->host_topo.maxcpus =3D=3D 0) { error_report("host max cpus =3D 0"); - ret =3D 1; - goto out; + return -1; } =20 /* Max number of packages on the host */ r->host_topo.maxpkgs =3D vmsr_get_max_physical_package(r->host_topo.ma= xcpus); if (r->host_topo.maxpkgs =3D=3D 0) { error_report("host max pkgs =3D 0"); - ret =3D 1; - goto out; + return -1; } =20 /* Allocate memory for each package on the host */ @@ -2980,8 +2975,7 @@ static int kvm_msr_energy_thread_init(KVMState *s, Ma= chineState *ms) for (int i =3D 0; i < r->host_topo.maxpkgs; i++) { if (r->host_topo.pkg_cpu_count[i] =3D=3D 0) { error_report("cpu per packages =3D 0 on package_%d", i); - ret =3D 1; - goto out; + return -1; } } =20 @@ -2998,8 +2992,7 @@ static int kvm_msr_energy_thread_init(KVMState *s, Ma= chineState *ms) =20 if (s->msr_energy.sioc =3D=3D NULL) { error_report("vmsr socket opening failed"); - ret =3D 1; - goto out; + return -1; } =20 /* Those MSR values should not change */ @@ -3011,15 +3004,13 @@ static int kvm_msr_energy_thread_init(KVMState *s, = MachineState *ms) s->msr_energy.sioc); if (r->msr_unit =3D=3D 0 || r->msr_limit =3D=3D 0 || r->msr_info =3D= =3D 0) { error_report("can't read any virtual msr"); - ret =3D 1; - goto out; + return -1; } =20 qemu_thread_create(&r->msr_thr, "kvm-msr", kvm_msr_energy_thread, s, QEMU_THREAD_JOINABLE); -out: - return ret; + return 0; } =20 int kvm_arch_get_default_type(MachineState *ms) @@ -3327,7 +3318,9 @@ int kvm_arch_init(MachineState *ms, KVMState *s) =20 if (s->msr_energy.enable =3D=3D true) { kvm_vm_enable_energy_msrs(s); - if (kvm_msr_energy_thread_init(s, ms)) { + + ret =3D kvm_msr_energy_thread_init(s, ms); + if (ret < 0) { error_report("kvm : error RAPL feature requirement not met= "); exit(1); } --=20 2.34.1 From nobody Sat Nov 23 21:51:17 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 From nobody Sat Nov 23 21:51:17 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=1730861471; cv=none; d=zohomail.com; s=zohoarc; b=Z6nvelFdivhMsYS3yN76eeeqHyuiWtvvJXLineNnSAGbSlRvqilDXZL9Vo77IkgYT5EH3r6BBID0Z6yYoWhoTU6zAs35ktYvsYvK70xz0HoSA99H1++DZEeyFTLzY5pVJ2LaAT3L6inOypxCP2i3+Obh5YDKeYykvd/Btk8jqAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730861471; 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=NQiDW6jSrs647EVfTfND7XKoh66OoeSJ38G6iLSIsUc=; b=fE9t+0cfraCMSarD3/XnX63XxOnD9nVGoF5t/JKTx4zDC1Liz2dhMwY/YtJnbGSXMlc0rNnJKnvnvULRJYNgwGzF5ibqy7FlktkREQxycjeqzymteDwEhz7OuXRpBub7jSVvfxfRr5SUPg+V8pbPn8Rw1MOp+VIS+fW9sn2cekg= 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 173086147141299.00443097159734; Tue, 5 Nov 2024 18:51:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8W7o-0007Bp-F6; Tue, 05 Nov 2024 21:50:28 -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 1t8W7m-0007BQ-O6 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:26 -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 1t8W7l-0003d6-0v for qemu-devel@nongnu.org; Tue, 05 Nov 2024 21:50:26 -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:24 -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:20 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861425; x=1762397425; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9AuyQrZYSzpVA3FJlyTq2ttbB88VVZZG/V9oVSStOkA=; b=VXlBmCNelqYELmuQJP+qwIjlpWReC5gEPjHxjdTLtqoHvzgsEZC2dkEV 44ypGqEdMY9Fsp+VCo1WFirVunrthLJEX3rZ1mBkIqB8ckWiNndgDX0uv q0CdqCSpsMXeqVRzrd0BfsSQnMcjPHbMlha7CFnmS1NWaAztC/Zq6AuEc Q8EXzI+w0DRI2iYxEd6GIwq5sw/7kJMAQ3o1alifIFTva9sIJ5ArreOQH R64vLRTjj8tjplW2gt6aq42KQDo1UiNCcgkMy6G42vJEm1RYnE3j/psKZ XvL+bbUYtnni0fX0x7WWVWQ0jMvDRGPiLvSTln9DgeKltxW0pnuNAonNW g==; X-CSE-ConnectionGUID: zGzZ8vs4RbW5wvWSAzDBjA== X-CSE-MsgGUID: 8NoJAtJ1Q+21EpaeEhwxGw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492330" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492330" X-CSE-ConnectionGUID: Xc1MDl7tSfCEEqJ32ZjcVg== X-CSE-MsgGUID: k7B4qdF5SEW5pn0ojYmSlg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,261,1725346800"; d="scan'208";a="115078037" 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 11/11] target/i386/kvm: Replace ARRAY_SIZE(msr_handlers) with KVM_MSR_FILTER_MAX_RANGES Date: Wed, 6 Nov 2024 11:07:28 +0800 Message-Id: <20241106030728.553238-12-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: 1730861472963116600 Content-Type: text/plain; charset="utf-8" kvm_install_msr_filters() uses KVM_MSR_FILTER_MAX_RANGES as the bound when traversing msr_handlers[], while other places still compute the size by ARRAY_SIZE(msr_handlers). In fact, msr_handlers[] is an array with the fixed size KVM_MSR_FILTER_MAX_RANGES, so there is no difference between the two ways. For the code consistency and to avoid additional computational overhead, use KVM_MSR_FILTER_MAX_RANGES instead of ARRAY_SIZE(msr_handlers). Suggested-by: Zide Chen Signed-off-by: Zhao Liu Reviewed-by: Zide Chen --- v4: new commit. --- target/i386/kvm/kvm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 013c0359acbe..501873475255 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -5885,7 +5885,7 @@ static int kvm_filter_msr(KVMState *s, uint32_t msr, = QEMURDMSRHandler *rdmsr, { int i, ret; =20 - for (i =3D 0; i < ARRAY_SIZE(msr_handlers); i++) { + for (i =3D 0; i < KVM_MSR_FILTER_MAX_RANGES; i++) { if (!msr_handlers[i].msr) { msr_handlers[i] =3D (KVMMSRHandlers) { .msr =3D msr, @@ -5911,7 +5911,7 @@ static int kvm_handle_rdmsr(X86CPU *cpu, struct kvm_r= un *run) int i; bool r; =20 - for (i =3D 0; i < ARRAY_SIZE(msr_handlers); i++) { + for (i =3D 0; i < KVM_MSR_FILTER_MAX_RANGES; i++) { KVMMSRHandlers *handler =3D &msr_handlers[i]; if (run->msr.index =3D=3D handler->msr) { if (handler->rdmsr) { @@ -5931,7 +5931,7 @@ static int kvm_handle_wrmsr(X86CPU *cpu, struct kvm_r= un *run) int i; bool r; =20 - for (i =3D 0; i < ARRAY_SIZE(msr_handlers); i++) { + for (i =3D 0; i < KVM_MSR_FILTER_MAX_RANGES; i++) { KVMMSRHandlers *handler =3D &msr_handlers[i]; if (run->msr.index =3D=3D handler->msr) { if (handler->wrmsr) { --=20 2.34.1