Presently there is only one `currentldt' variable for all cpus

in a SMP system. Unexpected things could happen if each cpu
        has a different ldt setting and one cpu tries to use value
        of currentldt set by another cpu.

        The fix is to move currentldt to the per-cpu area. It includes
        patches I filed in PR i386/6219 which are also user ldt related.

PR:		i386/7591, i386/6219
Submitted by:	Luoqi Chen <luoqi@watermarkgroup.com>
This commit is contained in:
Mike Smith 1998-08-18 07:47:12 +00:00
parent 95332616af
commit 287e61c39f
19 changed files with 110 additions and 35 deletions

View File

@ -34,10 +34,11 @@
* SUCH DAMAGE.
*
* from: @(#)genassym.c 5.11 (Berkeley) 5/10/91
* $Id: genassym.c,v 1.58 1998/05/28 09:29:55 phk Exp $
* $Id: genassym.c,v 1.59 1998/07/11 12:17:07 bde Exp $
*/
#include "opt_vm86.h"
#include "opt_user_ldt.h"
#include <stddef.h>
@ -204,6 +205,9 @@ main()
printf("#define\tGD_PRIVATE_TSS %#x\n", OS(globaldata, private_tss));
printf("#define\tGD_MY_TR %#x\n", OS(globaldata, my_tr));
#endif
#ifdef USER_LDT
printf("#define\tGD_CURRENTLDT %#x\n", OS(globaldata, currentldt));
#endif
#ifdef SMP
printf("#define\tGD_CPUID %#x\n", OS(globaldata, cpuid));
printf("#define\tGD_CPU_LOCKID %#x\n", OS(globaldata, cpu_lockid));

View File

@ -35,7 +35,7 @@
* SUCH DAMAGE.
*
* from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
* $Id: machdep.c,v 1.302 1998/06/30 21:25:58 phk Exp $
* $Id: machdep.c,v 1.303 1998/07/11 07:45:30 bde Exp $
*/
#include "apm.h"
@ -801,14 +801,15 @@ setregs(p, entry, stack)
u_long stack;
{
struct trapframe *regs = p->p_md.md_regs;
#ifdef USER_LDT
struct pcb *pcb = &p->p_addr->u_pcb;
#ifdef USER_LDT
/* was i386_user_cleanup() in NetBSD */
if (pcb->pcb_ldt) {
if (pcb == curpcb)
lldt(GSEL(GUSERLDT_SEL, SEL_KPL));
if (pcb == curpcb) {
lldt(_default_ldt);
currentldt = _default_ldt;
}
kmem_free(kernel_map, (vm_offset_t)pcb->pcb_ldt,
pcb->pcb_ldt_len * sizeof(union descriptor));
pcb->pcb_ldt_len = (int)pcb->pcb_ldt = 0;
@ -824,6 +825,14 @@ setregs(p, entry, stack)
regs->tf_es = _udatasel;
regs->tf_cs = _ucodesel;
/* reset %fs and %gs as well */
pcb->pcb_fs = _udatasel;
pcb->pcb_gs = _udatasel;
if (pcb == curpcb) {
__asm("mov %0,%%fs" : : "r" (_udatasel));
__asm("mov %0,%%gs" : : "r" (_udatasel));
}
/*
* Initialize the math emulator (if any) for the current process.
* Actually, just clear the bit that says that the emulator has
@ -881,7 +890,6 @@ SYSCTL_INT(_machdep, CPU_WALLCLOCK, wall_cmos_clock,
* Initialize segments & interrupt table
*/
int currentldt;
int _default_ldt;
#ifdef SMP
union descriptor gdt[NGDT + NCPU]; /* global descriptor table */
@ -1248,7 +1256,9 @@ init386(first)
_default_ldt = GSEL(GLDT_SEL, SEL_KPL);
lldt(_default_ldt);
#ifdef USER_LDT
currentldt = _default_ldt;
#endif
#ifdef DDB
kdb_init();

View File

@ -22,12 +22,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.76 1998/05/17 22:12:08 tegge Exp $
* $Id: mp_machdep.c,v 1.77 1998/08/16 00:41:40 bde Exp $
*/
#include "opt_smp.h"
#include "opt_vm86.h"
#include "opt_cpu.h"
#include "opt_user_ldt.h"
#ifdef SMP
#include <machine/smptests.h>
@ -466,6 +467,9 @@ init_secondary(void)
lgdt(&r_gdt); /* does magic intra-segment return */
lidt(&r_idt);
lldt(_default_ldt);
#ifdef USER_LDT
currentldt = _default_ldt;
#endif
my_tr = NGDT + cpuid;
gsel_tss = GSEL(my_tr, SEL_KPL);

View File

@ -22,12 +22,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.76 1998/05/17 22:12:08 tegge Exp $
* $Id: mp_machdep.c,v 1.77 1998/08/16 00:41:40 bde Exp $
*/
#include "opt_smp.h"
#include "opt_vm86.h"
#include "opt_cpu.h"
#include "opt_user_ldt.h"
#ifdef SMP
#include <machine/smptests.h>
@ -466,6 +467,9 @@ init_secondary(void)
lgdt(&r_gdt); /* does magic intra-segment return */
lidt(&r_idt);
lldt(_default_ldt);
#ifdef USER_LDT
currentldt = _default_ldt;
#endif
my_tr = NGDT + cpuid;
gsel_tss = GSEL(my_tr, SEL_KPL);

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* from: @(#)sys_machdep.c 5.5 (Berkeley) 1/19/91
* $Id: sys_machdep.c,v 1.34 1998/03/23 19:52:34 jlemon Exp $
* $Id: sys_machdep.c,v 1.35 1998/07/28 03:29:32 jlemon Exp $
*
*/
@ -64,8 +64,8 @@
void set_user_ldt __P((struct pcb *pcb));
#ifdef USER_LDT
void set_user_ldt __P((struct pcb *pcb));
static int i386_get_ldt __P((struct proc *, char *));
static int i386_set_ldt __P((struct proc *, char *));
#endif

View File

@ -38,7 +38,7 @@
*
* from: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91
* Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
* $Id: vm_machdep.c,v 1.107 1998/05/17 22:12:11 tegge Exp $
* $Id: vm_machdep.c,v 1.108 1998/05/19 00:00:10 tegge Exp $
*/
#include "npx.h"
@ -710,8 +710,10 @@ cpu_exit(p)
#endif
#ifdef USER_LDT
if (pcb->pcb_ldt != 0) {
if (pcb == curpcb)
lldt(GSEL(GUSERLDT_SEL, SEL_KPL));
if (pcb == curpcb) {
lldt(_default_ldt);
currentldt = _default_ldt;
}
kmem_free(kernel_map, (vm_offset_t)pcb->pcb_ldt,
pcb->pcb_ldt_len * sizeof(union descriptor));
pcb->pcb_ldt_len = (int)pcb->pcb_ldt = 0;

View File

@ -22,12 +22,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.76 1998/05/17 22:12:08 tegge Exp $
* $Id: mp_machdep.c,v 1.77 1998/08/16 00:41:40 bde Exp $
*/
#include "opt_smp.h"
#include "opt_vm86.h"
#include "opt_cpu.h"
#include "opt_user_ldt.h"
#ifdef SMP
#include <machine/smptests.h>
@ -466,6 +467,9 @@ init_secondary(void)
lgdt(&r_gdt); /* does magic intra-segment return */
lidt(&r_idt);
lldt(_default_ldt);
#ifdef USER_LDT
currentldt = _default_ldt;
#endif
my_tr = NGDT + cpuid;
gsel_tss = GSEL(my_tr, SEL_KPL);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: globaldata.h,v 1.4 1998/05/17 23:08:02 tegge Exp $
* $Id: globaldata.h,v 1.5 1998/05/28 09:30:02 phk Exp $
*/
/*
@ -49,6 +49,9 @@ struct globaldata {
u_int private_tss;
u_int my_tr;
#endif
#ifdef USER_LDT
int currentldt;
#endif
#ifdef SMP
u_int cpuid;
u_int cpu_lockid;

View File

@ -34,10 +34,11 @@
* SUCH DAMAGE.
*
* from: @(#)genassym.c 5.11 (Berkeley) 5/10/91
* $Id: genassym.c,v 1.58 1998/05/28 09:29:55 phk Exp $
* $Id: genassym.c,v 1.59 1998/07/11 12:17:07 bde Exp $
*/
#include "opt_vm86.h"
#include "opt_user_ldt.h"
#include <stddef.h>
@ -204,6 +205,9 @@ main()
printf("#define\tGD_PRIVATE_TSS %#x\n", OS(globaldata, private_tss));
printf("#define\tGD_MY_TR %#x\n", OS(globaldata, my_tr));
#endif
#ifdef USER_LDT
printf("#define\tGD_CURRENTLDT %#x\n", OS(globaldata, currentldt));
#endif
#ifdef SMP
printf("#define\tGD_CPUID %#x\n", OS(globaldata, cpuid));
printf("#define\tGD_CPU_LOCKID %#x\n", OS(globaldata, cpu_lockid));

View File

@ -23,10 +23,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: globals.s,v 1.5 1998/05/28 09:29:56 phk Exp $
* $Id: globals.s,v 1.6 1998/06/21 14:45:00 bde Exp $
*/
#include "opt_vm86.h"
#include "opt_user_ldt.h"
#ifndef SMP
#include <machine/asmacros.h>
@ -84,6 +85,11 @@ globaldata:
.set _my_tr,globaldata + GD_MY_TR
#endif
#ifdef USER_LDT
.globl _currentldt
.set _currentldt,globaldata + GD_CURRENTLDT
#endif
#ifdef SMP
/*
* The BSP version of these get setup in locore.s and pmap.c, while

View File

@ -35,7 +35,7 @@
* SUCH DAMAGE.
*
* from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
* $Id: machdep.c,v 1.302 1998/06/30 21:25:58 phk Exp $
* $Id: machdep.c,v 1.303 1998/07/11 07:45:30 bde Exp $
*/
#include "apm.h"
@ -801,14 +801,15 @@ setregs(p, entry, stack)
u_long stack;
{
struct trapframe *regs = p->p_md.md_regs;
#ifdef USER_LDT
struct pcb *pcb = &p->p_addr->u_pcb;
#ifdef USER_LDT
/* was i386_user_cleanup() in NetBSD */
if (pcb->pcb_ldt) {
if (pcb == curpcb)
lldt(GSEL(GUSERLDT_SEL, SEL_KPL));
if (pcb == curpcb) {
lldt(_default_ldt);
currentldt = _default_ldt;
}
kmem_free(kernel_map, (vm_offset_t)pcb->pcb_ldt,
pcb->pcb_ldt_len * sizeof(union descriptor));
pcb->pcb_ldt_len = (int)pcb->pcb_ldt = 0;
@ -824,6 +825,14 @@ setregs(p, entry, stack)
regs->tf_es = _udatasel;
regs->tf_cs = _ucodesel;
/* reset %fs and %gs as well */
pcb->pcb_fs = _udatasel;
pcb->pcb_gs = _udatasel;
if (pcb == curpcb) {
__asm("mov %0,%%fs" : : "r" (_udatasel));
__asm("mov %0,%%gs" : : "r" (_udatasel));
}
/*
* Initialize the math emulator (if any) for the current process.
* Actually, just clear the bit that says that the emulator has
@ -881,7 +890,6 @@ SYSCTL_INT(_machdep, CPU_WALLCLOCK, wall_cmos_clock,
* Initialize segments & interrupt table
*/
int currentldt;
int _default_ldt;
#ifdef SMP
union descriptor gdt[NGDT + NCPU]; /* global descriptor table */
@ -1248,7 +1256,9 @@ init386(first)
_default_ldt = GSEL(GLDT_SEL, SEL_KPL);
lldt(_default_ldt);
#ifdef USER_LDT
currentldt = _default_ldt;
#endif
#ifdef DDB
kdb_init();

View File

@ -22,12 +22,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.76 1998/05/17 22:12:08 tegge Exp $
* $Id: mp_machdep.c,v 1.77 1998/08/16 00:41:40 bde Exp $
*/
#include "opt_smp.h"
#include "opt_vm86.h"
#include "opt_cpu.h"
#include "opt_user_ldt.h"
#ifdef SMP
#include <machine/smptests.h>
@ -466,6 +467,9 @@ init_secondary(void)
lgdt(&r_gdt); /* does magic intra-segment return */
lidt(&r_idt);
lldt(_default_ldt);
#ifdef USER_LDT
currentldt = _default_ldt;
#endif
my_tr = NGDT + cpuid;
gsel_tss = GSEL(my_tr, SEL_KPL);

View File

@ -22,12 +22,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.76 1998/05/17 22:12:08 tegge Exp $
* $Id: mp_machdep.c,v 1.77 1998/08/16 00:41:40 bde Exp $
*/
#include "opt_smp.h"
#include "opt_vm86.h"
#include "opt_cpu.h"
#include "opt_user_ldt.h"
#ifdef SMP
#include <machine/smptests.h>
@ -466,6 +467,9 @@ init_secondary(void)
lgdt(&r_gdt); /* does magic intra-segment return */
lidt(&r_idt);
lldt(_default_ldt);
#ifdef USER_LDT
currentldt = _default_ldt;
#endif
my_tr = NGDT + cpuid;
gsel_tss = GSEL(my_tr, SEL_KPL);

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* from: @(#)sys_machdep.c 5.5 (Berkeley) 1/19/91
* $Id: sys_machdep.c,v 1.34 1998/03/23 19:52:34 jlemon Exp $
* $Id: sys_machdep.c,v 1.35 1998/07/28 03:29:32 jlemon Exp $
*
*/
@ -64,8 +64,8 @@
void set_user_ldt __P((struct pcb *pcb));
#ifdef USER_LDT
void set_user_ldt __P((struct pcb *pcb));
static int i386_get_ldt __P((struct proc *, char *));
static int i386_set_ldt __P((struct proc *, char *));
#endif

View File

@ -38,7 +38,7 @@
*
* from: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91
* Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
* $Id: vm_machdep.c,v 1.107 1998/05/17 22:12:11 tegge Exp $
* $Id: vm_machdep.c,v 1.108 1998/05/19 00:00:10 tegge Exp $
*/
#include "npx.h"
@ -710,8 +710,10 @@ cpu_exit(p)
#endif
#ifdef USER_LDT
if (pcb->pcb_ldt != 0) {
if (pcb == curpcb)
lldt(GSEL(GUSERLDT_SEL, SEL_KPL));
if (pcb == curpcb) {
lldt(_default_ldt);
currentldt = _default_ldt;
}
kmem_free(kernel_map, (vm_offset_t)pcb->pcb_ldt,
pcb->pcb_ldt_len * sizeof(union descriptor));
pcb->pcb_ldt_len = (int)pcb->pcb_ldt = 0;

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: globaldata.h,v 1.4 1998/05/17 23:08:02 tegge Exp $
* $Id: globaldata.h,v 1.5 1998/05/28 09:30:02 phk Exp $
*/
/*
@ -49,6 +49,9 @@ struct globaldata {
u_int private_tss;
u_int my_tr;
#endif
#ifdef USER_LDT
int currentldt;
#endif
#ifdef SMP
u_int cpuid;
u_int cpu_lockid;

View File

@ -22,12 +22,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.76 1998/05/17 22:12:08 tegge Exp $
* $Id: mp_machdep.c,v 1.77 1998/08/16 00:41:40 bde Exp $
*/
#include "opt_smp.h"
#include "opt_vm86.h"
#include "opt_cpu.h"
#include "opt_user_ldt.h"
#ifdef SMP
#include <machine/smptests.h>
@ -466,6 +467,9 @@ init_secondary(void)
lgdt(&r_gdt); /* does magic intra-segment return */
lidt(&r_idt);
lldt(_default_ldt);
#ifdef USER_LDT
currentldt = _default_ldt;
#endif
my_tr = NGDT + cpuid;
gsel_tss = GSEL(my_tr, SEL_KPL);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: globaldata.h,v 1.4 1998/05/17 23:08:02 tegge Exp $
* $Id: globaldata.h,v 1.5 1998/05/28 09:30:02 phk Exp $
*/
/*
@ -49,6 +49,9 @@ struct globaldata {
u_int private_tss;
u_int my_tr;
#endif
#ifdef USER_LDT
int currentldt;
#endif
#ifdef SMP
u_int cpuid;
u_int cpu_lockid;

View File

@ -22,12 +22,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.76 1998/05/17 22:12:08 tegge Exp $
* $Id: mp_machdep.c,v 1.77 1998/08/16 00:41:40 bde Exp $
*/
#include "opt_smp.h"
#include "opt_vm86.h"
#include "opt_cpu.h"
#include "opt_user_ldt.h"
#ifdef SMP
#include <machine/smptests.h>
@ -466,6 +467,9 @@ init_secondary(void)
lgdt(&r_gdt); /* does magic intra-segment return */
lidt(&r_idt);
lldt(_default_ldt);
#ifdef USER_LDT
currentldt = _default_ldt;
#endif
my_tr = NGDT + cpuid;
gsel_tss = GSEL(my_tr, SEL_KPL);