Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signal to be delivered on the correct thread. #9

Merged
merged 24 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e81db9d
Change the signal delivery (formally in do_signal) from delivering all
KenGordon Aug 27, 2020
113e697
tabs vs spaces
KenGordon Aug 28, 2020
f64013f
Merge branch 'upstream-refactor' into ken/sgxlkl709
KenGordon Aug 28, 2020
0eaf1f8
Per (some of) david's suggestions, remove volatile, improve comments,…
KenGordon Aug 28, 2020
6878f09
Merge branch 'ken/sgxlkl709' of ssh://github.com/lsds/lkl into ken/sg…
KenGordon Aug 28, 2020
89b22af
Formatting and left over conflict tag.
KenGordon Aug 28, 2020
36a56e0
Update arch/lkl/kernel/signal.c
KenGordon Aug 28, 2020
19a9133
Keep a tail pointer to make consuming signal nodes fast.
KenGordon Aug 28, 2020
b8db5b8
Basically a backup commit. Add much debugging code.
KenGordon Sep 2, 2020
9ce0c62
Support traps getting only the trap signal and not throw away any others
KenGordon Sep 7, 2020
4546860
Do not take teh cpu lock an extra time in move_signals_to_task as
KenGordon Sep 9, 2020
c919fcd
Remove bogus debug code.
KenGordon Sep 9, 2020
be2938b
Remove bogus print
KenGordon Sep 9, 2020
69505a4
Hold the signal list lock while deleting elements as suggested by Sean
KenGordon Sep 9, 2020
952818a
Fix commenting style, move allocation and init of signal list node in…
KenGordon Sep 9, 2020
651b1f3
Undo accidental checkin of patched config.
KenGordon Sep 10, 2020
6c15e96
Revert accidental commit of patched build files
KenGordon Sep 10, 2020
3159974
SGX-LKL Issue 709, signals improvements. Changes as per PR comments
KenGordon Sep 10, 2020
aa9bb4e
Take out bug check in lkl_cpu_put which would slow the fast path.
KenGordon Sep 10, 2020
515cb84
Update comment.
KenGordon Sep 10, 2020
033b7c0
Update arch/lkl/include/asm/thread_info.h
KenGordon Sep 14, 2020
3ca325a
Update arch/lkl/kernel/signal.c
KenGordon Sep 14, 2020
8757429
defconfig reverted again due to patching scheme.
KenGordon Sep 14, 2020
d4d06c1
Update commenst in cpu.c. Fix bug in linked list handling in signal.c.
KenGordon Sep 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 72 additions & 11 deletions arch/lkl/configs/defconfig
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# CONFIG_LOCALVERSION_AUTO is not set
KenGordon marked this conversation as resolved.
Show resolved Hide resolved
CONFIG_NO_HZ_IDLE=y
# CONFIG_SYSFS_SYSCALL is not set
CONFIG_KALLSYMS_USE_DATA_SECTION=y
CONFIG_KALLSYMS_ALL=y
CONFIG_KALLSYMS_USE_DATA_SECTION=n
CONFIG_KALLSYMS_ALL=n
CONFIG_KALLSYMS=n
# CONFIG_BASE_FULL is not set
# CONFIG_FUTEX is not set
CONFIG_FUTEX=y
CONFIG_HAVE_FUTEX_CMPXCHG=y
# CONFIG_SIGNALFD is not set
# CONFIG_TIMERFD is not set
# CONFIG_AIO is not set
# CONFIG_ADVISE_SYSCALLS is not set
CONFIG_EMBEDDED=y
# CONFIG_VM_EVENT_COUNTERS is not set
# CONFIG_COMPAT_BRK is not set
Expand All @@ -18,6 +19,8 @@ CONFIG_INET=y
# CONFIG_WIRELESS is not set
# CONFIG_UEVENT_HELPER is not set
# CONFIG_FW_LOADER is not set
CONFIG_VIRTIO_CONSOLE=y
CONFIG_BLK_DEV_LOOP=y
CONFIG_VIRTIO_BLK=y
CONFIG_NETDEVICES=y
CONFIG_VIRTIO_NET=y
Expand All @@ -29,14 +32,15 @@ CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
CONFIG_EXT4_FS=y
CONFIG_EXT4_FS_POSIX_ACL=y
CONFIG_EXT4_FS_SECURITY=y
CONFIG_XFS_FS=y
CONFIG_XFS_POSIX_ACL=y
CONFIG_BTRFS_FS=y
CONFIG_BTRFS_FS_POSIX_ACL=y
# CONFIG_FILE_LOCKING is not set
CONFIG_OVERLAY_FS=y
CONFIG_XFS_FS=n
CONFIG_XFS_POSIX_ACL=n
CONFIG_BTRFS_FS=n
CONFIG_BTRFS_FS_POSIX_ACL=n
CONFIG_FILE_LOCKING=y
# CONFIG_DNOTIFY is not set
# CONFIG_INOTIFY_USER is not set
CONFIG_VFAT_FS=y
CONFIG_VFAT_FS=n
CONFIG_NLS_CODEPAGE_437=y
CONFIG_NLS_CODEPAGE_737=y
CONFIG_NLS_CODEPAGE_775=y
Expand Down Expand Up @@ -90,6 +94,63 @@ CONFIG_HZ_100=y
CONFIG_CRYPTO_ANSI_CPRNG=y
CONFIG_PRINTK_TIME=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_INFO_REDUCED=y
CONFIG_DEBUG_INFO_REDUCED=n
# CONFIG_ENABLE_WARN_DEPRECATED is not set
# CONFIG_ENABLE_MUST_CHECK is not set
CONFIG_UNIX=y
CONFIG_PROC_FS=y
# Disable separate bootmem allocator
CONFIG_NO_BOOTMEM=y
CONFIG_HOST_NETWORK=y
CONFIG_DEVTMPFS=y
CONFIG_INPUT_MOUSEDEV=n
CONFIG_MD=y
CONFIG_BLK_DEV_DM=y
CONFIG_DM_CRYPT=y
CONFIG_DM_VERITY=y
CONFIG_DM_INTEGRITY=y
CONFIG_CRYPTO=y
CONFIG_CRYPTO_USER=y
CONFIG_CRYPTO_AUTHENC=y
CONFIG_CRYPTO_ECB=y
CONFIG_CRYPTO_XTS=y
CONFIG_CRYPTO_RNG=y
CONFIG_CRYPTO_AES=y
CONFIG_CRYPTO_USER_API=y
CONFIG_CRYPTO_USER_API_HASH=y
CONFIG_CRYPTO_USER_API_SKCIPHER=y
CONFIG_CRYPTO_USER_API_RNG=y
CONFIG_CRYPTO_USER_API_AEAD=y
CONFIG_CRYPTO_CRC32=y
CONFIG_CRYPTO_SHA1=y
CONFIG_CRYPTO_SHA256=y
CONFIG_CRYPTO_SHA512=y
CONFIG_CRYPTO_SHA3=y
CONFIG_CRYPTO_HMAC=y
CONFIG_RC_CORE=n
CONFIG_WIREGUARD=y
CONFIG_WIREGUARD_DEBUG=n
CONFIG_NET_UDP_TUNNEL=y
CONFIG_CRYPTO_BLKCIPHER=y
CONFIG_NETFILTER=y
CONFIG_IP_NF_IPTABLES=y
CONFIG_IP_NF_FILTER=y
CONFIG_NF_TABLES=y
CONFIG_NF_CONNTRACK=y
CONFIG_NF_NAT=y
CONFIG_NF_NAT_NEEDED=y
CONFIG_NF_NAT_PROTO_DCCP=y
CONFIG_NF_NAT_PROTO_UDPLITE=y
CONFIG_NF_NAT_PROTO_SCTP=y
CONFIG_NF_NAT_REDIRECT=y
CONFIG_NF_TABLES=y
CONFIG_NF_DEFRAG_IPV4=y
CONFIG_NF_CONNTRACK_IPV4=y
CONFIG_NFT_NFT_NAT=y
CONFIG_NETFILTER_XTABLES=y
CONFIG_NF_NAT_IPV4=y
CONFIG_NF_NAT_MASQUERADE_IPV4=y
CONFIG_IP_NF_NAT=y
CONFIG_IP_NF_TARGET_MASQUERADE=y
CONFIG_NETFILTER_XT_NAT=y
CONFIG_ADVISE_SYSCALLS=y
15 changes: 15 additions & 0 deletions arch/lkl/include/asm/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@

