From nobody Mon Apr 6 09:43:47 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 438F8C54EE9 for ; Thu, 8 Sep 2022 23:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229835AbiIHX1I (ORCPT ); Thu, 8 Sep 2022 19:27:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230130AbiIHX03 (ORCPT ); Thu, 8 Sep 2022 19:26:29 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C233EB86B; Thu, 8 Sep 2022 16:26:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662679571; x=1694215571; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eur7y1TP4jtJja2EWabGmkXbvuvmmXATztvuUODFrLI=; b=k2SMx2mHMicYKuB5K++kgYLoqIHX2PtE3wbizs1NyzwKNq6U9HyG46WU 5qwrugBIStCqYs//sQktCOUeAuVNu5NHbHFsKfouyfKOL2dSkwMj6TEWV 28wuZuysWyTw/+IRRqgUU/Ili9U8ivCgDsrS5eb+DEHkONPnZCntqfLFS 7W3TrVkPLaRL17ArP4CArvFZ48Gv7TH1HUlknntRMpkaq8HGdFVkKXWS/ tR0FDcwQMS3yy5hK1ccCXgdRR3trzLp1HpfBs/NPGgk3oFCJ9fEYfzDRN F6NKBfnrxIy3d2QhLz87uQnWTBYBlpfHBTvVFd0vGZca+9JdkTocabZpX Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10464"; a="298687004" X-IronPort-AV: E=Sophos;i="5.93,300,1654585200"; d="scan'208";a="298687004" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2022 16:26:09 -0700 X-IronPort-AV: E=Sophos;i="5.93,300,1654585200"; d="scan'208";a="610863208" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2022 16:26:09 -0700 From: isaku.yamahata@intel.com To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Marc Zyngier , Will Deacon , Yuan Yao Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Kai Huang , Chao Gao , Atish Patra , Shaokun Zhang , Qi Liu , John Garry , Daniel Lezcano , Huang Ying , Huacai Chen Subject: [PATCH v4 12/26] KVM: x86: Move TSC fixup logic to KVM arch resume callback Date: Thu, 8 Sep 2022 16:25:28 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata commit 0dd6a6edb012 ("KVM: Dont mark TSC unstable due to S4 suspend") made use of kvm_arch_hardware_enable() callback to detect that TSC goes backward due to S4 suspend. It has to check it only when resuming from S4. Not every time virtualization hardware ennoblement. Move the logic to kvm_arch_resume() callback. Suggested-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/kvm/x86.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0ab8db07fa0e..c733f65aaf3c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11835,18 +11835,27 @@ void kvm_vcpu_deliver_sipi_vector(struct kvm_vcpu= *vcpu, u8 vector) EXPORT_SYMBOL_GPL(kvm_vcpu_deliver_sipi_vector); =20 int kvm_arch_hardware_enable(void) +{ + return static_call(kvm_x86_hardware_enable)(); +} + +void kvm_arch_hardware_disable(void) +{ + static_call(kvm_x86_hardware_disable)(); + drop_user_return_notifiers(); +} + +void kvm_arch_resume(int usage_count) { struct kvm *kvm; struct kvm_vcpu *vcpu; unsigned long i; - int ret; u64 local_tsc; u64 max_tsc =3D 0; bool stable, backwards_tsc =3D false; =20 - ret =3D static_call(kvm_x86_hardware_enable)(); - if (ret !=3D 0) - return ret; + if (!usage_count) + return; =20 local_tsc =3D rdtsc(); stable =3D !kvm_check_tsc_unstable(); @@ -11921,13 +11930,6 @@ int kvm_arch_hardware_enable(void) } =20 } - return 0; -} - -void kvm_arch_hardware_disable(void) -{ - static_call(kvm_x86_hardware_disable)(); - drop_user_return_notifiers(); } =20 static inline void kvm_ops_update(struct kvm_x86_init_ops *ops) --=20 2.25.1