From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 5C5A64F798F for ; Thu, 6 Aug 2026 23:37:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059445; cv=none; b=E2L1MOJKCllX/68oKwVcncByRpi1VoJ3HS35DYebhUmoO6RR7kPF29QdqdZ+P5vQJQ/2RAvU/1J5gRaIkrTbVtWdGtg2UgXZhn+emp3OVX784mQ6vo5pRO/aN5bzcq8aIVks/1J5Xm9ZuEQ0TRwX8eaEHYsg/EtgpBtG0cw9tJQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059445; c=relaxed/simple; bh=KyczVRw6DQ4Q2CF9U3rOeviso8DvMN7GdliVgfbvQQ0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=j+iOCWYhUU3MC3VRep1f+gIMviBdfNMFP4Ry+7GNxIVQuZ2j5DZ0Ya/j/jrkcoNGIw5lNn5C0IUdUfT6ti8wZPgOe5/ZHNbeaR8KJkIPwdJ3ScF5VqOIX5lhIn1ByWsdsiLEs63xULCHPOymgKf0EQIbb1IC74cWXqf1udvOu4E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nBvaHWQj; arc=none smtp.client-ip=209.85.215.198 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=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nBvaHWQj" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cbb467e56aaso2947266a12.1 for ; Thu, 06 Aug 2026 16:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786059443; x=1786664243; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=NcgEnPBxyGviYS1Y0BEogKtyt4exk2sJiTd88Re19eg=; b=nBvaHWQjRUJBELDkGEpYOwrVRgx+Tj2Eac82OmyG0INkWqnxm6f2wA16yysVOtQOTb OYeJmwk4L8ZjbZ+c63zCfcx8uLF+xDAiSFodANwvuQCSIk3TC7OrdXBnTWlbyYYvVnRT ajL2oyhgK+HpHDh9OUNSo86Q/KzGl0stk1PIu2lyBsVnu9Ty+/IyliYDbwfAq6zchBqK aMSUzT0wngvsJdkJwQNKUGSOd6VpehY0mja6b4HXizQpz1BnxtHXRVzjV7aaX2ij5Ymv ykppzBHqwNRF8Z5zy6iJfvnDGajEi1xT2aYhjWDDxZpt2XDf211ui97uRYXmdNuSZhHK D0cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786059443; x=1786664243; h=content-type: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:content-type; bh=NcgEnPBxyGviYS1Y0BEogKtyt4exk2sJiTd88Re19eg=; b=cI8UVmxFkr4C7TVHiTD/SmOkCSvzf+yPZD0QZLXrFf5dlamH8xi7iyVA9120xF45ot rgSlbaUyZHxOP5yOLHuyYCrUVim6ne+gaQqg+aLM0+OLHY8GkgX+SvFRLe2enI5tHkDs t7l8Td/BnolElELOvl948hE48UvcCZkVB2lhL9t6sgBRIJPFtuoQK3VDh1J8m9FxnkL/ nkRDq02q+FkPtHzfqEsHuFgxqhb2F3gQeOA2eud/ux9QBXDgIrGJl0Los3oZPDtTTciB 4N5Wt6ZxLo+vHbPxFPGUz1NPmNjeIrtbj6gJISW5f2wAHb0LKyR5rrIpvQxbCrMjKpXe WwVQ== X-Forwarded-Encrypted: i=1; AHgh+RpmcfvcWdA0uOJow8P1hF6mltWHl8fGFoafD9k9H6AVz5v/y4CtmDiEeY0Mrkq2NbIWvFpvKj5ORavOcas=@vger.kernel.org X-Gm-Message-State: AOJu0YyVIrWIcEQEsXJLXAMnmkti9uNfyAvJFho/eZthFsewSHxknYX+ bGPejzwhs3vQdepYLOaAFu5DtnzSrxIDwEYCN1a/O9ZkMPYN+uTYXFOfTIxzhRD8ddUwpmX8V75 +2vheyg== X-Received: from pfbcw11.prod.google.com ([2002:a05:6a00:450b:b0:848:51a7:e8bb]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2999:b0:848:67ca:bfd with SMTP id d2e1a72fcca58-84f2dff1913mr22778991b3a.16.1786059442569; Thu, 06 Aug 2026 16:37:22 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 6 Aug 2026 16:36:04 -0700 In-Reply-To: <20260806233609.212337-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260806233609.212337-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.679.g6767b8d81c-goog Message-ID: <20260806233609.212337-48-seanjc@google.com> Subject: [PATCH v6 47/51] x86/paravirt: Don't use a PV sched_clock in CoCo guests with trusted TSC From: Sean Christopherson To: Kiryl Shutsemau , Rick Edgecombe , Sean Christopherson , Paolo Bonzini , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Ajay Kaher , Alexey Makhalov , Jan Kiszka , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Juergen Gross , Daniel Lezcano , Thomas Gleixner , John Stultz Cc: Vitaly Kuznetsov , Broadcom internal kernel review list , Boris Ostrovsky , Stephen Boyd , Miroslav Lichvar , x86@kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Michael Kelley , Tom Lendacky , Nikunj A Dadhania , David Woodhouse , David Woodhouse , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Silently ignore attempts to switch to a paravirt sched_clock when running as a CoCo guest with trusted TSC. In hand-wavy theory, a misbehaving hypervisor could attack the guest by manipulating the PV clock to affect guest scheduling in some weird and/or predictable way. More importantly, reading TSC on such platforms is faster than any PV clock, and sched_clock is all about speed. Reviewed-by: David Woodhouse Reviewed-by: Nikunj A Dadhania Signed-off-by: Sean Christopherson --- arch/x86/kernel/tsc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index fcf331ffd874..c0e4485484f2 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -283,6 +283,15 @@ bool using_native_sched_clock(void) int __init __paravirt_set_sched_clock(u64 (*func)(void), bool stable, void (*save)(void), void (*restore)(void)) { + /* + * Don't replace TSC with a PV clock when running as a CoCo guest and + * the TSC is secure/trusted; PV clocks are emulated by the hypervisor, + * which isn't in the guest's TCB. + */ + if (cc_platform_has(CC_ATTR_GUEST_SNP_SECURE_TSC) || + boot_cpu_has(X86_FEATURE_TDX_GUEST)) + return -EPERM; + if (!stable) clear_sched_clock_stable(); -- 2.55.0.679.g6767b8d81c-goog