int lkl_cpu_get(void);
void lkl_cpu_put(void);

#ifdef DEBUG
/* Bug if you do not have the cpu lock. */
void lkl_assert_cpu_owner(void);
/* Bug if you do have the cpu lock. */
void lkl_assert_cpu_not_owner(void);
/* Prints values of the various locking structure to aid debugging. */
void lkl_print_cpu_lock_state(const char *func_name);
#else
static inline void lkl_assert_cpu_owner(void) {}
static inline void lkl_assert_cpu_not_owner(void) {}
static inline void lkl_print_cpu_lock_state(const char *func_name) {}
#endif


int lkl_cpu_try_run_irq(int irq);
int lkl_cpu_init(void);
void lkl_cpu_shutdown(void);
Expand Down
26 changes: 24 additions & 2 deletions arch/lkl/include/asm/signal.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
#ifndef _ASM_LKL_SIGNAL_H
#define _ASM_LKL_SIGNAL_H
#include <asm-generic/signal.h>

struct ucontext;
void do_signal(struct pt_regs *regs);

struct thread_info;
struct ksignal_list_node;
struct ksignal;

void lkl_process_trap(int signr, struct ucontext *uctx);

/*
* Capture pending signals and move them to a task-specific list.
* Must be called only with the cpu lock held.
*/

