Received: by 10.192.165.156 with SMTP id m28csp1670335imm; Thu, 12 Apr 2018 01:10:32 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+0Bt1OjFfKlX4VDnrzxmOIf54batxCaKKRbBAuidNBlrvo6dzw9FuskzwzBTXNTmmD+fG+ X-Received: by 10.99.111.136 with SMTP id k130mr5824986pgc.378.1523520632545; Thu, 12 Apr 2018 01:10:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523520632; cv=none; d=google.com; s=arc-20160816; b=jZ00RUPhW5MlJjXUjKZMqbpiujmZiMc3wJlK5JdHxObPClyRp7ryfd90DiYWxP3jG4 QrqBvjOzdLtc55j1LLKLUSqSOuO3Ja57uSj7At0TXZU0iIRkYJ2iPJObrPrnmi/bj+Rr TLlQrkWp4AMmdsF0YPlmnWX87RQQTmHm2tm1s6zFN8JGM0OrbMh8CFQOEfmlryhAbRnM Jlo9XKJPw5u8KLxcexJvOpLcV4ooB+0RXYuBSJEuDJd/TbiFYkAE8XkvPYml5VBJMzuw h403XvnQZ2BMcLcctKnkZUlogkV2qUViWmcoQA3xbA0NwfKlRzMygJo8l/JfC92Oom7i gPYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:cc:dkim-signature :arc-authentication-results; bh=U6Fi5s1tBt8OGWuhePBeNyzBqwjPDCTw9BmJ4LehtRY=; b=nPV2B+1b+qDOyWzOE/Qg647SAi5LhY9a5+8dKCaBzG99ijzRjLLZZNLiO3ldGX/Sb2 j/5fj+YDKRbxexkr/MQjJ6zwgNzEtQurB7EzMd9o7oTpvzymRUK8EgcGutabPfkpsN2I 3xEdD7qbZbn1GB/Lr3KsXlUZqv7vPc+tICs7Q10xFlY56h/Z1y9DOBTrLeWzR+zki/aD 1jaja5weXe6vGkO09XQsd/d9l3SAKfj29nhPIwC4tqELhzo5f6Nr0UjLPAxnQSA4kLvb MbwKA1oCJr+WC5O65BTTrcsxc3ZRYTdP59iDwgLsBABCHBuYOIH127I6BguOhs7edzwn kOYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qCNvQt1m; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m18si1877366pgv.360.2018.04.12.01.09.55; Thu, 12 Apr 2018 01:10:32 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qCNvQt1m; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753085AbeDLIET (ORCPT + 99 others); Thu, 12 Apr 2018 04:04:19 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36863 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753032AbeDLIEL (ORCPT ); Thu, 12 Apr 2018 04:04:11 -0400 Received: by mail-wm0-f67.google.com with SMTP id x82so8000146wmg.1; Thu, 12 Apr 2018 01:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=cc:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=U6Fi5s1tBt8OGWuhePBeNyzBqwjPDCTw9BmJ4LehtRY=; b=qCNvQt1mtu240Ib3cLbihwniSrUEutTDg+p2wqpHuqGt/VmeAKcmhCKsnOrpUyvpsV yUNDFiHNS28ID4PoX9VZWfN6T1dyfLFsJ/DM+74iGm7PnrDxbvwYVdUOZ2+GMgI+My5X vNVogETn6X5AFfODsDa+NrzMqmGsfg+zFza10HN7gDvPe4Ths+b1aCil2ytd82nxM73M UTozq8NzyCE1P0Rlw5Gf873LlwRQl3JKXIaY31CM6l6Mx6amWeXCoExk/V/my2TU/Z2u 9fiYnRjQCLMGo6AcaI3PktgQTIiDO5M+6eKZuEGmUGhV3MIix1IAsH6hcBFZNKdBM4bU AQVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:cc:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=U6Fi5s1tBt8OGWuhePBeNyzBqwjPDCTw9BmJ4LehtRY=; b=hiwhJ2xPphWc/x+yjSJBkkmSB+m8oVx+IOAGXPTyP1JsfxQxEX68SvqGl3j+KJK4ht iJDA02oAZt/9O3EsR66MKkiC7CCS6ZSqoKaS9dPbGuOAeYBxkbrueO/UTcurunkeoEPD LjgzDwug8CWfeAOfRiF73ISD8AVpSWSDjT1FFAqaIbSvkbcound3HYf+LvBgDT9Byzra gBh2qQ4wIHqN8vX5hez++G3kxsduOIhAh0/uo0qiGHNcelF8aI4LqWcS19dlPUuMkGAC ku1g9BbLf42fHfjzO79IAT/VHXYBWXrVNYW1BacdO9MO0cRG9L8rptOJIC5qnqIPWsNq +F+Q== X-Gm-Message-State: ALQs6tDxTgtHXaGQPhC0Fu+ZvxF9YWAiZjN1SWV9y8AbMke9FeK8wXD8 Bpisioko4LTCs74u8vw430s= X-Received: by 10.28.66.206 with SMTP id k75mr4625944wmi.34.1523520250457; Thu, 12 Apr 2018 01:04:10 -0700 (PDT) Received: from [192.168.234.154] (mail2.jambit.com. [213.131.239.194]) by smtp.gmail.com with ESMTPSA id c141sm3912216wmh.21.2018.04.12.01.04.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Apr 2018 01:04:09 -0700 (PDT) Cc: mtk.manpages@gmail.com, John Hubbard , Andrew Morton , linux-mm@kvack.org, LKML , linux-api@vger.kernel.org, Michal Hocko Subject: Re: [PATCH] mmap.2: document new MAP_FIXED_NOREPLACE flag To: mhocko@kernel.org References: <20180411120452.1736-1-mhocko@kernel.org> From: "Michael Kerrisk (man-pages)" Message-ID: <97504dda-4252-a150-e7b5-43fe587aa055@gmail.com> Date: Thu, 12 Apr 2018 10:04:06 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180411120452.1736-1-mhocko@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Michal, On 04/11/2018 02:04 PM, mhocko@kernel.org wrote: > From: Michal Hocko > > 4.17+ kernels offer a new MAP_FIXED_NOREPLACE flag which allows the caller to > atomicaly probe for a given address range. > > [wording heavily updated by John Hubbard ] > Signed-off-by: Michal Hocko Thanks! I've applied your patch, and done a little tweaking. The results have already been pushed. Cheers Michael > --- > Hi, > Andrew's sent the MAP_FIXED_NOREPLACE to Linus for the upcoming merge > window. So here we go with the man page update. > > man2/mmap.2 | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/man2/mmap.2 b/man2/mmap.2 > index ea64eb8f0dcc..f702f3e4eba2 100644 > --- a/man2/mmap.2 > +++ b/man2/mmap.2 > @@ -261,6 +261,27 @@ Examples include > and the PAM libraries > .UR http://www.linux-pam.org > .UE . > +Newer kernels > +(Linux 4.17 and later) have a > +.B MAP_FIXED_NOREPLACE > +option that avoids the corruption problem; if available, MAP_FIXED_NOREPLACE > +should be preferred over MAP_FIXED. > +.TP > +.BR MAP_FIXED_NOREPLACE " (since Linux 4.17)" > +Similar to MAP_FIXED with respect to the > +.I > +addr > +enforcement, but different in that MAP_FIXED_NOREPLACE never clobbers a pre-existing > +mapped range. If the requested range would collide with an existing > +mapping, then this call fails with > +.B EEXIST. > +This flag can therefore be used as a way to atomically (with respect to other > +threads) attempt to map an address range: one thread will succeed; all others > +will report failure. Please note that older kernels which do not recognize this > +flag will typically (upon detecting a collision with a pre-existing mapping) > +fall back to a "non-MAP_FIXED" type of behavior: they will return an address that > +is different than the requested one. Therefore, backward-compatible software > +should check the returned address against the requested address. > .TP > .B MAP_GROWSDOWN > This flag is used for stacks. > @@ -487,6 +508,12 @@ is not a valid file descriptor (and > .B MAP_ANONYMOUS > was not set). > .TP > +.B EEXIST > +range covered by > +.IR addr , > +.IR length > +is clashing with an existing mapping. > +.TP > .B EINVAL > We don't like > .IR addr , > -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/