Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp480409rdg; Thu, 12 Oct 2023 11:02:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGCgk+dEElRel4l4FGhRDPdEzWsHb7gHAghNXi0rmtNUxoXeni/PdwlMBa5zHOERvaeDgNE X-Received: by 2002:a17:903:110d:b0:1bb:d59d:8c57 with SMTP id n13-20020a170903110d00b001bbd59d8c57mr27579207plh.18.1697133731800; Thu, 12 Oct 2023 11:02:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697133731; cv=none; d=google.com; s=arc-20160816; b=f/TWWKekdoZZS3HzNYBMZSN3WyI92RpNDyg+UNGlBFzOls6doVAONdkEYpDZ+FJeuk 3X+eh86QZ7hHol76j4RvRWonHY3unjr61B5ST7x/bXTofunZzd6hYLMNUF4E9Mfa8KLj 39a/kpmgvoajwu++n8v7d2yJdF5Fyge/VE8S8EHS2T+IoX+uJzcqmYf+09Nxp7hzyd9F GwQkG7ARHbRY7MqOLAB52vLcsnSO6+AEbmuT8X53FpIZ5qDLF6Gsa5UBJx6XLKkkvLpr 8AZa8O4rvV2ENZ3B4REz6OaNN8LzBxeiORbFbLN6WMqMsd/WCEMALSsAnIZd6Fih/qbu Og0w== 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=SC9y0UpEwJeLtyq6Y4MHb2iM/mNi8/I8ouMZ6JwJFxQ=; fh=/Dnf++/2xG0Xi30TGscvcX3UaoYjzLSxPPap0bUcRsE=; b=NlPprdqbcJ6OaQBxD52TJcIncyp7vZDtZVFdlzysxPE2a2c1awVWzR62sFej2LP6nL JI7XgXsATjN/HvXQQe2tm7q4iFDXsqehdGHsZWEZuOZhyGKhMO/Gedfk/pVaBIGM7bmw KzNVA8jOsXdXXcrbvpBIYiIufxpZIXS9IO/UUEew41jkeb0YZdJbQdR3LEcWqsApYs3e 6Dw+Z8XQOl5gExVq8aDdKn5B8bvRbZXFhvbzkaTMLFaCHXzrbkM54kRuluG59uRD8jAH HwvuA+O6cUF42vy2JbH6igkbt0g0/qFtKYcr1Fl2h/GYx1gqP3kuRz+pagLldXj8ynQY 4hrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mgKTGBas; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id j13-20020a170903024d00b001c74876f029si2965587plh.381.2023.10.12.11.02.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 11:02:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mgKTGBas; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 93E19801BFC1; Thu, 12 Oct 2023 11:02:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231256AbjJLSCB (ORCPT + 99 others); Thu, 12 Oct 2023 14:02:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379652AbjJLSB7 (ORCPT ); Thu, 12 Oct 2023 14:01:59 -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 E9FF8BB for ; Thu, 12 Oct 2023 11:01:57 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-53d8320f0easo2167987a12.3 for ; Thu, 12 Oct 2023 11:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697133716; x=1697738516; 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=SC9y0UpEwJeLtyq6Y4MHb2iM/mNi8/I8ouMZ6JwJFxQ=; b=mgKTGBasXJN0MG++dek025ixlXmGNFP57unXOLXjZwncsKUobgn+NQQAt4mXOBNUgO 4e5wKODTAkGneYQOLNaOhu/HcpUhONOCD/e//xABmJ4EyVss4BHNAcXmDyyCy20YBeoF xG6hPSByPoQ/bFw4HGyJCAq/XYMz5JR4zNVxB6/qbvSfEzixen3/Hx8MnQ4hm3t8btGv sqjqpEQRORwJA0qhH0N7gaOznGDthwHV7X9YzckYjsUtXsICVfPsJXLmgLMgjSLFIanY wf0m1+uiRkyTYb3FBXqyBVGWQK8O5eyRLSn0mKkPLdnyp0drKNiqGS6c0YcPqgZ5oKUg 3jbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697133716; x=1697738516; 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=SC9y0UpEwJeLtyq6Y4MHb2iM/mNi8/I8ouMZ6JwJFxQ=; b=wKyq0KMHOUvv8ZA4EYu6yr0gaT7AGJempx8H9Hb2IhfErbTlM1twuoLa070WmjvSYK EJRG+yzKXhWrs4yiHCmXcfaRWtCtBYiMpZtovactQFcHm5wDL8ZWg/iQqbS8RweAZTZ1 59/ovNsAvw/woHlNLQRIpWJkzV/LKE/8THGtAGYolugEjLivKblGeT+NGI3pF8xlDT70 jvzHT7mNcAC8Hk+A+kOW1K3jiCpiZu7sE7sL7pH+NPaP+5/BX+ih6Gx38jmaummVjzZz 5A1V/47URKyn46C5uzQaxIqxdNRldGTAeV1PUigKysLNTKYxh/VER/Wau2ZxDDUpMFhl qHcw== X-Gm-Message-State: AOJu0Yw2r8mjXEHJPcSHvFwqXPvqPii2iTekmAodFJfUlqJnRdeuLD85 EwXNUS+0hXck8EdQpHNODeVqa6TznQAhAXTebio= X-Received: by 2002:aa7:c74a:0:b0:525:7234:52b7 with SMTP id c10-20020aa7c74a000000b00525723452b7mr21411039eds.19.1697133716178; Thu, 12 Oct 2023 11:01:56 -0700 (PDT) MIME-Version: 1.0 References: <20231010164234.140750-1-ubizjak@gmail.com> <0617BB2F-D08F-410F-A6EE-4135BB03863C@vmware.com> In-Reply-To: From: Uros Bizjak Date: Thu, 12 Oct 2023 20:01:44 +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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 12 Oct 2023 11:02:08 -0700 (PDT) On Thu, Oct 12, 2023 at 7:47=E2=80=AFPM Linus Torvalds wrote: > > On Thu, 12 Oct 2023 at 10:10, Linus Torvalds > wrote: > > > > The fix seems to be a simple one-liner, ie just > > > > - asm(__pcpu_op2_##size(op, __percpu_arg(P[var]), "%[val]") = \ > > + asm(__pcpu_op2_##size(op, __percpu_arg(a[var]), "%[val]") = \ > > Nope. That doesn't work at all. > > It turns out that we're not the only ones that didn't know about the > 'a' modifier. > > clang has also never heard of it in this context, and the above > one-liner results in an endless sea of errors, with > > error: invalid operand in inline asm: 'movq %gs:${1:a}, $0' > > Looking around, I think it's X86AsmPrinter::PrintAsmOperand() that is > supposed to handle these things, and while it does have some handling > for 'a', the comment around it says > > case 'a': // This is an address. Currently only 'i' and 'r' are expe= cted. > > and I think our use ends up just confusing the heck out of clang. Of > course, clang also does this: > > case 'P': // This is the operand of a call, treat specially. > PrintPCRelImm(MI, OpNo, O); > return false; > > so clang *already* generates those 'current' accesses as PCrelative, and = I see > > movq %gs:pcpu_hot(%rip), %r13 > > in the generated code. > > End result: clang actually generates what we want just using 'P', and > the whole "P vs a" is only a gcc thing. Ugh, this isn't exactly following Clang's claim that "In general, Clang is highly compatible with the GCC inline assembly extensions, allowing the same set of constraints, modifiers and operands as GCC inline assembly." [1] https://clang.llvm.org/compatibility.html#inline-asm > Why *does* gcc do that silly thing of dropping '(%rip)' from the address,= btw? The documentation says: [p] Print raw symbol name (without syntax-specific prefixes). [P] If used for a function, print the PLT suf-fix and generate PIC code. For example, emit foo@PLT instead of =E2=80=99foo=E2=80=99 for the fu= nction foo(). If used for a constant, drop all syntax-specific prefixes and issue the bare constant. See p above. I'd say that "bare constant" is something without (%pic). Uros.