summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2018-03-29 01:21:03 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2018-03-29 01:21:03 +0000
commit1e03f28756871d678a1d4afa5909d7e68b52f8a7 (patch)
treee41c6104fde034f6f0078d7ca768634d9eb5fbf8 /sys
parentf9b0356f2ba56985da4d47cef5a2e0b37f78deb6 (diff)
Explicitly declare the gdt storage in struct cpu_info_full instead of
implicitly putting it in the padding to page-size. This eliminates a couple Coverity issues from the Meltdown work. testing daniel@ ok mlarkin@
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/amd64/amd64/cpu.c4
-rw-r--r--sys/arch/amd64/amd64/machdep.c4
-rw-r--r--sys/arch/amd64/include/cpu.h4
-rw-r--r--sys/arch/amd64/include/cpu_full.h10
-rw-r--r--sys/arch/amd64/include/segments.h6
5 files changed, 16 insertions, 12 deletions
diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c
index 00f8b8bd79e..e2f9fc9ac79 100644
--- a/sys/arch/amd64/amd64/cpu.c
+++ b/sys/arch/amd64/amd64/cpu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.c,v 1.113 2018/03/13 05:10:40 guenther Exp $ */
+/* $OpenBSD: cpu.c,v 1.114 2018/03/29 01:21:02 guenther Exp $ */
/* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
/*-
@@ -352,7 +352,7 @@ cpu_attach(struct device *parent, struct device *self, void *aux)
ci = &cif->cif_cpu;
#if defined(MULTIPROCESSOR)
ci->ci_tss = &cif->cif_tss;
- ci->ci_gdt = (void *)(ci->ci_tss + 1);
+ ci->ci_gdt = &cif->cif_gdt;
memcpy(ci->ci_gdt, cpu_info_primary.ci_gdt, GDT_SIZE);
cpu_enter_pages(cif);
if (cpu_info[cpunum] != NULL)
diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c
index dd0623b15c4..b05455ab943 100644
--- a/sys/arch/amd64/amd64/machdep.c
+++ b/sys/arch/amd64/amd64/machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.239 2018/02/21 19:24:15 guenther Exp $ */
+/* $OpenBSD: machdep.c,v 1.240 2018/03/29 01:21:02 guenther Exp $ */
/* $NetBSD: machdep.c,v 1.3 2003/05/07 22:58:18 fvdl Exp $ */
/*-
@@ -1617,7 +1617,7 @@ init_x86_64(paddr_t first_avail)
idt = (struct gate_descriptor *)idt_vaddr;
cpu_info_primary.ci_tss = &cpu_info_full_primary.cif_tss;
- cpu_info_primary.ci_gdt = (void *)(cpu_info_primary.ci_tss + 1);
+ cpu_info_primary.ci_gdt = &cpu_info_full_primary.cif_gdt;
/* make gdt gates and memory segments */
set_mem_segment(GDT_ADDR_MEM(cpu_info_primary.ci_gdt, GCODE_SEL), 0,
diff --git a/sys/arch/amd64/include/cpu.h b/sys/arch/amd64/include/cpu.h
index 8f973ba1423..f456c1a4681 100644
--- a/sys/arch/amd64/include/cpu.h
+++ b/sys/arch/amd64/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.119 2018/02/21 19:24:15 guenther Exp $ */
+/* $OpenBSD: cpu.h,v 1.120 2018/03/29 01:21:02 guenther Exp $ */
/* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */
/*-
@@ -177,7 +177,7 @@ struct cpu_info {
struct x86_cache_info ci_cinfo[CAI_COUNT];
struct x86_64_tss *ci_tss;
- char *ci_gdt;
+ void *ci_gdt;
volatile int ci_ddb_paused;
#define CI_DDB_RUNNING 0
diff --git a/sys/arch/amd64/include/cpu_full.h b/sys/arch/amd64/include/cpu_full.h
index 93c433f44dd..6350a6b4ae5 100644
--- a/sys/arch/amd64/include/cpu_full.h
+++ b/sys/arch/amd64/include/cpu_full.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu_full.h,v 1.2 2018/02/22 20:27:14 bluhm Exp $ */
+/* $OpenBSD: cpu_full.h,v 1.3 2018/03/29 01:21:02 guenther Exp $ */
/*
* Copyright (c) Philip Guenther <guenther@openbsd.org>
*
@@ -29,10 +29,14 @@
struct cpu_info_full {
/* page mapped kRO in u-k */
union {
- struct x86_64_tss u_tss; /* followed by gdt */
+ struct {
+ struct x86_64_tss uu_tss;
+ uint64_t uu_gdt[GDT_SIZE / 8];
+ } u_tssgdt;
char u_align[PAGE_SIZE];
} cif_RO;
-#define cif_tss cif_RO.u_tss
+#define cif_tss cif_RO.u_tssgdt.uu_tss
+#define cif_gdt cif_RO.u_tssgdt.uu_gdt
/* start of page mapped kRW in u-k */
uint64_t cif_tramp_stack[(PAGE_SIZE / 4
diff --git a/sys/arch/amd64/include/segments.h b/sys/arch/amd64/include/segments.h
index 0c6c8609d05..6ce184e88d1 100644
--- a/sys/arch/amd64/include/segments.h
+++ b/sys/arch/amd64/include/segments.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: segments.h,v 1.14 2015/09/30 05:44:32 guenther Exp $ */
+/* $OpenBSD: segments.h,v 1.15 2018/03/29 01:21:02 guenther Exp $ */
/* $NetBSD: segments.h,v 1.1 2003/04/26 18:39:47 fvdl Exp $ */
/*-
@@ -263,9 +263,9 @@ void cpu_init_idt(void);
#define GDT_SYS_OFFSET (NGDT_MEM << 3)
#define GDT_ADDR_MEM(s,i) \
- ((struct mem_segment_descriptor *)((s) + ((i) << 3)))
+ ((struct mem_segment_descriptor *)((char *)(s) + ((i) << 3)))
#define GDT_ADDR_SYS(s,i) \
- ((struct sys_segment_descriptor *)((s) + (((i) << 4) + SYSSEL_START)))
+ ((struct sys_segment_descriptor *)((char *)(s) + ((i) << 4) + SYSSEL_START))
/*
* Checks for valid user selectors.