From: Peter Zijlstra <peterz@infradead.org>
To: Andrew.Cooper3@citrix.com
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
mhiramat@kernel.org, jpoimboe@redhat.com
Subject: Re: [PATCH 2/2] x86: Shorten RESET_CALL_DEPTH
Date: Mon, 15 May 2023 12:26:18 +0200 [thread overview]
Message-ID: <20230515102618.GF83892@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <0111b953-500e-3716-b349-d5c8012e5220@citrix.com>
On Mon, May 15, 2023 at 10:47:42AM +0100, Andrew.Cooper3@citrix.com wrote:
> On 15/05/2023 10:28 am, Peter Zijlstra wrote:
> > Shrink it by 4 bytes:
> >
> > 0: 31 c0 xor %eax,%eax
> > 2: 48 0f ba e8 3f bts $0x3f,%rax
> > 7: 65 48 89 04 25 00 00 00 00 mov %rax,%gs:0x0
> > #define RESET_CALL_DEPTH \
> > - mov $0x80, %rax; \
> > - shl $56, %rax; \
> > + xor %eax, %eax; \
> > + bts $59, %rax; \
>
> $63 ?
>
> The disassembly looks correct.
Yeah, uhmm, clearly I fixed it somewhere but not on the version I send
out :-(
Too bad we need the RAX.W prefix...
---
Subject: x86: Shorten RESET_CALL_DEPTH
From: Peter Zijlstra <peterz@infradead.org>
Date: Fri Feb 10 10:10:57 CET 2023
RESET_CALL_DEPTH is a pretty fat monster and blows up UNTRAIN_RET to
20 bytes:
19: 48 c7 c0 80 00 00 00 mov $0x80,%rax
20: 48 c1 e0 38 shl $0x38,%rax
24: 65 48 89 04 25 00 00 00 00 mov %rax,%gs:0x0 29: R_X86_64_32S pcpu_hot+0x10
Shrink it by 4 bytes:
0: 31 c0 xor %eax,%eax
2: 48 0f ba e8 3f bts $0x3f,%rax
7: 65 48 89 04 25 00 00 00 00 mov %rax,%gs:0x0
Shrink RESET_CALL_DEPTH_FROM_CALL by 5 bytes by only setting al, the
other bits are shifted out (the same could be done for
RESET_CALL_DEPTH, but the xor+bts sequence has less depencies due to
the zeroing).
Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
arch/x86/include/asm/nospec-branch.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -84,12 +84,12 @@
movq $-1, PER_CPU_VAR(pcpu_hot + X86_call_depth);
#define RESET_CALL_DEPTH \
- mov $0x80, %rax; \
- shl $56, %rax; \
+ xor %eax, %eax; \
+ bts $63, %rax; \
movq %rax, PER_CPU_VAR(pcpu_hot + X86_call_depth);
#define RESET_CALL_DEPTH_FROM_CALL \
- mov $0xfc, %rax; \
+ movb $0xfc, %al; \
shl $56, %rax; \
movq %rax, PER_CPU_VAR(pcpu_hot + X86_call_depth); \
CALL_THUNKS_DEBUG_INC_CALLS
next prev parent reply other threads:[~2023-05-15 10:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-15 9:28 [PATCH 0/2] x86/alternatives: More nops and some shrinkage Peter Zijlstra
2023-05-15 9:28 ` [PATCH 1/2] x86_64: Longer NOPs Peter Zijlstra
2023-05-31 11:57 ` [tip: x86/alternatives] x86/alternatives: Add longer 64-bit NOPs tip-bot2 for Peter Zijlstra
[not found] ` <20230515093020.729622326@infradead.org>
2023-05-15 9:47 ` [PATCH 2/2] x86: Shorten RESET_CALL_DEPTH Andrew.Cooper3
2023-05-15 10:26 ` Peter Zijlstra [this message]
2023-05-31 11:57 ` [tip: x86/alternatives] x86/nospec: " tip-bot2 for Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230515102618.GF83892@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Andrew.Cooper3@citrix.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®