Commit 99bcd4a6 authored by Juergen Gross's avatar Juergen Gross Committed by Thomas Gleixner

x86/ioperm: Add new paravirt function update_io_bitmap()

Commit 111e7b15 ("x86/ioperm: Extend IOPL config to control ioperm()
as well") reworked the iopl syscall to use I/O bitmaps.

Unfortunately this broke Xen PV domains using that syscall as there is
currently no I/O bitmap support in PV domains.

Add I/O bitmap support via a new paravirt function update_io_bitmap which
Xen PV domains can use to update their I/O bitmaps via a hypercall.

Fixes: 111e7b15 ("x86/ioperm: Extend IOPL config to control ioperm() as well")
Reported-by: default avatarJan Beulich <jbeulich@suse.com>
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Tested-by: default avatarJan Beulich <jbeulich@suse.com>
Reviewed-by: default avatarJan Beulich <jbeulich@suse.com>
Cc: <stable@vger.kernel.org> # 5.5
Link: https://lkml.kernel.org/r/20200218154712.25490-1-jgross@suse.com
parent 735a6dd0
...@@ -19,7 +19,14 @@ struct task_struct; ...@@ -19,7 +19,14 @@ struct task_struct;
void io_bitmap_share(struct task_struct *tsk); void io_bitmap_share(struct task_struct *tsk);
void io_bitmap_exit(void); void io_bitmap_exit(void);
void tss_update_io_bitmap(void); void native_tss_update_io_bitmap(void);
#ifdef CONFIG_PARAVIRT_XXL
#include <asm/paravirt.h>
#else
#define tss_update_io_bitmap native_tss_update_io_bitmap
#endif
#else #else
static inline void io_bitmap_share(struct task_struct *tsk) { } static inline void io_bitmap_share(struct task_struct *tsk) { }
static inline void io_bitmap_exit(void) { } static inline void io_bitmap_exit(void) { }
......
...@@ -295,6 +295,13 @@ static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g) ...@@ -295,6 +295,13 @@ static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
PVOP_VCALL3(cpu.write_idt_entry, dt, entry, g); PVOP_VCALL3(cpu.write_idt_entry, dt, entry, g);
} }
#ifdef CONFIG_X86_IOPL_IOPERM
static inline void tss_update_io_bitmap(void)
{
PVOP_VCALL0(cpu.update_io_bitmap);
}
#endif
static inline void paravirt_activate_mm(struct mm_struct *prev, static inline void paravirt_activate_mm(struct mm_struct *prev,
struct mm_struct *next) struct mm_struct *next)
{ {
......
...@@ -140,6 +140,10 @@ struct pv_cpu_ops { ...@@ -140,6 +140,10 @@ struct pv_cpu_ops {
void (*load_sp0)(unsigned long sp0); void (*load_sp0)(unsigned long sp0);
#ifdef CONFIG_X86_IOPL_IOPERM
void (*update_io_bitmap)(void);
#endif
void (*wbinvd)(void); void (*wbinvd)(void);
/* cpuid emulation, mostly so that caps bits can be disabled */ /* cpuid emulation, mostly so that caps bits can be disabled */
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <asm/timer.h> #include <asm/timer.h>
#include <asm/special_insns.h> #include <asm/special_insns.h>
#include <asm/tlb.h> #include <asm/tlb.h>
#include <asm/io_bitmap.h>
/* /*
* nop stub, which must not clobber anything *including the stack* to * nop stub, which must not clobber anything *including the stack* to
...@@ -341,6 +342,10 @@ struct paravirt_patch_template pv_ops = { ...@@ -341,6 +342,10 @@ struct paravirt_patch_template pv_ops = {
.cpu.iret = native_iret, .cpu.iret = native_iret,
.cpu.swapgs = native_swapgs, .cpu.swapgs = native_swapgs,
#ifdef CONFIG_X86_IOPL_IOPERM
.cpu.update_io_bitmap = native_tss_update_io_bitmap,
#endif
.cpu.start_context_switch = paravirt_nop, .cpu.start_context_switch = paravirt_nop,
.cpu.end_context_switch = paravirt_nop, .cpu.end_context_switch = paravirt_nop,
......
...@@ -374,7 +374,7 @@ static void tss_copy_io_bitmap(struct tss_struct *tss, struct io_bitmap *iobm) ...@@ -374,7 +374,7 @@ static void tss_copy_io_bitmap(struct tss_struct *tss, struct io_bitmap *iobm)
/** /**
* tss_update_io_bitmap - Update I/O bitmap before exiting to usermode * tss_update_io_bitmap - Update I/O bitmap before exiting to usermode
*/ */
void tss_update_io_bitmap(void) void native_tss_update_io_bitmap(void)
{ {
struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw); struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw);
struct thread_struct *t = &current->thread; struct thread_struct *t = &current->thread;
......
...@@ -72,6 +72,9 @@ ...@@ -72,6 +72,9 @@
#include <asm/mwait.h> #include <asm/mwait.h>
#include <asm/pci_x86.h> #include <asm/pci_x86.h>
#include <asm/cpu.h> #include <asm/cpu.h>
#ifdef CONFIG_X86_IOPL_IOPERM
#include <asm/io_bitmap.h>
#endif
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
#include <linux/acpi.h> #include <linux/acpi.h>
...@@ -837,6 +840,25 @@ static void xen_load_sp0(unsigned long sp0) ...@@ -837,6 +840,25 @@ static void xen_load_sp0(unsigned long sp0)
this_cpu_write(cpu_tss_rw.x86_tss.sp0, sp0); this_cpu_write(cpu_tss_rw.x86_tss.sp0, sp0);
} }
#ifdef CONFIG_X86_IOPL_IOPERM
static void xen_update_io_bitmap(void)
{
struct physdev_set_iobitmap iobitmap;
struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw);
native_tss_update_io_bitmap();
iobitmap.bitmap = (uint8_t *)(&tss->x86_tss) +
tss->x86_tss.io_bitmap_base;
if (tss->x86_tss.io_bitmap_base == IO_BITMAP_OFFSET_INVALID)
iobitmap.nr_ports = 0;
else
iobitmap.nr_ports = IO_BITMAP_BITS;
HYPERVISOR_physdev_op(PHYSDEVOP_set_iobitmap, &iobitmap);
}
#endif
static void xen_io_delay(void) static void xen_io_delay(void)
{ {
} }
...@@ -1047,6 +1069,9 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = { ...@@ -1047,6 +1069,9 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
.write_idt_entry = xen_write_idt_entry, .write_idt_entry = xen_write_idt_entry,
.load_sp0 = xen_load_sp0, .load_sp0 = xen_load_sp0,
#ifdef CONFIG_X86_IOPL_IOPERM
.update_io_bitmap = xen_update_io_bitmap,
#endif
.io_delay = xen_io_delay, .io_delay = xen_io_delay,
/* Xen takes care of %gs when switching to usermode for us */ /* Xen takes care of %gs when switching to usermode for us */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment