Skip to contentSkip to conversation

an introduction of library operating system for Linux (LibOS)

RFC PATCH Superseded Hajime Tazaki 10 participants 117 messages Mar 24, 2015 – Sep 3, 2015 Page 2 of 2

Subsystems (11)
lore
Share & tools
lore
#98 lore raw

PATCH v5 3/10 lib: public headers and API implementations for userspace programs

In reply to Hajime Tazaki

userspace programs which uses libos access via a public API, lib_init(), with passed arguments struct SimImported and struct SimExported.

---
 arch/lib/include/sim-assert.h |  23 +++
 arch/lib/include/sim-init.h   | 134 ++++++++++++++
 arch/lib/include/sim-printf.h |  13 ++
 arch/lib/include/sim-types.h  |  53 ++++++
 arch/lib/include/sim.h        |  51 ++++++
 arch/lib/lib-device.c         | 187 +++++++++++++++++++
 arch/lib/lib-socket.c         | 410 ++++++++++++++++++++++++++++++++++++++++++
 arch/lib/lib.c                | 294 ++++++++++++++++++++++++++++++
 arch/lib/lib.h                |  21 +++
 9 files changed, 1186 insertions(+)
 create mode 100644 arch/lib/include/sim-assert.h
 create mode 100644 arch/lib/include/sim-init.h
 create mode 100644 arch/lib/include/sim-printf.h
 create mode 100644 arch/lib/include/sim-types.h
 create mode 100644 arch/lib/include/sim.h
 create mode 100644 arch/lib/lib-device.c
 create mode 100644 arch/lib/lib-socket.c
 create mode 100644 arch/lib/lib.c
 create mode 100644 arch/lib/lib.h
arch/lib/include/sim-assert.h new file +23 -0
new file mode 100644
index 0000000..974122c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#ifndef SIM_ASSERT_H
+#define SIM_ASSERT_H
+
+#include "sim-printf.h"
+
+#define lib_assert(v) {							\
+		while (!(v)) {						\
+			lib_printf("Assert failed %s:%u \"" #v "\"\n",	\
+				__FILE__, __LINE__);			\
+			char *p = 0;					\
+			*p = 1;						\
+		}							\
+	}
+
+
+#endif /* SIM_ASSERT_H */
arch/lib/include/sim-init.h new file +134 -0

134 lines not on this page · raw message

arch/lib/include/sim-printf.h new file +13 -0
new file mode 100644
index 0000000..2bf8245
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#ifndef SIM_PRINTF_H
+#define SIM_PRINTF_H
+
+void lib_printf(const char *str, ...);
+
+#endif /* SIM_PRINTF_H */
arch/lib/include/sim-types.h new file +53 -0

53 lines not on this page · raw message

arch/lib/include/sim.h new file +51 -0

51 lines not on this page · raw message

arch/lib/lib-device.c new file +187 -0

187 lines not on this page · raw message

arch/lib/lib-socket.c new file +410 -0

410 lines not on this page · raw message

arch/lib/lib.c new file +294 -0

294 lines not on this page · raw message

arch/lib/lib.h new file +21 -0
new file mode 100644
index 0000000..abf2a26
@@ -0,0 +1,21 @@
+/*
+ * library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ *         Frederic Urbani
+ */
+
+#ifndef LIB_H
+#define LIB_H
+
+#include <linux/sched.h>
+
+struct SimTask {
+	struct list_head head;
+	struct task_struct kernel_task;
+	void *private;
+};
+
+#endif /* LIB_H */
Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#99 lore raw

PATCH v5 4/10 lib: time handling (kernel glue code)

In reply to Hajime Tazaki

timer related (internal) functions such as add_timer(), do_gettimeofday() of kernel are trivially reimplemented
for libos. these eventually call the functions registered by lib_init() API.

---
 arch/lib/hrtimer.c         | 122 +++++++++++++++++++++++
 arch/lib/tasklet-hrtimer.c |  57 +++++++++++
 arch/lib/time.c            | 144 +++++++++++++++++++++++++++
 arch/lib/timer.c           | 238 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 561 insertions(+)
 create mode 100644 arch/lib/hrtimer.c
 create mode 100644 arch/lib/tasklet-hrtimer.c
 create mode 100644 arch/lib/time.c
 create mode 100644 arch/lib/timer.c
arch/lib/hrtimer.c new file +122 -0
new file mode 100644
index 0000000..4565b59
@@ -0,0 +1,122 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include <linux/hrtimer.h>
+#include "sim-assert.h"
+#include "sim.h"
+
+/**
+ * hrtimer_init - initialize a timer to the given clock
+ * @timer:      the timer to be initialized
+ * @clock_id:   the clock to be used
+ * @mode:       timer mode abs/rel
+ */
+void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
+		  enum hrtimer_mode mode)
+{
+	memset(timer, 0, sizeof(*timer));
+}
+static void trampoline(void *context)
+{
+	struct hrtimer *timer = context;
+	enum hrtimer_restart restart = timer->function(timer);
+
+	if (restart == HRTIMER_RESTART) {
+		void *event =
+			lib_event_schedule_ns(ktime_to_ns(timer->_softexpires),
+					      &trampoline, timer);
+		timer->base = event;
+	} else {
+		/* mark as completed. */
+		timer->base = 0;
+	}
+}
+/**
+ * hrtimer_start_range_ns - (re)start an hrtimer on the current CPU
+ * @timer:      the timer to be added
+ * @tim:        expiry time
+ * @delta_ns:   "slack" range for the timer
+ * @mode:       expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL)
+ *
+ * Returns:
+ *  0 on success
+ *  1 when the timer was active
+ */
+int __hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
+			     unsigned long delta_ns,
+			     const enum hrtimer_mode mode,
+			     int wakeup)
+{
+	int ret = hrtimer_cancel(timer);
+	s64 ns = ktime_to_ns(tim);
+	void *event;
+
+	if (mode == HRTIMER_MODE_ABS)
+		ns -= lib_current_ns();
+	timer->_softexpires = ns_to_ktime(ns);
+	event = lib_event_schedule_ns(ns, &trampoline, timer);
+	timer->base = event;
+	return ret;
+}
+/**
+ * hrtimer_try_to_cancel - try to deactivate a timer
+ * @timer:      hrtimer to stop
+ *
+ * Returns:
+ *  0 when the timer was not active
+ *  1 when the timer was active
+ * -1 when the timer is currently excuting the callback function and
+ *    cannot be stopped
+ */
+int hrtimer_try_to_cancel(struct hrtimer *timer)
+{
+	/* Note: we cannot return -1 from this function.
+	   see comment in hrtimer_cancel. */
+	if (timer->base == 0)
+		/* timer was not active yet */
+		return 1;
+	lib_event_cancel(timer->base);
+	timer->base = 0;
+	return 0;
+}
+/**
+ * hrtimer_cancel - cancel a timer and wait for the handler to finish.
+ * @timer:      the timer to be cancelled
+ *
+ * Returns:
+ *  0 when the timer was not active
+ *  1 when the timer was active
+ */
+int hrtimer_cancel(struct hrtimer *timer)
+{
+	/* Note: because we assume a uniprocessor non-interruptible */
+	/* system when running in the kernel, we know that the timer */
+	/* is not running when we execute this code, so, know that */
+	/* try_to_cancel cannot return -1 and we don't need to retry */
+	/* the cancel later to wait for the handler to finish. */
+	int ret = hrtimer_try_to_cancel(timer);
+
+	lib_assert(ret >= 0);
+	return ret;
+}
+int
+hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
+{
+	return __hrtimer_start_range_ns(timer, tim, 0, mode, 1);
+}
+int hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
+			   unsigned long delta_ns, const enum hrtimer_mode mode)
+{
+	return __hrtimer_start_range_ns(timer, tim, delta_ns, mode, 1);
+}
+
+int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp)
+{
+	*tp = ns_to_timespec(1);
+	return 0;
+}
arch/lib/tasklet-hrtimer.c new file +57 -0

57 lines not on this page · raw message

arch/lib/time.c new file +144 -0

144 lines not on this page · raw message

arch/lib/timer.c new file +238 -0

238 lines not on this page · raw message

Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#100 lore raw

PATCH v5 5/10 lib: context and scheduling functions (kernel glue code) for libos

In reply to Hajime Tazaki

context primitives of kernel such as soft interrupts, scheduling, tasklet are implemented for libos. these functions eventually call the functions registered by lib_init() API as well.

---
 arch/lib/sched.c     | 406 +++++++++++++++++++++++++++++++++++++++++++++++++++
 arch/lib/softirq.c   | 108 ++++++++++++++
 arch/lib/tasklet.c   |  76 ++++++++++
 arch/lib/workqueue.c | 242 ++++++++++++++++++++++++++++++
 4 files changed, 832 insertions(+)
 create mode 100644 arch/lib/sched.c
 create mode 100644 arch/lib/softirq.c
 create mode 100644 arch/lib/tasklet.c
 create mode 100644 arch/lib/workqueue.c
arch/lib/sched.c new file +406 -0
new file mode 100644
index 0000000..98a568a
@@ -0,0 +1,406 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include <linux/wait.h>
+#include <linux/list.h>
+#include <linux/sched.h>
+#include <linux/nsproxy.h>
+#include <linux/hash.h>
+#include <net/net_namespace.h>
+#include "lib.h"
+#include "sim.h"
+#include "sim-assert.h"
+
+/**
+   called by wait_event macro:
+   - prepare_to_wait
+   - schedule
+   - finish_wait
+ */
+
+struct SimTask *lib_task_create(void *private, unsigned long pid)
+{
+	struct SimTask *task = lib_malloc(sizeof(struct SimTask));
+	struct cred *cred;
+	struct nsproxy *ns;
+	struct user_struct *user;
+	struct thread_info *info;
+	struct pid *kpid;
+
+	if (!task)
+		return NULL;
+	memset(task, 0, sizeof(struct SimTask));
+	cred = lib_malloc(sizeof(struct cred));
+	if (!cred)
+		return NULL;
+	/* XXX: we could optimize away this allocation by sharing it
+	   for all tasks */
+	ns = lib_malloc(sizeof(struct nsproxy));
+	if (!ns)
+		return NULL;
+	user = lib_malloc(sizeof(struct user_struct));
+	if (!user)
+		return NULL;
+	info = alloc_thread_info(&task->kernel_task);
+	if (!info)
+		return NULL;
+	kpid = lib_malloc(sizeof(struct pid));
+	if (!kpid)
+		return NULL;
+	kpid->numbers[0].nr = pid;
+	cred->fsuid = make_kuid(current_user_ns(), 0);
+	cred->fsgid = make_kgid(current_user_ns(), 0);
+	cred->user = user;
+	atomic_set(&cred->usage, 1);
+	info->task = &task->kernel_task;
+	info->preempt_count = 0;
+	info->flags = 0;
+	atomic_set(&ns->count, 1);
+	ns->uts_ns = 0;
+	ns->ipc_ns = 0;
+	ns->mnt_ns = 0;
+	ns->pid_ns_for_children = 0;
+	ns->net_ns = &init_net;
+	task->kernel_task.cred = cred;
+	task->kernel_task.pid = pid;
+	task->kernel_task.pids[PIDTYPE_PID].pid = kpid;
+	task->kernel_task.pids[PIDTYPE_PGID].pid = kpid;
+	task->kernel_task.pids[PIDTYPE_SID].pid = kpid;
+	task->kernel_task.nsproxy = ns;
+	task->kernel_task.stack = info;
+	/* this is a hack. */
+	task->kernel_task.group_leader = &task->kernel_task;
+	task->private = private;
+	return task;
+}
+void lib_task_destroy(struct SimTask *task)
+{
+	lib_free((void *)task->kernel_task.nsproxy);
+	lib_free((void *)task->kernel_task.cred);
+	lib_free((void *)task->kernel_task.cred->user);
+	free_thread_info(task->kernel_task.stack);
+	lib_free(task);
+}
+void *lib_task_get_private(struct SimTask *task)
+{
+	return task->private;
+}
+
+int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
+{
+	struct SimTask *task = lib_task_start((void (*)(void *))fn, arg);
+
+	return task->kernel_task.pid;
+}
+
+struct task_struct *get_current(void)
+{
+	struct SimTask *lib_task = lib_task_current();
+
+	return &lib_task->kernel_task;
+}
+
+struct thread_info *current_thread_info(void)
+{
+	return task_thread_info(get_current());
+}
+struct thread_info *alloc_thread_info(struct task_struct *task)
+{
+	return lib_malloc(sizeof(struct thread_info));
+}
+void free_thread_info(struct thread_info *ti)
+{
+	lib_free(ti);
+}
+
+
+void __put_task_struct(struct task_struct *t)
+{
+	lib_free(t);
+}
+
+void add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait)
+{
+	wait->flags &= ~WQ_FLAG_EXCLUSIVE;
+	list_add(&wait->task_list, &q->task_list);
+}
+void add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
+{
+	wait->flags |= WQ_FLAG_EXCLUSIVE;
+	list_add_tail(&wait->task_list, &q->task_list);
+}
+void remove_wait_queue(wait_queue_head_t *q, wait_queue_t *wait)
+{
+	if (wait->task_list.prev != LIST_POISON2)
+		list_del(&wait->task_list);
+}
+void
+prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state)
+{
+	wait->flags |= WQ_FLAG_EXCLUSIVE;
+	if (list_empty(&wait->task_list))
+		list_add_tail(&wait->task_list, &q->task_list);
+	set_current_state(state);
+}
+void prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state)
+{
+	unsigned long flags;
+
+	wait->flags &= ~WQ_FLAG_EXCLUSIVE;
+	spin_lock_irqsave(&q->lock, flags);
+	if (list_empty(&wait->task_list))
+		__add_wait_queue(q, wait);
+	set_current_state(state);
+	spin_unlock_irqrestore(&q->lock, flags);
+}
+void finish_wait(wait_queue_head_t *q, wait_queue_t *wait)
+{
+	set_current_state(TASK_RUNNING);
+	if (!list_empty(&wait->task_list))
+		list_del_init(&wait->task_list);
+}
+int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync,
+			     void *key)
+{
+	int ret = default_wake_function(wait, mode, sync, key);
+
+	if (ret && (wait->task_list.prev != LIST_POISON2))
+		list_del_init(&wait->task_list);
+
+	return ret;
+}
+
+int woken_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key)
+{
+	wait->flags |= WQ_FLAG_WOKEN;
+	return default_wake_function(wait, mode, sync, key);
+}
+
+void __init_waitqueue_head(wait_queue_head_t *q, const char *name,
+			   struct lock_class_key *k)
+{
+	INIT_LIST_HEAD(&q->task_list);
+}
+/**
+ * wait_for_completion: - waits for completion of a task
+ * @x:  holds the state of this particular completion
+ *
+ * This waits to be signaled for completion of a specific task. It is NOT
+ * interruptible and there is no timeout.
+ *
+ * See also similar routines (i.e. wait_for_completion_timeout()) with timeout
+ * and interrupt capability. Also see complete().
+ */
+void wait_for_completion(struct completion *x)
+{
+	wait_for_completion_timeout(x, MAX_SCHEDULE_TIMEOUT);
+}
+unsigned long wait_for_completion_timeout(struct completion *x,
+					  unsigned long timeout)
+{
+	if (!x->done) {
+		DECLARE_WAITQUEUE(wait, current);
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		wait.flags |= WQ_FLAG_EXCLUSIVE;
+		list_add_tail(&wait.task_list, &x->wait.task_list);
+		do
+			timeout = schedule_timeout(timeout);
+		while (!x->done && timeout);
+		if (wait.task_list.prev != LIST_POISON2)
+			list_del(&wait.task_list);
+
+		if (!x->done)
+			return timeout;
+	}
+	x->done--;
+	return timeout ? : 1;
+}
+
+/**
+ * __wake_up - wake up threads blocked on a waitqueue.
+ * @q: the waitqueue
+ * @mode: which threads
+ * @nr_exclusive: how many wake-one or wake-many threads to wake up
+ * @key: is directly passed to the wakeup function
+ *
+ * It may be assumed that this function implies a write memory barrier before
+ * changing the task state if and only if any tasks are woken up.
+ */
+void __wake_up(wait_queue_head_t *q, unsigned int mode,
+	       int nr_exclusive, void *key)
+{
+	wait_queue_t *curr, *next;
+
+	list_for_each_entry_safe(curr, next, &q->task_list, task_list) {
+		unsigned flags = curr->flags;
+
+		if (curr->func(curr, mode, 0, key) &&
+		    (flags & WQ_FLAG_EXCLUSIVE) &&
+		    !--nr_exclusive)
+			break;
+	}
+}
+void __wake_up_sync_key(wait_queue_head_t *q, unsigned int mode,
+			int nr_exclusive, void *key)
+{
+	__wake_up(q, mode, nr_exclusive, key);
+}
+int default_wake_function(wait_queue_t *curr, unsigned mode, int wake_flags,
+			  void *key)
+{
+	struct task_struct *task = (struct task_struct *)curr->private;
+	struct SimTask *lib_task = container_of(task, struct SimTask,
+						kernel_task);
+
+	return lib_task_wakeup(lib_task);
+}
+__sched int bit_wait(struct wait_bit_key *word)
+{
+	if (signal_pending_state(current->state, current))
+		return 1;
+	schedule();
+	return 0;
+}
+int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *arg)
+{
+	struct wait_bit_key *key = arg;
+	struct wait_bit_queue *wait_bit
+		= container_of(wait, struct wait_bit_queue, wait);
+
+	if (wait_bit->key.flags != key->flags ||
+			wait_bit->key.bit_nr != key->bit_nr ||
+			test_bit(key->bit_nr, key->flags))
+		return 0;
+	else
+		return autoremove_wake_function(wait, mode, sync, key);
+}
+void __wake_up_bit(wait_queue_head_t *wq, void *word, int bit)
+{
+	struct wait_bit_key key = __WAIT_BIT_KEY_INITIALIZER(word, bit);
+	if (waitqueue_active(wq))
+		__wake_up(wq, TASK_NORMAL, 1, &key);
+}
+void wake_up_bit(void *word, int bit)
+{
+	/* FIXME */
+	return;
+	__wake_up_bit(bit_waitqueue(word, bit), word, bit);
+}
+wait_queue_head_t *bit_waitqueue(void *word, int bit)
+{
+	const int shift = BITS_PER_LONG == 32 ? 5 : 6;
+	const struct zone *zone = page_zone(virt_to_page(word));
+	unsigned long val = (unsigned long)word << shift | bit;
+
+	return &zone->wait_table[hash_long(val, zone->wait_table_bits)];
+}
+
+
+void schedule(void)
+{
+	lib_task_wait();
+}
+
+static void trampoline(void *context)
+{
+	struct SimTask *task = context;
+
+	lib_task_wakeup(task);
+}
+
+signed long schedule_timeout(signed long timeout)
+{
+	u64 ns;
+	struct SimTask *self;
+
+	if (timeout == MAX_SCHEDULE_TIMEOUT) {
+		lib_task_wait();
+		return MAX_SCHEDULE_TIMEOUT;
+	}
+	lib_assert(timeout >= 0);
+	ns = ((__u64)timeout) * (1000000000 / HZ);
+	self = lib_task_current();
+	lib_event_schedule_ns(ns, &trampoline, self);
+	lib_task_wait();
+	/* we know that we are always perfectly on time. */
+	return 0;
+}
+
+signed long schedule_timeout_uninterruptible(signed long timeout)
+{
+	return schedule_timeout(timeout);
+}
+signed long schedule_timeout_interruptible(signed long timeout)
+{
+	return schedule_timeout(timeout);
+}
+
+void yield(void)
+{
+	lib_task_yield();
+}
+
+void complete_all(struct completion *x)
+{
+	x->done += UINT_MAX / 2;
+	__wake_up(&x->wait, TASK_NORMAL, 0, 0);
+}
+void complete(struct completion *x)
+{
+	x->done++;
+	__wake_up(&x->wait, TASK_NORMAL, 1, 0);
+}
+
+long wait_for_completion_interruptible_timeout(
+	struct completion *x, unsigned long timeout)
+{
+	return wait_for_completion_timeout(x, timeout);
+}
+int wait_for_completion_interruptible(struct completion *x)
+{
+	wait_for_completion_timeout(x, MAX_SCHEDULE_TIMEOUT);
+	return 0;
+}
+int wake_up_process(struct task_struct *tsk)
+{
+	struct SimTask *lib_task =
+		container_of(tsk, struct SimTask, kernel_task);
+
+	return lib_task_wakeup(lib_task);
+}
+int _cond_resched(void)
+{
+	/* we never schedule to decrease latency. */
+	return 0;
+}
+int idle_cpu(int cpu)
+{
+	/* we are never idle: we call this from rcutiny.c and the answer */
+	/* does not matter, really. */
+	return 0;
+}
+
+unsigned long long __attribute__((weak)) sched_clock(void)
+{
+	return (unsigned long long)(jiffies - INITIAL_JIFFIES)
+	       * (NSEC_PER_SEC / HZ);
+}
+
+u64 local_clock(void)
+{
+	return sched_clock();
+}
+
+void __sched schedule_preempt_disabled(void)
+{
+}
+
+void resched_cpu(int cpu)
+{
+	rcu_sched_qs();
+}
arch/lib/softirq.c new file +108 -0

