Received: by 10.192.165.156 with SMTP id m28csp886015imm; Wed, 11 Apr 2018 08:45:35 -0700 (PDT) X-Google-Smtp-Source: AIpwx48GBAI3fGqRkT+b1ONgr2gGCX7dNNmnSA9SJnJ0dNs+/mIocvKBN275sGSwTnGYJWKCn5mD X-Received: by 10.101.100.212 with SMTP id t20mr3942545pgv.112.1523461535439; Wed, 11 Apr 2018 08:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523461535; cv=none; d=google.com; s=arc-20160816; b=p8uGldQyLgxbGiee01K/+91FXrHgPrcRruazSBDtFhXJ5rvV1llNBWjg4yquxY6WqG nUOETmbAZegMZIomCEatyhRj221Rt5x8bLuzf6VPyaJz+8R8/Jh2qDPot3wOsTEgmAMH 7mYWiDxRmTgpYbMgSG/dRV6JgvVviGvCu0cWChI8DSwsfw5NSMBafDypJjdbY8B8MSZB OqgJQ9xU78F5UTzc73k2yDEHVfcvBncQEKz3UA8sSBV6K6OpAHvocirqjD6zmvKDuJgt zRlH4vaNR3xWv74GGP98s+/S0cPxnEorjEZCIhD7FKSVocwEZGpk4TbX2ts95B5dIxR5 xqHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=aWG3FzJ4oE5K8axqNFjp1UmNceXJqYXadcpeUZ5mybY=; b=F9zDtsOlzAPbOpzUOoH8/139Z14AcIuxHgezI4lowJYgzQnSKdISQhJTsnige8q10r /g8uAipKTMpFYS9T15APa7CvRAIGBfys+2Nxb/nFzqr34s7bLKQUVgYXC+ARB0yt0xa2 +1V0UlS0S1sUbLMQDBt/mCnFAD/kiZBXOSR/8ylaJMcuj6laIKHEiv/M1lbeevuoUGYT ZnLJ+tOUK/JUnTO2CFvkcqPXhEKnE2JZN+QTs5XIzUWqMZdykNbzqTEXOiZHdtLMrZVF S5ziVbMwiU9D9keyTZxt8UFWDBdxIKlBtaUN9khR9VyLzLzHFJyaxZMo7tRoTKyfWcAy +e3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ES5vWODf; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f19si921228pgn.277.2018.04.11.08.44.58; Wed, 11 Apr 2018 08:45:35 -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=@google.com header.s=20161025 header.b=ES5vWODf; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753888AbeDKPiJ (ORCPT + 99 others); Wed, 11 Apr 2018 11:38:09 -0400 Received: from mail-oi0-f49.google.com ([209.85.218.49]:33118 "EHLO mail-oi0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753122AbeDKPiH (ORCPT ); Wed, 11 Apr 2018 11:38:07 -0400 Received: by mail-oi0-f49.google.com with SMTP id 126-v6so2129479oig.0 for ; Wed, 11 Apr 2018 08:38:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=aWG3FzJ4oE5K8axqNFjp1UmNceXJqYXadcpeUZ5mybY=; b=ES5vWODfYR1KvudS1Kf/r8RPAMprQhM7DKvXD01xeYTFxrIdkFRHYLOGAAGxMLykh5 0ebvc1KaY0AAfUZtcw2dBkXb+xhW2vyRKbb7cysMjy732Wjf92knrJrOH43eVz8XIIbA BRk4ivuakSwj7hXPgo6E5Wb/6lZhWnZq5v/ndSv7Xf+dn+kNpRzuewWBcno6i5JCTV+W 8msuNey/Ve8eUW/nQ+b/FkdluMEbXL4UQYnaf/DY3JBQZ4a6XXybOygvBuCuqLOj/j9z EfXzCg+0wLMLtvL2VuSE4dH/Z7alRJPoSBt/CmLStUbRD2ZNgxi66oOPtxBfjl+JtnBY JMdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=aWG3FzJ4oE5K8axqNFjp1UmNceXJqYXadcpeUZ5mybY=; b=ZkoLbk8oQXnZD7gT4v9n/Eh7dy4M9A+6GqI06Yd1hHRowkLGAP6wXpPBnqmQYuV4xo 8tBIY21/7TCIwCiKU23DnWNhlxtknjhsQOdDuMZuT2phYYC7Oxvi2HH7gIPKe7C/7zxy ml5lbXCuFvW9pj4R4yAS3KXuW2FnLAK1A6/YjI6SQQnPMiK/MK7vMzIQCozorR9SYZXe dtM11ilO8SKqLho8lWPOAd/8SATaUm5YC8zdNsvrV64d6xuSv3KcrtMePBD9tNgpkUmF w3J8CiwtZxSXU/GMOeixCp3GvI94EU2VtnAXhbYKKejrFZ38oMGcJHfwAWCgUbjBF1lE Dpsg== X-Gm-Message-State: ALQs6tD5AlGHobfqiUh0x2bTKWQdbK3AlcaavYdN9oNJOkrGj8WNZjxN 0ZVO0UNfOPl8DML4UskUpGJyVSjSaMS4Iy0Aw7DCVg== X-Received: by 2002:aca:5484:: with SMTP id i126-v6mr3108894oib.219.1523461086971; Wed, 11 Apr 2018 08:38:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.73.133 with HTTP; Wed, 11 Apr 2018 08:37:46 -0700 (PDT) In-Reply-To: <20180411120452.1736-1-mhocko@kernel.org> References: <20180411120452.1736-1-mhocko@kernel.org> From: Jann Horn Date: Wed, 11 Apr 2018 17:37:46 +0200 Message-ID: Subject: Re: [PATCH] mmap.2: document new MAP_FIXED_NOREPLACE flag To: Michal Hocko Cc: Michael Kerrisk , John Hubbard , Andrew Morton , Linux-MM , LKML , Linux API , Michal Hocko Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 11, 2018 at 2:04 PM, 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 > --- > 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. This still looks wrong to me. There are legitimate uses for MAP_FIXED, and for most users of MAP_FIXED that I'm aware of, MAP_FIXED_NOREPLACE wouldn't work while MAP_FIXED works perfectly well. MAP_FIXED is for when you have already reserved the targeted memory area using another VMA; MAP_FIXED_NOREPLACE is for when you haven't. Please don't make it sound as if MAP_FIXED is always wrong. > +.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. Maybe add something like ", and MAP_FIXED_NOREPLACE was specified"? I think most manpages explicitly document which error conditions can be triggered by which flags.