From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 103573FFADC for ; Fri, 29 May 2026 15:08:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780067311; cv=none; b=cnderEYw5aeQ0bmYaDK729HGVsR87JPXiL9c1CUKwiXHfuwMxvIsb3LcLSnWg2IpwIIS/1jTekCWhE6tcw5U6wtz7LC5+uue3cKOVvrCpjfBtvkp4NOUwOxcWaV5+Eke9ckIKFCxZt78tnOSPnGd4pHtSiNBoh2vSxalJY+D+9I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780067311; c=relaxed/simple; bh=DEZgJF7aGT/S6bfnpIcTdfbLyrYZ4GO7q+5YqQ+zuvQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qZ7/bYKZdeShcf3AtQrzdPGP1gWPciahxcaX4wIipfT6I79XXR9xnMN04TGY1GoOpn5wJxWMqROkWxEoryy5PiCXVOFStQOkR8rOModPgsEfviyBRGg6hD8DxnOwuhuWzcE5csjVK0dNnfZJ+vAg9wemMRKvdpgrlwSI4AS3IZI= 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=bliJiAuL; arc=none smtp.client-ip=209.85.214.201 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="bliJiAuL" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2bf160f7191so7902155ad.3 for ; Fri, 29 May 2026 08:08:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780067309; x=1780672109; darn=lists.linux.dev; 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=EFwMDca4i0UUfWhYRWZx1hhbmviPyyt5LCM1/HLShPA=; b=bliJiAuLaG3+nmRidPY682iIMJBnBPv43MROQyp26NNwr5z5uJe4QcEagFt1WMOe7C cndkt42OfhjpOfobFl96vTnCS2frmWO+0qBAzlo13OSDibfBpUZGcWhOtCKca2OI3muO 8eMowoY/4voFotpkOAJOHNiy0SunQhtyozSrfZ6yiG2zCyTG2oxdesA7jRzJrMfAxEcB dE2x5L023KZwwnhA0zJjnSIbcirVGUc5EAbkgq5KQd/6G8S3ff9w4j+kh2XxX7QKHoOf w2wkcWyHuNdlT2FUzpltYeZkLffqFv+loT7d6/gKAaUViUvOzlicuw6uL1UJZ8j9Vv8v hxEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780067309; x=1780672109; 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=EFwMDca4i0UUfWhYRWZx1hhbmviPyyt5LCM1/HLShPA=; b=pL2UVEdb7jQBRlq9CNAf7YWB6tI2f17nsCDrbucE/uNN4lQJu76cPBN7+k5mxS+NXO aXtwGlyV7zNWPc8WF8vua4tpmPjpsuTNX1sjPxryqnJyCktUoZP4oSY6VV+ltDCQC/OZ r1iQtBP9clt3eTHKx8JfqVUXwqJ4GMfwOz34sGoV7f8rV718h1r83iuwN0epOT+1ksc7 qlbaDNKrlYrenRaaaPD10A9oIH+OW1PewJn1+di5aSY4QxfwC+XevtmEljyHjHKxLrAB AFeDS9jIu6NDU5cgCzDPfcSgUKMjsynJs3JxbnxRysvpWoJcVF+sdy6GKwyjwQjYDMX5 w4lw== X-Forwarded-Encrypted: i=1; AFNElJ82MycE0h3581x1lidqgT8U3xRobv6X2CSiFPX4veDVhXi0ROX2zTyKrIvXWJXzXxCcD63+QUdz63+4@lists.linux.dev X-Gm-Message-State: AOJu0YwZi1bGZ4LprqQ3pm//9kCNUNtXuUAz3dfm9EeAA3wu8zvicw4/ ZkK1XJY0H5FYtu/Vr5kHdPnR9S7BYt5u3sMaQDHQNP3w7E2ukIv5J2aBT8KQSK0qinaIfgGZg7w FeYCQdg== X-Received: from plbjy6.prod.google.com ([2002:a17:903:42c6:b0:2bd:d2c2:2776]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:eccf:b0:2bf:3126:44b6 with SMTP id d9443c01a7336-2bf368bd5dfmr2325645ad.40.1780067309070; Fri, 29 May 2026 08:08:29 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 29 May 2026 08:08:26 -0700 In-Reply-To: <20260529144435.704127-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260529144435.704127-1-seanjc@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260529150827.714968-1-seanjc@google.com> Subject: [PATCH v4 44/47] x86/paravirt: Don't use a PV sched_clock in CoCo guests with trusted TSC From: Sean Christopherson To: Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Kiryl Shutsemau , Sean Christopherson , "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Ajay Kaher , Alexey Makhalov , Jan Kiszka , Andy Lutomirski , Peter Zijlstra , Juergen Gross , Daniel Lezcano , John Stultz Cc: "H . Peter Anvin" , Rick Edgecombe , Vitaly Kuznetsov , Broadcom internal kernel review list , Boris Ostrovsky , Stephen Boyd , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, xen-devel@lists.xenproject.org, David Woodhouse , Tom Lendacky , Nikunj A Dadhania , David Woodhouse , Michael Kelley , 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 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 7bcf757bf551..036916953f4a 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.54.0.823.g6e5bcc1fc9-goog