Skip to content

Commit 99bcd4a

Browse files
jgross1KAGA-KOKO
authored andcommitted
x86/ioperm: Add new paravirt function update_io_bitmap()
Commit 111e7b1 ("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: 111e7b1 ("x86/ioperm: Extend IOPL config to control ioperm() as well") Reported-by: Jan Beulich <[email protected]> Signed-off-by: Juergen Gross <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Jan Beulich <[email protected]> Reviewed-by: Jan Beulich <[email protected]> Cc: <[email protected]> # 5.5 Link: https://lkml.kernel.org/r/[email protected]
1 parent 735a6dd commit 99bcd4a

File tree

6 files changed

+50
-2
lines changed

6 files changed

+50
-2
lines changed

arch/x86/include/asm/io_bitmap.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ struct task_struct;
1919
void io_bitmap_share(struct task_struct *tsk);
2020
void io_bitmap_exit(void);
2121

22-
void tss_update_io_bitmap(void);
22+
void native_tss_update_io_bitmap(void);
23+
24+
#ifdef CONFIG_PARAVIRT_XXL
25+
#include <asm/paravirt.h>
26+
#else
27+
#define tss_update_io_bitmap native_tss_update_io_bitmap
28+
#endif
29+
2330
#else
2431
static inline void io_bitmap_share(struct task_struct *tsk) { }
2532
static inline void io_bitmap_exit(void) { }

arch/x86/include/asm/paravirt.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
295295
PVOP_VCALL3(cpu.write_idt_entry, dt, entry, g);
296296
}
297297

298+
#ifdef CONFIG_X86_IOPL_IOPERM
299+
static inline void tss_update_io_bitmap(void)
300+
{
301+
PVOP_VCALL0(cpu.update_io_bitmap);
302+
}
303+
#endif
304+
298305
static inline void paravirt_activate_mm(struct mm_struct *prev,
299306
struct mm_struct *next)
300307
{

arch/x86/include/asm/paravirt_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ struct pv_cpu_ops {
140140

141141
void (*load_sp0)(unsigned long sp0);
142142

143+
#ifdef CONFIG_X86_IOPL_IOPERM
144+
void (*update_io_bitmap)(void);
145+
#endif
146+
143147
void (*wbinvd)(void);
144148

145149
/* cpuid emulation, mostly so that caps bits can be disabled */

arch/x86/kernel/paravirt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <asm/timer.h>
3131
#include <asm/special_insns.h>
3232
#include <asm/tlb.h>
33+
#include <asm/io_bitmap.h>
3334

3435
/*
3536
* nop stub, which must not clobber anything *including the stack* to
@@ -341,6 +342,10 @@ struct paravirt_patch_template pv_ops = {
341342
.cpu.iret = native_iret,
342343
.cpu.swapgs = native_swapgs,
343344

345+
#ifdef CONFIG_X86_IOPL_IOPERM
346+
.cpu.update_io_bitmap = native_tss_update_io_bitmap,
347+
#endif
348+
344349
.cpu.start_context_switch = paravirt_nop,
345350
.cpu.end_context_switch = paravirt_nop,
346351

arch/x86/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ static void tss_copy_io_bitmap(struct tss_struct *tss, struct io_bitmap *iobm)
374374
/**
375375
* tss_update_io_bitmap - Update I/O bitmap before exiting to usermode
376376
*/
377-
void tss_update_io_bitmap(void)
377+
void native_tss_update_io_bitmap(void)
378378
{
379379
struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw);
380380
struct thread_struct *t = &current->thread;

arch/x86/xen/enlighten_pv.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
#include <asm/mwait.h>
7373
#include <asm/pci_x86.h>
7474
#include <asm/cpu.h>
75+
#ifdef CONFIG_X86_IOPL_IOPERM
76+
#include <asm/io_bitmap.h>
77+
#endif
7578

7679
#ifdef CONFIG_ACPI
7780
#include <linux/acpi.h>
@@ -837,6 +840,25 @@ static void xen_load_sp0(unsigned long sp0)
837840
this_cpu_write(cpu_tss_rw.x86_tss.sp0, sp0);
838841
}
839842

843+
#ifdef CONFIG_X86_IOPL_IOPERM
844+
static void xen_update_io_bitmap(void)
845+
{
846+
struct physdev_set_iobitmap iobitmap;
847+
struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw);
848+
849+
native_tss_update_io_bitmap();
850+
851+
iobitmap.bitmap = (uint8_t *)(&tss->x86_tss) +
852+
tss->x86_tss.io_bitmap_base;
853+
if (tss->x86_tss.io_bitmap_base == IO_BITMAP_OFFSET_INVALID)
854+
iobitmap.nr_ports = 0;
855+
else
856+
iobitmap.nr_ports = IO_BITMAP_BITS;
857+
858+
HYPERVISOR_physdev_op(PHYSDEVOP_set_iobitmap, &iobitmap);
859+
}
860+
#endif
861+
840862
static void xen_io_delay(void)
841863
{
842864
}
@@ -1047,6 +1069,9 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
10471069
.write_idt_entry = xen_write_idt_entry,
10481070
.load_sp0 = xen_load_sp0,
10491071

1072+
#ifdef CONFIG_X86_IOPL_IOPERM
1073+
.update_io_bitmap = xen_update_io_bitmap,
1074+
#endif
10501075
.io_delay = xen_io_delay,
10511076

10521077
/* Xen takes care of %gs when switching to usermode for us */

0 commit comments

Comments
 (0)