From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752151AbdJ0IZp (ORCPT ); Fri, 27 Oct 2017 04:25:45 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:52808 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751070AbdJ0IZk (ORCPT ); Fri, 27 Oct 2017 04:25:40 -0400 X-Google-Smtp-Source: ABhQp+ST+gx2RfgNVeSzdo8uyC4Fmvc8H6khJFP3ZzZSVGWq/BGop+85obZD1LiIOW8HgJ+/eKd3Iw== Date: Fri, 27 Oct 2017 10:25:36 +0200 From: Ingo Molnar To: Linus Torvalds Cc: Craig Bergstrom , Sander Eikelenboom , Boris Ostrovsky , Fengguang Wu , wfg@linux.intel.com, Linux Kernel Mailing List , LKP Subject: Re: ce56a86e2a ("x86/mm: Limit mmap() of /dev/mem to valid physical addresses"): kernel BUG at arch/x86/mm/physaddr.c:79! Message-ID: <20171027082536.nddlpodniv6saylz@gmail.com> References: <440615a7-6cc0-a607-ce7c-22a34b69e8fe@eikelenboom.it> <1d203c07-0595-a33a-620b-c51eea9721d1@eikelenboom.it> <8721eeac-a644-e815-55e9-5f01956dd22a@eikelenboom.it> <20171026163911.dnovh4zaik5qumtt@gmail.com> <20171026190229.zt743ooxvjsukmis@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Linus Torvalds wrote: > On Thu, Oct 26, 2017 at 9:02 PM, Ingo Molnar wrote: > > > > Well, 'mem=2048M' shouldn't really limit device memory, it's supposed to limit > > (trim) 'RAM' and not much else. > > Agreed. You should very much be able to map in IO memory or whatever > above the 2G address even if the high_memory itself might be limited > to 2GB. > > So I think that commit ce56a86e2ade ("x86/mm: Limit mmap() of /dev/mem > to valid physical addresses") is wrong, in that "high_memory" is very > much the wrong thing to test. > > The memory mapping limit might validly be something like > > 1ull << boot_cpu_data.x86_phys_bits > > or similar, but for now I suspect that the right thing to do is to > revert. I'm not convinced that our "x86_phys_bits" value is guaranteed > to be always right, since I think we mainlyjust use it for showing > things, rather than have lots of code that depends on it. > > Ingo? Yeah, I think a more robust condition would be something like: int valid_phys_addr_range(phys_addr_t addr, size_t count) { return !((addr + count) >> MAX_PHYSMEM_BITS); } ... as we already rely on MAX_PHYSMEM_BITS in a number of other critical places. (Totally untested though.) Thanks, Ingo