Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1260953rwb; Thu, 22 Sep 2022 12:22:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7SUoMMKCu3Pgki8mnvJ7DZediy6+uoBIQKdlV7tqy6n1+Pk2Yz7D3MD8ySUFdsaSsVkLF7 X-Received: by 2002:a17:907:2c4b:b0:77e:2c09:4111 with SMTP id hf11-20020a1709072c4b00b0077e2c094111mr4338243ejc.21.1663874539535; Thu, 22 Sep 2022 12:22:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663874539; cv=none; d=google.com; s=arc-20160816; b=LcsOT65mlVbsM7kY87aH6TA4bTDjpipcpOMVFimZieshk4lAErJ3iukrjZVDhw7wzp WkotQdR7dMDA9wxR2V7HGO18wqVwgTYukzraiNrcUrI+CuTH4htZ9JmiIVFkB2vnBoGA KvmDoTDOGSDmMFp4tBnQ6m5aiWynUWcB4U1pwJBonlMU15jzLXX8sJQW7imsOHGZIksn ZFpKDsmKYKKhR4McwqaqBfLzrR4W5NVBGcpMm+w81Dek/JIFEL/ix4P1/Qdn1QJ6oLCR ZNDoa2zwGrVeEEv6hQHKxLYYLhv/rLi77SnWCdB7tYRWBADDBWk9BeNe2eC8lPf1JrJm bD4w== 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=GTfqVnV2CXNRed0W4lXd2j2u0k0vYfzMmZiI3TdBrqA=; b=xkBC410a1a9RglMCOYMvxBzoZhY0MAADlhpB/tJMS1C8fBnm9ZbE1CVxqRPzYpVwM6 PjXt9oHk/207DKqb5yvRP5UDrPvBX1mWeKl8njN3ddPJ+oqcVLf4wfiuVO48gTyJOnVi XScL3q46+2GZfOY3m5MFIucSR670FP9vl2gpoFTW6o+I/z/GwZy/+N8iTK610qlAGGYb TL9B8FD+n3lNCMkvFC1bIFATSqIO4AGqNWsSpahe/qUpPMc5JJxmYKEdfIKjrbKtyanY UfXISjgbgFzZYyGWVLXgCyx+tJdmogWzaIljxz3rTmsjPO7Z21Vd+laC88hBjAKhS2Mp g1HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fLJleE3r; 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 cs17-20020a170906dc9100b0077e9417b5a7si5623826ejc.938.2022.09.22.12.21.53; Thu, 22 Sep 2022 12:22:19 -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=fLJleE3r; 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 S232603AbiIVSYB (ORCPT + 99 others); Thu, 22 Sep 2022 14:24:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232568AbiIVSX0 (ORCPT ); Thu, 22 Sep 2022 14:23:26 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EF1C10C79B; Thu, 22 Sep 2022 11:22:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663870939; x=1695406939; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QeHsRbI/skAm2S/DEhUEl4+spTF4gixFEqyGdTM2YXs=; b=fLJleE3rXocP3njQo2mbZzCfiXaEnLrrsd16DIvIrGqcJPVYfJq069b+ hcnnNBVwWBeQcUB41mherMtwIbLUkwij1TwpVdA5rJUEkTjdUsemO9uXb QQ68iCHeWgaUd0v+r6/3i6T4f6oeDssLVRI4+Dn2IG5fdzeIuGTVg3JBJ UDTU9oocbYm+4/KOVThCOlvgkwiX6TA3PKEMPjuil+/Zuk5QKa89xaNrT ucy+MnCXEKrL+c3bggX9TWOxv5wLeDYRYtY726mph0CY4Cy34sDU5xocW hibDnuSofUMYQ1lndA7q1hPxb0WyPBSF4XTx25GsV+WZvVzCycg2tuWPd Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10478"; a="326712916" X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="326712916" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 11:21:25 -0700 X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="653086819" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 11:21:25 -0700 From: isaku.yamahata@intel.com To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Thomas Gleixner , Marc Zyngier , Will Deacon Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Kai Huang , Chao Gao , Atish Patra , Shaokun Zhang , Daniel Lezcano , Huang Ying , Huacai Chen , Dave Hansen , Borislav Petkov Subject: [PATCH v5 22/30] KVM: x86: Move TSC fixup logic to KVM arch resume callback Date: Thu, 22 Sep 2022 11:20:51 -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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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 | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b15eb59096b6..d49396bb6c2e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11865,18 +11865,26 @@ 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)(); +} + +static int __hardware_enable(void); + +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 (__hardware_enable()) + return; local_tsc = rdtsc(); stable = !kvm_check_tsc_unstable(); @@ -11951,7 +11959,6 @@ int kvm_arch_hardware_enable(void) } } - return 0; } void kvm_arch_hardware_disable(void) @@ -12115,12 +12122,6 @@ int kvm_arch_suspend(int usage_count) return 0; } -void kvm_arch_resume(int usage_count) -{ - if (usage_count) - (void)__hardware_enable(); -} - static inline void kvm_ops_update(struct kvm_x86_init_ops *ops) { memcpy(&kvm_x86_ops, ops->runtime_ops, sizeof(kvm_x86_ops)); -- 2.25.1