#include <asm-generic/signal.h>
void move_signals_to_task(void);

/*
* Send any signals targeting this task.
* Must be called only with the cpu lock held, it will be unlocked for the call to user code.
*/

void send_current_signals(struct ucontext *uctx);

#endif
20 changes: 20 additions & 0 deletions arch/lkl/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
#include <asm/processor.h>
#include <asm/host_ops.h>

#include <linux/signal_types.h>
#include <linux/spinlock_types.h>

/*
* Used to track a thread's prending signals.
KenGordon marked this conversation as resolved.
Show resolved Hide resolved
* See signal_list_head/tail below.
*/

struct ksignal_list_node
KenGordon marked this conversation as resolved.
Show resolved Hide resolved
{
struct ksignal sig;
struct ksignal_list_node *next; /* consider using the kernel lists, but they are doubly linked and clumsy in this simple case */
};

typedef struct {
unsigned long seg;
} mm_segment_t;
Expand All @@ -29,6 +43,12 @@ struct thread_info {
/* The task for any child that was created during syscall execution. Only
* valid on return from a clone-family syscall. */
struct task_struct *cloned_child;

/* lock for the list below, the init is in the thread_info creation fn */
spinlock_t signal_list_lock;
/* a linked list of pending signals, pushed onto here as they are detected in move_signals_to_task */
KenGordon marked this conversation as resolved.
Show resolved Hide resolved
struct ksignal_list_node* signal_list_head;
struct ksignal_list_node* signal_list_tail;
};

#define INIT_THREAD_INFO(tsk) \
Expand Down
61 changes: 57 additions & 4 deletions arch/lkl/kernel/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ static void __cpu_try_get_unlock(int lock_ret, int n)
void lkl_cpu_change_owner(lkl_thread_t owner)
{
lkl_ops->mutex_lock(cpu.lock);
if (cpu.count > 1)
if (cpu.count > 1) {
lkl_print_cpu_lock_state(__func__);
lkl_bug("bad count while changing owner\n");
}
cpu.owner = owner;
lkl_ops->mutex_unlock(cpu.lock);
}
Expand Down Expand Up @@ -117,8 +119,10 @@ void lkl_cpu_put(void)
lkl_ops->mutex_lock(cpu.lock);

