Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp264067rdh; Mon, 18 Dec 2023 19:54:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEV66zcphmJV+Q/1I0kSsW+16bV0/E0KknPfPI3puvYzGEl1Sv0NOTykZppoJftydTQ3KP6 X-Received: by 2002:a05:6808:17a7:b0:3b8:b365:1e34 with SMTP id bg39-20020a05680817a700b003b8b3651e34mr21248105oib.33.1702958055323; Mon, 18 Dec 2023 19:54:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702958055; cv=none; d=google.com; s=arc-20160816; b=W8cG4fHbaQ9alNn1VYmSZ+GvXZYRIqunNOUcEnHO1cHH1B82BsVC+/9QkN+JAkdZa+ NGJgRpkd4jXsC4rTzXqiqQRn5jBYjIEU7uQsxHVkQ95T5+5/MbWcD9XFF8CllQKRlvtX HK/AzZy1uAJtOwOWUyohT/COtYSpB2BRMKkBCS5dqx0l3Wj5Nb3vmRo40X5fW1Rm+ie0 hyEnkVxuY/AUFHIMSRbFJeGXPcX7K32NOmo7wtctyFG5Sdm9BLMbkzgUhNZ9vHq1JF3T C0cvO6EPcTXIF8Bcvc4PzAWoJpbFY8thkpwjDkfO8bW/WP/mtLkdROpvXblx+MgaMtUT NAYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=Iy2IztVRXYniuUXW1tQyYprWZIpRHnU4kupTPbOUIiw=; fh=S++EKm+pOt+PHowXDgOck3Fso9pN06Nc0poTooMkWY0=; b=ry9yw1LitC4HnAy3ZOSRwAgGHAKtXUaXLqdEjVSbQaKapM86EG2W4PL2tciGDVGFai VLwd49tFSjNsD0w8Xr+CjHBKN1e1m6dXyL3tvErBzDAPiI90DKLEHEGmhzbnvXk9VCre iIhizb6/0lPdbQj4Efnbw3v6tuJAmA+DxnjTg96M8tAtdzdobpK1Q8HHDKgsDkd4hz/H crZ4FTRDdj1Uluk2OiED3WHTbrvTVnVQ6cEPLjNqm3kWUoW/YODhEdSR9WNaXQ5JcPLu rhYl0RLjPfkord6WulixaJfNfTvXTkWLmVfArPJimBJ3qNE3/YlrxMp9vnygIAiHaddw BQbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="D/4OGzgJ"; spf=pass (google.com: domain of linux-kernel+bounces-4653-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4653-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y16-20020a056a00191000b006d7cdae2bcesi2640030pfi.378.2023.12.18.19.54.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 19:54:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4653-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="D/4OGzgJ"; spf=pass (google.com: domain of linux-kernel+bounces-4653-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4653-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 103BBB241B0 for ; Tue, 19 Dec 2023 03:54:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2FD14C131; Tue, 19 Dec 2023 03:54:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="D/4OGzgJ" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBC24BE59 for ; Tue, 19 Dec 2023 03:54:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5534180f0e9so5142a12.1 for ; Mon, 18 Dec 2023 19:54:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702958041; x=1703562841; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Iy2IztVRXYniuUXW1tQyYprWZIpRHnU4kupTPbOUIiw=; b=D/4OGzgJRuH+EmHhahDvvXm14xPv9IC6beccImb1Y4tsPaaBu3+4RzhVMXcqQHW/U+ AJSugPHkTOX9derzmCWhqaYpFw4OEf0/WuORGH+CTE/l7mrOzSABpzNy3JwfXE7++X9b r0c6ZnbMQOsqJ0ASWdZ9sHF0gRHDPbJPtRbrUfWst25Al+1tbCtE5BpdtCsk52vQ8/eW vUi/A0NPE33p5OJUYtFnNrlI0k/7LwNmEupWI7Eyi7e7XvpynqxxqSulQgZFqMl59jHc Mdn7eJO+sgzE2sBD2ri0p2yDuRafiOZKQbmjHLihfRWqnFO9OdBk+xr31EjlulP73wN/ 8Qxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702958041; x=1703562841; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Iy2IztVRXYniuUXW1tQyYprWZIpRHnU4kupTPbOUIiw=; b=DxIcNXgq3bAOFuZs/01VYc9PwmDsg6NL3DRruFJrxCPZRzlcg39cUYcmkZZwG88z1z X2kPT7bn4T8aojeAfM0uLNQOs4jXmUZ003k6HDNY9iNO7rt2NkTTWJxZF+c0c+Z0oWUR af0Dt14ZK5g5QPAH4NZ/pwCu6HsJb+SCxb8p9RjzHI9eS7EnxF5iyDsHrMdBP5IdZ6ig yY8IBh1MaOYvaRchPUbzZPk56nrVOghaxdfxvCzW472uMnNUKJ2UgsVLFWW3/i1ECCJE HKc4/umn/HdVcjfkvEPYAfXxoco+KA2tnM5ff0PtFyIrIjlqkbgpu5cqoroqgIOjpEYp V5qQ== X-Gm-Message-State: AOJu0YyMgaddZAL38dDiy3jBvDwJaMk4OLSrFuYZ8prgvkPSwqEcw9sd Bmvs6H0nQm34V5C3goQuLY4zYrRvq2pW8tB4CVl4UvYPsQjs2Tz/G1Lg2ZFgoA== X-Received: by 2002:a50:d613:0:b0:553:44c8:cfc9 with SMTP id x19-20020a50d613000000b0055344c8cfc9mr113134edi.0.1702958040896; Mon, 18 Dec 2023 19:54:00 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <1c12f378af7de16d7895f8badb18c3b1715e9271.1699936040.git.isaku.yamahata@intel.com> <938efd3cfcb25d828deab0cc0ba797177cc69602.camel@redhat.com> <20231219014045.GA2639779@ls.amr.corp.intel.com> In-Reply-To: <20231219014045.GA2639779@ls.amr.corp.intel.com> From: Jim Mattson Date: Mon, 18 Dec 2023 19:53:45 -0800 Message-ID: Subject: Re: [PATCH v2 1/3] KVM: x86: Make the hardcoded APIC bus frequency vm variable To: 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Dec 18, 2023 at 5:40=E2=80=AFPM 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 advert= ise support > > > > for CPUID 0x15, i.e. doesn't announce to host userspace that it's s= afe to expose > > > > CPUID 0x15 to the guest. Because TDX makes exposing CPUID 0x15 man= datory, KVM > > > > needs to be taught to correctly emulate the guest's APIC bus freque= ncy, 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-fin= ished. It > > was supposed to say: > > > > I halfheartedly floated the idea of "fixing" the TDX module/architect= ure to either > > use 1Ghz as the base frequency or to allow configuring the base frequ= ency > > advertised to the guest. > > > > > > I halfheartedly floated the idea of "fixing" the TDX module/archite= cture 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 GH= z. 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.