Skip to contentSkip to conversation

sys_indirect RFC - sys_indirect core

PATCH In review Davide Libenzi 2 participants 2 messages Jun 29, 2007 – Jun 30, 2007 ABI/API

lore
Share & tools
lore
#0 lore raw

PATCH 3/6 sys_indirect RFC - sys_indirect core

This is the core skeleton for the new sys_indirect() system call.

- Davide

---
 include/linux/indirect.h |   32 +++++++++++++
 include/linux/syscalls.h |    5 ++
 kernel/Makefile          |    2 
 kernel/sys_indirect.c    |  109 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 147 insertions(+), 1 deletion(-)
include/linux/syscalls.h +5 -0
Index: linux-2.6.mod/include/linux/syscalls.h
===================================================================
@@ -65,6 +65,7 @@
 #include <asm/signal.h>
 #include <linux/quota.h>
 #include <linux/key.h>
+#include <linux/indirect.h>
 
 asmlinkage long sys_time(time_t __user *tloc);
 asmlinkage long sys_stime(time_t __user *tptr);
@@ -608,6 +609,10 @@
 asmlinkage long sys_timerfd(int ufd, int clockid, int flags,
 			    const struct itimerspec __user *utmr);
 asmlinkage long sys_eventfd(unsigned int count);
+asmlinkage long sys_indirect(unsigned int nr,
+			     const struct indirect_ctx __user * __user *ctxs,
+			     unsigned int nctxs,
+			     const unsigned long __user *params);
 
 int kernel_execve(const char *filename, char *const argv[], char *const envp[]);
 
kernel/Makefile +1 -1
Index: linux-2.6.mod/kernel/Makefile
===================================================================
@@ -5,7 +5,7 @@
 obj-y     = sched.o fork.o exec_domain.o panic.o printk.o profile.o \
 	    exit.o itimer.o time.o softirq.o resource.o \
 	    sysctl.o capability.o ptrace.o timer.o user.o \
-	    signal.o sys.o kmod.o workqueue.o pid.o \
+	    signal.o sys.o sys_indirect.o kmod.o workqueue.o pid.o \
 	    rcupdate.o extable.o params.o posix-timers.o \
 	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
 	    hrtimer.o rwsem.o latency.o nsproxy.o srcu.o die_notifier.o
kernel/sys_indirect.c new file +109 -0

109 lines not on this page · raw message

include/linux/indirect.h new file +32 -0
Index: linux-2.6.mod/include/linux/indirect.h
===================================================================
@@ -0,0 +1,32 @@
+/*
+ *  include/linux/indirect.h
+ *
+ *  Copyright (C) 2007  Davide Libenzi <[email protected]>
+ *
+ */
+
+#ifndef _LINUX_INDIRECT_H
+#define _LINUX_INDIRECT_H
+
+struct indirect_ctx {
+	__u32 ctx;
+};
+
+#ifdef __KERNEL__
+
+#include <linux/fsalloc.h>
+
+struct indirect_op {
+	struct indirect_op *next;
+	unsigned int ctx;
+};
+
+int indirect_set_context(struct fsa_context *ator,
+			 const struct indirect_ctx __user * __user *ctxs,
+			 unsigned int nctxs, struct indirect_op **first);
+void indirect_unset_context(struct indirect_op *curr);
+
+#endif /* __KERNEL__ */
+
+#endif /* _LINUX_INDIRECT_H */
+
#1 lore raw
Quoted 12 lines · Davide Libenzi
kernel/sys_indirect.c new file +12 -0
+int indirect_set_context(struct fsa_context *ator,
+                        const struct indirect_ctx __user * __user *ctxs,
+                        unsigned int nctxs, struct indirect_op **first)
+{
+       unsigned int i;
+       int error;
+       u32 ctx;
+       const struct indirect_ctx __user *pctx;
+       struct indirect_op *new;
+
+       *first = NULL;
+       for (i = 0; i < nctxs; i++) {

kernel/sys_indirect.c line 65

Quoted 10 lines
kernel/sys_indirect.c new file +10 -0
+               if (get_user(pctx, &ctxs[i]) || get_user(ctx, &pctx->ctx))
+                       return -EFAULT;
+               if (unlikely(ctx >= ARRAY_SIZE(inprocs) || !inprocs[ctx].set))
+                       return -EINVAL;
+               error = (*inprocs[ctx].set)(ator, pctx, &new);
+               if (unlikely(error))
+                       return error;
+               new->next = *first;
+               *first = new;
+       }

If you use one single struct as explained in my last mail all this shouldn't be necessary. The sys_indirect syscall would simply points current->ind_ctx to a kernel-copy of the struct. Then call the syscall and on return clear current->ind_ctx.

In the affected syscalls we can then test whether current->ind_ctx is NULL and if not, enable the extra functionality.

These callbacks etc seem to be far too expensive and complicated.