Message ID | 20231120153419.3045-1-ubizjak@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6359:6513:b0:164:83eb:24d7 with SMTP id sk19csp2371361rwb; Mon, 20 Nov 2023 07:35:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcU2Xz5auRgTxXbrV2arliM/fzGLrxx6rPemsMcgC6i2rwk5DlFj2yPg7vuv2R2tEZ5toX X-Received: by 2002:a17:902:f68a:b0:1cf:677d:964d with SMTP id l10-20020a170902f68a00b001cf677d964dmr1297822plg.25.1700494513314; Mon, 20 Nov 2023 07:35:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700494513; cv=none; d=google.com; s=arc-20160816; b=XL0ocB220TpqfEDhuGFM5q0Y+fb1WZRXRT0iWvknxRZVT3BtQ6Xn3+bd9aaTEY+fXK QvxLOAj1Hwa1opEfJz1ih/BW3fnmlu5CISL8QtxFg/QHgmtI/eLTSlQw/UjeU+PRfs2y WWWgkdnpFtx5NzjpgecyX1/aee+CSDfWQpwtLhpG+kAwkDcshuZJCo/TcPF8S0TpUvF3 DzOx5gTFcInNxU+c4jLK7mxQFAeK5QSp0ltf7uAlsti84X3eYXe4Z4rJM9qK6rUm8YGB RMo9z51wVLRRII9nNeE64OQWWl69fURHMZIWSz/i5PWiPXJgx0/I12/SdNVB1+LnP/w1 8MQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3urVBxbF5NZPUeIYke5inWHKIb6xfBZ0lmHUZJ/m1IY=; fh=26H8/YMwOEIvUVwzOWEUxwSuJMLfoacFvRlzImAZUM0=; b=IRwkUHHXLc5rp13GkdamXiEAS2rruU3FbFvnQpRGMbNenPA61bz2dVRpaiCDhzHSYL M3kuHxxIaPgLuX5gfjmG+Zhyjne9LTHHWcofk47k3EFMkkIP2hss2E+NeDRRn/5QCi9u DKRX4r7sUKb6MfpKvaNrcPpuhVORRft5h0xTL1np0tA6j2EDtA8wL+QClxac5ZALzRp/ jtPhyVnn00Lrm1v6RwITa2bsoRGeU5xLYrhNcLReyzNV93Sh6ZojZMgyIRWvQXdtWmew WqS6fn6WQddAv+DxIA/q6HhPMZNo68MObTNqzAhKSbhU/sX5Eh4C40j89zcm2GcYVpUF ph+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FtTUpU2X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id ij27-20020a170902ab5b00b001c9fb3b55f0si7741890plb.652.2023.11.20.07.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 07:35:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FtTUpU2X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 1E8FC807F4BD; Mon, 20 Nov 2023 07:34:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234313AbjKTPel (ORCPT <rfc822;heyuhang3455@gmail.com> + 27 others); Mon, 20 Nov 2023 10:34:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234303AbjKTPej (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 20 Nov 2023 10:34:39 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A53DB4 for <linux-kernel@vger.kernel.org>; Mon, 20 Nov 2023 07:34:31 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-332c46d5988so888040f8f.1 for <linux-kernel@vger.kernel.org>; Mon, 20 Nov 2023 07:34:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700494470; x=1701099270; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3urVBxbF5NZPUeIYke5inWHKIb6xfBZ0lmHUZJ/m1IY=; b=FtTUpU2X5cQJWbcF8Cs8LgCW4n4FHQt/+tEUA4LrtBvFR9od4YCVNzsRd5YitYrExP 7aKJw07oDLEEctj37088vIHugH3lTAf2ZG/XipwDljyeTqfhkXKxRgm1Rpkpn1vhQmSo tRlCNTpwS9H9ynXFDIZhg2depIcoeoNzVpHJUIUhEnttucdHk0+q/XfEHwgrGivQT605 QN7tIBOhxL/Eg3F9FqTqmet1A9OCozZfzrKELvsoR9YVx5AsMMCi0zpj2vpWz1E+O4Ps YDC9S895601pk2idqRpJavrvV/AIK1fOhFIaRvvOZ/BCjnKZdWwPpn3SZ9Zllw7zulm7 wgog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700494470; x=1701099270; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3urVBxbF5NZPUeIYke5inWHKIb6xfBZ0lmHUZJ/m1IY=; b=WZ8Xp6sSm7NtzR7ey3MZFMPGtLEPfO3Y7KGuGaH2QkG9vcQSsXoqV21xG0/rHBB59I olNOBQq/Vy3VGmM6jxBEtmr8DD4KxI8zFBYk6KFYUAAf9BkPOqSa0YcZl5a+owqpbg+C fKP2xfmlVFKqxaE09HDt2oar+JW1EyWXmWZo23fhCTxmnl8Zgqs/x4AShLNEwxNZPBLG Xc8Mt3l0DI9OOlqmgYZLiRnCQaB0eTzfS5+/ArHWorWq8xtAmXiLVJUgocQ1r2EE2UaG aXnHBvPWhir+sfV45hKuLxP+iJiV7/sRa8b3FpKlr4wYQrbP7JOTJ77yL3WMnsA/kVRw d/4Q== X-Gm-Message-State: AOJu0YyA+DDy0/gXFS//rafO0xUld45IRcAgF0djjKbPHwtD1IrW0s8l O5+Fk0bMwx3dpixkGD2yQRE= X-Received: by 2002:a5d:6d0a:0:b0:32f:c5ea:72ac with SMTP id e10-20020a5d6d0a000000b0032fc5ea72acmr5924188wrq.46.1700494469688; Mon, 20 Nov 2023 07:34:29 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id v9-20020a5d5909000000b0032f9688ea48sm11555870wrd.10.2023.11.20.07.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 07:34:29 -0800 (PST) From: Uros Bizjak <ubizjak@gmail.com> To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak <ubizjak@gmail.com>, Linus Torvalds <torvalds@linux-foundation.org>, Dave Hansen <dave.hansen@linux.intel.com>, Andy Lutomirski <luto@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com> Subject: [PATCH] x86/mm/encrypt: Use %a asm operand modifier to obtain %rip-relative address Date: Mon, 20 Nov 2023 16:33:50 +0100 Message-ID: <20231120153419.3045-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 20 Nov 2023 07:34:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783097734788258760 X-GMAIL-MSGID: 1783097734788258760 |
Series |
x86/mm/encrypt: Use %a asm operand modifier to obtain %rip-relative address
|
|
Commit Message
Uros Bizjak
Nov. 20, 2023, 3:33 p.m. UTC
The "a" asm operand modifier substitutes a memory reference, with the
actual operand treated as address. For x86_64, when a symbol is
provided, the "a" modifier emits "sym(%rip)" instead of "sym".
Clang allows only "i" and "r" operand constraints with an "a" modifier,
so the patch normalizes the modifier/constraint pair to "a"/"i"
which is consistent between both compilers.
No functional change intended.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
arch/x86/mm/mem_encrypt_identity.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
Comments
On Mon, Nov 20, 2023 at 04:33:50PM +0100, Uros Bizjak wrote: > The "a" asm operand modifier substitutes a memory reference, with the > actual operand treated as address. For x86_64, when a symbol is > provided, the "a" modifier emits "sym(%rip)" instead of "sym". > > Clang allows only "i" and "r" operand constraints with an "a" modifier, > so the patch normalizes the modifier/constraint pair to "a"/"i" s/the patch normalizes/normalize/ > which is consistent between both compilers. > > No functional change intended. > > Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> > Cc: Dave Hansen <dave.hansen@linux.intel.com> > Cc: Andy Lutomirski <luto@kernel.org> > Cc: Peter Zijlstra <peterz@infradead.org> > Cc: Thomas Gleixner <tglx@linutronix.de> > Cc: Ingo Molnar <mingo@kernel.org> > Cc: Borislav Petkov <bp@alien8.de> > Cc: "H. Peter Anvin" <hpa@zytor.com> > Signed-off-by: Uros Bizjak <ubizjak@gmail.com> > --- > arch/x86/mm/mem_encrypt_identity.c | 16 ++++------------ > 1 file changed, 4 insertions(+), 12 deletions(-) > > diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c > index d73aeb16417f..6a351fdd1b39 100644 > --- a/arch/x86/mm/mem_encrypt_identity.c > +++ b/arch/x86/mm/mem_encrypt_identity.c > @@ -346,9 +346,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp) > * We're running identity mapped, so we must obtain the address to the > * SME encryption workarea using rip-relative addressing. > */ > - asm ("lea sme_workarea(%%rip), %0" > - : "=r" (workarea_start) > - : "p" (sme_workarea)); > + asm ("lea %a1, %0" : "=r" (workarea_start) : "i" (sme_workarea)); Yeah, I saw that particular subthread today. Are you sure this "a" modifier DTRT with all gcc version we support? I.e., from 5.1 onwards... Just making sure. Thx.
On Mon, Nov 20, 2023 at 6:15 PM Borislav Petkov <bp@alien8.de> wrote: > > On Mon, Nov 20, 2023 at 04:33:50PM +0100, Uros Bizjak wrote: > > The "a" asm operand modifier substitutes a memory reference, with the > > actual operand treated as address. For x86_64, when a symbol is > > provided, the "a" modifier emits "sym(%rip)" instead of "sym". > > > > Clang allows only "i" and "r" operand constraints with an "a" modifier, > > so the patch normalizes the modifier/constraint pair to "a"/"i" > > s/the patch normalizes/normalize/ > > > which is consistent between both compilers. > > > > No functional change intended. > > > > Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> > > Cc: Dave Hansen <dave.hansen@linux.intel.com> > > Cc: Andy Lutomirski <luto@kernel.org> > > Cc: Peter Zijlstra <peterz@infradead.org> > > Cc: Thomas Gleixner <tglx@linutronix.de> > > Cc: Ingo Molnar <mingo@kernel.org> > > Cc: Borislav Petkov <bp@alien8.de> > > Cc: "H. Peter Anvin" <hpa@zytor.com> > > Signed-off-by: Uros Bizjak <ubizjak@gmail.com> > > --- > > arch/x86/mm/mem_encrypt_identity.c | 16 ++++------------ > > 1 file changed, 4 insertions(+), 12 deletions(-) > > > > diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c > > index d73aeb16417f..6a351fdd1b39 100644 > > --- a/arch/x86/mm/mem_encrypt_identity.c > > +++ b/arch/x86/mm/mem_encrypt_identity.c > > @@ -346,9 +346,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp) > > * We're running identity mapped, so we must obtain the address to the > > * SME encryption workarea using rip-relative addressing. > > */ > > - asm ("lea sme_workarea(%%rip), %0" > > - : "=r" (workarea_start) > > - : "p" (sme_workarea)); > > + asm ("lea %a1, %0" : "=r" (workarea_start) : "i" (sme_workarea)); > > Yeah, I saw that particular subthread today. > > Are you sure this "a" modifier DTRT with all gcc version we support? > > I.e., from 5.1 onwards... Yes [1]. [1] https://godbolt.org/z/aWe7b16rT Thanks, Uros.
On Mon, Nov 20, 2023 at 08:58:29PM +0100, Uros Bizjak wrote: > On Mon, Nov 20, 2023 at 6:15 PM Borislav Petkov <bp@alien8.de> wrote: > > > > On Mon, Nov 20, 2023 at 04:33:50PM +0100, Uros Bizjak wrote: > > > The "a" asm operand modifier substitutes a memory reference, with the > > > actual operand treated as address. For x86_64, when a symbol is > > > provided, the "a" modifier emits "sym(%rip)" instead of "sym". > > > > > > Clang allows only "i" and "r" operand constraints with an "a" modifier, > > > so the patch normalizes the modifier/constraint pair to "a"/"i" > > > > s/the patch normalizes/normalize/ > > > > > which is consistent between both compilers. > > > > > > No functional change intended. > > > > > > Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> > > > Cc: Dave Hansen <dave.hansen@linux.intel.com> > > > Cc: Andy Lutomirski <luto@kernel.org> > > > Cc: Peter Zijlstra <peterz@infradead.org> > > > Cc: Thomas Gleixner <tglx@linutronix.de> > > > Cc: Ingo Molnar <mingo@kernel.org> > > > Cc: Borislav Petkov <bp@alien8.de> > > > Cc: "H. Peter Anvin" <hpa@zytor.com> > > > Signed-off-by: Uros Bizjak <ubizjak@gmail.com> > > > --- > > > arch/x86/mm/mem_encrypt_identity.c | 16 ++++------------ > > > 1 file changed, 4 insertions(+), 12 deletions(-) > > > > > > diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c > > > index d73aeb16417f..6a351fdd1b39 100644 > > > --- a/arch/x86/mm/mem_encrypt_identity.c > > > +++ b/arch/x86/mm/mem_encrypt_identity.c > > > @@ -346,9 +346,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp) > > > * We're running identity mapped, so we must obtain the address to the > > > * SME encryption workarea using rip-relative addressing. > > > */ > > > - asm ("lea sme_workarea(%%rip), %0" > > > - : "=r" (workarea_start) > > > - : "p" (sme_workarea)); > > > + asm ("lea %a1, %0" : "=r" (workarea_start) : "i" (sme_workarea)); > > > > Yeah, I saw that particular subthread today. > > > > Are you sure this "a" modifier DTRT with all gcc version we support? > > > > I.e., from 5.1 onwards... > > Yes [1]. > > [1] https://godbolt.org/z/aWe7b16rT But Clang generates RIP-relative load only starting from version 15. Clange 11 claimed to be supported.
On Tue, Nov 21, 2023 at 10:05 AM Kirill A. Shutemov <kirill@shutemov.name> wrote: > > On Mon, Nov 20, 2023 at 08:58:29PM +0100, Uros Bizjak wrote: > > On Mon, Nov 20, 2023 at 6:15 PM Borislav Petkov <bp@alien8.de> wrote: > > > > > > On Mon, Nov 20, 2023 at 04:33:50PM +0100, Uros Bizjak wrote: > > > > The "a" asm operand modifier substitutes a memory reference, with the > > > > actual operand treated as address. For x86_64, when a symbol is > > > > provided, the "a" modifier emits "sym(%rip)" instead of "sym". > > > > > > > > Clang allows only "i" and "r" operand constraints with an "a" modifier, > > > > so the patch normalizes the modifier/constraint pair to "a"/"i" > > > > > > s/the patch normalizes/normalize/ > > > > > > > which is consistent between both compilers. > > > > > > > > No functional change intended. > > > > > > > > Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> > > > > Cc: Dave Hansen <dave.hansen@linux.intel.com> > > > > Cc: Andy Lutomirski <luto@kernel.org> > > > > Cc: Peter Zijlstra <peterz@infradead.org> > > > > Cc: Thomas Gleixner <tglx@linutronix.de> > > > > Cc: Ingo Molnar <mingo@kernel.org> > > > > Cc: Borislav Petkov <bp@alien8.de> > > > > Cc: "H. Peter Anvin" <hpa@zytor.com> > > > > Signed-off-by: Uros Bizjak <ubizjak@gmail.com> > > > > --- > > > > arch/x86/mm/mem_encrypt_identity.c | 16 ++++------------ > > > > 1 file changed, 4 insertions(+), 12 deletions(-) > > > > > > > > diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c > > > > index d73aeb16417f..6a351fdd1b39 100644 > > > > --- a/arch/x86/mm/mem_encrypt_identity.c > > > > +++ b/arch/x86/mm/mem_encrypt_identity.c > > > > @@ -346,9 +346,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp) > > > > * We're running identity mapped, so we must obtain the address to the > > > > * SME encryption workarea using rip-relative addressing. > > > > */ > > > > - asm ("lea sme_workarea(%%rip), %0" > > > > - : "=r" (workarea_start) > > > > - : "p" (sme_workarea)); > > > > + asm ("lea %a1, %0" : "=r" (workarea_start) : "i" (sme_workarea)); > > > > > > Yeah, I saw that particular subthread today. > > > > > > Are you sure this "a" modifier DTRT with all gcc version we support? > > > > > > I.e., from 5.1 onwards... > > > > Yes [1]. > > > > [1] https://godbolt.org/z/aWe7b16rT > > But Clang generates RIP-relative load only starting from version 15. > Clange 11 claimed to be supported. Huh, what a bummer... The patch is retracted then. Thanks, Uros.
diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c index d73aeb16417f..6a351fdd1b39 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -346,9 +346,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp) * We're running identity mapped, so we must obtain the address to the * SME encryption workarea using rip-relative addressing. */ - asm ("lea sme_workarea(%%rip), %0" - : "=r" (workarea_start) - : "p" (sme_workarea)); + asm ("lea %a1, %0" : "=r" (workarea_start) : "i" (sme_workarea)); /* * Calculate required number of workarea bytes needed: @@ -582,15 +580,9 @@ void __init sme_enable(struct boot_params *bp) * identity mapped, so we must obtain the address to the SME command * line argument data using rip-relative addressing. */ - asm ("lea sme_cmdline_arg(%%rip), %0" - : "=r" (cmdline_arg) - : "p" (sme_cmdline_arg)); - asm ("lea sme_cmdline_on(%%rip), %0" - : "=r" (cmdline_on) - : "p" (sme_cmdline_on)); - asm ("lea sme_cmdline_off(%%rip), %0" - : "=r" (cmdline_off) - : "p" (sme_cmdline_off)); + asm ("lea %a1, %0" : "=r" (cmdline_arg) : "i" (sme_cmdline_arg)); + asm ("lea %a1, %0" : "=r" (cmdline_on) : "i" (sme_cmdline_on)); + asm ("lea %a1, %0" : "=r" (cmdline_off) : "i" (sme_cmdline_off)); if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT)) active_by_default = true;