Index: sys/amd64/amd64/machdep.c =================================================================== --- sys/amd64/amd64/machdep.c (revision 265951) +++ sys/amd64/amd64/machdep.c (working copy) @@ -1147,7 +1147,7 @@ .ssd_gran = 1 }, /* GPROC0_SEL 9 Proc 0 Tss Descriptor */ { .ssd_base = 0x0, - .ssd_limit = sizeof(struct amd64tss) + IOPAGES * PAGE_SIZE - 1, + .ssd_limit = sizeof(struct amd64tss) + IOPERM_BITMAP_SIZE - 1, .ssd_type = SDT_SYSTSS, .ssd_dpl = SEL_KPL, .ssd_p = 1, @@ -2003,8 +2003,7 @@ common_tss[0].tss_ist2 = (long) np; /* Set the IO permission bitmap (empty due to tss seg limit) */ - common_tss[0].tss_iobase = sizeof(struct amd64tss) + - IOPAGES * PAGE_SIZE; + common_tss[0].tss_iobase = sizeof(struct amd64tss) + IOPERM_BITMAP_SIZE; gsel_tss = GSEL(GPROC0_SEL, SEL_KPL); ltr(gsel_tss); Index: sys/amd64/amd64/mp_machdep.c =================================================================== --- sys/amd64/amd64/mp_machdep.c (revision 265951) +++ sys/amd64/amd64/mp_machdep.c (working copy) @@ -637,7 +637,7 @@ common_tss[cpu] = common_tss[0]; common_tss[cpu].tss_rsp0 = 0; /* not used until after switch */ common_tss[cpu].tss_iobase = sizeof(struct amd64tss) + - IOPAGES * PAGE_SIZE; + IOPERM_BITMAP_SIZE; common_tss[cpu].tss_ist1 = (long)&doublefault_stack[PAGE_SIZE]; /* The NMI stack runs on IST2. */ Index: sys/amd64/amd64/sys_machdep.c =================================================================== --- sys/amd64/amd64/sys_machdep.c (revision 265951) +++ sys/amd64/amd64/sys_machdep.c (working copy) @@ -338,7 +338,7 @@ char *iomap; struct amd64tss *tssp; struct system_segment_descriptor *tss_sd; - u_long *addr; + char *addr; struct pcb *pcb; if ((error = priv_check(td, PRIV_IO)) != 0) @@ -361,9 +361,9 @@ if (tssp == NULL) return (ENOMEM); iomap = (char *)&tssp[1]; - addr = (u_long *)iomap; - for (i = 0; i < (ctob(IOPAGES) + 1) / sizeof(u_long); i++) - *addr++ = ~0; + addr = (char *)iomap; + for (i = 0; i < IOPERM_BITMAP_SIZE; i++) + *addr++ = 0xff; critical_enter(); /* Takes care of tss_rsp0. */ memcpy(tssp, &common_tss[PCPU_GET(cpuid)], Index: sys/amd64/include/param.h =================================================================== --- sys/amd64/include/param.h (revision 265951) +++ sys/amd64/include/param.h (working copy) @@ -120,6 +120,12 @@ #define MAXPAGESIZES 3 /* maximum number of supported page sizes */ #define IOPAGES 2 /* pages of i/o permission bitmap */ +/* + * I/O permission bitmap has a bit for each I/O port plus an additional + * byte at the end with all bits set. See section "I/O Permission Bit Map" + * in the Intel SDM for more details. + */ +#define IOPERM_BITMAP_SIZE (IOPAGES * PAGE_SIZE + 1) #ifndef KSTACK_PAGES #define KSTACK_PAGES 4 /* pages of kstack (with pcb) */