All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Roger Pau Monné" <roger.pau@citrix.com>, "Wei Liu" <wl@xen.org>,
	Xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH 6/8] x86/entry: Track the IST-ness of an entry for the exit paths
Date: Thu, 14 Sep 2023 20:44:06 +0100	[thread overview]
Message-ID: <fb9ec99d-9c76-82ff-9b82-22fff1a62c6c@citrix.com> (raw)
In-Reply-To: <762b58fe-a841-f92c-93a8-77dbb86bf118@suse.com>

On 14/09/2023 10:32 am, Jan Beulich wrote:
> On 13.09.2023 22:27, Andrew Cooper wrote:
>> --- a/xen/arch/x86/x86_64/compat/entry.S
>> +++ b/xen/arch/x86/x86_64/compat/entry.S
>> @@ -117,8 +117,15 @@ compat_process_trap:
>>          call  compat_create_bounce_frame
>>          jmp   compat_test_all_events
>>  
>> -/* %rbx: struct vcpu, interrupts disabled */
>> +/* %rbx: struct vcpu, %r12: ist_exit, interrupts disabled */
>>  ENTRY(compat_restore_all_guest)
>> +
>> +#ifdef CONFIG_DEBUG
>> +        mov   %rsp, %rdi
>> +        mov   %r12, %rsi
>> +        call  check_ist_exit
>> +#endif
>> +
>>          ASSERT_INTERRUPTS_DISABLED
>>          mov   $~(X86_EFLAGS_IOPL | X86_EFLAGS_VM), %r11d
>>          and   UREGS_eflags(%rsp),%r11d
> Without having peeked ahead, is there any use of %r12 going to appear
> on this path? I thought it's only going to be restore_all_xen?

For now, we only need to change behaviour based on ist_exit in
restore_all_xen.

But, we do get here in IST context, and I'm not interested in having to
re-do the analysis to determine if this is safe.  ist_exit is a global
property of exiting Xen, so should be kept correct from the outset.

>
>> --- a/xen/arch/x86/x86_64/entry.S
>> +++ b/xen/arch/x86/x86_64/entry.S
>> @@ -142,10 +142,16 @@ process_trap:
>>  
>>          .section .text.entry, "ax", @progbits
>>  
>> -/* %rbx: struct vcpu, interrupts disabled */
>> +/* %rbx: struct vcpu, %r12: ist_exit, interrupts disabled */
>>  restore_all_guest:
>> -        ASSERT_INTERRUPTS_DISABLED
>>  
>> +#ifdef CONFIG_DEBUG
>> +        mov   %rsp, %rdi
>> +        mov   %r12, %rsi
>> +        call  check_ist_exit
>> +#endif
>> +
>> +        ASSERT_INTERRUPTS_DISABLED
>>          /* Stash guest SPEC_CTRL value while we can read struct vcpu. */
>>          mov VCPU_arch_msrs(%rbx), %rdx
>>          mov VCPUMSR_spec_ctrl_raw(%rdx), %r15d
> Even here I don't think I see a need for the addition. Plus if the check
> is warranted here, is it really necessary for it to live ahead of the
> interrupts-disabled check?

What makes you think there is a relevance to the order of two assertions
in fully irqs-off code?

The checks are in the same order as the comment stating the invariants.

>  Further, seeing that being marco-ized, would
> it make sense to have a CHECK_IST_EXIT macro in case more than a single
> use site remains?
>
>> @@ -1087,6 +1100,10 @@ handle_ist_exception:
>>  .L_ist_dispatch_done:
>>          mov   %r15, STACK_CPUINFO_FIELD(xen_cr3)(%r14)
>>          mov   %bl, STACK_CPUINFO_FIELD(use_pv_cr3)(%r14)
>> +
>> +        /* This is an IST exit */
>> +        mov   $1, %r12
>> +
>>          cmpb  $X86_EXC_NMI, UREGS_entry_vector(%rsp)
>>          jne   ret_from_intr
> Could I talk you into using a less than 7-byte insn here? "or $1, %r12"
> would be 4 bytes, "mov $1, %r12b", "inc %r12", and "not %r12" would be
> just 3. All have certain downsides, yes, but I wonder whether switching
> isn't worth it. Even "mov $1, %r12d" would be at least one byte less,
> without any downsides. And the OR and INC variants would allow the
> remaining 63 bits to be used for another purpose down the road.

This is a 2Hz-at-most path.  The size of one instruction is not
something to care about.

But I did mean to use the %r12d form, so I'll go with that.  Everything
else depends on the behaviour of earlier logic.

~Andrew


  reply	other threads:[~2023-09-14 19:44 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13 20:27 [PATCH 0/8] x86/spec-ctrl: AMD DIV fix, and VERW prerequisite bugfixes Andrew Cooper
2023-09-13 20:27 ` [PATCH 1/8] x86/spec-ctrl: Fix confusion between SPEC_CTRL_EXIT_TO_XEN{,_IST} Andrew Cooper
2023-09-14  6:56   ` Jan Beulich
2023-09-14  9:54     ` Andrew Cooper
2023-09-13 20:27 ` [PATCH 2/8] x86/spec-ctrl: Fold DO_SPEC_CTRL_EXIT_TO_XEN into it's single user Andrew Cooper
2023-09-14  6:59   ` Jan Beulich
2023-09-13 20:27 ` [PATCH 3/8] x86/spec-ctrl: Turn the remaining SPEC_CTRL_{ENTRY,EXIT}_* into asm macros Andrew Cooper
2023-09-14  7:20   ` Jan Beulich
2023-09-13 20:27 ` [PATCH 4/8] x86/spec-ctrl: Extend all SPEC_CTRL_{ENTER,EXIT}_* comments Andrew Cooper
2023-09-14  7:58   ` Jan Beulich
2023-09-14 19:23     ` Andrew Cooper
2023-09-15  7:07       ` Jan Beulich
2023-09-15  9:27         ` Andrew Cooper
2023-09-13 20:27 ` [PATCH 5/8] x86/entry: Adjust restore_all_xen to hold stack_end in %r14 Andrew Cooper
2023-09-14  8:51   ` Jan Beulich
2023-09-14 19:28     ` Andrew Cooper
2023-09-13 20:27 ` [PATCH 6/8] x86/entry: Track the IST-ness of an entry for the exit paths Andrew Cooper
2023-09-14  9:32   ` Jan Beulich
2023-09-14 19:44     ` Andrew Cooper [this message]
2023-09-15  7:13       ` Jan Beulich
2023-09-15  9:30         ` Andrew Cooper
2023-09-13 20:27 ` [PATCH 7/8] x86/spec-ctrl: Issue VERW during IST exit to Xen Andrew Cooper
2023-09-14 10:01   ` Jan Beulich
2023-09-14 19:49     ` Andrew Cooper
2023-09-15  7:15       ` Jan Beulich
2023-09-13 20:27 ` [PATCH 8/8] x86/spec-ctrl: Mitigate the Zen1 DIV leakge Andrew Cooper
2023-09-13 20:43   ` Andrew Cooper
2023-09-13 21:12   ` Marek Marczykowski-Górecki
2023-09-14 10:52   ` Jan Beulich
2023-09-14 20:01     ` Andrew Cooper
2023-09-14 13:12   ` Jason Andryuk
2023-09-14 20:05     ` Andrew Cooper

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=fb9ec99d-9c76-82ff-9b82-22fff1a62c6c@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=roger.pau@citrix.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.