Skip to content

Commit f5848e5

Browse files
committed
x86/tss: Move I/O bitmap data into a seperate struct
Move the non hardware portion of I/O bitmap data into a seperate struct for readability sake. Originally-by: Ingo Molnar <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]>
1 parent ecc7e37 commit f5848e5

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

arch/x86/include/asm/processor.h

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ struct x86_hw_tss {
328328
* IO-bitmap sizes:
329329
*/
330330
#define IO_BITMAP_BITS 65536
331-
#define IO_BITMAP_BYTES (IO_BITMAP_BITS/8)
332-
#define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long))
331+
#define IO_BITMAP_BYTES (IO_BITMAP_BITS / BITS_PER_BYTE)
332+
#define IO_BITMAP_LONGS (IO_BITMAP_BYTES / sizeof(long))
333333

334-
#define IO_BITMAP_OFFSET_VALID \
335-
(offsetof(struct tss_struct, io_bitmap) - \
334+
#define IO_BITMAP_OFFSET_VALID \
335+
(offsetof(struct tss_struct, io_bitmap.bitmap) - \
336336
offsetof(struct tss_struct, x86_tss))
337337

338338
/*
@@ -356,30 +356,37 @@ struct entry_stack_page {
356356
struct entry_stack stack;
357357
} __aligned(PAGE_SIZE);
358358

359-
struct tss_struct {
360-
/*
361-
* The fixed hardware portion. This must not cross a page boundary
362-
* at risk of violating the SDM's advice and potentially triggering
363-
* errata.
364-
*/
365-
struct x86_hw_tss x86_tss;
366-
359+
/*
360+
* All IO bitmap related data stored in the TSS:
361+
*/
362+
struct x86_io_bitmap {
367363
/*
368364
* Store the dirty size of the last io bitmap offender. The next
369365
* one will have to do the cleanup as the switch out to a non io
370366
* bitmap user will just set x86_tss.io_bitmap_base to a value
371367
* outside of the TSS limit. So for sane tasks there is no need to
372368
* actually touch the io_bitmap at all.
373369
*/
374-
unsigned int io_bitmap_prev_max;
370+
unsigned int prev_max;
375371

376372
/*
377373
* The extra 1 is there because the CPU will access an
378374
* additional byte beyond the end of the IO permission
379375
* bitmap. The extra byte must be all 1 bits, and must
380376
* be within the limit.
381377
*/
382-
unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
378+
unsigned long bitmap[IO_BITMAP_LONGS + 1];
379+
};
380+
381+
struct tss_struct {
382+
/*
383+
* The fixed hardware portion. This must not cross a page boundary
384+
* at risk of violating the SDM's advice and potentially triggering
385+
* errata.
386+
*/
387+
struct x86_hw_tss x86_tss;
388+
389+
struct x86_io_bitmap io_bitmap;
383390
} __aligned(PAGE_SIZE);
384391

385392
DECLARE_PER_CPU_PAGE_ALIGNED(struct tss_struct, cpu_tss_rw);

arch/x86/kernel/cpu/common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,8 +1861,8 @@ void cpu_init(void)
18611861
/* Initialize the TSS. */
18621862
tss_setup_ist(tss);
18631863
tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET_INVALID;
1864-
tss->io_bitmap_prev_max = 0;
1865-
memset(tss->io_bitmap, 0xff, sizeof(tss->io_bitmap));
1864+
tss->io_bitmap.prev_max = 0;
1865+
memset(tss->io_bitmap.bitmap, 0xff, sizeof(tss->io_bitmap.bitmap));
18661866
set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
18671867

18681868
load_TR_desc();

arch/x86/kernel/ioport.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ long ksys_ioperm(unsigned long from, unsigned long num, int turn_on)
8181

8282
/* Update the TSS */
8383
tss = this_cpu_ptr(&cpu_tss_rw);
84-
memcpy(tss->io_bitmap, t->io_bitmap_ptr, bytes_updated);
84+
memcpy(tss->io_bitmap.bitmap, t->io_bitmap_ptr, bytes_updated);
8585
/* Store the new end of the zero bits */
86-
tss->io_bitmap_prev_max = bytes;
86+
tss->io_bitmap.prev_max = bytes;
8787
/* Make the bitmap base in the TSS valid */
8888
tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET_VALID;
8989
/* Make sure the TSS limit covers the I/O bitmap. */

arch/x86/kernel/process.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,11 @@ static inline void switch_to_bitmap(struct thread_struct *next,
374374
* bits permitted, then the copy needs to cover those as
375375
* well so they get turned off.
376376
*/
377-
memcpy(tss->io_bitmap, next->io_bitmap_ptr,
378-
max(tss->io_bitmap_prev_max, next->io_bitmap_max));
377+
memcpy(tss->io_bitmap.bitmap, next->io_bitmap_ptr,
378+
max(tss->io_bitmap.prev_max, next->io_bitmap_max));
379379

380380
/* Store the new max and set io_bitmap_base valid */
381-
tss->io_bitmap_prev_max = next->io_bitmap_max;
381+
tss->io_bitmap.prev_max = next->io_bitmap_max;
382382
tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET_VALID;
383383

384384
/*

0 commit comments

Comments
 (0)