Skip to content

Commit

Permalink
Merge branch 'robadams-procfs' into 'linux-6.6.y-memorizer-dev'
Browse files Browse the repository at this point in the history
Robadams procfs

See merge request ring0/memorizer!43
  • Loading branch information
illinoisrobert committed Oct 30, 2024
2 parents 4537012 + 661ca2a commit 36a34d2
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions Documentation/memorizer/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Summary of memorizer-specific kernel versions
- taskset "SMP" instructions
- Add test using baremetal.config
- Reorganize some of the documentation.
- Add /proc/<pid>/memorizer_enabled

- v6.6.51-memorizer-26

Expand Down
10 changes: 10 additions & 0 deletions Documentation/memorizer/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ Memorizer provides control, data, and status values through the
Linux ``debugfs`` filesystem. The ``debugfs`` filesystem is
conventionally mounted at ``/sys/kernel/debug/`` and the Memorizer
files are in the ``/sys/kernel/debug/memorizer/`` directory.
Memorizer files are in the ``/sys/kernel/debug/memorizer/`` directory,
with the single exception of ``/proc/<pid>/memorizer_enabled``.

Control Files
~~~~~~~~~~~~~
Expand Down Expand Up @@ -202,6 +204,14 @@ Control Files
- `READ` - The current Memorizer mode and, optionally, the
process-id of a Memorizer-enabled process.

``/proc/<pid>/memorizer_enabled``
- `WRITE` - Set or clear the memorizable status of the indicated
`process`. If a process is memorizable and memorizer is in mode
``2`` or ``3``, then the process and all of its subsequently created
child processes will be tracked.
This value is unused in modes ``0`` and ``1``.
- `READ` - The current memorizable status of the indicated process.

``log_accesses_enabled``
- `WRITE` - Writing any boolean value enables or disables the tracing
of memory reads and writes.
Expand Down
56 changes: 56 additions & 0 deletions fs/proc/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -3217,6 +3217,59 @@ static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns,
}
#endif /* CONFIG_KSM */

#ifdef CONFIG_MEMORIZER
static int proc_memorizer_enabled_show(struct seq_file *m, void *v)
{
struct inode *inode = m->private;
struct task_struct *task = get_proc_task(inode);

if (!task)
return -ESRCH;

seq_printf(m, "%d\n", task->memorizer_enabled);

put_task_struct(task);
return 0;
}

static ssize_t proc_memorizer_enabled_write(struct file *file,
const char __user *buf,
size_t count,
loff_t *ppos)
{
struct task_struct *task;
bool val;
int ret;

ret = kstrtobool_from_user(buf, count, &val);
if (ret < 0)
return ret;

task = get_proc_task(file_inode(file));
if (!task)
return -ESRCH;

task->memorizer_enabled = val;

put_task_struct(task);

return count;
}

static int proc_memorizer_enabled_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_memorizer_enabled_show, inode);
}

static const struct file_operations proc_memorizer_enabled_operations = {
.open = proc_memorizer_enabled_open,
.read = seq_read,
.write = proc_memorizer_enabled_write,
.llseek = seq_lseek,
.release = single_release,
};
#endif

#ifdef CONFIG_STACKLEAK_METRICS
static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *task)
Expand Down Expand Up @@ -3352,6 +3405,9 @@ static const struct pid_entry tgid_base_stuff[] = {
ONE("ksm_merging_pages", S_IRUSR, proc_pid_ksm_merging_pages),
ONE("ksm_stat", S_IRUSR, proc_pid_ksm_stat),
#endif
#ifdef CONFIG_MEMORIZER
REG("memorizer_enabled", S_IRUSR|S_IWUSR, proc_memorizer_enabled_operations),
#endif
};

static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx)
Expand Down
21 changes: 21 additions & 0 deletions scripts/memorizer/test/root/test/mztest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@
echo -n 0 > /sys/kernel/debug/memorizer/memorizer_enabled
}

@test "/proc/self/memorizer_enabled exists" {
[ "$(</proc/self/memorizer_enabled)" = "0" ]
[ "$(</proc/$$/memorizer_enabled)" = "0" ]
}

setup() {
echo -n 0 > /sys/kernel/debug/memorizer/memorizer_enabled
echo -n 0 > /proc/self/memorizer_enabled
}

@test "/proc/self/memorizer_enabled can be written/read" {
[ "$(</proc/self/memorizer_enabled)" = "0" ]
[ "$(</proc/$$/memorizer_enabled)" = "0" ]
echo -n yes > /proc/$$/memorizer_enabled
[ "$(</proc/self/memorizer_enabled)" = "1" ]
[ "$(</proc/$$/memorizer_enabled)" = "1" ]
echo -n no > /proc/self/memorizer_enabled
[ "$(</proc/self/memorizer_enabled)" = "0" ]
[ "$(</proc/$$/memorizer_enabled)" = "0" ]
}

@test "ls" {
echo -n 1 > /sys/kernel/debug/memorizer/clear_dead_objects
cp /sys/kernel/debug/memorizer/kmap /dev/null
Expand Down

0 comments on commit 36a34d2

Please sign in to comment.