Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1292402rwd; Thu, 1 Jun 2023 13:19:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4c85Rfcpq+cDYQYu2iblsgy/YVR0U/2z8ooBMy9TWo/OHM/Gdn0OBzvsAD34B99OESCqvJ X-Received: by 2002:a17:902:7c11:b0:1b0:34c6:3be5 with SMTP id x17-20020a1709027c1100b001b034c63be5mr247885pll.21.1685650763293; Thu, 01 Jun 2023 13:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685650763; cv=none; d=google.com; s=arc-20160816; b=CV6r3yWdFLspKBgPIAT3BIkgB6Xubb3H1icGWosrFqor0yqYLwYmDIfUSAfc960khQ /R679Jh6/CKFBjzHfh9ZO064CeTOe7eHXMAXWOzpRvnuVcyMTSXOkq1oI0tlQdV1wl8U gBB/ilZZ1fdxzSk5fEmdYeAKgm8pNruCOVa+bUJsiSSuRoolRmn2iOSQOiwBrj0fqSIq 2YFrepplUOOY/NdlVHvVK00g3H0ZAO7QwFJK+MWt8TKaO4OqBZtkkguDd1hLkwsZpQGi 7rzVsfTWo3KSDMcYf2fE7zkEyIZxGtkdJ89oeDRjgAAYs2rYcrw7hhvsVA5eIoXPbw2t +mwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=chRIhlGc1ewVpa0H2/yhfREyLjRPBthRnCPNhZqy3w4=; b=MEOtATf2Lev3pr5Afrg2rNP+8kjXekp3Y0DH29w9qsydhB0iTqS6zKiwWpdB3EGfME kgakO47AHAt0OJKRQtr/J78so6vVvMo3MRBF3dsi5t4jbknoa06WLmyDInRo4FqR3P+g PJknjpDvR/b/a25YdmDkByaCZI14bC1IkLPDwFY8dFrUpaywpMJRtqUf3zENQAzadD1S eCj4mtyOxrp2Gm9ew1X3tAjy3LSLw5msXaQTkcBBOifIci1ESELH3AoKdmsJGUaOBzhT rF/YR6050WIszJ8jzOouMsp+d7N1ZIHcA5PUHpqeoux0qaKumEOx8y8oDxSi4pemgen7 AMwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EqHSk8bE; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a170902d34900b001b06fa86b08si2010142plk.412.2023.06.01.13.19.07; Thu, 01 Jun 2023 13:19:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EqHSk8bE; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230397AbjFAUKv (ORCPT + 99 others); Thu, 1 Jun 2023 16:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjFAUKu (ORCPT ); Thu, 1 Jun 2023 16:10:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51B3D134; Thu, 1 Jun 2023 13:10:48 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685650245; 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=chRIhlGc1ewVpa0H2/yhfREyLjRPBthRnCPNhZqy3w4=; b=EqHSk8bEiOWSuwySTSmsQgtq830ssjROGQtit5HNEHYJ/gjR34yN8yXUz7ZMRh/Qnz3bsX 3q/i/8ubGcuRoJ9LNSOm4tE6yCne0OUWv7MBaao8tXdHM6EZkZUmK41E8orcToCH6B5LK7 Lmrcag+YuWD231i7hncnKtyPl2gvKJ78IKeMCI9gshnm6QdKevb0EZTNqShOV8AD8IiVcl A1ru55rc0KpZTSV2CCf3S3ot8HR9GgiqOUILX/9fN/a/g8aZMRL8PrNgPR9x3YmDzfH5Dt wgt12ihLEiy0/bVOzA41ZBMVyo2LuqhWOSBwWr2XKLDoM8BzfTK3qOgmTC2zZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685650245; 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=chRIhlGc1ewVpa0H2/yhfREyLjRPBthRnCPNhZqy3w4=; b=17MZUD2EjWUZBS3/xwGd6iUUcbbrPxMb6Kq6j0xq9Ck8dwTyIwKe7JOvBAYABUorn99+vq wiodoJbf/sg1+ICg== To: Steven Noonan Cc: Muhammad Usama Anjum , Jonathan Corbet , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "open list:DOCUMENTATION" , open list , "Guilherme G. Piccoli" , kernel@collabora.com Subject: Re: Direct rdtsc call side-effect In-Reply-To: References: <6719fb05-382c-8ec4-ccda-72798906a54b@collabora.com> <87mt1jeax1.ffs@tglx> <87h6rrdoy0.ffs@tglx> Date: Thu, 01 Jun 2023 22:10:45 +0200 Message-ID: <871qivdjui.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 01 2023 at 19:07, Steven Noonan wrote: > On Thursday, June 1st, 2023 at 11:20 AM, Thomas Gleixner wrote: >> Here is an example where it falls flat on its nose. >> >> One of the early Ryzen laptops had a broken BIOS which came up with >> unsynchronized TSCs. I tried to fix that up, but couldn't get it to sync >> on all CPUs because for some stupid reason the TSC write got >> arbritrarily delayed (assumably by SMI/SMM). > > Hah, I remember that. That was actually my laptop. A Lenovo ThinkPad > A485 with a Ryzen 2700U. I've seen the problem since then occasionally > on newer Ryzen laptops (and even desktops). Without the awful > "tsc=directsync" patch I wrote, which I've been carrying for years now > in my own kernel builds, it just falls back to HPET. It's not > pleasant, but at least it's a stable clock. Well, yours seem at least to sync. The silly box I tried refused due to SMM value add magic. > Agreed, TSC_ADJUST is the ultimate solution for any of these kinds of > issues. But last I heard from AMD, it's still several years out in > silicon, and there's plenty of hardware to maintain compatibility > with. Ugh. Yes. > A software solution would be preferable in the meantime, but I don't > know what options are left at this point. Not that many. > The trap-and-emulate via SIGSEGV approach proposed earlier in the > thread is unfortunately not likely to be practical, assuming I > implemented it properly. That's why I said we need to ask Microsoft to do the same so that the applications get fixed. :) > Most Windows games that use this instruction directly are doing so > under the assumption that the TSC is faster to read than any of the > native Windows API clock sources. The recommended interface QueryPerformanceCounter() is actually not much slower and safe. But sure performance first and correctness is overrated. So back to the options: 1) Kernel If at all then this needs to be disabled by default and enabled by a command line option along with a big fat warning that it might disable TSC for timekeeping and bug reports related to this are going to be ignored. Honestly I'm not too interested in this. It's yet another piece of art which needs to be maintained and kept alive for a long time. The fact that we need to check for synchronized TSCs in the first place is hillarious already. TSC_ADJUST makes the resynchronization attempt at least halfways sensible. Without it, it's just a pile of never going to be correct heuristics with a flood of "this fixes it for my machine (and breaks the rest)" patches. 2) Binary patching Unfortunately RDTSC is only a two byte instruction, but there are enough advanced binary patching tools to deal with that. It might be a completely crazy idea, but I wouldn't dismiss it before trying. Thanks, tglx