From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi0-f72.google.com (mail-oi0-f72.google.com [209.85.218.72]) by kanga.kvack.org (Postfix) with ESMTP id 16E4C6B0007 for ; Fri, 13 Apr 2018 12:05:47 -0400 (EDT) Received: by mail-oi0-f72.google.com with SMTP id g204-v6so5037431oic.14 for ; Fri, 13 Apr 2018 09:05:47 -0700 (PDT) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id t5-v6sor3073000ota.102.2018.04.13.09.05.46 for (Google Transport Security); Fri, 13 Apr 2018 09:05:46 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20180413160435.GA17484@dhcp22.suse.cz> References: <20180412153941.170849-1-jannh@google.com> <13801e2a-c44d-e940-f872-890a0612a483@nvidia.com> <9c714917-fc29-4d12-b5e8-cff28761a2c1@gmail.com> <20180413064917.GC17484@dhcp22.suse.cz> <20180413160435.GA17484@dhcp22.suse.cz> From: Jann Horn Date: Fri, 13 Apr 2018 18:05:24 +0200 Message-ID: Subject: Re: [PATCH] mmap.2: MAP_FIXED is okay if the address range has been reserved Content-Type: text/plain; charset="UTF-8" Sender: owner-linux-mm@kvack.org List-ID: To: Michal Hocko Cc: "Michael Kerrisk (man-pages)" , John Hubbard , linux-man , Andrew Morton , Linux-MM , lkml , Linux API On Fri, Apr 13, 2018 at 6:04 PM, Michal Hocko wrote: > On Fri 13-04-18 17:04:09, Jann Horn wrote: >> On Fri, Apr 13, 2018 at 8:49 AM, Michal Hocko wrote: >> > On Fri 13-04-18 08:43:27, Michael Kerrisk wrote: >> > [...] >> >> So, you mean remove this entire paragraph: >> >> >> >> For cases in which the specified memory region has not been >> >> reserved using an existing mapping, newer kernels (Linux >> >> 4.17 and later) provide an option MAP_FIXED_NOREPLACE that >> >> should be used instead; older kernels require the caller to >> >> use addr as a hint (without MAP_FIXED) and take appropriate >> >> action if the kernel places the new mapping at a different >> >> address. >> >> >> >> It seems like some version of the first half of the paragraph is worth >> >> keeping, though, so as to point the reader in the direction of a remedy. >> >> How about replacing that text with the following: >> >> >> >> Since Linux 4.17, the MAP_FIXED_NOREPLACE flag can be used >> >> in a multithreaded program to avoid the hazard described >> >> above. >> > >> > Yes, that sounds reasonable to me. >> >> But that kind of sounds as if you can't avoid it before Linux 4.17, >> when actually, you just have to call mmap() with the address as hint, >> and if mmap() returns a different address, munmap() it and go on your >> normal error path. > > This is still racy in multithreaded application which is the main point > of the whole section, no? No, it isn't.