Module: xenomai-jki
Branch: for-forge
Commit: 1ca1924e0a825e8656fbc63d4147a9734b6a0254
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=1ca1924e0a825e8656fbc63d4147a9734b6a0254

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Sun Jun 21 12:34:08 2015 +0200

cobalt/kernel: Simplify mayday processing

The mayday exist in order to kick a xenomai userspace task into
secondary mode while it is running userspace code. For that we ask
I-pipe to call us back when the task was interrupted and is about to
return to userspace. So far we defer the relaxation from that callback
via a VDSO-like mechanism that triggers a special syscall to the return
path of that syscall. However, that is not desirable because it is a
complex, arch-specific mechanism that may easily break and that destroys
the backtrace of ptraced tasks.

Fortunately, we can fulfill the needs of mayday also by relaxing the
task directly from that mayday callback. Tested successfully on x86-64
and ARM, other archs require validation.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 include/cobalt/kernel/ppd.h                        |    1 -
 kernel/cobalt/arch/arm/Makefile                    |    2 +-
 .../cobalt/arch/arm/include/asm/xenomai/thread.h   |   10 -
 kernel/cobalt/arch/arm/mayday.c                    |  146 --------------
 kernel/cobalt/arch/blackfin/Makefile               |    2 +-
 .../arch/blackfin/include/asm/xenomai/thread.h     |    5 -
 kernel/cobalt/arch/blackfin/mayday.c               |  112 -----------
 kernel/cobalt/arch/nios2/Makefile                  |    2 +-
 .../cobalt/arch/nios2/include/asm/xenomai/thread.h |    5 -
 kernel/cobalt/arch/nios2/mayday.c                  |   95 ---------
 kernel/cobalt/arch/powerpc/Makefile                |    2 +-
 .../arch/powerpc/include/asm/xenomai/thread.h      |    4 -
 kernel/cobalt/arch/powerpc/mayday.c                |   91 ---------
 kernel/cobalt/arch/sh/Makefile                     |    2 +-
 kernel/cobalt/arch/sh/include/asm/xenomai/thread.h |    4 -
 kernel/cobalt/arch/sh/mayday.c                     |   99 ---------
 kernel/cobalt/arch/x86/Makefile                    |    2 +-
 .../cobalt/arch/x86/include/asm/xenomai/thread.h   |    4 -
 kernel/cobalt/arch/x86/mayday.c                    |  212 --------------------
 kernel/cobalt/include/asm-generic/xenomai/mayday.h |   39 ----
 kernel/cobalt/posix/process.c                      |   47 +----
 kernel/cobalt/posix/syscall.c                      |   31 ---
 kernel/cobalt/thread.c                             |    1 -
 23 files changed, 8 insertions(+), 910 deletions(-)

