Re: [PATCH 16/19] x86, mpx: support 32-bit binaries on 64-bit kernel

Thomas Gleixner
2015-05-18T23:37:32Z

On Mon, 18 May 2015, Dave Hansen wrote:
> On 05/18/2015 02:53 PM, Thomas Gleixner wrote:
> >> +/*
> >> + * Total size of the process's virtual address space
> >> + * Use a u64 because 4GB (for 32-bit) won't fit in a long.
> >> + *
> >> + * __VIRTUAL_MASK does not work here. It only covers the
> >> + * user address space and the tables cover the *entire*
> >> + * virtual address space supported on the CPU.
> >> + */
> >> +static inline unsigned long long mm_virt_space(struct mm_struct *mm)
> >> +{
> >> + if (is_64bit_mm(mm))
> >> + return 1ULL << 48;
> >
> > cpu_info->x86_phys_bits will tell you the proper value
> >
> >> + else
> >> + return 1ULL << 32;
> >
> > And for a 32bit kernel 32 might be wrong because with PAE you have 36
> > bits.
>
> That's physical space. I really do need virtual space here.

Stupid me

> >> + /*
> >> + * The two return calls above are exact copies. If we
> >> + * pull out a single copy and put it in here, gcc won't
> >> + * realize that we're doing a power-of-2 divide and use
> >> + * shifts. It uses a real divide. If we put them up
> >> + * there, it manages to figure it out (gcc 4.8.3).
> >
> > Can't we provide the shift values from bd_entry_virt_space() so we
> > don't have to worry about gcc versions being more or less clever?
>
> Yes, I could go back and rework all the math to be done with shifts
> instead of power-of-2 divides (which is what was done before). But,
> it's very clear the way that it stands, minus this wart. The code look
> a *lot* better this way.
>
> This isn't super performance-sensitive code. It's basically in the
> munmap() path. I just really didn't like the idea of an actual integer
> divide in there.
>
> So, if GCC breaks this, so be it. I don't think we'll ever notice. The
> optimization was just too obvious to completely ignore.

Fair enough.

Thanks,

tglx