Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp221524rdh; Mon, 18 Dec 2023 17:41:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcy7F/ZrgbnEYYt1f63Ql2CGAalFYyJLPrm1RNPhwUU7eriDmVR4X/OXSNb923xDMfc/qn X-Received: by 2002:a05:6808:1441:b0:3b9:ec87:84b with SMTP id x1-20020a056808144100b003b9ec87084bmr20589548oiv.69.1702950069693; Mon, 18 Dec 2023 17:41:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702950069; cv=none; d=google.com; s=arc-20160816; b=ITLsZ6uU6PydG1Ts1UvP34ypFF9CwQXAe+WH0GYjw8U9UU1oiCyy74pA7Fz0Z4XbkY ruQVlpdoIokFOr8GsmyyVE3IXr/rygJ9NtwFsju8wjFCc5VLC6EZcKTQI+tWtYpNntGZ Ak3dbn27LVmhhyiKoN0ZXmrkLvokSYhuemIlvB4tUP/jvOiYtvlypPUHNNI+3PDYoKFl o/rmX6IfS97opriTlyZXwLnMbHT6kIpAseKSoMH1rhfILxM4I1YfY+bGsCzI3J52RCSq RNHEZYhVKbkQTZTR7p9CASPQPndgJlRZwBWRLvBbhBmhhQ2YlNxxnc615NiiK8+2bTGf UuqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=L8yVf9XNSzvgO3PfhEuyXMZ4Pby0nVVmYfYJ3eAKBAc=; fh=FKxJgM5yvt+jNVeJ6zGwEhf3RTqZlJc7k3Fo8CcyeO8=; b=B+OlLtlr8uU/lTY4IeckBTzUkHEMxkSlCKQuBO5XkUWQWL2O43lDvpSe6IGFvfXxCw O60vysxpU+HmX5/FtYZ3XqjorjLTryYT1iE7aGxPACJIjPVIH3vXwf9rxoU672hFkF6D x1aDYCSt87tNjK3sG/Z7901b0mEtoJ5OcHcvBs2ktgF/Ynh8CYUbbgkLwrCsM6qGKklF vlbAUfu7R2DtPjWEq4rL9oQ9IMySrskuwcMrcB/wa6dgdWvYMzJUEfKdM7vnNA4Wz/dG R68VG3ZlVDFjOTJD04A+CTuFUSF/U/8RuxL1PUwNXfo4B5BYVG+y9Hne3x4bmCRXEFVD aJyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nG4BN8I7; spf=pass (google.com: domain of linux-kernel+bounces-4563-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4563-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w5-20020a17090a4f4500b0028b9f6e19a5si295724pjl.17.2023.12.18.17.41.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 17:41:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4563-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nG4BN8I7; spf=pass (google.com: domain of linux-kernel+bounces-4563-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4563-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 53158286068 for ; Tue, 19 Dec 2023 01:41:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 52FB4187F; Tue, 19 Dec 2023 01:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nG4BN8I7" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) (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 432645253; Tue, 19 Dec 2023 01:40:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.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=1702950047; x=1734486047; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=j9LmI93wLucAqn3ykIcZ4njCWMyiil+5OfByZZ4Dj/Y=; b=nG4BN8I70NMVZ/QUSCBDeKkgdS+Au29Qp4XkYwg3h16dTG7hq9KKg4cd o/YKieMJVliOkxSeVJJX6nuZncu9r+RI9bV9iS/scNlbdTpn7WPhBwe2N 4JebH3XHZ9ETBxsCYsWM+V68s/9tpw700KZJ/3qSxQkBNCFRBQWpB0cGx hcmCgvfJqwaONHtWQCKPTlvdOQwynyLWZi7gdbVAmyzUeVelD/do4blKl n0yBm3Nu//DARKg1aDdob6LKmu3r4CoJ+y0qjnHDRS5mn3rKNR6moHExx bmbeOPSp2t++dXuc1f7ffoZT6o8rf2v7knnBn8qJ8OlFx3sGGMqkNRMEb A==; X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="399426475" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="399426475" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 17:40:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="919458015" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="919458015" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 17:40:46 -0800 Date: Mon, 18 Dec 2023 17:40:45 -0800 From: Isaku Yamahata To: Sean Christopherson Cc: 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 , Jim Mattson , isaku.yamahata@linux.intel.com Subject: Re: [PATCH v2 1/3] KVM: x86: Make the hardcoded APIC bus frequency vm variable Message-ID: <20231219014045.GA2639779@ls.amr.corp.intel.com> References: <1c12f378af7de16d7895f8badb18c3b1715e9271.1699936040.git.isaku.yamahata@intel.com> <938efd3cfcb25d828deab0cc0ba797177cc69602.camel@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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. -- Isaku Yamahata