On Thu, Mar 19, 2020 at 03:16:03PM +0100, Christophe Leroy wrote: > > > Le 19/03/2020 à 14:35, Andy Shevchenko a écrit : > > On Thu, Mar 19, 2020 at 1:54 PM Michal Suchanek <msucha...@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; > > > +} > > > > 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); And we can avoid the inversion here as well as in !valid_user_sp(sp) by changing to invalid_user_sp.
Thanks Michal