From nobody Sat Feb 7 05:35:47 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748589358; cv=none; d=zohomail.com; s=zohoarc; b=WyBTZ2u5qy93d1R58zkRJeurbycbKa13Q2YSMpF31EWn1UA+OhoFIgpBvLMOSKMbPDQUm9taortl0K5hWNuimQda9cSKlTSIfzYgnRmtP4YM8H9p1/EgDevCUHAhEdwxQrmW4Zif8Iaq+NLoBruKyRmWcaU4wAzCAqR8Wla5jfg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748589358; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=w9xJhpuzXINKl3LZpWge4QLi33eUyTvHiKnQt0qRGfg=; b=KvuJOVBQOqMjeAVWifvRANn9dLhOZR9cX7vNWnjNNSS3PWJ3B2G7Qt328sJch3gff1nZbONUqWFn7uXshnPAtZylIZoai6T2eNu55cVOx1bb0Q4gEpEBvtP+vAqXF0BxIWqsz2dYD64RZvEh1Jpn1LoZGu4OeX79hl8xhOr44PI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748589358659160.24219522151486; Fri, 30 May 2025 00:15:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKtwS-0001lX-Bs; Fri, 30 May 2025 03:14:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uKtwH-0001QE-64 for qemu-devel@nongnu.org; Fri, 30 May 2025 03:14:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uKtwF-0006vS-EK for qemu-devel@nongnu.org; Fri, 30 May 2025 03:14:00 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-74-2WXk8fS0PoaNExRkv6Yigg-1; Fri, 30 May 2025 03:13:57 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ac79e4764e5so176600466b.0 for ; Fri, 30 May 2025 00:13:57 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-adb318db274sm119163566b.162.2025.05.30.00.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 00:13:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748589238; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w9xJhpuzXINKl3LZpWge4QLi33eUyTvHiKnQt0qRGfg=; b=F9WBJig1yOWveqv0QFPEsnD85hRwN7Uaz39SBp3xfHbQ9Gc/L/npqfqLIWDqHMJQSBXEF0 tcsqvZSLAEJlII78nyMQpWzwT92WFm05LRDerX1Vo8+aAjhn4ppGrBBaURxy9Oo59uhvQy 1DO/5I7zEKR3j4vfpAuY2Bwie1vpRgU= X-MC-Unique: 2WXk8fS0PoaNExRkv6Yigg-1 X-Mimecast-MFC-AGG-ID: 2WXk8fS0PoaNExRkv6Yigg_1748589236 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748589236; x=1749194036; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w9xJhpuzXINKl3LZpWge4QLi33eUyTvHiKnQt0qRGfg=; b=iSg874SVUakl3HLI1O0CHryink99O/0+fhqPHEWqV5GP4xKCI0CKB+9ZFpHOht+Bvj ww8hqV3fVU/ELNwJ7kDSyoXvFXbYtbFolAeS4l9xuQIo4MCWMuHJPRQ+qqgCb5sld/GA 5819U0fe+FBpyMJsf0b3oJdJ1GV6i6GH0mXGsz4xdhRf92HgWNEEpOMy3r6tgHt1c2l7 IoAGbvcqH34OUdG23QysJnVd1jvyoyaWuiRKnrJ2xjtvNH1cXXZs2xGygspJX/oCpzxO WzZZ/C08nh2oMQWgRxnvqHSb7T//N9dgx613QoNfuV4GgpBXBnijzpMCELhjmAvRe/a1 euxQ== X-Gm-Message-State: AOJu0YwUtS8qJWUkgeYNQPD5vAIyG7TZ4ZbjaW6zFPPaFLaH4h89WJk9 gipfxx8bfKpPTdww3r1wBB/jEIIIbUCmRKAz4kMWzj8B29fEhX+oSI4/K7HF0hcd8cJ4lbEG6jK Wwfhl10ySAXyLH2oPrKJPSlMfutgcza0UU6t1NDi9YFZ4IA2AiwtiVrc2INaa0IETkvg0mx+GmT F5326NgN0LBu3VgoodKXBZTj000hq2IZEIsI+qp5rf X-Gm-Gg: ASbGncvUuCZzTAtO0Zw41UE6H/qF1tmc3qVdzJjMqt4CE8W6pd5aZu61mLee8dPB6Nw O/vmdFMAoBKq2IQ1EdMmJvnJHzmeNoe4wdrVB+DDeBaIXmrJAOxGG6botXyRcJv6qgBoK9HI4fA 9NThv129d1fnQyopGggkTjQv3CWHYIHiKc3ffoUjkMKqOvTNK4zVZNEdkWwGjI5OPsvGNmQbHDI 8uJJQKSGq3AQ9wuMuY3BcSSCgyFs5UuGyWu4v1j5J6nIvx3XP9kJHDCUXYnmtBkC6H9x/ih+mDD NOIyUWVLtvkWRw== X-Received: by 2002:a17:906:c143:b0:ad8:9428:6a3b with SMTP id a640c23a62f3a-adb36b05316mr105412466b.5.1748589235735; Fri, 30 May 2025 00:13:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDU/OvWQ+LeP/oaX6fosAlEG6akHJT5Aiv9+wMCyGhbG7aJsJA9LXFjewVZkjQYwcMu/xRGA== X-Received: by 2002:a17:906:c143:b0:ad8:9428:6a3b with SMTP id a640c23a62f3a-adb36b05316mr105409966b.5.1748589235358; Fri, 30 May 2025 00:13:55 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Zhao Liu Subject: [PULL 26/77] i386/tdx: Set APIC bus rate to match with what TDX module enforces Date: Fri, 30 May 2025 09:11:56 +0200 Message-ID: <20250530071250.2050910-27-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530071250.2050910-1-pbonzini@redhat.com> References: <20250530071250.2050910-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1748589360899116600 From: Xiaoyao Li TDX advertises core crystal clock with cpuid[0x15] as 25MHz for TD guests and it's unchangeable from VMM. As a result, TDX guest reads the APIC timer at the same frequency, 25MHz. While KVM's default emulated frequency for APIC bus is 1GHz, set the APIC bus rate to match with TDX explicitly to ensure KVM provide correct emulated APIC timer for TD guest. Signed-off-by: Xiaoyao Li Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250508150002.689633-15-xiaoyao.li@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/kvm/tdx.h | 3 +++ target/i386/kvm/tdx.c | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index e472b11fb0d..d39e733d9fc 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -16,6 +16,9 @@ typedef struct TdxGuestClass { X86ConfidentialGuestClass parent_class; } TdxGuestClass; =20 +/* TDX requires bus frequency 25MHz */ +#define TDX_APIC_BUS_CYCLES_NS 40 + typedef struct TdxGuest { X86ConfidentialGuest parent_obj; =20 diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 671f23d910a..58983edd80a 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -254,6 +254,19 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) init_vm =3D g_malloc0(sizeof(struct kvm_tdx_init_vm) + sizeof(struct kvm_cpuid_entry2) * KVM_MAX_CPUID_EN= TRIES); =20 + if (!kvm_check_extension(kvm_state, KVM_CAP_X86_APIC_BUS_CYCLES_NS)) { + error_setg(errp, "KVM doesn't support KVM_CAP_X86_APIC_BUS_CYCLES_= NS"); + return -EOPNOTSUPP; + } + + r =3D kvm_vm_enable_cap(kvm_state, KVM_CAP_X86_APIC_BUS_CYCLES_NS, + 0, TDX_APIC_BUS_CYCLES_NS); + if (r < 0) { + error_setg_errno(errp, -r, + "Unable to set core crystal clock frequency to 25= MHz"); + return r; + } + if (tdx_guest->mrconfigid) { g_autofree uint8_t *data =3D qbase64_decode(tdx_guest->mrconfigid, strlen(tdx_guest->mrconfigid), &data_len, er= rp); --=20 2.49.0