Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp899964rdg; Fri, 13 Oct 2023 04:54:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZvhJVQN5qY5ARWFnbQslliBIkeauhHfe/jqaAO0B/GICr9l3Pmn6RVvMJsYSK1NN83HBy X-Received: by 2002:a05:6a00:14d4:b0:68e:3fe6:2c82 with SMTP id w20-20020a056a0014d400b0068e3fe62c82mr27730252pfu.34.1697198039490; Fri, 13 Oct 2023 04:53:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697198039; cv=none; d=google.com; s=arc-20160816; b=nOccIIbUy7G4nxplhzC6KCI5zuhyM9iXFM6WtCdxxXE2EKNvaFBRICN6LBpfyPrn8m uJkrbZxSJnHodfen/v02rRhQQHOCWueXGnPczjIyINpZxqv6ngvJuVaLzdFK2MV/SH1K rgzMdjSwMuwtLxckI0uh9ta5clG19Ypfu0R5gnDTrxcowC4w7Pjl2etawfpzgSMMc+0v e1Um7MmVXqoDnDWuv+CFQwIajqw/ONdHopRD/f7uLPddUzV2rohKBUqdB2THaytu6GzA H6IW1svhGzkhT6hcLQlXKev9Ew4ILNzf5DfD68jQDR+PE4wiJK5POXrR5wyBNfT1c+Bd aN/A== 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=D5wBQDCPhCWlWzMxSldR9pNHTZGfP5MCipasrlMdn8s=; fh=/Dnf++/2xG0Xi30TGscvcX3UaoYjzLSxPPap0bUcRsE=; b=g3675l9jrdSklf0wEwSFNa77EH5X2qWYg3DSt8+2lfVFZa3/DwjBDz98iUo5Mn6Wjr Bo3sHotZ0Yht74gYVNUloS6gDui1pMGDtZW98tZRNTkzHf0Bi4bsK9Pl1OEddR2SHAz1 SqZV4I5hTotyUv3Mnk9TFT+H2+10pxesC8YkTJHhPDG1wUviyAvfUjUs9nzjsmOYd0WF WMCkW86wSlvn5jdEuROy6lxsMWBJ4Iluw7CQzxsYEUd+RqFmJ+ZuMrCdyLJZ+2ztiJ9f NmHoTHyHg9JVI94MnlwKYH+dDRQyw6cmK9txHG+k92q7YKlX6WC94IRmZGj+puhgnmuK UHaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WmgDiWTH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id k4-20020a056a00168400b00690fc88e4acsi17901172pfc.228.2023.10.13.04.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:53:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WmgDiWTH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id D8E0180952F3; Fri, 13 Oct 2023 04:53:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbjJMLxr (ORCPT + 99 others); Fri, 13 Oct 2023 07:53:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbjJMLxp (ORCPT ); Fri, 13 Oct 2023 07:53:45 -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 F0BB5BF for ; Fri, 13 Oct 2023 04:53:43 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-53d9b94731aso3756463a12.1 for ; Fri, 13 Oct 2023 04:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697198022; x=1697802822; 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=D5wBQDCPhCWlWzMxSldR9pNHTZGfP5MCipasrlMdn8s=; b=WmgDiWTHm0HI7ulXprXIHWb7GNlKrsRONGYtMbGSL+HIDcqVpWqx0mD5sCi5L54EpW VcZ7hVG9zR25qnymWxhTJyyK/3/yYJYFDox6K/2G5MfFo+CWpx5LQ6NdmvSDnin9sXAL /SN4WCFU/Up4InF3mYGjs7Q74yEkx4gNbF446A7Wf7yb9EEawO/8d+3WBs3lIM/kNFFC QtqrHEdvVTjFX2hBZD47L1HqPMj5L9k+0jbEBNo1dKsW9D9qMGvsf2mAY80y7vvhWdMA l00qTgJe1o6VKaZSghJcILSSCbZ4JgAQ3nwyOlTezIOo4BgkfatS1tIbo0HHnrkniq5u eGbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697198022; x=1697802822; 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=D5wBQDCPhCWlWzMxSldR9pNHTZGfP5MCipasrlMdn8s=; b=usANt4GFlpcuENNaYY/b/NtQBJ/hPl+mycYuEk56xk0pIGygMneM6hLorRu5AHJzjC YvyR81T+vPzq6Mui5Eykq/f6yi8c8Vr+ll0NWTjiKSdjXSosrQRz2lNfmhLMAiVINAUi 59zXYIFoKqUBFl94hEaBi/Gh3q04HegbYNlqkc6qjOFn9IHzT1b3/TFlTfnZ9/lrHSzB P+CljvjmZvmpivXHsOFKAV9grpeOYGiaIfMam7KyhzNlJVuPfMDwzPUHPrnkAcyS/OgM NHRcTCjNf7bRfi3W1BFdEf/dYaGqt8abgW5ZZvZs+jBJzpAKOmS35GvC2e8uC2NF0zNw ulXQ== X-Gm-Message-State: AOJu0YyIPE4+kuwQ/q0KUVxkLldCUwVzr5HMjmipuKfI5LPK3XVLNLsA EZQnCe/tXYdwGJcMERixGFRr16xxnCx70haF1LY= X-Received: by 2002:a05:6402:3228:b0:53d:b7e7:301b with SMTP id g40-20020a056402322800b0053db7e7301bmr7470667eda.24.1697198022179; Fri, 13 Oct 2023 04:53:42 -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 13:53:29 +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="00000000000039dbe6060797b562" 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 fry.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 (fry.vger.email [0.0.0.0]); Fri, 13 Oct 2023 04:53:57 -0700 (PDT) --00000000000039dbe6060797b562 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Oct 13, 2023 at 11:38=E2=80=AFAM Uros Bizjak wr= ote: > > On Thu, Oct 12, 2023 at 8:01=E2=80=AFPM Uros Bizjak w= rote: > > > > 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 = expected. > > > > > > 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. Maybe we should go with what Clang expects. %a with "i" constraint is also what GCC handles, because =E2=80=98i=E2=80=99: An immediate integer operand (one with constant value)= is allowed. This includes symbolic constants whose values will be known only at assembly time or later. Attached patch patches both cases: the generated code for mem_encrypt_identity.c does not change while the change in percpu.h brings expected 4kB code size reduction. I think this is the correct solution that will work for both compilers. Uros. --00000000000039dbe6060797b562 Content-Type: text/plain; charset="US-ASCII"; name="memref-2.diff.txt" Content-Disposition: attachment; filename="memref-2.diff.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lnojvewg0 ZGlmZiAtLWdpdCBhL2FyY2gveDg2L2luY2x1ZGUvYXNtL3BlcmNwdS5oIGIvYXJjaC94ODYvaW5j bHVkZS9hc20vcGVyY3B1LmgKaW5kZXggNjBlYTc3NTVjMGZlLi4xMmYzN2I5NTFmYTcgMTAwNjQ0 Ci0tLSBhL2FyY2gveDg2L2luY2x1ZGUvYXNtL3BlcmNwdS5oCisrKyBiL2FyY2gveDg2L2luY2x1 ZGUvYXNtL3BlcmNwdS5oCkBAIC0xNzUsOSArMTc1LDkgQEAgZG8gewkJCQkJCQkJCVwKICNkZWZp bmUgcGVyY3B1X3N0YWJsZV9vcChzaXplLCBvcCwgX3ZhcikJCQkJXAogKHsJCQkJCQkJCQlcCiAJ X19wY3B1X3R5cGVfIyNzaXplIHBmb192YWxfXzsJCQkJCVwKLQlhc20oX19wY3B1X29wMl8jI3Np emUob3AsIF9fZm9yY2VfcGVyY3B1X2FyZyhQW3Zhcl0pLCAiJVt2YWxdIikJXAorCWFzbShfX3Bj cHVfb3AyXyMjc2l6ZShvcCwgX19mb3JjZV9wZXJjcHVfYXJnKGFbdmFyXSksICIlW3ZhbF0iKSBc CiAJICAgIDogW3ZhbF0gX19wY3B1X3JlZ18jI3NpemUoIj0iLCBwZm9fdmFsX18pCQkJXAotCSAg ICA6IFt2YXJdICJwIiAoJihfdmFyKSkpOwkJCQkJXAorCSAgICA6IFt2YXJdICJpIiAoJihfdmFy KSkpOwkJCQkJXAogCSh0eXBlb2YoX3ZhcikpKHVuc2lnbmVkIGxvbmcpIHBmb192YWxfXzsJCQlc CiB9KQogCmRpZmYgLS1naXQgYS9hcmNoL3g4Ni9tbS9tZW1fZW5jcnlwdF9pZGVudGl0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