Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp341959rdh; Mon, 18 Dec 2023 23:57:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IECYUkqB8d7Y9AZw1bMzzYGC6wgCXRCjCpJzzpZ2EPT9VP/Z15zT2NB/omjqvOu2hL+kXKV X-Received: by 2002:a05:620a:13ec:b0:778:9148:3c2c with SMTP id h12-20020a05620a13ec00b0077891483c2cmr20303520qkl.18.1702972648507; Mon, 18 Dec 2023 23:57:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702972648; cv=none; d=google.com; s=arc-20160816; b=nCnOlPIfBUS3M7wRDvVDBOPoCCNJCwR0nsW+Qcyf+dlXC/hO+OSgC0FhZJ/BEyeRpV Bx31Zb1GmX/Ujiu+oFuzpGuABudZuAfor/S+CIU6ZUtkv85eV2DN7GzCFHxibjWHkG+S axIsCP71KgpAbM0ZtAVUmKeqLG/7iRaTbV9uIg5DidaxZVB8vJeZdetcKM7d8W9ROenY /YWefj7ET7RETu3KbmRJLR6maXS8o9jw/fAWRIlU64IlSBxZ7xRjxgj2tGc0LaX6ZjXM nUfl6005WTicOg/8Mikz5SPKi07xBSw3w4zkzemIsCQ7+9QLw7P7sG1XV6b/07J+alv4 mDsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=as6/xm9DsBU86oA7o9mNdgvA5gfBihtznNxmerTnb2s=; fh=Okt2uPE4POzv64FQH78lrGh2bp7fc1Z9f9o1Os9LL+s=; b=OkVm5wVYk/Ox5VO7ynx0BUhPv99BMqdI81Zkg8Dt1rVsq7rriPe2Z+mZkPRxeSJRQx 7yK2TSS1+7N0sfP8pG+xvsCgr/O4GdHKFNbE/rnrdM3CEAyz+RcOY17CYtIfqZbhQrQp CoBcWouChDxfcTGZOmYvARE1kPbEACaP0iqRd6sjDxdSnBJXLZnQNFEvRW1r4AGQ0Usm cwuYJ139JAJHj3XkvA/QMjrBkSXHwe94uuFWY+sh/tuNS+D7FlMcgSkwOYosB/zWyG6g doqt1wAMfxULDlBr3NjEG6viFEoQj1aSEzB9tZldQz+aVf8r+tlT5ugbQ0w2lY5TdLPC +YDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QggziDrV; spf=pass (google.com: domain of linux-kernel+bounces-4838-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4838-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n19-20020a0cdc93000000b0067f14fbeb3dsi9195967qvk.51.2023.12.18.23.57.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 23:57:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4838-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QggziDrV; spf=pass (google.com: domain of linux-kernel+bounces-4838-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4838-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 315BA1C238C2 for ; Tue, 19 Dec 2023 07:57:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7AA1B17988; Tue, 19 Dec 2023 07:57:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QggziDrV" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 99986168C5; Tue, 19 Dec 2023 07:56:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702972620; x=1734508620; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=7QZAN2TgmiaT+CnQk4h1E8Xg1rL7yUVfPvqjbeyoFus=; b=QggziDrVVQ+Z+U0j5+TPO8MY3DiBK+uA+QK2iOqbTQfo3GR0/fJL5aPC Ebyn4OcRP8pDB5ITetf/9nWBYHCfwLBIVDtFai+hiDJbfbWnCFshDXOPJ OWqTdml2m0O2ELCPCMsB6nMF7YD5ewp2XyOehdVzgLR2HMe6TQhd7Lcta KMQVDq1PipPtRHADQ6LiDnPM2EH8rjpw15Z2rbF++SDILFonwqoJSqbhK BYVitnb2XhSUhKXy8c/ajZOvbVXaLltnMf37jMHNWxOZT5GlPs2IZqD7r UMcgru7EbZwY8atJzlGJnko1ySzNV4u14FZ/25qoYMhEi3iyJqpU6kCi2 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="8994329" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="8994329" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 23:56:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="846252720" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="846252720" Received: from xiaoyaol-hp-g830.ccr.corp.intel.com (HELO [10.93.8.39]) ([10.93.8.39]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 23:56:55 -0800 Message-ID: Date: Tue, 19 Dec 2023 15:56:53 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/3] KVM: x86: Make the hardcoded APIC bus frequency vm variable To: Jim Mattson , Isaku Yamahata Cc: Sean Christopherson , Maxim Levitsky , isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Vishal Annapurve References: <1c12f378af7de16d7895f8badb18c3b1715e9271.1699936040.git.isaku.yamahata@intel.com> <938efd3cfcb25d828deab0cc0ba797177cc69602.camel@redhat.com> <20231219014045.GA2639779@ls.amr.corp.intel.com> Content-Language: en-US From: Xiaoyao Li In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 12/19/2023 11:53 AM, Jim Mattson wrote: > On Mon, Dec 18, 2023 at 5:40 PM Isaku Yamahata > wrote: >> >> On Thu, Dec 14, 2023 at 08:41:43AM -0800, >> Sean Christopherson wrote: >> >>> On Thu, Dec 14, 2023, Maxim Levitsky wrote: >>>> On Wed, 2023-12-13 at 15:10 -0800, Sean Christopherson wrote: >>>>> Upstream KVM's non-TDX behavior is fine, because KVM doesn't advertise support >>>>> for CPUID 0x15, i.e. doesn't announce to host userspace that it's safe to expose >>>>> CPUID 0x15 to the guest. Because TDX makes exposing CPUID 0x15 mandatory, KVM >>>>> needs to be taught to correctly emulate the guest's APIC bus frequency, a.k.a. >>>>> the TDX guest core crystal frequency of 25Mhz. >>>> >>>> I assume that TDX doesn't allow to change the CPUID 0x15 leaf. >>> >>> Correct. I meant to call that out below, but left my sentence half-finished. It >>> was supposed to say: >>> >>> I halfheartedly floated the idea of "fixing" the TDX module/architecture to either >>> use 1Ghz as the base frequency or to allow configuring the base frequency >>> advertised to the guest. >>> >>>>> I halfheartedly floated the idea of "fixing" the TDX module/architecture to either >>>>> use 1Ghz as the base frequency (off list), but it definitely isn't a hill worth >>>>> dying on since the KVM changes are relatively simple. >>>>> >>>>> https://lore.kernel.org/all/ZSnIKQ4bUavAtBz6@google.com >>>>> >>>> >>>> Best regards, >>>> Maxim Levitsky >> >> The followings are the updated version of the commit message. >> >> >> KVM: x86: Make the hardcoded APIC bus frequency VM variable >> >> The TDX architecture hard-codes the APIC bus frequency to 25MHz in the >> CPUID leaf 0x15. The >> TDX mandates it to be exposed and doesn't allow the VMM to override >> its value. The KVM APIC timer emulation hard-codes the frequency to >> 1GHz. It doesn't unconditionally enumerate it to the guest unless the >> user space VMM sets the CPUID leaf 0x15 by KVM_SET_CPUID. >> >> If the CPUID leaf 0x15 is enumerated, the guest kernel uses it as the >> APIC bus frequency. If not, the guest kernel measures the frequency >> based on other known timers like the ACPI timer or the legacy PIT. >> The TDX guest kernel gets timer interrupt more times by 1GHz / 25MHz. >> >> To ensure that the guest doesn't have a conflicting view of the APIC >> bus frequency, allow the userspace to tell KVM to use the same >> frequency that TDX mandates instead of the default 1Ghz. >> >> There are several options to address this. >> 1. Make the KVM able to configure APIC bus frequency (This patch). >> Pros: It resembles the existing hardware. The recent Intel CPUs >> adapts 25MHz. >> Cons: Require the VMM to emulate the APIC timer at 25MHz. >> 2. Make the TDX architecture enumerate CPUID 0x15 to configurable >> frequency or not enumerate it. >> Pros: Any APIC bus frequency is allowed. >> Cons: Deviation from the real hardware. >> 3. Make the TDX guest kernel use 1GHz when it's running on KVM. >> Cons: The kernel ignores CPUID leaf 0x15. > > 4. Change CPUID.15H under TDX to report the crystal clock frequency as 1 GHz. This will have an impact on TSC frequency. Core crystal clock frequency is also used to calculate TSC frequency. > Pro: This has been the virtual APIC frequency for KVM guests for 13 years. > Pro: This requires changing only one hard-coded constant in TDX. > > I see no compelling reason to complicate KVM with support for > configurable APIC frequencies, and I see no advantages to doing so. I'm wondering what's the attitude of KVM community to provide support CPUID leaf 0x15? Even KVM decides to never advertise CPUID 0x15 in GET_SUPPORTED_CPUID, hard-coded APIC frequency puts additional limitation when userspace want to emualte CPUID 0x15