bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] percpu: active_stack with gs


From: Damien Zammit
Subject: [PATCH] percpu: active_stack with gs
Date: Mon, 25 Sep 2023 00:24:25 +0000

---
 i386/i386/cswitch.S   | 12 ++++++------
 i386/i386/i386asm.sym |  1 +
 i386/i386/locore.S    |  2 +-
 i386/i386/percpu.h    |  2 +-
 kern/startup.c        |  2 +-
 kern/thread.c         |  4 +---
 kern/thread.h         |  5 +----
 x86_64/cswitch.S      | 10 ++++------
 x86_64/locore.S       |  2 +-
 9 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/i386/i386/cswitch.S b/i386/i386/cswitch.S
index 598e32cf..2dee309b 100644
--- a/i386/i386/cswitch.S
+++ b/i386/i386/cswitch.S
@@ -41,7 +41,7 @@ ENTRY(Load_context)
        lea     KERNEL_STACK_SIZE-IKS_SIZE-IEL_SIZE(%ecx),%edx
                                                /* point to stack top */
        CPU_NUMBER(%eax)
-       movl    %ecx,CX(EXT(active_stacks),%eax)        /* store stack address 
*/
+       movl    %ecx,MY(ACTIVE_STACK)           /* store stack address */
        movl    %edx,CX(EXT(kernel_stack),%eax) /* store stack top */
 
        movl    KSS_ESP(%ecx),%esp              /* switch stacks */
@@ -58,8 +58,7 @@ ENTRY(Load_context)
  */
 
 ENTRY(Switch_context)
-       CPU_NUMBER(%edx)
-       movl    CX(EXT(active_stacks),%edx),%ecx        /* get old kernel stack 
*/
+       movl    MY(ACTIVE_STACK),%ecx           /* get old kernel stack */
 
        movl    %ebx,KSS_EBX(%ecx)              /* save registers */
        movl    %ebp,KSS_EBP(%ecx)
@@ -79,8 +78,9 @@ ENTRY(Switch_context)
        lea     KERNEL_STACK_SIZE-IKS_SIZE-IEL_SIZE(%ecx),%ebx
                                                /* point to stack top */
 
+       CPU_NUMBER(%edx)
        movl    %esi,MY(ACTIVE_THREAD)          /* new thread is active */
-       movl    %ecx,CX(EXT(active_stacks),%edx)        /* set current stack */
+       movl    %ecx,MY(ACTIVE_STACK)           /* set current stack */
        movl    %ebx,CX(EXT(kernel_stack),%edx) /* set stack top */
 
        movl    KSS_ESP(%ecx),%esp              /* switch stacks */
@@ -110,8 +110,7 @@ ENTRY(Thread_continue)
  * has no FPU state)
  */
 ENTRY(switch_to_shutdown_context)
-       CPU_NUMBER(%edx)
-       movl    CX(EXT(active_stacks),%edx),%ecx        /* get old kernel stack 
*/
+       movl    MY(ACTIVE_STACK),%ecx           /* get old kernel stack */
        movl    %ebx,KSS_EBX(%ecx)              /* save registers */
        movl    %ebp,KSS_EBP(%ecx)
        movl    %edi,KSS_EDI(%ecx)
@@ -125,6 +124,7 @@ ENTRY(switch_to_shutdown_context)
        movl    4(%esp),%ebx                    /* get routine to run next */
        movl    8(%esp),%esi                    /* get its argument */
 
+       CPU_NUMBER(%edx)
        movl    CX(EXT(int_stack_base),%edx),%ecx       /* point to its 
interrupt stack */
        lea     -4+INTSTACK_SIZE(%ecx),%esp     /* switch to it (top) */
 
diff --git a/i386/i386/i386asm.sym b/i386/i386/i386asm.sym
index e9a792c3..e1f5c6bb 100644
--- a/i386/i386/i386asm.sym
+++ b/i386/i386/i386asm.sym
@@ -55,6 +55,7 @@ offset        ApicLocalUnit           lu      apic_id         
APIC_ID
 
 offset percpu                  pc      cpu_id          PERCPU_CPU_ID
 offset percpu                  pc      active_thread   PERCPU_ACTIVE_THREAD
+offset percpu                  pc      active_stack    PERCPU_ACTIVE_STACK
 
 offset pcb                     pcb     iss
 
diff --git a/i386/i386/locore.S b/i386/i386/locore.S
index 8fba7638..d3986793 100644
--- a/i386/i386/locore.S
+++ b/i386/i386/locore.S
@@ -555,7 +555,7 @@ trap_from_kernel:
        cmpl    CX(EXT(kernel_stack),%edx),%esp
                                        /* already on kernel stack? */
        ja      0f
-       cmpl    CX(EXT(active_stacks),%edx),%esp
+       cmpl    MY(ACTIVE_STACK),%esp
        ja      1f                      /* switch if not */
 0:
        movl    CX(EXT(kernel_stack),%edx),%esp
