Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
6064d76
ghOSt release for v5.11 (up through and including kcl/387592)
jackhumphries Jun 12, 2021
c9a5c55
Add README.md
jackhumphries Jun 12, 2021
06a37c8
Bug fix
jackhumphries Jun 21, 2021
ee0f851
Bug fix
jackhumphries Jun 21, 2021
d556edb
Apply latest KCLs (up through and including kcl/395125)
jackhumphries Jul 8, 2021
5c534a2
Apply KCLs up through and including kcl/395855
hannahyp Aug 18, 2021
2b63ce8
Apply kcl/395979
hannahyp Aug 18, 2021
46891cd
sched/ghost: add ghost_wake_agent_on_check()
Jun 25, 2021
62b13b9
sched/ghost: add bpf_ghost_wake_agent()
Jun 29, 2021
5ad5514
sched/ghost: add a BPF program to pick_next_task()
Jun 25, 2021
b70eb8a
sched/ghost: add bpf_ghost_run_gtid()
Jun 25, 2021
8c313a4
sched: avoid reordering MSG_TASK_NEW and MSG_TASK_AFFINITY_CHANGED.
neelnatu Jul 15, 2021
7d8ba10
sched: avoid reordering MSG_TASK_NEW and MSG_TASK_DEPARTED
neelnatu Jul 15, 2021
9a1e357
sched: simplify latched_task preemption during context_switch.
neelnatu Jul 20, 2021
ffb8a28
sched: WARN if preempt msg is produced while a switchto chain is active.
neelnatu Jul 20, 2021
6ad4f74
sched: fix null-pointer deref when delivering TASK_AFFINITY_CHANGED.
neelnatu Jul 20, 2021
ed828b9
sched: WARN if a deferred TASK_NEW is detected during msg delivery.
neelnatu Jul 21, 2021
e8e0392
sched: only call update_curr_ghost if a task is accumulating cputime.
neelnatu Jul 22, 2021
348e633
sched: Allow RTLA_ON_IDLE to be used when committing a txn that targe…
jackhumphries Jul 8, 2021
c0b5276
sched/ghost: add run_flags to trace_sched_ghost_latched()
Jul 28, 2021
3ffe3fb
sched/ghost: add MSG_TASK_LATCHED
Jul 20, 2021
63bb34c
sched/ghost: add was_latched to TASK_PREEMPT
Jul 29, 2021
36bdde1
sched/ghost: add cpu_seqnum to messages with a cpu parameter
Jul 29, 2021
af6f9eb
sched/ghost: add cpu_seqnum to struct ghost_txn
Jul 30, 2021
4fa9526
sched/ghost: add was_current to TASK_DEPARTED
Jul 30, 2021
5afb498
sched/ghost: Add ghOSt paper and talk links to the README
jackhumphries Oct 23, 2021
bb7bcaa
sched: actually treat 'txn->commit_flags' as flags.
neelnatu Aug 3, 2021
a9f0b7d
sched: move ALLOW_TASK_ONCPU to commit_flags
neelnatu Aug 4, 2021
c220ff5
sched: don't advertise a departing task as runnable.
neelnatu Aug 5, 2021
b91de8c
sched: convert ghost_switchto_disable sysctl to an enclave tunable
hannahyp Jul 30, 2021
1711dde
sched: ALLOW_TASK_ONCPU is now in commit_flags
neelnatu Aug 6, 2021
37e27b1
sched: free queue memory when last reference is dropped.
neelnatu Aug 6, 2021
4bc38bc
sched/ghost: use krefs with struct ghost_queue
Aug 10, 2021
45a2884
sched: refactor ghost_commit_txn exit path
joshdon Aug 3, 2021
7f5671e
sched: add more control over agent barrier increment
joshdon Jul 29, 2021
56142b2
sched: add flag to avoid agent preempting a latched task
joshdon Jul 30, 2021
72a9cd0
sched/ghost: allow the agent to request DO_NOT_PREEMPT
Aug 11, 2021
fecb261
sched/ghost: do not use BPF-PNT's return value to mean RETRY_TASK
Aug 13, 2021
7db4d3c
sched: convert ghost_wake_on_waker_cpu sysctl to an enclave tunable
hannahyp Aug 25, 2021
ce73c72
sched/ghost: allow BPF-PNT to tell the kernel to not idle a cpu
Aug 13, 2021
092f577
sched/ghost: ensure BPF helper IDs are correct
Aug 25, 2021
5bdf45c
sched: convert ghost_commit_at_tick sysctl to an enclave tunable
hannahyp Aug 31, 2021
02d52da
sched/ghost: restrict ioctl to writable ctl FDs
Sep 13, 2021
0674489
sched: initialize status_word with correct gtid
neelnatu Sep 13, 2021
e92deb2
sched: allow queue association for a task currently without a 'dst_q'
neelnatu Sep 13, 2021
e8e65a4
sched/ghost: remove unused bpf prog attach/detach
Sep 13, 2021
ef0f710
sched/ghost: remove ctx from bpf helpers
Sep 14, 2021
4a3e587
sched: handle tasks moving into ghost while rq->lock is dropped in PNT.
neelnatu Sep 14, 2021
934c481
sched/ghost: refactor message sending for bpf_ghost_msg
Sep 15, 2021
e9eb207
sched/ghost: refactor ghost_bpf_link()
Sep 15, 2021
834469b
sched/ghost: add BPF_PROG_TYPE_GHOST_MSG
Sep 15, 2021
2993dcd
sched/ghost: add agent_data to common 'runnable' messages
Sep 16, 2021
e752fd5
sched: fix typo in task_deliver_msg_departed()
neelnatu Sep 22, 2021
96d8a36
sched: prevent departed->new msg reordering.
neelnatu Sep 12, 2021
6d07e3a
sched/ghost: fix TASK_DEPARTED race with validate_next_task()
joshdon Aug 12, 2021
8d69b3d
sched/ghost: allow queue wakeup to be configured to empty
joshdon Sep 7, 2021
c180a76
sched: deprecate GHOST_NULL syscall
hannahyp Sep 8, 2021
3cacc7e
sched: use ioctls for GHOST_CREATE_QUEUE and GHOST_ASSOCIATE_QUEUE
hannahyp Sep 9, 2021
61315a0
sched: use ioctls for GHOST_SET_DEFAULT_QUEUE and GHOST_CONFIG_QUEUE_…
hannahyp Sep 14, 2021
a53baec
sched: use an ioctl for GHOST_GET_CPU_TIME and deprecate unused sysca…
hannahyp Sep 15, 2021
6836153
sched: use ioctls for GHOST_COMMIT_TXN and GHOST_SYNC_GROUP_TXN
hannahyp Sep 15, 2021
85524e3
sched: use an ioctl for GHOST_TIMERFD_SETTIME
hannahyp Sep 17, 2021
64f3996
sched: don't pass pointer to ghost ioctls
hannahyp Sep 29, 2021
6d83978
sched: add gtid to /proc
hannahyp Oct 12, 2021
1ac2bda
sched: get rid of usused GHOST_MAX_SW_REGIONS and sw_region_ids[]
neelnatu Oct 18, 2021
0b1012d
sched: add an empty include/linux/ghost.h
neelnatu Oct 19, 2021
79821de
sched: don't include ghost uapi header from <include/linux/sched.h>
neelnatu Oct 19, 2021
178d442
sched: move ghost status_word helper functions into the uapi header
neelnatu Oct 19, 2021
5ab35a1
sched: get rid of unused 'ghost_run_gtid_on_check()'
neelnatu Oct 19, 2021
10b3fc7
sched: add ghost_uapi.h
neelnatu Oct 19, 2021
7ed6738
sched: GHOST_CPU_DATA_REGION_SIZE is specific to an ABI
neelnatu Oct 19, 2021
81e5d38
sched: separate headers along the ABI boundaries.
neelnatu Oct 16, 2021
9f025ee
sched: embed ABI in the 'expected_attach_type' of ghost/bpf programs.
neelnatu Oct 20, 2021
26017f5
sched: move contents of ghostfs.c into ghost.c
neelnatu Oct 25, 2021
d3f5839
sched: restrict symbols leaked into global scope from ghost.c
neelnatu Oct 25, 2021
d877db6
sched: beginnings of ghost_abi
neelnatu Oct 25, 2021
014bd0a
sched: allow agent to select abi when creating an enclave
neelnatu Oct 25, 2021
3b188a4
sched: add "version" file to retrieve abi of an enclave.
neelnatu Oct 25, 2021
7bb9ba9
sched: move enclave cpu management into abi-independent code.
neelnatu Oct 25, 2021
2d20002
sched: sync_group_cookie generation is abi independent.
neelnatu Oct 25, 2021
e75e1a0
sched: add 'wait_for_rendezvous' handler to ghost_abi.
neelnatu Oct 27, 2021
6265c27
sched: add 'pnt_prologue' callback to ghost_abi.
neelnatu Nov 1, 2021
e21c211
sched: implement enclave_abi() properly.
neelnatu Nov 2, 2021
cd42a16
sched: split ghost bpf code along ABI dependent/independent lines.
neelnatu Nov 2, 2021
42181e4
sched: add 'enclave_release' handler to ghost_abi
neelnatu Nov 3, 2021
115c7fb
sched: move ghost_fdget_enclave() in abi-independent code.
neelnatu Nov 4, 2021
b3084c9
sched: make setsched into ghost abi-independent
neelnatu Nov 4, 2021
4ed0015
sched: ghost_prepare_task_switch() is abi-dependent.
neelnatu Nov 5, 2021
45a13bc
sched: add 'cpu_idle' callback to 'ghost_abi'
neelnatu Nov 5, 2021
b36a954
sched: pull ghost_cfs_added_load() into abi-independent code.
neelnatu Nov 5, 2021
ea09fac
sched: gtid allocation is independent of the ABI.
neelnatu Nov 6, 2021
87372ca
sched: cache 'abi' in ghost_fdget_enclave()
neelnatu Nov 6, 2021
037b5ec
sched: ghost_copy_process_epilogue()
neelnatu Nov 8, 2021
a713c25
sched: abi-specific ghost tick
neelnatu Nov 15, 2021
8b71ffb
sched: initialize 'rq->ghost' in abi-independent code.
neelnatu Nov 16, 2021
b954d05
sched: provide an abi-specific entrypoint for switchto
neelnatu Nov 16, 2021
fc089c0
sched: abi-specific entrypoint for setscheduler
neelnatu Nov 16, 2021
0eaa8c0
sched: add abi-specific entrypoint for sched_fork()
neelnatu Nov 16, 2021
c95154c
sched: move is_agent() into sched.h (abi independent)
neelnatu Nov 16, 2021
d794b83
sched: make some symbols in ghost.c static
neelnatu Nov 16, 2021
be4ba11
sched: abi-specific entrypoint to commit greedy transactions.
neelnatu Nov 16, 2021
24ecacb
sched: get rid of ghost uapi dependency in timerfd.c
neelnatu Nov 17, 2021
3dbe12c
sched: add abi-specific callback from pick_next_ghost_agent
neelnatu Nov 17, 2021
e4fcc3b
sched: s/update_curr_ghost/_update_curr_ghost
neelnatu Nov 17, 2021
aad7d15
sched: add abi-specific callback for sched_class.update_curr
neelnatu Nov 17, 2021
94448e4
sched: add abi-specific callback for sched_class.prio_changed
neelnatu Nov 17, 2021
a4080f8
sched: add abi-specific callback for sched_class.switched_to
neelnatu Nov 17, 2021
dca0289
sched: add abi-specific callback for sched_class.switched_from
neelnatu Nov 17, 2021
b56f869
sched: add abi-specific callback for sched_class.task_dead
neelnatu Nov 18, 2021
e36234d
sched: add abi-specific callback for sched_class.dequeue_task
neelnatu Nov 18, 2021
b6ba758
sched: add abi-specific callback for sched_class.put_prev_task
neelnatu Nov 18, 2021
b64d2e5
sched: add abi-specific callback for sched_class.enqueue_task
neelnatu Nov 18, 2021
5e0aea8
sched: add abi-specific callback for sched_class.set_curr_task
neelnatu Nov 18, 2021
3a830dc
sched: add abi-specific callback for sched_class.task_tick
neelnatu Nov 18, 2021
b6f63bf
sched: add abi-specific callback for sched_class.pick_next_task
neelnatu Nov 18, 2021
c91e13d
sched: add abi-specific callback for sched_class.check_preempt_curr
neelnatu Nov 18, 2021
234048a
sched: add abi-specific callback for sched_class.yield_task
neelnatu Nov 18, 2021
ffe002a
sched: add abi-specific callback for sched_class.select_task_rq
neelnatu Nov 18, 2021
111c644
sched: add abi-specific callback for sched_class.task_woken
neelnatu Nov 18, 2021
26104b1
sched: add abi-specific callback for sched_class.set_cpus_allowed
neelnatu Nov 18, 2021
5b959e7
sched: move 'ghost_sched_class' into abi-independent code.
neelnatu Nov 18, 2021
5d92e04
sched: use an ioctl for ghost_run()
neelnatu Nov 18, 2021
a29bcf8
sched: deprecate ghost syscall
neelnatu Nov 18, 2021
7e1e33c
sched: include "kernfs-internal.h" from ghost.c
neelnatu Nov 19, 2021
89c1eda
sched: helper script to easily manage ghost abi snapshots.
neelnatu Nov 19, 2021
a330883
sched: simplify for_each_abi()
neelnatu Dec 2, 2021
21800d0
sched: deprecate ghost_abi_ptr_t
neelnatu Dec 2, 2021
110db8b
sched: add _ghost_resolve_enclave(rq, p) helper
neelnatu Dec 15, 2021
6304d49
sched: Add GHOST_BPF macro to include/uapi/linux/bpf.h
jackhumphries Jan 6, 2022
fe2fddf
sched/ghost: fix kernfs hang with ghost_run
Jan 11, 2022
f891d03
sched/ghost: fix never-exiting agents during destroy
Jan 11, 2022
13696d3
sched/ghost: merge unpublish_cpu and return_cpu
Jan 11, 2022
1c5694b
sched/ghost: merge claim_cpu and publish_cpu
Jan 11, 2022
e8c8b54
sched/ghost: remove cpu_owner
Jan 11, 2022
f0a0620
sched/ghost: check txn cpu is in an enclave
Jan 11, 2022
50abbf3
sched/ghost: add warnings to catch kernfs_mutex deadlocks
Jan 11, 2022
9781814
ghost: add extra parameter to ghost_timer_fd
joshdon Nov 19, 2021
127e3a8
sched: eliminate gratuitous diffs
neelnatu Jan 14, 2022
1bfe4ab
sched: fix arm64 build
neelnatu Jan 14, 2022
5da05ec
sched: relocate 'ghost_rq' to the end of 'struct rq'
neelnatu Jan 27, 2022
cee36db
sched/ghost: allow lockless requests to resched prev
Jan 18, 2022
29cf8ee
sched/ghost: add bpf_ghost_resched_cpu
Jan 19, 2022
4c4e627
sched/ghost: fix bpf_helper enclave discovery
Jan 21, 2022
18cf57f
sched/ghost: alphabetize ghostfs enclave dirtab
Jan 25, 2022
b0cfdcd
sched: return status directly in ghost_associate_queue()
hannahyp Feb 10, 2022
2f3ddbf
sched: poisoned rendezvous should not produce TASK_PREEMPT.
neelnatu Feb 14, 2022
ba3d6cf
sched: relax VM_BUG_ON check in _ghost_resolve_enclave()
neelnatu Feb 14, 2022
6f78ab7
sched/ghost: use ghostfs to move tasks to an enclave
Jan 26, 2022
39c4b87
sched/ghost: move bpf_link guts into ABI-dependent code
Jan 27, 2022
d345fb7
sched/ghost: split out bpf helper ID definitions
Jan 27, 2022
e80efd1
sched/ghost: increase bpf magic numbers
Jan 27, 2022
db41b56
BPF fixes
hannahyp Jun 15, 2022
4b300a1
sched/ghost: pass the "create" cmd buffer to the abi
Feb 3, 2022
4bc32e6
sched/ghost: set uid/gid when creating an enclave
Feb 3, 2022
669f3f4
sched/ghost: always defer ghost_destroy_enclave to a CFS task
Feb 7, 2022
15bff6a
sched/ghost: replace BPF_GHOST_SCHED_SKIP_TICK with deliver_ticks
Feb 8, 2022
01b9b3b
sched/ghost: add ghost BPF bits to tools/ header
Feb 9, 2022
ddafcb8
sched/ghost: add a ctl command to disable the ability to load bpf pro…
Feb 16, 2022
bf32ce9
sched/ghost: make _ghost_commit_pending_txn() return void
Mar 17, 2022
3820d33
sched/ghost: move BPF-PNT to pnt-prologue
Mar 17, 2022
2599fa7
sched/ghost: remove stale comment
Mar 23, 2022
4b336df
sched/ghost: always use select_task_rq_ghost()
Apr 6, 2022
ce47f9f
sched/ghost: free status words for suppressed messages
Apr 6, 2022
5c33bc5
sched/ghost: add ctl command to discover tasks
Apr 6, 2022
c21b36f
ghost: add #define GHOST_BPF to scripts/bpf_helpers_doc.py
hannahyp Jul 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gconfig.ghost
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x86_64:CONFIG_SCHED_CLASS_GHOST=y
x86_64 and debug:CONFIG_DEBUG_GHOST=y
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ghOSt: Fast &amp; Flexible User-Space Delegation of Linux Scheduling

