From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Wei Liu <wei.liu2@citrix.com>, Jan Beulich <JBeulich@suse.com>
Subject: [PATCH for-next] x86/pv: Factor out the calculation of LDT/GDT descriptor pointers
Date: Tue, 17 Oct 2017 16:05:23 +0100 [thread overview]
Message-ID: <1508252723-29683-1-git-send-email-andrew.cooper3@citrix.com> (raw)
Rather than opencoding it in two places. While only used in the PV emulation
code, this helper is in principle usable anywhere in the hypervisor.
No functional change.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
---
xen/arch/x86/pv/emul-gate-op.c | 5 +----
xen/arch/x86/pv/emulate.c | 6 +-----
xen/arch/x86/pv/emulate.h | 11 +++++++++++
3 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/xen/arch/x86/pv/emul-gate-op.c b/xen/arch/x86/pv/emul-gate-op.c
index 0f89c91..14ce95e 100644
--- a/xen/arch/x86/pv/emul-gate-op.c
+++ b/xen/arch/x86/pv/emul-gate-op.c
@@ -54,11 +54,8 @@ static int read_gate_descriptor(unsigned int gate_sel,
unsigned int *ar)
{
struct desc_struct desc;
- const struct desc_struct *pdesc;
+ const struct desc_struct *pdesc = gdt_ldt_desc_ptr(gate_sel);
- pdesc = (const struct desc_struct *)
- (!(gate_sel & 4) ? GDT_VIRT_START(v) : LDT_VIRT_START(v))
- + (gate_sel >> 3);
if ( (gate_sel < 4) ||
((gate_sel >= FIRST_RESERVED_GDT_BYTE) && !(gate_sel & 4)) ||
__get_user(desc, pdesc) )
diff --git a/xen/arch/x86/pv/emulate.c b/xen/arch/x86/pv/emulate.c
index 5750c76..1b60911 100644
--- a/xen/arch/x86/pv/emulate.c
+++ b/xen/arch/x86/pv/emulate.c
@@ -33,11 +33,7 @@ int pv_emul_read_descriptor(unsigned int sel, const struct vcpu *v,
if ( sel < 4)
desc.b = desc.a = 0;
- else if ( __get_user(desc,
- (const struct desc_struct *)(!(sel & 4)
- ? GDT_VIRT_START(v)
- : LDT_VIRT_START(v))
- + (sel >> 3)) )
+ else if ( __get_user(desc, gdt_ldt_desc_ptr(sel)) )
return 0;
if ( !insn_fetch )
desc.b &= ~_SEGMENT_L;
diff --git a/xen/arch/x86/pv/emulate.h b/xen/arch/x86/pv/emulate.h
index 656c12f..9d58794 100644
--- a/xen/arch/x86/pv/emulate.h
+++ b/xen/arch/x86/pv/emulate.h
@@ -1,6 +1,7 @@
#ifndef __PV_EMULATE_H__
#define __PV_EMULATE_H__
+#include <asm/processor.h>
#include <asm/x86_emulate.h>
int pv_emul_read_descriptor(unsigned int sel, const struct vcpu *v,
@@ -16,4 +17,14 @@ static inline int pv_emul_is_mem_write(const struct x86_emulate_state *state,
: X86EMUL_UNHANDLEABLE;
}
+/* Return a pointer to the GDT/LDT descriptor referenced by sel. */
+static inline const struct desc_struct *gdt_ldt_desc_ptr(unsigned int sel)
+{
+ const struct vcpu *curr = current;
+ const struct desc_struct *tbl = (void *)
+ ((sel & X86_XEC_TI) ? LDT_VIRT_START(curr) : GDT_VIRT_START(curr));
+
+ return &tbl[sel >> 3];
+}
+
#endif /* __PV_EMULATE_H__ */
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next reply other threads:[~2017-10-17 15:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-17 15:05 Andrew Cooper [this message]
2017-10-17 16:54 ` [PATCH for-next] x86/pv: Factor out the calculation of LDT/GDT descriptor pointers Wei Liu
2017-10-26 15:06 ` Jan Beulich
2017-10-26 15:39 ` 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=1508252723-29683-1-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.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;
as well as URLs for NNTP newsgroup(s).