History

kcsan: Refactor access_info initialization

In subsequent patches we'll want to split kcsan_report() into distinct handlers for each report type. The largest bit of common work is initializing the `access_info`, so let's factor this out into a helper, and have the kcsan_report_*() functions pass the `aaccess_info` as a parameter to kcsan_report(). There should be no functional change as a result of this patch.

Mark Rutland committed 5 years ago

Commit 39b2e761 parent 97aa6131 file · +25 −17Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/kcsan/report.c+25−17
@@ -596,18 +596,10 @@ static noinline bool prepare_report(unsigned long *flags, · 595 unmodified lines
596596 }
597597 }
598598
599−static void kcsan_report(const volatile void *ptr, size_t size, int access_type,
600− enum kcsan_value_change value_change,
599+static void kcsan_report(const struct access_info *ai, enum kcsan_value_change value_change,
601600 enum kcsan_report_type type, struct other_info *other_info)
602601 {
603602 unsigned long flags = 0;
604− const struct access_info ai = {
605− .ptr = ptr,
606− .size = size,
607− .access_type = access_type,
608− .task_pid = in_task() ? task_pid_nr(current) : -1,
609− .cpu_id = raw_smp_processor_id()
610− };
611603
612604 kcsan_disable_current();
613605
@@ -620,14 +612,14 @@ static void kcsan_report(const volatile void *ptr, size_t size, int access_type, · 6 unmodified lines
620612 */
621613 lockdep_off();
622614
623− if (prepare_report(&flags, type, &ai, other_info)) {
615+ if (prepare_report(&flags, type, ai, other_info)) {
624616 /*
625617 * Never report if value_change is FALSE, only if we it is
626618 * either TRUE or MAYBE. In case of MAYBE, further filtering may
627619 * be done once we know the full stack trace in print_report().
628620 */
629621 if (value_change != KCSAN_VALUE_CHANGE_FALSE)
630− print_report(value_change, type, &ai, other_info);
622+ print_report(value_change, type, ai, other_info);
631623
632624 release_report(&flags, other_info);
633625 }
@@ -636,22 +628,38 @@ static void kcsan_report(const volatile void *ptr, size_t size, int access_type, · 2 unmodified lines
636628 kcsan_enable_current();
637629 }
638630
631+static struct access_info prepare_access_info(const volatile void *ptr, size_t size,
632+ int access_type)
633+{
634+ return (struct access_info) {
635+ .ptr = ptr,
636+ .size = size,
637+ .access_type = access_type,
638+ .task_pid = in_task() ? task_pid_nr(current) : -1,
639+ .cpu_id = raw_smp_processor_id()
640+ };
641+}
642+
639643 void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_type,
640644 int watchpoint_idx)
641645 {
642− kcsan_report(ptr, size, access_type, KCSAN_VALUE_CHANGE_MAYBE,
643− KCSAN_REPORT_CONSUMED_WATCHPOINT, &other_infos[watchpoint_idx]);
646+ const struct access_info ai = prepare_access_info(ptr, size, access_type);
647+
648+ kcsan_report(&ai, KCSAN_VALUE_CHANGE_MAYBE, KCSAN_REPORT_CONSUMED_WATCHPOINT,
649+ &other_infos[watchpoint_idx]);
644650 }
645651
646652 void kcsan_report_known_origin(const volatile void *ptr, size_t size, int access_type,
647653 enum kcsan_value_change value_change, int watchpoint_idx)
648654 {
649− kcsan_report(ptr, size, access_type, value_change,
650− KCSAN_REPORT_RACE_SIGNAL, &other_infos[watchpoint_idx]);
655+ const struct access_info ai = prepare_access_info(ptr, size, access_type);
656+
657+ kcsan_report(&ai, value_change, KCSAN_REPORT_RACE_SIGNAL, &other_infos[watchpoint_idx]);
651658 }
652659
653660 void kcsan_report_unknown_origin(const volatile void *ptr, size_t size, int access_type)
654661 {
655− kcsan_report(ptr, size, access_type, KCSAN_VALUE_CHANGE_TRUE,
656− KCSAN_REPORT_RACE_UNKNOWN_ORIGIN, NULL);
662+ const struct access_info ai = prepare_access_info(ptr, size, access_type);
663+
664+ kcsan_report(&ai, KCSAN_VALUE_CHANGE_TRUE, KCSAN_REPORT_RACE_UNKNOWN_ORIGIN, NULL);
657665 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t