Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5642437rdb; Wed, 13 Dec 2023 15:10:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbhGzNKqTqdW0SwHBtLUuccLf5HTRoodsSJdXHxkdVc3Gz6c2Pu7chYTzwTDLn4pDlEFz2 X-Received: by 2002:a05:6870:d38a:b0:1fb:6e5d:1ecb with SMTP id k10-20020a056870d38a00b001fb6e5d1ecbmr10754597oag.54.1702509057063; Wed, 13 Dec 2023 15:10:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702509057; cv=none; d=google.com; s=arc-20160816; b=YgcgTrwjmXDTs42o/bDV5KRROeJi1xrtKKVrNSuA7afNkTO6JXhwd2KBr33XT72w97 wtmwfZ7YjILIcOvAYQhWOHPPxFApLppJZ5iI3VYiZcsW/lOCKMMqCW+S9y7Y2HkNzlBx PCUHdIvZAdaFxw5ckFtE/K3EYS0rRm0hzkYBImN0If0+P84KNIVeONPYNlzkJGb7/XmI DgwdVGAuv3pNTswkBhCe6l7bziGSnku4iFTh7cgs9BaQW6X/doL9Gzl75M0r4KqGPkRx L6xtWI6bGYTJiq0sQU0guhJBzYWXvzAbP9MDtm6d6EurJoE2DeJcC2S+US3bWkr3Dgzx v/3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=CUqoDbZM9AopeA8SWQ56D3q7Q5pOcG2dnxXupG6r4AM=; fh=nvBy3rJL+yGH0qq99avyyJUGBcY0rSboGVxtVCw8HII=; b=GiLhfsPtHsTjOTukMk7uKe+Q9+18i9VL42cw1QQNU+V6vy7Hygru1qnYsh/RF6VWf3 2meIpAM8Y025yxURjOlnPUeJLmuKC/A4tXPpcauvSq+ROarqyT6zm42iMVb3wlqfRgXn ljBzluGW+Y3NJz5RYI7OOsYoQmL/toURlP6lAw6OycPn4xVyOQX8f7bwGrawoux1ee/P pl1yBfGoy5zeZdso0lLtXWggJejeIx//3DKA+fHhzlwAd46rjSPcIJfO0hKzK6AkaSkV OVnfgDOeWBW6ptQ/RMmU9pRXI0x/ZNj6BAP3DR0rl5iJvfOJ/4o/ZCEODyH85JNgZUVj qtCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Ps6YFuZW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id k13-20020a6568cd000000b005be007363a4si9942267pgt.669.2023.12.13.15.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 15:10:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Ps6YFuZW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id EC9BC809217E; Wed, 13 Dec 2023 15:10:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229835AbjLMXKX (ORCPT + 99 others); Wed, 13 Dec 2023 18:10:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbjLMXKW (ORCPT ); Wed, 13 Dec 2023 18:10:22 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 113BDD0 for ; Wed, 13 Dec 2023 15:10:28 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5e19414f714so39479847b3.0 for ; Wed, 13 Dec 2023 15:10:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702509027; x=1703113827; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CUqoDbZM9AopeA8SWQ56D3q7Q5pOcG2dnxXupG6r4AM=; b=Ps6YFuZWcYOBgvbAejx+2etW7sQb71fvhn6DU5QSVgdDdRoCp7E4/qn/oWnb/4/q32 +dCCQp1pBFtMaBanO9n96vbs3G8/NT9JlMw5vq9FaNDGdyr2qRZHDK5xxtXc1X+7Ie/j PRRjCvb+EZj3x9ruEH5cvuagLa7nvEhRGDfXxRrUlCI+78JpZbY9A1tExCvvfKRxcBI6 hkMXGUVETtq/SAE1bwd1uYWwMZDh3TUaOQqJyqUj0ZGcT6g8Xws7thBAP4HdPz61Cdys yXtPnXIpj29B+1zO9I55kZvDjXzkZ2b4vSfVIcbfI4UlMYMbpyyKkG+YmtBqACwROnH8 PCEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702509027; x=1703113827; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CUqoDbZM9AopeA8SWQ56D3q7Q5pOcG2dnxXupG6r4AM=; b=LP5MzPGUcDz8dmChWrhTfnf+3+eoIdnH903tadegelqyvkVdh9GlqxPQV2sy7B4A1y dfAEv9Jf+Y8Rfbtlc18yXWnAjR2Cl2GWi0db2IYeqxRP2Ns08q+w/Sxk6OatQQ2uTRI3 us4qbxJWz+hnyZ2ZkQOh3TkiEs+rSe0FzBNH8FzOiAP0WEvnNlo31PKlxN4zeA6bsUQG WAsAHSc9Nlol/TIVNe2xqnn0CFGs6j3uOLEUAsTmeU3B4H6DK60drP39XlSnt8LB2iuK VB5I4mR9wlNgMTHcGVUe5Uj+2+zyRYqZdWmHv0x9IJJ87TC3aMANMrqPxKwQKe5CAP8z 19ww== X-Gm-Message-State: AOJu0Yzbbpy+kJ6YcwMpeVJh6NAr19vHjGR/Y/b9kap1mAxA9Nf1Vte/ nLAd9lYgXaK/rUM2D/o7/RMCq+uygPM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:d0e:b0:5d7:9a6c:54aa with SMTP id cn14-20020a05690c0d0e00b005d79a6c54aamr98099ywb.5.1702509027129; Wed, 13 Dec 2023 15:10:27 -0800 (PST) Date: Wed, 13 Dec 2023 15:10:25 -0800 In-Reply-To: <938efd3cfcb25d828deab0cc0ba797177cc69602.camel@redhat.com> Mime-Version: 1.0 References: <1c12f378af7de16d7895f8badb18c3b1715e9271.1699936040.git.isaku.yamahata@intel.com> <938efd3cfcb25d828deab0cc0ba797177cc69602.camel@redhat.com> Message-ID: Subject: Re: [PATCH v2 1/3] KVM: x86: Make the hardcoded APIC bus frequency vm variable From: Sean Christopherson To: Maxim Levitsky Cc: 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 Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 13 Dec 2023 15:10:39 -0800 (PST) On Thu, Dec 14, 2023, Maxim Levitsky wrote: > On Mon, 2023-11-13 at 20:35 -0800, isaku.yamahata@intel.com wrote: > > From: Isaku Yamahata > > > > TDX virtualizes the advertised APIC bus frequency to be 25MHz. > > Can you explain a bit better why TDX needs this? I am not familiar > with TDX well enough yet to fully understand. TDX (the module/architecture) hardcodes the core crystal frequency to 25Mhz, whereas KVM hardcodes the APIC bus frequency to 1Ghz. And TDX (again, the module) *unconditionally* enumerates CPUID 0x15 to TDX guests, i.e. _tells_ the guest that the frequency is 25MHz regardless of what the VMM/hypervisor actually emulates. And so the guest skips calibrating the APIC timer, which results in the guest scheduling timer interrupts waaaaaaay too frequently, i.e. the guest ends up gettings interrupts at 40x the rate it wants. 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 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