xref: /linux/arch/x86/include/asm/io_bitmap.h (revision cadfad87)
1577d5cd7SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0 */
2577d5cd7SThomas Gleixner #ifndef _ASM_X86_IOBITMAP_H
3577d5cd7SThomas Gleixner #define _ASM_X86_IOBITMAP_H
4577d5cd7SThomas Gleixner 
54804e382SThomas Gleixner #include <linux/refcount.h>
6577d5cd7SThomas Gleixner #include <asm/processor.h>
7577d5cd7SThomas Gleixner 
8577d5cd7SThomas Gleixner struct io_bitmap {
9060aa16fSThomas Gleixner 	u64		sequence;
104804e382SThomas Gleixner 	refcount_t	refcnt;
11577d5cd7SThomas Gleixner 	/* The maximum number of bytes to copy so all zero bits are covered */
12577d5cd7SThomas Gleixner 	unsigned int	max;
13577d5cd7SThomas Gleixner 	unsigned long	bitmap[IO_BITMAP_LONGS];
14577d5cd7SThomas Gleixner };
15577d5cd7SThomas Gleixner 
164804e382SThomas Gleixner struct task_struct;
174804e382SThomas Gleixner 
18111e7b15SThomas Gleixner #ifdef CONFIG_X86_IOPL_IOPERM
194804e382SThomas Gleixner void io_bitmap_share(struct task_struct *tsk);
204bfe6cceSJay Lang void io_bitmap_exit(struct task_struct *tsk);
21ea5f1cd7SThomas Gleixner 
native_tss_invalidate_io_bitmap(void)22*cadfad87SAndy Lutomirski static inline void native_tss_invalidate_io_bitmap(void)
23*cadfad87SAndy Lutomirski {
24*cadfad87SAndy Lutomirski 	/*
25*cadfad87SAndy Lutomirski 	 * Invalidate the I/O bitmap by moving io_bitmap_base outside the
26*cadfad87SAndy Lutomirski 	 * TSS limit so any subsequent I/O access from user space will
27*cadfad87SAndy Lutomirski 	 * trigger a #GP.
28*cadfad87SAndy Lutomirski 	 *
29*cadfad87SAndy Lutomirski 	 * This is correct even when VMEXIT rewrites the TSS limit
30*cadfad87SAndy Lutomirski 	 * to 0x67 as the only requirement is that the base points
31*cadfad87SAndy Lutomirski 	 * outside the limit.
32*cadfad87SAndy Lutomirski 	 */
33*cadfad87SAndy Lutomirski 	this_cpu_write(cpu_tss_rw.x86_tss.io_bitmap_base,
34*cadfad87SAndy Lutomirski 		       IO_BITMAP_OFFSET_INVALID);
35*cadfad87SAndy Lutomirski }
36*cadfad87SAndy Lutomirski 
3799bcd4a6SJuergen Gross void native_tss_update_io_bitmap(void);
3899bcd4a6SJuergen Gross 
3999bcd4a6SJuergen Gross #ifdef CONFIG_PARAVIRT_XXL
4099bcd4a6SJuergen Gross #include <asm/paravirt.h>
4199bcd4a6SJuergen Gross #else
4299bcd4a6SJuergen Gross #define tss_update_io_bitmap native_tss_update_io_bitmap
43*cadfad87SAndy Lutomirski #define tss_invalidate_io_bitmap native_tss_invalidate_io_bitmap
4499bcd4a6SJuergen Gross #endif
4599bcd4a6SJuergen Gross 
46111e7b15SThomas Gleixner #else
io_bitmap_share(struct task_struct * tsk)47111e7b15SThomas Gleixner static inline void io_bitmap_share(struct task_struct *tsk) { }
io_bitmap_exit(struct task_struct * tsk)484bfe6cceSJay Lang static inline void io_bitmap_exit(struct task_struct *tsk) { }
tss_update_io_bitmap(void)49111e7b15SThomas Gleixner static inline void tss_update_io_bitmap(void) { }
50111e7b15SThomas Gleixner #endif
5122fe5b04SThomas Gleixner 
52577d5cd7SThomas Gleixner #endif
53