Skip to content

Commit 2910428

Browse files
hramrachmpe
authored andcommitted
powerpc/perf: consolidate valid_user_sp -> invalid_user_sp
Merge the 32bit and 64bit version. Halve the check constants on 32bit. Use STACK_TOP since it is defined. Passing is_64 is now redundant since is_32bit_task() is used to determine which callchain variant should be used. Use STACK_TOP and is_32bit_task() directly. This removes a page from the valid 32bit area on 64bit: #define TASK_SIZE_USER32 (0x0000000100000000UL - (1 * PAGE_SIZE)) #define STACK_TOP_USER32 TASK_SIZE_USER32 Change return value to bool. It is inverted by users anyway. Change to invalid_user_sp to avoid inverting the return value twice. Signed-off-by: Michal Suchanek <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/be8e40fc0737fb28ad08b198552dee7cac1c5ce2.1584699455.git.msuchanek@suse.de
1 parent d6c19bd commit 2910428

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

arch/powerpc/perf/callchain.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re
102102
}
103103
}
104104

105+
static inline bool invalid_user_sp(unsigned long sp)
106+
{
107+
unsigned long mask = is_32bit_task() ? 3 : 7;
108+
unsigned long top = STACK_TOP - (is_32bit_task() ? 16 : 32);
109+
110+
return (!sp || (sp & mask) || (sp > top));
111+
}
112+
105113
#ifdef CONFIG_PPC64
106114
/*
107115
* On 64-bit we don't want to invoke hash_page on user addresses from
@@ -161,13 +169,6 @@ static int read_user_stack_64(unsigned long __user *ptr, unsigned long *ret)
161169
return read_user_stack_slow(ptr, ret, 8);
162170
}
163171

164-
static inline int valid_user_sp(unsigned long sp, int is_64)
165-
{
166-
if (!sp || (sp & 7) || sp > (is_64 ? TASK_SIZE : 0x100000000UL) - 32)
167-
return 0;
168-
return 1;
169-
}
170-
171172
/*
172173
* 64-bit user processes use the same stack frame for RT and non-RT signals.
173174
*/
@@ -226,7 +227,7 @@ static void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry,
226227

227228
while (entry->nr < entry->max_stack) {
228229
fp = (unsigned long __user *) sp;
229-
if (!valid_user_sp(sp, 1) || read_user_stack_64(fp, &next_sp))
230+
if (invalid_user_sp(sp) || read_user_stack_64(fp, &next_sp))
230231
return;
231232
if (level > 0 && read_user_stack_64(&fp[2], &next_ip))
232233
return;
@@ -275,13 +276,6 @@ static inline void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry
275276
{
276277
}
277278

278-
static inline int valid_user_sp(unsigned long sp, int is_64)
279-
{
280-
if (!sp || (sp & 7) || sp > TASK_SIZE - 32)
281-
return 0;
282-
return 1;
283-
}
284-
285279
#define __SIGNAL_FRAMESIZE32 __SIGNAL_FRAMESIZE
286280
#define sigcontext32 sigcontext
287281
#define mcontext32 mcontext
@@ -423,7 +417,7 @@ static void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry,
423417

424418
while (entry->nr < entry->max_stack) {
425419
fp = (unsigned int __user *) (unsigned long) sp;
426-
if (!valid_user_sp(sp, 0) || read_user_stack_32(fp, &next_sp))
420+
if (invalid_user_sp(sp) || read_user_stack_32(fp, &next_sp))
427421
return;
428422
if (level > 0 && read_user_stack_32(&fp[1], &next_ip))
429423
return;

0 commit comments

Comments
 (0)