ghOSt is a general-purpose delegation of scheduling policy implemented on top of
the Linux kernel. The ghOSt framework provides a rich API that receives
scheduling decisions for processes from userspace and actuates them as
transactions. Programmers can use any language or tools to develop policies,
which can be upgraded without a machine reboot. ghOSt supports policies for a
range of scheduling objectives, from µs-scale latency, to throughput, to energy
efficiency, and beyond, and incurs low overheads for scheduling actions. Many
policies are just a few hundred lines of code. Overall, ghOSt provides a
performant framework for delegation of thread scheduling policy to userspace
processes that enables policy optimization, non-disruptive upgrades, and fault
isolation.

[SOSP '21 Paper](https://dl.acm.org/doi/10.1145/3477132.3483542)\
[SOSP '21 Talk](https://youtu.be/j4ABe4dsbIY)

You must compile and install this kernel in order to use the [ghOSt userspace
component](https://www.github.com/google/ghost-userspace).

This kernel is Linux 5.11. We recommend installing Ubuntu 20.04 LTS, which ships
with Linux 5.4 by default, as the distribution. Compile this kernel on Ubuntu
20.04 and then replace the existing 5.4 kernel with this one.

This is not an officially supported Google product.
7 changes: 7 additions & 0 deletions arch/x86/include/asm/preempt.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,18 @@ static __always_inline bool __preempt_count_dec_and_test(void)
return GEN_UNARY_RMWcc("decl", __preempt_count, e, __percpu_arg([var]));
}

#ifdef CONFIG_SCHED_CLASS_GHOST
extern void ghost_commit_greedy_txn(void);
#endif

/*
* Returns true when we need to resched and can (barring IRQ state).
*/
static __always_inline bool should_resched(int preempt_offset)
{
#ifdef CONFIG_SCHED_CLASS_GHOST
ghost_commit_greedy_txn();
#endif
return unlikely(raw_cpu_read_4(__preempt_count) == preempt_offset);
}

Expand Down
2 changes: 1 addition & 1 deletion fs/eventpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
* the same lock on wakeup ep_poll_callback() side, so it
* is safe to avoid an explicit barrier.
*/
__set_current_state(TASK_INTERRUPTIBLE);
__set_current_state(TASK_INTERRUPTIBLE|__TASK_DEFERRABLE_WAKEUP);

/*
* Do the final check under the lock. ep_scan_ready_list()
Expand Down
31 changes: 31 additions & 0 deletions fs/kernfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,29 @@ static __poll_t kernfs_fop_poll(struct file *filp, poll_table *wait)
return ret;
}

static long kernfs_fop_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
struct kernfs_open_file *of = kernfs_of(file);
const struct kernfs_ops *ops;
long ret;

/*
* Not locking of->mutex: you can have concurrent ioctl calls on the
* same file.
*/
if (!kernfs_get_active(of->kn))
return -ENODEV;
ops = kernfs_ops(of->kn);
if (ops->ioctl)
ret = ops->ioctl(of, cmd, arg);
else
ret = -ENOIOCTLCMD;
kernfs_put_active(of->kn);

return ret;
}

