Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp95094rwa; Fri, 19 Aug 2022 23:16:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR5z5ID7p9unsqLB/QjE9mB3Os6T0nA59QNazFlYuqrshbjVZ9Iazw4C7SUshmipIvaWgp2k X-Received: by 2002:a17:903:2443:b0:172:d2a2:b8c7 with SMTP id l3-20020a170903244300b00172d2a2b8c7mr1324763pls.148.1660976198468; Fri, 19 Aug 2022 23:16:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660976198; cv=none; d=google.com; s=arc-20160816; b=a/g1AeTHN4DePdqfEmVH6yufR1O1LEcwKf8Y/PtJ/8ASa1gastwOVfjl6pkxPoszne Y7x8AAPD9qzAvSLxdn3QAUAi1gtCREMFqOX+X2Joz0WQPrv5krP9Plnul6sEoQx6vq6N UQxnpw+GTjCP/sH4YsIiAUUgq8Oh7OCmJZRFFZRzvdaMo08VbZiQNGrDbKT2NeGPfB8J QbNDE5IqUzMFE/oX8s/RzK3ZYOQy1PPHRVakK2RmTxCq5Nf6LuZdflI4i46/Wkpg+B2t B80CwlKqH74etYwnL85DS07QoUYQFre8UVhCHiiWL5zqdZLgOnilaTaG+u7u55or2Oha e/gQ== 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=bmoBMdxUl/xYa7dJ6qxlGoIrZk/YUi6U9yhuurz8Org=; b=V9izwhakMUQHxVdmk2CAahzpqV3jaHYTaJnZ6dkhNC1r86pySVeEjbyvGPHBVw9Y6/ +d7ZPX9WkDVt1W7ueDkleaBWsP4qWvHhSkd+HEoDxYBJ+6o9JyfDN7+Zzz8sYrpPZFG9 lWzJeCvenlxcwYta9B08CfpL6kVNTLjHBhAbRH5xrcCjfTa2NCK7Go/nAD2jXJle+avJ bif6qL0dnU3gjdhm2XzAWbHD8+6TF4KvPU9yPZ+SVOqOUMiDYCirT3Jsg9z3adjZuXGZ pD2ETDcyw95+0G/T/SWt4YrZoNv1ON/+zvuXa3FU61xIXnzx+Pps1uINjDNLggYZmLTe h6Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ftFa88Zb; 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 nl7-20020a17090b384700b001f30b528291si7327523pjb.168.2022.08.19.23.16.26; Fri, 19 Aug 2022 23:16:38 -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=ftFa88Zb; 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 S245179AbiHTGBJ (ORCPT + 99 others); Sat, 20 Aug 2022 02:01:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244300AbiHTGAv (ORCPT ); Sat, 20 Aug 2022 02:00:51 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B41C6A260F; Fri, 19 Aug 2022 23:00:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660975250; x=1692511250; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eC/FmkI+0wbcW1yT5moTG/B/uNqw/iJshQXbZJpzhw4=; b=ftFa88ZbGO4NSyQwP1KWpSeFyG3MJeaPvGEFqXN0AnZEBZlvd28jLewq kWr6xahh1wFpYcsgN2inaj0v6Xl9sRTtJM8OEYbsv8xHMz4hRvcM+Al1S O9AnFC/LaS04deRYInNN6r92Oit4BS8Ku57JREYLT9KRyznnMUkHENo7M dJu/KRpYppwSvYioyMEB+DhaGAiDIaoT5jaQP66sP0PZx7jbHzq7ldZvH j/YosBRB/5YHG4eO1R8m8WLT81NjIxEqFb1iXZYqLaMccZW43MEwPQTIc fbnYmYlo2+U6A3kd07srb8BaQ1cEMw+HvIn+hAeHeQZxGu3wGivEEAwo8 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10444"; a="379448971" X-IronPort-AV: E=Sophos;i="5.93,250,1654585200"; d="scan'208";a="379448971" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2022 23:00:49 -0700 X-IronPort-AV: E=Sophos;i="5.93,250,1654585200"; d="scan'208";a="668857524" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2022 23:00:49 -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: [RFC PATCH 05/18] KVM: x86: Move TSC fixup logic to KVM arch resume callback Date: Fri, 19 Aug 2022 23:00:11 -0700 Message-Id: <054173a5afbcc79e596dbcdac32588bf9a2242e4.1660974106.git.isaku.yamahata@intel.com> 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 7d5fff68befe..a7ab9984a236 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