lkml.org 
[lkml]   [2020]   [Mar]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v11 4/8] powerpc/perf: consolidate valid_user_sp
From
Date


Le 19/03/2020 à 14:35, Andy Shevchenko a écrit :
> On Thu, Mar 19, 2020 at 1:54 PM Michal Suchanek <msuchanek@suse.de> wrote:
>>
>> 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
>
> ...
>
>> +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:

I prefer this one.

>
> unsigned long align = is_32bit_task() ? 3 : 7;

I would call it mask instead of align

> unsigned long top = STACK_TOP - (is_32bit_task() ? 16 : 32);
>
> return !(!sp || (sp & align) || sp > top);
>

Christophe

\
 
 \ /
  Last update: 2020-03-19 15:17    [W:0.039 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site