108 lines not on this page · raw message

arch/lib/tasklet.c new file +76 -0

76 lines not on this page · raw message

arch/lib/workqueue.c new file +242 -0

242 lines not on this page · raw message

Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#101 lore raw

PATCH v5 6/10 lib: sysctl handling (kernel glue code)

In reply to Hajime Tazaki

This interacts with fs/proc_fs.c for sysctl-like interface registered via lib_init() API.

---
 arch/lib/sysctl.c | 270 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 270 insertions(+)
 create mode 100644 arch/lib/sysctl.c
arch/lib/sysctl.c new file +270 -0
new file mode 100644
index 0000000..5f08f9f
@@ -0,0 +1,270 @@
+/*
+ * sysctl wrapper for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include <linux/mm.h>
+#include <linux/mmzone.h>
+#include <linux/mman.h>
+#include <linux/ratelimit.h>
+#include <linux/proc_fs.h>
+#include "sim-assert.h"
+#include "sim-types.h"
+
+int drop_caches_sysctl_handler(struct ctl_table *table, int write,
+			       void *buffer, size_t *length, loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int lowmem_reserve_ratio_sysctl_handler(struct ctl_table *table, int write,
+					void *buffer, size_t *length,
+					loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int min_free_kbytes_sysctl_handler(struct ctl_table *table, int write,
+				   void *buffer, size_t *length, loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+
+int percpu_pagelist_fraction_sysctl_handler(struct ctl_table *table, int write,
+					    void *buffer, size_t *length,
+					    loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int dirty_background_ratio_handler(struct ctl_table *table, int write,
+				   void *buffer, size_t *lenp,
+				   loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int dirty_background_bytes_handler(struct ctl_table *table, int write,
+				   void *buffer, size_t *lenp,
+				   loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int dirty_ratio_handler(struct ctl_table *table, int write,
+			void *buffer, size_t *lenp,
+			loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int dirty_bytes_handler(struct ctl_table *table, int write,
+			void *buffer, size_t *lenp,
+			loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int dirty_writeback_centisecs_handler(struct ctl_table *table, int write,
+				      void *buffer, size_t *length,
+				      loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int scan_unevictable_handler(struct ctl_table *table, int write,
+			     void __user *buffer,
+			     size_t *length, loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int sched_rt_handler(struct ctl_table *table, int write,
+		     void __user *buffer, size_t *lenp,
+		     loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+
+int sysctl_overcommit_memory = OVERCOMMIT_GUESS;
+int sysctl_overcommit_ratio = 50;
+int sysctl_panic_on_oom = 0;
+int sysctl_oom_dump_tasks = 0;
+int sysctl_oom_kill_allocating_task = 0;
+int sysctl_nr_trim_pages = 0;
+int sysctl_drop_caches = 0;
+int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES - 1] = { 32 };
+unsigned int sysctl_sched_child_runs_first = 0;
+unsigned int sysctl_sched_compat_yield = 0;
+unsigned int sysctl_sched_rt_period = 1000000;
+int sysctl_sched_rt_runtime = 950000;
+
+int vm_highmem_is_dirtyable;
+unsigned long vm_dirty_bytes = 0;
+int vm_dirty_ratio = 20;
+int dirty_background_ratio = 10;
+unsigned int dirty_expire_interval = 30 * 100;
+unsigned int dirty_writeback_interval = 5 * 100;
+unsigned long dirty_background_bytes = 0;
+int percpu_pagelist_fraction = 0;
+int panic_timeout = 0;
+int panic_on_oops = 0;
+int printk_delay_msec = 0;
+int panic_on_warn = 0;
+DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
+
+#define RESERVED_PIDS 300
+int pid_max = PID_MAX_DEFAULT;
+int pid_max_min = RESERVED_PIDS + 1;
+int pid_max_max = PID_MAX_LIMIT;
+int min_free_kbytes = 1024;
+int max_threads = 100;
+int laptop_mode = 0;
+
+#define DEFAULT_MESSAGE_LOGLEVEL 4
+#define MINIMUM_CONSOLE_LOGLEVEL 1
+#define DEFAULT_CONSOLE_LOGLEVEL 7
+int console_printk[4] = {
+	DEFAULT_CONSOLE_LOGLEVEL,       /* console_loglevel */
+	DEFAULT_MESSAGE_LOGLEVEL,       /* default_message_loglevel */
+	MINIMUM_CONSOLE_LOGLEVEL,       /* minimum_console_loglevel */
+	DEFAULT_CONSOLE_LOGLEVEL,       /* default_console_loglevel */
+};
+
+int print_fatal_signals = 0;
+unsigned int core_pipe_limit = 0;
+int core_uses_pid = 0;
+int vm_swappiness = 60;
+int nr_pdflush_threads = 0;
+unsigned long scan_unevictable_pages = 0;
+int suid_dumpable = 0;
+int page_cluster = 0;
+int block_dump = 0;
+int C_A_D = 0;
+#include <linux/nsproxy.h>
+struct nsproxy init_nsproxy;
+#include <linux/reboot.h>
+char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";
+unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
+unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
+
+int pdflush_proc_obsolete(struct ctl_table *table, int write,
+			  void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+	return nr_pdflush_threads;
+}
+#include <linux/fs.h>
+
+/**
+ * Honestly, I don't understand half of that code.
+ * It was modeled after fs/proc/proc_sysctl.c proc_sys_readdir
+ *
+ * Me either ;) (Hajime, Jan 2013)
+ */
+
+/* from proc_sysctl.c (XXX) */
+extern struct ctl_table_root sysctl_table_root;
+void ctl_table_first_entry(struct ctl_dir *dir,
+		 struct ctl_table_header **phead, struct ctl_table **pentry);
+void ctl_table_next_entry(struct ctl_table_header **phead, struct ctl_table **pentry);
+struct ctl_table *ctl_table_find_entry(struct ctl_table_header **phead,
+			     struct ctl_dir *dir, const char *name,
+			     int namelen);
+struct ctl_dir *ctl_table_xlate_dir(struct ctl_table_set *set, struct ctl_dir *dir);
+/* for init_net (XXX, should be fixed) */
+#include <net/net_namespace.h>
+
+static void iterate_table_recursive(const struct SimSysIterator *iter,
+				    struct ctl_table_header *head)
+{
+	struct ctl_table *entry;
+
+	for (entry = head->ctl_table; entry->procname; entry++) {
+		bool may_read = (head->ctl_table->mode & MAY_READ);
+		bool may_write = (head->ctl_table->mode & MAY_WRITE);
+		int flags = 0;
+
+		flags |= may_read ? SIM_SYS_FILE_READ : 0;
+		flags |= may_write ? SIM_SYS_FILE_WRITE : 0;
+		iter->report_file(iter, entry->procname, flags,
+				  (struct SimSysFile *)entry);
+	}
+}
+
+
+static void iterate_recursive(const struct SimSysIterator *iter,
+			      struct ctl_table_header *head)
+{
+	struct ctl_table_header *h = NULL;
+	struct ctl_table *entry;
+	struct ctl_dir *ctl_dir;
+
+	ctl_dir = container_of(head, struct ctl_dir, header);
+	for (ctl_table_first_entry(ctl_dir, &h, &entry); h;
+	     ctl_table_next_entry(&h, &entry)) {
+		struct ctl_dir *dir;
+		int ret;
+		const char *procname;
+
+		/* copy from sysctl_follow_link () */
+		if (S_ISLNK(entry->mode)) {
+			dir = ctl_table_xlate_dir(&init_net.sysctls, h->parent);
+			if (IS_ERR(dir)) {
+				ret = PTR_ERR(dir);
+				lib_assert(false);
+			} else {
+				procname = entry->procname;
+				h = NULL;
+				entry =
+					ctl_table_find_entry(&h, dir, procname,
+							     strlen(procname));
+				ret = -ENOENT;
+			}
+		}
+
+		if (S_ISDIR(entry->mode)) {
+			iter->report_start_dir(iter, entry->procname);
+			iterate_recursive(iter, h);
+			iter->report_end_dir(iter);
+		} else
+			iterate_table_recursive(iter, h);
+	}
+
+}
+
+
+void lib_sys_iterate_files(const struct SimSysIterator *iter)
+{
+	struct ctl_table_header *root =
+		&sysctl_table_root.default_set.dir.header;
+
+	iterate_recursive(iter, root);
+}
+
+int lib_sys_file_read(const struct SimSysFile *file, char *buffer, int size,
+		      int offset)
+{
+	struct ctl_table *table = (struct ctl_table *)file;
+	loff_t ppos = offset;
+	size_t result = size;
+	int error;
+
+	error = table->proc_handler(table, 0, buffer, &result, &ppos);
+	return result;
+}
+int lib_sys_file_write(const struct SimSysFile *file, const char *buffer,
+		       int size, int offset)
+{
+	struct ctl_table *table = (struct ctl_table *)file;
+	loff_t ppos = offset;
+	size_t result = size;
+	int error;
+
+	error = table->proc_handler(table, 1, (char *)buffer, &result, &ppos);
+	return result;
+}
Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#102 lore raw

PATCH v5 7/10 lib: other kernel glue layer code

In reply to Hajime Tazaki

These files are used to provide the same function calls so that other network stack code keeps untouched.

---
 arch/lib/capability.c |  25 +++++
 arch/lib/filemap.c    |  32 ++++++
 arch/lib/fs.c         |  70 ++++++++++++
 arch/lib/glue.c       | 289 ++++++++++++++++++++++++++++++++++++++++++++++++++
 arch/lib/modules.c    |  36 +++++++
 arch/lib/pid.c        |  29 +++++
 arch/lib/print.c      |  56 ++++++++++
 arch/lib/proc.c       |  34 ++++++
 arch/lib/random.c     |  53 +++++++++
 arch/lib/sysfs.c      |  83 +++++++++++++++
 arch/lib/vmscan.c     |  26 +++++
 11 files changed, 733 insertions(+)
 create mode 100644 arch/lib/capability.c
 create mode 100644 arch/lib/filemap.c
 create mode 100644 arch/lib/fs.c
 create mode 100644 arch/lib/glue.c
 create mode 100644 arch/lib/modules.c
 create mode 100644 arch/lib/pid.c
 create mode 100644 arch/lib/print.c
 create mode 100644 arch/lib/proc.c
 create mode 100644 arch/lib/random.c
 create mode 100644 arch/lib/sysfs.c
 create mode 100644 arch/lib/vmscan.c
arch/lib/capability.c new file +25 -0
new file mode 100644
index 0000000..3a1f301
@@ -0,0 +1,25 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include "linux/capability.h"
+
+struct sock;
+struct sk_buff;
+
+int file_caps_enabled = 0;
+
+int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
+{
+	return 0;
+}
+
+bool file_ns_capable(const struct file *file, struct user_namespace *ns,
+		     int cap)
+{
+	return true;
+}
arch/lib/filemap.c new file +32 -0
new file mode 100644
index 0000000..ce424ff
@@ -0,0 +1,32 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ *         Frederic Urbani
+ */
+
+#include "sim.h"
+#include "sim-assert.h"
+#include <linux/fs.h>
+
+
+ssize_t generic_file_aio_read(struct kiocb *a, const struct iovec *b,
+			      unsigned long c, loff_t d)
+{
+	lib_assert(false);
+
+	return 0;
+}
+
+int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	return -ENOSYS;
+}
+
+ssize_t
+generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
+{
+	return 0;
+}
arch/lib/fs.c new file +70 -0

70 lines not on this page · raw message

arch/lib/glue.c new file +289 -0

289 lines not on this page · raw message

arch/lib/modules.c new file +36 -0
new file mode 100644
index 0000000..ca43fdc
@@ -0,0 +1,36 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ *         Frederic Urbani
+ */
+
+#include "sim-assert.h"
+#include <linux/moduleparam.h>
+#include <linux/kmod.h>
+#include <linux/module.h>
+
+int modules_disabled = 0;
+char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
+
+static struct module_version_attribute g_empty_attr_buffer;
+/* we make the array empty by default because, really, we don't need */
+/* to look at the builtin params */
+const struct kernel_param __start___param[] = {{0}} ;
+const struct kernel_param __stop___param[] = {{0}} ;
+const struct module_version_attribute *__start___modver[] = {
+	&g_empty_attr_buffer};
+const struct module_version_attribute *__stop___modver[] = {
+	&g_empty_attr_buffer};
+
+struct module_attribute module_uevent;
+struct ctl_table usermodehelper_table[] = {};
+
+int __request_module(bool wait, const char *fmt, ...)
+{
+	/* we really should never be trying to load modules that way. */
+	/*  lib_assert (false); */
+	return 0;
+}
arch/lib/pid.c new file +29 -0
new file mode 100644
index 0000000..00cf7b6
@@ -0,0 +1,29 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include <linux/pid.h>
+#include "sim.h"
+#include "sim-assert.h"
+
+void put_pid(struct pid *pid)
+{
+}
+pid_t pid_vnr(struct pid *pid)
+{
+	return pid_nr(pid);
+}
+struct task_struct *find_task_by_vpid(pid_t nr)
+{
+	lib_assert(false);
+	return 0;
+}
+struct pid *find_get_pid(int nr)
+{
+	lib_assert(false);
+	return 0;
+}
arch/lib/print.c new file +56 -0

56 lines not on this page · raw message

arch/lib/proc.c new file +34 -0
new file mode 100644
index 0000000..5507730
@@ -0,0 +1,34 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2014 Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include <linux/fs.h>
+#include <linux/net.h>
+#include <linux/slab.h>
+#include <linux/proc_fs.h>
+#include <linux/string.h>
+#include <net/net_namespace.h>
+#include "sim-types.h"
+#include "sim-assert.h"
+#include "fs/proc/internal.h"           /* XXX */
+
+struct proc_dir_entry;
+static char proc_root_data[sizeof(struct proc_dir_entry) + 4];
+
+static struct proc_dir_entry *proc_root_sim  =
+	(struct proc_dir_entry *)proc_root_data;
+
+void lib_proc_net_initialize(void)
+{
+	proc_root_sim->parent = proc_root_sim;
+	strcpy(proc_root_sim->name, "net");
+	proc_root_sim->mode = S_IFDIR | S_IRUGO | S_IXUGO;
+	proc_root_sim->subdir = RB_ROOT;
+	init_net.proc_net = proc_root_sim;
+	init_net.proc_net_stat = proc_mkdir("stat", proc_root_sim);
+}
+
arch/lib/random.c new file +53 -0

53 lines not on this page · raw message

arch/lib/sysfs.c new file +83 -0

83 lines not on this page · raw message

arch/lib/vmscan.c new file +26 -0
new file mode 100644
index 0000000..3132f66
@@ -0,0 +1,26 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include <linux/mm.h>
+#include <linux/shrinker.h>
+
+/*
+ * Add a shrinker callback to be called from the vm
+ */
+int register_shrinker(struct shrinker *shrinker)
+{
+	return 0;
+}
+
+/*
+ * Remove one
+ */
+void unregister_shrinker(struct shrinker *shrinker)
+{
+}
+
Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#103 lore raw

PATCH v5 8/10 lib: auxiliary files for auto-generated asm-generic files of libos

In reply to Hajime Tazaki

these files works as stubs in order to transparently run the other kernel part (e.g., net/) on libos environment.

---
 arch/lib/include/asm/Kbuild           | 57 +++++++++++++++++++++++++++++++++
 arch/lib/include/asm/atomic.h         | 59 +++++++++++++++++++++++++++++++++++
 arch/lib/include/asm/barrier.h        |  8 +++++
 arch/lib/include/asm/bitsperlong.h    | 16 ++++++++++
 arch/lib/include/asm/current.h        |  7 +++++
 arch/lib/include/asm/elf.h            | 10 ++++++
 arch/lib/include/asm/hardirq.h        |  8 +++++
 arch/lib/include/asm/page.h           | 14 +++++++++
 arch/lib/include/asm/pgtable.h        | 30 ++++++++++++++++++
 arch/lib/include/asm/processor.h      | 19 +++++++++++
 arch/lib/include/asm/ptrace.h         |  4 +++
 arch/lib/include/asm/segment.h        |  6 ++++
 arch/lib/include/asm/sembuf.h         |  4 +++
 arch/lib/include/asm/shmbuf.h         |  4 +++
 arch/lib/include/asm/shmparam.h       |  4 +++
 arch/lib/include/asm/sigcontext.h     |  6 ++++
 arch/lib/include/asm/stat.h           |  4 +++
 arch/lib/include/asm/statfs.h         |  4 +++
 arch/lib/include/asm/swab.h           |  7 +++++
 arch/lib/include/asm/thread_info.h    | 36 +++++++++++++++++++++
 arch/lib/include/asm/uaccess.h        | 14 +++++++++
 arch/lib/include/asm/unistd.h         |  4 +++
 arch/lib/include/uapi/asm/byteorder.h |  6 ++++
 23 files changed, 331 insertions(+)
 create mode 100644 arch/lib/include/asm/Kbuild
 create mode 100644 arch/lib/include/asm/atomic.h
 create mode 100644 arch/lib/include/asm/barrier.h
 create mode 100644 arch/lib/include/asm/bitsperlong.h
 create mode 100644 arch/lib/include/asm/current.h
 create mode 100644 arch/lib/include/asm/elf.h
 create mode 100644 arch/lib/include/asm/hardirq.h
 create mode 100644 arch/lib/include/asm/page.h
 create mode 100644 arch/lib/include/asm/pgtable.h
 create mode 100644 arch/lib/include/asm/processor.h
 create mode 100644 arch/lib/include/asm/ptrace.h
 create mode 100644 arch/lib/include/asm/segment.h
 create mode 100644 arch/lib/include/asm/sembuf.h
 create mode 100644 arch/lib/include/asm/shmbuf.h
 create mode 100644 arch/lib/include/asm/shmparam.h
 create mode 100644 arch/lib/include/asm/sigcontext.h
 create mode 100644 arch/lib/include/asm/stat.h
 create mode 100644 arch/lib/include/asm/statfs.h
 create mode 100644 arch/lib/include/asm/swab.h
 create mode 100644 arch/lib/include/asm/thread_info.h
 create mode 100644 arch/lib/include/asm/uaccess.h
 create mode 100644 arch/lib/include/asm/unistd.h
 create mode 100644 arch/lib/include/uapi/asm/byteorder.h
