x86/ioperm: Remove bitmap if all permissions dropped

If ioperm() results in a bitmap with all bits set (no permissions to any
I/O port), then handling that bitmap on context switch and exit to user
mode is pointless. Drop it.

Move the bitmap exit handling to the ioport code and reuse it for both the
thread exit path and dropping it. This allows to reuse this code for the
upcoming iopl() emulation.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Andy Lutomirski <luto@kernel.org>
This commit is contained in:
Thomas Gleixner
2019-11-11 23:03:24 +01:00
parent 22fe5b0439
commit ea5f1cd7ab
3 changed files with 22 additions and 14 deletions

View File

@@ -16,6 +16,18 @@
static atomic64_t io_bitmap_sequence;
void io_bitmap_exit(void)
{
struct io_bitmap *iobm = current->thread.io_bitmap;
current->thread.io_bitmap = NULL;
clear_thread_flag(TIF_IO_BITMAP);
preempt_disable();
tss_update_io_bitmap();
preempt_enable();
kfree(iobm);
}
/*
* this changes the io permissions bitmap in the current task.
*/
@@ -61,11 +73,16 @@ long ksys_ioperm(unsigned long from, unsigned long num, int turn_on)
* Search for a (possibly new) maximum. This is simple and stupid,
* to keep it obviously correct:
*/
max_long = 0;
max_long = UINT_MAX;
for (i = 0; i < IO_BITMAP_LONGS; i++) {
if (iobm->bitmap[i] != ~0UL)
max_long = i;
}
/* All permissions dropped? */
if (max_long == UINT_MAX) {
io_bitmap_exit();
return 0;
}
iobm->max = (max_long + 1) * sizeof(unsigned long);