Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp356382lqa; Sat, 27 Apr 2024 05:26:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWBe1TuFQ0ajrjEpX/dtSsemkJuZB4xfhpThTgvzM1qSHpn9Fr8R0z6Xx7k9+66YPz5IH+mbWF39l+z97b4lWY6zBsHN83+G9WsMcLeYw== X-Google-Smtp-Source: AGHT+IHfJalUmfE9Nb51ckMi8aqnB/qdPmjayvaYp4O9tdA2BccKp62GnwaYimpHN/2XlX+mxBzJ X-Received: by 2002:a05:6a00:3a12:b0:6ed:7684:484b with SMTP id fj18-20020a056a003a1200b006ed7684484bmr5728700pfb.27.1714220783281; Sat, 27 Apr 2024 05:26:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714220783; cv=pass; d=google.com; s=arc-20160816; b=NPZ9oFeu9v5Hgm5Mv+aEKLzlm7+AUjaTdc7BEyLGUIivgQ4n1PG3Ba67Dv0TKKIIyd QBEuXUW0E+26UFay2RQeJaq1L4Jv0CGKMZNJraWgS6jddLtiZoK+Uz3zF3NwPkczrwuV s/ELJmpT4wzwdXCThstKgJU1fV+G0sERBnpLjDCNDIogAym3EfdPflUE55tHwi/8LIRS vnpZcHnIZF3gIhSXfmMitdCg6DfG09eUJKElNh934HuFkeAEFPB+i8ZYyBRM5JUjU+wj shbb4boRacMoOsdi+P2AUV3wJNl9wRlYnf4uw6pdoin9ylodhC7Q5+5wlo6lo8Sm3WvO vFWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vQRg8jTSE/w84X85rubENd1tTskSzNXDiSVdMmVU2k0=; fh=GxGcIBasQq2Gc/176mTrpEex7eS1coPy2FlYCD7Qc50=; b=tp4+cHVRuVNWex9hDapNvcVQjWoVTWdGHQyTHBAApMXzBNyBWfwocQ8JWJB7EtqpuC B5r6Rx+e5Bjd3gOx5yOni7/5oNhOtwXrDApDv72HcW1fCNTfcZqka9vSrnKaUGMRCbDY 7f4kw1zYzEaqHPoJ9BkwDCRByp4C+S8IpCCdK5R6F7whIExVIUcTExpv7ND0pPzGYbQh mJrJdHNAh883fcVm/WB7GNJLbNMeQRSQEEgK5/mnASlI5yrEjJnIYOrwUndhg5ejN4RL CbLvzVG1BdQhZv9OzTAyty7m5qbLocLV8mgZrAzYtFBxwLIpu+hWFKhDefUPzioETo1h MKeA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=cmn7aYhf; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-161016-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161016-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id w1-20020a654101000000b005cf94b8d9ddsi17023616pgp.869.2024.04.27.05.26.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Apr 2024 05:26:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-161016-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=cmn7aYhf; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-161016-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161016-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9205EB21857 for ; Sat, 27 Apr 2024 11:19:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A78224D58E; Sat, 27 Apr 2024 11:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="cmn7aYhf" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2C55495CC; Sat, 27 Apr 2024 11:19:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714216785; cv=none; b=ey8EDXetESwbmn18W6XLAzijjbV4KnTWXB5Aet5A9a2P+8A3Fr4xIhcMBw8TjI6SYmp3zMtdsJkdiX1Iazx7WxiNi7ATUV8n1gH+1SXu1vIiHjszF24PMU8Biaqvo0c9DAIpmeP9e674NPjQOCHvRs4jJEi2xdReKy4ajT7FS4c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714216785; c=relaxed/simple; bh=iOmvqV+vbYDKZG4Z0hPkoNLgaOP2tzUKcwotb2WDGfA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nrfr90tgWZdeM2481wSJT4veZnljYL3vuAX0oqGzn7hVc/cg+U1ySGa27ajsTEZy0CqhcGYUJgHIzFOL8jT0IVZcX7PJ+IHEdpIRCx4kdB/F4lGM7jxEzZTpkNxQv/lufRdsNIRXHnXVxYoSt8KSRjUHO415ZeEiYrHefyge2so= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=casper.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=cmn7aYhf; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=casper.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=vQRg8jTSE/w84X85rubENd1tTskSzNXDiSVdMmVU2k0=; b=cmn7aYhfwh7DslkWnh5DqUZEIx j9fX5K6GH0V9zbxwMg3+0ZIl9hHP+KQ/z/B9Zv/oQRJg/gjuQlViVmqmce4HtfXOe0GtacMer0Vzk ES7aVffN34pEVqZkTxXUuvI5QTx1wLclppF/bBswcoiRkHXhVTE1vKS1ZpKfSIAki1+2o9lp6Z8Cs pS2/wSeYj7ddIwxXXJnQzFI+HUTvkJi9QDt/9dr1yQ4mkIPAmGGaNVt/LlSWXd+cN7NZp3bIkzNnr T0gUJY0VuLBoesPKzPyxKkz35NojO96EiIEIzm2ONrbz1Fp0RiCYAfXCBOXkHblB2MhnbJpKQWrGL x90YaXoQ==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s0g5g-00000007Jwj-2Dkw; Sat, 27 Apr 2024 11:19:37 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1s0g5g-000000002bJ-0XQk; Sat, 27 Apr 2024 12:19:36 +0100 From: David Woodhouse To: kvm@vger.kernel.org Cc: Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Paul Durrant , Shuah Khan , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Oliver Upton , Marcelo Tosatti , jalliste@amazon.co.uk, sveith@amazon.de, zide.chen@intel.com, Dongli Zhang Subject: [PATCH v2 05/15] KVM: x86: Explicitly disable TSC scaling without CONSTANT_TSC Date: Sat, 27 Apr 2024 12:05:02 +0100 Message-ID: <20240427111929.9600-6-dwmw2@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240427111929.9600-1-dwmw2@infradead.org> References: <20240427111929.9600-1-dwmw2@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html From: David Woodhouse KVM does make an attempt to cope with non-constant TSC, and has notifiers to handle host TSC frequency changes. However, it *only* adjusts the KVM clock, and doesn't adjust TSC frequency scaling when the host changes. This is presumably because non-constant TSCs were fixed in hardware long before TSC scaling was implemented, so there should never be real CPUs which have TSC scaling but *not* CONSTANT_TSC. Such a combination could potentially happen in some odd L1 nesting environment, but it isn't worth trying to support it. Just make the dependency explicit. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- arch/x86/kvm/svm/svm.c | 3 ++- arch/x86/kvm/vmx/vmx.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 0f3b59da0d4a..4d3ec1c3231e 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -5202,7 +5202,8 @@ static __init int svm_hardware_setup(void) kvm_enable_efer_bits(EFER_FFXSR); if (tsc_scaling) { - if (!boot_cpu_has(X86_FEATURE_TSCRATEMSR)) { + if (!boot_cpu_has(X86_FEATURE_TSCRATEMSR) || + !boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) { tsc_scaling = false; } else { pr_info("TSC scaling supported\n"); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 6780313914f8..bee830adf744 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -8428,7 +8428,7 @@ __init int vmx_hardware_setup(void) if (!enable_apicv || !cpu_has_vmx_ipiv()) enable_ipiv = false; - if (cpu_has_vmx_tsc_scaling()) + if (cpu_has_vmx_tsc_scaling() && boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) kvm_caps.has_tsc_control = true; kvm_caps.max_tsc_scaling_ratio = KVM_VMX_TSC_MULTIPLIER_MAX; -- 2.44.0