Skip to content

Commit 76fd028

Browse files
sjp38torvalds
authored andcommitted
mm/damon: hide kernel pointer from tracepoint event
DAMON's virtual address spaces monitoring primitive uses 'struct pid *' of the target process as its monitoring target id. The kernel address is exposed as-is to the user space via the DAMON tracepoint, 'damon_aggregated'. Though primarily only privileged users are allowed to access that, it would be better to avoid unnecessarily exposing kernel pointers so. Because the trace result is only required to be able to distinguish each target, we aren't need to use the pointer as-is. This makes the tracepoint to use the index of the target in the context's targets list as its id in the tracepoint, to hide the kernel space address. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: SeongJae Park <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 962fe7a commit 76fd028

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

include/trace/events/damon.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
TRACE_EVENT(damon_aggregated,
1313

14-
TP_PROTO(struct damon_target *t, struct damon_region *r,
15-
unsigned int nr_regions),
14+
TP_PROTO(struct damon_target *t, unsigned int target_id,
15+
struct damon_region *r, unsigned int nr_regions),
1616

17-
TP_ARGS(t, r, nr_regions),
17+
TP_ARGS(t, target_id, r, nr_regions),
1818

1919
TP_STRUCT__entry(
2020
__field(unsigned long, target_id)
@@ -26,7 +26,7 @@ TRACE_EVENT(damon_aggregated,
2626
),
2727

2828
TP_fast_assign(
29-
__entry->target_id = t->id;
29+
__entry->target_id = target_id;
3030
__entry->nr_regions = nr_regions;
3131
__entry->start = r->ar.start;
3232
__entry->end = r->ar.end;

mm/damon/core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,15 +514,17 @@ static bool kdamond_aggregate_interval_passed(struct damon_ctx *ctx)
514514
static void kdamond_reset_aggregated(struct damon_ctx *c)
515515
{
516516
struct damon_target *t;
517+
unsigned int ti = 0; /* target's index */
517518

518519
damon_for_each_target(t, c) {
519520
struct damon_region *r;
520521

521522
damon_for_each_region(r, t) {
522-
trace_damon_aggregated(t, r, damon_nr_regions(t));
523+
trace_damon_aggregated(t, ti, r, damon_nr_regions(t));
523524
r->last_nr_accesses = r->nr_accesses;
524525
r->nr_accesses = 0;
525526
}
527+
ti++;
526528
}
527529
}
528530

0 commit comments

Comments
 (0)