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.
Unified · Split
| @@ -596,18 +596,10 @@ static noinline bool prepare_report(unsigned long *flags, · 595 unmodified lines | ||
| 596 | 596 | } |
| 597 | 597 | } |
| 598 | 598 | |
| 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, | |
| 601 | 600 | enum kcsan_report_type type, struct other_info *other_info) |
| 602 | 601 | { |
| 603 | 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 | 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 | 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 | 617 | * Never report if value_change is FALSE, only if we it is |
| 626 | 618 | * either TRUE or MAYBE. In case of MAYBE, further filtering may |
| 627 | 619 | * be done once we know the full stack trace in print_report(). |
| 628 | 620 | */ |
| 629 | 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 | 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 | 628 | kcsan_enable_current(); |
| 637 | 629 | } |
| 638 | 630 | |
| 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 | + | |
| 639 | 643 | void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_type, |
| 640 | 644 | int watchpoint_idx) |
| 641 | 645 | { |
| 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]); | |
| 644 | 650 | } |
| 645 | 651 | |
| 646 | 652 | void kcsan_report_known_origin(const volatile void *ptr, size_t size, int access_type, |
| 647 | 653 | enum kcsan_value_change value_change, int watchpoint_idx) |
| 648 | 654 | { |
| 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]); | |
| 651 | 658 | } |
| 652 | 659 | |
| 653 | 660 | void 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, | |
| 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); | |
| 657 | 665 | } |