Received: by 10.223.185.116 with SMTP id b49csp4710192wrg; Tue, 27 Feb 2018 00:59:05 -0800 (PST) X-Google-Smtp-Source: AH8x226N23KWw8Vi2osGqIRmRvhfTzU5grPbccfy6IIFR7OmevTcOUY6R1MvpRJaclqn/0hVA9gX X-Received: by 2002:a17:902:904b:: with SMTP id w11-v6mr13615354plz.11.1519721945762; Tue, 27 Feb 2018 00:59:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519721945; cv=none; d=google.com; s=arc-20160816; b=SWRzd9fHRoLdwDWJ/7T7XSwypnssGN/dG+tS46WXURSqGu9V5nTeBp2soNN42xwPvy Jj++OA8xX84qyqhe7mBiPVtlk/TA6WgbJFPbPvHol4SAlr2q1ziV8OKwpe4poOTMNCgg GvoClTDBfaiRYMZX1upM4l22Y1xWlViwPfJm38ft1pDgV+c/eF6Ja2rOXj8hEI0NpbAu f5F8sjKKfEXIhaqAGLwK3lwgWnsIFVpi00cm3V1xw0hYFlJJp2iJoKlRYD//4hSRdVzO 1Wml+ug5TY2DLYZDAPh+lt29OQ2lKHMC8aQ3dcbiVCNjnw0Jtrq62vEPBSB7SImIfikG dZ3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=2+/7LowXRF9jcurzYLnBsEzcKIvVGzAZHz7mV7zCWI0=; b=b6wHSmbTU7rgMwQ8XO5wWUZ/tSPQ2Pv/OPIdiQOPPuBV2jmCA9xEXrTiRoBZ/oV+Yg HfP9C22u1B/kcQvPoTUQjLA1dI3xEfGAge1zymcwoep3gVX/1IxXd41g0eaD6GZDikdK klCux6U82/OIMZOt7YXa16/ve6dSowfb/4HPTaKRRGqIlQvn6cPfaLlOB3pTGuhOFed2 T6EInIcTu09CJkGQcPSAtRJ1yQMPFDHQhp27/N2k8teU5Cfw1moH8143u4WK15Wd7DD/ LYtAJr9r5E01f4Kd8MoQyoU+Gumv+ojRobFxeSA6398MjybNj2y66m6N+O6wj3X8+VuQ mWlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t25si2424635pge.26.2018.02.27.00.58.51; Tue, 27 Feb 2018 00:59:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752103AbeB0I5y (ORCPT + 99 others); Tue, 27 Feb 2018 03:57:54 -0500 Received: from mx2.suse.de ([195.135.220.15]:59965 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752017AbeB0I53 (ORCPT ); Tue, 27 Feb 2018 03:57:29 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B3BCDAC53; Tue, 27 Feb 2018 08:57:27 +0000 (UTC) Date: Tue, 27 Feb 2018 09:57:27 +0100 From: Michal Hocko To: Ilya Smith Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, kirill.shutemov@linux.intel.com, dsafonov@virtuozzo.com, hughd@google.com, gregkh@linuxfoundation.org, craigb@google.com, oleg@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] Take mmap_min_addr into account while choosing unmapped address for x86-64. Message-ID: <20180227085726.GC15357@dhcp22.suse.cz> References: <20180226211257.63067-1-blackzert@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180226211257.63067-1-blackzert@gmail.com> User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 27-02-18 00:12:57, Ilya Smith wrote: [...] > diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c > index 676774b9bb8d..1752fe5cb735 100644 > --- a/arch/x86/kernel/sys_x86_64.c > +++ b/arch/x86/kernel/sys_x86_64.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -185,7 +186,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, > return addr; > > /* requested length too big for entire address space */ > - if (len > TASK_SIZE) > + if (len > TASK_SIZE - mmap_min_addr) > return -ENOMEM; > > /* No address checking. See comment at mmap_address_hint_valid() */ > @@ -210,7 +211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, > > info.flags = VM_UNMAPPED_AREA_TOPDOWN; > info.length = len; > - info.low_limit = PAGE_SIZE; > + info.low_limit = max(PAGE_SIZE, mmap_min_addr); > info.high_limit = get_mmap_base(0); > > /* mmap_min_addr handling is a bit mess... As you say, we would return EPERM rather than ENOMEM which can be confusing but depleting the address space like that is quite unlikely on 64b unless I am missing. It is good to be in sync here with the generic implementation though, IMO. > diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c > index 155ecbac9e28..b6d0c317639e 100644 > --- a/arch/x86/mm/mmap.c > +++ b/arch/x86/mm/mmap.c > @@ -31,6 +31,7 @@ > #include > #include > #include > +#include > #include > > #include "physaddr.h" > @@ -220,6 +221,9 @@ bool mmap_address_hint_valid(unsigned long addr, unsigned long len) > if (TASK_SIZE - len < addr) > return false; > > + if (addr < mmap_min_addr) > + return false; > + > return (addr > DEFAULT_MAP_WINDOW) == (addr + len > DEFAULT_MAP_WINDOW); But is this one necessary? We do sanitze hint address before going to get_unmapped_address AFAIR. -- Michal Hocko SUSE Labs