Received: by 10.192.165.156 with SMTP id m28csp640097imm; Wed, 11 Apr 2018 05:09:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+ghalzub+u3z2Jtgm9gMCRm0tk+rrtXV4B8mj+BaKTxY//CYgSyxeYfRqhfomQDEemLUZR X-Received: by 2002:a17:902:3084:: with SMTP id v4-v6mr4890453plb.262.1523448580500; Wed, 11 Apr 2018 05:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523448580; cv=none; d=google.com; s=arc-20160816; b=BwzMKsueSylfYxeaLPRIcYbBZuGDUfe4vrWaBXpi1O2ShjRCOTRGAnjkU0VSXzSMfB 6tRbZuDvY27DbhQ2yukC0wnzXhn01mwDZtU6G6HQoLPNh2f889/D2sXdk7paAD4K1ICp jw4uoD9f8QrobkrffLk0495oEsb+n7zDRo9m7UeyGp8J90dhv7PaCb44k1mawRnNBAj7 LkujeB6P/jjFyY095Kg/g219jCNBQtuHOQgXg/cUyCLBG/WbnDKouHyb+xTccH8sPdn9 XUvdeptZWRUfd3P410uCxV6Fe+wZQQ9v3Ign6ztqq3tb4nuNqAQrg6iUIt1vGJiIHFNK 0IQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=/cHqUyN0igsx7dW1LNxgVGQVc9gZ5B167o1Bd/dZpCQ=; b=cAL0gDxj6uj+CFM85N7eqkj132mGrXJxuGfHvkQFJh2Lx1u4WyxRrzgy0U6VIyoN+r qdPQ55nVgdqU1+M5sZqO+B3VRsyw15ZrCl92YywXuPG39zVlmuJ0YG/7XghpzadtiABo zuCr5MsGL7xqZimv2YsAs7gDoXOyD1cOBG+QUGssf0WBUi+Dc2o9tH7W46MtK/HpNJdO vMiPnmpRUffK7NaLVLJCpVVMLQ5iSIv5ZQuyI+Ai63LgfO4z9n25ZjDYuPj4bhQoKmCo qVL6+OVTCxsrzw3Fi6gKUhqUD3Z7/erc3CneG4dB06D/Pj4MPFqdXmEmmmKMpBKOpoGf 4PAw== 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 z11si645667pgz.412.2018.04.11.05.09.02; Wed, 11 Apr 2018 05:09:40 -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; 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 S1753122AbeDKMFD (ORCPT + 99 others); Wed, 11 Apr 2018 08:05:03 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:35257 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753093AbeDKMFB (ORCPT ); Wed, 11 Apr 2018 08:05:01 -0400 Received: by mail-pf0-f181.google.com with SMTP id u86so845948pfd.2; Wed, 11 Apr 2018 05:05:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/cHqUyN0igsx7dW1LNxgVGQVc9gZ5B167o1Bd/dZpCQ=; b=TDcMxW/vS6XOy/jRP/uGj5X+m/EVWyOCo7EljXnDFN2XH4rs1TWwoLF4ex49hN7nha jXQSOApX/EIao6CcpesPGSAO2RghqaYP6h3b4lbW6eOsWCwQEm9BxEB3pTcnSPk0dUfM n7TwN5UeOe5i8C9Zbq6ZwUnZFkbpeHMavHRJ2Y9vXjFGzuwC2yy0hCNoyQroVRPrc+6S QFODXH6nBWGKjUI4wm/pw2nHRzSo68SpEwfORxWPPABSEPj+g2+4bTkkPZHfBzFf0WL4 dBjCK+FMKyYg17kNvUmFUQmP52PjrK0i5APnCFU2DrFn3Mjg52JLDnwtCwPMBMg+1iaZ ekJA== X-Gm-Message-State: ALQs6tBuZBGWySc848ROLuScQmR4R4ChovfQ5FYIqaNq39Tor2wT9VsE 3ooYRXGmVkqOyBUYz/6q5tdEuw== X-Received: by 10.98.93.149 with SMTP id n21mr3826945pfj.222.1523448300828; Wed, 11 Apr 2018 05:05:00 -0700 (PDT) Received: from tiehlicka.suse.cz (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id z13sm2174922pgp.80.2018.04.11.05.04.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Apr 2018 05:04:59 -0700 (PDT) From: mhocko@kernel.org To: Michael Kerrisk Cc: John Hubbard , Andrew Morton , , LKML , linux-api@vger.kernel.org, Michal Hocko Subject: [PATCH] mmap.2: document new MAP_FIXED_NOREPLACE flag Date: Wed, 11 Apr 2018 14:04:52 +0200 Message-Id: <20180411120452.1736-1-mhocko@kernel.org> X-Mailer: git-send-email 2.16.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. +.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 , -- 2.16.3