Re: [PATCH v11 4/8] powerpc/perf: consolidate valid_user_sp
From: Michal Suchánek <hidden>
Date: 2020-03-19 14:04:22
Also in:
lkml
On Thu, Mar 19, 2020 at 03:35:03PM +0200, Andy Shevchenko wrote:
On Thu, Mar 19, 2020 at 1:54 PM Michal Suchanek [off-list ref] wrote:quoted
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...quoted
+static inline int valid_user_sp(unsigned long sp) +{ + bool is_64 = !is_32bit_task(); + + if (!sp || (sp & (is_64 ? 7 : 3)) || sp > STACK_TOP - (is_64 ? 32 : 16)) + return 0; + return 1; +}Perhaps better to read if (!sp) return 0; if (is_32bit_task()) { if (sp & 0x03) return 0; if (sp > STACK_TOP - 16) return 0; } else { ... } return 1; Other possibility: unsigned long align = is_32bit_task() ? 3 : 7; unsigned long top = STACK_TOP - (is_32bit_task() ? 16 : 32); return !(!sp || (sp & align) || sp > top);
Sounds reasonale. Thanks Michal
-- With Best Regards, Andy Shevchenko