Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3956604rdg; Wed, 18 Oct 2023 10:29:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYZhrlBJVAIzr6ZL4iS9ZCe2NuixNVjlDzUtbScSyhRS5EbMXvuNbvIbP+9OJWh8xHfyKL X-Received: by 2002:a05:6a20:3d93:b0:160:cf09:8019 with SMTP id s19-20020a056a203d9300b00160cf098019mr6348502pzi.32.1697650159117; Wed, 18 Oct 2023 10:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697650159; cv=none; d=google.com; s=arc-20160816; b=uDSv6RALF+k8Owro8okeikq5De61renmpAQhJUuxzLO6QFTpy+EEK4btx4XTgTYm7B VsWqKUG3djxUDkm4FFE7rQj4oU8Nx+7NgGm45Cp6YlgBobD2xD65xbPKTQXqnZtqkdx0 SqGrW5KPYeZVo+AxmJVaxAFVfEW8ICSgxRLt7kgkon6ZM5lvUdPQKIfNLnw4WaDYbAL6 I0gBlhz5ICbHAdLTPK+3VIljZ1VGKoYscJO+BV1vtLtRrQMeRExlFSr4TZycVFwWgyTU th/y0kkPCS3nfDvHxuQ08QDXtQX5hmSNfJIQqHC4SxaZmLQXwmmWvEdzUCye6UmQsIdE 312w== 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=qlsBb8jenRCxdIl7j9zet5It8gScLwOuosdLEhMzLL8=; fh=/Dnf++/2xG0Xi30TGscvcX3UaoYjzLSxPPap0bUcRsE=; b=CfLAeiyuaZDNqC1fHlB4GNXEkfuKlu0i4VTGlgGBbeZ2cdeG45VF6CPY02Ciq2uOni q2fv4dGAtU9JP7SOgxbLxwzDKMtJep/mVX0SJmk0a3+YTZwW8rTJ4aXBeImFlkofsoqY L9iO9u0tl7cO3o4A0f1cvNRTth2AT3DzrVDZ68v6MXLBuNZABNm+lm2JXbCbf5XxkMhC ffVRZiK+NLW3vJ9LGo9q3W3QFnlZ4//vhqBm+XCpzPOHOVj/pr0diqfmgI/V7DGU4KX6 bV2IsCQzxUQ6iHWFQLa+d1YJzd1ULJ6/BDHl7gsLe4APxq70SGp7l4dwe7sQmhesqy4i o1YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hADilJN6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id f10-20020a17090ace0a00b0027d12ed9e08si306231pju.106.2023.10.18.10.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 10:29:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hADilJN6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 03CC48201B2F; Wed, 18 Oct 2023 10:29:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230234AbjJRR3G (ORCPT + 99 others); Wed, 18 Oct 2023 13:29:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230288AbjJRR24 (ORCPT ); Wed, 18 Oct 2023 13:28:56 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D4823C10 for ; Wed, 18 Oct 2023 10:23:30 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-53e751aeb3cso7766168a12.2 for ; Wed, 18 Oct 2023 10:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697649808; x=1698254608; 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=qlsBb8jenRCxdIl7j9zet5It8gScLwOuosdLEhMzLL8=; b=hADilJN66zRTLr7AXEtinqXjYvyWS5u5TqynljlxOCXyHx4GLpnY6fiP2Nt2gPr1tf t8KJs+OoxriN5u3fIbr8ZeDIwOS356uIG1cmQ10eberoU6tndHn8fZuvqU9LlFgQqvzd UyRTbNaXCJoPeYNQS2Gixk1z6ECozA+2bLJBn+1X/oexigN0I9Focc9HSZTxPsQ9WTlT 4g/pmU0PpD+qvkaAIfN4z1edRIkb5vhZlcfQfit0OYGmJZ31fwZlPeJmoXSh6bOfZuCb t7NNnu2C1/hcPMmHlQxinpl3rJ2eqjA2kL160ZQwanQnr4x5TFojdO0n1s3asKxkbd06 rybg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697649808; x=1698254608; 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=qlsBb8jenRCxdIl7j9zet5It8gScLwOuosdLEhMzLL8=; b=FID3FH6UCG+ffQsQWyTdgtGeC/BnDo2E9tK3JLMs5qScRWSpd4Nc6/vZzDKbpMFm/1 n7c3WStD0nk8JXmJljG6Xs7ndJB6drLWvg1eUT8OrMm/YYvbgjecR/+3QwrNBWJ5SZcA Y/gP6Z3OB3ggN76MzY26loD7Uiwf8BXAhy1rU6dKz0pWYLrPJBEmbm5r8DOLJ8FeMasY DmKzosAm0Yj2IUhuV/ViTqA+ONr1zZEWX2OAZ8i1z1zgnGA5xtZBoyJFze/Z6fgMtvoo NE9uRTfGXzPMHxmP9TRbEAnIqFJXf9kw/h759AkEvCozK/AfycXFCfUcjj+ZR+VGbBkk uuEQ== X-Gm-Message-State: AOJu0YxZqK8aez8NBDFGnlPv47t635FW3tJHluXFVZ9MwetEng0rQjrw SxxvMThyPDFx2QSshn+8oOGK9NqykWKsh+P8gRo= X-Received: by 2002:a05:6402:3493:b0:53d:a7ea:225c with SMTP id v19-20020a056402349300b0053da7ea225cmr4865720edc.30.1697649808345; Wed, 18 Oct 2023 10:23:28 -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: Wed, 18 Oct 2023 19:23:16 +0200 Message-ID: Subject: Re: [PATCH v2 -tip] x86/percpu: Use C for arch_raw_cpu_ptr() To: Linus Torvalds 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" 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 morse.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 (morse.vger.email [0.0.0.0]); Wed, 18 Oct 2023 10:29:16 -0700 (PDT) On Wed, Oct 18, 2023 at 6:26=E2=80=AFPM Linus Torvalds wrote: > > On Wed, 18 Oct 2023 at 09:03, Nadav Amit wrote: > > > > Having said that, I am not sure what other usages you have in mind. > > =E2=80=9Ccurrent=E2=80=9D is a pretty obvious straight forward case wit= h considerable > > impact on code generation. There may be additional variables, but it is > > likely that there would be more functions/TU in which they would not be > > constant and would require more refined techniques to avoid mistakes > > such as the use of stale cached values. > > Yeah, I don't think there really are other cases. In processor.h, we have: static __always_inline unsigned long current_top_of_stack(void) { /* * We can't read directly from tss.sp0: sp0 on x86_32 is special in * and around vm86 mode and sp0 on x86_64 is special because of the * entry trampoline. */ return this_cpu_read_stable(pcpu_hot.top_of_stack); } But I don't know how much it is used. Uros. > We do have things that could be considered stable (like > "smp_processor_id()" which is stable as long as preemption or > migration is disabled (or it's in an irq-off section). > > And it might be lovely to optimize those too, *BUT* that would require > that there be a barrier against that optimization that works. > > And if there is anything that this thread has made clear, it's that > the whole 'load from a constant section' doesn't seem to have any sane > barriers. > > So while the CSE for inline asm statements is a bit too weak with that > whole "only CSE within a basic block" thing, the CSE of "load a > constant value from memory" is too *strong*, in that we don't seem to > have _any_ sane way to say "now you need to reload". > > The traditional way we've done that is with our "barrier()" macro, > which does the whole inline asm with a memory clobber, but even that > doesn't act as a barrier for gcc optimizing the constant load. > > Which means that while we'd probably love for the compiere to optimize > smp_processor_id() a bit more, we can't use the 'stable memory > location' trick for it. > > Because I can't think of anything but 'current' that would be _that_ > stable as far as C code is concerned. > > Linus