arch/lib/include/asm/Kbuild new file +57 -0
new file mode 100644
index 0000000..c647b1c
@@ -0,0 +1,57 @@
+generic-y += auxvec.h
+generic-y += bitops.h
+generic-y += bug.h
+generic-y += cache.h
+generic-y += cacheflush.h
+generic-y += checksum.h
+generic-y += cputime.h
+generic-y += cmpxchg.h
+generic-y += delay.h
+generic-y += device.h
+generic-y += div64.h
+generic-y += dma.h
+generic-y += exec.h
+generic-y += emergency-restart.h
+generic-y += errno.h
+generic-y += fcntl.h
+generic-y += ftrace.h
+generic-y += io.h
+generic-y += ioctl.h
+generic-y += ioctls.h
+generic-y += ipcbuf.h
+generic-y += irq.h
+generic-y += irqflags.h
+generic-y += irq_regs.h
+generic-y += kdebug.h
+generic-y += kmap_types.h
+generic-y += linkage.h
+generic-y += local.h
+generic-y += mcs_spinlock.h
+generic-y += mman.h
+generic-y += mmu.h
+generic-y += mmu_context.h
+generic-y += module.h
+generic-y += mutex.h
+generic-y += param.h
+generic-y += pci.h
+generic-y += percpu.h
+generic-y += poll.h
+generic-y += posix_types.h
+generic-y += preempt.h
+generic-y += resource.h
+generic-y += scatterlist.h
+generic-y += sections.h
+generic-y += setup.h
+generic-y += signal.h
+generic-y += siginfo.h
+generic-y += socket.h
+generic-y += sockios.h
+generic-y += string.h
+generic-y += termbits.h
+generic-y += termios.h
+generic-y += timex.h
+generic-y += tlbflush.h
+generic-y += types.h
+generic-y += topology.h
+generic-y += trace_clock.h
+generic-y += unaligned.h
arch/lib/include/asm/atomic.h new file +59 -0

59 lines not on this page · raw message

arch/lib/include/asm/barrier.h new file +8 -0
new file mode 100644
index 0000000..47adcc6
@@ -0,0 +1,8 @@
+#include <asm-generic/barrier.h>
+
+#undef smp_store_release
+#define smp_store_release(p, v)						\
+	do {								\
+		smp_mb();						\
+		ACCESS_ONCE(*p) = (v);					\
+	} while (0)
arch/lib/include/asm/bitsperlong.h new file +16 -0
new file mode 100644
index 0000000..9890ba9
@@ -0,0 +1,16 @@
+#ifndef _ASM_SIM_BITSPERLONG_H
+#define _ASM_SIM_BITSPERLONG_H
+
+#ifdef CONFIG_64BIT
+#define BITS_PER_LONG 64
+#else
+#define BITS_PER_LONG 32
+#endif /* CONFIG_64BIT */
+
+#define __BITS_PER_LONG BITS_PER_LONG
+
+#ifndef BITS_PER_LONG_LONG
+#define BITS_PER_LONG_LONG 64
+#endif
+
+#endif /* _ASM_SIM_BITSPERLONG_H */
arch/lib/include/asm/current.h new file +7 -0
new file mode 100644
index 0000000..62489cd
@@ -0,0 +1,7 @@
+#ifndef _ASM_SIM_CURRENT_H
+#define _ASM_SIM_CURRENT_H
+
+struct task_struct *get_current(void);
+#define current get_current()
+
+#endif /* _ASM_SIM_CURRENT_H */
arch/lib/include/asm/elf.h new file +10 -0
new file mode 100644
index 0000000..a7396c9
@@ -0,0 +1,10 @@
+#ifndef _ASM_SIM_ELF_H
+#define _ASM_SIM_ELF_H
+
+#if defined(CONFIG_64BIT)
+#define ELF_CLASS ELFCLASS64
+#else
+#define ELF_CLASS ELFCLASS32
+#endif
+
+#endif /* _ASM_SIM_ELF_H */
arch/lib/include/asm/hardirq.h new file +8 -0
new file mode 100644
index 0000000..47d47f9
@@ -0,0 +1,8 @@
+#ifndef _ASM_SIM_HARDIRQ_H
+#define _ASM_SIM_HARDIRQ_H
+
+extern unsigned int interrupt_pending;
+
+#define local_softirq_pending() (interrupt_pending)
+
+#endif /* _ASM_SIM_HARDIRQ_H */
arch/lib/include/asm/page.h new file +14 -0
new file mode 100644
index 0000000..8c0aa74
@@ -0,0 +1,14 @@
+#ifndef _ASM_SIM_PAGE_H
+#define _ASM_SIM_PAGE_H
+
+typedef struct {} pud_t;
+
+#define THREAD_ORDER    1
+#define THREAD_SIZE  (PAGE_SIZE << THREAD_ORDER)
+
+#define WANT_PAGE_VIRTUAL 1
+
+#include <asm-generic/page.h>
+#include <asm-generic/getorder.h>
+
+#endif /* _ASM_SIM_PAGE_H */
arch/lib/include/asm/pgtable.h new file +30 -0
new file mode 100644
index 0000000..ce599c8
@@ -0,0 +1,30 @@
+#ifndef _ASM_SIM_PGTABLE_H
+#define _ASM_SIM_PGTABLE_H
+
+#define PAGE_KERNEL ((pgprot_t) {0 })
+
+#define arch_start_context_switch(prev) do {} while (0)
+
+#define kern_addr_valid(addr)(1)
+#define pte_file(pte)(1)
+/* Encode and de-code a swap entry */
+#define __swp_type(x)                   (((x).val >> 5) & 0x1f)
+#define __swp_offset(x)                 ((x).val >> 11)
+#define __swp_entry(type, offset) \
+	((swp_entry_t) {((type) << 5) | ((offset) << 11) })
+#define __pte_to_swp_entry(pte)         ((swp_entry_t) {pte_val((pte)) })
+#define __swp_entry_to_pte(x)           ((pte_t) {(x).val })
+#define pmd_page(pmd) (struct page *)(pmd_val(pmd) & PAGE_MASK)
+#define pgtable_cache_init()   do { } while (0)
+
+static inline int pte_swp_soft_dirty(pte_t pte)
+{
+	return 0;
+}
+
+static inline pte_t pte_swp_clear_soft_dirty(pte_t pte)
+{
+	return pte;
+}
+
+#endif /* _ASM_SIM_PGTABLE_H */
arch/lib/include/asm/processor.h new file +19 -0
new file mode 100644
index 0000000..b673ee0
@@ -0,0 +1,19 @@
+#ifndef _ASM_SIM_PROCESSOR_H
+#define _ASM_SIM_PROCESSOR_H
+
+struct thread_struct {};
+
+#define cpu_relax()
+#define cpu_relax_lowlatency() cpu_relax()
+#define KSTK_ESP(tsk)	(0)
+
+void *current_text_addr(void);
+
+#define TASK_SIZE ((~(long)0))
+
+#define thread_saved_pc(x) (unsigned long)0
+#define task_pt_regs(t) NULL
+
+int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
+
+#endif /* _ASM_SIM_PROCESSOR_H */
arch/lib/include/asm/ptrace.h new file +4 -0
new file mode 100644
index 0000000..ddd9708
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_PTRACE_H
+#define _ASM_SIM_PTRACE_H
+
+#endif /* _ASM_SIM_PTRACE_H */
arch/lib/include/asm/segment.h new file +6 -0
new file mode 100644
index 0000000..e056922
@@ -0,0 +1,6 @@
+#ifndef _ASM_SIM_SEGMENT_H
+#define _ASM_SIM_SEGMENT_H
+
+typedef struct { int seg; } mm_segment_t;
+
+#endif /* _ASM_SIM_SEGMENT_H */
arch/lib/include/asm/sembuf.h new file +4 -0
new file mode 100644
index 0000000..d64927b
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_SEMBUF_H
+#define _ASM_SIM_SEMBUF_H
+
+#endif /* _ASM_SIM_SEMBUF_H */
arch/lib/include/asm/shmbuf.h new file +4 -0
new file mode 100644
index 0000000..42d0a71
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_SHMBUF_H
+#define _ASM_SIM_SHMBUF_H
+
+#endif /* _ASM_SIM_SHMBUF_H */
arch/lib/include/asm/shmparam.h new file +4 -0
new file mode 100644
index 0000000..3410f1b
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_SHMPARAM_H
+#define _ASM_SIM_SHMPARAM_H
+
+#endif /* _ASM_SIM_SHMPARAM_H */
arch/lib/include/asm/sigcontext.h new file +6 -0
new file mode 100644
index 0000000..230b4b5
@@ -0,0 +1,6 @@
+#ifndef _ASM_SIM_SIGCONTEXT_H
+#define _ASM_SIM_SIGCONTEXT_H
+
+struct sigcontext {};
+
+#endif /* _ASM_SIM_SIGCONTEXT_H */
arch/lib/include/asm/stat.h new file +4 -0
new file mode 100644
index 0000000..80fa2cb
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_STAT_H
+#define _ASM_SIM_STAT_H
+
+#endif /* _ASM_SIM_STAT_H */
arch/lib/include/asm/statfs.h new file +4 -0
new file mode 100644
index 0000000..881ce51
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_STATFS_H
+#define _ASM_SIM_STATFS_H
+
+#endif /* _ASM_SIM_STATFS_H */
arch/lib/include/asm/swab.h new file +7 -0
new file mode 100644
index 0000000..d81376a
@@ -0,0 +1,7 @@
+#ifndef _ASM_SIM_SWAB_H
+#define _ASM_SIM_SWAB_H
+
+#include <linux/types.h>
+
+
+#endif /* _ASM_SIM_SWAB_H */
arch/lib/include/asm/thread_info.h new file +36 -0
new file mode 100644
index 0000000..ec316c6
@@ -0,0 +1,36 @@
+#ifndef _ASM_SIM_THREAD_INFO_H
+#define _ASM_SIM_THREAD_INFO_H
+
+#define TIF_NEED_RESCHED 1
+#define TIF_SIGPENDING 2
+#define TIF_MEMDIE 5
+
+struct thread_info {
+	__u32 flags;
+	int preempt_count;
+	struct task_struct *task;
+	struct restart_block restart_block;
+};
+
+struct thread_info *current_thread_info(void);
+struct thread_info *alloc_thread_info(struct task_struct *task);
+void free_thread_info(struct thread_info *ti);
+
+#define TS_RESTORE_SIGMASK      0x0008  /* restore signal mask in do_signal() */
+#define HAVE_SET_RESTORE_SIGMASK        1
+static inline void set_restore_sigmask(void)
+{
+}
+static inline void clear_restore_sigmask(void)
+{
+}
+static inline bool test_restore_sigmask(void)
+{
+	return true;
+}
+static inline bool test_and_clear_restore_sigmask(void)
+{
+	return true;
+}
+
+#endif /* _ASM_SIM_THREAD_INFO_H */
arch/lib/include/asm/uaccess.h new file +14 -0
new file mode 100644
index 0000000..74f973b
@@ -0,0 +1,14 @@
+#ifndef _ASM_SIM_UACCESS_H
+#define _ASM_SIM_UACCESS_H
+
+#define KERNEL_DS ((mm_segment_t) {0 })
+#define USER_DS ((mm_segment_t) {0 })
+#define get_fs() KERNEL_DS
+#define get_ds() USER_DS
+#define set_fs(x) do {} while ((x.seg) != (x.seg))
+
+#define __access_ok(addr, size) (1)
+
+#include <asm-generic/uaccess.h>
+
+#endif /* _ASM_SIM_UACCESS_H */
arch/lib/include/asm/unistd.h new file +4 -0
new file mode 100644
index 0000000..6b482b4
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_UNISTD_H
+#define _ASM_SIM_UNISTD_H
+
+#endif /* _ASM_SIM_UNISTD_H */
arch/lib/include/uapi/asm/byteorder.h new file +6 -0
new file mode 100644
index 0000000..b13a7a8
@@ -0,0 +1,6 @@
+#ifndef _ASM_X86_BYTEORDER_H
+#define _ASM_X86_BYTEORDER_H
+
+#include <linux/byteorder/little_endian.h>
+
+#endif /* _ASM_X86_BYTEORDER_H */
Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#104 lore raw

PATCH v5 9/10 lib: libos build scripts and documentation

In reply to Hajime Tazaki

document and build scripts for libos architecture.

---
 Documentation/virtual/libos-howto.txt | 144 ++++++++
 MAINTAINERS                           |   9 +
 arch/lib/.gitignore                   |   3 +
 arch/lib/Kconfig                      | 124 +++++++
 arch/lib/Makefile                     | 224 ++++++++++++
 arch/lib/Makefile.print               |  45 +++
 arch/lib/defconfig                    | 653 ++++++++++++++++++++++++++++++++++
 arch/lib/generate-linker-script.py    |  50 +++
 8 files changed, 1252 insertions(+)
 create mode 100644 Documentation/virtual/libos-howto.txt
 create mode 100644 arch/lib/.gitignore
 create mode 100644 arch/lib/Kconfig
 create mode 100644 arch/lib/Makefile
 create mode 100644 arch/lib/Makefile.print
 create mode 100644 arch/lib/defconfig
 create mode 100755 arch/lib/generate-linker-script.py
Documentation/virtual/libos-howto.txt new file +144 -0
new file mode 100644
index 0000000..fbf7946
@@ -0,0 +1,144 @@
+Library operating system (libos) version of Linux
+=================================================
+
+* Overview
+
+New hardware independent architecture 'arch/lib', configured by
+CONFIG_LIB gives you two features.
+
+- network stack in userspace (NUSE)
+  NUSE will give you a personalized network stack for each application
+  without replacing host operating system.
+
+- network simulator integration, which is called Direct Code Execution (DCE)
+  DCE will give us a network simulation environment with Linux network stack
+  to investigate the detail behavior protocol implementation with a flexible
+  network configuration. This is also useful for the testing environment.
+
+(- more abstracted implementation of underlying platform will be a future
+   direction (e.g., rump hypercall))
+
+In both features, Linux kernel network stack is running on top of
+userspace application with a linked or dynamically loaded library.
+
+They have their own, isolated network stack from host operating system
+so they are configured different IP addresses as other virtualization
+methods do.
+
+
+* How different with others ?
+
+- User-mode Linux (UML)
+
+UML is a way to execute Linux kernel code as a userspace
+application. It is completely isolated from host kernel but can host
+arbitrary userspace applications on top of UML.
+
+- namespace / container
+
+Container technologies with namespace brings a process-level isolation
+to host multiple network entities but shares the kernel among
+processes, which prevents to introduce new features implemented in
+kernel space.
+
+
+* How to build it ?
+
+configuration of arch/lib follows a standard configuration of kernel.
+
+ make defconfig ARCH=lib
+
+or
+
+ make menuconfig ARCH=lib
+
+then you can build a set of libraries for libos.
+
+ make library ARCH=lib
+
+This will give you a shared library file liblinux-$(KERNELVERSION).so
+in the top directory.
+
+* Hello world
+
+you may first need to configure a configuration file, named
+'nuse.conf' so that the library version of network stack can know what
+kind of IP configuration should be used. There is an example file
+at arch/lib/nuse.conf.sample: you may copy and modify it for your purpose.
+
+ sudo NUSECONF=nuse.conf ./nuse ping www.google.com
+
+
+
+* Example use cases
+- regression test with Direct Code Execution (DCE)
+
+'make test' by DCE gives a test platform for networking code, with the
+help of network simulator facilities like link delay/bandwidth/drop
+configurations, large network topology with userspace routing protocol
+daemons, etc.
+
+An interesting feature is the determinism of any test executions. A
+test script always gives same results in every execution if there is
+no modification on test target code.
+
+For the first step, you need to obtain network simulator
+environment. 'make testbin' does all the stuff for the preparation.
+
+% make testbin -C tools/testing/libos
+
+Then, you can 'make test' for your code.
+
+% make test ARCH=lib
+
+ PASS: TestSuite netlink-socket
+ PASS: TestSuite process-manager
+ PASS: TestSuite dce-cradle
+ PASS: TestSuite dce-mptcp
+ PASS: TestSuite dce-umip
+ PASS: TestSuite dce-quagga
+ PASS: Example dce-tcp-simple
+ PASS: Example dce-udp-simple
+
+
+- userspace network stack (NUSE)
+
+an application can use its own network stack, distinct from host network stack
+in order to personalize any network feature to the application specific one.
+The 'nuse' wrapper script, based on LD_PRELOAD technique, carefully replaces
+socket API and redirects system calls to the network stack library, provided by
+this framework.
+
+the network stack can be used with any kind of raw-socket like
+technologies such as Intel DPDK, netmap, etc.
+
+
+
+* Files / External Repository
+
+The kernel source tree (i.e., arch/lib) only contains a shared part of
+applications (NUSE/DCE). Pure userspace part is managed at a different
+repository, called Linux-libos-tools: it is automatically downloaded
+during make library.
+
+ https://github.com/libos-nuse/linux-libos-tools
+
+
+* More information
+- [email protected] (LibOS in general and NUSE related questions)
+- [email protected] (ns-3 related questions)
+- articles, slides
+ Experimentation Tools for Networking Research (Lacage, 2010)
+   http://cutebugs.net/files/thesis.pdf
+ Direct code execution: revisiting library OS architecture for reproducible
+  network experiments (Tazaki et al., 2013)
+   http://dx.doi.org/10.1145/2535372.2535374
+ Library Operating System with Mainline Linux Network Stack (Tazaki et al., 2015)
+   https://www.netdev01.org/docs/netdev01-tazaki-libos.pdf (slides)
+
+
+* Authors
+ Mathieu Lacage <[email protected]>
+ Hajime Tazaki <[email protected]>
+ Frederic Urbani <[email protected]>
+ Ryo Nakamura <[email protected]>
MAINTAINERS +9 -0
index 590304b..895c55f 100644
@@ -5912,6 +5912,15 @@ M:	Sasha Levin <[email protected]>
 S:	Maintained
 F:	tools/lib/lockdep/
 