if (!cpu.count || !cpu.owner ||
!lkl_ops->thread_equal(cpu.owner, lkl_ops->thread_self()))
!lkl_ops->thread_equal(cpu.owner, lkl_ops->thread_self())) {
lkl_print_cpu_lock_state(__func__);
lkl_bug("%s: unbalanced put\n", __func__);
}

while (cpu.irqs_pending && !irqs_disabled()) {
cpu.irqs_pending = false;
Expand All @@ -128,9 +132,11 @@ void lkl_cpu_put(void)
}

if (test_ti_thread_flag(current_thread_info(), TIF_HOST_THREAD) &&
!single_task_running() && cpu.count == 1) {
if (in_interrupt())
!single_task_running() && cpu.count == 1) {
KenGordon marked this conversation as resolved.
Show resolved Hide resolved
if (in_interrupt()) {
lkl_print_cpu_lock_state(__func__);
lkl_bug("%s: in interrupt\n", __func__);
}
lkl_ops->mutex_unlock(cpu.lock);
thread_sched_jb();
return;
Expand All @@ -150,6 +156,53 @@ void lkl_cpu_put(void)
lkl_ops->mutex_unlock(cpu.lock);
}

#ifdef DEBUG

/*
* Debug tool. Essentially allows for assert(cpuLockTaken);
*/

static int lkl_check_cpu_owner()
KenGordon marked this conversation as resolved.
Show resolved Hide resolved
{
int result;
lkl_ops->mutex_lock(cpu.lock);
lkl_thread_t self = lkl_ops->thread_self();
lkl_thread_t owner = cpu.owner;
if (!cpu.count || !owner ||
KenGordon marked this conversation as resolved.
Show resolved Hide resolved
!lkl_ops->thread_equal(owner, self)) {
result = 0;
} else {
result = 1;
}
lkl_ops->mutex_unlock(cpu.lock);
return result.
}

/* Expected the cpu to be locked by this task. */
void lkl_assert_cpu_owner(void)
{
BUG_ON(lkl_check_cpu_owner() != 1);
}

/* Expected the cpu to be unlocked or locked by another task. */
void lkl_assert_cpu_not_owner(void)
{
BUG_ON(lkl_check_cpu_owner() != 0);
}

/* Debugging, print state of flags etc for a particular caller. */
void lkl_print_cpu_lock_state(const char *func_name)
{
lkl_thread_t self = lkl_ops->thread_self();
lkl_thread_t owner = cpu.owner;
unsigned int count = cpu.count;
unsigned int sleepers = cpu.sleepers;
unsigned int shutdown_gate = cpu.shutdown_gate;

LKL_TRACE("%s: self %lx owner %lx count %u sleepers %u shutdown gate %u\n", func_name, self, owner, count, sleepers, shutdown_gate);
}
#endif

int lkl_cpu_try_run_irq(int irq)
{
int ret;
Expand Down
11 changes: 11 additions & 0 deletions arch/lkl/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ int lkl_is_running(void)

void machine_halt(void)
{
/*
* All lkl_cpu_shutdown does is set cpu.shutdown_gate to MAX_THREADS
* as a flag. It does return and so machine_halt will return too.
*/

lkl_cpu_shutdown();
}

Expand All @@ -156,6 +161,12 @@ long lkl_sys_halt(void)
LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART, };

err = lkl_syscall(__NR_reboot, params);

/*
This code does get run even though machine_halt (above)
is called.
*/

if (err < 0) {
LKL_TRACE("sys_reboot failed (err=%i)\n", err);
return err;
Expand Down
Loading