From patchwork Sat Feb 1 02:17:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13956058 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 15C11C0218F for ; Sat, 1 Feb 2025 02:17:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.880054.1290246 (Exim 4.92) (envelope-from ) id 1te34j-0003ey-KI; Sat, 01 Feb 2025 02:17:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 880054.1290246; Sat, 01 Feb 2025 02:17:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1te34j-0003ep-GM; Sat, 01 Feb 2025 02:17:37 +0000 Received: by outflank-mailman (input) for mailman id 880054; Sat, 01 Feb 2025 02:17:36 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1te34i-0002sH-6O for xen-devel@lists.xenproject.org; Sat, 01 Feb 2025 02:17:36 +0000 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [2607:f8b0:4864:20::64a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b309a045-e042-11ef-a0e6-8be0dac302b0; Sat, 01 Feb 2025 03:17:35 +0100 (CET) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-2166e907b5eso47823905ad.3 for ; Fri, 31 Jan 2025 18:17:35 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b309a045-e042-11ef-a0e6-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738376254; x=1738981054; darn=lists.xenproject.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=MDyJubTgvsqHYl0zNK5/PK8+bagsI5N8h9xCVnMunLg=; b=wzQcXBizw7xYzYg2D25OYLFEMJ9VCs1zKSXddkKG0+E/konSYwZkdfbWujHJjmuI56 tWzZsD7Qh7piHt3o2GfnuvEpX/g9jnmKIu3zGGM3p0cKzsldhvnhUDiwjC3P5uhFLwAX 3rw2lWcefkmL2K9/SpW8Mjfgqq/dh3mZmld1SD+04bK4hDwrVqbKPVxZc7gQv4PdiLKv hu/xUhrQyRC9s9ILe6chhB9i/K/UZrlXUwSG05pNtluVz5WATPt8d+mkz4T3dP8UfUBx KF+OuQzZHF6cz2gGmuoAhKjl9H6VOrd/HoBpOQZmXKbsGUe20asNatueIkv0H8JIG5QM CufQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738376254; x=1738981054; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MDyJubTgvsqHYl0zNK5/PK8+bagsI5N8h9xCVnMunLg=; b=WFt3gOeoTnEWFsNPAjiYTRh6A3+rFrycIbAzHv97EATVJOCSDrAAsy64nVCZFyq+Hn jjkUkELPv6SIkPHirZBED9axxu0w28wa9z1ZUvnUekuExRr2qSg3fb+Zbgctv0wIPxRk Z8SMOjcF0Js4LSG0Rh9VehsEd5EVcRssHqepIFDy0z91i70cclRJhH0A6CvwK2HvbwvG EsL4t4FJ0IF/92itT3irrBpgo6nHGfxemIvMwfm/An5w9wM5eD3leKcNjAbbcz7P11xD 5eUygtHPTupfxfKlcJpqQbVuy00QIPF8VIbBD3QEGEdSVGgnRrcg4tNQOjy6n8M5tf8U gBkg== X-Forwarded-Encrypted: i=1; AJvYcCXAzkqlPMWVXvmXbw0pQkCREZRoJ/AZE+TvZrbNoimCnaceNMyTULUb1j9fHqTR/iGR6gKWAjYLy5E=@lists.xenproject.org X-Gm-Message-State: AOJu0YzqA5V5syJqpEV6nb/AbtlXHHkTpAit+jo3rMH8i14FP2gxzhS+ MhnHdYQEuHMcxzzHntarja+B7Uxmoi0hjNilQ0WDIfQP3aGA4TELDBjg3rF//48H+yxGcEkOoE6 K9w== X-Google-Smtp-Source: AGHT+IGkjSAAWxmwHiu0qCv61xkb4iGGZ5alFNn1UCDa8mCUkr+gLXYmTCgtlrE3otTrUQeGakGB8oHEBGw= X-Received: from pjj16.prod.google.com ([2002:a17:90b:5550:b0:2e5:8726:a956]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:db04:b0:216:4c88:d93a with SMTP id d9443c01a7336-21dd7dd7356mr228949515ad.48.1738376254204; Fri, 31 Jan 2025 18:17:34 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 31 Jan 2025 18:17:06 -0800 In-Reply-To: <20250201021718.699411-1-seanjc@google.com> Mime-Version: 1.0 References: <20250201021718.699411-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250201021718.699411-5-seanjc@google.com> Subject: [PATCH 04/16] x86/sev: Mark TSC as reliable when configuring Secure TSC From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "Kirill A. Shutemov" , Juergen Gross , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Ajay Kaher , Alexey Makhalov , Jan Kiszka , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, virtualization@lists.linux.dev, linux-hyperv@vger.kernel.org, jailhouse-dev@googlegroups.com, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, Sean Christopherson , Nikunj A Dadhania , Tom Lendacky Move the code to mark the TSC as reliable from sme_early_init() to snp_secure_tsc_init(). The only reader of TSC_RELIABLE is the aptly named check_system_tsc_reliable(), which runs in tsc_init(), i.e. after snp_secure_tsc_init(). This will allow consolidating the handling of TSC_KNOWN_FREQ and TSC_RELIABLE when overriding the TSC calibration routine. Cc: Nikunj A Dadhania Cc: Tom Lendacky Signed-off-by: Sean Christopherson Reviewed-by: Nikunj A Dadhania --- arch/x86/coco/sev/core.c | 2 ++ arch/x86/mm/mem_encrypt_amd.c | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 684cef70edc1..e6ce4ca72465 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -3288,6 +3288,8 @@ void __init snp_secure_tsc_init(void) return; setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); + setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); + rdmsrl(MSR_AMD64_GUEST_TSC_FREQ, tsc_freq_mhz); snp_tsc_freq_khz = (unsigned long)(tsc_freq_mhz * 1000); diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index b56c5c073003..774f9677458f 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -541,9 +541,6 @@ void __init sme_early_init(void) * kernel mapped. */ snp_update_svsm_ca(); - - if (sev_status & MSR_AMD64_SNP_SECURE_TSC) - setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); } void __init mem_encrypt_free_decrypted_mem(void)