From patchwork Fri Apr 26 10:07:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13644486 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 2FDE213C9A7 for ; Fri, 26 Apr 2024 09:53:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714125202; cv=none; b=X0EQ75ZiG+o8sOkf4t++KPJiax0HOe54a3ajI+PcLQfxfM4++mJvMkdsmuyAbv54t9HsSXh+u05H/Sfglido3cKLxw0j3UqAtjpGf5RiWwcpc8rQfknjCoZ7AWvTeWN4iAkdtw/Uo7H4i4jPEIaogsdNX7vy28OtiuwINiXrDpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714125202; c=relaxed/simple; bh=qijGxXFvV8iZRXcREWHGG85ad89+AhgWWgpYseJlNhg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iomFMACYZlYc9f6P37prCGYaUfSxo8rpYE51zYzBzS78AVWxjLsRUWL0FNKiB+ISxIXnllDve/hFMac5sDaneywEbJrsz6kaaLWpKlFKuUK9pzgPW9Cw6SU19LRbFE5vE2z9qN/5TPJ6droYQpq5lusvFxjvMmXTT0mQ1PyAx/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=cHidUfap; arc=none smtp.client-ip=192.198.163.18 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="cHidUfap" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714125201; x=1745661201; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qijGxXFvV8iZRXcREWHGG85ad89+AhgWWgpYseJlNhg=; b=cHidUfapHbdsxs+uvUmLJzKHV5SnEIhIHQsJ9g//RKvEbts5hyCBryxw KYAVDWVJqH95CNUwY15gpZqzMgZhimbE1mf/PaQlM44k6vB4J+D0F7HJi tduftF1cHCDnFlRpB6gtt+nTvcc80nsyL2mlcZtaZzpP4hRPIMvxLdlp8 mB9y/ud1eEeMazA5LTvGTI6UcULRTrb1MR7RqjBOdDB9dNUPf1TPP7D2O mVfUXXFvV2kk8vOLa6Lhn2I81MG0+lwVWSYrO/rHFJLcZ9/XPc703bTrn xBWQmPhGRmMEQRsUsXzZ+c2PalWmEUKQuKLIRa1DCPF5PDK569lTPZFRn Q==; X-CSE-ConnectionGUID: GGBij42aRgCcxeP07bJ1gQ== X-CSE-MsgGUID: bRFI0QHGRYOVOi7/6+42jA== X-IronPort-AV: E=McAfee;i="6600,9927,11055"; a="9707414" X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="9707414" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2024 02:53:21 -0700 X-CSE-ConnectionGUID: LD77/FKTQr2Z/8ciWMY+UQ== X-CSE-MsgGUID: g1IuyKSmQXmpL7xat0jwpQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="25412325" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa008.fm.intel.com with ESMTP; 26 Apr 2024 02:53:19 -0700 From: Zhao Liu To: Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S . Tsirkin" , Marcel Apfelbaum , Marcelo Tosatti Cc: Xiaoyao Li , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu Subject: [PATCH 3/6] target/i386/kvm: Only Save/load kvmclock MSRs when kvmclock enabled Date: Fri, 26 Apr 2024 18:07:12 +0800 Message-Id: <20240426100716.2111688-4-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240426100716.2111688-1-zhao1.liu@intel.com> References: <20240426100716.2111688-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 --- 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 b2c52ec9561f..75d2091c4f8c 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3372,8 +3372,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); } @@ -3837,8 +3839,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_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); }