From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michal Hocko Subject: Re: [PATCH] mmap.2: MAP_FIXED is okay if the address range has been reserved Date: Tue, 17 Apr 2018 08:23:10 +0200 Message-ID: <20180417062310.GW17484@dhcp22.suse.cz> References: <20180416100736.GG17484@dhcp22.suse.cz> <20180416191805.GS17484@dhcp22.suse.cz> <20180416195726.GT17484@dhcp22.suse.cz> <20180416211115.GU17484@dhcp22.suse.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Jann Horn Cc: "Michael Kerrisk (man-pages)" , John Hubbard , linux-man , Andrew Morton , Linux-MM , lkml , Linux API List-Id: linux-man@vger.kernel.org On Mon 16-04-18 23:12:48, Jann Horn wrote: > On Mon, Apr 16, 2018 at 11:11 PM, Michal Hocko wrote: > > On Mon 16-04-18 22:17:40, Jann Horn wrote: > >> On Mon, Apr 16, 2018 at 9:57 PM, Michal Hocko wrote: > >> > On Mon 16-04-18 21:30:09, Jann Horn wrote: > >> >> On Mon, Apr 16, 2018 at 9:18 PM, Michal Hocko wrote: > >> > [...] > >> >> > Yes, reasonably well written application will not have this problem. > >> >> > That, however, requires an external synchronization and that's why > >> >> > called it error prone and racy. I guess that was the main motivation for > >> >> > that part of the man page. > >> >> > >> >> What requires external synchronization? I still don't understand at > >> >> all what you're talking about. > >> >> > >> >> The following code: > >> >> > >> >> void *try_to_alloc_addr(void *hint, size_t len) { > >> >> char *x = mmap(hint, len, ...); > >> >> if (x == MAP_FAILED) return NULL; > >> >> if (x == hint) return x; > >> > > >> > Any other thread can modify the address space at this moment. > >> > >> But not parts of the address space that were returned by this mmap() call. > > ? > >> > Just > >> > consider that another thread would does mmap(x, MAP_FIXED) (or any other > >> > address overlapping [x, x+len] range) > >> > >> If the other thread does that without previously having created a > >> mapping covering the area in question, that would be a bug in the > >> other thread. > > > > MAP_FIXED is sometimes used without preallocated address ranges. > > Wow, really? Can you point to an example? Just from top of my head. Some of that is for historical reasons because the hint address used to be ignored on some operating systems so MAP_FIXED had to be used. Currently not user I guess but MAP_FIXED for addresses above 47b address space AFAIR. And I am pretty sure there would be much more if you actually browsed code search. -- Michal Hocko SUSE Labs