Module Name:    src
Committed By:   cherry
Date:           Sat Nov  4 08:50:48 UTC 2017

Modified Files:
        src/sys/arch/amd64/amd64: machdep.c
        src/sys/arch/amd64/include: segments.h
        src/sys/arch/i386/i386: machdep.c
        src/sys/arch/i386/include: segments.h
        src/sys/arch/x86/x86: idt.c
        src/sys/arch/xen/conf: files.xen

Log Message:
In XEN PV, the idt vector table is not required to be altered at
runtime, since only entries for exceptions/traps are registered with
the hypervisor and interrupts are managed via a completely different
mechanism.

This change uses the idt_vec_reserve() mechanism nevertheless,
modifying it slightly to only do namespace management in XEN, while on
native it will continue to do idt entry init as before.

Rationale: Consistent API usage and potential future merging of
XEN/non-XEN code.

There are no functional changes in this commit.


To generate a diff of this commit:
cvs rdiff -u -r1.274 -r1.275 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/amd64/include/segments.h
cvs rdiff -u -r1.797 -r1.798 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/i386/include/segments.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x86/x86/idt.c
cvs rdiff -u -r1.157 -r1.158 src/sys/arch/xen/conf/files.xen

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.274 src/sys/arch/amd64/amd64/machdep.c:1.275
--- src/sys/arch/amd64/amd64/machdep.c:1.274	Sun Oct 29 10:25:28 2017
+++ src/sys/arch/amd64/amd64/machdep.c	Sat Nov  4 08:50:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.274 2017/10/29 10:25:28 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.275 2017/11/04 08:50:47 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.274 2017/10/29 10:25:28 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.275 2017/11/04 08:50:47 cherry Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1747,6 +1747,7 @@ init_x86_64(paddr_t first_avail)
 		    GSEL(GCODE_SEL, SEL_KPL));
 #else /* XEN */
 		pmap_changeprot_local(idt_vaddr, VM_PROT_READ|VM_PROT_WRITE);
