This source file includes following definitions.
- rdt_last_cmd_clear
- rdt_last_cmd_puts
- rdt_last_cmd_printf
- closids_supported
- closid_init
- closid_alloc
- closid_free
- closid_allocated
- rdtgroup_mode_by_closid
- rdtgroup_mode_str
- rdtgroup_kn_set_ugid
- rdtgroup_add_file
- rdtgroup_seqfile_show
- rdtgroup_file_write
- is_cpu_list
- rdtgroup_cpus_show
- update_cpu_closid_rmid
- update_closid_rmid
- cpus_mon_write
- cpumask_rdtgrp_clear
- cpus_ctrl_write
- rdtgroup_cpus_write
- move_myself
- __rdtgroup_move_task
- rdtgroup_tasks_assigned
- rdtgroup_task_write_permission
- rdtgroup_move_task
- rdtgroup_tasks_write
- show_rdt_tasks
- rdtgroup_tasks_show
- rdt_last_cmd_status_show
- rdt_num_closids_show
- rdt_default_ctrl_show
- rdt_min_cbm_bits_show
- rdt_shareable_bits_show
- rdt_bit_usage_show
- rdt_min_bw_show
- rdt_num_rmids_show
- rdt_mon_features_show
- rdt_bw_gran_show
- rdt_delay_linear_show
- max_threshold_occ_show
- max_threshold_occ_write
- rdtgroup_mode_show
- rdt_cdp_peer_get
- __rdtgroup_cbm_overlaps
- rdtgroup_cbm_overlaps
- rdtgroup_mode_test_exclusive
- rdtgroup_mode_write
- rdtgroup_cbm_to_size
- rdtgroup_size_show
- rdtgroup_add_files
- rdtgroup_kn_mode_restrict
- rdtgroup_kn_mode_restore
- rdtgroup_mkdir_info_resdir
- rdtgroup_create_info_dir
- mongroup_create_dir
- l3_qos_cfg_update
- l2_qos_cfg_update
- is_mba_linear
- set_cache_qos_cfg
- rdt_domain_reconfigure_cdp
- set_mba_sc
- cdp_enable
- cdpl3_enable
- cdpl2_enable
- cdp_disable
- cdpl3_disable
- cdpl2_disable
- cdp_disable_all
- kernfs_to_rdtgroup
- rdtgroup_kn_lock_live
- rdtgroup_kn_unlock
- rdt_enable_ctx
- rdt_get_tree
- rdt_parse_param
- rdt_fs_context_free
- rdt_init_fs_context
- reset_all_ctrls
- is_closid_match
- is_rmid_match
- rdt_move_group_tasks
- free_all_child_rdtgrp
- rmdir_all_sub
- rdt_kill_sb
- mon_addfile
- rmdir_mondata_subdir_allrdtgrp
- mkdir_mondata_subdir
- mkdir_mondata_subdir_allrdtgrp
- mkdir_mondata_subdir_alldom
- mkdir_mondata_all
- cbm_ensure_valid
- __init_one_rdt_domain
- rdtgroup_init_cat
- rdtgroup_init_mba
- rdtgroup_init_alloc
- mkdir_rdt_prepare
- mkdir_rdt_prepare_clean
- rdtgroup_mkdir_mon
- rdtgroup_mkdir_ctrl_mon
- is_mon_groups
- rdtgroup_mkdir
- rdtgroup_rmdir_mon
- rdtgroup_ctrl_remove
- rdtgroup_rmdir_ctrl
- rdtgroup_rmdir
- rdtgroup_show_options
- rdtgroup_setup_root
- rdtgroup_init
- rdtgroup_exit
1
2
3
4
5
6
7
8
9
10
11
12
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
15 #include <linux/cacheinfo.h>
16 #include <linux/cpu.h>
17 #include <linux/debugfs.h>
18 #include <linux/fs.h>
19 #include <linux/fs_parser.h>
20 #include <linux/sysfs.h>
21 #include <linux/kernfs.h>
22 #include <linux/seq_buf.h>
23 #include <linux/seq_file.h>
24 #include <linux/sched/signal.h>
25 #include <linux/sched/task.h>
26 #include <linux/slab.h>
27 #include <linux/task_work.h>
28 #include <linux/user_namespace.h>
29
30 #include <uapi/linux/magic.h>
31
32 #include <asm/resctrl_sched.h>
33 #include "internal.h"
34
35 DEFINE_STATIC_KEY_FALSE(rdt_enable_key);
36 DEFINE_STATIC_KEY_FALSE(rdt_mon_enable_key);
37 DEFINE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
38 static struct kernfs_root *rdt_root;
39 struct rdtgroup rdtgroup_default;
40 LIST_HEAD(rdt_all_groups);
41
42
43 static struct kernfs_node *kn_info;
44
45
46 static struct kernfs_node *kn_mongrp;
47
48
49 static struct kernfs_node *kn_mondata;
50
51 static struct seq_buf last_cmd_status;
52 static char last_cmd_status_buf[512];
53
54 struct dentry *debugfs_resctrl;
55
56 void rdt_last_cmd_clear(void)
57 {
58 lockdep_assert_held(&rdtgroup_mutex);
59 seq_buf_clear(&last_cmd_status);
60 }
61
62 void rdt_last_cmd_puts(const char *s)
63 {
64 lockdep_assert_held(&rdtgroup_mutex);
65 seq_buf_puts(&last_cmd_status, s);
66 }
67
68 void rdt_last_cmd_printf(const char *fmt, ...)
69 {
70 va_list ap;
71
72 va_start(ap, fmt);
73 lockdep_assert_held(&rdtgroup_mutex);
74 seq_buf_vprintf(&last_cmd_status, fmt, ap);
75 va_end(ap);
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 static int closid_free_map;
94 static int closid_free_map_len;
95
96 int closids_supported(void)
97 {
98 return closid_free_map_len;
99 }
100
101 static void closid_init(void)
102 {
103 struct rdt_resource *r;
104 int rdt_min_closid = 32;
105
106
107 for_each_alloc_enabled_rdt_resource(r)
108 rdt_min_closid = min(rdt_min_closid, r->num_closid);
109
110 closid_free_map = BIT_MASK(rdt_min_closid) - 1;
111
112
113 closid_free_map &= ~1;
114 closid_free_map_len = rdt_min_closid;
115 }
116
117 static int closid_alloc(void)
118 {
119 u32 closid = ffs(closid_free_map);
120
121 if (closid == 0)
122 return -ENOSPC;
123 closid--;
124 closid_free_map &= ~(1 << closid);
125
126 return closid;
127 }
128
129 void closid_free(int closid)
130 {
131 closid_free_map |= 1 << closid;
132 }
133
134
135
136
137
138
139
140
141 static bool closid_allocated(unsigned int closid)
142 {
143 return (closid_free_map & (1 << closid)) == 0;
144 }
145
146
147
148
149
150
151
152
153
154
155 enum rdtgrp_mode rdtgroup_mode_by_closid(int closid)
156 {
157 struct rdtgroup *rdtgrp;
158
159 list_for_each_entry(rdtgrp, &rdt_all_groups, rdtgroup_list) {
160 if (rdtgrp->closid == closid)
161 return rdtgrp->mode;
162 }
163
164 return RDT_NUM_MODES;
165 }
166
167 static const char * const rdt_mode_str[] = {
168 [RDT_MODE_SHAREABLE] = "shareable",
169 [RDT_MODE_EXCLUSIVE] = "exclusive",
170 [RDT_MODE_PSEUDO_LOCKSETUP] = "pseudo-locksetup",
171 [RDT_MODE_PSEUDO_LOCKED] = "pseudo-locked",
172 };
173
174
175
176
177
178
179
180 static const char *rdtgroup_mode_str(enum rdtgrp_mode mode)
181 {
182 if (mode < RDT_MODE_SHAREABLE || mode >= RDT_NUM_MODES)
183 return "unknown";
184
185 return rdt_mode_str[mode];
186 }
187
188
189 static int rdtgroup_kn_set_ugid(struct kernfs_node *kn)
190 {
191 struct iattr iattr = { .ia_valid = ATTR_UID | ATTR_GID,
192 .ia_uid = current_fsuid(),
193 .ia_gid = current_fsgid(), };
194
195 if (uid_eq(iattr.ia_uid, GLOBAL_ROOT_UID) &&
196 gid_eq(iattr.ia_gid, GLOBAL_ROOT_GID))
197 return 0;
198
199 return kernfs_setattr(kn, &iattr);
200 }
201
202 static int rdtgroup_add_file(struct kernfs_node *parent_kn, struct rftype *rft)
203 {
204 struct kernfs_node *kn;
205 int ret;
206
207 kn = __kernfs_create_file(parent_kn, rft->name, rft->mode,
208 GLOBAL_ROOT_UID, GLOBAL_ROOT_GID,
209 0, rft->kf_ops, rft, NULL, NULL);
210 if (IS_ERR(kn))
211 return PTR_ERR(kn);
212
213 ret = rdtgroup_kn_set_ugid(kn);
214 if (ret) {
215 kernfs_remove(kn);
216 return ret;
217 }
218
219 return 0;
220 }
221
222 static int rdtgroup_seqfile_show(struct seq_file *m, void *arg)
223 {
224 struct kernfs_open_file *of = m->private;
225 struct rftype *rft = of->kn->priv;
226
227 if (rft->seq_show)
228 return rft->seq_show(of, m, arg);
229 return 0;
230 }
231
232 static ssize_t rdtgroup_file_write(struct kernfs_open_file *of, char *buf,
233 size_t nbytes, loff_t off)
234 {
235 struct rftype *rft = of->kn->priv;
236
237 if (rft->write)
238 return rft->write(of, buf, nbytes, off);
239
240 return -EINVAL;
241 }
242
243 static struct kernfs_ops rdtgroup_kf_single_ops = {
244 .atomic_write_len = PAGE_SIZE,
245 .write = rdtgroup_file_write,
246 .seq_show = rdtgroup_seqfile_show,
247 };
248
249 static struct kernfs_ops kf_mondata_ops = {
250 .atomic_write_len = PAGE_SIZE,
251 .seq_show = rdtgroup_mondata_show,
252 };
253
254 static bool is_cpu_list(struct kernfs_open_file *of)
255 {
256 struct rftype *rft = of->kn->priv;
257
258 return rft->flags & RFTYPE_FLAGS_CPUS_LIST;
259 }
260
261 static int rdtgroup_cpus_show(struct kernfs_open_file *of,
262 struct seq_file *s, void *v)
263 {
264 struct rdtgroup *rdtgrp;
265 struct cpumask *mask;
266 int ret = 0;
267
268 rdtgrp = rdtgroup_kn_lock_live(of->kn);
269
270 if (rdtgrp) {
271 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
272 if (!rdtgrp->plr->d) {
273 rdt_last_cmd_clear();
274 rdt_last_cmd_puts("Cache domain offline\n");
275 ret = -ENODEV;
276 } else {
277 mask = &rdtgrp->plr->d->cpu_mask;
278 seq_printf(s, is_cpu_list(of) ?
279 "%*pbl\n" : "%*pb\n",
280 cpumask_pr_args(mask));
281 }
282 } else {
283 seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n",
284 cpumask_pr_args(&rdtgrp->cpu_mask));
285 }
286 } else {
287 ret = -ENOENT;
288 }
289 rdtgroup_kn_unlock(of->kn);
290
291 return ret;
292 }
293
294
295
296
297
298
299
300 static void update_cpu_closid_rmid(void *info)
301 {
302 struct rdtgroup *r = info;
303
304 if (r) {
305 this_cpu_write(pqr_state.default_closid, r->closid);
306 this_cpu_write(pqr_state.default_rmid, r->mon.rmid);
307 }
308
309
310
311
312
313
314 resctrl_sched_in();
315 }
316
317
318
319
320
321
322 static void
323 update_closid_rmid(const struct cpumask *cpu_mask, struct rdtgroup *r)
324 {
325 int cpu = get_cpu();
326
327 if (cpumask_test_cpu(cpu, cpu_mask))
328 update_cpu_closid_rmid(r);
329 smp_call_function_many(cpu_mask, update_cpu_closid_rmid, r, 1);
330 put_cpu();
331 }
332
333 static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
334 cpumask_var_t tmpmask)
335 {
336 struct rdtgroup *prgrp = rdtgrp->mon.parent, *crgrp;
337 struct list_head *head;
338
339
340 cpumask_andnot(tmpmask, newmask, &prgrp->cpu_mask);
341 if (cpumask_weight(tmpmask)) {
342 rdt_last_cmd_puts("Can only add CPUs to mongroup that belong to parent\n");
343 return -EINVAL;
344 }
345
346
347 cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
348 if (cpumask_weight(tmpmask)) {
349
350 cpumask_or(&prgrp->cpu_mask, &prgrp->cpu_mask, tmpmask);
351 update_closid_rmid(tmpmask, prgrp);
352 }
353
354
355
356
357
358 cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
359 if (cpumask_weight(tmpmask)) {
360 head = &prgrp->mon.crdtgrp_list;
361 list_for_each_entry(crgrp, head, mon.crdtgrp_list) {
362 if (crgrp == rdtgrp)
363 continue;
364 cpumask_andnot(&crgrp->cpu_mask, &crgrp->cpu_mask,
365 tmpmask);
366 }
367 update_closid_rmid(tmpmask, rdtgrp);
368 }
369
370
371 cpumask_copy(&rdtgrp->cpu_mask, newmask);
372
373 return 0;
374 }
375
376 static void cpumask_rdtgrp_clear(struct rdtgroup *r, struct cpumask *m)
377 {
378 struct rdtgroup *crgrp;
379
380 cpumask_andnot(&r->cpu_mask, &r->cpu_mask, m);
381
382 list_for_each_entry(crgrp, &r->mon.crdtgrp_list, mon.crdtgrp_list)
383 cpumask_and(&crgrp->cpu_mask, &r->cpu_mask, &crgrp->cpu_mask);
384 }
385
386 static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
387 cpumask_var_t tmpmask, cpumask_var_t tmpmask1)
388 {
389 struct rdtgroup *r, *crgrp;
390 struct list_head *head;
391
392
393 cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
394 if (cpumask_weight(tmpmask)) {
395
396 if (rdtgrp == &rdtgroup_default) {
397 rdt_last_cmd_puts("Can't drop CPUs from default group\n");
398 return -EINVAL;
399 }
400
401
402 cpumask_or(&rdtgroup_default.cpu_mask,
403 &rdtgroup_default.cpu_mask, tmpmask);
404 update_closid_rmid(tmpmask, &rdtgroup_default);
405 }
406
407
408
409
410
411
412 cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
413 if (cpumask_weight(tmpmask)) {
414 list_for_each_entry(r, &rdt_all_groups, rdtgroup_list) {
415 if (r == rdtgrp)
416 continue;
417 cpumask_and(tmpmask1, &r->cpu_mask, tmpmask);
418 if (cpumask_weight(tmpmask1))
419 cpumask_rdtgrp_clear(r, tmpmask1);
420 }
421 update_closid_rmid(tmpmask, rdtgrp);
422 }
423
424
425 cpumask_copy(&rdtgrp->cpu_mask, newmask);
426
427
428
429
430
431 head = &rdtgrp->mon.crdtgrp_list;
432 list_for_each_entry(crgrp, head, mon.crdtgrp_list) {
433 cpumask_and(tmpmask, &rdtgrp->cpu_mask, &crgrp->cpu_mask);
434 update_closid_rmid(tmpmask, rdtgrp);
435 cpumask_clear(&crgrp->cpu_mask);
436 }
437
438 return 0;
439 }
440
441 static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
442 char *buf, size_t nbytes, loff_t off)
443 {
444 cpumask_var_t tmpmask, newmask, tmpmask1;
445 struct rdtgroup *rdtgrp;
446 int ret;
447
448 if (!buf)
449 return -EINVAL;
450
451 if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL))
452 return -ENOMEM;
453 if (!zalloc_cpumask_var(&newmask, GFP_KERNEL)) {
454 free_cpumask_var(tmpmask);
455 return -ENOMEM;
456 }
457 if (!zalloc_cpumask_var(&tmpmask1, GFP_KERNEL)) {
458 free_cpumask_var(tmpmask);
459 free_cpumask_var(newmask);
460 return -ENOMEM;
461 }
462
463 rdtgrp = rdtgroup_kn_lock_live(of->kn);
464 if (!rdtgrp) {
465 ret = -ENOENT;
466 goto unlock;
467 }
468
469 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED ||
470 rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
471 ret = -EINVAL;
472 rdt_last_cmd_puts("Pseudo-locking in progress\n");
473 goto unlock;
474 }
475
476 if (is_cpu_list(of))
477 ret = cpulist_parse(buf, newmask);
478 else
479 ret = cpumask_parse(buf, newmask);
480
481 if (ret) {
482 rdt_last_cmd_puts("Bad CPU list/mask\n");
483 goto unlock;
484 }
485
486
487 cpumask_andnot(tmpmask, newmask, cpu_online_mask);
488 if (cpumask_weight(tmpmask)) {
489 ret = -EINVAL;
490 rdt_last_cmd_puts("Can only assign online CPUs\n");
491 goto unlock;
492 }
493
494 if (rdtgrp->type == RDTCTRL_GROUP)
495 ret = cpus_ctrl_write(rdtgrp, newmask, tmpmask, tmpmask1);
496 else if (rdtgrp->type == RDTMON_GROUP)
497 ret = cpus_mon_write(rdtgrp, newmask, tmpmask);
498 else
499 ret = -EINVAL;
500
501 unlock:
502 rdtgroup_kn_unlock(of->kn);
503 free_cpumask_var(tmpmask);
504 free_cpumask_var(newmask);
505 free_cpumask_var(tmpmask1);
506
507 return ret ?: nbytes;
508 }
509
510 struct task_move_callback {
511 struct callback_head work;
512 struct rdtgroup *rdtgrp;
513 };
514
515 static void move_myself(struct callback_head *head)
516 {
517 struct task_move_callback *callback;
518 struct rdtgroup *rdtgrp;
519
520 callback = container_of(head, struct task_move_callback, work);
521 rdtgrp = callback->rdtgrp;
522
523
524
525
526
527
528 if (atomic_dec_and_test(&rdtgrp->waitcount) &&
529 (rdtgrp->flags & RDT_DELETED)) {
530 current->closid = 0;
531 current->rmid = 0;
532 kfree(rdtgrp);
533 }
534
535 preempt_disable();
536
537 resctrl_sched_in();
538 preempt_enable();
539
540 kfree(callback);
541 }
542
543 static int __rdtgroup_move_task(struct task_struct *tsk,
544 struct rdtgroup *rdtgrp)
545 {
546 struct task_move_callback *callback;
547 int ret;
548
549 callback = kzalloc(sizeof(*callback), GFP_KERNEL);
550 if (!callback)
551 return -ENOMEM;
552 callback->work.func = move_myself;
553 callback->rdtgrp = rdtgrp;
554
555
556
557
558
559 atomic_inc(&rdtgrp->waitcount);
560 ret = task_work_add(tsk, &callback->work, true);
561 if (ret) {
562
563
564
565
566
567 atomic_dec(&rdtgrp->waitcount);
568 kfree(callback);
569 rdt_last_cmd_puts("Task exited\n");
570 } else {
571
572
573
574
575
576 if (rdtgrp->type == RDTCTRL_GROUP) {
577 tsk->closid = rdtgrp->closid;
578 tsk->rmid = rdtgrp->mon.rmid;
579 } else if (rdtgrp->type == RDTMON_GROUP) {
580 if (rdtgrp->mon.parent->closid == tsk->closid) {
581 tsk->rmid = rdtgrp->mon.rmid;
582 } else {
583 rdt_last_cmd_puts("Can't move task to different control group\n");
584 ret = -EINVAL;
585 }
586 }
587 }
588 return ret;
589 }
590
591
592
593
594
595
596
597 int rdtgroup_tasks_assigned(struct rdtgroup *r)
598 {
599 struct task_struct *p, *t;
600 int ret = 0;
601
602 lockdep_assert_held(&rdtgroup_mutex);
603
604 rcu_read_lock();
605 for_each_process_thread(p, t) {
606 if ((r->type == RDTCTRL_GROUP && t->closid == r->closid) ||
607 (r->type == RDTMON_GROUP && t->rmid == r->mon.rmid)) {
608 ret = 1;
609 break;
610 }
611 }
612 rcu_read_unlock();
613
614 return ret;
615 }
616
617 static int rdtgroup_task_write_permission(struct task_struct *task,
618 struct kernfs_open_file *of)
619 {
620 const struct cred *tcred = get_task_cred(task);
621 const struct cred *cred = current_cred();
622 int ret = 0;
623
624
625
626
627
628 if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
629 !uid_eq(cred->euid, tcred->uid) &&
630 !uid_eq(cred->euid, tcred->suid)) {
631 rdt_last_cmd_printf("No permission to move task %d\n", task->pid);
632 ret = -EPERM;
633 }
634
635 put_cred(tcred);
636 return ret;
637 }
638
639 static int rdtgroup_move_task(pid_t pid, struct rdtgroup *rdtgrp,
640 struct kernfs_open_file *of)
641 {
642 struct task_struct *tsk;
643 int ret;
644
645 rcu_read_lock();
646 if (pid) {
647 tsk = find_task_by_vpid(pid);
648 if (!tsk) {
649 rcu_read_unlock();
650 rdt_last_cmd_printf("No task %d\n", pid);
651 return -ESRCH;
652 }
653 } else {
654 tsk = current;
655 }
656
657 get_task_struct(tsk);
658 rcu_read_unlock();
659
660 ret = rdtgroup_task_write_permission(tsk, of);
661 if (!ret)
662 ret = __rdtgroup_move_task(tsk, rdtgrp);
663
664 put_task_struct(tsk);
665 return ret;
666 }
667
668 static ssize_t rdtgroup_tasks_write(struct kernfs_open_file *of,
669 char *buf, size_t nbytes, loff_t off)
670 {
671 struct rdtgroup *rdtgrp;
672 int ret = 0;
673 pid_t pid;
674
675 if (kstrtoint(strstrip(buf), 0, &pid) || pid < 0)
676 return -EINVAL;
677 rdtgrp = rdtgroup_kn_lock_live(of->kn);
678 if (!rdtgrp) {
679 rdtgroup_kn_unlock(of->kn);
680 return -ENOENT;
681 }
682 rdt_last_cmd_clear();
683
684 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED ||
685 rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
686 ret = -EINVAL;
687 rdt_last_cmd_puts("Pseudo-locking in progress\n");
688 goto unlock;
689 }
690
691 ret = rdtgroup_move_task(pid, rdtgrp, of);
692
693 unlock:
694 rdtgroup_kn_unlock(of->kn);
695
696 return ret ?: nbytes;
697 }
698
699 static void show_rdt_tasks(struct rdtgroup *r, struct seq_file *s)
700 {
701 struct task_struct *p, *t;
702
703 rcu_read_lock();
704 for_each_process_thread(p, t) {
705 if ((r->type == RDTCTRL_GROUP && t->closid == r->closid) ||
706 (r->type == RDTMON_GROUP && t->rmid == r->mon.rmid))
707 seq_printf(s, "%d\n", t->pid);
708 }
709 rcu_read_unlock();
710 }
711
712 static int rdtgroup_tasks_show(struct kernfs_open_file *of,
713 struct seq_file *s, void *v)
714 {
715 struct rdtgroup *rdtgrp;
716 int ret = 0;
717
718 rdtgrp = rdtgroup_kn_lock_live(of->kn);
719 if (rdtgrp)
720 show_rdt_tasks(rdtgrp, s);
721 else
722 ret = -ENOENT;
723 rdtgroup_kn_unlock(of->kn);
724
725 return ret;
726 }
727
728 static int rdt_last_cmd_status_show(struct kernfs_open_file *of,
729 struct seq_file *seq, void *v)
730 {
731 int len;
732
733 mutex_lock(&rdtgroup_mutex);
734 len = seq_buf_used(&last_cmd_status);
735 if (len)
736 seq_printf(seq, "%.*s", len, last_cmd_status_buf);
737 else
738 seq_puts(seq, "ok\n");
739 mutex_unlock(&rdtgroup_mutex);
740 return 0;
741 }
742
743 static int rdt_num_closids_show(struct kernfs_open_file *of,
744 struct seq_file *seq, void *v)
745 {
746 struct rdt_resource *r = of->kn->parent->priv;
747
748 seq_printf(seq, "%d\n", r->num_closid);
749 return 0;
750 }
751
752 static int rdt_default_ctrl_show(struct kernfs_open_file *of,
753 struct seq_file *seq, void *v)
754 {
755 struct rdt_resource *r = of->kn->parent->priv;
756
757 seq_printf(seq, "%x\n", r->default_ctrl);
758 return 0;
759 }
760
761 static int rdt_min_cbm_bits_show(struct kernfs_open_file *of,
762 struct seq_file *seq, void *v)
763 {
764 struct rdt_resource *r = of->kn->parent->priv;
765
766 seq_printf(seq, "%u\n", r->cache.min_cbm_bits);
767 return 0;
768 }
769
770 static int rdt_shareable_bits_show(struct kernfs_open_file *of,
771 struct seq_file *seq, void *v)
772 {
773 struct rdt_resource *r = of->kn->parent->priv;
774
775 seq_printf(seq, "%x\n", r->cache.shareable_bits);
776 return 0;
777 }
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793 static int rdt_bit_usage_show(struct kernfs_open_file *of,
794 struct seq_file *seq, void *v)
795 {
796 struct rdt_resource *r = of->kn->parent->priv;
797
798
799
800
801 unsigned long sw_shareable = 0, hw_shareable = 0;
802 unsigned long exclusive = 0, pseudo_locked = 0;
803 struct rdt_domain *dom;
804 int i, hwb, swb, excl, psl;
805 enum rdtgrp_mode mode;
806 bool sep = false;
807 u32 *ctrl;
808
809 mutex_lock(&rdtgroup_mutex);
810 hw_shareable = r->cache.shareable_bits;
811 list_for_each_entry(dom, &r->domains, list) {
812 if (sep)
813 seq_putc(seq, ';');
814 ctrl = dom->ctrl_val;
815 sw_shareable = 0;
816 exclusive = 0;
817 seq_printf(seq, "%d=", dom->id);
818 for (i = 0; i < closids_supported(); i++, ctrl++) {
819 if (!closid_allocated(i))
820 continue;
821 mode = rdtgroup_mode_by_closid(i);
822 switch (mode) {
823 case RDT_MODE_SHAREABLE:
824 sw_shareable |= *ctrl;
825 break;
826 case RDT_MODE_EXCLUSIVE:
827 exclusive |= *ctrl;
828 break;
829 case RDT_MODE_PSEUDO_LOCKSETUP:
830
831
832
833
834
835
836
837 break;
838 case RDT_MODE_PSEUDO_LOCKED:
839 case RDT_NUM_MODES:
840 WARN(1,
841 "invalid mode for closid %d\n", i);
842 break;
843 }
844 }
845 for (i = r->cache.cbm_len - 1; i >= 0; i--) {
846 pseudo_locked = dom->plr ? dom->plr->cbm : 0;
847 hwb = test_bit(i, &hw_shareable);
848 swb = test_bit(i, &sw_shareable);
849 excl = test_bit(i, &exclusive);
850 psl = test_bit(i, &pseudo_locked);
851 if (hwb && swb)
852 seq_putc(seq, 'X');
853 else if (hwb && !swb)
854 seq_putc(seq, 'H');
855 else if (!hwb && swb)
856 seq_putc(seq, 'S');
857 else if (excl)
858 seq_putc(seq, 'E');
859 else if (psl)
860 seq_putc(seq, 'P');
861 else
862 seq_putc(seq, '0');
863 }
864 sep = true;
865 }
866 seq_putc(seq, '\n');
867 mutex_unlock(&rdtgroup_mutex);
868 return 0;
869 }
870
871 static int rdt_min_bw_show(struct kernfs_open_file *of,
872 struct seq_file *seq, void *v)
873 {
874 struct rdt_resource *r = of->kn->parent->priv;
875
876 seq_printf(seq, "%u\n", r->membw.min_bw);
877 return 0;
878 }
879
880 static int rdt_num_rmids_show(struct kernfs_open_file *of,
881 struct seq_file *seq, void *v)
882 {
883 struct rdt_resource *r = of->kn->parent->priv;
884
885 seq_printf(seq, "%d\n", r->num_rmid);
886
887 return 0;
888 }
889
890 static int rdt_mon_features_show(struct kernfs_open_file *of,
891 struct seq_file *seq, void *v)
892 {
893 struct rdt_resource *r = of->kn->parent->priv;
894 struct mon_evt *mevt;
895
896 list_for_each_entry(mevt, &r->evt_list, list)
897 seq_printf(seq, "%s\n", mevt->name);
898
899 return 0;
900 }
901
902 static int rdt_bw_gran_show(struct kernfs_open_file *of,
903 struct seq_file *seq, void *v)
904 {
905 struct rdt_resource *r = of->kn->parent->priv;
906
907 seq_printf(seq, "%u\n", r->membw.bw_gran);
908 return 0;
909 }
910
911 static int rdt_delay_linear_show(struct kernfs_open_file *of,
912 struct seq_file *seq, void *v)
913 {
914 struct rdt_resource *r = of->kn->parent->priv;
915
916 seq_printf(seq, "%u\n", r->membw.delay_linear);
917 return 0;
918 }
919
920 static int max_threshold_occ_show(struct kernfs_open_file *of,
921 struct seq_file *seq, void *v)
922 {
923 struct rdt_resource *r = of->kn->parent->priv;
924
925 seq_printf(seq, "%u\n", resctrl_cqm_threshold * r->mon_scale);
926
927 return 0;
928 }
929
930 static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
931 char *buf, size_t nbytes, loff_t off)
932 {
933 struct rdt_resource *r = of->kn->parent->priv;
934 unsigned int bytes;
935 int ret;
936
937 ret = kstrtouint(buf, 0, &bytes);
938 if (ret)
939 return ret;
940
941 if (bytes > (boot_cpu_data.x86_cache_size * 1024))
942 return -EINVAL;
943
944 resctrl_cqm_threshold = bytes / r->mon_scale;
945
946 return nbytes;
947 }
948
949
950
951
952 static int rdtgroup_mode_show(struct kernfs_open_file *of,
953 struct seq_file *s, void *v)
954 {
955 struct rdtgroup *rdtgrp;
956
957 rdtgrp = rdtgroup_kn_lock_live(of->kn);
958 if (!rdtgrp) {
959 rdtgroup_kn_unlock(of->kn);
960 return -ENOENT;
961 }
962
963 seq_printf(s, "%s\n", rdtgroup_mode_str(rdtgrp->mode));
964
965 rdtgroup_kn_unlock(of->kn);
966 return 0;
967 }
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992 static int rdt_cdp_peer_get(struct rdt_resource *r, struct rdt_domain *d,
993 struct rdt_resource **r_cdp,
994 struct rdt_domain **d_cdp)
995 {
996 struct rdt_resource *_r_cdp = NULL;
997 struct rdt_domain *_d_cdp = NULL;
998 int ret = 0;
999
1000 switch (r->rid) {
1001 case RDT_RESOURCE_L3DATA:
1002 _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3CODE];
1003 break;
1004 case RDT_RESOURCE_L3CODE:
1005 _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3DATA];
1006 break;
1007 case RDT_RESOURCE_L2DATA:
1008 _r_cdp = &rdt_resources_all[RDT_RESOURCE_L2CODE];
1009 break;
1010 case RDT_RESOURCE_L2CODE:
1011 _r_cdp = &rdt_resources_all[RDT_RESOURCE_L2DATA];
1012 break;
1013 default:
1014 ret = -ENOENT;
1015 goto out;
1016 }
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027 _d_cdp = rdt_find_domain(_r_cdp, d->id, NULL);
1028 if (WARN_ON(IS_ERR_OR_NULL(_d_cdp))) {
1029 _r_cdp = NULL;
1030 ret = -EINVAL;
1031 }
1032
1033 out:
1034 *r_cdp = _r_cdp;
1035 *d_cdp = _d_cdp;
1036
1037 return ret;
1038 }
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060 static bool __rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
1061 unsigned long cbm, int closid, bool exclusive)
1062 {
1063 enum rdtgrp_mode mode;
1064 unsigned long ctrl_b;
1065 u32 *ctrl;
1066 int i;
1067
1068
1069 if (!exclusive) {
1070 ctrl_b = r->cache.shareable_bits;
1071 if (bitmap_intersects(&cbm, &ctrl_b, r->cache.cbm_len))
1072 return true;
1073 }
1074
1075
1076 ctrl = d->ctrl_val;
1077 for (i = 0; i < closids_supported(); i++, ctrl++) {
1078 ctrl_b = *ctrl;
1079 mode = rdtgroup_mode_by_closid(i);
1080 if (closid_allocated(i) && i != closid &&
1081 mode != RDT_MODE_PSEUDO_LOCKSETUP) {
1082 if (bitmap_intersects(&cbm, &ctrl_b, r->cache.cbm_len)) {
1083 if (exclusive) {
1084 if (mode == RDT_MODE_EXCLUSIVE)
1085 return true;
1086 continue;
1087 }
1088 return true;
1089 }
1090 }
1091 }
1092
1093 return false;
1094 }
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116 bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
1117 unsigned long cbm, int closid, bool exclusive)
1118 {
1119 struct rdt_resource *r_cdp;
1120 struct rdt_domain *d_cdp;
1121
1122 if (__rdtgroup_cbm_overlaps(r, d, cbm, closid, exclusive))
1123 return true;
1124
1125 if (rdt_cdp_peer_get(r, d, &r_cdp, &d_cdp) < 0)
1126 return false;
1127
1128 return __rdtgroup_cbm_overlaps(r_cdp, d_cdp, cbm, closid, exclusive);
1129 }
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143 static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)
1144 {
1145 int closid = rdtgrp->closid;
1146 struct rdt_resource *r;
1147 bool has_cache = false;
1148 struct rdt_domain *d;
1149
1150 for_each_alloc_enabled_rdt_resource(r) {
1151 if (r->rid == RDT_RESOURCE_MBA)
1152 continue;
1153 has_cache = true;
1154 list_for_each_entry(d, &r->domains, list) {
1155 if (rdtgroup_cbm_overlaps(r, d, d->ctrl_val[closid],
1156 rdtgrp->closid, false)) {
1157 rdt_last_cmd_puts("Schemata overlaps\n");
1158 return false;
1159 }
1160 }
1161 }
1162
1163 if (!has_cache) {
1164 rdt_last_cmd_puts("Cannot be exclusive without CAT/CDP\n");
1165 return false;
1166 }
1167
1168 return true;
1169 }
1170
1171
1172
1173
1174
1175 static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
1176 char *buf, size_t nbytes, loff_t off)
1177 {
1178 struct rdtgroup *rdtgrp;
1179 enum rdtgrp_mode mode;
1180 int ret = 0;
1181
1182
1183 if (nbytes == 0 || buf[nbytes - 1] != '\n')
1184 return -EINVAL;
1185 buf[nbytes - 1] = '\0';
1186
1187 rdtgrp = rdtgroup_kn_lock_live(of->kn);
1188 if (!rdtgrp) {
1189 rdtgroup_kn_unlock(of->kn);
1190 return -ENOENT;
1191 }
1192
1193 rdt_last_cmd_clear();
1194
1195 mode = rdtgrp->mode;
1196
1197 if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE) ||
1198 (!strcmp(buf, "exclusive") && mode == RDT_MODE_EXCLUSIVE) ||
1199 (!strcmp(buf, "pseudo-locksetup") &&
1200 mode == RDT_MODE_PSEUDO_LOCKSETUP) ||
1201 (!strcmp(buf, "pseudo-locked") && mode == RDT_MODE_PSEUDO_LOCKED))
1202 goto out;
1203
1204 if (mode == RDT_MODE_PSEUDO_LOCKED) {
1205 rdt_last_cmd_puts("Cannot change pseudo-locked group\n");
1206 ret = -EINVAL;
1207 goto out;
1208 }
1209
1210 if (!strcmp(buf, "shareable")) {
1211 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
1212 ret = rdtgroup_locksetup_exit(rdtgrp);
1213 if (ret)
1214 goto out;
1215 }
1216 rdtgrp->mode = RDT_MODE_SHAREABLE;
1217 } else if (!strcmp(buf, "exclusive")) {
1218 if (!rdtgroup_mode_test_exclusive(rdtgrp)) {
1219 ret = -EINVAL;
1220 goto out;
1221 }
1222 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
1223 ret = rdtgroup_locksetup_exit(rdtgrp);
1224 if (ret)
1225 goto out;
1226 }
1227 rdtgrp->mode = RDT_MODE_EXCLUSIVE;
1228 } else if (!strcmp(buf, "pseudo-locksetup")) {
1229 ret = rdtgroup_locksetup_enter(rdtgrp);
1230 if (ret)
1231 goto out;
1232 rdtgrp->mode = RDT_MODE_PSEUDO_LOCKSETUP;
1233 } else {
1234 rdt_last_cmd_puts("Unknown or unsupported mode\n");
1235 ret = -EINVAL;
1236 }
1237
1238 out:
1239 rdtgroup_kn_unlock(of->kn);
1240 return ret ?: nbytes;
1241 }
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258 unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,
1259 struct rdt_domain *d, unsigned long cbm)
1260 {
1261 struct cpu_cacheinfo *ci;
1262 unsigned int size = 0;
1263 int num_b, i;
1264
1265 num_b = bitmap_weight(&cbm, r->cache.cbm_len);
1266 ci = get_cpu_cacheinfo(cpumask_any(&d->cpu_mask));
1267 for (i = 0; i < ci->num_leaves; i++) {
1268 if (ci->info_list[i].level == r->cache_level) {
1269 size = ci->info_list[i].size / r->cache.cbm_len * num_b;
1270 break;
1271 }
1272 }
1273
1274 return size;
1275 }
1276
1277
1278
1279
1280
1281
1282
1283
1284 static int rdtgroup_size_show(struct kernfs_open_file *of,
1285 struct seq_file *s, void *v)
1286 {
1287 struct rdtgroup *rdtgrp;
1288 struct rdt_resource *r;
1289 struct rdt_domain *d;
1290 unsigned int size;
1291 int ret = 0;
1292 bool sep;
1293 u32 ctrl;
1294
1295 rdtgrp = rdtgroup_kn_lock_live(of->kn);
1296 if (!rdtgrp) {
1297 rdtgroup_kn_unlock(of->kn);
1298 return -ENOENT;
1299 }
1300
1301 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
1302 if (!rdtgrp->plr->d) {
1303 rdt_last_cmd_clear();
1304 rdt_last_cmd_puts("Cache domain offline\n");
1305 ret = -ENODEV;
1306 } else {
1307 seq_printf(s, "%*s:", max_name_width,
1308 rdtgrp->plr->r->name);
1309 size = rdtgroup_cbm_to_size(rdtgrp->plr->r,
1310 rdtgrp->plr->d,
1311 rdtgrp->plr->cbm);
1312 seq_printf(s, "%d=%u\n", rdtgrp->plr->d->id, size);
1313 }
1314 goto out;
1315 }
1316
1317 for_each_alloc_enabled_rdt_resource(r) {
1318 sep = false;
1319 seq_printf(s, "%*s:", max_name_width, r->name);
1320 list_for_each_entry(d, &r->domains, list) {
1321 if (sep)
1322 seq_putc(s, ';');
1323 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
1324 size = 0;
1325 } else {
1326 ctrl = (!is_mba_sc(r) ?
1327 d->ctrl_val[rdtgrp->closid] :
1328 d->mbps_val[rdtgrp->closid]);
1329 if (r->rid == RDT_RESOURCE_MBA)
1330 size = ctrl;
1331 else
1332 size = rdtgroup_cbm_to_size(r, d, ctrl);
1333 }
1334 seq_printf(s, "%d=%u", d->id, size);
1335 sep = true;
1336 }
1337 seq_putc(s, '\n');
1338 }
1339
1340 out:
1341 rdtgroup_kn_unlock(of->kn);
1342
1343 return ret;
1344 }
1345
1346
1347 static struct rftype res_common_files[] = {
1348 {
1349 .name = "last_cmd_status",
1350 .mode = 0444,
1351 .kf_ops = &rdtgroup_kf_single_ops,
1352 .seq_show = rdt_last_cmd_status_show,
1353 .fflags = RF_TOP_INFO,
1354 },
1355 {
1356 .name = "num_closids",
1357 .mode = 0444,
1358 .kf_ops = &rdtgroup_kf_single_ops,
1359 .seq_show = rdt_num_closids_show,
1360 .fflags = RF_CTRL_INFO,
1361 },
1362 {
1363 .name = "mon_features",
1364 .mode = 0444,
1365 .kf_ops = &rdtgroup_kf_single_ops,
1366 .seq_show = rdt_mon_features_show,
1367 .fflags = RF_MON_INFO,
1368 },
1369 {
1370 .name = "num_rmids",
1371 .mode = 0444,
1372 .kf_ops = &rdtgroup_kf_single_ops,
1373 .seq_show = rdt_num_rmids_show,
1374 .fflags = RF_MON_INFO,
1375 },
1376 {
1377 .name = "cbm_mask",
1378 .mode = 0444,
1379 .kf_ops = &rdtgroup_kf_single_ops,
1380 .seq_show = rdt_default_ctrl_show,
1381 .fflags = RF_CTRL_INFO | RFTYPE_RES_CACHE,
1382 },
1383 {
1384 .name = "min_cbm_bits",
1385 .mode = 0444,
1386 .kf_ops = &rdtgroup_kf_single_ops,
1387 .seq_show = rdt_min_cbm_bits_show,
1388 .fflags = RF_CTRL_INFO | RFTYPE_RES_CACHE,
1389 },
1390 {
1391 .name = "shareable_bits",
1392 .mode = 0444,
1393 .kf_ops = &rdtgroup_kf_single_ops,
1394 .seq_show = rdt_shareable_bits_show,
1395 .fflags = RF_CTRL_INFO | RFTYPE_RES_CACHE,
1396 },
1397 {
1398 .name = "bit_usage",
1399 .mode = 0444,
1400 .kf_ops = &rdtgroup_kf_single_ops,
1401 .seq_show = rdt_bit_usage_show,
1402 .fflags = RF_CTRL_INFO | RFTYPE_RES_CACHE,
1403 },
1404 {
1405 .name = "min_bandwidth",
1406 .mode = 0444,
1407 .kf_ops = &rdtgroup_kf_single_ops,
1408 .seq_show = rdt_min_bw_show,
1409 .fflags = RF_CTRL_INFO | RFTYPE_RES_MB,
1410 },
1411 {
1412 .name = "bandwidth_gran",
1413 .mode = 0444,
1414 .kf_ops = &rdtgroup_kf_single_ops,
1415 .seq_show = rdt_bw_gran_show,
1416 .fflags = RF_CTRL_INFO | RFTYPE_RES_MB,
1417 },
1418 {
1419 .name = "delay_linear",
1420 .mode = 0444,
1421 .kf_ops = &rdtgroup_kf_single_ops,
1422 .seq_show = rdt_delay_linear_show,
1423 .fflags = RF_CTRL_INFO | RFTYPE_RES_MB,
1424 },
1425 {
1426 .name = "max_threshold_occupancy",
1427 .mode = 0644,
1428 .kf_ops = &rdtgroup_kf_single_ops,
1429 .write = max_threshold_occ_write,
1430 .seq_show = max_threshold_occ_show,
1431 .fflags = RF_MON_INFO | RFTYPE_RES_CACHE,
1432 },
1433 {
1434 .name = "cpus",
1435 .mode = 0644,
1436 .kf_ops = &rdtgroup_kf_single_ops,
1437 .write = rdtgroup_cpus_write,
1438 .seq_show = rdtgroup_cpus_show,
1439 .fflags = RFTYPE_BASE,
1440 },
1441 {
1442 .name = "cpus_list",
1443 .mode = 0644,
1444 .kf_ops = &rdtgroup_kf_single_ops,
1445 .write = rdtgroup_cpus_write,
1446 .seq_show = rdtgroup_cpus_show,
1447 .flags = RFTYPE_FLAGS_CPUS_LIST,
1448 .fflags = RFTYPE_BASE,
1449 },
1450 {
1451 .name = "tasks",
1452 .mode = 0644,
1453 .kf_ops = &rdtgroup_kf_single_ops,
1454 .write = rdtgroup_tasks_write,
1455 .seq_show = rdtgroup_tasks_show,
1456 .fflags = RFTYPE_BASE,
1457 },
1458 {
1459 .name = "schemata",
1460 .mode = 0644,
1461 .kf_ops = &rdtgroup_kf_single_ops,
1462 .write = rdtgroup_schemata_write,
1463 .seq_show = rdtgroup_schemata_show,
1464 .fflags = RF_CTRL_BASE,
1465 },
1466 {
1467 .name = "mode",
1468 .mode = 0644,
1469 .kf_ops = &rdtgroup_kf_single_ops,
1470 .write = rdtgroup_mode_write,
1471 .seq_show = rdtgroup_mode_show,
1472 .fflags = RF_CTRL_BASE,
1473 },
1474 {
1475 .name = "size",
1476 .mode = 0444,
1477 .kf_ops = &rdtgroup_kf_single_ops,
1478 .seq_show = rdtgroup_size_show,
1479 .fflags = RF_CTRL_BASE,
1480 },
1481
1482 };
1483
1484 static int rdtgroup_add_files(struct kernfs_node *kn, unsigned long fflags)
1485 {
1486 struct rftype *rfts, *rft;
1487 int ret, len;
1488
1489 rfts = res_common_files;
1490 len = ARRAY_SIZE(res_common_files);
1491
1492 lockdep_assert_held(&rdtgroup_mutex);
1493
1494 for (rft = rfts; rft < rfts + len; rft++) {
1495 if ((fflags & rft->fflags) == rft->fflags) {
1496 ret = rdtgroup_add_file(kn, rft);
1497 if (ret)
1498 goto error;
1499 }
1500 }
1501
1502 return 0;
1503 error:
1504 pr_warn("Failed to add %s, err=%d\n", rft->name, ret);
1505 while (--rft >= rfts) {
1506 if ((fflags & rft->fflags) == rft->fflags)
1507 kernfs_remove_by_name(kn, rft->name);
1508 }
1509 return ret;
1510 }
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529 int rdtgroup_kn_mode_restrict(struct rdtgroup *r, const char *name)
1530 {
1531 struct iattr iattr = {.ia_valid = ATTR_MODE,};
1532 struct kernfs_node *kn;
1533 int ret = 0;
1534
1535 kn = kernfs_find_and_get_ns(r->kn, name, NULL);
1536 if (!kn)
1537 return -ENOENT;
1538
1539 switch (kernfs_type(kn)) {
1540 case KERNFS_DIR:
1541 iattr.ia_mode = S_IFDIR;
1542 break;
1543 case KERNFS_FILE:
1544 iattr.ia_mode = S_IFREG;
1545 break;
1546 case KERNFS_LINK:
1547 iattr.ia_mode = S_IFLNK;
1548 break;
1549 }
1550
1551 ret = kernfs_setattr(kn, &iattr);
1552 kernfs_put(kn);
1553 return ret;
1554 }
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567 int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name,
1568 umode_t mask)
1569 {
1570 struct iattr iattr = {.ia_valid = ATTR_MODE,};
1571 struct kernfs_node *kn, *parent;
1572 struct rftype *rfts, *rft;
1573 int ret, len;
1574
1575 rfts = res_common_files;
1576 len = ARRAY_SIZE(res_common_files);
1577
1578 for (rft = rfts; rft < rfts + len; rft++) {
1579 if (!strcmp(rft->name, name))
1580 iattr.ia_mode = rft->mode & mask;
1581 }
1582
1583 kn = kernfs_find_and_get_ns(r->kn, name, NULL);
1584 if (!kn)
1585 return -ENOENT;
1586
1587 switch (kernfs_type(kn)) {
1588 case KERNFS_DIR:
1589 parent = kernfs_get_parent(kn);
1590 if (parent) {
1591 iattr.ia_mode |= parent->mode;
1592 kernfs_put(parent);
1593 }
1594 iattr.ia_mode |= S_IFDIR;
1595 break;
1596 case KERNFS_FILE:
1597 iattr.ia_mode |= S_IFREG;
1598 break;
1599 case KERNFS_LINK:
1600 iattr.ia_mode |= S_IFLNK;
1601 break;
1602 }
1603
1604 ret = kernfs_setattr(kn, &iattr);
1605 kernfs_put(kn);
1606 return ret;
1607 }
1608
1609 static int rdtgroup_mkdir_info_resdir(struct rdt_resource *r, char *name,
1610 unsigned long fflags)
1611 {
1612 struct kernfs_node *kn_subdir;
1613 int ret;
1614
1615 kn_subdir = kernfs_create_dir(kn_info, name,
1616 kn_info->mode, r);
1617 if (IS_ERR(kn_subdir))
1618 return PTR_ERR(kn_subdir);
1619
1620 kernfs_get(kn_subdir);
1621 ret = rdtgroup_kn_set_ugid(kn_subdir);
1622 if (ret)
1623 return ret;
1624
1625 ret = rdtgroup_add_files(kn_subdir, fflags);
1626 if (!ret)
1627 kernfs_activate(kn_subdir);
1628
1629 return ret;
1630 }
1631
1632 static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
1633 {
1634 struct rdt_resource *r;
1635 unsigned long fflags;
1636 char name[32];
1637 int ret;
1638
1639
1640 kn_info = kernfs_create_dir(parent_kn, "info", parent_kn->mode, NULL);
1641 if (IS_ERR(kn_info))
1642 return PTR_ERR(kn_info);
1643 kernfs_get(kn_info);
1644
1645 ret = rdtgroup_add_files(kn_info, RF_TOP_INFO);
1646 if (ret)
1647 goto out_destroy;
1648
1649 for_each_alloc_enabled_rdt_resource(r) {
1650 fflags = r->fflags | RF_CTRL_INFO;
1651 ret = rdtgroup_mkdir_info_resdir(r, r->name, fflags);
1652 if (ret)
1653 goto out_destroy;
1654 }
1655
1656 for_each_mon_enabled_rdt_resource(r) {
1657 fflags = r->fflags | RF_MON_INFO;
1658 sprintf(name, "%s_MON", r->name);
1659 ret = rdtgroup_mkdir_info_resdir(r, name, fflags);
1660 if (ret)
1661 goto out_destroy;
1662 }
1663
1664
1665
1666
1667
1668 kernfs_get(kn_info);
1669
1670 ret = rdtgroup_kn_set_ugid(kn_info);
1671 if (ret)
1672 goto out_destroy;
1673
1674 kernfs_activate(kn_info);
1675
1676 return 0;
1677
1678 out_destroy:
1679 kernfs_remove(kn_info);
1680 return ret;
1681 }
1682
1683 static int
1684 mongroup_create_dir(struct kernfs_node *parent_kn, struct rdtgroup *prgrp,
1685 char *name, struct kernfs_node **dest_kn)
1686 {
1687 struct kernfs_node *kn;
1688 int ret;
1689
1690
1691 kn = kernfs_create_dir(parent_kn, name, parent_kn->mode, prgrp);
1692 if (IS_ERR(kn))
1693 return PTR_ERR(kn);
1694
1695 if (dest_kn)
1696 *dest_kn = kn;
1697
1698
1699
1700
1701
1702 kernfs_get(kn);
1703
1704 ret = rdtgroup_kn_set_ugid(kn);
1705 if (ret)
1706 goto out_destroy;
1707
1708 kernfs_activate(kn);
1709
1710 return 0;
1711
1712 out_destroy:
1713 kernfs_remove(kn);
1714 return ret;
1715 }
1716
1717 static void l3_qos_cfg_update(void *arg)
1718 {
1719 bool *enable = arg;
1720
1721 wrmsrl(MSR_IA32_L3_QOS_CFG, *enable ? L3_QOS_CDP_ENABLE : 0ULL);
1722 }
1723
1724 static void l2_qos_cfg_update(void *arg)
1725 {
1726 bool *enable = arg;
1727
1728 wrmsrl(MSR_IA32_L2_QOS_CFG, *enable ? L2_QOS_CDP_ENABLE : 0ULL);
1729 }
1730
1731 static inline bool is_mba_linear(void)
1732 {
1733 return rdt_resources_all[RDT_RESOURCE_MBA].membw.delay_linear;
1734 }
1735
1736 static int set_cache_qos_cfg(int level, bool enable)
1737 {
1738 void (*update)(void *arg);
1739 struct rdt_resource *r_l;
1740 cpumask_var_t cpu_mask;
1741 struct rdt_domain *d;
1742 int cpu;
1743
1744 if (level == RDT_RESOURCE_L3)
1745 update = l3_qos_cfg_update;
1746 else if (level == RDT_RESOURCE_L2)
1747 update = l2_qos_cfg_update;
1748 else
1749 return -EINVAL;
1750
1751 if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
1752 return -ENOMEM;
1753
1754 r_l = &rdt_resources_all[level];
1755 list_for_each_entry(d, &r_l->domains, list) {
1756
1757 cpumask_set_cpu(cpumask_any(&d->cpu_mask), cpu_mask);
1758 }
1759 cpu = get_cpu();
1760
1761 if (cpumask_test_cpu(cpu, cpu_mask))
1762 update(&enable);
1763
1764 smp_call_function_many(cpu_mask, update, &enable, 1);
1765 put_cpu();
1766
1767 free_cpumask_var(cpu_mask);
1768
1769 return 0;
1770 }
1771
1772
1773 void rdt_domain_reconfigure_cdp(struct rdt_resource *r)
1774 {
1775 if (!r->alloc_capable)
1776 return;
1777
1778 if (r == &rdt_resources_all[RDT_RESOURCE_L2DATA])
1779 l2_qos_cfg_update(&r->alloc_enabled);
1780
1781 if (r == &rdt_resources_all[RDT_RESOURCE_L3DATA])
1782 l3_qos_cfg_update(&r->alloc_enabled);
1783 }
1784
1785
1786
1787
1788
1789
1790
1791 static int set_mba_sc(bool mba_sc)
1792 {
1793 struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA];
1794 struct rdt_domain *d;
1795
1796 if (!is_mbm_enabled() || !is_mba_linear() ||
1797 mba_sc == is_mba_sc(r))
1798 return -EINVAL;
1799
1800 r->membw.mba_sc = mba_sc;
1801 list_for_each_entry(d, &r->domains, list)
1802 setup_default_ctrlval(r, d->ctrl_val, d->mbps_val);
1803
1804 return 0;
1805 }
1806
1807 static int cdp_enable(int level, int data_type, int code_type)
1808 {
1809 struct rdt_resource *r_ldata = &rdt_resources_all[data_type];
1810 struct rdt_resource *r_lcode = &rdt_resources_all[code_type];
1811 struct rdt_resource *r_l = &rdt_resources_all[level];
1812 int ret;
1813
1814 if (!r_l->alloc_capable || !r_ldata->alloc_capable ||
1815 !r_lcode->alloc_capable)
1816 return -EINVAL;
1817
1818 ret = set_cache_qos_cfg(level, true);
1819 if (!ret) {
1820 r_l->alloc_enabled = false;
1821 r_ldata->alloc_enabled = true;
1822 r_lcode->alloc_enabled = true;
1823 }
1824 return ret;
1825 }
1826
1827 static int cdpl3_enable(void)
1828 {
1829 return cdp_enable(RDT_RESOURCE_L3, RDT_RESOURCE_L3DATA,
1830 RDT_RESOURCE_L3CODE);
1831 }
1832
1833 static int cdpl2_enable(void)
1834 {
1835 return cdp_enable(RDT_RESOURCE_L2, RDT_RESOURCE_L2DATA,
1836 RDT_RESOURCE_L2CODE);
1837 }
1838
1839 static void cdp_disable(int level, int data_type, int code_type)
1840 {
1841 struct rdt_resource *r = &rdt_resources_all[level];
1842
1843 r->alloc_enabled = r->alloc_capable;
1844
1845 if (rdt_resources_all[data_type].alloc_enabled) {
1846 rdt_resources_all[data_type].alloc_enabled = false;
1847 rdt_resources_all[code_type].alloc_enabled = false;
1848 set_cache_qos_cfg(level, false);
1849 }
1850 }
1851
1852 static void cdpl3_disable(void)
1853 {
1854 cdp_disable(RDT_RESOURCE_L3, RDT_RESOURCE_L3DATA, RDT_RESOURCE_L3CODE);
1855 }
1856
1857 static void cdpl2_disable(void)
1858 {
1859 cdp_disable(RDT_RESOURCE_L2, RDT_RESOURCE_L2DATA, RDT_RESOURCE_L2CODE);
1860 }
1861
1862 static void cdp_disable_all(void)
1863 {
1864 if (rdt_resources_all[RDT_RESOURCE_L3DATA].alloc_enabled)
1865 cdpl3_disable();
1866 if (rdt_resources_all[RDT_RESOURCE_L2DATA].alloc_enabled)
1867 cdpl2_disable();
1868 }
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878 static struct rdtgroup *kernfs_to_rdtgroup(struct kernfs_node *kn)
1879 {
1880 if (kernfs_type(kn) == KERNFS_DIR) {
1881
1882
1883
1884
1885
1886
1887 if (kn == kn_info || kn->parent == kn_info)
1888 return NULL;
1889 else
1890 return kn->priv;
1891 } else {
1892 return kn->parent->priv;
1893 }
1894 }
1895
1896 struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn)
1897 {
1898 struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn);
1899
1900 if (!rdtgrp)
1901 return NULL;
1902
1903 atomic_inc(&rdtgrp->waitcount);
1904 kernfs_break_active_protection(kn);
1905
1906 mutex_lock(&rdtgroup_mutex);
1907
1908
1909 if (rdtgrp->flags & RDT_DELETED)
1910 return NULL;
1911
1912 return rdtgrp;
1913 }
1914
1915 void rdtgroup_kn_unlock(struct kernfs_node *kn)
1916 {
1917 struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn);
1918
1919 if (!rdtgrp)
1920 return;
1921
1922 mutex_unlock(&rdtgroup_mutex);
1923
1924 if (atomic_dec_and_test(&rdtgrp->waitcount) &&
1925 (rdtgrp->flags & RDT_DELETED)) {
1926 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
1927 rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)
1928 rdtgroup_pseudo_lock_remove(rdtgrp);
1929 kernfs_unbreak_active_protection(kn);
1930 kernfs_put(rdtgrp->kn);
1931 kfree(rdtgrp);
1932 } else {
1933 kernfs_unbreak_active_protection(kn);
1934 }
1935 }
1936
1937 static int mkdir_mondata_all(struct kernfs_node *parent_kn,
1938 struct rdtgroup *prgrp,
1939 struct kernfs_node **mon_data_kn);
1940
1941 static int rdt_enable_ctx(struct rdt_fs_context *ctx)
1942 {
1943 int ret = 0;
1944
1945 if (ctx->enable_cdpl2)
1946 ret = cdpl2_enable();
1947
1948 if (!ret && ctx->enable_cdpl3)
1949 ret = cdpl3_enable();
1950
1951 if (!ret && ctx->enable_mba_mbps)
1952 ret = set_mba_sc(true);
1953
1954 return ret;
1955 }
1956
1957 static int rdt_get_tree(struct fs_context *fc)
1958 {
1959 struct rdt_fs_context *ctx = rdt_fc2context(fc);
1960 struct rdt_domain *dom;
1961 struct rdt_resource *r;
1962 int ret;
1963
1964 cpus_read_lock();
1965 mutex_lock(&rdtgroup_mutex);
1966
1967
1968
1969 if (static_branch_unlikely(&rdt_enable_key)) {
1970 ret = -EBUSY;
1971 goto out;
1972 }
1973
1974 ret = rdt_enable_ctx(ctx);
1975 if (ret < 0)
1976 goto out_cdp;
1977
1978 closid_init();
1979
1980 ret = rdtgroup_create_info_dir(rdtgroup_default.kn);
1981 if (ret < 0)
1982 goto out_mba;
1983
1984 if (rdt_mon_capable) {
1985 ret = mongroup_create_dir(rdtgroup_default.kn,
1986 &rdtgroup_default, "mon_groups",
1987 &kn_mongrp);
1988 if (ret < 0)
1989 goto out_info;
1990 kernfs_get(kn_mongrp);
1991
1992 ret = mkdir_mondata_all(rdtgroup_default.kn,
1993 &rdtgroup_default, &kn_mondata);
1994 if (ret < 0)
1995 goto out_mongrp;
1996 kernfs_get(kn_mondata);
1997 rdtgroup_default.mon.mon_data_kn = kn_mondata;
1998 }
1999
2000 ret = rdt_pseudo_lock_init();
2001 if (ret)
2002 goto out_mondata;
2003
2004 ret = kernfs_get_tree(fc);
2005 if (ret < 0)
2006 goto out_psl;
2007
2008 if (rdt_alloc_capable)
2009 static_branch_enable_cpuslocked(&rdt_alloc_enable_key);
2010 if (rdt_mon_capable)
2011 static_branch_enable_cpuslocked(&rdt_mon_enable_key);
2012
2013 if (rdt_alloc_capable || rdt_mon_capable)
2014 static_branch_enable_cpuslocked(&rdt_enable_key);
2015
2016 if (is_mbm_enabled()) {
2017 r = &rdt_resources_all[RDT_RESOURCE_L3];
2018 list_for_each_entry(dom, &r->domains, list)
2019 mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL);
2020 }
2021
2022 goto out;
2023
2024 out_psl:
2025 rdt_pseudo_lock_release();
2026 out_mondata:
2027 if (rdt_mon_capable)
2028 kernfs_remove(kn_mondata);
2029 out_mongrp:
2030 if (rdt_mon_capable)
2031 kernfs_remove(kn_mongrp);
2032 out_info:
2033 kernfs_remove(kn_info);
2034 out_mba:
2035 if (ctx->enable_mba_mbps)
2036 set_mba_sc(false);
2037 out_cdp:
2038 cdp_disable_all();
2039 out:
2040 rdt_last_cmd_clear();
2041 mutex_unlock(&rdtgroup_mutex);
2042 cpus_read_unlock();
2043 return ret;
2044 }
2045
2046 enum rdt_param {
2047 Opt_cdp,
2048 Opt_cdpl2,
2049 Opt_mba_mbps,
2050 nr__rdt_params
2051 };
2052
2053 static const struct fs_parameter_spec rdt_param_specs[] = {
2054 fsparam_flag("cdp", Opt_cdp),
2055 fsparam_flag("cdpl2", Opt_cdpl2),
2056 fsparam_flag("mba_MBps", Opt_mba_mbps),
2057 {}
2058 };
2059
2060 static const struct fs_parameter_description rdt_fs_parameters = {
2061 .name = "rdt",
2062 .specs = rdt_param_specs,
2063 };
2064
2065 static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param)
2066 {
2067 struct rdt_fs_context *ctx = rdt_fc2context(fc);
2068 struct fs_parse_result result;
2069 int opt;
2070
2071 opt = fs_parse(fc, &rdt_fs_parameters, param, &result);
2072 if (opt < 0)
2073 return opt;
2074
2075 switch (opt) {
2076 case Opt_cdp:
2077 ctx->enable_cdpl3 = true;
2078 return 0;
2079 case Opt_cdpl2:
2080 ctx->enable_cdpl2 = true;
2081 return 0;
2082 case Opt_mba_mbps:
2083 if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
2084 return -EINVAL;
2085 ctx->enable_mba_mbps = true;
2086 return 0;
2087 }
2088
2089 return -EINVAL;
2090 }
2091
2092 static void rdt_fs_context_free(struct fs_context *fc)
2093 {
2094 struct rdt_fs_context *ctx = rdt_fc2context(fc);
2095
2096 kernfs_free_fs_context(fc);
2097 kfree(ctx);
2098 }
2099
2100 static const struct fs_context_operations rdt_fs_context_ops = {
2101 .free = rdt_fs_context_free,
2102 .parse_param = rdt_parse_param,
2103 .get_tree = rdt_get_tree,
2104 };
2105
2106 static int rdt_init_fs_context(struct fs_context *fc)
2107 {
2108 struct rdt_fs_context *ctx;
2109
2110 ctx = kzalloc(sizeof(struct rdt_fs_context), GFP_KERNEL);
2111 if (!ctx)
2112 return -ENOMEM;
2113
2114 ctx->kfc.root = rdt_root;
2115 ctx->kfc.magic = RDTGROUP_SUPER_MAGIC;
2116 fc->fs_private = &ctx->kfc;
2117 fc->ops = &rdt_fs_context_ops;
2118 put_user_ns(fc->user_ns);
2119 fc->user_ns = get_user_ns(&init_user_ns);
2120 fc->global = true;
2121 return 0;
2122 }
2123
2124 static int reset_all_ctrls(struct rdt_resource *r)
2125 {
2126 struct msr_param msr_param;
2127 cpumask_var_t cpu_mask;
2128 struct rdt_domain *d;
2129 int i, cpu;
2130
2131 if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
2132 return -ENOMEM;
2133
2134 msr_param.res = r;
2135 msr_param.low = 0;
2136 msr_param.high = r->num_closid;
2137
2138
2139
2140
2141
2142
2143 list_for_each_entry(d, &r->domains, list) {
2144 cpumask_set_cpu(cpumask_any(&d->cpu_mask), cpu_mask);
2145
2146 for (i = 0; i < r->num_closid; i++)
2147 d->ctrl_val[i] = r->default_ctrl;
2148 }
2149 cpu = get_cpu();
2150
2151 if (cpumask_test_cpu(cpu, cpu_mask))
2152 rdt_ctrl_update(&msr_param);
2153
2154 smp_call_function_many(cpu_mask, rdt_ctrl_update, &msr_param, 1);
2155 put_cpu();
2156
2157 free_cpumask_var(cpu_mask);
2158
2159 return 0;
2160 }
2161
2162 static bool is_closid_match(struct task_struct *t, struct rdtgroup *r)
2163 {
2164 return (rdt_alloc_capable &&
2165 (r->type == RDTCTRL_GROUP) && (t->closid == r->closid));
2166 }
2167
2168 static bool is_rmid_match(struct task_struct *t, struct rdtgroup *r)
2169 {
2170 return (rdt_mon_capable &&
2171 (r->type == RDTMON_GROUP) && (t->rmid == r->mon.rmid));
2172 }
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182 static void rdt_move_group_tasks(struct rdtgroup *from, struct rdtgroup *to,
2183 struct cpumask *mask)
2184 {
2185 struct task_struct *p, *t;
2186
2187 read_lock(&tasklist_lock);
2188 for_each_process_thread(p, t) {
2189 if (!from || is_closid_match(t, from) ||
2190 is_rmid_match(t, from)) {
2191 t->closid = to->closid;
2192 t->rmid = to->mon.rmid;
2193
2194 #ifdef CONFIG_SMP
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204 if (mask && t->on_cpu)
2205 cpumask_set_cpu(task_cpu(t), mask);
2206 #endif
2207 }
2208 }
2209 read_unlock(&tasklist_lock);
2210 }
2211
2212 static void free_all_child_rdtgrp(struct rdtgroup *rdtgrp)
2213 {
2214 struct rdtgroup *sentry, *stmp;
2215 struct list_head *head;
2216
2217 head = &rdtgrp->mon.crdtgrp_list;
2218 list_for_each_entry_safe(sentry, stmp, head, mon.crdtgrp_list) {
2219 free_rmid(sentry->mon.rmid);
2220 list_del(&sentry->mon.crdtgrp_list);
2221
2222 if (atomic_read(&sentry->waitcount) != 0)
2223 sentry->flags = RDT_DELETED;
2224 else
2225 kfree(sentry);
2226 }
2227 }
2228
2229
2230
2231
2232 static void rmdir_all_sub(void)
2233 {
2234 struct rdtgroup *rdtgrp, *tmp;
2235
2236
2237 rdt_move_group_tasks(NULL, &rdtgroup_default, NULL);
2238
2239 list_for_each_entry_safe(rdtgrp, tmp, &rdt_all_groups, rdtgroup_list) {
2240
2241 free_all_child_rdtgrp(rdtgrp);
2242
2243
2244 if (rdtgrp == &rdtgroup_default)
2245 continue;
2246
2247 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
2248 rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)
2249 rdtgroup_pseudo_lock_remove(rdtgrp);
2250
2251
2252
2253
2254
2255
2256 cpumask_or(&rdtgroup_default.cpu_mask,
2257 &rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask);
2258
2259 free_rmid(rdtgrp->mon.rmid);
2260
2261 kernfs_remove(rdtgrp->kn);
2262 list_del(&rdtgrp->rdtgroup_list);
2263
2264 if (atomic_read(&rdtgrp->waitcount) != 0)
2265 rdtgrp->flags = RDT_DELETED;
2266 else
2267 kfree(rdtgrp);
2268 }
2269
2270 update_closid_rmid(cpu_online_mask, &rdtgroup_default);
2271
2272 kernfs_remove(kn_info);
2273 kernfs_remove(kn_mongrp);
2274 kernfs_remove(kn_mondata);
2275 }
2276
2277 static void rdt_kill_sb(struct super_block *sb)
2278 {
2279 struct rdt_resource *r;
2280
2281 cpus_read_lock();
2282 mutex_lock(&rdtgroup_mutex);
2283
2284 set_mba_sc(false);
2285
2286
2287 for_each_alloc_enabled_rdt_resource(r)
2288 reset_all_ctrls(r);
2289 cdp_disable_all();
2290 rmdir_all_sub();
2291 rdt_pseudo_lock_release();
2292 rdtgroup_default.mode = RDT_MODE_SHAREABLE;
2293 static_branch_disable_cpuslocked(&rdt_alloc_enable_key);
2294 static_branch_disable_cpuslocked(&rdt_mon_enable_key);
2295 static_branch_disable_cpuslocked(&rdt_enable_key);
2296 kernfs_kill_sb(sb);
2297 mutex_unlock(&rdtgroup_mutex);
2298 cpus_read_unlock();
2299 }
2300
2301 static struct file_system_type rdt_fs_type = {
2302 .name = "resctrl",
2303 .init_fs_context = rdt_init_fs_context,
2304 .parameters = &rdt_fs_parameters,
2305 .kill_sb = rdt_kill_sb,
2306 };
2307
2308 static int mon_addfile(struct kernfs_node *parent_kn, const char *name,
2309 void *priv)
2310 {
2311 struct kernfs_node *kn;
2312 int ret = 0;
2313
2314 kn = __kernfs_create_file(parent_kn, name, 0444,
2315 GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, 0,
2316 &kf_mondata_ops, priv, NULL, NULL);
2317 if (IS_ERR(kn))
2318 return PTR_ERR(kn);
2319
2320 ret = rdtgroup_kn_set_ugid(kn);
2321 if (ret) {
2322 kernfs_remove(kn);
2323 return ret;
2324 }
2325
2326 return ret;
2327 }
2328
2329
2330
2331
2332
2333 void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r, unsigned int dom_id)
2334 {
2335 struct rdtgroup *prgrp, *crgrp;
2336 char name[32];
2337
2338 if (!r->mon_enabled)
2339 return;
2340
2341 list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
2342 sprintf(name, "mon_%s_%02d", r->name, dom_id);
2343 kernfs_remove_by_name(prgrp->mon.mon_data_kn, name);
2344
2345 list_for_each_entry(crgrp, &prgrp->mon.crdtgrp_list, mon.crdtgrp_list)
2346 kernfs_remove_by_name(crgrp->mon.mon_data_kn, name);
2347 }
2348 }
2349
2350 static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,
2351 struct rdt_domain *d,
2352 struct rdt_resource *r, struct rdtgroup *prgrp)
2353 {
2354 union mon_data_bits priv;
2355 struct kernfs_node *kn;
2356 struct mon_evt *mevt;
2357 struct rmid_read rr;
2358 char name[32];
2359 int ret;
2360
2361 sprintf(name, "mon_%s_%02d", r->name, d->id);
2362
2363 kn = kernfs_create_dir(parent_kn, name, parent_kn->mode, prgrp);
2364 if (IS_ERR(kn))
2365 return PTR_ERR(kn);
2366
2367
2368
2369
2370
2371 kernfs_get(kn);
2372 ret = rdtgroup_kn_set_ugid(kn);
2373 if (ret)
2374 goto out_destroy;
2375
2376 if (WARN_ON(list_empty(&r->evt_list))) {
2377 ret = -EPERM;
2378 goto out_destroy;
2379 }
2380
2381 priv.u.rid = r->rid;
2382 priv.u.domid = d->id;
2383 list_for_each_entry(mevt, &r->evt_list, list) {
2384 priv.u.evtid = mevt->evtid;
2385 ret = mon_addfile(kn, mevt->name, priv.priv);
2386 if (ret)
2387 goto out_destroy;
2388
2389 if (is_mbm_event(mevt->evtid))
2390 mon_event_read(&rr, d, prgrp, mevt->evtid, true);
2391 }
2392 kernfs_activate(kn);
2393 return 0;
2394
2395 out_destroy:
2396 kernfs_remove(kn);
2397 return ret;
2398 }
2399
2400
2401
2402
2403
2404 void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
2405 struct rdt_domain *d)
2406 {
2407 struct kernfs_node *parent_kn;
2408 struct rdtgroup *prgrp, *crgrp;
2409 struct list_head *head;
2410
2411 if (!r->mon_enabled)
2412 return;
2413
2414 list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
2415 parent_kn = prgrp->mon.mon_data_kn;
2416 mkdir_mondata_subdir(parent_kn, d, r, prgrp);
2417
2418 head = &prgrp->mon.crdtgrp_list;
2419 list_for_each_entry(crgrp, head, mon.crdtgrp_list) {
2420 parent_kn = crgrp->mon.mon_data_kn;
2421 mkdir_mondata_subdir(parent_kn, d, r, crgrp);
2422 }
2423 }
2424 }
2425
2426 static int mkdir_mondata_subdir_alldom(struct kernfs_node *parent_kn,
2427 struct rdt_resource *r,
2428 struct rdtgroup *prgrp)
2429 {
2430 struct rdt_domain *dom;
2431 int ret;
2432
2433 list_for_each_entry(dom, &r->domains, list) {
2434 ret = mkdir_mondata_subdir(parent_kn, dom, r, prgrp);
2435 if (ret)
2436 return ret;
2437 }
2438
2439 return 0;
2440 }
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459 static int mkdir_mondata_all(struct kernfs_node *parent_kn,
2460 struct rdtgroup *prgrp,
2461 struct kernfs_node **dest_kn)
2462 {
2463 struct rdt_resource *r;
2464 struct kernfs_node *kn;
2465 int ret;
2466
2467
2468
2469
2470 ret = mongroup_create_dir(parent_kn, prgrp, "mon_data", &kn);
2471 if (ret)
2472 return ret;
2473
2474 if (dest_kn)
2475 *dest_kn = kn;
2476
2477
2478
2479
2480
2481 for_each_mon_enabled_rdt_resource(r) {
2482 ret = mkdir_mondata_subdir_alldom(kn, r, prgrp);
2483 if (ret)
2484 goto out_destroy;
2485 }
2486
2487 return 0;
2488
2489 out_destroy:
2490 kernfs_remove(kn);
2491 return ret;
2492 }
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509 static u32 cbm_ensure_valid(u32 _val, struct rdt_resource *r)
2510 {
2511 unsigned int cbm_len = r->cache.cbm_len;
2512 unsigned long first_bit, zero_bit;
2513 unsigned long val = _val;
2514
2515 if (!val)
2516 return 0;
2517
2518 first_bit = find_first_bit(&val, cbm_len);
2519 zero_bit = find_next_zero_bit(&val, cbm_len, first_bit);
2520
2521
2522 bitmap_clear(&val, zero_bit, cbm_len - zero_bit);
2523 return (u32)val;
2524 }
2525
2526
2527
2528
2529
2530
2531
2532 static int __init_one_rdt_domain(struct rdt_domain *d, struct rdt_resource *r,
2533 u32 closid)
2534 {
2535 struct rdt_resource *r_cdp = NULL;
2536 struct rdt_domain *d_cdp = NULL;
2537 u32 used_b = 0, unused_b = 0;
2538 unsigned long tmp_cbm;
2539 enum rdtgrp_mode mode;
2540 u32 peer_ctl, *ctrl;
2541 int i;
2542
2543 rdt_cdp_peer_get(r, d, &r_cdp, &d_cdp);
2544 d->have_new_ctrl = false;
2545 d->new_ctrl = r->cache.shareable_bits;
2546 used_b = r->cache.shareable_bits;
2547 ctrl = d->ctrl_val;
2548 for (i = 0; i < closids_supported(); i++, ctrl++) {
2549 if (closid_allocated(i) && i != closid) {
2550 mode = rdtgroup_mode_by_closid(i);
2551 if (mode == RDT_MODE_PSEUDO_LOCKSETUP)
2552
2553
2554
2555
2556
2557 continue;
2558
2559
2560
2561
2562
2563 if (d_cdp)
2564 peer_ctl = d_cdp->ctrl_val[i];
2565 else
2566 peer_ctl = 0;
2567 used_b |= *ctrl | peer_ctl;
2568 if (mode == RDT_MODE_SHAREABLE)
2569 d->new_ctrl |= *ctrl | peer_ctl;
2570 }
2571 }
2572 if (d->plr && d->plr->cbm > 0)
2573 used_b |= d->plr->cbm;
2574 unused_b = used_b ^ (BIT_MASK(r->cache.cbm_len) - 1);
2575 unused_b &= BIT_MASK(r->cache.cbm_len) - 1;
2576 d->new_ctrl |= unused_b;
2577
2578
2579
2580
2581 d->new_ctrl = cbm_ensure_valid(d->new_ctrl, r);
2582
2583
2584
2585
2586 tmp_cbm = d->new_ctrl;
2587 if (bitmap_weight(&tmp_cbm, r->cache.cbm_len) < r->cache.min_cbm_bits) {
2588 rdt_last_cmd_printf("No space on %s:%d\n", r->name, d->id);
2589 return -ENOSPC;
2590 }
2591 d->have_new_ctrl = true;
2592
2593 return 0;
2594 }
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606 static int rdtgroup_init_cat(struct rdt_resource *r, u32 closid)
2607 {
2608 struct rdt_domain *d;
2609 int ret;
2610
2611 list_for_each_entry(d, &r->domains, list) {
2612 ret = __init_one_rdt_domain(d, r, closid);
2613 if (ret < 0)
2614 return ret;
2615 }
2616
2617 return 0;
2618 }
2619
2620
2621 static void rdtgroup_init_mba(struct rdt_resource *r)
2622 {
2623 struct rdt_domain *d;
2624
2625 list_for_each_entry(d, &r->domains, list) {
2626 d->new_ctrl = is_mba_sc(r) ? MBA_MAX_MBPS : r->default_ctrl;
2627 d->have_new_ctrl = true;
2628 }
2629 }
2630
2631
2632 static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
2633 {
2634 struct rdt_resource *r;
2635 int ret;
2636
2637 for_each_alloc_enabled_rdt_resource(r) {
2638 if (r->rid == RDT_RESOURCE_MBA) {
2639 rdtgroup_init_mba(r);
2640 } else {
2641 ret = rdtgroup_init_cat(r, rdtgrp->closid);
2642 if (ret < 0)
2643 return ret;
2644 }
2645
2646 ret = update_domains(r, rdtgrp->closid);
2647 if (ret < 0) {
2648 rdt_last_cmd_puts("Failed to initialize allocations\n");
2649 return ret;
2650 }
2651
2652 }
2653
2654 rdtgrp->mode = RDT_MODE_SHAREABLE;
2655
2656 return 0;
2657 }
2658
2659 static int mkdir_rdt_prepare(struct kernfs_node *parent_kn,
2660 struct kernfs_node *prgrp_kn,
2661 const char *name, umode_t mode,
2662 enum rdt_group_type rtype, struct rdtgroup **r)
2663 {
2664 struct rdtgroup *prdtgrp, *rdtgrp;
2665 struct kernfs_node *kn;
2666 uint files = 0;
2667 int ret;
2668
2669 prdtgrp = rdtgroup_kn_lock_live(parent_kn);
2670 if (!prdtgrp) {
2671 ret = -ENODEV;
2672 goto out_unlock;
2673 }
2674
2675 if (rtype == RDTMON_GROUP &&
2676 (prdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
2677 prdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)) {
2678 ret = -EINVAL;
2679 rdt_last_cmd_puts("Pseudo-locking in progress\n");
2680 goto out_unlock;
2681 }
2682
2683
2684 rdtgrp = kzalloc(sizeof(*rdtgrp), GFP_KERNEL);
2685 if (!rdtgrp) {
2686 ret = -ENOSPC;
2687 rdt_last_cmd_puts("Kernel out of memory\n");
2688 goto out_unlock;
2689 }
2690 *r = rdtgrp;
2691 rdtgrp->mon.parent = prdtgrp;
2692 rdtgrp->type = rtype;
2693 INIT_LIST_HEAD(&rdtgrp->mon.crdtgrp_list);
2694
2695
2696 kn = kernfs_create_dir(parent_kn, name, mode, rdtgrp);
2697 if (IS_ERR(kn)) {
2698 ret = PTR_ERR(kn);
2699 rdt_last_cmd_puts("kernfs create error\n");
2700 goto out_free_rgrp;
2701 }
2702 rdtgrp->kn = kn;
2703
2704
2705
2706
2707
2708
2709
2710 kernfs_get(kn);
2711
2712 ret = rdtgroup_kn_set_ugid(kn);
2713 if (ret) {
2714 rdt_last_cmd_puts("kernfs perm error\n");
2715 goto out_destroy;
2716 }
2717
2718 files = RFTYPE_BASE | BIT(RF_CTRLSHIFT + rtype);
2719 ret = rdtgroup_add_files(kn, files);
2720 if (ret) {
2721 rdt_last_cmd_puts("kernfs fill error\n");
2722 goto out_destroy;
2723 }
2724
2725 if (rdt_mon_capable) {
2726 ret = alloc_rmid();
2727 if (ret < 0) {
2728 rdt_last_cmd_puts("Out of RMIDs\n");
2729 goto out_destroy;
2730 }
2731 rdtgrp->mon.rmid = ret;
2732
2733 ret = mkdir_mondata_all(kn, rdtgrp, &rdtgrp->mon.mon_data_kn);
2734 if (ret) {
2735 rdt_last_cmd_puts("kernfs subdir error\n");
2736 goto out_idfree;
2737 }
2738 }
2739 kernfs_activate(kn);
2740
2741
2742
2743
2744 return 0;
2745
2746 out_idfree:
2747 free_rmid(rdtgrp->mon.rmid);
2748 out_destroy:
2749 kernfs_remove(rdtgrp->kn);
2750 out_free_rgrp:
2751 kfree(rdtgrp);
2752 out_unlock:
2753 rdtgroup_kn_unlock(parent_kn);
2754 return ret;
2755 }
2756
2757 static void mkdir_rdt_prepare_clean(struct rdtgroup *rgrp)
2758 {
2759 kernfs_remove(rgrp->kn);
2760 free_rmid(rgrp->mon.rmid);
2761 kfree(rgrp);
2762 }
2763
2764
2765
2766
2767
2768
2769 static int rdtgroup_mkdir_mon(struct kernfs_node *parent_kn,
2770 struct kernfs_node *prgrp_kn,
2771 const char *name,
2772 umode_t mode)
2773 {
2774 struct rdtgroup *rdtgrp, *prgrp;
2775 int ret;
2776
2777 ret = mkdir_rdt_prepare(parent_kn, prgrp_kn, name, mode, RDTMON_GROUP,
2778 &rdtgrp);
2779 if (ret)
2780 return ret;
2781
2782 prgrp = rdtgrp->mon.parent;
2783 rdtgrp->closid = prgrp->closid;
2784
2785
2786
2787
2788
2789 list_add_tail(&rdtgrp->mon.crdtgrp_list, &prgrp->mon.crdtgrp_list);
2790
2791 rdtgroup_kn_unlock(parent_kn);
2792 return ret;
2793 }
2794
2795
2796
2797
2798
2799 static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,
2800 struct kernfs_node *prgrp_kn,
2801 const char *name, umode_t mode)
2802 {
2803 struct rdtgroup *rdtgrp;
2804 struct kernfs_node *kn;
2805 u32 closid;
2806 int ret;
2807
2808 ret = mkdir_rdt_prepare(parent_kn, prgrp_kn, name, mode, RDTCTRL_GROUP,
2809 &rdtgrp);
2810 if (ret)
2811 return ret;
2812
2813 kn = rdtgrp->kn;
2814 ret = closid_alloc();
2815 if (ret < 0) {
2816 rdt_last_cmd_puts("Out of CLOSIDs\n");
2817 goto out_common_fail;
2818 }
2819 closid = ret;
2820 ret = 0;
2821
2822 rdtgrp->closid = closid;
2823 ret = rdtgroup_init_alloc(rdtgrp);
2824 if (ret < 0)
2825 goto out_id_free;
2826
2827 list_add(&rdtgrp->rdtgroup_list, &rdt_all_groups);
2828
2829 if (rdt_mon_capable) {
2830
2831
2832
2833
2834 ret = mongroup_create_dir(kn, rdtgrp, "mon_groups", NULL);
2835 if (ret) {
2836 rdt_last_cmd_puts("kernfs subdir error\n");
2837 goto out_del_list;
2838 }
2839 }
2840
2841 goto out_unlock;
2842
2843 out_del_list:
2844 list_del(&rdtgrp->rdtgroup_list);
2845 out_id_free:
2846 closid_free(closid);
2847 out_common_fail:
2848 mkdir_rdt_prepare_clean(rdtgrp);
2849 out_unlock:
2850 rdtgroup_kn_unlock(parent_kn);
2851 return ret;
2852 }
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864 static bool is_mon_groups(struct kernfs_node *kn, const char *name)
2865 {
2866 return (!strcmp(kn->name, "mon_groups") &&
2867 strcmp(name, "mon_groups"));
2868 }
2869
2870 static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
2871 umode_t mode)
2872 {
2873
2874 if (strchr(name, '\n'))
2875 return -EINVAL;
2876
2877
2878
2879
2880
2881
2882 if (rdt_alloc_capable && parent_kn == rdtgroup_default.kn)
2883 return rdtgroup_mkdir_ctrl_mon(parent_kn, parent_kn, name, mode);
2884
2885
2886
2887
2888
2889 if (rdt_mon_capable && is_mon_groups(parent_kn, name))
2890 return rdtgroup_mkdir_mon(parent_kn, parent_kn->parent, name, mode);
2891
2892 return -EPERM;
2893 }
2894
2895 static int rdtgroup_rmdir_mon(struct kernfs_node *kn, struct rdtgroup *rdtgrp,
2896 cpumask_var_t tmpmask)
2897 {
2898 struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
2899 int cpu;
2900
2901
2902 rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask);
2903
2904
2905 for_each_cpu(cpu, &rdtgrp->cpu_mask)
2906 per_cpu(pqr_state.default_rmid, cpu) = prdtgrp->mon.rmid;
2907
2908
2909
2910
2911 cpumask_or(tmpmask, tmpmask, &rdtgrp->cpu_mask);
2912 update_closid_rmid(tmpmask, NULL);
2913
2914 rdtgrp->flags = RDT_DELETED;
2915 free_rmid(rdtgrp->mon.rmid);
2916
2917
2918
2919
2920 WARN_ON(list_empty(&prdtgrp->mon.crdtgrp_list));
2921 list_del(&rdtgrp->mon.crdtgrp_list);
2922
2923
2924
2925
2926
2927 kernfs_get(kn);
2928 kernfs_remove(rdtgrp->kn);
2929
2930 return 0;
2931 }
2932
2933 static int rdtgroup_ctrl_remove(struct kernfs_node *kn,
2934 struct rdtgroup *rdtgrp)
2935 {
2936 rdtgrp->flags = RDT_DELETED;
2937 list_del(&rdtgrp->rdtgroup_list);
2938
2939
2940
2941
2942
2943 kernfs_get(kn);
2944 kernfs_remove(rdtgrp->kn);
2945 return 0;
2946 }
2947
2948 static int rdtgroup_rmdir_ctrl(struct kernfs_node *kn, struct rdtgroup *rdtgrp,
2949 cpumask_var_t tmpmask)
2950 {
2951 int cpu;
2952
2953
2954 rdt_move_group_tasks(rdtgrp, &rdtgroup_default, tmpmask);
2955
2956
2957 cpumask_or(&rdtgroup_default.cpu_mask,
2958 &rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask);
2959
2960
2961 for_each_cpu(cpu, &rdtgrp->cpu_mask) {
2962 per_cpu(pqr_state.default_closid, cpu) = rdtgroup_default.closid;
2963 per_cpu(pqr_state.default_rmid, cpu) = rdtgroup_default.mon.rmid;
2964 }
2965
2966
2967
2968
2969
2970 cpumask_or(tmpmask, tmpmask, &rdtgrp->cpu_mask);
2971 update_closid_rmid(tmpmask, NULL);
2972
2973 closid_free(rdtgrp->closid);
2974 free_rmid(rdtgrp->mon.rmid);
2975
2976 rdtgroup_ctrl_remove(kn, rdtgrp);
2977
2978
2979
2980
2981 free_all_child_rdtgrp(rdtgrp);
2982
2983 return 0;
2984 }
2985
2986 static int rdtgroup_rmdir(struct kernfs_node *kn)
2987 {
2988 struct kernfs_node *parent_kn = kn->parent;
2989 struct rdtgroup *rdtgrp;
2990 cpumask_var_t tmpmask;
2991 int ret = 0;
2992
2993 if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL))
2994 return -ENOMEM;
2995
2996 rdtgrp = rdtgroup_kn_lock_live(kn);
2997 if (!rdtgrp) {
2998 ret = -EPERM;
2999 goto out;
3000 }
3001
3002
3003
3004
3005
3006
3007
3008
3009 if (rdtgrp->type == RDTCTRL_GROUP && parent_kn == rdtgroup_default.kn &&
3010 rdtgrp != &rdtgroup_default) {
3011 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
3012 rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
3013 ret = rdtgroup_ctrl_remove(kn, rdtgrp);
3014 } else {
3015 ret = rdtgroup_rmdir_ctrl(kn, rdtgrp, tmpmask);
3016 }
3017 } else if (rdtgrp->type == RDTMON_GROUP &&
3018 is_mon_groups(parent_kn, kn->name)) {
3019 ret = rdtgroup_rmdir_mon(kn, rdtgrp, tmpmask);
3020 } else {
3021 ret = -EPERM;
3022 }
3023
3024 out:
3025 rdtgroup_kn_unlock(kn);
3026 free_cpumask_var(tmpmask);
3027 return ret;
3028 }
3029
3030 static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
3031 {
3032 if (rdt_resources_all[RDT_RESOURCE_L3DATA].alloc_enabled)
3033 seq_puts(seq, ",cdp");
3034
3035 if (rdt_resources_all[RDT_RESOURCE_L2DATA].alloc_enabled)
3036 seq_puts(seq, ",cdpl2");
3037
3038 if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA]))
3039 seq_puts(seq, ",mba_MBps");
3040
3041 return 0;
3042 }
3043
3044 static struct kernfs_syscall_ops rdtgroup_kf_syscall_ops = {
3045 .mkdir = rdtgroup_mkdir,
3046 .rmdir = rdtgroup_rmdir,
3047 .show_options = rdtgroup_show_options,
3048 };
3049
3050 static int __init rdtgroup_setup_root(void)
3051 {
3052 int ret;
3053
3054 rdt_root = kernfs_create_root(&rdtgroup_kf_syscall_ops,
3055 KERNFS_ROOT_CREATE_DEACTIVATED |
3056 KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK,
3057 &rdtgroup_default);
3058 if (IS_ERR(rdt_root))
3059 return PTR_ERR(rdt_root);
3060
3061 mutex_lock(&rdtgroup_mutex);
3062
3063 rdtgroup_default.closid = 0;
3064 rdtgroup_default.mon.rmid = 0;
3065 rdtgroup_default.type = RDTCTRL_GROUP;
3066 INIT_LIST_HEAD(&rdtgroup_default.mon.crdtgrp_list);
3067
3068 list_add(&rdtgroup_default.rdtgroup_list, &rdt_all_groups);
3069
3070 ret = rdtgroup_add_files(rdt_root->kn, RF_CTRL_BASE);
3071 if (ret) {
3072 kernfs_destroy_root(rdt_root);
3073 goto out;
3074 }
3075
3076 rdtgroup_default.kn = rdt_root->kn;
3077 kernfs_activate(rdtgroup_default.kn);
3078
3079 out:
3080 mutex_unlock(&rdtgroup_mutex);
3081
3082 return ret;
3083 }
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093 int __init rdtgroup_init(void)
3094 {
3095 int ret = 0;
3096
3097 seq_buf_init(&last_cmd_status, last_cmd_status_buf,
3098 sizeof(last_cmd_status_buf));
3099
3100 ret = rdtgroup_setup_root();
3101 if (ret)
3102 return ret;
3103
3104 ret = sysfs_create_mount_point(fs_kobj, "resctrl");
3105 if (ret)
3106 goto cleanup_root;
3107
3108 ret = register_filesystem(&rdt_fs_type);
3109 if (ret)
3110 goto cleanup_mountpoint;
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133 debugfs_resctrl = debugfs_create_dir("resctrl", NULL);
3134
3135 return 0;
3136
3137 cleanup_mountpoint:
3138 sysfs_remove_mount_point(fs_kobj, "resctrl");
3139 cleanup_root:
3140 kernfs_destroy_root(rdt_root);
3141
3142 return ret;
3143 }
3144
3145 void __exit rdtgroup_exit(void)
3146 {
3147 debugfs_remove_recursive(debugfs_resctrl);
3148 unregister_filesystem(&rdt_fs_type);
3149 sysfs_remove_mount_point(fs_kobj, "resctrl");
3150 kernfs_destroy_root(rdt_root);
3151 }