Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp507274rdb; Thu, 19 Oct 2023 10:21:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWxO/oWrh+CdqEntLKkWaO21bhqd79uPVzyvuO9xJqdX7e2/vkX7xaorIToDg8Nl+6Osgx X-Received: by 2002:a05:6a21:6d94:b0:f0:50c4:4c43 with SMTP id wl20-20020a056a216d9400b000f050c44c43mr3456413pzb.5.1697736110241; Thu, 19 Oct 2023 10:21:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697736110; cv=none; d=google.com; s=arc-20160816; b=jxj1b9SycC3UPgNbeJRD8Ug1Q6bKadJ3Eeolg8UmKW8XJA23eDFWK6HEJPgFJKlPyy VfwEJcjLnVwgdenjwl+UzUDy4dQq9olr89hpCxFQcZW3SQEiZY/cD8esATH/jNregF/y 1Q4X2N96AY9ZeQxew6nsO8lI7XHTTG2+YgCRjO7wiuQZw1t6QVlEAXc2aKYLyGRN0DmC 4lt+viGNjaAdehtSLh1DP8s7h6GfWzr8mc9MswbUR6AQ1AUSKTVs05KdVYrt4SCWNGnl wyyBtmDTZGK0mFSfv5q/fJmDBTPOpfbJu2HruCjSpOO7wAp2x73WmjU00K0R2JugmqMq gIvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Ba/oGqTPfrZodec+lJ/3NDrbOWqxCdK6uYtuTP2TGGA=; fh=TuuuGpTiDGt8cLITKAD9aywCBLE/HV6krcer7Bl+EDo=; b=E0uwz8hNTGbUsTou2amib7UjT8PPtWx5g14Eu1Gc894zQpyyc6DVUAqPml1+oen+gS 9FdzrZfrsHLZ+UQdk+ObohBmRhoK0HC+mAzuwjLDo/yhm7wmAK6ZoiIssHUnLs2lP1eV bdvPQUZn/G9mMQKmU4xzGUJGgZqm2Vc0mpHNSxyDihpJrRfzUdGZY0peGAqTknEcIBAe Ntup0HLRj8x+8G3cO8s5P0QhdU4YHg68uBZSz7VR6SjaVgi7rN1l+ICIvtPeYnb51sc4 6BEE1octcAholYGobTnjre44stNfACthbHTInsftd9+eYWaiEq3TkmZFgfZUGqHftFMF s1pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="afmTc8K/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id q11-20020a632a0b000000b005b7dd20f8c1si38879pgq.20.2023.10.19.10.21.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 10:21:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="afmTc8K/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id DEB8581B454F; Thu, 19 Oct 2023 10:21:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345167AbjJSRVj (ORCPT + 99 others); Thu, 19 Oct 2023 13:21:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235472AbjJSRVi (ORCPT ); Thu, 19 Oct 2023 13:21:38 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28335126 for ; Thu, 19 Oct 2023 10:21:36 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-507d7b73b74so401231e87.3 for ; Thu, 19 Oct 2023 10:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697736094; x=1698340894; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Ba/oGqTPfrZodec+lJ/3NDrbOWqxCdK6uYtuTP2TGGA=; b=afmTc8K/SLzZTpp1+IeUfchAiseqdx1Y2MP9y/prtsVLSHI/WAJ03iwvaQOP4kNzOX iAZZ6qvBi/fSVO54veAsr+dFCiBh2geFJyrMl3Tvx9OyWFPmeTdUIGAmp3w13WnEYV24 NFD1iAblKCGc2jJT3PPcurTdjd4Xhih8khA6SFQqMhijKQ2AeLoiKKabmzc9pAMdV0Sd tUS6JGHC97F6gA6s47mvCZovRgIQVeKZ/IONeRWS4HqxVr1AZpbjWc2R/qlTY/51uJuF wyH19REAmlMK5SqJDq6t6eI8qumh6ZzftsGlHdYS4qGfULmKH/lxPV4CzmUJSqEdLS0m dXNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697736094; x=1698340894; h=content-transfer-encoding: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=Ba/oGqTPfrZodec+lJ/3NDrbOWqxCdK6uYtuTP2TGGA=; b=etMnIXr/QzFFPI97/+MybNOXuUYNmjZ73xH3CbHzwBLxC9IiSZJidnKnuOK93v6sLp H8ElMymwFftDlRT5kq5pPBun5mqG+lZ0XGBJSVy4XzOIbiW7FZ+jv/Jxma/GmiApBvQ0 jvUJW186NIoyJ+EI6Ab6mPve32wlvIHiebOdRs8HvgVsHjqbvNCiEPBq3lEwkpypT2Ea DLnju7cHoBlsNQjYUT1wtwOlzinBAgWrfvHUZXDQOWgiIBO/Zg6Wf9LsNsNMngR+8f/Z xoO577fd4z6uDmy/B3jedFiwvNEOtF7bvTjttNvar2XgaaDp7ViIwNjK3fuhMT7voAp3 W3xQ== X-Gm-Message-State: AOJu0YxQDRvmHeAODVY8dRWgQgiXRa9hTnpfLWiYslESahZ8t5hYKsfO qv2I/NTsKNik+Ug9nQDb+LEFoxrZ+BHl+hZOqEI= X-Received: by 2002:ac2:5a50:0:b0:500:b5db:990b with SMTP id r16-20020ac25a50000000b00500b5db990bmr1944154lfn.47.1697736094137; Thu, 19 Oct 2023 10:21:34 -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: Uros Bizjak Date: Thu, 19 Oct 2023 19:21:22 +0200 Message-ID: Subject: Re: [PATCH v2 -tip] x86/percpu: Use C for arch_raw_cpu_ptr() To: Linus Torvalds Cc: peterz@infradead.org, Nadav Amit , "the arch/x86 maintainers" , Linux Kernel Mailing List , Andy Lutomirski , Brian Gerst , Denys Vlasenko , "H . Peter Anvin" , Thomas Gleixner , Josh Poimboeuf , Nick Desaulniers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 10:21:48 -0700 (PDT) On Thu, Oct 19, 2023 at 7:00=E2=80=AFPM Linus Torvalds wrote: > > On Thu, 19 Oct 2023 at 00:04, Uros Bizjak wrote: > > > > Let me explain how the compiler handles volatile. > > We're talking past each other. > > You are talking about the volatile *memory* ops, and the the > difference that "raw" vs "this" would cause with and without the > "volatile". > > While *I* am now convinced that the memory ops aren't even an option, > because they will generate worse code, because pretty much all users > use the "this" version (which would have to use volatile), Please see [1]. Even with volatile access, with memory ops the compiler can propagate operands, resulting in ~8k code size reduction, and many hundreds (if not thousands) MOVs propagated into subsequent instructions. Please note many code examples in [1]. This is not possible with the asm variant. [1] https://lore.kernel.org/lkml/20231004192404.31733-1-ubizjak@gmail.com/ > Because if we just stick with inline asms, the need for "volatile" > simply goes away. No, the compiler is then free to remove or duplicate the asm (plus other unwanted optimizations), please see the end of chapter 6.47.2.1 in [2]. [2] https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Extended-Asm.html#Volatil= e-1 > The existing volatile on those percpu inline asms is *wrong*. It's a > historical mistake. Please see above. > And with just a plain non-volatile inline asm, the inline asm wins. Please see [1] for the code propagation argument. > It doesn't have the (bad) read-once behavior of a volatile memory op. > > And it also doesn't have the (horrible correctness issue) > rematerialization behavior of a non-volatile memory op. Unfortunately, it does. Without volatile, asm can be rematerialized in the same way as it can be CSEd. OTOH, the memory op with memory-ops approach is casted to volatile in this_* case, so it for sure won't get rematerialized. > A compiler that were to rematerializes an inline asm (instead of > spilling) would be a bad joke. That's not an optimization, that's just > a crazy bad compiler with a code generation bug. But that is what the compiler does without volatile. Thanks, Uros.