18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_IOBITMAP_H 38c2ecf20Sopenharmony_ci#define _ASM_X86_IOBITMAP_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/refcount.h> 68c2ecf20Sopenharmony_ci#include <asm/processor.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_cistruct io_bitmap { 98c2ecf20Sopenharmony_ci u64 sequence; 108c2ecf20Sopenharmony_ci refcount_t refcnt; 118c2ecf20Sopenharmony_ci /* The maximum number of bytes to copy so all zero bits are covered */ 128c2ecf20Sopenharmony_ci unsigned int max; 138c2ecf20Sopenharmony_ci unsigned long bitmap[IO_BITMAP_LONGS]; 148c2ecf20Sopenharmony_ci}; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistruct task_struct; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_IOPL_IOPERM 198c2ecf20Sopenharmony_civoid io_bitmap_share(struct task_struct *tsk); 208c2ecf20Sopenharmony_civoid io_bitmap_exit(struct task_struct *tsk); 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistatic inline void native_tss_invalidate_io_bitmap(void) 238c2ecf20Sopenharmony_ci{ 248c2ecf20Sopenharmony_ci /* 258c2ecf20Sopenharmony_ci * Invalidate the I/O bitmap by moving io_bitmap_base outside the 268c2ecf20Sopenharmony_ci * TSS limit so any subsequent I/O access from user space will 278c2ecf20Sopenharmony_ci * trigger a #GP. 288c2ecf20Sopenharmony_ci * 298c2ecf20Sopenharmony_ci * This is correct even when VMEXIT rewrites the TSS limit 308c2ecf20Sopenharmony_ci * to 0x67 as the only requirement is that the base points 318c2ecf20Sopenharmony_ci * outside the limit. 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_ci this_cpu_write(cpu_tss_rw.x86_tss.io_bitmap_base, 348c2ecf20Sopenharmony_ci IO_BITMAP_OFFSET_INVALID); 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_civoid native_tss_update_io_bitmap(void); 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#ifdef CONFIG_PARAVIRT_XXL 408c2ecf20Sopenharmony_ci#include <asm/paravirt.h> 418c2ecf20Sopenharmony_ci#else 428c2ecf20Sopenharmony_ci#define tss_update_io_bitmap native_tss_update_io_bitmap 438c2ecf20Sopenharmony_ci#define tss_invalidate_io_bitmap native_tss_invalidate_io_bitmap 448c2ecf20Sopenharmony_ci#endif 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#else 478c2ecf20Sopenharmony_cistatic inline void io_bitmap_share(struct task_struct *tsk) { } 488c2ecf20Sopenharmony_cistatic inline void io_bitmap_exit(struct task_struct *tsk) { } 498c2ecf20Sopenharmony_cistatic inline void tss_update_io_bitmap(void) { } 508c2ecf20Sopenharmony_ci#endif 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#endif 53