diff --git a/i386/i386/percpu.h b/i386/i386/percpu.h
index ad4836ce..d73cfc8d 100644
--- a/i386/i386/percpu.h
+++ b/i386/i386/percpu.h
@@ -59,10 +59,10 @@ struct percpu {
     int                        cpu_id;
     struct processor   processor;
     thread_t           active_thread;
+    vm_offset_t                active_stack;
 /*
     struct machine_slot        machine_slot;
     struct mp_desc_table mp_desc_table;
-    vm_offset_t                active_stack;
     vm_offset_t                int_stack_top;
     vm_offset_t                int_stack_base;
     ast_t              need_ast;
diff --git a/kern/startup.c b/kern/startup.c
index 177232fc..e72cf6f4 100644
--- a/kern/startup.c
+++ b/kern/startup.c
@@ -301,7 +301,7 @@ void cpu_launch_first_thread(thread_t th)
        PMAP_ACTIVATE_KERNEL(mycpu);
 
        percpu_assign(active_thread, th);
-       active_stacks[mycpu] = th->kernel_stack;
+       percpu_assign(active_stack, th->kernel_stack);
        thread_lock(th);
        th->state &= ~TH_UNINT;
        thread_unlock(th);
diff --git a/kern/thread.c b/kern/thread.c
index c397de84..38287581 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -69,8 +69,6 @@
 #include <machine/pcb.h>
 #include <machine/thread.h>            /* for MACHINE_STACK */
 
-vm_offset_t active_stacks[NCPUS];
-
 struct kmem_cache thread_cache;
 struct kmem_cache thread_stack_cache;
 
@@ -2572,7 +2570,7 @@ kern_return_t processor_set_stack_usage(
 
                        for (cpu = 0; cpu < smp_get_numcpus(); cpu++)
                                if (percpu_array[cpu].active_thread == thread) {
-                                       stack = active_stacks[cpu];
+                                       stack = percpu_array[cpu].active_stack;
                                        break;
                                }
                }
diff --git a/kern/thread.h b/kern/thread.h
index 144160d5..7bfe2e89 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -268,9 +268,6 @@ typedef struct thread *thread_t;
 typedef        mach_port_t *thread_array_t;
 #endif /* _KERN_KERN_TYPES_H_ */
 
-
-extern vm_offset_t     active_stacks[NCPUS];   /* active kernel stacks */
-
 #ifdef KERNEL
 /*
  *     User routines
@@ -417,7 +414,7 @@ extern void         thread_unfreeze(
 #define current_thread()       (percpu_get(thread_t, active_thread))
 #endif /* CURRENT_THREAD */
 
-#define        current_stack()         (active_stacks[cpu_number()])
+#define        current_stack()         (percpu_get(vm_offset_t, active_stack))
 
 #define        current_task()          (current_thread()->task)
 #define        current_space()         (current_task()->itk_space)
diff --git a/x86_64/cswitch.S b/x86_64/cswitch.S
index 29dae62c..9c4640fd 100644
--- a/x86_64/cswitch.S
+++ b/x86_64/cswitch.S
@@ -40,7 +40,7 @@ ENTRY(Load_context)
        lea     KERNEL_STACK_SIZE-IKS_SIZE-IEL_SIZE(%rcx),%rdx
                                                /* point to stack top */
        CPU_NUMBER(%eax)
-       movq    %rcx,CX(EXT(active_stacks),%rax)        /* store stack address 
*/
+       movq    %rcx,MY(ACTIVE_STACK)           /* store stack address */
        movq    %rdx,CX(EXT(kernel_stack),%rax) /* store stack top */
 
 /* XXX complete */
@@ -61,8 +61,7 @@ ENTRY(Load_context)
  */
 
 ENTRY(Switch_context)
-       CPU_NUMBER(%eax)
-       movq    CX(EXT(active_stacks),%rax),%rcx        /* get old kernel stack 
*/
+       movq    MY(ACTIVE_STACK),%rcx           /* get old kernel stack */
 
        movq    %r12,KSS_R12(%rcx)              /* save registers */
        movq    %r13,KSS_R13(%rcx)
@@ -86,7 +85,7 @@ ENTRY(Switch_context)
 
        CPU_NUMBER(%eax)
        movq    %rsi,MY(ACTIVE_THREAD)          /* new thread is active */
-       movq    %rcx,CX(EXT(active_stacks),%rax)        /* set current stack */
+       movq    %rcx,MY(ACTIVE_STACK)           /* set current stack */
        movq    %rbx,CX(EXT(kernel_stack),%rax) /* set stack top */
 
        movq    KSS_ESP(%rcx),%rsp              /* switch stacks */
@@ -119,8 +118,7 @@ ENTRY(Thread_continue)
  */
 ENTRY(switch_to_shutdown_context)
 ud2
-       CPU_NUMBER(%eax)
-       movq    CX(EXT(active_stacks),%rax),%rcx        /* get old kernel stack 
*/
+       movq    MY(ACTIVE_STACK),%rcx           /* get old kernel stack */
        movq    %r12,KSS_R12(%rcx)              /* save registers */
        movq    %r13,KSS_R13(%rcx)
        movq    %r14,KSS_R14(%rcx)
diff --git a/x86_64/locore.S b/x86_64/locore.S
index 55dc4d27..7eaeda3b 100644
--- a/x86_64/locore.S
+++ b/x86_64/locore.S
@@ -673,7 +673,7 @@ trap_from_kernel:
        cmpq    CX(EXT(kernel_stack),%rdx),%rsp
                                        /* already on kernel stack? */
        ja      0f
-       cmpq    CX(EXT(active_stacks),%rdx),%rsp
+       cmpq    MY(ACTIVE_STACK),%rsp
        ja      1f                      /* switch if not */
 0:
        movq    CX(EXT(kernel_stack),%rdx),%rsp
-- 
2.40.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]