summaryrefslogtreecommitdiff
path: root/arch/x86/kernel/ioport.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2019-11-11 23:03:23 +0100
committerThomas Gleixner <tglx@linutronix.de>2019-11-16 11:24:03 +0100
commit22fe5b0439dd53643fd6f4c582c46c6dba0fde53 (patch)
treee74ed4d8d8f6182811570d21185a7703e76e56d7 /arch/x86/kernel/ioport.c
parent060aa16fdb7c5078a4159a76e5dc87d6a493af9b (diff)
x86/ioperm: Move TSS bitmap update to exit to user work
There is no point to update the TSS bitmap for tasks which use I/O bitmaps on every context switch. It's enough to update it right before exiting to user space. That reduces the context switch bitmap handling to invalidating the io bitmap base offset in the TSS when the outgoing task has TIF_IO_BITMAP set. The invaldiation is done on purpose when a task with an IO bitmap switches out to prevent any possible leakage of an activated IO bitmap. It also removes the requirement to update the tasks bitmap atomically in ioperm(). Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86/kernel/ioport.c')
-rw-r--r--arch/x86/kernel/ioport.c25
1 files changed, 4 insertions, 21 deletions
diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
index 7c1ab5c2b395..198beadb3732 100644
--- a/arch/x86/kernel/ioport.c
+++ b/arch/x86/kernel/ioport.c
@@ -21,9 +21,8 @@ static atomic64_t io_bitmap_sequence;
*/
long ksys_ioperm(unsigned long from, unsigned long num, int turn_on)
{
- unsigned int i, max_long, bytes, bytes_updated;
struct thread_struct *t = &current->thread;
- struct tss_struct *tss;
+ unsigned int i, max_long;
struct io_bitmap *iobm;
if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
@@ -50,10 +49,9 @@ long ksys_ioperm(unsigned long from, unsigned long num, int turn_on)
}
/*
- * Update the bitmap and the TSS copy with preemption disabled to
- * prevent a race against context switch.
+ * Update the tasks bitmap. The update of the TSS bitmap happens on
+ * exit to user mode. So this needs no protection.
*/
- preempt_disable();
if (turn_on)
bitmap_clear(iobm->bitmap, from, num);
else
@@ -69,11 +67,8 @@ long ksys_ioperm(unsigned long from, unsigned long num, int turn_on)
max_long = i;
}
- bytes = (max_long + 1) * sizeof(unsigned long);
- bytes_updated = max(bytes, t->io_bitmap->max);
+ iobm->max = (max_long + 1) * sizeof(unsigned long);
- /* Update the thread data */
- iobm->max = bytes;
/* Update the sequence number to force an update in switch_to() */
iobm->sequence = atomic64_add_return(1, &io_bitmap_sequence);
@@ -85,18 +80,6 @@ long ksys_ioperm(unsigned long from, unsigned long num, int turn_on)
t->io_bitmap = iobm;
set_thread_flag(TIF_IO_BITMAP);
- /* Update the TSS */
- tss = this_cpu_ptr(&cpu_tss_rw);
- memcpy(tss->io_bitmap.bitmap, iobm->bitmap, bytes_updated);
- /* Store the new end of the zero bits */
- tss->io_bitmap.prev_max = bytes;
- /* Make the bitmap base in the TSS valid */
- tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET_VALID;
- /* Make sure the TSS limit covers the I/O bitmap. */
- refresh_tss_limit();
-
- preempt_enable();
-
return 0;
}