Skip to content

Commit dcbd1ac

Browse files
beaubelgraverostedt
authored andcommitted
tracing/user_events: Rename link fields for clarity
Currently most list_head fields of various structs within user_events are simply named link. This causes folks to keep additional context in their head when working with the code, which can be confusing. Instead of using link, describe what the actual link is, for example: list_del_rcu(&mm->link); Changes into: list_del_rcu(&mm->mms_link); The reader now is given a hint the link is to the mms global list instead of having to remember or spot check within the code. Link: https://lkml.kernel.org/r/20230519230741.669-4-beaub@linux.microsoft.com Link: https://lore.kernel.org/linux-trace-kernel/CAHk-=wicngggxVpbnrYHjRTwGE0WYscPRM+L2HO2BF8ia1EXgQ@mail.gmail.com/ Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent aaecdaf commit dcbd1ac

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

include/linux/user_events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#ifdef CONFIG_USER_EVENTS
1919
struct user_event_mm {
20-
struct list_head link;
20+
struct list_head mms_link;
2121
struct list_head enablers;
2222
struct mm_struct *mm;
2323
struct user_event_mm *next;

kernel/trace/trace_events_user.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct user_event {
9696
* these to track enablement sites that are tied to an event.
9797
*/
9898
struct user_event_enabler {
99-
struct list_head link;
99+
struct list_head mm_enablers_link;
100100
struct user_event *event;
101101
unsigned long addr;
102102

@@ -155,7 +155,7 @@ struct user_event_file_info {
155155
#define VALIDATOR_REL (1 << 1)
156156

157157
struct user_event_validator {
158-
struct list_head link;
158+
struct list_head user_event_link;
159159
int offset;
160160
int flags;
161161
};
@@ -261,7 +261,7 @@ static struct user_event_group
261261

262262
static void user_event_enabler_destroy(struct user_event_enabler *enabler)
263263
{
264-
list_del_rcu(&enabler->link);
264+
list_del_rcu(&enabler->mm_enablers_link);
265265

266266
/* No longer tracking the event via the enabler */
267267
refcount_dec(&enabler->event->refcnt);
@@ -440,7 +440,7 @@ static bool user_event_enabler_exists(struct user_event_mm *mm,
440440
{
441441
struct user_event_enabler *enabler;
442442

443-
list_for_each_entry(enabler, &mm->enablers, link) {
443+
list_for_each_entry(enabler, &mm->enablers, mm_enablers_link) {
444444
if (enabler->addr == uaddr && ENABLE_BIT(enabler) == bit)
445445
return true;
446446
}
@@ -461,7 +461,7 @@ static void user_event_enabler_update(struct user_event *user)
461461
next = mm->next;
462462
mmap_read_lock(mm->mm);
463463

464-
list_for_each_entry(enabler, &mm->enablers, link) {
464+
list_for_each_entry(enabler, &mm->enablers, mm_enablers_link) {
465465
if (enabler->event == user) {
466466
attempt = 0;
467467
user_event_enabler_write(mm, enabler, true, &attempt);
@@ -497,7 +497,7 @@ static bool user_event_enabler_dup(struct user_event_enabler *orig,
497497
refcount_inc(&enabler->event->refcnt);
498498

499499
/* Enablers not exposed yet, RCU not required */
500-
list_add(&enabler->link, &mm->enablers);
500+
list_add(&enabler->mm_enablers_link, &mm->enablers);
501501

502502
return true;
503503
}
@@ -527,13 +527,15 @@ static struct user_event_mm *user_event_mm_get_all(struct user_event *user)
527527
*/
528528
rcu_read_lock();
529529

530-
list_for_each_entry_rcu(mm, &user_event_mms, link)
531-
list_for_each_entry_rcu(enabler, &mm->enablers, link)
530+
list_for_each_entry_rcu(mm, &user_event_mms, mms_link) {
531+
list_for_each_entry_rcu(enabler, &mm->enablers, mm_enablers_link) {
532532
if (enabler->event == user) {
533533
mm->next = found;
534534
found = user_event_mm_get(mm);
535535
break;
536536
}
537+
}
538+
}
537539

538540
rcu_read_unlock();
539541

@@ -572,7 +574,7 @@ static void user_event_mm_attach(struct user_event_mm *user_mm, struct task_stru
572574
unsigned long flags;
573575

574576
spin_lock_irqsave(&user_event_mms_lock, flags);
575-
list_add_rcu(&user_mm->link, &user_event_mms);
577+
list_add_rcu(&user_mm->mms_link, &user_event_mms);
576578
spin_unlock_irqrestore(&user_event_mms_lock, flags);
577579

578580
t->user_event_mm = user_mm;
@@ -601,7 +603,7 @@ static void user_event_mm_destroy(struct user_event_mm *mm)
601603
{
602604
struct user_event_enabler *enabler, *next;
603605

604-
list_for_each_entry_safe(enabler, next, &mm->enablers, link)
606+
list_for_each_entry_safe(enabler, next, &mm->enablers, mm_enablers_link)
605607
user_event_enabler_destroy(enabler);
606608

607609
mmdrop(mm->mm);
@@ -638,7 +640,7 @@ void user_event_mm_remove(struct task_struct *t)
638640

639641
/* Remove the mm from the list, so it can no longer be enabled */
640642
spin_lock_irqsave(&user_event_mms_lock, flags);
641-
list_del_rcu(&mm->link);
643+
list_del_rcu(&mm->mms_link);
642644
spin_unlock_irqrestore(&user_event_mms_lock, flags);
643645

644646
/*
@@ -686,9 +688,10 @@ void user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm)
686688

687689
rcu_read_lock();
688690

689-
list_for_each_entry_rcu(enabler, &old_mm->enablers, link)
691+
list_for_each_entry_rcu(enabler, &old_mm->enablers, mm_enablers_link) {
690692
if (!user_event_enabler_dup(enabler, mm))
691693
goto error;
694+
}
692695

693696
rcu_read_unlock();
694697

@@ -757,7 +760,7 @@ static struct user_event_enabler
757760
*/
758761
if (!*write_result) {
759762
refcount_inc(&enabler->event->refcnt);
760-
list_add_rcu(&enabler->link, &user_mm->enablers);
763+
list_add_rcu(&enabler->mm_enablers_link, &user_mm->enablers);
761764
}
762765

763766
mutex_unlock(&event_mutex);
@@ -913,8 +916,8 @@ static void user_event_destroy_validators(struct user_event *user)
913916
struct user_event_validator *validator, *next;
914917
struct list_head *head = &user->validators;
915918

916-
list_for_each_entry_safe(validator, next, head, link) {
917-
list_del(&validator->link);
919+
list_for_each_entry_safe(validator, next, head, user_event_link) {
920+
list_del(&validator->user_event_link);
918921
kfree(validator);
919922
}
920923
}
@@ -968,7 +971,7 @@ static int user_event_add_field(struct user_event *user, const char *type,
968971
validator->offset = offset;
969972

970973
/* Want sequential access when validating */
971-
list_add_tail(&validator->link, &user->validators);
974+
list_add_tail(&validator->user_event_link, &user->validators);
972975

973976
add_field:
974977
field->type = type;
@@ -1358,7 +1361,7 @@ static int user_event_validate(struct user_event *user, void *data, int len)
13581361
void *pos, *end = data + len;
13591362
u32 loc, offset, size;
13601363

1361-
list_for_each_entry(validator, head, link) {
1364+
list_for_each_entry(validator, head, user_event_link) {
13621365
pos = data + validator->offset;
13631366

13641367
/* Already done min_size check, no bounds check here */
@@ -2279,7 +2282,7 @@ static long user_events_ioctl_unreg(unsigned long uarg)
22792282
*/
22802283
mutex_lock(&event_mutex);
22812284

2282-
list_for_each_entry_safe(enabler, next, &mm->enablers, link)
2285+
list_for_each_entry_safe(enabler, next, &mm->enablers, mm_enablers_link) {
22832286
if (enabler->addr == reg.disable_addr &&
22842287
ENABLE_BIT(enabler) == reg.disable_bit) {
22852288
set_bit(ENABLE_VAL_FREEING_BIT, ENABLE_BITOPS(enabler));
@@ -2290,6 +2293,7 @@ static long user_events_ioctl_unreg(unsigned long uarg)
22902293
/* Removed at least one */
22912294
ret = 0;
22922295
}
2296+
}
22932297

22942298
mutex_unlock(&event_mutex);
22952299

0 commit comments

Comments
 (0)