diff --git a/include/cobalt/kernel/ppd.h b/include/cobalt/kernel/ppd.h
index 5eabd1d..f0079fe 100644
--- a/include/cobalt/kernel/ppd.h
+++ b/include/cobalt/kernel/ppd.h
@@ -32,7 +32,6 @@ struct cobalt_umm {
 
 struct cobalt_ppd {
        struct cobalt_umm umm;
-       unsigned long mayday_tramp;
        atomic_t refcnt;
        char *exe_path;
        struct rb_root fds;
diff --git a/kernel/cobalt/arch/arm/Makefile b/kernel/cobalt/arch/arm/Makefile
index f2e4e20..f182435 100644
--- a/kernel/cobalt/arch/arm/Makefile
+++ b/kernel/cobalt/arch/arm/Makefile
@@ -1,5 +1,5 @@
 obj-$(CONFIG_XENOMAI) += xenomai.o
 
-xenomai-y := machine.o mayday.o thread.o switch.o syscall.o
+xenomai-y := machine.o thread.o switch.o syscall.o
 
 ccflags-y := -Iarch/arm/xenomai/include -Iinclude/xenomai
diff --git a/kernel/cobalt/arch/arm/include/asm/xenomai/thread.h 
b/kernel/cobalt/arch/arm/include/asm/xenomai/thread.h
index 3d8e699..304a059 100644
--- a/kernel/cobalt/arch/arm/include/asm/xenomai/thread.h
+++ b/kernel/cobalt/arch/arm/include/asm/xenomai/thread.h
@@ -37,16 +37,6 @@ struct xnarchtcb {
 #define xnarch_fpu_ptr(tcb)     NULL
 #endif
 #endif
-       struct {
-               unsigned long pc;
-               unsigned long r0;
-#ifdef __ARM_EABI__
-               unsigned long r7;
-#endif
-#ifdef CONFIG_ARM_THUMB
-               unsigned long psr;
-#endif
-       } mayday;
 };
 
 #define xnarch_fault_regs(d)   ((d)->regs)
diff --git a/kernel/cobalt/arch/arm/mayday.c b/kernel/cobalt/arch/arm/mayday.c
deleted file mode 100644
index 20e4559..0000000
--- a/kernel/cobalt/arch/arm/mayday.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (C) 2010 Philippe Gerum <r...@xenomai.org>.
- *
- * Xenomai is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-#include <linux/types.h>
-#include <linux/ipipe.h>
-#include <linux/vmalloc.h>
-#include <cobalt/kernel/thread.h>
-#include <cobalt/uapi/syscall.h>
-#include <asm/cacheflush.h>
-#include <asm/ptrace.h>
-
-static void *mayday;
-
-static inline void setup_mayday(void *page)
-{
-       /*
-        * We want this code to appear at the top of the MAYDAY page:
-        *
-        * ifdef ARM_EABI
-        *
-        * e59f000c     ldr     r0, [pc, #12]
-        * e59f700c     ldr     r7, [pc, #12]
-        * ef000000     svc     0x00000000
-        * e3a00000     mov     r0, #0
-        * e5800000     str     r0, [r0]        ; <bug>
-        * 1000005e     .word   0x1000005e      ; sc_cobalt_mayday | 
__COBALT_SYSCALL_BIT
-        * 000f0042     .word   0x000f0042
-        *
-        * elif ARM_OABI
-        *
-        * e59f0008     ldr     r0, [pc, #8]
-        * ef9f0042     swi     0x009f0042
-        * e3a00000     mov     r0, #0
-        * e5800000     str     r0, [r0]        ; <bug>
-        * 1000005e     .word   0x1000005e      ; sc_cobalt_mayday | 
__COBALT_SYSCALL_BIT
-        *
-        * endif
-        *
-        * 32bit instruction words will be laid out by the compiler as
-        * the target endianness requires.
-        *
-        * We don't mess with CPSR here, so no need to save/restore it
-        * in handle/fixup code.
-        */
-#ifdef __ARM_EABI__
-       static const struct {
-               u32 ldr_r0;
-               u32 ldr_r7;
-               u32 swi_0;
-               u32 mov_r0;
-               u32 str_r0;
-               u32 cst_r0;
-               u32 cst_r7;
-       } code = {
-               .ldr_r0 = 0xe59f000c,
-               .ldr_r7 = 0xe59f700c,
-               .swi_0 = 0xef000000,
-               .mov_r0 = 0xe3a00000,
-               .str_r0 = 0xe5800000,
-               .cst_r0 =  __xn_syscode(sc_cobalt_mayday),
-               .cst_r7 = 0x000f0042,
-       };
-#else /* OABI */
-       static const struct {
-               u32 ldr_r0;
-               u32 swi_syscall;
-               u32 mov_r0;
-               u32 str_r0;
-               u32 cst_r0;
-       } code = {
-               .ldr_r0 = 0xe59f0008,
-               .swi_syscall = 0xef9f0042,
-               .mov_r0 = 0xe3a00000,
-               .str_r0 = 0xe5800000,
-               .cst_r0 =  __xn_syscode(sc_cobalt_mayday),
-       };
-#endif /* OABI */
-
-       memcpy(page, &code, sizeof(code));
-
-       flush_dcache_page(vmalloc_to_page(page));
-}
-
-int xnarch_init_mayday(void)
-{
-       mayday = vmalloc(PAGE_SIZE);
-       if (mayday == NULL)
-               return -ENOMEM;
-
-       setup_mayday(mayday);
-
-       return 0;
-}
-
-void xnarch_cleanup_mayday(void)
-{
-       vfree(mayday);
-}
-
-void *xnarch_get_mayday_page(void)
-{
-       return mayday;
-}
-
-void xnarch_handle_mayday(struct xnarchtcb *tcb, struct pt_regs *regs,
-                         unsigned long tramp)
-{
-       tcb->mayday.pc = regs->ARM_pc;
-       tcb->mayday.r0 = regs->ARM_r0;
-#ifdef __ARM_EABI__
-       tcb->mayday.r7 = regs->ARM_r7;
-#endif
-#ifdef CONFIG_ARM_THUMB
-       /* The code on the mayday page must be run in ARM mode */
-       tcb->mayday.psr = regs->ARM_cpsr;
-       regs->ARM_cpsr &= ~PSR_T_BIT;
-#endif
-       regs->ARM_pc = tramp;
-}
-
-void xnarch_fixup_mayday(struct xnarchtcb *tcb, struct pt_regs *regs)
-{
-       regs->ARM_pc = tcb->mayday.pc;
-       regs->ARM_r0 = tcb->mayday.r0;
-#ifdef __ARM_EABI__
-       regs->ARM_r7 = tcb->mayday.r7;
-#endif
-#ifdef CONFIG_ARM_THUMB
-       regs->ARM_cpsr = tcb->mayday.psr;
-#endif
-}
diff --git a/kernel/cobalt/arch/blackfin/Makefile 
b/kernel/cobalt/arch/blackfin/Makefile
index 8ef7e23..a4ac322 100644
--- a/kernel/cobalt/arch/blackfin/Makefile
+++ b/kernel/cobalt/arch/blackfin/Makefile
@@ -1,5 +1,5 @@
 obj-$(CONFIG_XENOMAI) += xenomai.o
 
-xenomai-y := machine.o mayday.o thread.o switch.o syscall.o
+xenomai-y := machine.o thread.o switch.o syscall.o
 
 ccflags-y := -Iarch/blackfin/xenomai/include -Iinclude/xenomai
diff --git a/kernel/cobalt/arch/blackfin/include/asm/xenomai/thread.h 
b/kernel/cobalt/arch/blackfin/include/asm/xenomai/thread.h
index e270fa8..626ae92 100644
--- a/kernel/cobalt/arch/blackfin/include/asm/xenomai/thread.h
+++ b/kernel/cobalt/arch/blackfin/include/asm/xenomai/thread.h
@@ -23,11 +23,6 @@
 
 struct xnarchtcb {
        struct xntcb core;
-       struct {
-               unsigned long pc;
-               unsigned long p0;
-               unsigned long r5;
-       } mayday;
 };
 
 #define xnarch_fpu_ptr(tcb)     NULL
diff --git a/kernel/cobalt/arch/blackfin/mayday.c 
b/kernel/cobalt/arch/blackfin/mayday.c
deleted file mode 100644
index bd76fee..0000000
--- a/kernel/cobalt/arch/blackfin/mayday.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (C) 2009,2012 Philippe Gerum <r...@xenomai.org>.
- *
- * Xenomai is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-#include <linux/types.h>
-#include <linux/ipipe.h>
-#include <linux/vmalloc.h>
-#include <cobalt/kernel/thread.h>
-#include <cobalt/uapi/syscall.h>
-#include <asm/cacheflush.h>
-#include <asm/ptrace.h>
-#include <asm/bug.h>
-
-static void *mayday;
-
-static inline void setup_mayday(void *page)
-{
-       /*
-        * We want this code to appear at the top of the MAYDAY page:
-        *
-        * 45 e1 0c 00    R5.H = 0x1000
-        * 05 e1 2b 02    R5.L = 0x005e
-        * 05 32          P0 = R5
-        * a0 00          EXCPT 0x0
-        * cd ef          <bug opcode>
-        *
-        * We don't mess with ASTAT here, so no need to save/restore
-        * it in handle/fixup code.
-        */
-       static const struct __attribute__ ((__packed__)) {
-               struct __attribute__ ((__packed__)) {
-                       u16 op;
-                       u16 imm;
-               } load_r5h;
-               struct __attribute__ ((__packed__)) {
-                       u16 op;
-                       u16 imm;
-               } load_r5l;
-               u16 mov_p0;
-               u16 syscall;
-               u16 bug;
-       } code = {
-               .load_r5h = {
-                       .op = 0xe145,
-                       .imm = __xn_syscode(sc_cobalt_mayday) >> 16
-               },
-               .load_r5l = {
-                       .op = 0xe105,
-                       .imm = __xn_syscode(sc_cobalt_mayday) & 0xffff
-               },
-               .mov_p0 = 0x3205,
-               .syscall = 0x00a0,
-               .bug = BFIN_BUG_OPCODE,
-       };
-
-       memcpy(page, &code, sizeof(code));
-
-       flush_dcache_range((unsigned long)page,
-                          (unsigned long)page + sizeof(code));
-}
-
-int xnarch_init_mayday(void)
-{
-       mayday = vmalloc(PAGE_SIZE);
-       if (mayday == NULL)
-               return -ENOMEM;
-
-       setup_mayday(mayday);
-
-       return 0;
-}
-
-void xnarch_cleanup_mayday(void)
-{
-       vfree(mayday);
-}
-
-void *xnarch_get_mayday_page(void)
-{
-       return mayday;
-}
-
-void xnarch_handle_mayday(struct xnarchtcb *tcb,
-                         struct pt_regs *regs,
-                         unsigned long tramp)
-{
-       tcb->mayday.pc = regs->pc;
-       tcb->mayday.p0 = regs->p0;
-       tcb->mayday.r5 = regs->r5;
-       regs->pc = tramp;       /* i.e. RETI */
-}
-
-void xnarch_fixup_mayday(struct xnarchtcb *tcb, struct pt_regs *regs)
-{
-       regs->pc = tcb->mayday.pc;
-       regs->p0 = tcb->mayday.p0;
-       regs->r5 = tcb->mayday.r5;
-}
diff --git a/kernel/cobalt/arch/nios2/Makefile 
b/kernel/cobalt/arch/nios2/Makefile
index ce960c8..c498e3d 100644
--- a/kernel/cobalt/arch/nios2/Makefile
+++ b/kernel/cobalt/arch/nios2/Makefile
@@ -1,6 +1,6 @@
 
 obj-$(CONFIG_XENOMAI) += xenomai.o
 
-xenomai-y := machine.o mayday.o thread.o switch.o syscall.o
+xenomai-y := machine.o thread.o switch.o syscall.o
 
 ccflags-y := -Iarch/nios2/xenomai/include -Iinclude/xenomai
diff --git a/kernel/cobalt/arch/nios2/include/asm/xenomai/thread.h 
b/kernel/cobalt/arch/nios2/include/asm/xenomai/thread.h
index df473c9..fe55e10 100644
--- a/kernel/cobalt/arch/nios2/include/asm/xenomai/thread.h
+++ b/kernel/cobalt/arch/nios2/include/asm/xenomai/thread.h
@@ -27,11 +27,6 @@
 
 struct xnarchtcb {
        struct xntcb core;
-       struct {
-               unsigned long ea;
-               unsigned long r2;
-               unsigned long r3;
-       } mayday;
 };
 
 #define xnarch_fpu_ptr(tcb)     NULL
diff --git a/kernel/cobalt/arch/nios2/mayday.c 
b/kernel/cobalt/arch/nios2/mayday.c
deleted file mode 100644
index 15775f3..0000000
--- a/kernel/cobalt/arch/nios2/mayday.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2009 Philippe Gerum <r...@xenomai.org>.
- *
- * Xenomai is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-#include <linux/types.h>
-#include <linux/ipipe.h>
-#include <linux/vmalloc.h>
-#include <cobalt/kernel/thread.h>
-#include <cobalt/uapi/syscall.h>
-#include <asm/cacheflush.h>
-#include <asm/ptrace.h>
-
-static void *mayday;
-
-static inline void setup_mayday(void *page)
-{
-       /*
-        * We want this code to appear at the top of the MAYDAY page:
-        *
-        *      00c00334        movhi   r3,#sc_cobalt_mayday
-        *      18c08ac4        addi    r3,r3,#cobalt_syscall_tag
-        *      00800004        movi    r2,0
-        *      003b683a        trap
-        *      003fff06        br      .
-        */
-       static const struct {
-               u32 movhi_r3h;
-               u32 addi_r3l;
-               u32 movi_r2;
-               u32 syscall;
-               u32 bug;
-       } code = {
-               .movhi_r3h = 0x00c00334,
-               .addi_r3l = 0x18c08ac4,
-               .movi_r2 = 0x00800004,
-               .syscall = 0x003b683a,
-               .bug = 0x003fff06
-       };
-
-       memcpy(page, &code, sizeof(code));
-
-       flush_dcache_range((unsigned long)page,
-                          (unsigned long)page + sizeof(code));
-}
-
-int xnarch_init_mayday(void)
-{
-       mayday = vmalloc(PAGE_SIZE);
-       if (mayday == NULL)
-               return -ENOMEM;
-
-       setup_mayday(mayday);
-
-       return 0;
-}
-
-void xnarch_cleanup_mayday(void)
-{
-       vfree(mayday);
-}
-
-void *xnarch_get_mayday_page(void)
-{
-       return mayday;
-}
-
-void xnarch_handle_mayday(struct xnarchtcb *tcb,
-                         struct pt_regs *regs, unsigned long tramp)
-{
-       tcb->mayday.ea = regs->ea;
-       tcb->mayday.r2 = regs->r2;
-       tcb->mayday.r3 = regs->r3;
-       regs->ea = tramp;
-}
-
-void xnarch_fixup_mayday(struct xnarchtcb *tcb, struct pt_regs *regs)
-{
-       regs->ea = tcb->mayday.ea;
-       regs->r2 = tcb->mayday.r2;
-       regs->r3 = tcb->mayday.r3;
-}
diff --git a/kernel/cobalt/arch/powerpc/Makefile 
b/kernel/cobalt/arch/powerpc/Makefile
index 4e728d5..18147ee 100644
--- a/kernel/cobalt/arch/powerpc/Makefile
+++ b/kernel/cobalt/arch/powerpc/Makefile
@@ -1,7 +1,7 @@
 
 obj-$(CONFIG_XENOMAI) += xenomai.o
 
-xenomai-y := machine.o mayday.o thread.o
+xenomai-y := machine.o thread.o
 
 xenomai-$(CONFIG_XENO_ARCH_FPU) += fpu.o
 
diff --git a/kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h 
b/kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h
index 8858bdd..4f4fe62 100644
--- a/kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h
+++ b/kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h
@@ -29,10 +29,6 @@ struct xnarchtcb {
 #else
 #define xnarch_fpu_ptr(tcb)     NULL
 #endif
-       struct {
-               unsigned long nip;
-               unsigned long r0;
-       } mayday;
 };
 
 #define xnarch_fault_regs(d)   ((d)->regs)
diff --git a/kernel/cobalt/arch/powerpc/mayday.c 
b/kernel/cobalt/arch/powerpc/mayday.c
deleted file mode 100644
index 254f9ab..0000000
--- a/kernel/cobalt/arch/powerpc/mayday.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2010 Philippe Gerum <r...@xenomai.org>.
- *
- * Xenomai is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include <linux/types.h>
-#include <linux/ipipe.h>
-#include <linux/vmalloc.h>
-#include <cobalt/kernel/thread.h>
-#include <cobalt/uapi/syscall.h>
-#include <asm/cacheflush.h>
-#include <asm/ptrace.h>
-
-static void *mayday;
-
-static inline void setup_mayday(void *page)
-{
-       /*
-        * We want this code to appear at the top of the MAYDAY page:
-        *
-        * 3c 00 0b 00  lis     r0,mux_code@h
-        * 60 00 02 2b  ori     r0,r0,mux_code@l
-        * 44 00 00 02  sc
-        * 00 b0 0b 00  .long   0x00b00b00 <illegal insn>
-        *
-        * We don't mess with CCR here, so no need to save/restore it
-        * in handle/fixup code.
-        */
-       u32 mux, insn[4];
-
-       mux = __xn_syscode(sc_cobalt_mayday);
-       insn[0] = 0x3c000000 | (mux >> 16);
-       insn[1] = 0x60000000 | (mux & 0xffff);
-       insn[2] = 0x44000002;
-       insn[3] = 0x00b00b00;
-       memcpy(page, insn, sizeof(insn));
-
-       flush_dcache_range((unsigned long)page,
-                          (unsigned long)page + sizeof(insn));
-}
-
-int xnarch_init_mayday(void)
-{
-       mayday = vmalloc(PAGE_SIZE);
-       if (mayday == NULL)
-               return -ENOMEM;
-
-       setup_mayday(mayday);
-
-       return 0;
-}
-
-void xnarch_cleanup_mayday(void)
-{
-       vfree(mayday);
-}
-
-void *xnarch_get_mayday_page(void)
-{
-       return mayday;
-}
-
-void xnarch_handle_mayday(struct xnarchtcb *tcb,
-                         struct pt_regs *regs,
-                         unsigned long tramp)
-{
-       tcb->mayday.nip = regs->nip;
-       tcb->mayday.r0 = regs->gpr[0];
-       regs->nip = tramp;
-}
-
-void xnarch_fixup_mayday(struct xnarchtcb *tcb,
-                        struct pt_regs *regs)
-{
-       regs->nip = tcb->mayday.nip;
-       regs->gpr[0] = tcb->mayday.r0;
-}
diff --git a/kernel/cobalt/arch/sh/Makefile b/kernel/cobalt/arch/sh/Makefile
index 82477a1..8aadb4b 100644
--- a/kernel/cobalt/arch/sh/Makefile
+++ b/kernel/cobalt/arch/sh/Makefile
@@ -1,6 +1,6 @@
 
 obj-$(CONFIG_XENOMAI) += xenomai.o
 
-xenomai-y := machine.o mayday.o thread.o trampoline.o
+xenomai-y := machine.o thread.o trampoline.o
 
 ccflags-y := -Iarch/sh/xenomai/include -Iinclude/xenomai
diff --git a/kernel/cobalt/arch/sh/include/asm/xenomai/thread.h 
b/kernel/cobalt/arch/sh/include/asm/xenomai/thread.h
index 654bfa7..b29b007 100644
--- a/kernel/cobalt/arch/sh/include/asm/xenomai/thread.h
+++ b/kernel/cobalt/arch/sh/include/asm/xenomai/thread.h
@@ -29,10 +29,6 @@ struct xnarchtcb {
 #else
 #define xnarch_fpu_ptr(tcb)     NULL
 #endif
-       struct {
-               unsigned long pc;
-               unsigned long r3;
-       } mayday;
 };
 
 #define xnarch_fault_trap(d)   ((d)->exception)
diff --git a/kernel/cobalt/arch/sh/mayday.c b/kernel/cobalt/arch/sh/mayday.c
deleted file mode 100644
index a138223..0000000
--- a/kernel/cobalt/arch/sh/mayday.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2011 Philippe Gerum <r...@xenomai.org>.
- *
- * Xenomai is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include <linux/types.h>
-#include <linux/ipipe.h>
-#include <linux/vmalloc.h>
-#include <linux/mm.h>
-#include <cobalt/kernel/thread.h>
-#include <cobalt/uapi/syscall.h>
-#include <asm/cacheflush.h>
-#include <asm/ptrace.h>
-
-static void *mayday;
-
-static inline void setup_mayday(void *page)
-{
-       u16 insn[11];
-
-       /*
-        * We want this code to appear at the top of the MAYDAY page:
-        *
-        * 0:   03 d3   mov.l   12 <pc+0x12>,r3 ! b022b
-        * 2:   09 00   nop
-        * 4:   10 c3   trapa   #16
-        * 6:   0b 20   or      r0,r0
-        * 8:   0b 20   or      r0,r0
-        * a:   0b 20   or      r0,r0
-        * c:   0b 20   or      r0,r0
-        * e:   0b 20   or      r0,r0
-        * 10:  3e c3   trapa   #62
-        * 12:  2b 02   .word 0x022b
-        * 14:  0b 00   .word 0x000b
-        */
-       insn[0] = 0xd303;
-       insn[1] = 0x0009;
-       insn[2] = 0xc310;
-       insn[3] = 0x200b;
-       insn[4] = 0x200b;
-       insn[5] = 0x200b;
-       insn[6] = 0x200b;
-       insn[7] = 0x200b;
-       insn[8] = 0xc33e;
-       insn[9] = 0x022b;
-       insn[10] = 0x000b;
-       memcpy(page, insn, sizeof(insn));
-
-       flush_dcache_page(vmalloc_to_page(page));
-}
-
-int xnarch_init_mayday(void)
-{
-       mayday = vmalloc(PAGE_SIZE);
-       if (mayday == NULL)
-               return -ENOMEM;
-
-       setup_mayday(mayday);
-
-       return 0;
-}
-
-void xnarch_cleanup_mayday(void)
-{
-       vfree(mayday);
-}
-
-void *xnarch_get_mayday_page(void)
-{
-       return mayday;
-}
-
-void xnarch_handle_mayday(struct xnarchtcb *tcb,
-                         struct pt_regs *regs, unsigned long tramp)
-{
-       tcb->mayday.pc = regs->pc;
-       tcb->mayday.r3 = regs->regs[3];
-       regs->pc = tramp;
-}
-
-void xnarch_fixup_mayday(struct xnarchtcb *tcb, struct pt_regs *regs)
-{
-       regs->pc = tcb->mayday.pc;
-       regs->regs[3] = tcb->mayday.r3;
-}
diff --git a/kernel/cobalt/arch/x86/Makefile b/kernel/cobalt/arch/x86/Makefile
index e65d25a..d430a67 100644
--- a/kernel/cobalt/arch/x86/Makefile
+++ b/kernel/cobalt/arch/x86/Makefile
@@ -1,5 +1,5 @@
 
 obj-$(CONFIG_XENOMAI) += xenomai.o
-xenomai-y := machine.o mayday.o thread.o smi.o c1e.o
+xenomai-y := machine.o thread.o smi.o c1e.o
 
 ccflags-y := -Iarch/x86/xenomai/include -Iinclude/xenomai
diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h 
b/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h
index f58caf7..32bac1c 100644
--- a/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h
+++ b/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h
@@ -36,10 +36,6 @@ struct xnarchtcb {
        x86_fpustate *fpup;
        unsigned int root_kfpu: 1;
        unsigned int root_used_math: 1;
-       struct {
-               unsigned long ip;
-               unsigned long ax;
-       } mayday;
 };
 
 static inline int xnarch_shadow_p(struct xnarchtcb *tcb, struct task_struct 
*task)
diff --git a/kernel/cobalt/arch/x86/mayday.c b/kernel/cobalt/arch/x86/mayday.c
deleted file mode 100644
index 15f07bd..0000000
--- a/kernel/cobalt/arch/x86/mayday.c
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright (C) 2010 Philippe Gerum <r...@xenomai.org>.
- *
- * Xenomai is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include <linux/types.h>
-#include <linux/ipipe.h>
-#include <linux/vmalloc.h>
-#include <cobalt/kernel/thread.h>
-#include <cobalt/uapi/syscall.h>
-#include <asm/ptrace.h>
-
-static void *mayday;
-#ifdef CONFIG_XENO_ARCH_SYS3264
-static void *mayday_compat;
-#endif
-
-static inline void setup_mayday32(void *page)
-{
-       /*
-        * We want this code to appear at the top of the MAYDAY page:
-        *
-        *      b8 2b 02 00 0c          mov    $<mux_code>,%eax
-        *      cd 80                   int    $0x80
-        *      0f 0b                   ud2a
-        *
-        * We intentionally don't mess with EFLAGS here, so that we
-        * don't have to save/restore it in handle/fixup code.
-        */
-       static const struct __attribute__ ((__packed__)) {
-               struct __attribute__ ((__packed__)) {
-                       u8 op;
-                       u32 imm;
-               } mov_eax;
-               u16 syscall;
-               u16 bug;
-       } code = {
-               .mov_eax = {
-                       .op = 0xb8,
-                       .imm = __xn_syscode(sc_cobalt_mayday)
-               },
-               .syscall = 0x80cd,
-               .bug = 0x0b0f,
-       };
-
-       memcpy(page, &code, sizeof(code));
-
-       /* no cache flush required. */
-}
-
-static inline void setup_mayday64(void *page)
-{
-       /*
-        * We want this code to appear at the top of the MAYDAY page:
-        *
-        *      50                      push   %rax
-        *      41 53                   push   %r11
-        *      51                      push   %rcx
-        *      b8 2b 02 00 0c          mov    $<mux_code>,%eax
-        *      0f 05                   syscall
-        *      59                      pop     %rcx
-        *      41 5b                   pop     %r11
-        *      48 87 04 24             xchg    %rax,(%rsp)
-        *      c3                      retq
-        *
-        * The flow for a MAYDAY diversion on x86_64 is as follows:
-        *
-        * [runaway code]
-        *      <watchdog/timer IRQ entry>
-        *             [%orig_rip = %rip, %rip = &mayday_page] ; handle_mayday
-        *      <watchdog/timer IRQ exit>
-        *
-        * [mayday_page trampoline]
-        *      <MAYDAY syscall>             ; relax + fixup_mayday
-        *             [%rax = %orig_rip]
-         *      ret-to-runaway-code
-        *
-        * [runaway code]
-        *      ...
-        *
-        * We must take care of preserving %rcx and %r11 which are
-        * clobbered by the kernel when handling a syscall in long
-        * mode. This is required because the runaway thread code did
-        * not actually plan for running the MAYDAY syscall - we
-        * forced it to do so, by diverting the return path of the
-        * watchdog/timer IRQ which preempted it.
-        *
-        * On x86_64, we want the MAYDAY syscall to return to us, so
-        * that we can restore the clobbered registers, prior to
-        * branching back to the user code. fixup_mayday ensures that
-        * the original %rip is returned from the MAYDAY syscall in
-        * %rax, therefore we have to save the latter across the
-        * syscall as well.
-        *
-        * In addition, we intentionally don't mess with EFLAGS here,
-        * so that we don't have to save/restore it in handle/fixup
-        * code.
-        */
-       static const struct __attribute__ ((__packed__)) {
-               u8 push_rax;
-               u16 push_r11;
-               u8 push_rcx;
-               struct __attribute__ ((__packed__)) {
-                       u8 op;
-                       u32 imm;
-               } mov_eax;
-               u16 syscall;
-               u8 pop_rcx;
-               u16 pop_r11;
-               struct __attribute__ ((__packed__)) {
-                       u16 op;
-                       u16 spec;
-               } xchg_rax_tos;
-               u8 retq;
-       } code = {
-               .push_rax = 0x50,
-               .push_r11 = 0x5341,
-               .push_rcx = 0x51,
-               .mov_eax = {
-                       .op = 0xb8,
-                       .imm = __xn_syscode(sc_cobalt_mayday)
-               },
-               .syscall = 0x050f,
-               .pop_rcx = 0x59,
-               .pop_r11 = 0x5b41,
-               .xchg_rax_tos = {
-                       .op = 0x8748,
-                       .spec = 0x2404
-               },
-               .retq = 0xc3,
-       };
-
-       memcpy(page, &code, sizeof(code));
-
-       /* no cache flush required. */
-}
-
-int xnarch_init_mayday(void)
-{
-       mayday = vmalloc(PAGE_SIZE);
-       if (mayday == NULL)
-               return -ENOMEM;
-
-#ifdef CONFIG_X86_32
-       setup_mayday32(mayday);
-#else
-       setup_mayday64(mayday);
-#ifdef CONFIG_XENO_ARCH_SYS3264
-       mayday_compat = vmalloc(PAGE_SIZE);
-       if (mayday_compat == NULL) {
-               vfree(mayday);
-               return -ENOMEM;
-       }
-       setup_mayday32(mayday_compat);
-#endif
-#endif
-       return 0;
-}
-
-void xnarch_cleanup_mayday(void)
-{
-       vfree(mayday);
-#ifdef CONFIG_XENO_ARCH_SYS3264
-       vfree(mayday_compat);
-#endif
-}
-
-void *xnarch_get_mayday_page(void)
-{
-#if defined(CONFIG_X86_32) || !defined(CONFIG_XENO_ARCH_SYS3264)
-       return mayday;
-#else
-       return test_thread_flag(TIF_IA32) ? mayday_compat : mayday;
-#endif
-}
-
-void xnarch_handle_mayday(struct xnarchtcb *tcb, struct pt_regs *regs,
-                         unsigned long tramp)
-{
-       tcb->mayday.ip = regs->ip;
-       tcb->mayday.ax = regs->ax;
-       regs->ip = tramp;
-}
-
-void xnarch_fixup_mayday(struct xnarchtcb *tcb, struct pt_regs *regs)
-{
-#ifdef CONFIG_X86_64
-       if (IS_ENABLED(CONFIG_XENO_ARCH_SYS3264) &&
-               test_thread_flag(TIF_IA32)) {
-               regs->ip = tcb->mayday.ip;
-               regs->ax = tcb->mayday.ax;
-       } else
-               regs->ax = tcb->mayday.ip;
-#else
-       regs->ip = tcb->mayday.ip;
-       regs->ax = tcb->mayday.ax;
-#endif
-}
diff --git a/kernel/cobalt/include/asm-generic/xenomai/mayday.h 
b/kernel/cobalt/include/asm-generic/xenomai/mayday.h
deleted file mode 100644
index 67f6983..0000000
--- a/kernel/cobalt/include/asm-generic/xenomai/mayday.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2009, 2012 Philippe Gerum <r...@xenomai.org>.
- *
- * Xenomai is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-#ifndef _COBALT_ASM_GENERIC_MAYDAY_H
-#define _COBALT_ASM_GENERIC_MAYDAY_H
-
-struct xnarchtcb;
-struct task_struct;
-struct pt_regs;
-
-int xnarch_init_mayday(void);
-
-void xnarch_cleanup_mayday(void);
-
-void *xnarch_get_mayday_page(void);
-
-void xnarch_handle_mayday(struct xnarchtcb *tcb,
-                         struct pt_regs *regs,
-                         unsigned long tramp);
-
-void xnarch_fixup_mayday(struct xnarchtcb *tcb,
-                        struct pt_regs *regs);
-
-#endif /* !_COBALT_ASM_GENERIC_MAYDAY_H */
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index 828e9e5..8fbfb1b 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -54,7 +54,6 @@
 #include <rtdm/driver.h>
 #include <asm/xenomai/features.h>
 #include <asm/xenomai/syscall.h>
-#include <asm-generic/xenomai/mayday.h>
 #include "../debug.h"
 #include "internal.h"
 #include "thread.h"
@@ -762,16 +761,9 @@ static inline int handle_exception(struct ipipe_trap_data 
*d)
 
 static int handle_mayday_event(struct pt_regs *regs)
 {
-       struct xnthread *thread = xnthread_current();
-       struct xnarchtcb *tcb = xnthread_archtcb(thread);
-       struct cobalt_ppd *sys_ppd;
-
-       XENO_BUG_ON(COBALT, !xnthread_test_state(thread, XNUSER));
+       XENO_BUG_ON(COBALT, !xnthread_test_state(xnthread_current(), XNUSER));
 
-       /* We enter the mayday handler with hw IRQs off. */
-       sys_ppd = cobalt_ppd_get(0);
-
-       xnarch_handle_mayday(tcb, regs, sys_ppd->mayday_tramp);
+       xnthread_relax(0, 0);
 
        return KEVENT_PROPAGATE;
 }
@@ -1257,21 +1249,6 @@ int ipipe_kevent_hook(int kevent, void *data)
        return ret;
 }
 
-static inline unsigned long map_mayday_page(void)
-{
-       void __user *u_addr = NULL;
-       void *mayday_page;
-       int ret;
-
-       mayday_page = xnarch_get_mayday_page();
-       ret = rtdm_mmap_to_user(NULL, mayday_page, PAGE_SIZE,
-                               PROT_READ|PROT_EXEC, &u_addr, NULL, NULL);
-       if (ret)
-               return 0UL;
-
-       return (unsigned long)u_addr;
-}
-
 static int attach_process(struct cobalt_process *process)
 {
        struct cobalt_ppd *p = &process->sys_ppd;
@@ -1285,15 +1262,6 @@ static int attach_process(struct cobalt_process *process)
 
        cobalt_umm_set_name(&p->umm, "private heap[%d]", current->pid);
 
-       p->mayday_tramp = map_mayday_page();
-       if (p->mayday_tramp == 0) {
-               printk(XENO_WARNING
-                      "%s[%d] cannot map MAYDAY page\n",
-                      current->comm, current->pid);
-               ret = -ENOMEM;
-               goto fail_mayday;
-       }
-
        exe_path = get_exe_path(current);
        if (IS_ERR(exe_path)) {
                printk(XENO_WARNING
@@ -1313,7 +1281,6 @@ static int attach_process(struct cobalt_process *process)
 fail_hash:
        if (p->exe_path)
                kfree(p->exe_path);
-fail_mayday:
        cobalt_umm_destroy(&p->umm);
 
        return ret;
@@ -1460,14 +1427,6 @@ __init int cobalt_init(void)
        if (ret)
                goto fail_debug;
 
-       /*
-        * Setup the mayday stuff early, before userland can mess with
-        * real-time ops.
-        */
-       ret = xnarch_init_mayday();
-       if (ret)
-               goto fail_mayday;
-
        for (i = 0; i < PROCESS_HASH_SIZE; i++)
                INIT_HLIST_HEAD(&process_hash[i]);
 
@@ -1496,8 +1455,6 @@ fail_register:
        cobalt_memdev_cleanup();
 fail_memdev:
        xnsynch_destroy(&yield_sync);
-       xnarch_cleanup_mayday();
-fail_mayday:
        xndebug_cleanup();
 fail_debug:
        kfree(process_hash);
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index c636c0f..2d6f6af 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -25,7 +25,6 @@
 #include <cobalt/kernel/vdso.h>
 #include <cobalt/kernel/init.h>
 #include <xenomai/version.h>
-#include <asm-generic/xenomai/mayday.h>
 #include "internal.h"
 #include "thread.h"
 #include "sched.h"
@@ -249,34 +248,6 @@ static COBALT_SYSCALL(serialdbg, current,
        return 0;
 }
 
-static COBALT_SYSCALL(mayday, current, (void))
-{
-       struct pt_regs *regs = task_pt_regs(current);
-       struct xnthread *cur;
-
-       cur = xnthread_current();
-       if (cur == NULL) {
-               printk(XENO_WARNING
-                      "MAYDAY received from invalid context %s[%d]\n",
-                      current->comm, current->pid);
-               return -EPERM;
-       }
-
-       /*
-        * If the thread was kicked by the watchdog, this syscall we
-        * have just forced on it via the mayday escape will cause it
-        * to relax. See handle_head_syscall().
-        */
-       xnarch_fixup_mayday(xnthread_archtcb(cur), regs);
-
-       /*
-        * Return whatever value xnarch_fixup_mayday set for this
-        * register, in order not to undo what xnarch_fixup_mayday
-        * did.
-        */
-       return __xn_reg_rval(regs);
-}
-
 static void stringify_feature_set(unsigned long fset, char *buf, int size)
 {
        unsigned long feature;
@@ -692,7 +663,6 @@ static const cobalt_syshand cobalt_syscalls[] = {
        __COBALT_CALL_ENTRY(extend),
        __COBALT_CALL_ENTRY(trace),
        __COBALT_CALL_ENTRY(get_current),
-       __COBALT_CALL_ENTRY(mayday),
        __COBALT_CALL_ENTRY(backtrace),
        __COBALT_CALL_ENTRY(serialdbg),
        __COBALT_CALL_ENTRY(corectl),
@@ -795,7 +765,6 @@ static const int cobalt_sysmodes[] = {
        __COBALT_MODE(extend, lostage),
        __COBALT_MODE(trace, current),
        __COBALT_MODE(get_current, current),
-       __COBALT_MODE(mayday, current),
        __COBALT_MODE(backtrace, current),
        __COBALT_MODE(serialdbg, current),
        __COBALT_MODE(corectl, probing),
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 22729a8..59fe57d 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -37,7 +37,6 @@
 #include <cobalt/kernel/lock.h>
 #include <cobalt/kernel/thread.h>
 #include <trace/events/cobalt-core.h>
-#include <asm-generic/xenomai/mayday.h>
 #include "debug.h"
 
 /**


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to