Skip to content

Commit f4c87db

Browse files
melverpaulmckrcu
authored andcommitted
kcsan: Save instruction pointer for scoped accesses
Save the instruction pointer for scoped accesses, so that it becomes possible for the reporting code to construct more accurate stack traces that will show the start of the scope. Signed-off-by: Marco Elver <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 55a55fe commit f4c87db

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

include/linux/kcsan-checks.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ void kcsan_set_access_mask(unsigned long mask);
100100
/* Scoped access information. */
101101
struct kcsan_scoped_access {
102102
struct list_head list;
103+
/* Access information. */
103104
const volatile void *ptr;
104105
size_t size;
105106
int type;
107+
/* Location where scoped access was set up. */
108+
unsigned long ip;
106109
};
107110
/*
108111
* Automatically call kcsan_end_scoped_access() when kcsan_scoped_access goes

kernel/kcsan/core.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ static __always_inline struct kcsan_ctx *get_ctx(void)
202202
return in_task() ? &current->kcsan_ctx : raw_cpu_ptr(&kcsan_cpu_ctx);
203203
}
204204

205+
static __always_inline void
206+
check_access(const volatile void *ptr, size_t size, int type, unsigned long ip);
207+
205208
/* Check scoped accesses; never inline because this is a slow-path! */
206209
static noinline void kcsan_check_scoped_accesses(void)
207210
{
@@ -210,8 +213,10 @@ static noinline void kcsan_check_scoped_accesses(void)
210213
struct kcsan_scoped_access *scoped_access;
211214

212215
ctx->scoped_accesses.prev = NULL; /* Avoid recursion. */
213-
list_for_each_entry(scoped_access, &ctx->scoped_accesses, list)
214-
__kcsan_check_access(scoped_access->ptr, scoped_access->size, scoped_access->type);
216+
list_for_each_entry(scoped_access, &ctx->scoped_accesses, list) {
217+
check_access(scoped_access->ptr, scoped_access->size,
218+
scoped_access->type, scoped_access->ip);
219+
}
215220
ctx->scoped_accesses.prev = prev_save;
216221
}
217222

@@ -767,6 +772,7 @@ kcsan_begin_scoped_access(const volatile void *ptr, size_t size, int type,
767772
sa->ptr = ptr;
768773
sa->size = size;
769774
sa->type = type;
775+
sa->ip = _RET_IP_;
770776

771777
if (!ctx->scoped_accesses.prev) /* Lazy initialize list head. */
772778
INIT_LIST_HEAD(&ctx->scoped_accesses);
@@ -798,7 +804,7 @@ void kcsan_end_scoped_access(struct kcsan_scoped_access *sa)
798804

799805
ctx->disable_count--;
800806

801-
__kcsan_check_access(sa->ptr, sa->size, sa->type);
807+
check_access(sa->ptr, sa->size, sa->type, sa->ip);
802808
}
803809
EXPORT_SYMBOL(kcsan_end_scoped_access);
804810

0 commit comments

Comments
 (0)