Skip to content

Commit e92606f

Browse files
jpoimboePeter Zijlstra
authored andcommitted
livepatch: Convert stack entries array to percpu
The entries array in klp_check_stack() is static local because it's too big to be reasonably allocated on the stack. Serialized access is enforced by the klp_mutex. In preparation for calling klp_check_stack() without the mutex (from cond_resched), convert it to a percpu variable. Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20230313233346.kayh4t2lpicjkpsv@treble
1 parent 41abdba commit e92606f

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

kernel/livepatch/transition.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "transition.h"
1515

1616
#define MAX_STACK_ENTRIES 100
17+
DEFINE_PER_CPU(unsigned long[MAX_STACK_ENTRIES], klp_stack_entries);
18+
1719
#define STACK_ERR_BUF_SIZE 128
1820

1921
#define SIGNALS_TIMEOUT 15
@@ -240,12 +242,15 @@ static int klp_check_stack_func(struct klp_func *func, unsigned long *entries,
240242
*/
241243
static int klp_check_stack(struct task_struct *task, const char **oldname)
242244
{
243-
static unsigned long entries[MAX_STACK_ENTRIES];
245+
unsigned long *entries = this_cpu_ptr(klp_stack_entries);
244246
struct klp_object *obj;
245247
struct klp_func *func;
246248
int ret, nr_entries;
247249

248-
ret = stack_trace_save_tsk_reliable(task, entries, ARRAY_SIZE(entries));
250+
/* Protect 'klp_stack_entries' */
251+
lockdep_assert_preemption_disabled();
252+
253+
ret = stack_trace_save_tsk_reliable(task, entries, MAX_STACK_ENTRIES);
249254
if (ret < 0)
250255
return -EINVAL;
251256
nr_entries = ret;

0 commit comments

Comments
 (0)