From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755212AbbERXhc (ORCPT ); Mon, 18 May 2015 19:37:32 -0400 Received: from www.linutronix.de ([62.245.132.108]:51700 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755045AbbERXha (ORCPT ); Mon, 18 May 2015 19:37:30 -0400 Date: Tue, 19 May 2015 01:37:40 +0200 (CEST) From: Thomas Gleixner To: Dave Hansen cc: linux-kernel@vger.kernel.org, x86@kernel.org, dave.hansen@linux.intel.com Subject: Re: [PATCH 16/19] x86, mpx: support 32-bit binaries on 64-bit kernel In-Reply-To: <555A75F5.1000503@sr71.net> Message-ID: References: <20150508185948.4C19F4B0@viggo.jf.intel.com> <20150508185955.677AE7E0@viggo.jf.intel.com> <555A75F5.1000503@sr71.net> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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