Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1276568rwn; Thu, 8 Sep 2022 16:51:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR77Sqyyyu04BNG7wvSzBgFzV4zEhKDlH3zJnGLgwhcYA2RWqiHenPDcNTQzMx1roePH9Fku X-Received: by 2002:a05:6512:2293:b0:492:f04f:2ff9 with SMTP id f19-20020a056512229300b00492f04f2ff9mr3344811lfu.95.1662681100278; Thu, 08 Sep 2022 16:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662681100; cv=none; d=google.com; s=arc-20160816; b=EOtCykZm6+QNUslBHjHDtcwTI8AxHf7Z96i8HCQCKHMUGbBUUkFH6dgMfYUcnfYccJ bKWSvTGZ+7t/Ma1NnH+BXEotWUM2kfALoaA8GlJWnNmMvs3OEw3f8oJ9nAYlwqNhqWfR R202fhmJbaKIzIvP0D14edH6tz//+J3QokgG+RrHvpi2wLfaVrkczzYPsZdyWgE5ivDQ QN5ZBnyCiy66+a8nG8f45EOFizPqHulgXEAAA1TdwK2EttJ21cj0sMupsMgBU25lCKq6 GNeHVKwsiqzsCHK5otRUA9oMEipS2Qda7Ghr3uzNgw7SaDPS65+LT7nzbwHf0bAXf2SO ngfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=U2Jji82VXzDLNPpBdoJE0x6ao5LY6go0L+djklq/U1M=; b=YC/gHEMmW0QZRF0NuQEdtqevoMzjLTES2Y1fymgHwbde2UTzEZ/J2VvO0D9gOHER4d jkGJF9FKY75dFXwF8Tav2wvC5BcomjYFX6LaIXPBe5D3ptpFTTHRa9n38ABHQVzwURvZ oPSHAtkYsDXvSsjRVj2KMobdSXEvFkmrA5OTy3J3ww4EE0x2/LAjx2JcaMTyV859Ms6o C4XVRe2QsmAJYqAH1AdyXx9DCbWhWtddbL0/QMMukHtPQDLPP5YjiEM+WvPLSuGmDbeY S9VUxvtT+lbnRDjPCPUXkgdj+qCBTXTQn/nlt6rztzhzpz2BsxaqBLWkbl4odaAOyQv+ +e5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k2SMx2mH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k26-20020a2ea27a000000b00265d1db2af4si86433ljm.601.2022.09.08.16.51.10; Thu, 08 Sep 2022 16:51:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k2SMx2mH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230119AbiIHX1H (ORCPT + 99 others); Thu, 8 Sep 2022 19:27:07 -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: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); 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 = 0; bool stable, backwards_tsc = false; - ret = static_call(kvm_x86_hardware_enable)(); - if (ret != 0) - return ret; + if (!usage_count) + return; local_tsc = rdtsc(); stable = !kvm_check_tsc_unstable(); @@ -11921,13 +11930,6 @@ int kvm_arch_hardware_enable(void) } } - return 0; -} - -void kvm_arch_hardware_disable(void) -{ - static_call(kvm_x86_hardware_disable)(); - drop_user_return_notifiers(); } static inline void kvm_ops_update(struct kvm_x86_init_ops *ops) -- 2.25.1