Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp430543rdg; Thu, 12 Oct 2023 09:33:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXu4MqpbKOjoMiYs42ti92W1v7OL1O8GWq1OCmJkTK0PMNvHANbz32ztLuSjBCv8GulK78 X-Received: by 2002:a05:6358:2616:b0:157:a791:53cc with SMTP id l22-20020a056358261600b00157a79153ccmr27244639rwc.32.1697128435521; Thu, 12 Oct 2023 09:33:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697128435; cv=none; d=google.com; s=arc-20160816; b=wvLLvkRr78oPDaSnsNuBtb/esKF7qtJ/SH85THLqD/gpOXOTKXX6Syaql3lHe117Hk hKZmfAemcJk/xz/iWcTiUuGBiNIkoiP1H8oAPvq+Z7blcCBZVogow/ZrOM85nBRijtoG beJ6I34SBCgD1kTInKeNJXhuAzE5EJOgAu1e7bl3s7zeJtYSbqNCTvKXMLLtKd2Ru6ru RvLkhbtU/Wl/KZrDx1YWG+dU2dqJiTtl37MZpCAjbtR5ib8tiK+IHp6D2K3JUj6noQmm QXidg1P72SRfu/RKvS64L73tvzCxOw2ldia9Lskp96VDWAA3ZY/Y0kk5Uw16CTW+TXMb ajbA== 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=BLyH6yQ7oOXpP9deXgxc3Z6pkd3CfbHZ/Wfl0aSvuj0=; fh=nzKsBgWTayDZeLT+2QeVjDtJqAbCmI+Z4Pl3/plqRts=; b=VkJGqf7pPwZ/lHS6N6goGaA461S2vN0V7+Ez/2FKKAPEH/9ceSyujY6pKay/QyKadc B73zmGMNqyT11HWJ5+IxXjthRSblnF90VXLFYwOwGRDiCi9IHKYZOlSJf1ucXk6Ter3p 14deB1IoT3lpldrzD7h5Ka/1i6+TQSNlPJLUwHvgkwT716LOZgn2dfSgQdgVErOBneOd wJ2q2JAd+btSXeotMSgK6RBZnmlZFDbtIewCzeKUNnZ6z37Yw1AB14JIarzGT/u5mWGm GuWgoTPmsTo64UstiMi3YbwfqqdLj+2fQayj+W+KnkBh/RJQeg6S/NdovXduGDpTypeL WJZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=avpOyrpi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id y29-20020a63181d000000b00578af609d05si2820645pgl.244.2023.10.12.09.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 09:33:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=avpOyrpi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 8C0AE8242F5D; Thu, 12 Oct 2023 09:33:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378723AbjJLQdk (ORCPT + 99 others); Thu, 12 Oct 2023 12:33:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343912AbjJLQdj (ORCPT ); Thu, 12 Oct 2023 12:33:39 -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 5AD58C0 for ; Thu, 12 Oct 2023 09:33:36 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-507975d34e8so320200e87.1 for ; Thu, 12 Oct 2023 09:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697128414; x=1697733214; 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=BLyH6yQ7oOXpP9deXgxc3Z6pkd3CfbHZ/Wfl0aSvuj0=; b=avpOyrpijl49x6OXB9leHSo/KS3iz3cILNKM8FSejNZrQfehuObNzCtaG36s74jQYr 78+oQpZrN75QJv3r5HVKSR9CcRk+8ngBtRSvCyaR2ng5x/gozcllvsmrIrogw5HUpEqA Jg/cSCAz+CdioMCG0Ewxs3Nex6WUC7NjLfST/7j3dVyXpBb1YBZe5oFXK4j6DzS/1C9K +LYGld6k9xVE0T+aOSqV3XMSgw46nqMpzxBW2Jrq1XAkHgVJa24IUTZYvBoLuppdfmQP 5I/QwB7+8Qa1CehzSUJQstROZbwapEP0FRtn0wCC2Mu39E36rwmnFsfOUCO7lq4CYn6S 0KMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697128414; x=1697733214; 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=BLyH6yQ7oOXpP9deXgxc3Z6pkd3CfbHZ/Wfl0aSvuj0=; b=VOdPUvT6cJFlj7ubvZTb0nhtO0qwAXkHRlmWFs9FbV8VVTmuWUVeAPGhQS2ukl/Z+B B04W3rNUSfJUjKKp8y+n91yxD8eJMP/AFOYHXHAPYX5FFVI6f9SOHsLCEwYP3JRUAxq5 pOIYfzA/g6ru1FYTj5vLvrMzbJJlLmX9Fdvdx6725oGRrO3AnSzrLEJmi+7aCe8/x4UD yAYQgFAimt+4Us0MstSZ8GB1pggDCftos2+KmGUqyLOpBFHf/SXJkdrP9ktnisGHuKPt y36t2o034eQ1TdnHtKkqApqrTvx9CNxcVlCO5ugSVFF0DVslfcYB7yAgSE+Ma+ndAVrP VLXg== X-Gm-Message-State: AOJu0Yx5OVnGpDdUHeMh2Fg4FzYen2iRix4enSdWh6nMT9/BswBq77xe Kwrlc42/KqlDN/LQREPi6dpVuQmHzDhVq8vzGas= X-Received: by 2002:ac2:5e21:0:b0:502:ff3b:766f with SMTP id o1-20020ac25e21000000b00502ff3b766fmr17488538lfg.6.1697128414290; Thu, 12 Oct 2023 09:33:34 -0700 (PDT) MIME-Version: 1.0 References: <20231010164234.140750-1-ubizjak@gmail.com> <0617BB2F-D08F-410F-A6EE-4135BB03863C@vmware.com> In-Reply-To: <0617BB2F-D08F-410F-A6EE-4135BB03863C@vmware.com> From: Uros Bizjak Date: Thu, 12 Oct 2023 18:33:22 +0200 Message-ID: Subject: Re: [PATCH v2 -tip] x86/percpu: Use C for arch_raw_cpu_ptr() To: Nadav Amit Cc: Linus Torvalds , "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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 12 Oct 2023 09:33:51 -0700 (PDT) On Thu, Oct 12, 2023 at 5:19=E2=80=AFPM Nadav Amit wrote= : > > > > On Oct 12, 2023, at 12:54 AM, Linus Torvalds wrote: > > > > !! External Email > > > > On Wed, 11 Oct 2023 at 14:33, Uros Bizjak wrote: > >> > >> 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. > > > > Well, maybe I'd like it if I saw what the effect of it was, but that > > patch mentions "sync_mm_rss()" which doesn't actually exist > > (SPLIT_RSS_COUNTING is never defined, the split version is gone and > > hasn't existed since commit f1a7941243c1 "mm: convert mm's rss stats > > into percpu_counter") > > So I added a new version of the current aliasing (well, actually pcpu_hot > in the new version) on top of Uros=E2=80=99s patches, and the effect can = be seen > in many functions. I don=E2=80=99t want to bother with many examples so h= ere is > a common and simple one: > > Currently syscall_exit_work() that starts with: > > 0xffffffff8111e120 <+0>: push %rbp > 0xffffffff8111e121 <+1>: mov %rdi,%rbp > 0xffffffff8111e124 <+4>: push %rbx > 0xffffffff8111e125 <+5>: mov %rsi,%rbx > 0xffffffff8111e128 <+8>: and $0x20,%esi > 0xffffffff8111e12b <+11>: je 0xffffffff8111e143 > 0xffffffff8111e12d <+13>: mov %gs:0x2ac80,%rax > 0xffffffff8111e136 <+22>: cmpb $0x0,0x800(%rax) > 0xffffffff8111e13d <+29>: jne 0xffffffff8111e22a > 0xffffffff8111e143 <+35>: mov %gs:0x2ac80,%rax > 0xffffffff8111e14c <+44>: cmpq $0x0,0x7c8(%rax) > > Using the const-alias changes the beginning of syscall_exit_work to: > > 0xffffffff8111cb80 <+0>: push %r12 > 0xffffffff8111cb82 <+2>: mov %gs:0x7ef0e0f6(%rip),%r12 # 0x2= ac80 > 0xffffffff8111cb8a <+10>: push %rbp > 0xffffffff8111cb8b <+11>: mov %rdi,%rbp > 0xffffffff8111cb8e <+14>: push %rbx > 0xffffffff8111cb8f <+15>: mov %rsi,%rbx > 0xffffffff8111cb92 <+18>: and $0x20,%esi > 0xffffffff8111cb95 <+21>: je 0xffffffff8111cba6 > 0xffffffff8111cb97 <+23>: cmpb $0x0,0x800(%r12) > 0xffffffff8111cba0 <+32>: jne 0xffffffff8111cc7a > 0xffffffff8111cba6 <+38>: cmpq $0x0,0x7c8(%r12) > > So we both see RIP-relative addressing is being used (hence the instructi= on is > one byte shorter) and the reload going away. Just a quick remark here: For some reason existing percpu_stable_op asm uses %P operand modifier. This will drop all syntax-specific prefixes and issue the bare constant. It will also remove the (%rip) suffix. What we want here is a generic %a modifier (See 6.47.2.8 Generic Operand Modifiers [1]) that will substitute a memory reference, with the actual operand treated as the address. In combination with "p" constraint will DTRT and will emit symbol with the (%rip) suffix when available, also when -fpie is in effect. [1] https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc.pdf Uros.