+LIBRARY OS (LIBOS)
+M:	Hajime Tazaki <[email protected]>
+L:	[email protected]
+W:	http://libos-nuse.github.io/
+S:	Maintained
+F:	Documentation/virtual/libos-howto.txt
+F:	arch/lib/
+F:	tools/testing/libos/
+
 LINUX FOR IBM pSERIES (RS/6000)
 M:	Paul Mackerras <[email protected]>
 W:	http://www.ibm.com/linux/ltc/projects/ppc
arch/lib/.gitignore new file +3 -0
new file mode 100644
index 0000000..4370d48
@@ -0,0 +1,3 @@
+linker.lds
+objs.mk
+tools
arch/lib/Kconfig new file +124 -0

125 lines not on this page · raw message

arch/lib/Makefile new file +224 -0

224 lines not on this page · raw message

arch/lib/Makefile.print new file +45 -0

45 lines not on this page · raw message

arch/lib/defconfig new file +653 -0

653 lines not on this page · raw message

arch/lib/generate-linker-script.py new file +50 -0

50 lines not on this page · raw message

Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#105 lore raw

PATCH v5 10/10 lib: tools used for test scripts

In reply to Hajime Tazaki

These auxiliary files are used for testing and debugging of net/ code with libos. a simple test is implemented with make test ARCH=lib.

---
 tools/testing/libos/.gitignore   |  6 +++++
 tools/testing/libos/Makefile     | 38 +++++++++++++++++++++++++++
 tools/testing/libos/README       | 15 +++++++++++
 tools/testing/libos/bisect.sh    | 10 +++++++
 tools/testing/libos/dce-test.sh  | 23 ++++++++++++++++
 tools/testing/libos/nuse-test.sh | 57 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 149 insertions(+)
 create mode 100644 tools/testing/libos/.gitignore
 create mode 100644 tools/testing/libos/Makefile
 create mode 100644 tools/testing/libos/README
 create mode 100755 tools/testing/libos/bisect.sh
 create mode 100755 tools/testing/libos/dce-test.sh
 create mode 100755 tools/testing/libos/nuse-test.sh
tools/testing/libos/.gitignore new file +6 -0
new file mode 100644
index 0000000..57a74a0
@@ -0,0 +1,6 @@
+*.pcap
+files-*
+bake
+buildtop
+core
+exitprocs
tools/testing/libos/Makefile new file +38 -0
new file mode 100644
index 0000000..3da25429
@@ -0,0 +1,38 @@
+ADD_PARAM?=
+
+all: test
+
+bake:
+	hg clone http://code.nsnam.org/bake
+
+check_pkgs:
+	@./bake/bake.py check | grep Bazaar | grep OK || (echo "bzr is missing" && ./bake/bake.py check)
+	@./bake/bake.py check | grep autoreconf | grep OK || (echo "autotools is missing" && ./bake/bake.py check && exit 1)
+
+testbin: bake check_pkgs
+	@cp ../../../arch/lib/tools/bakeconf-linux.xml bake/bakeconf.xml
+	@mkdir -p buildtop/build/bin_dce
+	cd buildtop ; \
+	../bake/bake.py configure -e dce-linux-inkernel $(BAKECONF_PARAMS)
+	cd buildtop ; \
+	../bake/bake.py show --enabledTree | grep -v  -E "pygoocanvas|graphviz|python-dev" | grep Missing && (echo "required packages are missing") || echo ""
+	cd buildtop ; \
+	../bake/bake.py download ; \
+	../bake/bake.py update ; \
+	../bake/bake.py build
+
+test:
+	@./dce-test.sh ADD_PARAM=$(ADD_PARAM)
+
+test-valgrind:
+	@./dce-test.sh -g ADD_PARAM=$(ADD_PARAM)
+
+test-fault-injection:
+	@./dce-test.sh -f ADD_PARAM=$(ADD_PARAM)
+
+clean:
+#	@rm -rf buildtop
+	@rm -f *.pcap
+	@rm -rf files-*
+	@rm -f exitprocs
+	@rm -f core
tools/testing/libos/README new file +15 -0
new file mode 100644
index 0000000..51ac5a5
@@ -0,0 +1,15 @@
+
+- bisect.sh
+a sample script to bisect an issue of network stack code with the help
+of LibOS (and ns-3 network simulator). This was used to detect the issue
+for the following patch.
+
+http://patchwork.ozlabs.org/patch/436351/
+
+- dce-test.sh
+a test script invoked by 'make test ARCH=lib'. The contents of test
+scenario are implemented as test suites of ns-3 network simulator.
+
+- nuse-test.sh
+a simple test script for Network Stack in Userspace (NUSE).
+
tools/testing/libos/bisect.sh new file +10 -0
new file mode 100755
index 0000000..9377ac3
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+git merge origin/nuse --no-commit
+make clean ARCH=lib
+make library ARCH=lib OPT=no
+make test ARCH=lib ADD_PARAM=" -s dce-umip"
+RET=$?
+git reset --hard
+
+exit $RET
tools/testing/libos/dce-test.sh new file +23 -0
new file mode 100755
index 0000000..e81e2d8
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+set -e
+#set -x
+export LD_LOG=symbol-fail
+#VERBOSE="-v"
+VALGRIND=""
+FAULT_INJECTION=""
+
+if [ "$1" = "-g" ] ; then
+ VALGRIND="-g"
+# Not implemneted yet.
+#elif [ "$1" = "-f" ] ; then
+# FAULT_INJECTION="-f"
+fi
+
+# FIXME
+#export NS_ATTRIBUTE_DEFAULT='ns3::DceManagerHelper::LoaderFactory=ns3::\
+#DlmLoaderFactory[];ns3::TaskManager::FiberManagerType=UcontextFiberManager'
+
+cd buildtop/source/ns-3-dce
+LD_LIBRARY_PATH=${srctree} ./test.py -n ${VALGRIND} ${FAULT_INJECTION}\
+	   ${VERBOSE} ${ADD_PARAM}
tools/testing/libos/nuse-test.sh new file +57 -0

57 lines not on this page · raw message

Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#106 lore raw

v6 cover an introduction of Linux library operating system (LibOS)

In reply to Hajime Tazaki

Although I've been kept quiet, I'm preparing this 6th version of Linux LibOS patchset.

During the time, I've observed the growth of our branch and seen two good news regarding the maintenance overhead and benefit of libos patches.

* news 1

To answer the following suggestion raised by Richard Weinberger, I've observed the maintenance burden (manual modification, follow stub function signature, etc) which we were worried about.

Quoted 11 lines

I'd suggest the following:
Maintain LibOS in your git tree and follow Linus' tree. Make sure that all kernel releases build and work.

This way you can experiment with automation and other stuff. If it works well you can ask for mainline inclusion after a few kernel releases.

Your git history will show how much maintenance burden LibOS has and how much with every merge window breaks and needs manual fixup.

here is the list of commits which I updated stub functions since around 4.0 release. As I mentioned, each of stub functions updates are mostly happened during merge window and those are 2 to 5. We may see similar numbers in coming the 4.3 version.

4.1-4.2
- 2000c14 lib: fix the signature of vfs_caches_init() (4.2-rc6)
- 576b8d7 lib: fix new proc behavior for emulated proc files (4.2-rc1)
- b72596c lib: fix workqueue stub for new header (4.2-rc1)
- 06289a2 merge conflicts (MAINTAINERS) (4.2-rc1)
- 12c0b79 lib: fix new signature of struct timer_list (4.2-rc0) 4.0-4.1
- acbf6ed lib: fix __ktime_divns() to latest update (4.1-rc7)
- 0fe9ba4 lib: merge fix from net-next around 4.0.0-next (4.1-rc0)
- 070691d lib: fix new sock_sendmsg() API (4.1-rc0) 3.19-4.0
- 609d8c7 lib: adapt linux-4.0.0-rc7
- 796347a lib: adapt linux-4.0.0-rc5

the full list of commit history can be found below, which also includes other commits of libos enhancements.

https://github.com/libos-nuse/net-next-nuse/commits/master?author=thehajime

Considering the number of commits in Linus tree since v4.0 to now (4.2+) is around 29K, I think the number of stubs update (in libos) is not that big matter.

I believe saying something with the-number-of-commits makes almost zero sense, but will help to smell something a bit.

I would like to hear your honest opinions.

* news 2
on the other hand, I also have a good news which libos has detected a couple of regressions in net-next tree.

- [net-next,v2] ipv6: Do not iterate over all interfaces when finding source address on specific interface. (v4.2-rc0) patchwork:
http://patchwork.ozlabs.org/patch/493675/
detected by:
http://ns-3-dce.cloud.wide.ad.jp/jenkins/job/daily-net-next-sim/958/

- [v3] ipv6: Fix protocol resubmission (v4.1-rc7)
patchwork:
http://patchwork.ozlabs.org/patch/482645/
detected by:
http://ns-3-dce.cloud.wide.ad.jp/jenkins/job/umip-net-next/716/

- [net-next] ipv6: Check RTF_LOCAL on rt->rt6i_flags instead of rt->dst.flags patchwork:
http://patchwork.ozlabs.org/patch/467447/
detected by:
http://ns-3-dce.cloud.wide.ad.jp/jenkins/job/daily-net-next-sim/878/

- [net-next] xfrm6: Fix a offset value for network header in _decode_session6 (v3.19-rc7?) patchwork:
http://patchwork.ozlabs.org/patch/436351/

some of detected bugs with other tests like kbuild test robot are not
included: above bugs purely require real and (sometimes) complex setup, which DCE (libos) eases with the virtualized environment.

changes from v5:
- Patch 09/10 ("lib: libos build scripts and documentation")
1) introduce symbol namespace for the symbols in Linux libos to avoid conflicts
- Patch 04/10 ("lib: time handling (kernel glue code)")
2) lib: un-stub timekeeping code and reuse timekeeping.c and co.
- Overall
3) rebased to Linux 4.2+ (revision 1e1a4e8f439113b7820bc7150569f685e1cc2b43)

changes from v4:
- Patch 09/10 ("lib: libos build scripts and documentation")
1) lib: fix dependency detection of kernel/time/timeconst.h (commented by Richard Weinberger)
- Overall
2) rebased to Linux 4.1-rc3 (4cfceaf0c087f47033f5e61a801f4136d6fb68c6)

changes from v3:
- Patch 09/10 ("lib: libos build scripts and documentation")
1) Remove RFC (now it's a proposal)
2) build environment cleanup (commented by Paul Bolle)
- Overall
3) change based tree from arnd/asm-generic to torvalds/linux.git (commented by Richard Weinberger)
4) rebased to Linux 4.1-rc1 (b787f68c36d49bb1d9236f403813641efa74a031)
5) change the title of cover letter a bit

changes from v2:
- Patch 02/11 ("slab: add private memory allocator header for arch/lib")
1) add new allocator named SLIB (Library Allocator): Patch 04/11 is integrated to 02 (commented by Christoph Lameter)
- Overall
2) rewrite commit log messages

changes from v1:
- Patch 01/11 ("sysctl: make some functions unstatic to access by arch/lib"):
1) add prefix ctl_table_ to newly publiced functions (commented by Joe Perches)
- Patch 08/11 ("lib: other kernel glue layer code"):
2) significantly reduce glue codes (stubs) (commented by Richard Weinberger)
- Others
3) adapt to linux-4.0.0
4) detect make dependency by Kbuild .cmd files

patchset history
-----------------
[v5] : https://lkml.org/lkml/2015/5/13/25
[v4] : https://lkml.org/lkml/2015/4/26/279
[v3] : https://lkml.org/lkml/2015/4/19/63
[v2] : https://lkml.org/lkml/2015/4/17/140
[v1] : https://lkml.org/lkml/2015/3/24/254

This is an introduction of Linux library operating system (LibOS).

Our objective is to build the kernel network stack as a shared library that can be linked to by userspace programs to provide network stack personality and testing facilities, and allow researchers to more easily simulate complex network topologies of linux routers/hosts.

Although the architecture itself can virtualize various things, the current design only focuses on the network stack. You can benefit network stack feature such as TCP, UDP, SCTP, DCCP (IPv4 and IPv6), Mobie IPv6, Multipath TCP (IPv4/IPv6, out-of-tree at the present moment), and netlink with various userspace applications (quagga, iproute2, iperf, wget, and thttpd).

== What is LibOS ? ==

The library exposes an entry point as an API, which is lib_init(), in order to connect userspace applications to the (userspace-version) kernel network stack. The clock source, virtual struct net_device, and scheduler are provided by caller while kernel resource like system calls is provided by callee.

Once the LibOS is initialized via the API, userspace applications with POSIX socket can use the system calls defined in LibOS by replacing from the original socket-related symbols to the LibOS-specific one. Then application can benefit the network stack of LibOS without involving the host network stack.

Currently, there are two users of LibOS: Network Stack in Userspace (NUSE) and ns-3 network simulatior with Direct Code Execution (DCE). These codes are managed at an external repository(*1).

== How to use it ? ==

to build the library,
% make {defconfig,menuconfig} ARCH=lib

then, build it.
% make library ARCH=lib

You will see liblinux-$(KERNELVERSION).so in the top directory.

== More information ==

The crucial difference between UML (user-mode linux) and this approach is that we allow multiple network stack instances to co-exist within a single process with dlmopen(3) like linking for easy debugging.

These patches are also available on this branch:

git://github.com/libos-nuse/net-next-nuse.git for-linus-upstream-libos-v6

For further information, here is a slideset presented at the last netdev0.1 conference.

http://www.slideshare.net/hajimetazaki/library-operating-system-for-linux-netdev01

I would appreciate any kind of your feedback regarding to upstream this feature.

*1 https://github.com/libos-nuse/linux-libos-tools

Hajime Tazaki (10):
sysctl: make some functions unstatic to access by arch/lib
slab: add SLIB (Library memory allocator) for arch/lib
lib: public headers and API implementations for userspace programs
lib: time handling (kernel glue code)
lib: context and scheduling functions (kernel glue code) for libos
lib: sysctl handling (kernel glue code)
lib: other kernel glue layer code
lib: auxiliary files for auto-generated asm-generic files of libos
lib: libos build scripts and documentation
lib: tools used for test scripts

 Documentation/virtual/libos-howto.txt | 144 ++++++++
 MAINTAINERS                           |   9 +
 arch/lib/.gitignore                   |   3 +
 arch/lib/Kconfig                      | 124 +++++++
 arch/lib/Makefile                     | 235 ++++++++++++
 arch/lib/Makefile.print               |  45 +++
 arch/lib/capability.c                 |  25 ++
 arch/lib/defconfig                    | 655 ++++++++++++++++++++++++++++++++++
 arch/lib/filemap.c                    |  32 ++
 arch/lib/fs.c                         |  70 ++++
 arch/lib/generate-linker-script.py    |  50 +++
 arch/lib/glue.c                       | 284 +++++++++++++++
 arch/lib/hrtimer.c                    | 117 ++++++
 arch/lib/include/asm/Kbuild           |  57 +++
 arch/lib/include/asm/atomic.h         |  62 ++++
 arch/lib/include/asm/barrier.h        |   8 +
 arch/lib/include/asm/bitsperlong.h    |  16 +
 arch/lib/include/asm/current.h        |   7 +
 arch/lib/include/asm/elf.h            |  10 +
 arch/lib/include/asm/hardirq.h        |   8 +
 arch/lib/include/asm/page.h           |  14 +
 arch/lib/include/asm/pgtable.h        |  30 ++
 arch/lib/include/asm/processor.h      |  19 +
 arch/lib/include/asm/ptrace.h         |   4 +
 arch/lib/include/asm/segment.h        |   6 +
 arch/lib/include/asm/sembuf.h         |   4 +
 arch/lib/include/asm/shmbuf.h         |   4 +
 arch/lib/include/asm/shmparam.h       |   4 +
 arch/lib/include/asm/sigcontext.h     |   6 +
 arch/lib/include/asm/stat.h           |   4 +
 arch/lib/include/asm/statfs.h         |   4 +
 arch/lib/include/asm/swab.h           |   7 +
 arch/lib/include/asm/thread_info.h    |  36 ++
 arch/lib/include/asm/uaccess.h        |  14 +
 arch/lib/include/asm/unistd.h         |   4 +
 arch/lib/include/sim-assert.h         |  23 ++
 arch/lib/include/sim-init.h           | 134 +++++++
 arch/lib/include/sim-printf.h         |  13 +
 arch/lib/include/sim-types.h          |  53 +++
 arch/lib/include/sim.h                |  51 +++
 arch/lib/include/uapi/asm/byteorder.h |   6 +
 arch/lib/lib-device.c                 | 187 ++++++++++
 arch/lib/lib-socket.c                 | 370 +++++++++++++++++++
 arch/lib/lib.c                        | 296 +++++++++++++++
 arch/lib/lib.h                        |  21 ++
 arch/lib/modules.c                    |  36 ++
 arch/lib/pid.c                        |  29 ++
 arch/lib/print.c                      |  56 +++
 arch/lib/proc.c                       |  36 ++
 arch/lib/random.c                     |  54 +++
 arch/lib/sched.c                      | 406 +++++++++++++++++++++
 arch/lib/softirq.c                    | 108 ++++++
 arch/lib/sysctl.c                     | 270 ++++++++++++++
 arch/lib/sysfs.c                      |  83 +++++
 arch/lib/tasklet-hrtimer.c            |  57 +++
 arch/lib/tasklet.c                    |  76 ++++
 arch/lib/time.c                       | 116 ++++++
 arch/lib/timer.c                      | 299 ++++++++++++++++
 arch/lib/vmscan.c                     |  26 ++
 arch/lib/workqueue.c                  | 238 ++++++++++++
 fs/proc/proc_sysctl.c                 |  36 +-
 include/linux/slab.h                  |   6 +-
 include/linux/slib_def.h              |  21 ++
 mm/Makefile                           |   1 +
 mm/slab.h                             |   4 +
 mm/slib.c                             | 209 +++++++++++
 tools/testing/libos/.gitignore        |   6 +
 tools/testing/libos/Makefile          |  38 ++
 tools/testing/libos/README            |  15 +
 tools/testing/libos/bisect.sh         |  10 +
 tools/testing/libos/dce-test.sh       |  23 ++
 tools/testing/libos/nuse-test.sh      |  57 +++
 72 files changed, 5573 insertions(+), 18 deletions(-)
 create mode 100644 Documentation/virtual/libos-howto.txt
 create mode 100644 arch/lib/.gitignore
 create mode 100644 arch/lib/Kconfig
 create mode 100644 arch/lib/Makefile
 create mode 100644 arch/lib/Makefile.print
 create mode 100644 arch/lib/capability.c
 create mode 100644 arch/lib/defconfig
 create mode 100644 arch/lib/filemap.c
 create mode 100644 arch/lib/fs.c
 create mode 100755 arch/lib/generate-linker-script.py
 create mode 100644 arch/lib/glue.c
 create mode 100644 arch/lib/hrtimer.c
 create mode 100644 arch/lib/include/asm/Kbuild
 create mode 100644 arch/lib/include/asm/atomic.h
 create mode 100644 arch/lib/include/asm/barrier.h
 create mode 100644 arch/lib/include/asm/bitsperlong.h
 create mode 100644 arch/lib/include/asm/current.h
 create mode 100644 arch/lib/include/asm/elf.h
 create mode 100644 arch/lib/include/asm/hardirq.h
 create mode 100644 arch/lib/include/asm/page.h
 create mode 100644 arch/lib/include/asm/pgtable.h
 create mode 100644 arch/lib/include/asm/processor.h
 create mode 100644 arch/lib/include/asm/ptrace.h
 create mode 100644 arch/lib/include/asm/segment.h
 create mode 100644 arch/lib/include/asm/sembuf.h
 create mode 100644 arch/lib/include/asm/shmbuf.h
 create mode 100644 arch/lib/include/asm/shmparam.h
 create mode 100644 arch/lib/include/asm/sigcontext.h
 create mode 100644 arch/lib/include/asm/stat.h
 create mode 100644 arch/lib/include/asm/statfs.h
 create mode 100644 arch/lib/include/asm/swab.h
 create mode 100644 arch/lib/include/asm/thread_info.h
 create mode 100644 arch/lib/include/asm/uaccess.h
 create mode 100644 arch/lib/include/asm/unistd.h
 create mode 100644 arch/lib/include/sim-assert.h
 create mode 100644 arch/lib/include/sim-init.h
 create mode 100644 arch/lib/include/sim-printf.h
 create mode 100644 arch/lib/include/sim-types.h
 create mode 100644 arch/lib/include/sim.h
 create mode 100644 arch/lib/include/uapi/asm/byteorder.h
 create mode 100644 arch/lib/lib-device.c
 create mode 100644 arch/lib/lib-socket.c
 create mode 100644 arch/lib/lib.c
 create mode 100644 arch/lib/lib.h
 create mode 100644 arch/lib/modules.c
 create mode 100644 arch/lib/pid.c
 create mode 100644 arch/lib/print.c
 create mode 100644 arch/lib/proc.c
 create mode 100644 arch/lib/random.c
 create mode 100644 arch/lib/sched.c
 create mode 100644 arch/lib/softirq.c
 create mode 100644 arch/lib/sysctl.c
 create mode 100644 arch/lib/sysfs.c
 create mode 100644 arch/lib/tasklet-hrtimer.c
 create mode 100644 arch/lib/tasklet.c
 create mode 100644 arch/lib/time.c
 create mode 100644 arch/lib/timer.c
 create mode 100644 arch/lib/vmscan.c
 create mode 100644 arch/lib/workqueue.c
 create mode 100644 include/linux/slib_def.h
 create mode 100644 mm/slib.c
 create mode 100644 tools/testing/libos/.gitignore
 create mode 100644 tools/testing/libos/Makefile
 create mode 100644 tools/testing/libos/README
 create mode 100755 tools/testing/libos/bisect.sh
 create mode 100755 tools/testing/libos/dce-test.sh
 create mode 100755 tools/testing/libos/nuse-test.sh
Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#107 lore raw

