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
596 }596 }
597}597}
598 598
599static void kcsan_report(const volatile void *ptr, size_t size, int access_type,599static void kcsan_report(const struct access_info *ai, enum kcsan_value_change value_change,
600 enum kcsan_value_change value_change,
601 enum kcsan_report_type type, struct other_info *other_info)600 enum kcsan_report_type type, struct other_info *other_info)
602{601{
603 unsigned long flags = 0;602 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 };
611 603
612 kcsan_disable_current();604 kcsan_disable_current();
613 605
@@ -620,14 +612,14 @@ static void kcsan_report(const volatile void *ptr, size_t size, int access_type, · 6 unmodified lines
620 */612 */
621 lockdep_off();613 lockdep_off();
622 614
623 if (prepare_report(&flags, type, &ai, other_info)) {615 if (prepare_report(&flags, type, ai, other_info)) {
624 /*616 /*
625 * Never report if value_change is FALSE, only if we it is617 * Never report if value_change is FALSE, only if we it is
626 * either TRUE or MAYBE. In case of MAYBE, further filtering may618 * either TRUE or MAYBE. In case of MAYBE, further filtering may
627 * be done once we know the full stack trace in print_report().619 * be done once we know the full stack trace in print_report().
628 */620 */
629 if (value_change != KCSAN_VALUE_CHANGE_FALSE)621 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);
631 623
632 release_report(&flags, other_info);624 release_report(&flags, other_info);
633 }625 }
@@ -636,22 +628,38 @@ static void kcsan_report(const volatile void *ptr, size_t size, int access_type, · 2 unmodified lines
636 kcsan_enable_current();628 kcsan_enable_current();
637}629}
638 630
631static 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
639void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_type,643void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_type,
640 int watchpoint_idx)644 int watchpoint_idx)
641{645{
642 kcsan_report(ptr, size, access_type, KCSAN_VALUE_CHANGE_MAYBE,646 const struct access_info ai = prepare_access_info(ptr, size, access_type);
643 KCSAN_REPORT_CONSUMED_WATCHPOINT, &other_infos[watchpoint_idx]);647
648 kcsan_report(&ai, KCSAN_VALUE_CHANGE_MAYBE, KCSAN_REPORT_CONSUMED_WATCHPOINT,
649 &other_infos[watchpoint_idx]);
644}650}
645 651
646void kcsan_report_known_origin(const volatile void *ptr, size_t size, int access_type,652void kcsan_report_known_origin(const volatile void *ptr, size_t size, int access_type,
647 enum kcsan_value_change value_change, int watchpoint_idx)653 enum kcsan_value_change value_change, int watchpoint_idx)
648{654{
649 kcsan_report(ptr, size, access_type, value_change,655 const struct access_info ai = prepare_access_info(ptr, size, access_type);
650 KCSAN_REPORT_RACE_SIGNAL, &other_infos[watchpoint_idx]);656
657 kcsan_report(&ai, value_change, KCSAN_REPORT_RACE_SIGNAL, &other_infos[watchpoint_idx]);
651}658}
652 659
653void kcsan_report_unknown_origin(const volatile void *ptr, size_t size, int access_type)660void kcsan_report_unknown_origin(const volatile void *ptr, size_t size, int access_type)
654{661{
655 kcsan_report(ptr, size, access_type, KCSAN_VALUE_CHANGE_TRUE,662 const struct access_info ai = prepare_access_info(ptr, size, access_type);
656 KCSAN_REPORT_RACE_UNKNOWN_ORIGIN, NULL);663
664 kcsan_report(&ai, KCSAN_VALUE_CHANGE_TRUE, KCSAN_REPORT_RACE_UNKNOWN_ORIGIN, NULL);
657}665}

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