Received: by 10.192.165.156 with SMTP id m28csp2330766imm; Thu, 12 Apr 2018 12:26:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx49OrRLNTE4dppik45DWkItJdGZw1lEtDgo4tilgrLxoSEnQp7LJhOw5usfu6hYrbLT1lzAG X-Received: by 2002:a17:902:8646:: with SMTP id y6-v6mr2362753plt.86.1523561168176; Thu, 12 Apr 2018 12:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523561168; cv=none; d=google.com; s=arc-20160816; b=MUP2rOlyocGfxHVjLvD+byHVjEj/rYveqEtTUtiFfvYeDZouLb1+mqAzs8tQvfONF6 I4w6m3C5iQfIDh7YkoLrmS9Mty6J/WZDjOEzhr92STd4IODnE5civydq+/5pblTo7t2p QYP5Q6s0PiSnlb/LsHdermuGeYxcfOanPaNrZwAuAAeHQan5FhohXYF31EVx+oOXjRcd sTrF3hTMfJLebUjE0VAJ15G7IdbsG7UJ00eQOGJm3EVoNXRNgaWMUmfxupAwNWj0U4Yv WaX+zXP7R5CqK2yC/iLArsOC4gP6dtyiRy1ab7fz487wKFWjIiAUMpoDiiXaqWNasXcn FP1Q== 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=Q/30eztdskxj/jgS3B4pUbU7E9oJE9zKnu1iA3SIBr0=; b=b8gLzudRDTrG1E+UR03MarpV3fNL6tLnv+/5f+KjNSdclXk0N9Q7FrGCSwpHJyT+p9 lDoWEHgTFtg7GVTbN2oPu6tOzDANMjU9N9PvWp5vAPV6/qcKlmByeq+7OrdxlBqkCSft gda6gERLg6OdwFzVlUHkWtqmBIDHo2hI5Qv/z2d1nEk+zMrw1EW4JQ73R58R037TrjB0 emfh7AWo0CWMk1U4I6W+vgn7zqTCEqdE+1Bs4PAqRRVVZRGAfX0hAmHdjIBetfAC8Lvb 7YO0cM2AGnDCIOD+zxzYR2bLlTfkNc+ZUD0IHfXL0plZmze2SWiVbRY0nC73VEb9hrsM y8FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fIEChYnP; 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 y7-v6si3910828plh.583.2018.04.12.12.25.54; Thu, 12 Apr 2018 12:26:08 -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=fIEChYnP; 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 S1753102AbeDLTSn (ORCPT + 99 others); Thu, 12 Apr 2018 15:18:43 -0400 Received: from mail-ot0-f194.google.com ([74.125.82.194]:42325 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752846AbeDLTSl (ORCPT ); Thu, 12 Apr 2018 15:18:41 -0400 Received: by mail-ot0-f194.google.com with SMTP id h55-v6so7262355ote.9 for ; Thu, 12 Apr 2018 12:18:41 -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=Q/30eztdskxj/jgS3B4pUbU7E9oJE9zKnu1iA3SIBr0=; b=fIEChYnPnIXuXL55E/j7ONXU6k4QNmKEqeFbZ/UvCHeT40Qg9pZkrAiaEWLUso+RQg CYmig7rWEqCWrog869a1Ifes+qq7EQHCInPaXtuNMr4cr4qgCZliNennrD+askYsXijm PQgcDX0GPVaszHT+AiEc6U++fVyWHRW60Hm2wYSGuiT0mqqJ63R6nJce4MtXRsuIxe+Y Dis4eVNzG1eZKesoMIEBRwtDIXs/K/tWMBHiVW02CeDn/1N8KLpT7YUH6X4hu/eNm/IU 1JZpc4x211iql9ZklDPNUAs3duNgUPlsI0IQIxUh+t5eXFeiXy+fH3mcFWM5N5aJPmsL 0SZg== 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=Q/30eztdskxj/jgS3B4pUbU7E9oJE9zKnu1iA3SIBr0=; b=O1f6ZxNejKAOI4dwobz3L1yPlW+qAa5tl9tG/miL2Eex2ny4FGzrvT25LZ9B7O+vil XxccHw74ZWW6nrqYpt1CkfyzsgqvT86UF14J0Tj92lVc78eEOMSz05EE9sNXaKkziTav OmlYapLM2hn5QqAM6PvR4h1ckTRyjLJbSx8wKeEkCYDoe6+1PLZBLQZQWFwkojMvcvJo cCzPoTzv7mw1jvJIcP4Yr3VAPANYBprR1L79Oou388P/gQOZRcrjnIl6I9HT+aJ3xqxm QEu4K7A/4Zy5xvI9kn/1f1LN8Mxyw6mvMGpvcZyCNTOreod/jaS7JiG0qr1q/BPmY1hG r3tw== X-Gm-Message-State: ALQs6tBCg7Tl2vB/Y3sq992cxKAJVLtdYXBY4NJW2wl5ePxJ5J57J+DH 23gECuKHY3MKaH8oo7NoRHs+1seAQZ2mHCDZRN+0wQ== X-Received: by 2002:a9d:1dc3:: with SMTP id w3-v6mr1637345otw.216.1523560720355; Thu, 12 Apr 2018 12:18:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.73.133 with HTTP; Thu, 12 Apr 2018 12:18:19 -0700 (PDT) In-Reply-To: <13801e2a-c44d-e940-f872-890a0612a483@nvidia.com> References: <20180412153941.170849-1-jannh@google.com> <13801e2a-c44d-e940-f872-890a0612a483@nvidia.com> From: Jann Horn Date: Thu, 12 Apr 2018 21:18:19 +0200 Message-ID: Subject: Re: [PATCH] mmap.2: MAP_FIXED is okay if the address range has been reserved To: John Hubbard Cc: Michael Kerrisk-manpages , linux-man , Michal Hocko , Andrew Morton , Linux-MM , lkml , Linux API 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 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. > 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.