From patchwork Wed Nov 6 03:07:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13863867 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1B2C18FC84 for ; Wed, 6 Nov 2024 02:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861395; cv=none; b=B1myF2p+oHRP8vD6unCFPPxyow+8c9yN9S9sypswZxPvGpNf+U2D1on23jfKa8o02BozDPkOLV0mpTbgjujLFnLEhOXZpS5FddgVRb1erhTjkH2CI0erbfBEiX9vYkXfQ42Gbf2ejYFT6dI7LskgBaN/W/fUTFe0C9qfh5k+IE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861395; c=relaxed/simple; bh=H7lerJmEuC7yP69gP6zV6WKJa2+lLUCqxp5WR8/LiAI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dmp/tAIlHA0L9D+Oi15o9RxyTq0eVYtyxFIiEZOmYVDmjWB0vDEA7TwzwOhwEAikEM1CSgO0J6cEXNQe8zwPw51KUpX8JosHEAVOKz1YxtVae3yooS/vIL9/6Ta5TPEMaoJfc4rGZkfpJkd2dw1pHTFtFBd+qQivKY8UDhi95wg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hJjb/yyI; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hJjb/yyI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861394; x=1762397394; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H7lerJmEuC7yP69gP6zV6WKJa2+lLUCqxp5WR8/LiAI=; b=hJjb/yyIMldPDo1Uk9NH6lf/PRKgN2pt71zQIu90I0m1Iv+7r6Rg4nKR RrZyN8/uqoPBzRidBj0oRIHrHKdWK0YcDUhDipGRQsSe0r7NOsOfxbetK /QBkfblM3QEfD9UPLvVf8EL9FMRtBEhxMRlXpqyzMv/5l/v6uwp0L7Raq gPBolSo48vJmbRjKp5nilQ0MzlKqSIg3/dc4FJFB3cT+J3lUaRpLh8sp+ 27gBcwYqWAVHZqrHb4jKPOqzTsXQIB9rYw3EfmxwAhNlGQrrFFk9ZiE2b TO9vNgL5Uz9EWT8pi/MF7OBsNtbROxSnoxY94OshO/ibc7TAYwE+FCe44 A==; X-CSE-ConnectionGUID: Ap0A7msvSuyN1H8RWUi0vw== X-CSE-MsgGUID: qOaggdNlRjyH3zd4SAuNZg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492200" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492200" 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 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" 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 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 version property") Signed-off-by: Zhao Liu --- 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, bool verbose) env->avx10_version = version; have_filtered_features = 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 = true; } From patchwork Wed Nov 6 03:07:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13863868 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28AF218FC84 for ; Wed, 6 Nov 2024 02:49:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861399; cv=none; b=qVUd/jnMEonA9KipaE0EDCcLKBppnB2N80hzDahh1UJxxh3Fv88uQzlDL4QNxKntAOFll5dS+CSg91g2Vv6CAlEyuWM5NaEmozYXA3zM6Ezy4d8unSteoYjd8Awv4/ftW3LmXWqzkn3AorFKM3rekOvpGYWHXb6Uls4kv2JY9qo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861399; c=relaxed/simple; bh=8vl5rexe63k4nr+JznMOIYOBxZwKEHBFQriO22wJpks=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iy655nyI3Fn5uRkebfyNnBLs1lHg0fBYbisUT0w39Nw36uvyWhjKGXTsVKjIrRE6M8f4J1bXXAnJ99Li3MU4q2OyosbV5FWoGvNpcNwkGR3ajZyLEFaUkoId2/44nZZ1B652qqpUwQ+aOMpTiDAlBQv/lRr92uNAvpMwTqc2FFU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=N+g+ElIV; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="N+g+ElIV" 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=8vl5rexe63k4nr+JznMOIYOBxZwKEHBFQriO22wJpks=; b=N+g+ElIV5QHYolq/yy1w3Atn/oJ9gtW8yx4fn764DlC19QSQf24jAfvV r+1phPYh5JeDYoVq3EGTx+tfAq89nPhPE5G62BkHNulMyH/tM3Y5shiSV 7Rzyl1hiZHL5gH0u7D3lYxEaJLz1DR/FUftTVUX+JweQ9/AhVmxyE4CAw igvnQMeVI0Zd4NUnIPDEdYR2DaQvBZNSOGtOiz0CuxneSspR8RwAQ6qhD OqmMKBrnt0m2MTEwBLYZ2GRewooPufjL7iIvTzHiEag/PUUyulm08el2r uTr0vLx1L7QW4EwBy+AYJ1+nbkvK1M/Vl0sFHMMo+grSe7XnNEDas000e w==; X-CSE-ConnectionGUID: rb+iZfbdTIWeCqEriaoJ3Q== X-CSE-MsgGUID: PEw9EYUzRbWOZQVD+7h9gQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492210" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492210" 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 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" 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 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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" #include -#include "standard-headers/asm-x86/kvm_para.h" #include "qom/object.h" #define TYPE_KVM_CLOCK "kvmclock" @@ -334,8 +333,8 @@ void kvmclock_create(bool create_always) 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" #define XEN_NR_VIRQS 24 @@ -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) +/* (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, uint32_t function, * be enabled without the in-kernel irqchip */ if (!kvm_irqchip_in_kernel()) { - ret &= ~(1U << KVM_FEATURE_PV_UNHALT); + ret &= ~CPUID_KVM_PV_UNHALT; } if (kvm_irqchip_is_split()) { - ret |= 1U << KVM_FEATURE_MSI_EXT_DEST_ID; + ret |= CPUID_KVM_MSI_EXT_DEST_ID; } } else if (function == KVM_CPUID_FEATURES && reg == R_EDX) { - ret |= 1U << KVM_HINTS_REALTIME; + ret |= CPUID_KVM_HINTS_REALTIME; } 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_msr); } - 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); } - 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); } @@ -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 = &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; } From patchwork Wed Nov 6 03:07:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13863869 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 160B518A92C for ; Wed, 6 Nov 2024 02:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861400; cv=none; b=g6BEZPXQ9qYUKmzwwI4btdAInIiGlEFbijq0NqrzMk64Yo9rioDPUas6xf4VxtK7M5q4MlaZe2tP712vnBd8KaeMPEM5NG8XQ3SHdQZeyrhcoK69KJFej9ljIjk71Y6/UVsw2hVeoDHF/1Z/LrN45jZpVavK+vFRLhO1p1y3U8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861400; c=relaxed/simple; bh=YCBXtXIe8Tj9CHWP8C3P1QBlVFRxdenXMtX2KpHHTFo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UtmyeuQ9+XBV5mo1SM7RXeIWqQEfHg+tm4CvV6DmMb1INHHYwPKBJfu21q+k8TPqYvgBD/GoYVLSW2eMZfIjxXdMHyq7B20cZSeWDIGB4E9QcJaPWAf+i6Dwn9AoBKT6kvWHqVY/qYa8XIs1nnvcdqJeHNTHf1rDO3anYp8aG9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=VSibFtXS; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VSibFtXS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861399; x=1762397399; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YCBXtXIe8Tj9CHWP8C3P1QBlVFRxdenXMtX2KpHHTFo=; b=VSibFtXSvGpnlD8FC6Vt8hhR+tojof1mnxZO/ZBHNjQLdVy+zitIhDCt PQ9WPSOmhEfn6MS1uL/sZH3GLejtelPr+GutQno/yWj0AHY8NfZqw/4S7 CH7eOIE8Bj1r8Bj8S8OCxz7Ydb7BUAbOA/ISyXqNd1j9zBbSLH2aGr5D6 BI3OchjDkmcGkZEx0Bm8SnQkuq21g0BPjNkueJg3OgHtKAr3K8PoXX4I5 XaxmWZ2cljHEW09YA06BFkKsaZ1KJcPKfza1C58rKh8OMq/iCoCB3686D 9DlvCnsr/l0BMyCG/o5V1r1ZaLQAPc1g1iWAsMMj+RGnDenzYM5ctih1Z w==; X-CSE-ConnectionGUID: Tg8In+fZQiW8LiaVXwiGZw== X-CSE-MsgGUID: S+ZIj9JTTwqltONyqqrmoA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492220" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492220" 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 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" 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 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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) -#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 From patchwork Wed Nov 6 03:07:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13863870 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03BDA18FDC6 for ; Wed, 6 Nov 2024 02:50:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861403; cv=none; b=lRPn13Udoz7agmQ8tBSOKQzLDozunpdyxx+boUtVg71Sy9vqrijoZOvm4w/lnJa72lV2uoAGOevBB2PAvNr/Six1DxLyvMeySatF06zBI0sIKZmzvtNFroNk+tBdJmNamrZf5UnqcseHD1xlodS35+6aVXqw+i0l6ve8F2i5Ki0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861403; c=relaxed/simple; bh=tKBwJL6L5EVOtxNNwMzd9GyrmnhuJhfCstxsPM8l8TE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AYvBvCZO3nnk3ccKNujmr1fBbVxAjTivvMSSuSiEOyfXjWzx62EO2b8WclSAJHXybMadyN10hXrge2ujQ5Fx6lFyhBma/LhauuM3vjMMmrs2duFpZw/lLh6xV5p9S7IvQpd/4Om5fBuD0Pfu5IDXwlB499BoNXwQPZPeFsq4sa0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gxHIj8q+; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gxHIj8q+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861402; x=1762397402; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tKBwJL6L5EVOtxNNwMzd9GyrmnhuJhfCstxsPM8l8TE=; b=gxHIj8q+Yy952QQ0JfTKDF02qLjrsAKVJkpGGg6RvKW3yXUC32TZtyWV vexci+y+6QL4gyOupNecGttKgvBrImgk64HdLF8RUBulHLFdVu+NnU0+G cuy+Lxlm2UifCYJGkwAJoUYn2QAHUoo3m+pKO3kfQIuSHgmP1RzA7nvJU N5gr88KE2q7IBz+ZG3CaHUZxjeK379dcnbElLbhpMQaf3Tb1pJvr84BYU uAzVBVyZAimtpT4sRyH9K++Ch+GDl3M177gqKqM79bqBDUBjW7CZrzgzM gfOpgGGwnu1fEWOWdW7+pdvap1T/LjlVx0rWTH8zc5+/7fWx0zDt+4Zh/ g==; X-CSE-ConnectionGUID: ic6Wq1uXQKarA3eDXFPSRg== X-CSE-MsgGUID: /SF/c9vBTcq4kgDzRwJFUQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492259" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492259" 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 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" 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 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 >= 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_msr); + 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); } From patchwork Wed Nov 6 03:07:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13863871 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A036190056 for ; Wed, 6 Nov 2024 02:50:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861406; cv=none; b=eIFEfMdPUu1GhGHZWYB3VQke28M7C8v3HY+3LwTjG8cHEqd+2poPl3Ke35w3nJwFzNzGFAFljoHpDWUIqwduoTztnqd3wJQV62FP3n329b08iAXjZDjj51hlsGMcacDAO0KXudpc1fZJoP0DpwydYLxhRHGsZxZg9LFzu1IcM/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861406; c=relaxed/simple; bh=JcVwYkgHmlLrfByBJgICNQrNbswie+WUwEU7n23xvn8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HxK4PqmCu3NDb0QvBDj5EjhcBDCwTbf/AnXh09A173tbohMle9GY4D7Ei9uWu2TUWrXLXLb41Pg5LEQarjL0EKR/N5EdS7aZ16FE7XMMr7ccQXgjO/rn4gE5nlhNC3eoCRPmIyH69XhlhOuZx6v/0J06aK5CBsQZ0HeqMkEWy7A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=PeJ1Kage; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="PeJ1Kage" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861405; x=1762397405; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JcVwYkgHmlLrfByBJgICNQrNbswie+WUwEU7n23xvn8=; b=PeJ1Kage2MCxJUE4vbI7rdNMR3yqN1V/K5YgjhxmvBjmk08LdEp2ocTo 7RDaRcIT7A73pVdxXMqyxVE7HfHWmHQgR3kgRUeKTO02r02iCVagWZCyK iumvmdJ9+/fv6mW1Y8oMeOPmtkL7KI6Zg9MfRMUwx2vSJeuz7KMeW/a6/ /yKRl5YW0tcIy40Tzl6w5nHAPL336dh82utdBa021QZ7ng3JIrcKFwENt l7vMsFtMALzeQnRZF9SR0Q06AihAffOKwA/jwjIg5JAjwXIzjrfhvVx61 rR56outVl1+WWZBZtvYIFMWp9QQ1i8Gwp/YWr+SiOKcHbEY+4PIF2oaFF Q==; X-CSE-ConnectionGUID: YDPoDqDUTfGO6Ev2z7CtSQ== X-CSE-MsgGUID: uik7HcDoQYGsZlBEg3JolA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492269" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492269" 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 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" 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 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 { 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_msr); 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 = msrs[i].data; break; + case MSR_KVM_SYSTEM_TIME_NEW: + env->system_time_new_msr = msrs[i].data; + break; + case MSR_KVM_WALL_CLOCK_NEW: + env->wall_clock_new_msr = msrs[i].data; + break; case MSR_MCG_STATUS: env->mcg_status = msrs[i].data; break; From patchwork Wed Nov 6 03:07:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13863872 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC7DD18B47E for ; Wed, 6 Nov 2024 02:50:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861409; cv=none; b=J6bDfDdSpEt9OERHJ/AnoxNxYRfyntyMj89Q+56f0KiN067RNUTiEFys8j2U7m+5KZA8hfUjMKkUiTb7L8VuzmZbuVaFoyRf8HSRoWzgGK1LLwBR9KZ58O7osUcF9xCk5Tt8yanIEMNVxqw9fiDXcVqTfV28A+9dk4Z27kMXoQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861409; c=relaxed/simple; bh=M4sDt9QkECcSbT07XJdCv1wUJiDP78YRHjt03Sbegi4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L/B53XNLRa0zhTBuZxFOH9fH53Qs6QvdWz6Rl6BmW1B+C4ruJr2rpom/HNPsGtuvLxtINoB1OpcWR91T32NFyrAkMC2OjaRYR4HQzqdAXRr5GRnu7BxmNi/1AgBaTU3ruUtZv0q+QZ1v2r39D9hdWJHPyMb8lDg3FgcDtKw67gA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dNaqAnjf; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dNaqAnjf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861408; x=1762397408; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=M4sDt9QkECcSbT07XJdCv1wUJiDP78YRHjt03Sbegi4=; b=dNaqAnjfDLvwEbcynU4WrFQBWBSlcSuBCLnYfMal+3HEcZTnMyR6arom Mooa/3T3bfMy1KCvqOW92A2e+EEaM+kGxTyDiMk9SrvW6Tnge37Tri1r4 WZGQXRqGH9EQGcd6D/t9kNN9+rpdhMfH1uuyGUh5OeLOQc+OIQQv5ahdf wR6gvSQxTBTSG6/B9FMjvm/bMYy1ElCOvqzTdhBVyKcr5j7H3ZFtjq/wc D2jBOhBFTkHwOQvS7K+Et9r5a8Hvp0qyNSauXxjBkKIJQIbqMZ49m2MD8 KT5j7BeQ0A2C05fhhDp00yKqDKqNwuoke6aV2Y4h7OK1ANIPaCpJD7YWl w==; X-CSE-ConnectionGUID: DDuj7ppUQSC47wOA4zFSfA== X-CSE-MsgGUID: sdbvqcjYQvCemmBsW0V93A== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492279" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492279" 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 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" 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 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 = 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_HLT) -#define KVM_X86_DISABLE_EXITS_HLT KVM_X86_DISABLE_EXITS_HTL -#endif + if (disable_exits) { disable_exits &= (KVM_X86_DISABLE_EXITS_MWAIT | KVM_X86_DISABLE_EXITS_HLT | From patchwork Wed Nov 6 03:07:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13863873 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1F8518B47E for ; Wed, 6 Nov 2024 02:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861412; cv=none; b=jbxIA7abtg/kPW/K914vjcQ072kbZ1TRucVl2WKkmqf7f/JnsLQd0/+p3woR18nlNYYkGr8vJNLiIFSdKOYjwNj4lvA34dvCi5xtkr+BIkA5FFs802h+Rpdz+9BWHGt8u9WLZU4RlEZI89p3dKXvmmwdlTa8Spdl96TAFLjpe78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861412; c=relaxed/simple; bh=HwNeX5BRFdrce3Z7AoO6W2SxOR4OlRNekMyhln01fPU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QnTKmPdo9YtJCGLhowfkLWGiIofzavZ3Z2KJtq26pjy8bD8JEeS8r1Kqo+mn9A6atvc8s69PBZ4LYVXi16fgnIEZl0IzHPkOUW31u4QYZ6qhnPtc84PhIuCYa291bRqrB8vUwNwSPbhDX1WslzZYr5Pf9aSSR2GoXB5AHKoQi/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=eCJ/jQ82; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="eCJ/jQ82" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861411; x=1762397411; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HwNeX5BRFdrce3Z7AoO6W2SxOR4OlRNekMyhln01fPU=; b=eCJ/jQ826WbyN+JMnGhuPwpiJOZFnFwbAA5lUOxPegM8PU8cB/zgWBQz XaxWE11PP1tdkkzuY8kXOMscSkdBSs2A+QAECqw4c2d/ziq6MCgWM33Sq RI9P07jiuC7PVuPpQ164CXJ+gyMokXyYfuUzcON+hNxBx2y0CXHE1CdwB CXbzc9Jr5LnvzdSW+MRijYNLWEm7Y1ngiJHbsY07a4mAxwl/eXqBNmrS0 KVlJuoSDNaELxEVfhbw7hlqZK1jxhnkUxTFSdW8yhWjlCXn/cGpBc4i5i zhKK76Sy0dfgPrjbv7uAn0haTsIUIjNDriK9V5MGMWno9/UjxoQrnaM/Y w==; X-CSE-ConnectionGUID: zsKAvF7eRPW2oKl0mwUjeA== X-CSE-MsgGUID: /BH42PkkStekqWcRWIKgTw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492289" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492289" 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 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" 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 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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-guest.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) { From patchwork Wed Nov 6 03:07:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13863874 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 212EE18B47E for ; Wed, 6 Nov 2024 02:50:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861415; cv=none; b=qabGUCIiwALd1Yjl6PLY9LWh3te8AC7eCx1Z8tvGVQHgZjejtAO/SpiYcATzRhurZWqPpWrowk/dvEDcGO/QHN0UAS3o982e1SptEORVi0dCH8QqRXdZhHZLaSsMs8y8gi21o6fkyXU6yYFqTiOfoWCnPvZ6mQ84EOcTDAPajsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861415; c=relaxed/simple; bh=jFWGnz+suDCZpSQMmtwVwuQ2yns3DjY1J2pGL1AK0/Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Qioy7F4/X0vr7y81kCCJv1A2dJcbPlMBQlL02ncsxKncFnS1EduMRUZbJb/yFzHkB4ynWwJEjX1ZV4WhBR6s1x/Whby85/uZ7Z/30D4TSH6mTjNNV5Qp1eDhizcH5vcnVDVPqu47HH82wb+kCxuM68JFeQlH5SBMBcxjSTRR2gQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=iwE37OhL; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iwE37OhL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861414; x=1762397414; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jFWGnz+suDCZpSQMmtwVwuQ2yns3DjY1J2pGL1AK0/Y=; b=iwE37OhLGRrGZ8aj2/N6/wYrdtbbfHm3ZO+i2GDH02KD/KxdZTJ3LUiQ XPVN0238rmBFXr/OKRIU5revLLoc4TGbMLh+F1Jx+HlIJSVyr1y3yn6lt A86wAWDAdkgIZ1zj2zaf7vb75Fq+ysYUzL9AIeh1YniJAxq2nG1VM8Dwp uD+W+krHYozbEeQspFzcbrGyc4qyJJbLpsPAlnnD73qjCQzstfoq9sMmS r+UrtlNSxh2h2fQhj8d4zv++gCYpfhb5XHq7XmR1jACZiwUUt5cARl4Hr aqkLTiSows7Xv+IARslRlNLWhRuyOeBluUGoBwmkP5yQp5ZlLMLg4oQwo Q==; X-CSE-ConnectionGUID: SDkFoRFcRBmmpY2sYZoAPw== X-CSE-MsgGUID: ZgMk9iUXSvqguqXCkLKdoQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492300" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492300" 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 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" 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 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; static void kvm_init_msrs(X86CPU *cpu); -static bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdmsr, - QEMUWRMSRHandler *wrmsr); +static int kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdmsr, + QEMUWRMSRHandler *wrmsr); const KVMCapabilityInfo kvm_arch_required_capabilities[] = { KVM_CAP_INFO(SET_TSS_ADDR), @@ -3135,17 +3135,21 @@ static int kvm_vm_enable_notify_vmexit(KVMState *s) static int kvm_vm_enable_userspace_msr(KVMState *s) { - int ret = kvm_vm_enable_cap(s, KVM_CAP_X86_USER_SPACE_MSR, 0, - KVM_MSR_EXIT_REASON_FILTER); + int ret; + + ret = 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); } - 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 = 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); } @@ -3154,36 +3158,37 @@ static int kvm_vm_enable_userspace_msr(KVMState *s) static void kvm_vm_enable_energy_msrs(KVMState *s) { - bool r; + int ret; + if (s->msr_energy.enable == true) { - r = 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 = 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); } - r = 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 = 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); } - r = 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 = 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 = 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 = 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, struct kvm_guest_debug *dbg) } } -static bool kvm_install_msr_filters(KVMState *s) +static int kvm_install_msr_filters(KVMState *s) { uint64_t zero = 0; struct kvm_msr_filter filter = { .flags = KVM_MSR_FILTER_DEFAULT_ALLOW, }; - int r, i, j = 0; + int i, j = 0; for (i = 0; i < KVM_MSR_FILTER_MAX_RANGES; i++) { KVMMSRHandlers *handler = &msr_handlers[i]; @@ -5872,18 +5877,13 @@ static bool kvm_install_msr_filters(KVMState *s) } } - r = 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); } -static bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdmsr, - QEMUWRMSRHandler *wrmsr) +static int kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdmsr, + QEMUWRMSRHandler *wrmsr) { - int i; + int i, ret; for (i = 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 msr, QEMURDMSRHandler *rdmsr, .wrmsr = wrmsr, }; - if (!kvm_install_msr_filters(s)) { + ret = kvm_install_msr_filters(s); + if (ret) { msr_handlers[i] = (KVMMSRHandlers) { }; - return false; + return ret; } - return true; + return 0; } } - return false; + return -EINVAL; } static int kvm_handle_rdmsr(X86CPU *cpu, struct kvm_run *run) From patchwork Wed Nov 6 03:07:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13863875 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DB9118B47E for ; Wed, 6 Nov 2024 02:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861418; cv=none; b=L/HzZhN2W6OftPfjOdh2P6WSyw/wl95RZXFf4eTRMLuv19uOGlVtI2oCNB3azoxSWrbIWOoo/90q9PND3+zNXFuxZIucOZ+pANx6lwwEeGFnffEhqhZ/DLAuBfOYeWzY15Jkn9t8tUJEkDhQehHw1ZF5z4bbtlsrDPGf3Gnh0bA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861418; c=relaxed/simple; bh=W73DxTAKGKDwOxIP+UEa3mm04Ri1kkHN13Gfy8Im22A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IsFMdZfiJuNXNYOZFRHampJ8V2JMCTG6Yb5aknZduBAl9EUf7bODPL597IJkw0Jp4KAxoEjGKZqoz67Np6V6BzmwInCSnSntUu7XyeVKnYgkJ5JK+Zesi7nL3KcBWpwhWl6XI+aBQR5HdGuHleXyi3+/N8wOfE4TObX5qj0pBuk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=XAP6aoc0; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XAP6aoc0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861417; x=1762397417; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W73DxTAKGKDwOxIP+UEa3mm04Ri1kkHN13Gfy8Im22A=; b=XAP6aoc0H0Bnvw+hYVVvg+8kCcJ4Ca3+ncZlhEi8HkisVrNdsX53yKtK EVBVjLWACks8jUifb5tWEhV98VsZV0wOaFPQGzLb1Ue7ok8r4Nh1Q8n3f twHSnGHsmH605x75n/Gc9bB2IWe+cjKAF6EHqBMwmPWTK+JOuh5lNDL3Q DX0hVtupRwZJ4+WJECDwvMgXwInV7u1PjGyWIGt9KvMHOOp867A14gdei fRUkk2Mi8rmlQbrzQd70dqbAV2QpOG/cqr9CQWz3oH0yFXUAsKEYdCLBW td45hu3NPLXsmDAJHUkQESR7sO+WprQoK2AfbxZPZzpikjLsk/mOnWYXZ Q==; X-CSE-ConnectionGUID: NyKbVK0YTRyS927sBfKHFg== X-CSE-MsgGUID: 6kT8DyQ+TM+Fi2d7ieDhBw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492310" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492310" 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 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" 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 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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, MachineState *ms) { MachineClass *mc = MACHINE_GET_CLASS(ms); struct KVMMsrEnergy *r = &s->msr_energy; - int ret = 0; /* * 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 = 1; - goto out; + return -1; } if (!is_rapl_enabled()) { - ret = 1; - goto out; + return -1; } /* Retrieve the virtual topology */ @@ -2959,16 +2956,14 @@ static int kvm_msr_energy_thread_init(KVMState *s, MachineState *ms) r->host_topo.maxcpus = vmsr_get_maxcpus(); if (r->host_topo.maxcpus == 0) { error_report("host max cpus = 0"); - ret = 1; - goto out; + return -1; } /* Max number of packages on the host */ r->host_topo.maxpkgs = vmsr_get_max_physical_package(r->host_topo.maxcpus); if (r->host_topo.maxpkgs == 0) { error_report("host max pkgs = 0"); - ret = 1; - goto out; + return -1; } /* Allocate memory for each package on the host */ @@ -2980,8 +2975,7 @@ static int kvm_msr_energy_thread_init(KVMState *s, MachineState *ms) for (int i = 0; i < r->host_topo.maxpkgs; i++) { if (r->host_topo.pkg_cpu_count[i] == 0) { error_report("cpu per packages = 0 on package_%d", i); - ret = 1; - goto out; + return -1; } } @@ -2998,8 +2992,7 @@ static int kvm_msr_energy_thread_init(KVMState *s, MachineState *ms) if (s->msr_energy.sioc == NULL) { error_report("vmsr socket opening failed"); - ret = 1; - goto out; + return -1; } /* 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 == 0 || r->msr_limit == 0 || r->msr_info == 0) { error_report("can't read any virtual msr"); - ret = 1; - goto out; + return -1; } qemu_thread_create(&r->msr_thr, "kvm-msr", kvm_msr_energy_thread, s, QEMU_THREAD_JOINABLE); -out: - return ret; + return 0; } int kvm_arch_get_default_type(MachineState *ms) @@ -3327,7 +3318,9 @@ int kvm_arch_init(MachineState *ms, KVMState *s) if (s->msr_energy.enable == true) { kvm_vm_enable_energy_msrs(s); - if (kvm_msr_energy_thread_init(s, ms)) { + + ret = kvm_msr_energy_thread_init(s, ms); + if (ret < 0) { error_report("kvm : error RAPL feature requirement not met"); exit(1); } From patchwork Wed Nov 6 03:07:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13863876 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB290190462 for ; Wed, 6 Nov 2024 02:50:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861422; cv=none; b=HJF5/pA2coCnpAZlV2IsJ/iBEySvEdYEb3QulE9phr7byRSPHed84QIABxIUv+o+0pSMDFp6yP+aTBsQCjNS4pUx8XtDJkIsA4MCIPBNGHb9AG1qGtPPO2wJW6FEMVZzM2tdj5PSat/wW6YdaMvWgkaMtJqRgCkD8Vzt0CQxAzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861422; c=relaxed/simple; bh=cDyoHsWzKph1fodDMEJqXgXb9rXZ334jDEhsYTPjqKQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lhIZHPhCK4m+ix0Wz5PrNjFqtcu9vbywba+ymo0A6BedFx5mPt2oiuU4dS5DF5VQPU5X5VgWoDyDbjCG/+eFB7LdJEs3FPFTsbwlBYkEE04Jqt2xWDMeLsggmWMPBORUtlLq+lUbV5Je1FSMe2E4weJXVJSp5uOIPItSV5CdsZg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bUFWUO+q; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bUFWUO+q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861421; x=1762397421; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cDyoHsWzKph1fodDMEJqXgXb9rXZ334jDEhsYTPjqKQ=; b=bUFWUO+qyaX9INMW92NwMiGpYIEiN3icGFrR3HnABmpkzlUPV85Ug5q+ 2ss3HDThgR7XpTd8DtwW8ToC4/B8bOuqE15uM7tnTwO9f0T39en46P/zN kYIf/kH+q0mGmVXWD2nyIbO0yq0Q112pLmq6N5FFd5URHzJNqaKyCrKUu RXYvynr5s7V5rlfCeyA5rn/+AZpFdhMHapkoXn8l7KYsfA0N7ZgwIJwpp 7pSvF03oH0wR+KLKN10VeeINBMbQCY0P2LADrvVxouOvw1ci0vu1sXbGd cm1XtqEmVcvexjpbNXXMNP/Eu72P8Cc0QPc/RkmWmvQcfR99cViZpv4FK Q==; X-CSE-ConnectionGUID: SwVwo+pqTrmJJ7/LJRSvPw== X-CSE-MsgGUID: Y1uUnWMBQA+8DrhQ3yWU7w== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492320" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492320" 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 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" 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 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; } -static void kvm_vm_enable_energy_msrs(KVMState *s) +static int kvm_vm_enable_energy_msrs(KVMState *s) { int ret; @@ -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; } ret = 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; } ret = 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 = 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; } int kvm_arch_init(MachineState *ms, KVMState *s) @@ -3250,7 +3250,10 @@ int kvm_arch_init(MachineState *ms, KVMState *s) return ret; } - kvm_get_supported_feature_msrs(s); + ret = kvm_get_supported_feature_msrs(s); + if (ret < 0) { + return ret; + } uname(&utsname); lm_capable_kernel = strcmp(utsname.machine, "x86_64") == 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; } } @@ -3317,12 +3321,15 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } if (s->msr_energy.enable == true) { - kvm_vm_enable_energy_msrs(s); + ret = kvm_vm_enable_energy_msrs(s); + if (ret < 0) { + return ret; + } ret = kvm_msr_energy_thread_init(s, ms); if (ret < 0) { error_report("kvm : error RAPL feature requirement not met"); - exit(1); + return ret; } } } From patchwork Wed Nov 6 03:07:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13863877 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB35619046E for ; Wed, 6 Nov 2024 02:50:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861425; cv=none; b=EI4reBCXMWQoLhC6brTGyJYlk1xQLy2eN3pyi/eeDHvDx9D5qKev/TcLx0XfBDWZgFNT9/L5/VcHMbI1bodC7SlJC415QI0leMhkavBInSOG2TuE5/zvBZYTPAYZ+gZOp2kbQT3znY/Bqivf7UKVAq7/lSNuVeFZ6dEV5+4iQfA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730861425; c=relaxed/simple; bh=9AuyQrZYSzpVA3FJlyTq2ttbB88VVZZG/V9oVSStOkA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gBUvjU4BCAec4SsmWdQ3t3KI6DsH3cN7o9dzrFpTxt7W1JlMkKgMIISs6KB40ddtSnVi/ry1WygIz9x03OkPTIl2kt5FbXPs5gb9PTt/HsPOxD2fdlAW4LrlFpMlCgDlLzZ62V5zijDtKDc4R2smhhIquEYON0+NqRvbuZ7Oyx8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WC1x4pRt; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WC1x4pRt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730861424; x=1762397424; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9AuyQrZYSzpVA3FJlyTq2ttbB88VVZZG/V9oVSStOkA=; b=WC1x4pRtT2wYixV7DepMT15h3fVb9vrsZ8+LF7mBQ++TrdZ8xENXTBj2 wmABVCi/Cik4T7y9GE1BsoLo73tefg1u6oyuVbo6u0BZWVcfOBGmUd7u5 XacwHqbn25vEkclUMaNhK6NLOkk3A/cRC+F16DT1Bs7BA8ciA8G19SQ4l DNMZ1jmij+e/PgxeilHRcRfq2D8bdjhevE357lnG5e8LSmQDUs2acJ83E j9dBWSeufq9jvinVKAFiMQt2CUEs0mS2HORXzxTAUTn93NX32GxfObrXR FO55sWGl35E+iSbZPAhOwUy7XACA+g2ItWRufAs3a4KYPutGsV1Brezxt A==; X-CSE-ConnectionGUID: FxQOSwM0SgC8CtLvBDICmQ== X-CSE-MsgGUID: FDNMdexlTn6DSgtI3567WA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30492328" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30492328" 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 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" 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 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; - for (i = 0; i < ARRAY_SIZE(msr_handlers); i++) { + for (i = 0; i < KVM_MSR_FILTER_MAX_RANGES; i++) { if (!msr_handlers[i].msr) { msr_handlers[i] = (KVMMSRHandlers) { .msr = msr, @@ -5911,7 +5911,7 @@ static int kvm_handle_rdmsr(X86CPU *cpu, struct kvm_run *run) int i; bool r; - for (i = 0; i < ARRAY_SIZE(msr_handlers); i++) { + for (i = 0; i < KVM_MSR_FILTER_MAX_RANGES; i++) { KVMMSRHandlers *handler = &msr_handlers[i]; if (run->msr.index == handler->msr) { if (handler->rdmsr) { @@ -5931,7 +5931,7 @@ static int kvm_handle_wrmsr(X86CPU *cpu, struct kvm_run *run) int i; bool r; - for (i = 0; i < ARRAY_SIZE(msr_handlers); i++) { + for (i = 0; i < KVM_MSR_FILTER_MAX_RANGES; i++) { KVMMSRHandlers *handler = &msr_handlers[i]; if (run->msr.index == handler->msr) { if (handler->wrmsr) {