Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1584744 > unrolled thread

[PATCH 4/6] x86/kvm/vmx: Simplify segment_base()

Started byAndy Lutomirski <luto@kernel.org>
First post2017-02-20 18:00 +0100
Last post2017-02-20 19:00 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 4/6] x86/kvm/vmx: Simplify segment_base() Andy Lutomirski <luto@kernel.org> - 2017-02-20 18:00 +0100
    Re: [PATCH 4/6] x86/kvm/vmx: Simplify segment_base() Thomas Garnier <thgarnie@google.com> - 2017-02-20 19:00 +0100

#1584744 — [PATCH 4/6] x86/kvm/vmx: Simplify segment_base()

FromAndy Lutomirski <luto@kernel.org>
Date2017-02-20 18:00 +0100
Subject[PATCH 4/6] x86/kvm/vmx: Simplify segment_base()
Message-ID<tcZtF-7aS-45@gated-at.bofh.it>
Use actual pointer types for pointers (instead of unsigned long) and
replace hardcoded constants with the appropriate self-documenting
macros.

The function is still a bit messy, but this seems a lot better than
before to me.

This is mostly borrowed from a patch by Thomas Garnier.

Cc: Thomas Garnier <thgarnie@google.com>
Cc: Jim Mattson <jmattson@google.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 arch/x86/kvm/vmx.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index b1810a0edec3..17ef11c64702 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2069,24 +2069,23 @@ static unsigned long segment_base(u16 selector)
 {
 	struct desc_ptr *gdt = this_cpu_ptr(&host_gdt);
 	struct desc_struct *d;
-	unsigned long table_base;
+	struct desc_struct *table;
 	unsigned long v;
 
-	if (!(selector & ~3))
+	if (!(selector & ~SEGMENT_RPL_MASK))
 		return 0;
 
-	table_base = gdt->address;
+	table = (struct desc_struct *)gdt->address;
 
-	if (selector & 4) {           /* from ldt */
+	if ((selector & SEGMENT_TI_MASK) == SEGMENT_LDT) {
 		u16 ldt_selector = kvm_read_ldt();
 
-		if (!(ldt_selector & ~3))
+		if (!(ldt_selector & ~SEGMENT_RPL_MASK))
 			return 0;
 
-		table_base = segment_base(ldt_selector);
+		table = (struct desc_struct *)segment_base(ldt_selector);
 	}
-	d = (struct desc_struct *)(table_base + (selector & ~7));
-	v = get_desc_base(d);
+	v = get_desc_base(&table[selector >> 3]);
 	return v;
 }
 #endif
-- 
2.9.3

[toc] | [next] | [standalone]


#1584805

FromThomas Garnier <thgarnie@google.com>
Date2017-02-20 19:00 +0100
Message-ID<td0pI-7LH-9@gated-at.bofh.it>
In reply to#1584744
On Mon, Feb 20, 2017 at 8:56 AM, Andy Lutomirski <luto@kernel.org> wrote:
> Use actual pointer types for pointers (instead of unsigned long) and
> replace hardcoded constants with the appropriate self-documenting
> macros.
>
> The function is still a bit messy, but this seems a lot better than
> before to me.
>
> This is mostly borrowed from a patch by Thomas Garnier.
>

Looks good, I like that the 64-bit usage could be removed. Thanks!

> Cc: Thomas Garnier <thgarnie@google.com>
> Cc: Jim Mattson <jmattson@google.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Andy Lutomirski <luto@kernel.org>
> ---
>  arch/x86/kvm/vmx.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index b1810a0edec3..17ef11c64702 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -2069,24 +2069,23 @@ static unsigned long segment_base(u16 selector)
>  {
>         struct desc_ptr *gdt = this_cpu_ptr(&host_gdt);
>         struct desc_struct *d;
> -       unsigned long table_base;
> +       struct desc_struct *table;
>         unsigned long v;
>
> -       if (!(selector & ~3))
> +       if (!(selector & ~SEGMENT_RPL_MASK))
>                 return 0;
>
> -       table_base = gdt->address;
> +       table = (struct desc_struct *)gdt->address;
>
> -       if (selector & 4) {           /* from ldt */
> +       if ((selector & SEGMENT_TI_MASK) == SEGMENT_LDT) {
>                 u16 ldt_selector = kvm_read_ldt();
>
> -               if (!(ldt_selector & ~3))
> +               if (!(ldt_selector & ~SEGMENT_RPL_MASK))
>                         return 0;
>
> -               table_base = segment_base(ldt_selector);
> +               table = (struct desc_struct *)segment_base(ldt_selector);
>         }
> -       d = (struct desc_struct *)(table_base + (selector & ~7));
> -       v = get_desc_base(d);
> +       v = get_desc_base(&table[selector >> 3]);
>         return v;
>  }
>  #endif
> --
> 2.9.3
>



-- 
Thomas

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web