static void kernfs_notify_workfn(struct work_struct *work)
{
struct kernfs_node *kn;
Expand Down Expand Up @@ -948,11 +971,19 @@ const struct file_operations kernfs_file_fops = {
.open = kernfs_fop_open,
.release = kernfs_fop_release,
.poll = kernfs_fop_poll,
.unlocked_ioctl = kernfs_fop_ioctl,
.fsync = noop_fsync,
.splice_read = generic_file_splice_read,
.splice_write = iter_file_splice_write,
};

struct kernfs_node *kernfs_node_from_file(struct file *file)
{
if (file->f_op != &kernfs_file_fops)
return NULL;
return file->f_inode->i_private;
}

/**
* __kernfs_create_file - kernfs internal function to create a file
* @parent: directory to create the file in
Expand Down
64 changes: 64 additions & 0 deletions fs/proc/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -3156,6 +3156,11 @@ static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns,
static const struct file_operations proc_task_operations;
static const struct inode_operations proc_task_inode_operations;

#ifdef CONFIG_SCHED_CLASS_GHOST
static const struct file_operations proc_ghost_dir_operations;
static const struct inode_operations proc_ghost_dir_inode_operations;
#endif

static const struct pid_entry tgid_base_stuff[] = {
DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
Expand Down Expand Up @@ -3266,6 +3271,10 @@ static const struct pid_entry tgid_base_stuff[] = {
#ifdef CONFIG_SECCOMP_CACHE_DEBUG
ONE("seccomp_cache", S_IRUSR, proc_pid_seccomp_cache),
#endif
#ifdef CONFIG_SCHED_CLASS_GHOST
DIR("ghost", S_IRUGO|S_IXUGO, proc_ghost_dir_inode_operations,
proc_ghost_dir_operations),
#endif
};

static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx)
Expand Down Expand Up @@ -3831,3 +3840,58 @@ void __init set_proc_pid_nlink(void)
nlink_tid = pid_entry_nlink(tid_base_stuff, ARRAY_SIZE(tid_base_stuff));
nlink_tgid = pid_entry_nlink(tgid_base_stuff, ARRAY_SIZE(tgid_base_stuff));
}

#ifdef CONFIG_SCHED_CLASS_GHOST

static ssize_t proc_ghost_gtid_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
struct task_struct *task = get_proc_task(file_inode(file));
char buffer[32];
size_t len;

if (!task)
return -ESRCH;

len = snprintf(buffer, sizeof(buffer), "%ld\n",
task->gtid);
WARN_ON_ONCE(len >= sizeof(buffer));
put_task_struct(task);
return simple_read_from_buffer(buf, count, ppos, buffer, len);
}

static const struct file_operations proc_ghost_gtid_operations = {
.read = proc_ghost_gtid_read,
.llseek = generic_file_llseek,
};

static const struct pid_entry ghost_dir_stuff[] = {
REG("gtid", S_IRUGO, proc_ghost_gtid_operations),
};

static struct dentry *proc_ghost_dir_lookup(struct inode *dir,
struct dentry *dentry,
unsigned int flags)
{
return proc_pident_lookup(dir, dentry, ghost_dir_stuff,
ghost_dir_stuff + ARRAY_SIZE(ghost_dir_stuff));
}

static int proc_ghost_dir_readdir(struct file *file, struct dir_context *ctx)
{
return proc_pident_readdir(file, ctx, ghost_dir_stuff,
ARRAY_SIZE(ghost_dir_stuff));
}

static const struct inode_operations proc_ghost_dir_inode_operations = {
.lookup = proc_ghost_dir_lookup,
.getattr = pid_getattr,
};

static const struct file_operations proc_ghost_dir_operations = {
.read = generic_read_dir,
.iterate_shared = proc_ghost_dir_readdir,
.llseek = default_llseek,
};

#endif
41 changes: 39 additions & 2 deletions fs/timerfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ struct timerfd_ctx {
struct list_head clist;
spinlock_t cancel_lock;
bool might_cancel;
#ifdef CONFIG_SCHED_CLASS_GHOST
struct __kernel_timerfd_ghost timerfd_ghost;
#endif
};

static LIST_HEAD(cancel_list);
Expand All @@ -64,11 +67,26 @@ static void timerfd_triggered(struct timerfd_ctx *ctx)
{
unsigned long flags;

#ifdef CONFIG_SCHED_CLASS_GHOST
struct __kernel_timerfd_ghost timerfd_ghost = {
.enabled = false,
};
#endif

spin_lock_irqsave(&ctx->wqh.lock, flags);
ctx->expired = 1;
ctx->ticks++;
wake_up_locked_poll(&ctx->wqh, EPOLLIN);
#ifdef CONFIG_SCHED_CLASS_GHOST
if (unlikely(&ctx->timerfd_ghost.enabled))
timerfd_ghost = ctx->timerfd_ghost;
#endif
spin_unlock_irqrestore(&ctx->wqh.lock, flags);

#ifdef CONFIG_SCHED_CLASS_GHOST
if (unlikely(timerfd_ghost.enabled))
ghost_timerfd_triggered(&timerfd_ghost);
#endif
}

static enum hrtimer_restart timerfd_tmrproc(struct hrtimer *htmr)
Expand Down Expand Up @@ -435,9 +453,15 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)
return ufd;
}

static int do_timerfd_settime(int ufd, int flags,
#ifdef CONFIG_SCHED_CLASS_GHOST
int do_timerfd_settime(int ufd, int flags, const struct itimerspec64 *new,
struct itimerspec64 *old,
struct __kernel_timerfd_ghost *ktfd)
#else
static int do_timerfd_settime(int ufd, int flags,
const struct itimerspec64 *new,
struct itimerspec64 *old)
#endif
{
struct fd f;
struct timerfd_ctx *ctx;
Expand Down Expand Up @@ -501,7 +525,12 @@ static int do_timerfd_settime(int ufd, int flags,
* Re-program the timer to the new value ...
*/
ret = timerfd_setup(ctx, flags, new);

#ifdef CONFIG_SCHED_CLASS_GHOST
if (ktfd)
memcpy(&ctx->timerfd_ghost, ktfd, sizeof(*ktfd));
else
ctx->timerfd_ghost.enabled = false;
#endif
spin_unlock_irq(&ctx->wqh.lock);
fdput(f);
return ret;
Expand Down Expand Up @@ -548,7 +577,11 @@ SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags,

if (get_itimerspec64(&new, utmr))
return -EFAULT;
#ifdef CONFIG_SCHED_CLASS_GHOST
ret = do_timerfd_settime(ufd, flags, &new, &old, NULL);
#else
ret = do_timerfd_settime(ufd, flags, &new, &old);
#endif
if (ret)
return ret;
if (otmr && put_itimerspec64(&old, otmr))
Expand Down Expand Up @@ -576,7 +609,11 @@ SYSCALL_DEFINE4(timerfd_settime32, int, ufd, int, flags,

if (get_old_itimerspec32(&new, utmr))
return -EFAULT;
#ifdef CONFIG_SCHED_CLASS_GHOST
ret = do_timerfd_settime(ufd, flags, &new, &old, NULL);
#else
ret = do_timerfd_settime(ufd, flags, &new, &old);
#endif
if (ret)
return ret;
if (otmr && put_old_itimerspec32(&old, otmr))
Expand Down
25 changes: 25 additions & 0 deletions include/asm-generic/vmlinux.lds.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,29 @@
* used to determine the order of the priority of each sched class in
* relation to each other.
*/
#ifdef CONFIG_SCHED_CLASS_GHOST
#define SCHED_DATA \
STRUCT_ALIGN(); \
__begin_sched_classes = .; \
*(__idle_sched_class) \
*(__ghost_sched_class) \
*(__fair_sched_class) \
*(__rt_sched_class) \
*(__dl_sched_class) \
*(__ghost_agent_sched_class) \
*(__stop_sched_class) \
__end_sched_classes = .;
#else
#define SCHED_DATA \
STRUCT_ALIGN(); \
__begin_sched_classes = .; \
*(__idle_sched_class) \
*(__fair_sched_class) \
*(__rt_sched_class) \
*(__dl_sched_class) \
*(__stop_sched_class) \
__end_sched_classes = .;
#endif

/* The actual configuration determine if the init/exit sections
* are handled as text/data or they can be discarded (which
Expand Down Expand Up @@ -409,13 +423,24 @@
__end_ro_after_init = .;
#endif

#ifdef CONFIG_SCHED_CLASS_GHOST
#define GHOST_ABI_RODATA \
STRUCT_ALIGN(); \
__begin_ghost_abi = .; \
*(.rodata.ghost_abi) \
__end_ghost_abi = .;
#else
#define GHOST_ABI_RODATA
#endif

/*
* Read only Data
*/
#define RO_DATA(align) \
. = ALIGN((align)); \
.rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
__start_rodata = .; \
GHOST_ABI_RODATA \
*(.rodata) *(.rodata.*) \
SCHED_DATA \
RO_AFTER_INIT_DATA /* Read only after init */ \
Expand Down
7 changes: 6 additions & 1 deletion include/linux/bpf_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_LSM, lsm,
void *, void *)
#endif /* CONFIG_BPF_LSM */
#endif

#ifdef CONFIG_SCHED_CLASS_GHOST
BPF_PROG_TYPE(BPF_PROG_TYPE_GHOST_SCHED, ghost_sched, struct bpf_ghost_sched,
struct bpf_ghost_sched_kern)
BPF_PROG_TYPE(BPF_PROG_TYPE_GHOST_MSG, ghost_msg, struct bpf_ghost_msg,
struct bpf_ghost_msg_kern)
#endif
BPF_MAP_TYPE(BPF_MAP_TYPE_ARRAY, array_map_ops)
BPF_MAP_TYPE(BPF_MAP_TYPE_PERCPU_ARRAY, percpu_array_map_ops)
BPF_MAP_TYPE(BPF_MAP_TYPE_PROG_ARRAY, prog_array_map_ops)
Expand Down
13 changes: 13 additions & 0 deletions include/linux/ghost.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _LINUX_GHOST_H_
#define _LINUX_GHOST_H_

/*
* Empty header to satisfy inclusions like <linux/ghost.h> which if this
* file were not present would end up resolving to <uapi/linux/ghost.h>
*
* We care about this because including <uapi/linux/ghost.h> has abi
* implications so we want this header to be included explicitly.
*/

#endif /* _LINUX_GHOST_H_ */

4 changes: 4 additions & 0 deletions include/linux/kernfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ struct kernfs_ops {
__poll_t (*poll)(struct kernfs_open_file *of,
struct poll_table_struct *pt);

long (*ioctl)(struct kernfs_open_file *of, unsigned int cmd,
unsigned long arg);

int (*mmap)(struct kernfs_open_file *of, struct vm_area_struct *vma);

#ifdef CONFIG_DEBUG_LOCK_ALLOC
Expand Down Expand Up @@ -357,6 +360,7 @@ void kernfs_get(struct kernfs_node *kn);
void kernfs_put(struct kernfs_node *kn);

struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry);
struct kernfs_node *kernfs_node_from_file(struct file *file);
struct kernfs_root *kernfs_root_from_sb(struct super_block *sb);
struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn);

Expand Down
Loading