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

[Minios-devel] [UNIKRAFT PATCH 04/23] plat: Hardware context - Add trampoline for starting threads


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 8 Jul 2019 11:33:33 +0300
  • Cc: felipe.huici@xxxxxxxxx, simon.kuenzer@xxxxxxxxx
  • Delivery-date: Mon, 08 Jul 2019 08:53:54 +0000
  • Ironport-phdr: 9a23:dGbSBh+F5Ps8sP9uRHKM819IXTAuvvDOBiVQ1KB20+McTK2v8tzYMVDF4r011RmVBN+dt6oP07aempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffhtEiCCybL9uIxm6sQrcvdQKjIV/Lao81gHHqWZSdeRMwmNoK1OTnxLi6cq14ZVu7Sdete8/+sBZSan1cLg2QrJeDDQ9LmA6/9brugXZTQuO/XQTTGMbmQdVDgff7RH6WpDxsjbmtud4xSKXM9H6QawyVD+/6apgVR3mhzodNzMh8G/ZlNF+gqxYrhympRN/zZXZbJ2JOPdkYq/QZ88WSXZHU81MVyJBGIS8b44XAucfOuZYtJX9p1oIrRCjAwesGfvvyiJVjXLxwaI61P8hER3H3AwmBd4OtGnUrM3oNKoJTe+117PEzS3eb/xNwzv98o/IfwknrPqRU7xwds/RxlMuFwPDlliQspDlMCmP1uQRqWSb9PFvWOSygGAkswF8uiWjy8gxhoXThY8YykrI+TtnzIs3P9G1RlZ3bcOrHZdNrS2XNIt7Ttk8T2xmtis20KAKtJGlcCUM1Z8p3QTQa+adfIiN+h/jUeGRLipmi399Y7K/ggqy8VCnyu3hSsm4yFZKoTRBktnLrn0NyRnT5dKGSvt55EuuxS2P2xrL6uFZOk84j7DbK5k5zr4xkJocr1jDEzfrlEj5kaOabEYp9+iy5+j5fLnrpIWQOoFshgH7KKsum8i/AeoiMggJWmiW4fiz1Lr4/U3lQbVKiOc6kq3EsJDCOMQWvbK2AxRP3oY79hawFC2q0M4fnXUfNlJKZAqHj5T1O1HJOP34CPa/g1KtkDds3PDKJ6DuDYvTLnfdlLfsZrJ9609HyAov1tBT/Z1VBa8HIP7pXU/xrtPYBAcjMwOo2+bnFMl91oQGVGKBHKCZNKLSsUeW6e41I+mMeY4Vtyr8K/U+4f7hk2M2mVsHcqayx5cYdm24FOx8I0qFeXrsnssBEWASswolTezqjVqCUThJa3axQqIz+Dc7CYO4AofZXY2thqKO0zu/HpJMfW9KEE6DEWq7P7mDDvINbiOVOYptnyIJUZClSpQ9zle+uQm8zKBofcTO/ShNnpX4yNlzr8nOjQx6oTdzFNic1SeJUnlptmgTAScr1uZlphoumR+4zaFkjqkARpRo7PRTX1JiOA==
  • Ironport-sdr: Hdo/NuShgH03LzVoHGQ1oeiqiG2PVqwM6Je0D8A8lvni613rOm+875HIpL6I14vhSDj/XiClNe aABmk4SBTMAQ==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Before starting threads, we consider they were "interrupted" because we use the
hardware support in order to enable interrupts atomically on activating the
thread. An interrupted thread may be preempted and therefore we need to save its
continuation point - the address that will be first executed when it will be
switched back on. Thus we need such a continuation point for starting the thread
as well. For this purpose this patch introduces the trampoline which will be the
first continuation point of newly created threads. We recycle the padding field
of the __regs structure for saving continuations from now on.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 plat/common/x86/hw_ctx.c       | 11 +++++++++++
 plat/common/x86/thread_start.S | 13 +++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/plat/common/x86/hw_ctx.c b/plat/common/x86/hw_ctx.c
index e82beb5f..778e546d 100644
--- a/plat/common/x86/hw_ctx.c
+++ b/plat/common/x86/hw_ctx.c
@@ -48,6 +48,7 @@ static void  hw_ctx_start(void *ctx) __noreturn;
 static void  hw_ctx_switch(void *prevctx, void *nextctx);
 
 extern void asm_thread_starter(void);
+extern void asm_thread_starter_trampoline(void);
 
 /* Architecture specific setup of thread creation */
 void hw_ctx_init(void *ctx, unsigned long sp)
@@ -63,6 +64,16 @@ void hw_ctx_init(void *ctx, unsigned long sp)
        hw_ctx->regs.eflags = X86_EFLAGS_IF;
        hw_ctx->regs.rsp = sp;
        hw_ctx->regs.ss = GDT_DESC_SELECTOR(DATA);
+
+       /*
+        * We start by setting interrupted on true because this thread
+        * hasn't yield yet and we'll be using the hardware support to
+        * start it with enabled interrupts
+        */
+       hw_ctx->interrupted = true;
+
+       /* First continuation is a trampoline to initial thread IP */
+       hw_ctx->regs.pad = (unsigned long) asm_thread_starter_trampoline;
 }
 
 extern void asm_ctx_start(unsigned long sp, unsigned long ip) __noreturn;
diff --git a/plat/common/x86/thread_start.S b/plat/common/x86/thread_start.S
index 57d957a6..105691ee 100644
--- a/plat/common/x86/thread_start.S
+++ b/plat/common/x86/thread_start.S
@@ -26,12 +26,25 @@
  */
 /* Taken from Mini-OS arch/x86/x86_64.S */
 
+#include <uk/arch/limits.h>
+#include <x86/regs.h>
 #include <sw_ctx.h>
 
 #define ENTRY(X) .globl X ; X :
 
 #include "thread_macros.S"
 
+ENTRY(asm_thread_starter_trampoline)
+       /* Load current thread */
+       and $STACK_MASK_TOP, %rsp
+       mov (%rsp), %rsp
+       /* Load current context */
+       mov OFFSETOF_UKTHREAD_REGS(%rsp), %rsp
+       mov (%rsp), %rsp
+       /* Load exception stack */
+       add $OFFSETOF_REGS_RIP, %rsp
+       iretq
+
 ENTRY(asm_thread_starter)
        popq %rdi
        popq %rbx
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.