Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp4053708rdg; Wed, 18 Oct 2023 13:35:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/CEIWmF8srpfePaM+4ZMwJgYczgy7fL7MEhD7ydQ3rb0aY65BcOS+87MhzJRCFSD1wGzn X-Received: by 2002:a17:903:120f:b0:1c7:245a:7fea with SMTP id l15-20020a170903120f00b001c7245a7feamr508646plh.58.1697661304295; Wed, 18 Oct 2023 13:35:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697661304; cv=none; d=google.com; s=arc-20160816; b=hJyCpeg8se57D0HGc6rK4E4Jlj7zDYwhIgGhJwkGZf98Ge6gaOL3/HekJJM2makDsT mHVQg4WZfKg/rb4KsKp3UknIX46NeNei22jgCSfQDsG2Hui23t5rq5c2ir5niLM3Z0XY uG1P/9ou+a2XWRwUn1Lsq7N2nPqeplJHFaX2DxiJrUqeadFHWtvEY+OZ10MxeuPaJN8k mTRxJ+CCnn0/DXKoCEN/KmF1qiJA8tC1elkJpBnyHmpafT4yhMSE+EL/vGjuGQ56afXv J/OL/ZC4tGFw08TynYQDvRcX2Ip0304oXJYfOjO4z6nSuC0Ctc47ErDDzVNa64+5lha1 IKXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=iR5fccMdFmWM7UuROlGRgDSCnsuRPDsroqebJRQmpUE=; fh=3hMqaci1aSMG0AFmuDTcNcT9Fdla45I/j/Dj+Dy/pas=; b=rOoLAPbN1qhZXBqwaCYI1dtlk2WYqcEugVeNZG14WHKGHq9RZQNKgeXervu1tcZ7tk Xl40SGPEIXUaBQkplY73ImUJ1VxW4BJaS2wleQz+DQH5dwXGxP986KDp+q3YtYiveNex C2MiYybUpDwMpvjZuH1tTFFQyC+7eoEDzy80kw18UqLd+lgZt6U4uSlrnNyUuey8qtZ9 YKPgDykYDapqqb84VcZjMtMAHoNnPZBYgUoOgnqhaPGrFgy37nbjc9CoiVfXMMFi8X12 0rJ0lNaFc6tpCONj9gvacVngxr1m+99b1ZZlMWYFc3fM2cX9w1/cu2RXpezmLNE2RqSJ obnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=a5LKEv4f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id 12-20020a170902c10c00b001c62e42ad8bsi629565pli.72.2023.10.18.13.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 13:35:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=a5LKEv4f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DBBD8824C4FC; Wed, 18 Oct 2023 13:34:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232008AbjJRUes (ORCPT + 99 others); Wed, 18 Oct 2023 16:34:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231775AbjJRUeq (ORCPT ); Wed, 18 Oct 2023 16:34:46 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E990EF7 for ; Wed, 18 Oct 2023 13:34:43 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-99de884ad25so1171260266b.3 for ; Wed, 18 Oct 2023 13:34:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1697661282; x=1698266082; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=iR5fccMdFmWM7UuROlGRgDSCnsuRPDsroqebJRQmpUE=; b=a5LKEv4f9Qqcd5tOEPntyB5ff7hKYVRsd1XCi4QYmGlcyyrjrJujU30JCvkF4iHNPi ZD0TonI87yWy4MO8Mcu20gwS0YFCxDrZYcdRtc4g6AtxC/edM7fOAxKfYC8tEE9SQOvg E+6OPCRUbKMDnjrBOQifKjLaSdTO2x5hakMTc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697661282; x=1698266082; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iR5fccMdFmWM7UuROlGRgDSCnsuRPDsroqebJRQmpUE=; b=aDWSfAtBVGwyvupH07Ia0uEsdoP/0svVKCFaXiB76wf4wuSZrrT9p1wAts/iR0+6Fn iVQ63aK489Lo5RYvdDMa/YAxJ+WXTj7n5CEUdj4U+t9bAPc2uTvKG86E97nUB5O4MKyQ g+BWlo0FA9GindRac0w/MOfPyvC0BI0efoMYMoUBZ4NfZPP0ZKEWIsB+3Alc9Vyncwbg Kt80tw2Ye1SnCe2u4ClZHeBqBejkc7XVy0u3YI8iV7WsFF2POcgr4qMQNZoPN99MjVzJ GBUoc6/Z1uIlchKI+Zsu4ihZ2A53tC437JhwpAGrtXJAyB2zOV3uUsqcu1hiokeEP0tC OHlw== X-Gm-Message-State: AOJu0Yyir9ZeNhtT5NJZHzxCBQsFnefE4lRiUxrHtv1AZIIQ1sC0lRc9 Q0EhKcJfXQrHcjELlOcdrixu+58ySPVdFW3zIJzG0VmL X-Received: by 2002:a17:906:db07:b0:9b8:b683:5837 with SMTP id xj7-20020a170906db0700b009b8b6835837mr210372ejb.46.1697661281967; Wed, 18 Oct 2023 13:34:41 -0700 (PDT) Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com. [209.85.218.51]) by smtp.gmail.com with ESMTPSA id h3-20020a1709063b4300b009b9aa8fffdasm2273373ejf.131.2023.10.18.13.34.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Oct 2023 13:34:41 -0700 (PDT) Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-99de884ad25so1171255566b.3 for ; Wed, 18 Oct 2023 13:34:41 -0700 (PDT) X-Received: by 2002:a17:907:7211:b0:9b8:5b0d:b55a with SMTP id dr17-20020a170907721100b009b85b0db55amr254124ejc.54.1697661280825; Wed, 18 Oct 2023 13:34:40 -0700 (PDT) MIME-Version: 1.0 References: <20231010164234.140750-1-ubizjak@gmail.com> <0617BB2F-D08F-410F-A6EE-4135BB03863C@vmware.com> <7D77A452-E61E-4B8B-B49C-949E1C8E257C@vmware.com> <9F926586-20D9-4979-AB7A-71124BBAABD3@vmware.com> <3F9D776E-AD7E-4814-9E3C-508550AD9287@vmware.com> <28B9471C-4FB0-4AB0-81DD-4885C3645E95@vmware.com> In-Reply-To: From: Linus Torvalds Date: Wed, 18 Oct 2023 13:34:23 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 -tip] x86/percpu: Use C for arch_raw_cpu_ptr() To: Uros Bizjak Cc: Nadav Amit , "the arch/x86 maintainers" , Linux Kernel Mailing List , Andy Lutomirski , Brian Gerst , Denys Vlasenko , "H . Peter Anvin" , Peter Zijlstra , Thomas Gleixner , Josh Poimboeuf , Nick Desaulniers Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 18 Oct 2023 13:34:56 -0700 (PDT) On Wed, 18 Oct 2023 at 13:22, Linus Torvalds wrote: > > And yes, sometimes we use actual volatile accesses for them > (READ_ONCE() and WRITE_ONCE()) but those are *horrendous* in general, > and are much too strict. Not only does gcc generally lose its mind > when it sees volatile (ie it stops doing various sane combinations > that would actually be perfectly valid), but it obviously also stops > doing CSE on the loads (as it has to). Note, in case you wonder what I mean by "lose its mind", try this (extremely stupid) test program: void a(volatile int *i) { ++*i; } void b(int *i) { ++*i; } and note that the non-volatile version does addl $1, (%rdi) but the volatile version then refuses to combine the read+write into a rmw instruction, and generates movl (%rdi), %eax addl $1, %eax movl %eax, (%rdi) instead. Sure, it's correct, but it's an example of how 'volatile' ends up disabling a lot of other optimizations than just the "don't remove the access". Doing the volatile as one rmw instruction would still have been very obviously valid - it's still doing a read and a write. You don't need two instructions for that. I'm not complaining, and I understand *why* it happens - compiler writers very understandably go "oh, I'm not touching that". I'm just trying to point out that volatile really screws up code generation even aside from the "access _exactly_ once" issue. So using inline asm and relying on gcc doing (minimal) CSE will then generate better code than volatile ever could, even when we just use a simple 'mov" instruction. At least you get that basic combining effect, even if it's not great. And for memory ops, *not* using volatile is dangerous when they aren't stable. Linus