Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6253702rdb; Thu, 14 Dec 2023 12:36:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzza4BYlfIOTmVhfxYDRZdU9LjIzAznKHXzcZqfQVZOZOez1sYx2eiCA1udAU/cwsCH+Xr X-Received: by 2002:a05:6a21:a5a4:b0:18f:fcc5:4c4f with SMTP id gd36-20020a056a21a5a400b0018ffcc54c4fmr5110371pzc.40.1702586201668; Thu, 14 Dec 2023 12:36:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702586201; cv=none; d=google.com; s=arc-20160816; b=RE/3pQ6oPUaTOvIxh7m9antOYFy+QgSlAkBQm2llFkkNMlUraNl/v5axNFlsTy0Ty4 Vot3KmN/tIiGjA56k7wsxvegnBZsg3e2TLO3LGKvJZytrRIBrGNNck5PpuGSX4PRYB+t OMb5jGaVk2RXo1FxuwnCG/9p53xEPY4XVexP9V/j6z1ODI174bh5hXklG2P+63nKsGnL YnjzqAQsVvjnfA6OUIUdRJ/jbBf8BXVHkB3akEx8F1b1piph/TH70tCh8Ap/Vaty/E4c 91dbiFyeItDcBOlVh18H9DN1xLyOlY0t8R+2kcGxegV/ZRfv3TwPIajxDBAa8MKpJ3KL ZEUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=5FMjJRYiiZckKtTIj9zaZrWi8vKUflTh4DmLTKZvBJc=; fh=JnmPWmgzBVXFNCVT5PLF0Zk+bQCYgGE3k9ZGPWXgV7w=; b=Wpa6cKVKqaq5WNbrWD8Mu+FvJVTNTRMNSEmkSudHA2NRNnwA0rsBEZMFYuyCgTuaUb kOBWvZ/kJJOgNOFQJ1CPHLcx2f4VQaN/GUhK0dQ3HnLP2r7/X6ETO6lANfJdCyJfh9IS 53ahr518jCz9HeaDWL+Ota6ARdGTMRrlMUaH9l0MaQ2AYMdd3WInujDVwPcgfearF0g/ FXSvsm3b0gKA1tTTmlSen/kFAksi00nVwVaE0OXXmq/gY1lo06qjdAhkD9D292sEch1o f3Fuy0HEPTL3a7PdiD5CPD61O0MFemuNfIJHJUTLso1K/42RRaZN4ga2C2sU/lplMnwf vVJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-76-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id me17-20020a17090b17d100b0028b24e56588si386263pjb.64.2023.12.14.12.36.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:36:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-76-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76-linux.lists.archive=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A93B8B21ADB for ; Thu, 14 Dec 2023 20:36:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCC7A6D1C5; Thu, 14 Dec 2023 20:35:52 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A3C136D1AD; Thu, 14 Dec 2023 20:35:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B920C433C8; Thu, 14 Dec 2023 20:35:48 +0000 (UTC) Date: Thu, 14 Dec 2023 15:36:36 -0500 From: Steven Rostedt To: Linus Torvalds Cc: "linux-arch@vger.kernel.org" , LKML , Linux Trace Kernel , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: Re: [PATCH] ring-buffer: Remove 32bit timestamp logic Message-ID: <20231214153636.655e18ce@gandalf.local.home> In-Reply-To: References: <20231213211126.24f8c1dd@gandalf.local.home> <20231213214632.15047c40@gandalf.local.home> <20231214115614.2cf5a40e@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 14 Dec 2023 11:44:55 -0800 Linus Torvalds wrote: > On Thu, 14 Dec 2023 at 08:55, Steven Rostedt wrote: > > > > And yes, this does get called in NMI context. > > Not on an i486-class machine they won't. You don't have a local apic > on those, and they won't have any NMI sources under our control (ie > NMI does exist, but we're talking purely legacy NMI for "motherboard > problems" like RAM parity errors etc) Ah, so we should not worry about being in NMI context without a 64bit cmpxchg? > > > I had a patch that added: > > > > + /* ring buffer does cmpxchg, make sure it is safe in NMI context */ > > + if (!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) && > > + (unlikely(in_nmi()))) { > > + return NULL; > > + } > > CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG doesn't work on x86 in this context, > because the issue is that yes, there's a safe 'cmpxchg', but that's > not what you want. Sorry, that's from another patch that I combined into this one that I added in case there's architectures that have NMIs but need to avoid cmpxchg, as this code does normal long word cmpxchg too. And that change *should* go to you and stable. It's either just luck that things didn't crash on those systems today. Or it happens so infrequently, nobody reported it. > > You want the save cmpxchg64, which is an entirely different beast. Understood, but this code has both. It's just that the "special" code I'm removing does the 64-bit cmpxchg. > > And honestly, I don't think that NMI_SAFE_CMPXCHG covers the > double-word case anywhere else either, except purely by luck. I still need to cover the normal cmpxchg. I'll keep that a separate patch. > > In mm/slab.c, we also use a double-wide cmpxchg, and there the rule > has literally been that it's conditional on > > (a) system_has_cmpxchg64() existing as a macro > > (b) using that macro to then gate - at runtime - whether it actually > works or not > > I think - but didn't check - that we essentially only enable the > two-word case on x86 as a result, and fall back to the slow case on > all other architectures - and on the i486 case. > > That said, other architectures *do* have a working double-word > cmpxchg, but I wouldn't guarantee it. For example, 32-bit arm does > have one using ldrexd/strexd, but that only exists on arm v6+. > > And guess what? You'll silently get a "disable interrupts, do it as a > non-atomic load-store" on arm too for that case. And again, pre-v6 arm > is about as relevant as i486 is, but my point is, that double-word > cmpxchg you rely on simply DOES NOT EXIST on 32-bit platforms except > under special circumstances. > > So this isn't a "x86 is the odd man out". This is literally generic. > > > Now back to my original question. Are you OK with me sending this to you > > now, or should I send you just the subtle fixes to the 32-bit rb_time_* > > code and keep this patch for the merge window? > > I'm absolutely not taking some untested random "let's do 64-bit > cmpxchg that we know is broken on 32-bit using broken conditionals" > shit. > > What *would* work is that slab approach, which is essentially > > #ifndef system_has_cmpxchg64 > #define system_has_cmpxchg64() false > #endif > > ... > if (!system_has_cmpxchg64()) > return error or slow case > > do_64bit_cmpxchg_case(); > > (although the slub case is much more indirect, and uses a > __CMPXCHG_DOUBLE flag that only gets set when that define exists etc). > > But that would literally cut off support for all non-x86 32-bit architectures. > > So no. You need to forget about the whole "do a 64-bit cmpxchg on > 32-bit architectures" as being some kind of solution in the short > term. But do all archs have an implementation of cmpxchg64, even if it requires disabling interrupts? If not, then I definitely cannot remove this code. If they all have an implementation, where some is just very slow, then that is also perfectly fine. The only time cmpxchg64 gets called is on the slow path, which is if an event is interrupted by an interrupt, and that interrupt writes an event to the same buffer. This doesn't happen often, and if it requires disabling interrupts, then it shouldn't be much notice. I just want to avoid the case that it will simply break, which is the NMI case. In which case, would: if (!system_has_cmpxchg64() && in_nmi()) return NULL; Be OK? -- Steve