All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaron Lewis <aaronlewis@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, jmattson@google.com, zxwang42@gmail.com,
	marcorr@google.com, seanjc@google.com, jroedel@suse.de,
	varad.gautam@suse.com
Subject: Re: [PATCH kvm-unit-tests 7/9] x86: get rid of ring0stacktop
Date: Thu, 21 Oct 2021 23:08:01 +0000	[thread overview]
Message-ID: <CAAAPnDHGEJP8Ss2M3KxVHT=MnHrbb-3=RAdpQVXzKyx9KWpRvw@mail.gmail.com> (raw)
In-Reply-To: <20211021114910.1347278-8-pbonzini@redhat.com>

> --- a/lib/x86/usermode.c
> +++ b/lib/x86/usermode.c
> @@ -47,8 +47,8 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector,
>         }
>
>         asm volatile (
> -                       /* Backing Up Stack in rdi */
> -                       "mov %%rsp, %%rdi\n\t"
> +                       /* Prepare kernel SP for exception handlers */
> +                       "mov %%rsp, %[rsp0]\n\t"
>                         /* Load user_ds to DS and ES */
>                         "mov %[user_ds], %%ax\n\t"
>                         "mov %%ax, %%ds\n\t"
> @@ -92,9 +92,10 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector,
>                         "int %[kernel_entry_vector]\n\t"
>                         /* Kernel Mode */
>                         "ret_to_kernel:\n\t"
> -                       "mov %%rdi, %%rsp\n\t"
> +                       "mov %[rsp0], %%rsp\n\t"
>                         :
> -                       "+a"(rax)
> +                       "+a"(rax),
> +                       [rsp0]"=m"(tss.rsp0),
>                         :

The compiler didn't like the comma:
-                       [rsp0]"=m"(tss.rsp0),
+                       [rsp0]"=m"(tss.rsp0)

>                         [arg1]"m"(arg1),
>                         [arg2]"m"(arg2),

> --- a/x86/umip.c
> +++ b/x86/umip.c
> @@ -124,7 +124,7 @@ static noinline int do_ring3(void (*fn)(const char *), const char *arg)
>                   "mov %%dx, %%es\n\t"
>                   "mov %%dx, %%fs\n\t"
>                   "mov %%dx, %%gs\n\t"
> -                 "mov %%" R "sp, %%" R "cx\n\t"
> +                 "mov %%" R "sp, %[sp0]\n\t" /* kernel sp for exception handlers */
>                   "push" W " %%" R "dx \n\t"
>                   "lea %[user_stack_top], %%" R "dx \n\t"
>                   "push" W " %%" R "dx \n\t"
> @@ -133,8 +133,6 @@ static noinline int do_ring3(void (*fn)(const char *), const char *arg)
>                   "push" W " $1f \n\t"
>                   "iret" W "\n"
>                   "1: \n\t"
> -                 "push %%" R "cx\n\t"   /* save kernel SP */
> -
>  #ifndef __x86_64__
>                   "push %[arg]\n\t"
>  #endif
> @@ -142,13 +140,15 @@ static noinline int do_ring3(void (*fn)(const char *), const char *arg)
>  #ifndef __x86_64__
>                   "pop %%ecx\n\t"
>  #endif
> -
> -                 "pop %%" R "cx\n\t"
>                   "mov $1f, %%" R "dx\n\t"
>                   "int %[kernel_entry_vector]\n\t"
>                   ".section .text.entry \n\t"
>                   "kernel_entry: \n\t"
> -                 "mov %%" R "cx, %%" R "sp \n\t"
> +#ifdef __x86_64__
> +                 "mov %[sp0], %%" R "sp\n\t"
> +#else
> +                 "add $(5 * " S "), %%esp\n\t"
> +#endif
>                   "mov %[kernel_ds], %%cx\n\t"
>                   "mov %%cx, %%ds\n\t"
>                   "mov %%cx, %%es\n\t"
> @@ -157,7 +157,12 @@ static noinline int do_ring3(void (*fn)(const char *), const char *arg)
>                   "jmp *%%" R "dx \n\t"
>                   ".section .text\n\t"
>                   "1:\n\t"
> -                 : [ret] "=&a" (ret)
> +                 : [ret] "=&a" (ret),
> +#ifdef __x86_64__
> +                   [sp0] "=m" (tss.rsp0),
> +#else
> +                   [sp0] "=m" (tss.esp0),
> +#endif
>                   : [user_ds] "i" (USER_DS),

Same here:
-                   [sp0] "=m" (tss.rsp0),
-                   [sp0] "=m" (tss.esp0),
+                   [sp0] "=m" (tss.rsp0)
+                   [sp0] "=m" (tss.esp0)

>                     [user_cs] "i" (USER_CS),
>                     [user_stack_top]"m"(user_stack[sizeof(user_stack) -
> --
> 2.27.0
>
>

  reply	other threads:[~2021-10-21 23:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21 11:49 [PATCH v3 kvm-unit-tests 0/8] x86: Move IDT, GDT and TSS to C code Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 1/9] x86: cleanup handling of 16-byte GDT descriptors Paolo Bonzini
2021-11-29 21:46   ` Marc Orr
2021-11-30 10:55     ` Paolo Bonzini
2021-11-30 17:22       ` Marc Orr
2021-11-30 17:26         ` Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 2/9] x86: fix call to set_gdt_entry Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 3/9] unify field names and definitions for GDT descriptors Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 4/9] replace tss_descr global with a function Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 5/9] x86: Move IDT to desc.c Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 6/9] x86: unify name of 32-bit and 64-bit GDT Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 7/9] x86: get rid of ring0stacktop Paolo Bonzini
2021-10-21 23:08   ` Aaron Lewis [this message]
2021-10-21 11:49 ` [PATCH kvm-unit-tests 8/9] x86: Move 64-bit GDT and TSS to desc.c Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 9/9] x86: Move 32-bit " Paolo Bonzini
2021-10-21 14:37 ` [PATCH v3 kvm-unit-tests 0/8] x86: Move IDT, GDT and TSS to C code Paolo Bonzini

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='CAAAPnDHGEJP8Ss2M3KxVHT=MnHrbb-3=RAdpQVXzKyx9KWpRvw@mail.gmail.com' \
    --to=aaronlewis@google.com \
    --cc=jmattson@google.com \
    --cc=jroedel@suse.de \
    --cc=kvm@vger.kernel.org \
    --cc=marcorr@google.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=varad.gautam@suse.com \
    --cc=zxwang42@gmail.com \
    /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.