Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6599142rdb; Tue, 2 Jan 2024 07:10:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxNWsnbB1rpmpw5GlBXsca8x1PFrlrWlrAXs9C1pQPfJyOuAs/pT+xGDNwkcfO1qqtE1u/ X-Received: by 2002:a17:902:ea0d:b0:1d4:3b5b:7aae with SMTP id s13-20020a170902ea0d00b001d43b5b7aaemr20780551plg.104.1704208200851; Tue, 02 Jan 2024 07:10:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704208200; cv=none; d=google.com; s=arc-20160816; b=ZsnfQkcl/Scp1AfVVOP1L65hBoMu1Hqh3vrwhPgqVAu7xdYYN8UIwnkZ8wE7wpHn28 mo+WPsvCBoAQTGgCWIi9UCd9fQ3ac5UZmysB+jRKKQYrkkapXQ4IHNUymRiPNtxWMui8 oevSnqFuQLXT5frqWzzcZzNjF83AkOiMQUhv7Zi73GCMjjT6W8UFQemKmNT78BmMjSuR qrw0C4cijMe4Kq+1rhWSaxXZXak7fIWlxnGwbG3iqF8zhcLcb+AogAWGyVSrjhK44iGU OtUV1a33SboHG62kHDlYxDuEuXEcwrwPIoSySmrsSSf9g2lMgK1SxWJs+eb1TQgOlVtg 1rOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=JyAp2a63bNUdMnRsj/hhIizx1kpY/IpGl6RFLf7olc0=; fh=mzUxr405klZcYQewwqRdF5D5vNnlrbfzCEgcza5233M=; b=qWHADepIDJRKSZpdQrMDzYoPev3l4kgY3kf4LKqvNwnqz4qjYC1AkzSWnOnXx2tfZB wfFwCPowGnvvR0qUgfsPf8OZRr7FrlOOc9QXeIWY17G3SRSVb11at+f0JqL1daFRHqu6 svlJXu0ADw3/D3icLBZfbBDQ6aTtiPBzC2BrHmveBxAWmQGSg68RRLfzXCfTE53GK3Bs rDQ7HedLEAuGXVFwMpWe6skjNxKfYP4xIvn8tdxPKfsqu1TJwUNUU4/iR1elznl3QPNd LRYnXJboGv6dzDQrczQmPev72noY2B0K8Y6uiO0HFugBA126ryHPFEJfQUZ2bGdNc5c0 iIfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EGcEb+FB; spf=pass (google.com: domain of linux-kernel+bounces-14534-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14534-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h7-20020a170902f7c700b001d3e11cf5ebsi20139501plw.34.2024.01.02.07.10.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 07:10:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14534-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EGcEb+FB; spf=pass (google.com: domain of linux-kernel+bounces-14534-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14534-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C69B028139D for ; Tue, 2 Jan 2024 15:09:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08B2714A85; Tue, 2 Jan 2024 15:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EGcEb+FB" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE69412E7E for ; Tue, 2 Jan 2024 15:09:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704208179; 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: in-reply-to:in-reply-to:references:references; bh=JyAp2a63bNUdMnRsj/hhIizx1kpY/IpGl6RFLf7olc0=; b=EGcEb+FBf1SCon9Px0Ou9S1QT3PeXhaZdnve0OngsZuwDvTCRtt1qt2nv9HqHcWBcb9H08 XLIDyZCxmmZyNfSnUnCIlOIlOe9fVz02EneNVqiIGBjfDQWzt+sj3e3Ma5rsB39db5d+1f yBUzpFwKGsXkgly/uSlCOl71G3pY0C8= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-0ouZ8hJSOiqjMOhFQZR5-Q-1; Tue, 02 Jan 2024 10:09:38 -0500 X-MC-Unique: 0ouZ8hJSOiqjMOhFQZR5-Q-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-336811fc1d7so7172225f8f.0 for ; Tue, 02 Jan 2024 07:09:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704208177; x=1704812977; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JyAp2a63bNUdMnRsj/hhIizx1kpY/IpGl6RFLf7olc0=; b=aJFJycAWnRSikkni+pSpcJ/e3u4GHEAoq7YzYUqvgdFgXEXcKU6SwX0MSJhwQ0wLOI iRK4BdgzFTyX3tOQexFW8H3U7Vxc8DyQJJOpme3GO8uESjVl8XrDMiirBRPdECR5vqqN g9KdfG2lmeYoGZ5kE/fHy/AHf7Mtjr05pLwXa7W74uvNK6MqJFRHhVH4vnMO1jNaFkCC GL3rL8x7mI2oAdXKq29U5/ViD6p4Tog4XNJGfQ21r+V/eSw9yx8URnbzitk3mi2xJuxZ 2AGvLy9u6fvwfEGb34CGMlpikzoW1UKgBjfs+FwysSBhk7dFjEldFSpH1IZgQFbCpzNe GqFQ== X-Gm-Message-State: AOJu0YynxloUJH3Y0YnRKGAiyiTCRB/jvqJggJ5OnYOFTV9L0wnL4bIU S28B11lf0A0R3YT8aOQq/ojdbTlEZoNC0Yb4UKjjWnfYw4V2NBzfjLYVeTuc1CcGFn45LfQ9e19 lW4lbm21zDq/ibSH7+Q6wtwLwhbdmlg39 X-Received: by 2002:a5d:6744:0:b0:336:45cd:6d87 with SMTP id l4-20020a5d6744000000b0033645cd6d87mr10953343wrw.60.1704208177486; Tue, 02 Jan 2024 07:09:37 -0800 (PST) X-Received: by 2002:a5d:6744:0:b0:336:45cd:6d87 with SMTP id l4-20020a5d6744000000b0033645cd6d87mr10953332wrw.60.1704208177153; Tue, 02 Jan 2024 07:09:37 -0800 (PST) Received: from vschneid-thinkpadt14sgen2i.remote.csb (213-44-141-166.abo.bbox.fr. [213.44.141.166]) by smtp.gmail.com with ESMTPSA id a1-20020adfed01000000b0033748f5600csm1610410wro.108.2024.01.02.07.09.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 07:09:36 -0800 (PST) From: Valentin Schneider To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, Thomas Gleixner , Borislav Petkov , Josh Poimboeuf , Pawan Gupta , Ingo Molnar , Dave Hansen , "H. Peter Anvin" , Paolo Bonzini , Wanpeng Li , Vitaly Kuznetsov , Arnd Bergmann , Jason Baron , Steven Rostedt , Ard Biesheuvel , Frederic Weisbecker , "Paul E. McKenney" , Feng Tang , Andrew Morton , "Mike Rapoport (IBM)" , Vlastimil Babka , David Hildenbrand , "ndesaulniers@google.com" , Michael Kelley , "Masami Hiramatsu (Google)" Subject: Re: [PATCH 5/5] x86/tsc: Make __use_tsc __ro_after_init In-Reply-To: <20231204182043.GB7299@noisy.programming.kicks-ass.net> References: <20231120105528.760306-1-vschneid@redhat.com> <20231120105528.760306-6-vschneid@redhat.com> <20231120120553.GU8262@noisy.programming.kicks-ass.net> <20231204182043.GB7299@noisy.programming.kicks-ass.net> Date: Tue, 02 Jan 2024 16:09:35 +0100 Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On 04/12/23 19:20, Peter Zijlstra wrote: > On Mon, Dec 04, 2023 at 05:51:49PM +0100, Valentin Schneider wrote: >> On 20/11/23 13:05, Peter Zijlstra wrote: >> > On Mon, Nov 20, 2023 at 11:55:28AM +0100, Valentin Schneider wrote: >> >> __use_tsc is only ever enabled in __init tsc_enable_sched_clock(), so mark >> >> it as __ro_after_init. >> >> >> >> Signed-off-by: Valentin Schneider >> >> --- >> >> arch/x86/kernel/tsc.c | 2 +- >> >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> >> >> diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c >> >> index 15f97c0abc9d0..f19b42ea40573 100644 >> >> --- a/arch/x86/kernel/tsc.c >> >> +++ b/arch/x86/kernel/tsc.c >> >> @@ -44,7 +44,7 @@ EXPORT_SYMBOL(tsc_khz); >> >> static int __read_mostly tsc_unstable; >> >> static unsigned int __initdata tsc_early_khz; >> >> >> >> -static DEFINE_STATIC_KEY_FALSE(__use_tsc); >> >> +static DEFINE_STATIC_KEY_FALSE_RO(__use_tsc); >> > >> > So sure, we can absolutely do that, but do we want to take this one >> > further perhaps? "notsc" on x86_64 makes no sense what so ever. Lets >> > drag things into this millennium. >> > >> >> Just to make sure I follow: currently, for the static key to be enabled, we >> (mostly) need: >> o X86_FEATURE_TSC is in CPUID >> o determine_cpu_tsc_frequencies()->pit_hpet_ptimer_calibrate_cpu() passes >> >> IIUC all X86_64 systems have a TSC, so the CPUID feature should be a given. >> >> AFAICT pit_hpt_ptimer_calibrate_cpu() relies on having either HPET or the >> ACPI PM timer, the latter should be widely available, though X86_PM_TIMER >> can be disabled via EXPERT - is that a fringe case we don't care about, or >> did I miss something? I don't really know this stuff, and I'm trying to >> write a changelog... > > Ah, I was mostly just going by the fact that all of x86_64 have TSC and > disabling it makes no sense. > > TSC calibration is always 'fun', but I don't know of a system where its > failure causes us to not use TSC, Thomas? Having another look at this, it looks like the actual requirements for the TSC being used are either of: o CPUID accepting 0x16 as eax input (cf. cpu_khz_from_cpuid()) o MSR_FSB_FREQ being available (cf. cpu_khz_from_msr()) o pit_hpet_ptimer_calibrate_cpu() doesn't mess up I couldn't find any guarantees for x86_64 on having the processor frequency information CPUID leaf, nor for the FSB_FREQ MSR (both tsc_msr_cpu_ids and the SDM seem to point at only a handful of models). Also for x86_64 there is this "apicpmtimer" cmdline arg which currently disables the TSC. The commit that introduced it [1] suggests there are x86_64 systems out there with calibration issues, so now I'm not sure whether we can kill the static key for x86_64 :( [1]: 0c3749c41f5e ("[PATCH] x86_64: Calibrate APIC timer using PM timer") followed by: 7fd67843b96f ("[PATCH] x86_64: Disable tsc when apicpmtimer is active")