From patchwork Fri Mar 29 10:19:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13610507 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 CE2C8537E8 for ; Fri, 29 Mar 2024 10:06:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711706777; cv=none; b=fBNt4IU2rOdGiFqka6SrSgHxnT+ZgzwlBKjBLoTsm2bmHhwvcgaMZutTjqWG/laMSfLihZEPnJ1DOrnOuUB96dF7f6VMXWQa5haKilfdz6DHTL6/rcAIRONxAh0eIQeTfX8+TmHdqCkQKBpfQUaqTEEd94usl33vU0MO/jsnxl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711706777; c=relaxed/simple; bh=YsoWb/M4LNq8Md17vTgsxsQeQ69Hei3aqAO+226S55Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LAQiGZSt0S6eJUosK7GGJHC3X8i3FXgUhNriAmk7uVwt26DPGg/zkJygiy1q6DJTOYuaXmvcvv7kCmUMMltUve+GTQKdeT7IeKzpTNVUlKpfMBvic5USfLZnQQMPtGPY++DCIEjXTVWA+7vK9Wm0x3314OdRl7npMZdIgYgcx94= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=UxOFBa91; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UxOFBa91" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711706776; x=1743242776; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YsoWb/M4LNq8Md17vTgsxsQeQ69Hei3aqAO+226S55Q=; b=UxOFBa91cKn69ER6G2ZBRRM++Zl0bPugL9BJba9cKqs2xFTec+y69J6q 0z2uIJo8uKdycci1j2xjcoDE3fIkmCgmOLgQ6TE3mgpTEIJ6zA6onOw0y AYLYn8ndnzfp/ZDT8GnP9USTgf+OcKf5KuPC9N+e7hcashsr73wKOgQuI /Vy6pUKBGIw1avYx7oZ4KNE2sC024zQ6IYldaaGZA9rrIqyviithoDPxV xA8YqmKsRN2E/wQPaYeRBvxANZg9EfckqklT/7qEHAEfhiQVCFgnTj8UX oZcOPZ6AfDMiboe0pLgjv2QAsBLCAynmCqyNAQIlealc9oA3A/VbkUp4g w==; X-CSE-ConnectionGUID: stenhHcwS9KTxwCo0pyh2Q== X-CSE-MsgGUID: yuSpKrRRQUC1RrMBZLEPEg== X-IronPort-AV: E=McAfee;i="6600,9927,11027"; a="17519217" X-IronPort-AV: E=Sophos;i="6.07,164,1708416000"; d="scan'208";a="17519217" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2024 03:06:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,164,1708416000"; d="scan'208";a="21441971" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa003.fm.intel.com with ESMTP; 29 Mar 2024 03:06:13 -0700 From: Zhao Liu To: Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S . Tsirkin" , Marcel Apfelbaum , Marcelo Tosatti , Igor Mammedov , Tim Wiederhake Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu Subject: [PATCH for-9.1 3/7] target/i386/kvm: Only Save/load kvmclock MSRs when kvmclock enabled Date: Fri, 29 Mar 2024 18:19:50 +0800 Message-Id: <20240329101954.3954987-4-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240329101954.3954987-1-zhao1.liu@linux.intel.com> References: <20240329101954.3954987-1-zhao1.liu@linux.intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zhao Liu 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 --- 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 be88339fb8bd..498580d60c3b 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3319,8 +3319,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_FEAT_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_FEAT_KVM_ASYNCPF_INT) { kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_INT, env->async_pf_int_msr); } @@ -3784,8 +3786,10 @@ static int kvm_get_msrs(X86CPU *cpu) kvm_msr_entry_add(cpu, MSR_LSTAR, 0); } #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_FEAT_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_FEAT_KVM_ASYNCPF_INT) { kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_INT, 0); }