Received: by 10.192.165.156 with SMTP id m28csp349100imm; Thu, 12 Apr 2018 23:45:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx488hn4Js9nBiUO5POF86sForMhRT4qZO6eyKnl99sFwQ+MEd3BadcyUYwj5Hu8GpbLZEnXJ X-Received: by 10.101.98.22 with SMTP id d22mr3186418pgv.344.1523601933764; Thu, 12 Apr 2018 23:45:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523601933; cv=none; d=google.com; s=arc-20160816; b=Ol/WIWCLcZIELShGQYeG5TK9FfxDAA88tqvQbfAsz6FIvuQlRb7N1gznK0yHxW8mlV V1xdmfQZN9iDN5Ty9ngh5G2efr5ZG+6oxdNpffHPqw/t7Q/2INllJqur2jPBvHw1zlaP P15rFL8QsCBouMYvG//T9253l2ovXZ9gT2ijtZmo+v89dX5y+epwIZnwQZTaHjzmJZyT xy7r5zKuV0FtZY5mUNtHjyFdBWVhNv3a4jOseFLdWQQWVc6mLCskRd+M+ayjwrDVtngA QxoEfNXO7heHb/sXNiFzNG6nXzWHTVGciDSuCXTHpptKSNGEJA/4l/YgqCB3RNM/8/SA Mqcg== 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=NTOH380AyW8naRD6As/9HiyVH0K5v2dOT7CmBXSaO10=; b=SjA/sAexoJyE1pzQqaxW7KNr+NY+ncBpSoKXi0TI273xqJO/H7a2zhWyng34eYp8Aj ydxu6cMf6IfBX8/rWgPx5j692rFV2eVCNWj9TZr7BSwidW8yYLG9EiLG4k9A9xQEzRmP VEF/xMWPiWiIGnz9Doy4Uq8nyQ6cQAIM/q8GCBC75XCBHMCrPCwqHd8f7v0IiiFpBzwn g8KM7Mm8OsIxgbMhBKy8t8grqiA18X47kqXOhLuhxCz02ciccnqRClyL1RDt/LeN0F1e 2OoTN9Bl45ygX+sz2KwPcRWQJdveSYWX7yq0iOuikOaIBnehk5155vahJsEc+r69Dp9s pYew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oJMiLUsG; 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 h13si3838981pfi.192.2018.04.12.23.45.20; Thu, 12 Apr 2018 23:45:33 -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=oJMiLUsG; 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 S1753638AbeDMGng (ORCPT + 99 others); Fri, 13 Apr 2018 02:43:36 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:40889 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751133AbeDMGnd (ORCPT ); Fri, 13 Apr 2018 02:43:33 -0400 Received: by mail-wm0-f67.google.com with SMTP id x4so2174641wmh.5; Thu, 12 Apr 2018 23:43:32 -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=NTOH380AyW8naRD6As/9HiyVH0K5v2dOT7CmBXSaO10=; b=oJMiLUsG+0tU3VmGl9lVHeTJvJMbohvZHMuYUKHtnZmAH+wBgx7ZGLwUglcpO7YOhc zA1hV6lDvVI3Z7i58o4x3C/DGRINEUfYlCcR6xpV3w+CrtSlrGRlaB5jCgKZEVHgJnM2 tClnACl9ECtjnwUM+vNK4dVTzeMmRsRDkuEaSp2KC6HF00WhV54EQsLxpNfrRQS6vTm6 Diy36bLFBhJjtCE/nfW1XGMynumb8tFmYbgjHTOyOGbqIbYGS8oAK8Iy8Wy22eGgR02l MY1oe0sg/qo+3zW6Qk+1pt9wzFQ476C6GOe8oUGoWpiWv909Br7+ilEo3RVZzvT9nB7M Lw8Q== 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=NTOH380AyW8naRD6As/9HiyVH0K5v2dOT7CmBXSaO10=; b=nIYdAPvQgeYHOC5ByS6giGkDJwj5TG3aihhA8HOpYjPE+eXKWAGqphaVQkmtQGh53k 4Md0HW6moCcCuM9MnpkoEFQOMxfT5/s30jiqddBy9rSXStXS6w+AOw+xAVxgIuq3Xhx5 hGVr74jBHTa01K7WKFmyDM5R0nx3RlAe+p0jvxKGr1cx7GOvKAg7jv3YwXWzsg0bV/cc GtUafBp4bWlNuc7jVAqGjuVd0iuHWt0uQvM8D44S4OsCZpKAkwkT9ckoxrcF8Ei8A0Kh xmtkx95Lepshzrv2XTGn8yOWrIhQCEKDi3oXJQ5VesXirVV+nrFFMqAQgwhoCLz6TWjf pErA== X-Gm-Message-State: ALQs6tBxUpYwvEmgrllHUKhdkMWsCq8MNLEfjGWrwGh5sWKEd1WOt5c4 fY9B87Q8rBa0CHQKFMpR0yXzWVlu X-Received: by 10.28.144.196 with SMTP id s187mr2643042wmd.82.1523601812094; Thu, 12 Apr 2018 23:43:32 -0700 (PDT) Received: from [192.168.234.154] (mail2.jambit.com. [213.131.239.194]) by smtp.gmail.com with ESMTPSA id d9sm1664767wmh.38.2018.04.12.23.43.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Apr 2018 23:43:30 -0700 (PDT) Cc: mtk.manpages@gmail.com, linux-man , Michal Hocko , Andrew Morton , Linux-MM , lkml , Linux API Subject: Re: [PATCH] mmap.2: MAP_FIXED is okay if the address range has been reserved To: John Hubbard , Jann Horn References: <20180412153941.170849-1-jannh@google.com> <13801e2a-c44d-e940-f872-890a0612a483@nvidia.com> From: "Michael Kerrisk (man-pages)" Message-ID: <9c714917-fc29-4d12-b5e8-cff28761a2c1@gmail.com> Date: Fri, 13 Apr 2018 08:43:27 +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/12/2018 09:24 PM, John Hubbard wrote: > On 04/12/2018 12:18 PM, Jann Horn wrote: >> On Thu, Apr 12, 2018 at 8:59 PM, John Hubbard wrote: >>> On 04/12/2018 11:49 AM, Jann Horn wrote: >>>> On Thu, Apr 12, 2018 at 8:37 PM, Michael Kerrisk (man-pages) >>>> wrote: >>>>> Hi John, >>>>> >>>>> On 12 April 2018 at 20:33, John Hubbard wrote: >>>>>> On 04/12/2018 08:39 AM, Jann Horn wrote: >>>>>>> Clarify that MAP_FIXED is appropriate if the specified address range has >>>>>>> been reserved using an existing mapping, but shouldn't be used otherwise. >>>>>>> >>>>>>> Signed-off-by: Jann Horn >>>>>>> --- >>>>>>> man2/mmap.2 | 19 +++++++++++-------- >>>>>>> 1 file changed, 11 insertions(+), 8 deletions(-) >>>>>>> >>>>>>> diff --git a/man2/mmap.2 b/man2/mmap.2 >>>> [...] >>>>>>> .IP >>>>>>> For example, suppose that thread A looks through >>>>>>> @@ -284,13 +285,15 @@ and the PAM libraries >>>>>>> .UR http://www.linux-pam.org >>>>>>> .UE . >>>>>>> .IP >>>>>>> -Newer kernels >>>>>>> -(Linux 4.17 and later) have a >>>>>>> +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 >>>>>>> .B MAP_FIXED_NOREPLACE >>>>>>> -option that avoids the corruption problem; if available, >>>>>>> -.B MAP_FIXED_NOREPLACE >>>>>>> -should be preferred over >>>>>>> -.BR MAP_FIXED . >>>>>>> +that should be used instead; older kernels require the caller to use >>>>>>> +.I addr >>>>>>> +as a hint (without >>>>>>> +.BR MAP_FIXED ) >>>>>> >>>>>> Here, I got lost: the sentence suddenly jumps into explaining non-MAP_FIXED >>>>>> behavior, in the MAP_FIXED section. Maybe if you break up the sentence, and >>>>>> possibly omit non-MAP_FIXED discussion, it will help. >>>>> >>>>> Hmmm -- true. That piece could be a little clearer. >>>> >>>> How about something like this? >>>> >>>> For cases in which MAP_FIXED can not be used because >>>> 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 and take appropriate action if >>>> the kernel places the new mapping at a different address. >>>> >>>> John, Michael, what do you think? >>> >>> >>> I'm still having difficulty with it, because this is in the MAP_FIXED section, >>> but I think you're documenting the behavior that you get if you do *not* >>> specify MAP_FIXED, right? Also, the hint behavior is true of both older and >>> new kernels... >> >> The manpage patch you and mhocko wrote mentioned MAP_FIXED_NOREPLACE >> in the MAP_FIXED section - I was trying to avoid undoing a change you >> had just explicitly made. > > heh. So I've succeeding in getting my own wording removed, then? Progress! :) > >> >>> So, if that's your intent (you want to sort of document by contrast to what >>> would happen if this option were not used), then how about something like this: >>> >>> >>> Without the MAP_FIXED option, the kernel would treat addr as a hint, rather >>> than a requirement, and the caller would need to take appropriate action >>> if the kernel placed the mapping at a different address. (For example, >>> munmap and try again.) >> >> I'd be fine with removing the paragraph. As you rightly pointed out, >> it doesn't really describe MAP_FIXED. >> > > OK, that's probably the simplest fix. 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. ? Thanks, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/