+		idt_vec_reserve(x);
 		xen_idt[xen_idt_idx].vector = x;
 
 		switch (x) {
@@ -1776,6 +1777,7 @@ init_x86_64(paddr_t first_avail)
 	setgate(&idt[128], &IDTVEC(osyscall), 0, SDT_SYS386IGT, SEL_UPL,
 	    GSEL(GCODE_SEL, SEL_KPL));
 #else
+	idt_vec_reserve(128);
 	xen_idt[xen_idt_idx].vector = 128;
 	xen_idt[xen_idt_idx].flags = SEL_KPL;
 	xen_idt[xen_idt_idx].cs = GSEL(GCODE_SEL, SEL_KPL);

Index: src/sys/arch/amd64/include/segments.h
diff -u src/sys/arch/amd64/include/segments.h:1.32 src/sys/arch/amd64/include/segments.h:1.33
--- src/sys/arch/amd64/include/segments.h:1.32	Wed Nov  1 07:14:29 2017
+++ src/sys/arch/amd64/include/segments.h	Sat Nov  4 08:50:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: segments.h,v 1.32 2017/11/01 07:14:29 maxv Exp $	*/
+/*	$NetBSD: segments.h,v 1.33 2017/11/04 08:50:47 cherry Exp $	*/
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -245,12 +245,12 @@ void set_mem_segment(struct mem_segment_
 void cpu_init_idt(void);
 void update_descriptor(void *, void *);
 
-#if !defined(XEN)
+
 void idt_vec_reserve(int);
 int idt_vec_alloc(int, int);
 void idt_vec_set(int, void (*)(void));
 void idt_vec_free(int);
-#endif
+
 
 struct lwp;
 void cpu_segregs64_zero(struct lwp *);

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.797 src/sys/arch/i386/i386/machdep.c:1.798
--- src/sys/arch/i386/i386/machdep.c:1.797	Sun Oct 29 10:01:21 2017
+++ src/sys/arch/i386/i386/machdep.c	Sat Nov  4 08:50:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.797 2017/10/29 10:01:21 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.798 2017/11/04 08:50:47 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.797 2017/10/29 10:01:21 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.798 2017/11/04 08:50:47 cherry Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -1355,6 +1355,7 @@ init386(paddr_t first_avail)
 	xen_idt_idx = 0;
 	for (x = 0; x < 32; x++) {
 		KASSERT(xen_idt_idx < MAX_XEN_IDT);
+		idt_vec_reserve(x);
 		xen_idt[xen_idt_idx].vector = x;
 
 		switch (x) {
@@ -1377,6 +1378,7 @@ init386(paddr_t first_avail)
 		xen_idt_idx++;
 	}
 	KASSERT(xen_idt_idx < MAX_XEN_IDT);
+	idt_vec_reserve(128);
 	xen_idt[xen_idt_idx].vector = 128;
 	xen_idt[xen_idt_idx].flags = SEL_UPL;
 	xen_idt[xen_idt_idx].cs = GSEL(GCODE_SEL, SEL_KPL);

Index: src/sys/arch/i386/include/segments.h
diff -u src/sys/arch/i386/include/segments.h:1.62 src/sys/arch/i386/include/segments.h:1.63
--- src/sys/arch/i386/include/segments.h:1.62	Sun Sep 17 09:41:35 2017
+++ src/sys/arch/i386/include/segments.h	Sat Nov  4 08:50:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: segments.h,v 1.62 2017/09/17 09:41:35 maxv Exp $	*/
+/*	$NetBSD: segments.h,v 1.63 2017/11/04 08:50:47 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -200,12 +200,12 @@ void unsetgate(struct gate_descriptor *)
 void cpu_init_idt(void);
 void update_descriptor(union descriptor *, union descriptor *);
 
-#if !defined(XEN)
+
 void idt_vec_reserve(int);
 int idt_vec_alloc(int, int);
 void idt_vec_set(int, void (*)(void));
 void idt_vec_free(int);
-#endif
+
 
 #endif /* _KERNEL */
 

Index: src/sys/arch/x86/x86/idt.c
diff -u src/sys/arch/x86/x86/idt.c:1.5 src/sys/arch/x86/x86/idt.c:1.6
--- src/sys/arch/x86/x86/idt.c:1.5	Mon Aug  7 17:10:09 2017
+++ src/sys/arch/x86/x86/idt.c	Sat Nov  4 08:50:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: idt.c,v 1.5 2017/08/07 17:10:09 maxv Exp $	*/
+/*	$NetBSD: idt.c,v 1.6 2017/11/04 08:50:47 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2009 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: idt.c,v 1.5 2017/08/07 17:10:09 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: idt.c,v 1.6 2017/11/04 08:50:47 cherry Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -75,9 +75,12 @@ __KERNEL_RCSID(0, "$NetBSD: idt.c,v 1.5 
 
 #include <machine/segments.h>
 
+/* On xen PV this is just numberspace management - used in x86/intr.c */
 #if !defined(XEN)
 
 struct gate_descriptor *idt;
+#endif
+
 static char idt_allocmap[NIDT];
 
 /*
@@ -120,8 +123,10 @@ idt_vec_set(int vec, void (*function)(vo
 {
 
 	KASSERT(idt_allocmap[vec] == 1);
+#if !defined(XEN)
 	setgate(&idt[vec], function, 0, SDT_SYS386IGT, SEL_KPL,
 	    GSEL(GCODE_SEL, SEL_KPL));
+#endif
 }
 
 /*
@@ -131,8 +136,9 @@ void
 idt_vec_free(int vec)
 {
 
+#if !defined(XEN)
 	unsetgate(&idt[vec]);
+#endif
 	idt_allocmap[vec] = 0;
 }
 
-#endif /* !defined(XEN) */

Index: src/sys/arch/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.157 src/sys/arch/xen/conf/files.xen:1.158
--- src/sys/arch/xen/conf/files.xen:1.157	Sat Nov  4 07:01:45 2017
+++ src/sys/arch/xen/conf/files.xen	Sat Nov  4 08:50:47 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.157 2017/11/04 07:01:45 cherry Exp $
+#	$NetBSD: files.xen,v 1.158 2017/11/04 08:50:47 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -140,6 +140,7 @@ file	arch/xen/x86/consinit.c		machdep
 file	arch/x86/x86/identcpu.c		machdep
 file	arch/xen/x86/intr.c		machdep
 file	arch/xen/x86/xen_ipi.c		multiprocessor
+file	arch/x86/x86/idt.c		machdep
 file	arch/x86/x86/pmap.c		machdep
 file	arch/x86/x86/pmap_tlb.c		machdep
 file	arch/x86/x86/procfs_machdep.c	procfs

Reply via email to