All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>,
	xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH 2/4] x86: eliminate most XPTI entry/exit code when it's not in use
Date: Tue, 30 Jan 2018 12:02:48 +0000	[thread overview]
Message-ID: <1b5fd587-f11b-129e-78df-d7b3760d8f27@citrix.com> (raw)
In-Reply-To: <5A671E8302000078001A17C4@prv-mh.provo.novell.com>

On 23/01/18 10:37, Jan Beulich wrote:
> Introduce a synthetic feature flag to use alternative instruction
> patching to NOP out all code on entry/exit paths other than those
> involved in NMI/#MC handling (the patching logic can't properly handle
> those paths yet). Having NOPs here is generally better than using
> conditional branches.

Given my other series, I'd prefer to fix the IST paths rather than
introduce yet-more workarounds.

> --- a/xen/arch/x86/x86_64/compat/entry.S
> +++ b/xen/arch/x86/x86_64/compat/entry.S
> @@ -189,7 +189,7 @@ ENTRY(compat_post_handle_exception)
>  
>  /* See lstar_enter for entry register state. */
>  ENTRY(cstar_enter)
> -        /* sti could live here when we don't switch page tables below. */
> +        ALTERNATIVE nop, sti, X86_FEATURE_NO_XPTI

I do not think the complexity of of altering the position of sti
outweighs the fractional extra delay which would result from
unilaterally having the sti later.  Furthermore, if you really are
concerned about microoptimising this, you don't want a singlebyte nop here.

>          CR4_PV32_RESTORE
>          movq  8(%rsp),%rax /* Restore %rax. */
>          movq  $FLAT_KERNEL_SS,8(%rsp)
> @@ -201,6 +201,7 @@ ENTRY(cstar_enter)
>          SAVE_ALL
>  
>          GET_STACK_END(bx)
> +.Lcstar_cr3_start:
>          mov   STACK_CPUINFO_FIELD(xen_cr3)(%rbx), %rcx
>          neg   %rcx
>          jz    .Lcstar_cr3_okay
> @@ -210,6 +211,12 @@ ENTRY(cstar_enter)
>          movq  $0, STACK_CPUINFO_FIELD(xen_cr3)(%rbx)
>  .Lcstar_cr3_okay:
>          sti
> +.Lcstar_cr3_end:
> +        .pushsection .altinstructions, "a", @progbits
> +        altinstruction_entry .Lcstar_cr3_start, .Lcstar_cr3_start, \
> +                             X86_FEATURE_NO_XPTI, \
> +                             (.Lcstar_cr3_end - .Lcstar_cr3_start), 0
> +        .popsection

It occurs to me that this would be far more legible if we had an alt_nop
wrapper.  Reusing .Lcstar_cr3_start and a length of 0 isn't obvious.

> --- a/xen/arch/x86/x86_64/entry.S
> +++ b/xen/arch/x86/x86_64/entry.S
> @@ -46,7 +47,6 @@ restore_all_guest:
>          movabs $DIRECTMAP_VIRT_START, %rcx
>          mov   %rdi, %rax
>          and   %rsi, %rdi
> -        jz    .Lrag_keep_cr3

This looks like a functional change?

>          and   %r9, %rsi
>          add   %rcx, %rdi
>          add   %rcx, %rsi
> @@ -473,6 +499,7 @@ ENTRY(dom_crash_sync_extable)
>  ENTRY(common_interrupt)
>          SAVE_ALL CLAC
>  
> +.Lintr_cr3_start:
>          GET_STACK_END(14)
>          mov   STACK_CPUINFO_FIELD(xen_cr3)(%r14), %rcx
>          mov   %rcx, %r15
> @@ -492,9 +519,20 @@ ENTRY(common_interrupt)
>          CR4_PV32_RESTORE
>          movq %rsp,%rdi
>          callq do_IRQ
> +.Lintr_cr3_restore:
>          mov   %r15, STACK_CPUINFO_FIELD(xen_cr3)(%r14)
> +.Lintr_cr3_end:
>          jmp ret_from_intr
>  
> +        .pushsection .altinstructions, "a", @progbits
> +        altinstruction_entry .Lintr_cr3_restore, .Lintr_cr3_restore, \
> +                             X86_FEATURE_NO_XPTI, \
> +                             (.Lintr_cr3_end - .Lintr_cr3_restore), 0
> +        altinstruction_entry .Lintr_cr3_start, .Lintr_cr3_start, \
> +                             X86_FEATURE_NO_XPTI, \
> +                             (.Lintr_cr3_okay - .Lintr_cr3_start), 0

This is now getting very complicated to follow.  Is it just for IST
safety and liable to disappear?  If not, I think we need a different
way,as this is now saying "sporadic instructions inside this block, but
not all of them, turn into nops".

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-01-30 12:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-23 10:33 [PATCH 0/4] x86: reduce Meltdown band-aid overhead a little further Jan Beulich
2018-01-23 10:36 ` [PATCH 1/4] x86: remove CR reads from exit-to-guest path Jan Beulich
2018-01-30 11:01   ` Andrew Cooper
2018-01-30 11:10     ` Jan Beulich
2018-02-05 16:47       ` Andrew Cooper
2018-01-23 10:37 ` [PATCH 2/4] x86: eliminate most XPTI entry/exit code when it's not in use Jan Beulich
2018-01-30 12:02   ` Andrew Cooper [this message]
2018-01-30 13:51     ` Jan Beulich
2018-02-05 17:28       ` Andrew Cooper
2018-02-06  9:52         ` Jan Beulich
2018-01-23 10:38 ` [PATCH 3/4] x86: re-organize toggle_guest_*() Jan Beulich
2018-01-30 13:45   ` Andrew Cooper
2018-01-23 10:38 ` [PATCH 4/4] x86: avoid double CR3 reload when switching to guest user mode Jan Beulich
2018-01-30 14:29   ` Andrew Cooper
2018-01-31 10:12     ` Jan Beulich
2018-02-05 17:37       ` Andrew Cooper
2018-02-06 10:01         ` Jan Beulich

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=1b5fd587-f11b-129e-78df-d7b3760d8f27@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --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.