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>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
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) )
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;
#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,
: 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__ */