Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp837318rdg; Fri, 13 Oct 2023 02:40:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/zje5QUFphwbj0W6/zS/lm5P/IXMzeRwcE2lpCd2mOvQuq7swhARuC4NoQ38AI9j/t4HC X-Received: by 2002:a05:6a00:2404:b0:68a:45a1:c0ee with SMTP id z4-20020a056a00240400b0068a45a1c0eemr29497142pfh.15.1697190008801; Fri, 13 Oct 2023 02:40:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697190008; cv=none; d=google.com; s=arc-20160816; b=CHoUhsGDTvWWzOi3fcJ1PWjXMhzO5anu/fN68oSZtxazD7z00nUWMI8RuWZIsUqujk vTatEbbBr9yTMehHeqjN00a/FNnWUqep1tsj8z5Gzdty7quZAhF6gVGKFPilCCrJDeSc wwBUtyYQW8uparilzzBgIwUvTlbS79IDtBQ4abFPxTnvBEDHszR0/keo21VeYciCXy0H /17iw8+7j1tVFtaVRQ4oYMWCiQNX9L+BzK2wA/HeS0Cb6wExc6zJZcV8KdkgK+LSULoB D3dMLLPRsoXaYP8y3S4WfA6iwmfv4FV3AFHTfjl8zbvpvF6yoCF1XAPUuwtR6WeWyGeb Px6Q== 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=YrzadSgsgTlC4uFU2lvzbmqnsROGfT+yADAPxLvJUbc=; fh=/Dnf++/2xG0Xi30TGscvcX3UaoYjzLSxPPap0bUcRsE=; b=MKOs//Nq34k2zqP9NWzWLCI/ZsUTJenQ8xIPOR7ui+Te08zHPMt1t9jNM0zHpTw8c+ kcLeXX5W2pZNQafgFjfTUMsLh4ECux46VDRxyJcNQ5+bHFlfhdeoeL/0E/s4beeVmsZn zQkrSWwsePggjDuSJCeqNhuNzHdZvopATGepIqKgdibNTkGCMvSlsc+49/CRWsXHCFAo izA7vT9FEr7FG6S82wuUPNi3/X2A2hT7nIExKAuxSbz4kVjMmN1b6hsRB36Q/WNUpslo ejKui/g3oJ5KH8cT8eKCiIt/CVjot2It3+i9Vk1bhfx18Aw+3xqgVm3TlpNNwZVMo2Td l/Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Pfbs7NoI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id g14-20020a056a000b8e00b0068e0fcf8c28si17638420pfj.336.2023.10.13.02.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 02:40:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Pfbs7NoI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 3DAB58229D0D; Fri, 13 Oct 2023 02:39:52 -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 S231426AbjJMJjR (ORCPT + 99 others); Fri, 13 Oct 2023 05:39:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231283AbjJMJiR (ORCPT ); Fri, 13 Oct 2023 05:38:17 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 466AD95 for ; Fri, 13 Oct 2023 02:38:15 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-533c5d10dc7so3341835a12.3 for ; Fri, 13 Oct 2023 02:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697189894; x=1697794694; 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=YrzadSgsgTlC4uFU2lvzbmqnsROGfT+yADAPxLvJUbc=; b=Pfbs7NoInWO6/jaxpi3xTSQoVdUqFnQxOpCODoAWd+ypoSBz2xwHaSkpSRuZ/1rZxY f74fqcHMTw+IHNZj1+qpWQ2lKcPxtM1wSrDnWVebDLtoj1c/yBvruBx0oUYZZyOzjJcv AIdw9VY0GyeqUfww4KNAc++WTy7xBDq7D3GJJSRHBFUS6L+1xM1ckQuRh10cglfkYf90 z1yOLqRXkfw+n6HDsrSc7Ekk0yW9p0ncORONUiHRWAF2g6i+iSC99hI14iuFmFJfOzbz lp3zcgyiSIXD6AKTSfcFKaw0Vf9Ve137DYxBg6sFaxrkS7Id9G58lJa7R1gRnO/bcRhB Mtiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697189894; x=1697794694; 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=YrzadSgsgTlC4uFU2lvzbmqnsROGfT+yADAPxLvJUbc=; b=HpNNPYmjW42qe8FFhw2aUZQDIfrwmILSW21bLvn6XE9F7KeWHpBzqp7wBJomg2jhR6 5dEH3j8rxtXncMLURjQJhGDd6TSW4ISyKZuWHBQePZuHMDRzg9F1H9wPOzN62rpf1dgW CYcRFlHlBiBXkwxAUgzqi5zjz6jRJStGsOUZwSKTYBOzFtz6ZJk5hLXMJz2hodZsATph IaL1A/mdfRYOt5Cw9cQzE+EqlJKsHDu2PyzcnN6U+Bq2HhDYEqGXRSU6C5XxQbd9n2NK TPHwCKibukYUpnCjNwOdYU9ijf1OfT33neX4uxvHaSrKdYTscCFIEp9cF/Myqrx8MSkK dmJw== X-Gm-Message-State: AOJu0Yz96hWTQVb7eeYV+hs64HyhZuaP02ZHT+yzJ8+4DUZ4TqxjFMnN 0bTL/8BKX4AB4QvmLjdpiwNJcwMDkp/eBWP0+jw= X-Received: by 2002:a50:ee84:0:b0:532:bed7:d0dd with SMTP id f4-20020a50ee84000000b00532bed7d0ddmr25307669edr.5.1697189893461; Fri, 13 Oct 2023 02:38:13 -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: Fri, 13 Oct 2023 11:38:01 +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: multipart/mixed; boundary="000000000000b76f50060795d072" 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]); Fri, 13 Oct 2023 02:39:53 -0700 (PDT) --000000000000b76f50060795d072 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Oct 12, 2023 at 8:01=E2=80=AFPM Uros Bizjak wro= te: > > 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 ex= pected. > > > > 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, an= d 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." For added fun I obtained some old clang: $ clang --version clang version 11.0.0 (Fedora 11.0.0-3.fc33) and tried to compile this: int m; __seg_gs int n; void foo (void) { asm ("# %a0 %a1" :: "p" (&m), "p" (&n)); asm ("# %P0 %P1" :: "p" (&m), "p" (&n)); } clang-11: # m n # m n clang-11 -fpie: # m(%rip) n(%rip) # m n clang-11 -m32: # m n # m n gcc: # m(%rip) n(%rip) # m n gcc -fpie: # m(%rip) n(%rip) # m n gcc -m32: # m n # m n Please find attached a patch that should bring some order to this issue. The patch includes two demonstration sites, the generated code for mem_encrypt_identity.c does not change while the change in percpu.h brings expected 4kB code size reduction. Uros. --000000000000b76f50060795d072 Content-Type: text/plain; charset="US-ASCII"; name="memref.diff.txt" Content-Disposition: attachment; filename="memref.diff.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lnof0qsl0 ZGlmZiAtLWdpdCBhL2FyY2gveDg2L2luY2x1ZGUvYXNtL2NvbXBpbGVyLmggYi9hcmNoL3g4Ni9p bmNsdWRlL2FzbS9jb21waWxlci5oCm5ldyBmaWxlIG1vZGUgMTAwNjQ0CmluZGV4IDAwMDAwMDAw MDAwMC4uMzdjOWRlYTUwYmU2Ci0tLSAvZGV2L251bGwKKysrIGIvYXJjaC94ODYvaW5jbHVkZS9h c20vY29tcGlsZXIuaApAQCAtMCwwICsxLDE2IEBACisvKiBTUERYLUxpY2Vuc2UtSWRlbnRpZmll cjogR1BMLTIuMCAqLworI2lmbmRlZiBfX0FTTV9YODZfQ09NUElMRVJfSAorI2RlZmluZSBfX0FT TV9YODZfQ09NUElMRVJfSAorCisvKgorICogU3Vic3RpdHV0ZSBhIG1lbW9yeSByZWZlcmVuY2Us IHdpdGggdGhlIGFjdHVhbAorICogb3BlcmFuZCB0cmVhdGVkIGFzIHRoZSBhZGRyZXNzLgorICov CisKKyNpZmRlZiBfX2NsYW5nX18KKyNkZWZpbmUgX19tZW1yZWYoeCkJCSIlUCIgI3gKKyNlbHNl CisjZGVmaW5lIF9fbWVtcmVmKHgpCQkiJWEiICN4CisjZW5kaWYKKworI2VuZGlmIC8qIF9fQVNN X1g4Nl9DT01QSUxFUl9IICovCmRpZmYgLS1naXQgYS9hcmNoL3g4Ni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