-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproc.c
More file actions
170 lines (144 loc) · 3.59 KB
/
proc.c
File metadata and controls
170 lines (144 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* SPDX-License-Identifier: GPL-2.0
* Copyright (c) 2026 Ant Group Corporation.
*/
#include <linux/errno.h>
#include <linux/sysctl.h>
#include <linux/gfp.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/seq_file.h>
#include <linux/proc_fs.h>
#include <linux/version.h>
#include "proc.h"
#include "slimvm.h"
#include "vmx.h"
#include "instance.h"
#define SLIMVM_OP_RECLAIM_LEAKED_INSTANCES 100678677
static struct ctl_table_header *slimvm_sysctl_header;
static int slimvm_vcpu_num;
static int slimvm_vm_num;
static long slimvm_operation_code;
int slimvm_debug_enable;
static struct proc_dir_entry *slimvm_proc_dir;
static struct proc_dir_entry *vm_mem_stat;
static int read_vcpu_num(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp,
loff_t *ppos)
{
slimvm_vcpu_num = instance_get_vcpu_num();
proc_dointvec(table, write, buffer, lenp, ppos);
return 0;
}
static int read_vm_num(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp,
loff_t *ppos)
{
slimvm_vm_num = instance_get_vm_num();
proc_dointvec(table, write, buffer, lenp, ppos);
return 0;
}
static int slimvm_do_operation(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp, loff_t *ppos)
{
proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
if (write) {
switch (slimvm_operation_code) {
case SLIMVM_OP_RECLAIM_LEAKED_INSTANCES:
slimvm_reclaim_leaked_instances();
break;
default:
return -EINVAL;
}
}
return 0;
}
struct ctl_table slimvm_table[] = {
{
.procname = "slimvm_vcpu_num",
.data = &slimvm_vcpu_num,
.maxlen = sizeof(int),
.mode = 0444,
.proc_handler = read_vcpu_num
},
{
.procname = "slimvm_vm_num",
.data = &slimvm_vm_num,
.maxlen = sizeof(int),
.mode = 0444,
.proc_handler = read_vm_num
},
{
.procname = "slimvm_operation",
.data = &slimvm_operation_code,
.maxlen = sizeof(unsigned long),
.mode = 0200,
.proc_handler = slimvm_do_operation,
},
{
.procname = "slimvm_debug_enable",
.data = &slimvm_debug_enable,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec,
},
{ }
};
struct ctl_table slimvm_sysctl_table[] = {
{
.procname = "slimvm",
.mode = 0555,
.child = slimvm_table,
},
{ }
};
static void ept_show_vm_mem_stat(struct instance *instp, void *data)
{
char buf[128];
struct seq_file *seq = data;
sprintf(buf, "%lx %lld %lld %lld %llx %lld\n",
instp->sid, instp->ept_4k_pages, instp->ept_2m_pages,
instp->ept_invl_count, instp->ept_invl_range,
instp->ept_invl_ipi);
seq_puts(seq, buf);
}
static int ept_stat_show(struct seq_file *seq, void *offset)
{
seq_puts(seq, "SID 4K 2M invl_count invl_range invl_ipi\n");
on_each_vm_instance(ept_show_vm_mem_stat, seq);
return 0;
}
static int ept_stat_open(struct inode *inode, struct file *file)
{
return single_open(file, ept_stat_show, NULL);
}
static const struct proc_ops vm_mem_stat_fops = {
.proc_open = ept_stat_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = single_release,
};
bool slimvm_sysctl_init(void)
{
char buf[64];
slimvm_sysctl_header = register_sysctl_table(slimvm_sysctl_table);
if (!slimvm_sysctl_header)
return false;
sprintf(buf, "slimvm");
slimvm_proc_dir = proc_mkdir(buf, NULL);
if (slimvm_proc_dir)
vm_mem_stat = proc_create("vm_mem_stat", 0444,
slimvm_proc_dir, &vm_mem_stat_fops);
return true;
}
void slimvm_sysctl_exit(void)
{
if (vm_mem_stat)
proc_remove(vm_mem_stat);
if (slimvm_proc_dir)
proc_remove(slimvm_proc_dir);
if (slimvm_sysctl_header) {
unregister_sysctl_table(slimvm_sysctl_header);
slimvm_sysctl_header = NULL;
}
}