PATCH v6 1/10 sysctl: make some functions unstatic to access by arch/lib

libos (arch/lib) emulates a sysctl-like interface by a function call of userspace by enumerating sysctl tree from sysctl_table_root. It requires to be publicly accessible to this symbol and related functions.

---
 fs/proc/proc_sysctl.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)
fs/proc/proc_sysctl.c +19 -17
index fdda62e6115e..e1003cf51d22 100644
@@ -57,7 +57,7 @@ static struct ctl_table root_table[] = {
 	},
 	{ }
 };
-static struct ctl_table_root sysctl_table_root = {
+struct ctl_table_root sysctl_table_root = {
 	.default_set.dir.header = {
 		{{.count = 1,
 		  .nreg = 1,
@@ -99,8 +99,9 @@ static int namecmp(const char *name1, int len1, const char *name2, int len2)
 }
 
 /* Called under sysctl_lock */
-static struct ctl_table *find_entry(struct ctl_table_header **phead,
-	struct ctl_dir *dir, const char *name, int namelen)
+struct ctl_table *ctl_table_find_entry(struct ctl_table_header **phead,
+				       struct ctl_dir *dir, const char *name,
+				       int namelen)
 {
 	struct ctl_table_header *head;
 	struct ctl_table *entry;
@@ -335,7 +336,7 @@ static struct ctl_table *lookup_entry(struct ctl_table_header **phead,
 	struct ctl_table *entry;
 
 	spin_lock(&sysctl_lock);
-	entry = find_entry(&head, dir, name, namelen);
+	entry = ctl_table_find_entry(&head, dir, name, namelen);
 	if (entry && use_table(head))
 		*phead = head;
 	else
@@ -356,7 +357,7 @@ static struct ctl_node *first_usable_entry(struct rb_node *node)
 	return NULL;
 }
 
-static void first_entry(struct ctl_dir *dir,
+void ctl_table_first_entry(struct ctl_dir *dir,
 	struct ctl_table_header **phead, struct ctl_table **pentry)
 {
 	struct ctl_table_header *head = NULL;
@@ -374,7 +375,7 @@ static void first_entry(struct ctl_dir *dir,
 	*pentry = entry;
 }
 
-static void next_entry(struct ctl_table_header **phead, struct ctl_table **pentry)
+void ctl_table_next_entry(struct ctl_table_header **phead, struct ctl_table **pentry)
 {
 	struct ctl_table_header *head = *phead;
 	struct ctl_table *entry = *pentry;
@@ -707,7 +708,8 @@ static int proc_sys_readdir(struct file *file, struct dir_context *ctx)
 
 	pos = 2;
 
-	for (first_entry(ctl_dir, &h, &entry); h; next_entry(&h, &entry)) {
+	for (ctl_table_first_entry(ctl_dir, &h, &entry); h;
+	     ctl_table_next_entry(&h, &entry)) {
 		if (!scan(h, entry, &pos, file, ctx)) {
 			sysctl_head_finish(h);
 			break;
@@ -865,7 +867,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
 	struct ctl_table_header *head;
 	struct ctl_table *entry;
 
-	entry = find_entry(&head, dir, name, namelen);
+	entry = ctl_table_find_entry(&head, dir, name, namelen);
 	if (!entry)
 		return ERR_PTR(-ENOENT);
 	if (!S_ISDIR(entry->mode))
@@ -961,13 +963,13 @@ failed:
 	return subdir;
 }
 
-static struct ctl_dir *xlate_dir(struct ctl_table_set *set, struct ctl_dir *dir)
+struct ctl_dir *ctl_table_xlate_dir(struct ctl_table_set *set, struct ctl_dir *dir)
 {
 	struct ctl_dir *parent;
 	const char *procname;
 	if (!dir->header.parent)
 		return &set->dir;
-	parent = xlate_dir(set, dir->header.parent);
+	parent = ctl_table_xlate_dir(set, dir->header.parent);
 	if (IS_ERR(parent))
 		return parent;
 	procname = dir->header.ctl_table[0].procname;
@@ -988,13 +990,13 @@ static int sysctl_follow_link(struct ctl_table_header **phead,
 	spin_lock(&sysctl_lock);
 	root = (*pentry)->data;
 	set = lookup_header_set(root, namespaces);
-	dir = xlate_dir(set, (*phead)->parent);
+	dir = ctl_table_xlate_dir(set, (*phead)->parent);
 	if (IS_ERR(dir))
 		ret = PTR_ERR(dir);
 	else {
 		const char *procname = (*pentry)->procname;
 		head = NULL;
-		entry = find_entry(&head, dir, procname, strlen(procname));
+		entry = ctl_table_find_entry(&head, dir, procname, strlen(procname));
 		ret = -ENOENT;
 		if (entry && use_table(head)) {
 			unuse_table(*phead);
@@ -1106,7 +1108,7 @@ static bool get_links(struct ctl_dir *dir,
 	/* Are there links available for every entry in table? */
 	for (entry = table; entry->procname; entry++) {
 		const char *procname = entry->procname;
-		link = find_entry(&head, dir, procname, strlen(procname));
+		link = ctl_table_find_entry(&head, dir, procname, strlen(procname));
 		if (!link)
 			return false;
 		if (S_ISDIR(link->mode) && S_ISDIR(entry->mode))
@@ -1119,7 +1121,7 @@ static bool get_links(struct ctl_dir *dir,
 	/* The checks passed.  Increase the registration count on the links */
 	for (entry = table; entry->procname; entry++) {
 		const char *procname = entry->procname;
-		link = find_entry(&head, dir, procname, strlen(procname));
+		link = ctl_table_find_entry(&head, dir, procname, strlen(procname));
 		head->nreg++;
 	}
 	return true;
@@ -1135,7 +1137,7 @@ static int insert_links(struct ctl_table_header *head)
 	if (head->set == root_set)
 		return 0;
 
-	core_parent = xlate_dir(root_set, head->parent);
+	core_parent = ctl_table_xlate_dir(root_set, head->parent);
 	if (IS_ERR(core_parent))
 		return 0;
 
@@ -1516,7 +1518,7 @@ static void put_links(struct ctl_table_header *header)
 	if (header->set == root_set)
 		return;
 
-	core_parent = xlate_dir(root_set, parent);
+	core_parent = ctl_table_xlate_dir(root_set, parent);
 	if (IS_ERR(core_parent))
 		return;
 
@@ -1525,7 +1527,7 @@ static void put_links(struct ctl_table_header *header)
 		struct ctl_table *link;
 		const char *name = entry->procname;
 
-		link = find_entry(&link_head, core_parent, name, strlen(name));
+		link = ctl_table_find_entry(&link_head, core_parent, name, strlen(name));
 		if (link &&
 		    ((S_ISDIR(link->mode) && S_ISDIR(entry->mode)) ||
 		     (S_ISLNK(link->mode) && (link->data == root)))) {
Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#108 lore raw

PATCH v6 2/10 slab: add SLIB (Library memory allocator) for arch/lib

In reply to Hajime Tazaki

add SLIB allocator for arch/lib (CONFIG_LIB) to wrap kmalloc and co. This will bring user's own allocator of libos: malloc(3) etc.

---
 include/linux/slab.h     |   6 +-
 include/linux/slib_def.h |  21 +++++
 mm/Makefile              |   1 +
 mm/slab.h                |   4 +
 mm/slib.c                | 209 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 240 insertions(+), 1 deletion(-)
 create mode 100644 include/linux/slib_def.h
 create mode 100644 mm/slib.c
include/linux/slab.h +5 -1
index a99f0e5243e1..104c1aeec560 100644
@@ -191,7 +191,7 @@ size_t ksize(const void *);
 #endif
 #endif
 
-#ifdef CONFIG_SLOB
+#if defined(CONFIG_SLOB) || defined(CONFIG_SLIB)
 /*
  * SLOB passes all requests larger than one page to the page allocator.
  * No kmalloc array is necessary since objects of different sizes can
@@ -356,6 +356,9 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
 }
 #endif
 
+#ifdef CONFIG_SLIB
+#include <linux/slib_def.h>
+#else
 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
 {
 	unsigned int order = get_order(size);
@@ -434,6 +437,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
 	}
 	return __kmalloc(size, flags);
 }
+#endif /* CONFIG_SLIB */
 
 /*
  * Determine size used for the nth kmalloc cache.
include/linux/slib_def.h new file +21 -0
new file mode 100644
index 000000000000..d9fe7d59bd4e
@@ -0,0 +1,21 @@
+#ifndef _LINUX_SLLB_DEF_H
+#define _LINUX_SLLB_DEF_H
+
+
+struct kmem_cache {
+	unsigned int object_size;
+	const char *name;
+	size_t size;
+	size_t align;
+	unsigned long flags;
+	void (*ctor)(void *);
+};
+
+void *__kmalloc(size_t size, gfp_t flags);
+void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
+static __always_inline void *kmalloc(size_t size, gfp_t flags)
+{
+	return __kmalloc(size, flags);
+}
+
+#endif /* _LINUX_SLLB_DEF_H */
mm/Makefile +1 -0
index 98c4eaeabdcb..7d8314f95ce3 100644
@@ -46,6 +46,7 @@ obj-$(CONFIG_NUMA) 	+= mempolicy.o
 obj-$(CONFIG_SPARSEMEM)	+= sparse.o
 obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o
 obj-$(CONFIG_SLOB) += slob.o
+obj-$(CONFIG_SLIB) += slib.o
 obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o
 obj-$(CONFIG_KSM) += ksm.o
 obj-$(CONFIG_PAGE_POISONING) += debug-pagealloc.o
mm/slab.h +4 -0
index 8da63e4e470f..2cf4f0f67a19 100644
@@ -37,6 +37,10 @@ struct kmem_cache {
 #include <linux/slub_def.h>
 #endif
 
+#ifdef CONFIG_SLIB
+#include <linux/slib_def.h>
+#endif
+
 #include <linux/memcontrol.h>
 
 /*
mm/slib.c new file +209 -0

209 lines not on this page · raw message

Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#109 lore raw

PATCH v6 3/10 lib: public headers and API implementations for userspace programs

In reply to Hajime Tazaki

userspace programs which uses libos access via a public API, lib_init(), with passed arguments struct SimImported and struct SimExported.

---
 arch/lib/include/sim-assert.h |  23 +++
 arch/lib/include/sim-init.h   | 134 +++++++++++++++
 arch/lib/include/sim-printf.h |  13 ++
 arch/lib/include/sim-types.h  |  53 ++++++
 arch/lib/include/sim.h        |  51 ++++++
 arch/lib/lib-device.c         | 187 +++++++++++++++++++++
 arch/lib/lib-socket.c         | 370 ++++++++++++++++++++++++++++++++++++++++++
 arch/lib/lib.c                | 296 +++++++++++++++++++++++++++++++++
 arch/lib/lib.h                |  21 +++
 9 files changed, 1148 insertions(+)
 create mode 100644 arch/lib/include/sim-assert.h
 create mode 100644 arch/lib/include/sim-init.h
 create mode 100644 arch/lib/include/sim-printf.h
 create mode 100644 arch/lib/include/sim-types.h
 create mode 100644 arch/lib/include/sim.h
 create mode 100644 arch/lib/lib-device.c
 create mode 100644 arch/lib/lib-socket.c
 create mode 100644 arch/lib/lib.c
 create mode 100644 arch/lib/lib.h
arch/lib/include/sim-assert.h new file +23 -0
new file mode 100644
index 000000000000..974122c3a0f1
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#ifndef SIM_ASSERT_H
+#define SIM_ASSERT_H
+
+#include "sim-printf.h"
+
+#define lib_assert(v) {							\
+		while (!(v)) {						\
+			lib_printf("Assert failed %s:%u \"" #v "\"\n",	\
+				__FILE__, __LINE__);			\
+			char *p = 0;					\
+			*p = 1;						\
+		}							\
+	}
+
+
+#endif /* SIM_ASSERT_H */
arch/lib/include/sim-init.h new file +134 -0

134 lines not on this page · raw message

arch/lib/include/sim-printf.h new file +13 -0
new file mode 100644
index 000000000000..2bf82451cfa8
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#ifndef SIM_PRINTF_H
+#define SIM_PRINTF_H
+
+void lib_printf(const char *str, ...);
+
+#endif /* SIM_PRINTF_H */
arch/lib/include/sim-types.h new file +53 -0

53 lines not on this page · raw message

arch/lib/include/sim.h new file +51 -0

51 lines not on this page · raw message

arch/lib/lib-device.c new file +187 -0

187 lines not on this page · raw message

arch/lib/lib-socket.c new file +370 -0

370 lines not on this page · raw message

arch/lib/lib.c new file +296 -0

296 lines not on this page · raw message

arch/lib/lib.h new file +21 -0
new file mode 100644
index 000000000000..abf2a2628bb2
@@ -0,0 +1,21 @@
+/*
+ * library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ *         Frederic Urbani
+ */
+
+#ifndef LIB_H
+#define LIB_H
+
+#include <linux/sched.h>
+
+struct SimTask {
+	struct list_head head;
+	struct task_struct kernel_task;
+	void *private;
+};
+
+#endif /* LIB_H */
Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#110 lore raw

PATCH v6 4/10 lib: time handling (kernel glue code)

In reply to Hajime Tazaki

timer related (internal) functions such as add_timer(), do_gettimeofday() of kernel are trivially reimplemented
for libos. these eventually call the functions registered by lib_init() API.

---
 arch/lib/hrtimer.c         | 117 ++++++++++++++++++
 arch/lib/tasklet-hrtimer.c |  57 +++++++++
 arch/lib/time.c            | 116 ++++++++++++++++++
 arch/lib/timer.c           | 299 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 589 insertions(+)
 create mode 100644 arch/lib/hrtimer.c
 create mode 100644 arch/lib/tasklet-hrtimer.c
 create mode 100644 arch/lib/time.c
 create mode 100644 arch/lib/timer.c
arch/lib/hrtimer.c new file +117 -0
new file mode 100644
index 000000000000..6a99bad6c5b7
@@ -0,0 +1,117 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include <linux/hrtimer.h>
+#include "sim-assert.h"
+#include "sim.h"
+
+/**
+ * hrtimer_init - initialize a timer to the given clock
+ * @timer:      the timer to be initialized
+ * @clock_id:   the clock to be used
+ * @mode:       timer mode abs/rel
+ */
+void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
+		  enum hrtimer_mode mode)
+{
+	memset(timer, 0, sizeof(*timer));
+}
+static void trampoline(void *context)
+{
+	struct hrtimer *timer = context;
+	enum hrtimer_restart restart = timer->function(timer);
+
+	if (restart == HRTIMER_RESTART) {
+		void *event =
+			lib_event_schedule_ns(ktime_to_ns(timer->_softexpires),
+					      &trampoline, timer);
+		timer->base = event;
+	} else {
+		/* mark as completed. */
+		timer->base = 0;
+	}
+}
+/**
+ * hrtimer_start_range_ns - (re)start an hrtimer on the current CPU
+ * @timer:      the timer to be added
+ * @tim:        expiry time
+ * @delta_ns:   "slack" range for the timer
+ * @mode:       expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL)
+ *
+ * Returns:
+ *  0 on success
+ *  1 when the timer was active
+ */
+int __hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
+			     unsigned long delta_ns,
+			     const enum hrtimer_mode mode,
+			     int wakeup)
+{
+	int ret = hrtimer_cancel(timer);
+	s64 ns = ktime_to_ns(tim);
+	void *event;
+
+	if (mode == HRTIMER_MODE_ABS)
+		ns -= lib_current_ns();
+	timer->_softexpires = ns_to_ktime(ns);
+	event = lib_event_schedule_ns(ns, &trampoline, timer);
+	timer->base = event;
+	return ret;
+}
+/**
+ * hrtimer_try_to_cancel - try to deactivate a timer
+ * @timer:      hrtimer to stop
+ *
+ * Returns:
+ *  0 when the timer was not active
+ *  1 when the timer was active
+ * -1 when the timer is currently excuting the callback function and
+ *    cannot be stopped
+ */
+int hrtimer_try_to_cancel(struct hrtimer *timer)
+{
+	/* Note: we cannot return -1 from this function.
+	   see comment in hrtimer_cancel. */
+	if (timer->base == 0)
+		/* timer was not active yet */
+		return 1;
+	lib_event_cancel(timer->base);
+	timer->base = 0;
+	return 0;
+}
+/**
+ * hrtimer_cancel - cancel a timer and wait for the handler to finish.
+ * @timer:      the timer to be cancelled
+ *
+ * Returns:
+ *  0 when the timer was not active
+ *  1 when the timer was active
+ */
+int hrtimer_cancel(struct hrtimer *timer)
+{
+	/* Note: because we assume a uniprocessor non-interruptible */
+	/* system when running in the kernel, we know that the timer */
+	/* is not running when we execute this code, so, know that */
+	/* try_to_cancel cannot return -1 and we don't need to retry */
+	/* the cancel later to wait for the handler to finish. */
+	int ret = hrtimer_try_to_cancel(timer);
+
+	lib_assert(ret >= 0);
+	return ret;
+}
+void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
+			   unsigned long delta_ns, const enum hrtimer_mode mode)
+{
+	__hrtimer_start_range_ns(timer, tim, delta_ns, mode, 1);
+}
+
+int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp)
+{
+	*tp = ns_to_timespec(1);
+	return 0;
+}
arch/lib/tasklet-hrtimer.c new file +57 -0

57 lines not on this page · raw message

arch/lib/time.c new file +116 -0

116 lines not on this page · raw message

arch/lib/timer.c new file +299 -0

299 lines not on this page · raw message

Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#111 lore raw

PATCH v6 5/10 lib: context and scheduling functions (kernel glue code) for libos

In reply to Hajime Tazaki

context primitives of kernel such as soft interrupts, scheduling, tasklet are implemented for libos. these functions eventually call the functions registered by lib_init() API as well.

---
 arch/lib/sched.c     | 406 +++++++++++++++++++++++++++++++++++++++++++++++++++
 arch/lib/softirq.c   | 108 ++++++++++++++
 arch/lib/tasklet.c   |  76 ++++++++++
 arch/lib/workqueue.c | 238 ++++++++++++++++++++++++++++++
 4 files changed, 828 insertions(+)
 create mode 100644 arch/lib/sched.c
 create mode 100644 arch/lib/softirq.c
 create mode 100644 arch/lib/tasklet.c
 create mode 100644 arch/lib/workqueue.c
arch/lib/sched.c new file +406 -0
new file mode 100644
index 000000000000..98a568a16903
@@ -0,0 +1,406 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include <linux/wait.h>
+#include <linux/list.h>
+#include <linux/sched.h>
+#include <linux/nsproxy.h>
+#include <linux/hash.h>
+#include <net/net_namespace.h>
+#include "lib.h"
+#include "sim.h"
+#include "sim-assert.h"
+
+/**
+   called by wait_event macro:
+   - prepare_to_wait
+   - schedule
+   - finish_wait
+ */
+
+struct SimTask *lib_task_create(void *private, unsigned long pid)
+{
+	struct SimTask *task = lib_malloc(sizeof(struct SimTask));
+	struct cred *cred;
+	struct nsproxy *ns;
+	struct user_struct *user;
+	struct thread_info *info;
+	struct pid *kpid;
+
+	if (!task)
+		return NULL;
+	memset(task, 0, sizeof(struct SimTask));
+	cred = lib_malloc(sizeof(struct cred));
+	if (!cred)
+		return NULL;
+	/* XXX: we could optimize away this allocation by sharing it
+	   for all tasks */
+	ns = lib_malloc(sizeof(struct nsproxy));
+	if (!ns)
+		return NULL;
+	user = lib_malloc(sizeof(struct user_struct));
+	if (!user)
+		return NULL;
+	info = alloc_thread_info(&task->kernel_task);
+	if (!info)
+		return NULL;
+	kpid = lib_malloc(sizeof(struct pid));
+	if (!kpid)
+		return NULL;
+	kpid->numbers[0].nr = pid;
+	cred->fsuid = make_kuid(current_user_ns(), 0);
+	cred->fsgid = make_kgid(current_user_ns(), 0);
+	cred->user = user;
+	atomic_set(&cred->usage, 1);
+	info->task = &task->kernel_task;
+	info->preempt_count = 0;
+	info->flags = 0;
+	atomic_set(&ns->count, 1);
+	ns->uts_ns = 0;
+	ns->ipc_ns = 0;
+	ns->mnt_ns = 0;
+	ns->pid_ns_for_children = 0;
+	ns->net_ns = &init_net;
+	task->kernel_task.cred = cred;
+	task->kernel_task.pid = pid;
+	task->kernel_task.pids[PIDTYPE_PID].pid = kpid;
+	task->kernel_task.pids[PIDTYPE_PGID].pid = kpid;
+	task->kernel_task.pids[PIDTYPE_SID].pid = kpid;
+	task->kernel_task.nsproxy = ns;
+	task->kernel_task.stack = info;
+	/* this is a hack. */
+	task->kernel_task.group_leader = &task->kernel_task;
+	task->private = private;
+	return task;
+}
+void lib_task_destroy(struct SimTask *task)
+{
+	lib_free((void *)task->kernel_task.nsproxy);
+	lib_free((void *)task->kernel_task.cred);
+	lib_free((void *)task->kernel_task.cred->user);
+	free_thread_info(task->kernel_task.stack);
+	lib_free(task);
+}
+void *lib_task_get_private(struct SimTask *task)
+{
+	return task->private;
+}
+
+int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
+{
+	struct SimTask *task = lib_task_start((void (*)(void *))fn, arg);
+
+	return task->kernel_task.pid;
+}
+
+struct task_struct *get_current(void)
+{
+	struct SimTask *lib_task = lib_task_current();
+
+	return &lib_task->kernel_task;
+}
+
+struct thread_info *current_thread_info(void)
+{
+	return task_thread_info(get_current());
+}
+struct thread_info *alloc_thread_info(struct task_struct *task)
+{
+	return lib_malloc(sizeof(struct thread_info));
+}
+void free_thread_info(struct thread_info *ti)
+{
+	lib_free(ti);
+}
+
+
+void __put_task_struct(struct task_struct *t)
+{
+	lib_free(t);
+}
+
+void add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait)
+{
+	wait->flags &= ~WQ_FLAG_EXCLUSIVE;
+	list_add(&wait->task_list, &q->task_list);
+}
+void add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
+{
+	wait->flags |= WQ_FLAG_EXCLUSIVE;
+	list_add_tail(&wait->task_list, &q->task_list);
+}
+void remove_wait_queue(wait_queue_head_t *q, wait_queue_t *wait)
+{
+	if (wait->task_list.prev != LIST_POISON2)
+		list_del(&wait->task_list);
+}
+void
+prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state)
+{
+	wait->flags |= WQ_FLAG_EXCLUSIVE;
+	if (list_empty(&wait->task_list))
+		list_add_tail(&wait->task_list, &q->task_list);
+	set_current_state(state);
+}
+void prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state)
+{
+	unsigned long flags;
+
+	wait->flags &= ~WQ_FLAG_EXCLUSIVE;
+	spin_lock_irqsave(&q->lock, flags);
+	if (list_empty(&wait->task_list))
+		__add_wait_queue(q, wait);
+	set_current_state(state);
+	spin_unlock_irqrestore(&q->lock, flags);
+}
+void finish_wait(wait_queue_head_t *q, wait_queue_t *wait)
+{
+	set_current_state(TASK_RUNNING);
+	if (!list_empty(&wait->task_list))
+		list_del_init(&wait->task_list);
+}
+int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync,
+			     void *key)
+{
+	int ret = default_wake_function(wait, mode, sync, key);
+
+	if (ret && (wait->task_list.prev != LIST_POISON2))
+		list_del_init(&wait->task_list);
+
+	return ret;
+}
+
+int woken_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key)
+{
+	wait->flags |= WQ_FLAG_WOKEN;
+	return default_wake_function(wait, mode, sync, key);
+}
+
+void __init_waitqueue_head(wait_queue_head_t *q, const char *name,
+			   struct lock_class_key *k)
+{
+	INIT_LIST_HEAD(&q->task_list);
+}
+/**
+ * wait_for_completion: - waits for completion of a task
+ * @x:  holds the state of this particular completion
+ *
+ * This waits to be signaled for completion of a specific task. It is NOT
+ * interruptible and there is no timeout.
+ *
+ * See also similar routines (i.e. wait_for_completion_timeout()) with timeout
+ * and interrupt capability. Also see complete().
+ */
+void wait_for_completion(struct completion *x)
+{
+	wait_for_completion_timeout(x, MAX_SCHEDULE_TIMEOUT);
+}
+unsigned long wait_for_completion_timeout(struct completion *x,
+					  unsigned long timeout)
+{
+	if (!x->done) {
+		DECLARE_WAITQUEUE(wait, current);
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		wait.flags |= WQ_FLAG_EXCLUSIVE;
+		list_add_tail(&wait.task_list, &x->wait.task_list);
+		do
+			timeout = schedule_timeout(timeout);
+		while (!x->done && timeout);
+		if (wait.task_list.prev != LIST_POISON2)
+			list_del(&wait.task_list);
+
+		if (!x->done)
+			return timeout;
+	}
+	x->done--;
+	return timeout ? : 1;
+}
+
+/**
+ * __wake_up - wake up threads blocked on a waitqueue.
+ * @q: the waitqueue
+ * @mode: which threads
+ * @nr_exclusive: how many wake-one or wake-many threads to wake up
+ * @key: is directly passed to the wakeup function
+ *
+ * It may be assumed that this function implies a write memory barrier before
+ * changing the task state if and only if any tasks are woken up.
+ */
+void __wake_up(wait_queue_head_t *q, unsigned int mode,
+	       int nr_exclusive, void *key)
+{
+	wait_queue_t *curr, *next;
+
+	list_for_each_entry_safe(curr, next, &q->task_list, task_list) {
+		unsigned flags = curr->flags;
+
+		if (curr->func(curr, mode, 0, key) &&
+		    (flags & WQ_FLAG_EXCLUSIVE) &&
+		    !--nr_exclusive)
+			break;
+	}
+}
+void __wake_up_sync_key(wait_queue_head_t *q, unsigned int mode,
+			int nr_exclusive, void *key)
+{
+	__wake_up(q, mode, nr_exclusive, key);
+}
+int default_wake_function(wait_queue_t *curr, unsigned mode, int wake_flags,
+			  void *key)
+{
+	struct task_struct *task = (struct task_struct *)curr->private;
+	struct SimTask *lib_task = container_of(task, struct SimTask,
+						kernel_task);
+
+	return lib_task_wakeup(lib_task);
+}
+__sched int bit_wait(struct wait_bit_key *word)
+{
+	if (signal_pending_state(current->state, current))
+		return 1;
+	schedule();
+	return 0;
+}
+int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *arg)
+{
+	struct wait_bit_key *key = arg;
+	struct wait_bit_queue *wait_bit
+		= container_of(wait, struct wait_bit_queue, wait);
+
+	if (wait_bit->key.flags != key->flags ||
+			wait_bit->key.bit_nr != key->bit_nr ||
+			test_bit(key->bit_nr, key->flags))
+		return 0;
+	else
+		return autoremove_wake_function(wait, mode, sync, key);
+}
+void __wake_up_bit(wait_queue_head_t *wq, void *word, int bit)
+{
+	struct wait_bit_key key = __WAIT_BIT_KEY_INITIALIZER(word, bit);
+	if (waitqueue_active(wq))
+		__wake_up(wq, TASK_NORMAL, 1, &key);
+}
+void wake_up_bit(void *word, int bit)
+{
+	/* FIXME */
+	return;
+	__wake_up_bit(bit_waitqueue(word, bit), word, bit);
+}
+wait_queue_head_t *bit_waitqueue(void *word, int bit)
+{
+	const int shift = BITS_PER_LONG == 32 ? 5 : 6;
+	const struct zone *zone = page_zone(virt_to_page(word));
+	unsigned long val = (unsigned long)word << shift | bit;
+
+	return &zone->wait_table[hash_long(val, zone->wait_table_bits)];
+}
+
+
+void schedule(void)
+{
+	lib_task_wait();
+}
+
+static void trampoline(void *context)
+{
+	struct SimTask *task = context;
+
+	lib_task_wakeup(task);
+}
+
+signed long schedule_timeout(signed long timeout)
+{
+	u64 ns;
+	struct SimTask *self;
+
+	if (timeout == MAX_SCHEDULE_TIMEOUT) {
+		lib_task_wait();
+		return MAX_SCHEDULE_TIMEOUT;
+	}
+	lib_assert(timeout >= 0);
+	ns = ((__u64)timeout) * (1000000000 / HZ);
+	self = lib_task_current();
+	lib_event_schedule_ns(ns, &trampoline, self);
+	lib_task_wait();
+	/* we know that we are always perfectly on time. */
+	return 0;
+}
+
+signed long schedule_timeout_uninterruptible(signed long timeout)
+{
+	return schedule_timeout(timeout);
+}
+signed long schedule_timeout_interruptible(signed long timeout)
+{
+	return schedule_timeout(timeout);
+}
+
+void yield(void)
+{
+	lib_task_yield();
+}
+
+void complete_all(struct completion *x)
+{
+	x->done += UINT_MAX / 2;
+	__wake_up(&x->wait, TASK_NORMAL, 0, 0);
+}
+void complete(struct completion *x)
+{
+	x->done++;
+	__wake_up(&x->wait, TASK_NORMAL, 1, 0);
+}
+
+long wait_for_completion_interruptible_timeout(
+	struct completion *x, unsigned long timeout)
+{
+	return wait_for_completion_timeout(x, timeout);
+}
+int wait_for_completion_interruptible(struct completion *x)
+{
+	wait_for_completion_timeout(x, MAX_SCHEDULE_TIMEOUT);
+	return 0;
+}
+int wake_up_process(struct task_struct *tsk)
+{
+	struct SimTask *lib_task =
+		container_of(tsk, struct SimTask, kernel_task);
+
+	return lib_task_wakeup(lib_task);
+}
+int _cond_resched(void)
+{
+	/* we never schedule to decrease latency. */
+	return 0;
+}
+int idle_cpu(int cpu)
+{
+	/* we are never idle: we call this from rcutiny.c and the answer */
+	/* does not matter, really. */
+	return 0;
+}
+
+unsigned long long __attribute__((weak)) sched_clock(void)
+{
+	return (unsigned long long)(jiffies - INITIAL_JIFFIES)
+	       * (NSEC_PER_SEC / HZ);
+}
+
+u64 local_clock(void)
+{
+	return sched_clock();
+}
+
+void __sched schedule_preempt_disabled(void)
+{
+}
+
+void resched_cpu(int cpu)
+{
+	rcu_sched_qs();
+}
arch/lib/softirq.c new file +108 -0

108 lines not on this page · raw message

arch/lib/tasklet.c new file +76 -0

76 lines not on this page · raw message

arch/lib/workqueue.c new file +238 -0

238 lines not on this page · raw message

Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#112 lore raw

PATCH v6 6/10 lib: sysctl handling (kernel glue code)

In reply to Hajime Tazaki

This interacts with fs/proc_fs.c for sysctl-like interface registered via lib_init() API.

---
 arch/lib/sysctl.c | 270 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 270 insertions(+)
 create mode 100644 arch/lib/sysctl.c
arch/lib/sysctl.c new file +270 -0
new file mode 100644
index 000000000000..5f08f9f97103
@@ -0,0 +1,270 @@
+/*
+ * sysctl wrapper for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include <linux/mm.h>
+#include <linux/mmzone.h>
+#include <linux/mman.h>
+#include <linux/ratelimit.h>
+#include <linux/proc_fs.h>
+#include "sim-assert.h"
+#include "sim-types.h"
+
+int drop_caches_sysctl_handler(struct ctl_table *table, int write,
+			       void *buffer, size_t *length, loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int lowmem_reserve_ratio_sysctl_handler(struct ctl_table *table, int write,
+					void *buffer, size_t *length,
+					loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int min_free_kbytes_sysctl_handler(struct ctl_table *table, int write,
+				   void *buffer, size_t *length, loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+
+int percpu_pagelist_fraction_sysctl_handler(struct ctl_table *table, int write,
+					    void *buffer, size_t *length,
+					    loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int dirty_background_ratio_handler(struct ctl_table *table, int write,
+				   void *buffer, size_t *lenp,
+				   loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int dirty_background_bytes_handler(struct ctl_table *table, int write,
+				   void *buffer, size_t *lenp,
+				   loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int dirty_ratio_handler(struct ctl_table *table, int write,
+			void *buffer, size_t *lenp,
+			loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int dirty_bytes_handler(struct ctl_table *table, int write,
+			void *buffer, size_t *lenp,
+			loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int dirty_writeback_centisecs_handler(struct ctl_table *table, int write,
+				      void *buffer, size_t *length,
+				      loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int scan_unevictable_handler(struct ctl_table *table, int write,
+			     void __user *buffer,
+			     size_t *length, loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+int sched_rt_handler(struct ctl_table *table, int write,
+		     void __user *buffer, size_t *lenp,
+		     loff_t *ppos)
+{
+	lib_assert(false);
+	return 0;
+}
+
+int sysctl_overcommit_memory = OVERCOMMIT_GUESS;
+int sysctl_overcommit_ratio = 50;
+int sysctl_panic_on_oom = 0;
+int sysctl_oom_dump_tasks = 0;
+int sysctl_oom_kill_allocating_task = 0;
+int sysctl_nr_trim_pages = 0;
+int sysctl_drop_caches = 0;
+int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES - 1] = { 32 };
+unsigned int sysctl_sched_child_runs_first = 0;
+unsigned int sysctl_sched_compat_yield = 0;
+unsigned int sysctl_sched_rt_period = 1000000;
+int sysctl_sched_rt_runtime = 950000;
+
+int vm_highmem_is_dirtyable;
+unsigned long vm_dirty_bytes = 0;
+int vm_dirty_ratio = 20;
+int dirty_background_ratio = 10;
+unsigned int dirty_expire_interval = 30 * 100;
+unsigned int dirty_writeback_interval = 5 * 100;
+unsigned long dirty_background_bytes = 0;
+int percpu_pagelist_fraction = 0;
+int panic_timeout = 0;
+int panic_on_oops = 0;
+int printk_delay_msec = 0;
+int panic_on_warn = 0;
+DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
+
+#define RESERVED_PIDS 300
+int pid_max = PID_MAX_DEFAULT;
+int pid_max_min = RESERVED_PIDS + 1;
+int pid_max_max = PID_MAX_LIMIT;
+int min_free_kbytes = 1024;
+int max_threads = 100;
+int laptop_mode = 0;
+
+#define DEFAULT_MESSAGE_LOGLEVEL 4
+#define MINIMUM_CONSOLE_LOGLEVEL 1
+#define DEFAULT_CONSOLE_LOGLEVEL 7
+int console_printk[4] = {
+	DEFAULT_CONSOLE_LOGLEVEL,       /* console_loglevel */
+	DEFAULT_MESSAGE_LOGLEVEL,       /* default_message_loglevel */
+	MINIMUM_CONSOLE_LOGLEVEL,       /* minimum_console_loglevel */
+	DEFAULT_CONSOLE_LOGLEVEL,       /* default_console_loglevel */
+};
+
+int print_fatal_signals = 0;
+unsigned int core_pipe_limit = 0;
+int core_uses_pid = 0;
+int vm_swappiness = 60;
+int nr_pdflush_threads = 0;
+unsigned long scan_unevictable_pages = 0;
+int suid_dumpable = 0;
+int page_cluster = 0;
+int block_dump = 0;
+int C_A_D = 0;
+#include <linux/nsproxy.h>
+struct nsproxy init_nsproxy;
+#include <linux/reboot.h>
+char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";
+unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
+unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
+
+int pdflush_proc_obsolete(struct ctl_table *table, int write,
+			  void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+	return nr_pdflush_threads;
+}
+#include <linux/fs.h>
+
+/**
+ * Honestly, I don't understand half of that code.
+ * It was modeled after fs/proc/proc_sysctl.c proc_sys_readdir
+ *
+ * Me either ;) (Hajime, Jan 2013)
+ */
+
+/* from proc_sysctl.c (XXX) */
+extern struct ctl_table_root sysctl_table_root;
+void ctl_table_first_entry(struct ctl_dir *dir,
+		 struct ctl_table_header **phead, struct ctl_table **pentry);
+void ctl_table_next_entry(struct ctl_table_header **phead, struct ctl_table **pentry);
+struct ctl_table *ctl_table_find_entry(struct ctl_table_header **phead,
+			     struct ctl_dir *dir, const char *name,
+			     int namelen);
+struct ctl_dir *ctl_table_xlate_dir(struct ctl_table_set *set, struct ctl_dir *dir);
+/* for init_net (XXX, should be fixed) */
+#include <net/net_namespace.h>
+
+static void iterate_table_recursive(const struct SimSysIterator *iter,
+				    struct ctl_table_header *head)
+{
+	struct ctl_table *entry;
+
+	for (entry = head->ctl_table; entry->procname; entry++) {
+		bool may_read = (head->ctl_table->mode & MAY_READ);
+		bool may_write = (head->ctl_table->mode & MAY_WRITE);
+		int flags = 0;
+
+		flags |= may_read ? SIM_SYS_FILE_READ : 0;
+		flags |= may_write ? SIM_SYS_FILE_WRITE : 0;
+		iter->report_file(iter, entry->procname, flags,
+				  (struct SimSysFile *)entry);
+	}
+}
+
+
+static void iterate_recursive(const struct SimSysIterator *iter,
+			      struct ctl_table_header *head)
+{
+	struct ctl_table_header *h = NULL;
+	struct ctl_table *entry;
+	struct ctl_dir *ctl_dir;
+
+	ctl_dir = container_of(head, struct ctl_dir, header);
+	for (ctl_table_first_entry(ctl_dir, &h, &entry); h;
+	     ctl_table_next_entry(&h, &entry)) {
+		struct ctl_dir *dir;
+		int ret;
+		const char *procname;
+
+		/* copy from sysctl_follow_link () */
+		if (S_ISLNK(entry->mode)) {
+			dir = ctl_table_xlate_dir(&init_net.sysctls, h->parent);
+			if (IS_ERR(dir)) {
+				ret = PTR_ERR(dir);
+				lib_assert(false);
+			} else {
+				procname = entry->procname;
+				h = NULL;
+				entry =
+					ctl_table_find_entry(&h, dir, procname,
+							     strlen(procname));
+				ret = -ENOENT;
+			}
+		}
+
+		if (S_ISDIR(entry->mode)) {
+			iter->report_start_dir(iter, entry->procname);
+			iterate_recursive(iter, h);
+			iter->report_end_dir(iter);
+		} else
+			iterate_table_recursive(iter, h);
+	}
+
+}
+
+
+void lib_sys_iterate_files(const struct SimSysIterator *iter)
+{
+	struct ctl_table_header *root =
+		&sysctl_table_root.default_set.dir.header;
+
+	iterate_recursive(iter, root);
+}
+
+int lib_sys_file_read(const struct SimSysFile *file, char *buffer, int size,
+		      int offset)
+{
+	struct ctl_table *table = (struct ctl_table *)file;
+	loff_t ppos = offset;
+	size_t result = size;
+	int error;
+
+	error = table->proc_handler(table, 0, buffer, &result, &ppos);
+	return result;
+}
+int lib_sys_file_write(const struct SimSysFile *file, const char *buffer,
+		       int size, int offset)
+{
+	struct ctl_table *table = (struct ctl_table *)file;
+	loff_t ppos = offset;
+	size_t result = size;
+	int error;
+
+	error = table->proc_handler(table, 1, (char *)buffer, &result, &ppos);
+	return result;
+}
Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#113 lore raw

PATCH v6 7/10 lib: other kernel glue layer code

In reply to Hajime Tazaki

These files are used to provide the same function calls so that other network stack code keeps untouched.

---
 arch/lib/capability.c |  25 +++++
 arch/lib/filemap.c    |  32 ++++++
 arch/lib/fs.c         |  70 +++++++++++++
 arch/lib/glue.c       | 284 ++++++++++++++++++++++++++++++++++++++++++++++++++
 arch/lib/modules.c    |  36 +++++++
 arch/lib/pid.c        |  29 ++++++
 arch/lib/print.c      |  56 ++++++++++
 arch/lib/proc.c       |  36 +++++++
 arch/lib/random.c     |  54 ++++++++++
 arch/lib/sysfs.c      |  83 +++++++++++++++
 arch/lib/vmscan.c     |  26 +++++
 11 files changed, 731 insertions(+)
 create mode 100644 arch/lib/capability.c
 create mode 100644 arch/lib/filemap.c
 create mode 100644 arch/lib/fs.c
 create mode 100644 arch/lib/glue.c
 create mode 100644 arch/lib/modules.c
 create mode 100644 arch/lib/pid.c
 create mode 100644 arch/lib/print.c
 create mode 100644 arch/lib/proc.c
 create mode 100644 arch/lib/random.c
 create mode 100644 arch/lib/sysfs.c
 create mode 100644 arch/lib/vmscan.c
arch/lib/capability.c new file +25 -0
new file mode 100644
index 000000000000..3a1f30129fb7
@@ -0,0 +1,25 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include "linux/capability.h"
+
+struct sock;
+struct sk_buff;
+
+int file_caps_enabled = 0;
+
+int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
+{
+	return 0;
+}
+
+bool file_ns_capable(const struct file *file, struct user_namespace *ns,
+		     int cap)
+{
+	return true;
+}
arch/lib/filemap.c new file +32 -0
new file mode 100644
index 000000000000..ce424ffae8c2
@@ -0,0 +1,32 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ *         Frederic Urbani
+ */
+
+#include "sim.h"
+#include "sim-assert.h"
+#include <linux/fs.h>
+
+
+ssize_t generic_file_aio_read(struct kiocb *a, const struct iovec *b,
+			      unsigned long c, loff_t d)
+{
+	lib_assert(false);
+
+	return 0;
+}
+
+int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	return -ENOSYS;
+}
+
+ssize_t
+generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
+{
+	return 0;
+}
arch/lib/fs.c new file +70 -0

70 lines not on this page · raw message

arch/lib/glue.c new file +284 -0

284 lines not on this page · raw message

arch/lib/modules.c new file +36 -0
new file mode 100644
index 000000000000..ca43fdc691b0
@@ -0,0 +1,36 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ *         Frederic Urbani
+ */
+
+#include "sim-assert.h"
+#include <linux/moduleparam.h>
+#include <linux/kmod.h>
+#include <linux/module.h>
+
+int modules_disabled = 0;
+char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
+
+static struct module_version_attribute g_empty_attr_buffer;
+/* we make the array empty by default because, really, we don't need */
+/* to look at the builtin params */
+const struct kernel_param __start___param[] = {{0}} ;
+const struct kernel_param __stop___param[] = {{0}} ;
+const struct module_version_attribute *__start___modver[] = {
+	&g_empty_attr_buffer};
+const struct module_version_attribute *__stop___modver[] = {
+	&g_empty_attr_buffer};
+
+struct module_attribute module_uevent;
+struct ctl_table usermodehelper_table[] = {};
+
+int __request_module(bool wait, const char *fmt, ...)
+{
+	/* we really should never be trying to load modules that way. */
+	/*  lib_assert (false); */
+	return 0;
+}
arch/lib/pid.c new file +29 -0
new file mode 100644
index 000000000000..00cf7b620c43
@@ -0,0 +1,29 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include <linux/pid.h>
+#include "sim.h"
+#include "sim-assert.h"
+
+void put_pid(struct pid *pid)
+{
+}
+pid_t pid_vnr(struct pid *pid)
+{
+	return pid_nr(pid);
+}
+struct task_struct *find_task_by_vpid(pid_t nr)
+{
+	lib_assert(false);
+	return 0;
+}
+struct pid *find_get_pid(int nr)
+{
+	lib_assert(false);
+	return 0;
+}
arch/lib/print.c new file +56 -0

56 lines not on this page · raw message

arch/lib/proc.c new file +36 -0
new file mode 100644
index 000000000000..3183d05f2c91
@@ -0,0 +1,36 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2014 Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include <linux/fs.h>
+#include <linux/net.h>
+#include <linux/slab.h>
+#include <linux/proc_fs.h>
+#include <linux/string.h>
+#include <net/net_namespace.h>
+#include "sim-types.h"
+#include "sim-assert.h"
+#include "fs/proc/internal.h"           /* XXX */
+
+struct proc_dir_entry;
+static char proc_root_data[sizeof(struct proc_dir_entry) + 4];
+
+static struct proc_dir_entry *proc_root_sim  =
+	(struct proc_dir_entry *)proc_root_data;
+extern const struct inode_operations proc_link_inode_operations;
+
+void lib_proc_net_initialize(void)
+{
+	proc_root_sim->parent = proc_root_sim;
+	strcpy(proc_root_sim->name, "net");
+	proc_root_sim->mode = S_IFDIR | S_IRUGO | S_IXUGO;
+	proc_root_sim->subdir = RB_ROOT;
+	proc_root_sim->proc_iops = &proc_link_inode_operations;
+	init_net.proc_net = proc_root_sim;
+	init_net.proc_net_stat = proc_mkdir("stat", proc_root_sim);
+}
+
arch/lib/random.c new file +54 -0

54 lines not on this page · raw message

arch/lib/sysfs.c new file +83 -0

83 lines not on this page · raw message

arch/lib/vmscan.c new file +26 -0
new file mode 100644
index 000000000000..3132f66d5085
@@ -0,0 +1,26 @@
+/*
+ * glue code for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <[email protected]>
+ *         Hajime Tazaki <[email protected]>
+ */
+
+#include <linux/mm.h>
+#include <linux/shrinker.h>
+
+/*
+ * Add a shrinker callback to be called from the vm
+ */
+int register_shrinker(struct shrinker *shrinker)
+{
+	return 0;
+}
+
+/*
+ * Remove one
+ */
+void unregister_shrinker(struct shrinker *shrinker)
+{
+}
+
Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#114 lore raw

PATCH v6 8/10 lib: auxiliary files for auto-generated asm-generic files of libos

In reply to Hajime Tazaki

these files works as stubs in order to transparently run the other kernel part (e.g., net/) on libos environment.

---
 arch/lib/include/asm/Kbuild           | 57 ++++++++++++++++++++++++++++++++
 arch/lib/include/asm/atomic.h         | 62 +++++++++++++++++++++++++++++++++++
 arch/lib/include/asm/barrier.h        |  8 +++++
 arch/lib/include/asm/bitsperlong.h    | 16 +++++++++
 arch/lib/include/asm/current.h        |  7 ++++
 arch/lib/include/asm/elf.h            | 10 ++++++
 arch/lib/include/asm/hardirq.h        |  8 +++++
 arch/lib/include/asm/page.h           | 14 ++++++++
 arch/lib/include/asm/pgtable.h        | 30 +++++++++++++++++
 arch/lib/include/asm/processor.h      | 19 +++++++++++
 arch/lib/include/asm/ptrace.h         |  4 +++
 arch/lib/include/asm/segment.h        |  6 ++++
 arch/lib/include/asm/sembuf.h         |  4 +++
 arch/lib/include/asm/shmbuf.h         |  4 +++
 arch/lib/include/asm/shmparam.h       |  4 +++
 arch/lib/include/asm/sigcontext.h     |  6 ++++
 arch/lib/include/asm/stat.h           |  4 +++
 arch/lib/include/asm/statfs.h         |  4 +++
 arch/lib/include/asm/swab.h           |  7 ++++
 arch/lib/include/asm/thread_info.h    | 36 ++++++++++++++++++++
 arch/lib/include/asm/uaccess.h        | 14 ++++++++
 arch/lib/include/asm/unistd.h         |  4 +++
 arch/lib/include/uapi/asm/byteorder.h |  6 ++++
 23 files changed, 334 insertions(+)
 create mode 100644 arch/lib/include/asm/Kbuild
 create mode 100644 arch/lib/include/asm/atomic.h
 create mode 100644 arch/lib/include/asm/barrier.h
 create mode 100644 arch/lib/include/asm/bitsperlong.h
 create mode 100644 arch/lib/include/asm/current.h
 create mode 100644 arch/lib/include/asm/elf.h
 create mode 100644 arch/lib/include/asm/hardirq.h
 create mode 100644 arch/lib/include/asm/page.h
 create mode 100644 arch/lib/include/asm/pgtable.h
 create mode 100644 arch/lib/include/asm/processor.h
 create mode 100644 arch/lib/include/asm/ptrace.h
 create mode 100644 arch/lib/include/asm/segment.h
 create mode 100644 arch/lib/include/asm/sembuf.h
 create mode 100644 arch/lib/include/asm/shmbuf.h
 create mode 100644 arch/lib/include/asm/shmparam.h
 create mode 100644 arch/lib/include/asm/sigcontext.h
 create mode 100644 arch/lib/include/asm/stat.h
 create mode 100644 arch/lib/include/asm/statfs.h
 create mode 100644 arch/lib/include/asm/swab.h
 create mode 100644 arch/lib/include/asm/thread_info.h
 create mode 100644 arch/lib/include/asm/uaccess.h
 create mode 100644 arch/lib/include/asm/unistd.h
 create mode 100644 arch/lib/include/uapi/asm/byteorder.h
arch/lib/include/asm/Kbuild new file +57 -0
new file mode 100644
index 000000000000..c647b1ca8cca
@@ -0,0 +1,57 @@
+generic-y += auxvec.h
+generic-y += bitops.h
+generic-y += bug.h
+generic-y += cache.h
+generic-y += cacheflush.h
+generic-y += checksum.h
+generic-y += cputime.h
+generic-y += cmpxchg.h
+generic-y += delay.h
+generic-y += device.h
+generic-y += div64.h
+generic-y += dma.h
+generic-y += exec.h
+generic-y += emergency-restart.h
+generic-y += errno.h
+generic-y += fcntl.h
+generic-y += ftrace.h
+generic-y += io.h
+generic-y += ioctl.h
+generic-y += ioctls.h
+generic-y += ipcbuf.h
+generic-y += irq.h
+generic-y += irqflags.h
+generic-y += irq_regs.h
+generic-y += kdebug.h
+generic-y += kmap_types.h
+generic-y += linkage.h
+generic-y += local.h
+generic-y += mcs_spinlock.h
+generic-y += mman.h
+generic-y += mmu.h
+generic-y += mmu_context.h
+generic-y += module.h
+generic-y += mutex.h
+generic-y += param.h
+generic-y += pci.h
+generic-y += percpu.h
+generic-y += poll.h
+generic-y += posix_types.h
+generic-y += preempt.h
+generic-y += resource.h
+generic-y += scatterlist.h
+generic-y += sections.h
+generic-y += setup.h
+generic-y += signal.h
+generic-y += siginfo.h
+generic-y += socket.h
+generic-y += sockios.h
+generic-y += string.h
+generic-y += termbits.h
+generic-y += termios.h
+generic-y += timex.h
+generic-y += tlbflush.h
+generic-y += types.h
+generic-y += topology.h
+generic-y += trace_clock.h
+generic-y += unaligned.h
arch/lib/include/asm/atomic.h new file +62 -0

62 lines not on this page · raw message

arch/lib/include/asm/barrier.h new file +8 -0
new file mode 100644
index 000000000000..47adcc659b50
@@ -0,0 +1,8 @@
+#include <asm-generic/barrier.h>
+
+#undef smp_store_release
+#define smp_store_release(p, v)						\
+	do {								\
+		smp_mb();						\
+		ACCESS_ONCE(*p) = (v);					\
+	} while (0)
arch/lib/include/asm/bitsperlong.h new file +16 -0
new file mode 100644
index 000000000000..9890ba90aec1
@@ -0,0 +1,16 @@
+#ifndef _ASM_SIM_BITSPERLONG_H
+#define _ASM_SIM_BITSPERLONG_H
+
+#ifdef CONFIG_64BIT
+#define BITS_PER_LONG 64
+#else
+#define BITS_PER_LONG 32
+#endif /* CONFIG_64BIT */
+
+#define __BITS_PER_LONG BITS_PER_LONG
+
+#ifndef BITS_PER_LONG_LONG
+#define BITS_PER_LONG_LONG 64
+#endif
+
+#endif /* _ASM_SIM_BITSPERLONG_H */
arch/lib/include/asm/current.h new file +7 -0
new file mode 100644
index 000000000000..62489cdc9ff2
@@ -0,0 +1,7 @@
+#ifndef _ASM_SIM_CURRENT_H
+#define _ASM_SIM_CURRENT_H
+
+struct task_struct *get_current(void);
+#define current get_current()
+
+#endif /* _ASM_SIM_CURRENT_H */
arch/lib/include/asm/elf.h new file +10 -0
new file mode 100644
index 000000000000..a7396c9d4225
@@ -0,0 +1,10 @@
+#ifndef _ASM_SIM_ELF_H
+#define _ASM_SIM_ELF_H
+
+#if defined(CONFIG_64BIT)
+#define ELF_CLASS ELFCLASS64
+#else
+#define ELF_CLASS ELFCLASS32
+#endif
+
+#endif /* _ASM_SIM_ELF_H */
arch/lib/include/asm/hardirq.h new file +8 -0
new file mode 100644
index 000000000000..47d47f95a793
@@ -0,0 +1,8 @@
+#ifndef _ASM_SIM_HARDIRQ_H
+#define _ASM_SIM_HARDIRQ_H
+
+extern unsigned int interrupt_pending;
+
+#define local_softirq_pending() (interrupt_pending)
+
+#endif /* _ASM_SIM_HARDIRQ_H */
arch/lib/include/asm/page.h new file +14 -0
new file mode 100644
index 000000000000..8c0aa7437374
@@ -0,0 +1,14 @@
+#ifndef _ASM_SIM_PAGE_H
+#define _ASM_SIM_PAGE_H
+
+typedef struct {} pud_t;
+
+#define THREAD_ORDER    1
+#define THREAD_SIZE  (PAGE_SIZE << THREAD_ORDER)
+
+#define WANT_PAGE_VIRTUAL 1
+
+#include <asm-generic/page.h>
+#include <asm-generic/getorder.h>
+
+#endif /* _ASM_SIM_PAGE_H */
arch/lib/include/asm/pgtable.h new file +30 -0
new file mode 100644
index 000000000000..ce599c852795
@@ -0,0 +1,30 @@
+#ifndef _ASM_SIM_PGTABLE_H
+#define _ASM_SIM_PGTABLE_H
+
+#define PAGE_KERNEL ((pgprot_t) {0 })
+
+#define arch_start_context_switch(prev) do {} while (0)
+
+#define kern_addr_valid(addr)(1)
+#define pte_file(pte)(1)
+/* Encode and de-code a swap entry */
+#define __swp_type(x)                   (((x).val >> 5) & 0x1f)
+#define __swp_offset(x)                 ((x).val >> 11)
+#define __swp_entry(type, offset) \
+	((swp_entry_t) {((type) << 5) | ((offset) << 11) })
+#define __pte_to_swp_entry(pte)         ((swp_entry_t) {pte_val((pte)) })
+#define __swp_entry_to_pte(x)           ((pte_t) {(x).val })
+#define pmd_page(pmd) (struct page *)(pmd_val(pmd) & PAGE_MASK)
+#define pgtable_cache_init()   do { } while (0)
+
+static inline int pte_swp_soft_dirty(pte_t pte)
+{
+	return 0;
+}
+
+static inline pte_t pte_swp_clear_soft_dirty(pte_t pte)
+{
+	return pte;
+}
+
+#endif /* _ASM_SIM_PGTABLE_H */
arch/lib/include/asm/processor.h new file +19 -0
new file mode 100644
index 000000000000..4ac2e89127a0
@@ -0,0 +1,19 @@
+#ifndef _ASM_SIM_PROCESSOR_H
+#define _ASM_SIM_PROCESSOR_H
+
+struct thread_struct {};
+
+#define cpu_relax()
+#define cpu_relax_lowlatency() cpu_relax()
+#define KSTK_ESP(tsk)	(0)
+
+# define current_text_addr() ({ __label__ _l; _l: &&_l; })
+
+#define TASK_SIZE ((~(long)0))
+
+#define thread_saved_pc(x) (unsigned long)0
+#define task_pt_regs(t) NULL
+
+int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
+
+#endif /* _ASM_SIM_PROCESSOR_H */
arch/lib/include/asm/ptrace.h new file +4 -0
new file mode 100644
index 000000000000..ddd97080b759
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_PTRACE_H
+#define _ASM_SIM_PTRACE_H
+
+#endif /* _ASM_SIM_PTRACE_H */
arch/lib/include/asm/segment.h new file +6 -0
new file mode 100644
index 000000000000..e056922cd24c
@@ -0,0 +1,6 @@
+#ifndef _ASM_SIM_SEGMENT_H
+#define _ASM_SIM_SEGMENT_H
+
+typedef struct { int seg; } mm_segment_t;
+
+#endif /* _ASM_SIM_SEGMENT_H */
arch/lib/include/asm/sembuf.h new file +4 -0
new file mode 100644
index 000000000000..d64927bbe08a
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_SEMBUF_H
+#define _ASM_SIM_SEMBUF_H
+
+#endif /* _ASM_SIM_SEMBUF_H */
arch/lib/include/asm/shmbuf.h new file +4 -0
new file mode 100644
index 000000000000..42d0a7157375
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_SHMBUF_H
+#define _ASM_SIM_SHMBUF_H
+
+#endif /* _ASM_SIM_SHMBUF_H */
arch/lib/include/asm/shmparam.h new file +4 -0
new file mode 100644
index 000000000000..3410f1be84a3
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_SHMPARAM_H
+#define _ASM_SIM_SHMPARAM_H
+
+#endif /* _ASM_SIM_SHMPARAM_H */
arch/lib/include/asm/sigcontext.h new file +6 -0
new file mode 100644
index 000000000000..230b4b5eabbe
@@ -0,0 +1,6 @@
+#ifndef _ASM_SIM_SIGCONTEXT_H
+#define _ASM_SIM_SIGCONTEXT_H
+
+struct sigcontext {};
+
+#endif /* _ASM_SIM_SIGCONTEXT_H */
arch/lib/include/asm/stat.h new file +4 -0
new file mode 100644
index 000000000000..80fa2cbbba08
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_STAT_H
+#define _ASM_SIM_STAT_H
+
+#endif /* _ASM_SIM_STAT_H */
arch/lib/include/asm/statfs.h new file +4 -0
new file mode 100644
index 000000000000..881ce51f5aaf
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_STATFS_H
+#define _ASM_SIM_STATFS_H
+
+#endif /* _ASM_SIM_STATFS_H */
arch/lib/include/asm/swab.h new file +7 -0
new file mode 100644
index 000000000000..d81376a35d9c
@@ -0,0 +1,7 @@
+#ifndef _ASM_SIM_SWAB_H
+#define _ASM_SIM_SWAB_H
+
+#include <linux/types.h>
+
+
+#endif /* _ASM_SIM_SWAB_H */
arch/lib/include/asm/thread_info.h new file +36 -0
new file mode 100644
index 000000000000..ec316c613041
@@ -0,0 +1,36 @@
+#ifndef _ASM_SIM_THREAD_INFO_H
+#define _ASM_SIM_THREAD_INFO_H
+
+#define TIF_NEED_RESCHED 1
+#define TIF_SIGPENDING 2
+#define TIF_MEMDIE 5
+
+struct thread_info {
+	__u32 flags;
+	int preempt_count;
+	struct task_struct *task;
+	struct restart_block restart_block;
+};
+
+struct thread_info *current_thread_info(void);
+struct thread_info *alloc_thread_info(struct task_struct *task);
+void free_thread_info(struct thread_info *ti);
+
+#define TS_RESTORE_SIGMASK      0x0008  /* restore signal mask in do_signal() */
+#define HAVE_SET_RESTORE_SIGMASK        1
+static inline void set_restore_sigmask(void)
+{
+}
+static inline void clear_restore_sigmask(void)
+{
+}
+static inline bool test_restore_sigmask(void)
+{
+	return true;
+}
+static inline bool test_and_clear_restore_sigmask(void)
+{
+	return true;
+}
+
+#endif /* _ASM_SIM_THREAD_INFO_H */
arch/lib/include/asm/uaccess.h new file +14 -0
new file mode 100644
index 000000000000..74f973b666f1
@@ -0,0 +1,14 @@
+#ifndef _ASM_SIM_UACCESS_H
+#define _ASM_SIM_UACCESS_H
+
+#define KERNEL_DS ((mm_segment_t) {0 })
+#define USER_DS ((mm_segment_t) {0 })
+#define get_fs() KERNEL_DS
+#define get_ds() USER_DS
+#define set_fs(x) do {} while ((x.seg) != (x.seg))
+
+#define __access_ok(addr, size) (1)
+
+#include <asm-generic/uaccess.h>
+
+#endif /* _ASM_SIM_UACCESS_H */
arch/lib/include/asm/unistd.h new file +4 -0
new file mode 100644
index 000000000000..6b482b41051b
@@ -0,0 +1,4 @@
+#ifndef _ASM_SIM_UNISTD_H
+#define _ASM_SIM_UNISTD_H
+
+#endif /* _ASM_SIM_UNISTD_H */
arch/lib/include/uapi/asm/byteorder.h new file +6 -0
new file mode 100644
index 000000000000..b13a7a88f3eb
@@ -0,0 +1,6 @@
+#ifndef _ASM_X86_BYTEORDER_H
+#define _ASM_X86_BYTEORDER_H
+
+#include <linux/byteorder/little_endian.h>
+
+#endif /* _ASM_X86_BYTEORDER_H */
Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#115 lore raw

PATCH v6 9/10 lib: libos build scripts and documentation

In reply to Hajime Tazaki

document and build scripts for libos architecture.

---
 Documentation/virtual/libos-howto.txt | 144 ++++++++
 MAINTAINERS                           |   9 +
 arch/lib/.gitignore                   |   3 +
 arch/lib/Kconfig                      | 124 +++++++
 arch/lib/Makefile                     | 235 ++++++++++++
 arch/lib/Makefile.print               |  45 +++
 arch/lib/defconfig                    | 655 ++++++++++++++++++++++++++++++++++
 arch/lib/generate-linker-script.py    |  50 +++
 8 files changed, 1265 insertions(+)
 create mode 100644 Documentation/virtual/libos-howto.txt
 create mode 100644 arch/lib/.gitignore
 create mode 100644 arch/lib/Kconfig
 create mode 100644 arch/lib/Makefile
 create mode 100644 arch/lib/Makefile.print
 create mode 100644 arch/lib/defconfig
 create mode 100755 arch/lib/generate-linker-script.py
Documentation/virtual/libos-howto.txt new file +144 -0
new file mode 100644
index 000000000000..fbf7946f42ef
@@ -0,0 +1,144 @@
+Library operating system (libos) version of Linux
+=================================================
+
+* Overview
+
+New hardware independent architecture 'arch/lib', configured by
+CONFIG_LIB gives you two features.
+
+- network stack in userspace (NUSE)
+  NUSE will give you a personalized network stack for each application
+  without replacing host operating system.
+
+- network simulator integration, which is called Direct Code Execution (DCE)
+  DCE will give us a network simulation environment with Linux network stack
+  to investigate the detail behavior protocol implementation with a flexible
+  network configuration. This is also useful for the testing environment.
+
+(- more abstracted implementation of underlying platform will be a future
+   direction (e.g., rump hypercall))
+
+In both features, Linux kernel network stack is running on top of
+userspace application with a linked or dynamically loaded library.
+
+They have their own, isolated network stack from host operating system
+so they are configured different IP addresses as other virtualization
+methods do.
+
+
+* How different with others ?
+
+- User-mode Linux (UML)
+
+UML is a way to execute Linux kernel code as a userspace
+application. It is completely isolated from host kernel but can host
+arbitrary userspace applications on top of UML.
+
+- namespace / container
+
+Container technologies with namespace brings a process-level isolation
+to host multiple network entities but shares the kernel among
+processes, which prevents to introduce new features implemented in
+kernel space.
+
+
+* How to build it ?
+
+configuration of arch/lib follows a standard configuration of kernel.
+
+ make defconfig ARCH=lib
+
+or
+
+ make menuconfig ARCH=lib
+
+then you can build a set of libraries for libos.
+
+ make library ARCH=lib
+
+This will give you a shared library file liblinux-$(KERNELVERSION).so
+in the top directory.
+
+* Hello world
+
+you may first need to configure a configuration file, named
+'nuse.conf' so that the library version of network stack can know what
+kind of IP configuration should be used. There is an example file
+at arch/lib/nuse.conf.sample: you may copy and modify it for your purpose.
+
+ sudo NUSECONF=nuse.conf ./nuse ping www.google.com
+
+
+
+* Example use cases
+- regression test with Direct Code Execution (DCE)
+
+'make test' by DCE gives a test platform for networking code, with the
+help of network simulator facilities like link delay/bandwidth/drop
+configurations, large network topology with userspace routing protocol
+daemons, etc.
+
+An interesting feature is the determinism of any test executions. A
+test script always gives same results in every execution if there is
+no modification on test target code.
+
+For the first step, you need to obtain network simulator
+environment. 'make testbin' does all the stuff for the preparation.
+
+% make testbin -C tools/testing/libos
+
+Then, you can 'make test' for your code.
+
+% make test ARCH=lib
+
+ PASS: TestSuite netlink-socket
+ PASS: TestSuite process-manager
+ PASS: TestSuite dce-cradle
+ PASS: TestSuite dce-mptcp
+ PASS: TestSuite dce-umip
+ PASS: TestSuite dce-quagga
+ PASS: Example dce-tcp-simple
+ PASS: Example dce-udp-simple
+
+
+- userspace network stack (NUSE)
+
+an application can use its own network stack, distinct from host network stack
+in order to personalize any network feature to the application specific one.
+The 'nuse' wrapper script, based on LD_PRELOAD technique, carefully replaces
+socket API and redirects system calls to the network stack library, provided by
+this framework.
+
+the network stack can be used with any kind of raw-socket like
+technologies such as Intel DPDK, netmap, etc.
+
+
+
+* Files / External Repository
+
+The kernel source tree (i.e., arch/lib) only contains a shared part of
+applications (NUSE/DCE). Pure userspace part is managed at a different
+repository, called Linux-libos-tools: it is automatically downloaded
+during make library.
+
+ https://github.com/libos-nuse/linux-libos-tools
+
+
+* More information
+- [email protected] (LibOS in general and NUSE related questions)
+- [email protected] (ns-3 related questions)
+- articles, slides
+ Experimentation Tools for Networking Research (Lacage, 2010)
+   http://cutebugs.net/files/thesis.pdf
+ Direct code execution: revisiting library OS architecture for reproducible
+  network experiments (Tazaki et al., 2013)
+   http://dx.doi.org/10.1145/2535372.2535374
+ Library Operating System with Mainline Linux Network Stack (Tazaki et al., 2015)
+   https://www.netdev01.org/docs/netdev01-tazaki-libos.pdf (slides)
+
+
+* Authors
+ Mathieu Lacage <[email protected]>
+ Hajime Tazaki <[email protected]>
+ Frederic Urbani <[email protected]>
+ Ryo Nakamura <[email protected]>
MAINTAINERS +9 -0
index 4be7e5e7e9f9..b919060c9821 100644
@@ -6197,6 +6197,15 @@ S:	Supported
 F:	drivers/nvdimm/pmem.c
 F:	include/linux/pmem.h
 
+LIBRARY OS (LIBOS)
+M:	Hajime Tazaki <[email protected]>
+L:	[email protected]
+W:	http://libos-nuse.github.io/
+S:	Maintained
+F:	Documentation/virtual/libos-howto.txt
+F:	arch/lib/
+F:	tools/testing/libos/
+
 LINUX FOR IBM pSERIES (RS/6000)
 M:	Paul Mackerras <[email protected]>
 W:	http://www.ibm.com/linux/ltc/projects/ppc
arch/lib/.gitignore new file +3 -0
new file mode 100644
index 000000000000..4370d48271cb
@@ -0,0 +1,3 @@
+linker.lds
+objs.mk
+tools
arch/lib/Kconfig new file +124 -0

125 lines not on this page · raw message

arch/lib/Makefile new file +235 -0

235 lines not on this page · raw message

arch/lib/Makefile.print new file +45 -0

45 lines not on this page · raw message

arch/lib/defconfig new file +655 -0

655 lines not on this page · raw message

arch/lib/generate-linker-script.py new file +50 -0

50 lines not on this page · raw message

Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#116 lore raw

PATCH v6 10/10 lib: tools used for test scripts

In reply to Hajime Tazaki

These auxiliary files are used for testing and debugging of net/ code with libos. a simple test is implemented with make test ARCH=lib.

---
 tools/testing/libos/.gitignore   |  6 +++++
 tools/testing/libos/Makefile     | 38 +++++++++++++++++++++++++++
 tools/testing/libos/README       | 15 +++++++++++
 tools/testing/libos/bisect.sh    | 10 +++++++
 tools/testing/libos/dce-test.sh  | 23 ++++++++++++++++
 tools/testing/libos/nuse-test.sh | 57 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 149 insertions(+)
 create mode 100644 tools/testing/libos/.gitignore
 create mode 100644 tools/testing/libos/Makefile
 create mode 100644 tools/testing/libos/README
 create mode 100755 tools/testing/libos/bisect.sh
 create mode 100755 tools/testing/libos/dce-test.sh
 create mode 100755 tools/testing/libos/nuse-test.sh
tools/testing/libos/.gitignore new file +6 -0
new file mode 100644
index 000000000000..57a74a05482c
@@ -0,0 +1,6 @@
+*.pcap
+files-*
+bake
+buildtop
+core
+exitprocs
tools/testing/libos/Makefile new file +38 -0
new file mode 100644
index 000000000000..a27eb84e7712
@@ -0,0 +1,38 @@
+ADD_PARAM?=
+
+all: test
+
+bake:
+	hg clone http://code.nsnam.org/bake
+
+check_pkgs:
+	@./bake/bake.py check | grep Bazaar | grep OK || (echo "bzr is missing" && ./bake/bake.py check)
+	@./bake/bake.py check | grep autoreconf | grep OK || (echo "autotools is missing" && ./bake/bake.py check && exit 1)
+
+testbin: bake check_pkgs
+	@cp ../../../arch/lib/tools/bakeconf-linux.xml bake/bakeconf.xml
+	@mkdir -p buildtop/build/bin_dce
+	cd buildtop ; \
+	../bake/bake.py configure -e dce-linux-inkernel $(BAKECONF_PARAMS)
+	cd buildtop ; \
+	../bake/bake.py show --enabledTree | grep -v  -E "pygoocanvas|graphviz|python-dev" | grep Missing && (echo "required packages are missing") || echo ""
+	cd buildtop ; \
+	../bake/bake.py download ; \
+	../bake/bake.py update ; \
+	../bake/bake.py build $(BAKEBUILD_PARAMS)
+
+test:
+	@./dce-test.sh ADD_PARAM=$(ADD_PARAM)
+
+test-valgrind:
+	@./dce-test.sh -g ADD_PARAM=$(ADD_PARAM)
+
+test-fault-injection:
+	@./dce-test.sh -f ADD_PARAM=$(ADD_PARAM)
+
+clean:
+#	@rm -rf buildtop
+	@rm -f *.pcap
+	@rm -rf files-*
+	@rm -f exitprocs
+	@rm -f core
tools/testing/libos/README new file +15 -0
new file mode 100644
index 000000000000..51ac5a52336e
@@ -0,0 +1,15 @@
+
+- bisect.sh
+a sample script to bisect an issue of network stack code with the help
+of LibOS (and ns-3 network simulator). This was used to detect the issue
+for the following patch.
+
+http://patchwork.ozlabs.org/patch/436351/
+
+- dce-test.sh
+a test script invoked by 'make test ARCH=lib'. The contents of test
+scenario are implemented as test suites of ns-3 network simulator.
+
+- nuse-test.sh
+a simple test script for Network Stack in Userspace (NUSE).
+
tools/testing/libos/bisect.sh new file +10 -0
new file mode 100755
index 000000000000..9377ac3214c1
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+git merge origin/nuse --no-commit
+make clean ARCH=lib
+make library ARCH=lib OPT=no
+make test ARCH=lib ADD_PARAM=" -s dce-umip"
+RET=$?
+git reset --hard
+
+exit $RET
tools/testing/libos/dce-test.sh new file +23 -0
new file mode 100755
index 000000000000..e81e2d84c156
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+set -e
+#set -x
+export LD_LOG=symbol-fail
+#VERBOSE="-v"
+VALGRIND=""
+FAULT_INJECTION=""
+
+if [ "$1" = "-g" ] ; then
+ VALGRIND="-g"
+# Not implemneted yet.
+#elif [ "$1" = "-f" ] ; then
+# FAULT_INJECTION="-f"
+fi
+
+# FIXME
+#export NS_ATTRIBUTE_DEFAULT='ns3::DceManagerHelper::LoaderFactory=ns3::\
+#DlmLoaderFactory[];ns3::TaskManager::FiberManagerType=UcontextFiberManager'
+
+cd buildtop/source/ns-3-dce
+LD_LIBRARY_PATH=${srctree} ./test.py -n ${VALGRIND} ${FAULT_INJECTION}\
+	   ${VERBOSE} ${ADD_PARAM}
tools/testing/libos/nuse-test.sh new file +57 -0

57 lines not on this page · raw message

Signature · 7 lines
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>