Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1097678rdg; Wed, 11 Oct 2023 14:33:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcNxxKnQ7PkB2ODmtjfINiyJwpsBzSRDQxfdixpbAEDKzdEKNVQ7D6/CSsLAgIAb4T5Gh8 X-Received: by 2002:a05:6870:11cf:b0:1e9:ae68:fda3 with SMTP id 15-20020a05687011cf00b001e9ae68fda3mr773174oav.12.1697060003291; Wed, 11 Oct 2023 14:33:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697060003; cv=none; d=google.com; s=arc-20160816; b=zcEQwZY483nvudsgAJN1zs2CiHAhPN/hbcSe38MTiW6c5CeSBRW5BdbmU4aKPm+vrH zX2KC5dxTZuIgQBGxwUKZnpmot68JAmn1WW1M2BfARbWCO32o0WXxhrLRDq/NIzmeOMg gxcy6fv3mZe6mRPcbw27ZrC5oPhtjtu9COve69F1nmyJXaIGF4Hruane2bHrOJjfVlFW polO2jg+fiJc5m76mEu2URv72t+f7edGJvsQlXtvImXN3es1OcPR4OXxWuqxwtZLhODD QsGNwz4+OHGczapp2LnKi8aXis82At+/ep/GmKbn2kqZSbh+WVSeUypUrlcOmsupoblb F4xA== 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=TKrYYRaD2RfNLNfOhiIpEBPF24FekdqyFgqdK3sdhAs=; fh=mJqdYMh8CzBfg3ihPMu0yse4AllbKeOWrz2p0BKTJU4=; b=Q8FiRshOP/Uydi1PcxvnkFQLXU9TD9d7+mYfRZBNPVHr0KT5WSDWsIg9Ra0iWq9of9 3aPLmXAmv0rKjCZmCIiuQTJdmY7uHZpDGMIXbGmuhvdC1DaCni45yhqMvx64qPUuykFc c0dRP9JVCMBJ2qw2Hpa5kRYCeugCNPBpBVvOaVQjje6JGj/Fs5Pq1V0jTXGNOUUmEIJG 8OQaKaVpzYLnq5OlQFRq67CKbktYCd01JGBQ3e0JzdhZQNDcICalAW9yfi5aCPgH3tUj 9AQCaBXMTG7+BCRZU6s77y8jctIdzgCA3ENKZJuDIat0PceqCgfBoVhWV/wtKo/wjP+A eQKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="g9Itb/3g"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id t185-20020a6381c2000000b005774a3b3efdsi660189pgd.301.2023.10.11.14.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:33:23 -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=@gmail.com header.s=20230601 header.b="g9Itb/3g"; 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; 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 lipwig.vger.email (Postfix) with ESMTP id 76DD181BF31C; Wed, 11 Oct 2023 14:33:20 -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 S235164AbjJKVdE (ORCPT + 99 others); Wed, 11 Oct 2023 17:33:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233582AbjJKVdC (ORCPT ); Wed, 11 Oct 2023 17:33:02 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 283B1A9 for ; Wed, 11 Oct 2023 14:32:59 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-523100882f2so541767a12.2 for ; Wed, 11 Oct 2023 14:32:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697059977; x=1697664777; 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=TKrYYRaD2RfNLNfOhiIpEBPF24FekdqyFgqdK3sdhAs=; b=g9Itb/3gLoAMUfddb6LnLSUqreDyU5pZV6IYZnMgwVqqEk4xj4hSHO3fdk9pWvOlmn OydHTKU8qYGqDIpWIl53LFnv86wKBfPIGdXIL5UlUBkk5pmnVhFH54OvTpfVu9uWghXv fsnmxE24wIp/pKGJRWOIamk5gyE0tuL1pIOHzA6N1wq6fHbDcyFodjcaJTUWjG9oAdQf b9n2rSlnTBgmEg2lKHul2MCKeitn7ecCHRqM5uJKnnTcK9xYigDkBA4Evhok/nJw/OBu mTc6lzXXRW7u/FZND32Ls8nCmzKa6o1Vdw4mbNnQCG14oPc7M/4Q/lvsmXR63a7uy/xI 21uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697059977; x=1697664777; 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=TKrYYRaD2RfNLNfOhiIpEBPF24FekdqyFgqdK3sdhAs=; b=cZ/Xm5rwqaDFdyJzPeJ+UlOtkoTkvx9hAgPTAYnYLUiyTiwY7Ug0iprVhyJ5RzD+Tp v0nAj0lDa6SGmx5uGbmpWKJV65htLLtLZkdffgufa6/pGnT65fQZIyCnO8kkSv/qzBST MHvcV4Bsdu+15urpqFvM3dMCCbr/GqhkIoO0i17pSkCjmPAbxa6wLCvQQEjWY5qjxIQo hVxwc0U6cPYO0jludXZie6r+8eqDMTtbgnlaGXYCPjwkUxUU62hOAzhtN55Nhn089a5K rdrRSlABIfPbc3p/vZMxaDwvsFopavcthHsHf6eXLRAsyPq04dRrs8RSEg81fytSNG0t XXzA== X-Gm-Message-State: AOJu0YyVI2PBUE3qsc3E/fPlGdl2H/99re2DVRNyaxHPGFZEvhc6lmbH jm2EAlUpTLtYtTyNs03ura2KjzlEtcN7woIsSVY= X-Received: by 2002:a05:6402:b58:b0:53d:d4a0:3154 with SMTP id bx24-20020a0564020b5800b0053dd4a03154mr2582378edb.31.1697059977240; Wed, 11 Oct 2023 14:32:57 -0700 (PDT) MIME-Version: 1.0 References: <20231010164234.140750-1-ubizjak@gmail.com> In-Reply-To: From: Uros Bizjak Date: Wed, 11 Oct 2023 23:32:45 +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 Content-Type: multipart/mixed; boundary="0000000000001b39a80607779171" X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no 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, 11 Oct 2023 14:33:20 -0700 (PDT) X-Spam-Level: ** --0000000000001b39a80607779171 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Oct 11, 2023 at 9:37=E2=80=AFPM Linus Torvalds wrote: > > On Wed, 11 Oct 2023 at 00:42, Nadav Amit wrote: > > > > You are correct. Having said that, for =E2=80=9Ccurrent" we may be able= to do something > > better, as regardless to preemption =E2=80=9Ccurrent" remains the same,= and > > this_cpu_read_stable() does miss some opportunities to avoid reloading = the > > value from memory. > > It would be lovely to generate even better code, but that > this_cpu_read_stable() thing is the best we've come up with. It > intentionally has *no* memory inputs or anything else that might make > gcc think "I need to re-do this". The attached patch makes this_cpu_read_stable a bit better by using rip-relative addressing. Immediate reduction of text section by 4kB and also makes the kernel some more PIE friendly. > For example, instead of using "m" as a memory input, it very > intentionally uses "p", to make it clear that that it just uses the > _pointer_, not the memory location itself. > > That's obviously a lie - it actually does access memory - but it's a > lie exactly because of the reason you mention: even when the memory > location changes due to preemption (or explicit scheduling), it always > changes back to the the value we care about. > > So gcc _should_ be able to CSE it in all situations, but it's entirely > possible that gcc then decides to re-generate the value for whatever > reason. It's a cheap op, so it's ok to regen, of course, but the > intent is basically to let the compiler re-use the value as much as > possible. > > But it *is* probably better to regenerate the value than it would be > to spill and re-load it, and from the cases I've seen, this all tends > to work fairly well. Reading the above, it looks to me that we don't want to play games with "const aliased" versions of current_task [1], as proposed by Nadav in his patch series. The current version of this_cpu_read_stable() (plus the attached trivial patch) is as good as it can get. [1] https://lore.kernel.org/lkml/20190823224424.15296-8-namit@vmware.com/ Uros. --0000000000001b39a80607779171 Content-Type: text/plain; charset="US-ASCII"; name="p.diff.txt" Content-Disposition: attachment; filename="p.diff.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lnm9o9ol0 ZGlmZiAtLWdpdCBhL2Fy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