Received: by 10.192.165.156 with SMTP id m28csp2298456imm; Thu, 12 Apr 2018 11:53:53 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+TS3KNjdPaZM54xJoNHm65vtNbD2iYsl43gaFoWT/izz9I9ZxtEVYfPidw95/ZQUq0+wES X-Received: by 10.99.96.66 with SMTP id u63mr1589687pgb.22.1523559233488; Thu, 12 Apr 2018 11:53:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523559233; cv=none; d=google.com; s=arc-20160816; b=jOuXZwPBsHy/FZuIy2iVOf1oiisfJnkfdFZHdyMYhRK1ALgE3ZEgddB9BHttCLUcDL huLob5ekBpFRuDBfjUx/6A5qNNnxEs2wzKE2F6c2sDKiHiQC9UsSZrR7+JvLAB6WPC64 ciyia4rSd4SBzVMe54u/N+2sWLgzihzyL8quTxg2utRHePl15rY+pImnWOZe2l0rA2qh Q0+KWs/ypi7e8wrQ2Rp/IWmtEoSr63gEP3oWcWB2vhzNpot0XiWh6G2Tas2v3Rz/38Wu +lY+T0HTKx6zrZ5PM+Q23VYp/6J6xUTPJC2OxSqS49NVCkdZ4kDD6Tr69d3sCCa21+QA zGSg== 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=qURUL0y7LlQXzZ8+9+hnklaSOIpJJR1IcgBW/jXm1rc=; b=hMwFmMjo3vV84rp6npNIhuBFjws/RWKvxB8lP/g5sYiIhAjDyqS+h+5UpziDmO//5A osOGnZqWMbzh8CqD4e1ipuF9iJJlMe74nyKKZBWFRruFfSH/pgK5BSWkyWxmRd6J+47U D44xTSCEboc9ZjIHmcbAs3uk8VKTy9ikdmiO+rYy0Hm5LLo4dYQZIGFZDNM1Dfpdygin 47QK/z5FUMKw3KgZrXqKmIDo5E30vBr1gi+QN8qfNN5wdnUXpnsOo5P4dAv+tUxfZe57 GA9jQrL8O61Q9QfU8TQzZts6vJmkLiX4Z3XkzrrY9kcLcaY/sL8kNOotvwenx0aaavM0 1oog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SEasxir1; 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 44-v6si3962058plc.252.2018.04.12.11.53.30; Thu, 12 Apr 2018 11:53:53 -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=SEasxir1; 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 S1753364AbeDLSuD (ORCPT + 99 others); Thu, 12 Apr 2018 14:50:03 -0400 Received: from mail-ot0-f195.google.com ([74.125.82.195]:39760 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752931AbeDLSuA (ORCPT ); Thu, 12 Apr 2018 14:50:00 -0400 Received: by mail-ot0-f195.google.com with SMTP id a14-v6so7184894otf.6 for ; Thu, 12 Apr 2018 11:50:00 -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=qURUL0y7LlQXzZ8+9+hnklaSOIpJJR1IcgBW/jXm1rc=; b=SEasxir1PykmsoDmZH1j2Tt9WTUsupTIR3pkWnS9p9S0cdmJJvln2i8O1+tgrHAgPn yYwSnG0XAE9bh3pAnv7gOHrQ6ynHcf+5eYLrosggsmu+gwo9PqBvTfWofnsihasMfI7r NJ2nn1DLb7lBW460lQFW31ZktZLFmcVy+yeIJ9uHzNmMR4EXPn/tBZBgYg+ttQ4AWymw K1/M6n3d0MHQ7d76TllCpMXXO6IGkFKc8+pNsHXSZAoUZYncdg7/djo7i7X2pdNgKz0w wL//V+Wr+HgDuAewEdQZJeV/jo74/rbe02RC16D8yyES/vFlntRFJw2BJpOHJ378wQV7 lB2Q== 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=qURUL0y7LlQXzZ8+9+hnklaSOIpJJR1IcgBW/jXm1rc=; b=hl5FG3dcVY+oukaYNqs14nkYgRMxNzQk1zdxrGEvg1RKn4B/3qom/LwvMHmBlUqsqf 00P3BW5/Myi59qdgqquO8aMqe97QTXg87+O1srSQsREy17sitdw+TR11b2MSJ9BlgiaR O7RxKbbT4IqMggXVunF42eTSUhom/LIR3M43r8U+TGDf8SsFVaTGT1DDnDzYexX8Rrnt g/ySC5nVytTtt2Wjv+8uRFK2b6U5Dz+ONeBgwW0REDMjgaJfpMaLPX3OEuU2B10lKjfK uv8siFJQ5mvE3KGQBXBo8jp5cjHkZUaMF4dXkCxS43nR5IoQ6lsQnKQGCoSYDlMBmjAV QpKA== X-Gm-Message-State: ALQs6tBz1SsmQGLKmMsjVEZBiRLrh9bbfBQ5DWIsxi47yurkRTAY47si HGjMsbLc8Al3GZ4sYh9xf38QISYJZRHeuENcA5oOxA== X-Received: by 2002:a9d:7047:: with SMTP id x7-v6mr1435925otj.254.1523558999396; Thu, 12 Apr 2018 11:49:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.73.133 with HTTP; Thu, 12 Apr 2018 11:49:38 -0700 (PDT) In-Reply-To: References: <20180412153941.170849-1-jannh@google.com> From: Jann Horn Date: Thu, 12 Apr 2018 20:49:38 +0200 Message-ID: Subject: Re: [PATCH] mmap.2: MAP_FIXED is okay if the address range has been reserved To: Michael Kerrisk-manpages , John Hubbard Cc: 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: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? > Jann, I've already pushed the existing patch. Do you want to add a patch on top?