Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp4117156rwe; Tue, 30 Aug 2022 05:05:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR4I+5HvDCJdFeZQqPVqq4hgVkUafjt6kJQ5xxP2aQ2wzE8pzJEknuXbBx/1q/m4t1AkNAnm X-Received: by 2002:a17:90a:e383:b0:1fd:bc7d:bf60 with SMTP id b3-20020a17090ae38300b001fdbc7dbf60mr11815252pjz.237.1661861130238; Tue, 30 Aug 2022 05:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661861130; cv=none; d=google.com; s=arc-20160816; b=iJRL7FcBpqlKcgkLLtkm1jGr7cFtEUWJdl91hUl49d/FOXQx8VOQoya+VEgvyMDtyv o9Y8UdyI6aRhEU6m6ROugqp7ORUCkQs1K0s4GBKlnniN3kQW/LP2irG1zo8tzTYNQROo E08/u6Fj2wIKDPlQf9dM+RpSmFf2y1tHxXWjpyTN3GQwa7Lud6fBI/SE4Y9k6A+Xj2sc 4R8lkceoXDFDj/H5STwREljddmKR709yCNumsXjypX4gOJcgZlIbXxP/2I466H4aJwo+ kGsR+U/1VFbQ6+azjbhhcBHBpPzJKVCWBY6fBB6la2zSg5WGydiJDYbfLnpRcH3SboFG 5ypQ== 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=EoLZj/xq1KwMNtTxvQJ05klisu+wngAkq30jVwJNupo=; b=Bn22jGqGHiXXr4xRx9UPFKwwMcC5w65G3RnWtbR38aX5aAlQ2TOk+BpVOhFN/09Ok9 0j6bMtsWR4h/k8tBblR96dfNvvwFARW1yEcoj7NyA/vLTIHoXDmfAE8gaYrYXSR1u8TB Bv3ymEmQOUuOhMrrbMmQtAn2OPE/Ilk8+k6ahUF4GOC5YVBYmz4NQF9NZ9gi8GT0jS6z 5N4DgdkbsPBMx5B+kpvvLu3ab7M9GnerrCBtSjP927rk1x+49v9xFq/PSUWTT756cJWG jcIngkr2Tnde22/KPJCeSrnyNRyaZ3HRl9fRmIfFLO5+BF300poBs7/MIm1Sm+sKtlgz xNbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fYAbcL6y; 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 u8-20020a056a00124800b0053626696747si12266228pfi.367.2022.08.30.05.05.17; Tue, 30 Aug 2022 05:05:30 -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=fYAbcL6y; 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 S230441AbiH3MCj (ORCPT + 99 others); Tue, 30 Aug 2022 08:02:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230082AbiH3MCB (ORCPT ); Tue, 30 Aug 2022 08:02:01 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06263E58B0; Tue, 30 Aug 2022 05:01:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661860919; x=1693396919; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TYBvZOLwTg/r74aw4zfac896o38NzV2pCG9Didy3epg=; b=fYAbcL6yIjnpValKDsFxEWoHtE6MOYkI7m7tfYudui6ipqNHGeTVSUPJ 0BxE+LISWMAcRZFsnfZjQnfm6+Qcr3HbPef/mDEJ1dgWuL6Z48veoN06I qyd3/4eJ4BDMk+6I/3EgUhWjH0tC237FDgNB7Hm7LFkfoC8BNs+uHn2HY 4I1qotIYKEkJhbKc4ew/vBCI+YGqsi6Vx9T35ddhLcjFGYYZrAlq2FcZe Ri6bAWPcJRl7YL9ucozITjkA5FBSUporR5U3ePHwhS1CSz6mOL/4Tvicw xbSmn+vSn8Bcp/Zhp09d8iY9duOej1pRiIHM4SBczHaCPx18WN1fbreMO A==; X-IronPort-AV: E=McAfee;i="6500,9779,10454"; a="356870970" X-IronPort-AV: E=Sophos;i="5.93,274,1654585200"; d="scan'208";a="356870970" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 05:01:57 -0700 X-IronPort-AV: E=Sophos;i="5.93,274,1654585200"; d="scan'208";a="787469634" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 05:01:57 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , Sean Christopherson , Kai Huang , Chao Gao , Will Deacon Subject: [PATCH v2 08/19] KVM: x86: Move TSC fixup logic to KVM arch resume callback Date: Tue, 30 Aug 2022 05:01:23 -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 | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ca920b6b925d..0b112cd7de58 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11831,18 +11831,30 @@ 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; + + if (kvm_arch_hardware_enable()) + return; local_tsc = rdtsc(); stable = !kvm_check_tsc_unstable(); @@ -11917,13 +11929,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