Received: by 10.192.165.156 with SMTP id m28csp1672229imm; Thu, 12 Apr 2018 01:13:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx48iNCs7BPIWpAgdxsx+gl+ppVS/w+msrFLhewo+ZydjtKVWEMB+dLso73RrbDviBg2XGvN3 X-Received: by 2002:a17:902:8606:: with SMTP id f6-v6mr8907386plo.258.1523520785446; Thu, 12 Apr 2018 01:13:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523520785; cv=none; d=google.com; s=arc-20160816; b=kRuGCTb28AVvhCVPp1sopONP6VBJsBVlphczFKWDK6jhgxUNjU/ENn6AWUKhYMWVCg 40i7Z2TQqk4fcE+VvClq5dIfIBfI+p9FVUTU0xaGJVvjCsgs5scJmiffFBzkvY4gjKs+ dzvU8N4NK1WNDKV/Ah0yzJk8qr7JdDA3cDAliAoCLl1SEiQ4BN8BpDM408cu1GiLjWsK Y2rmOyIyTZ5XX5bMaoK58KEFdecJHWsLrKLs+Td4OAY3cT2+/8uvKAvj3zdwKdrJ5sOH TZGdbnKwzkayh4Vz09u39sGpfZH4sJgstmdTbu02lvd0oDKKrhebsVDwowhCNbBM3VdA lwGA== 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=X+FFt0a89Ldn/Ku4qebHJdeKzLGvsa55zYlAeW10b7M=; b=L+04OoqBFpeXSYHDbgd5eomo1Se7eyTXvCg2NnI1mVY+GEK/ZoiVhM+frxzKvVqk+t bWlwlR/88LyFccOMcfLuWQiwGtRXCr1GzZ2JYArOq/J56QqV5vArD6OQXuoZITI4ewq9 5mPVxpXIUwKOGbiKRNKapw+iUlAXUiLJ3YlDnPogsQ6H1Gc+Cvopn15npn8rZTTGeiqb VJVMHpqBivrrfNPJIn3OQxQL64YJm91YZGZpKxKRghACN7x5hzzg+/ORMf5HSI/Qypuu ses8VNBK3n1uLcw+1adGIXsdDFcI7EjItpXfm78exq0nl/DnCufd7Ky3/Rr5WwECJtqP tzXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=j90HxZKZ; 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 w130si2172078pfd.408.2018.04.12.01.12.28; Thu, 12 Apr 2018 01:13:05 -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=j90HxZKZ; 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 S1753104AbeDLIJT (ORCPT + 99 others); Thu, 12 Apr 2018 04:09:19 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:52778 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753027AbeDLIJR (ORCPT ); Thu, 12 Apr 2018 04:09:17 -0400 Received: by mail-wm0-f68.google.com with SMTP id g8so9528803wmd.2; Thu, 12 Apr 2018 01:09:16 -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=X+FFt0a89Ldn/Ku4qebHJdeKzLGvsa55zYlAeW10b7M=; b=j90HxZKZ7mhJbH34Q/CBmJNmRltxzC/+NvF26u/MQlIpT17kgfmwhNXzzCM99Vr0M/ bPJKIaD8sSOB57voqpUc8oS7q9e22tSKwN+uTmWboT2rjk5lraTCSDGoZ0PolF6EMYpT inn0x3hadJRXoJgj6eN4Ok6svK/PPUFv3ee3vtZhBGaAzOITSL5M1Nu1j37hXj1iYQxj GW7cgh/VLNhhMal86p36BiBJp0dxEaflBZtO6bbnXug2yXEXKhe8bS0HbUcNebGnXBFQ Q3PmA4mG43TF2dtbSqBZBL3ZRxGwWaKxdQI5uQ7H3RROllkrS5hH4YANTTrPhCG9r7Tq 9Q0w== 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=X+FFt0a89Ldn/Ku4qebHJdeKzLGvsa55zYlAeW10b7M=; b=fz0/Nt+5ikwqcqpeeTBD4dn7X6lXtQHKK+waPqR10yG1uWbpPkiI1pobgOdFpGpAGP Ac9bqTECrTWpYtNPoTj6IPKjWcto6T9Ni03LnGDEEKXgz1oXfJiZgfHnO+cZlOj490Yg FFtmgE+nvf8lIfQdkLkFYA3LdsNAbbfubb5eL4NztY/+6LMzTP+/pY6XRSkykEPn1EI8 7dyVQOGlgU49PIR3oAIPYTartr1i40ZXAayLMy5Sj7qCP4FY+mngYtBFrrqpRv/7nnHz C3x3sirhQvwAi4MfVw0ujHxH6jRkiBIYcysn3HQcmzyIhChrqdmc++p7J3hC6mqy8uiY eHrQ== X-Gm-Message-State: ALQs6tBqAmFtNmlz7kszMac8QFqr2MAhtGiK1bEmQShKwAT2VDB5K11v vKJMboxYoBO+pEhNvdzDXhfpqa8K X-Received: by 10.28.237.11 with SMTP id l11mr4606369wmh.124.1523520555837; Thu, 12 Apr 2018 01:09:15 -0700 (PDT) Received: from [192.168.234.154] (mail2.jambit.com. [213.131.239.194]) by smtp.gmail.com with ESMTPSA id p128sm4487385wmd.45.2018.04.12.01.09.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Apr 2018 01:09:15 -0700 (PDT) Cc: mtk.manpages@gmail.com, John Hubbard , Andrew Morton , Linux-MM , LKML , Linux API Subject: Re: [PATCH] mmap.2: document new MAP_FIXED_NOREPLACE flag To: Jann Horn , Michal Hocko References: <20180411120452.1736-1-mhocko@kernel.org> <20180411163631.GL23400@dhcp22.suse.cz> From: "Michael Kerrisk (man-pages)" Message-ID: Date: Thu, 12 Apr 2018 10:09:09 +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: 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 On 04/11/2018 06:40 PM, Jann Horn wrote: > On Wed, Apr 11, 2018 at 6:36 PM, Michal Hocko wrote: >> On Wed 11-04-18 17:37:46, Jann Horn wrote: >>> 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. >> >> Well, this was suggested by John. I think, nobody is objecting that >> MAP_FIXED has legitimate usecases. The above text just follows up on >> the previous section which emphasises the potential memory corruption >> problems and it suggests that a new flag is safe with that regards. >> >> If you have specific wording that would be better I am open for changes. > > I guess I'd probably also want to change the previous text; so I > should probably send a followup patch once this one has landed. > >>>> +.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. >> >> sure, no objection from me. I've added the suggested piece from Jann to the EEXIST error description. Cheers, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/