Received: by 10.192.165.156 with SMTP id m28csp805373imm; Fri, 13 Apr 2018 08:07:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx48uUH5YbQ7XKj+2aVtjBVO1YgQSoY2/OiCHTzuwqlM6KqRokOjev83DvkfEIQ5xUjSYfT1N X-Received: by 10.98.211.4 with SMTP id q4mr12021948pfg.0.1523632051186; Fri, 13 Apr 2018 08:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523632051; cv=none; d=google.com; s=arc-20160816; b=zChrcYixB8TXyHo2GQkbOTlbJ0XPpr8qMvnQ9xWSyFjehL7OxySIk/hWVDLSDSxDEh FE2UDrUzX1nV1rUn30WBDTl8SE7DjeNbz1oCIXgJG9PxptatkV3ur+/G5kOeCfQ5zTv4 bveI0OFq3Suo74P+Jv/P9eZBYxteWcyxoVlG+BEfs1tLeYlBWUf9zCkTC6tTXngr0jiA h1R8rRAtjk2TzpD1y6p09TLe9dT7qe+WRz9Q1FUGUweF6yCOXqeKFt+GbmHiLYQCTxt+ vvNcMkLDsMwum5KMo49Pgr7FJJvRz1vrU2hm1d/mLzHdptwYZa2LQE29vMDaGEDIFvZC wQ8A== 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=15SqwTLW42bT5QCLF3CbZmfusJcYGHc8EvzKtTvmNEY=; b=GlZD5uhrZ9LwvAccyCt64m0gqiCecyBt+YSW9Z4dhHol3LzdXzurGc5+XUKM2N0659 GjN6t8+3hQhBrUjpeeh52FaktdpotVrvWXGFXc+gSRiXQUvHKFoDumxqZvnlQR8VeBoY B73NSTagNCUeyw/Qn55W9d5TtUbiig2Wno5vbKrw7QPRcU1l0QO/d1RJ3lZHwTo7uByj vuXsf4z43nGUIySVmsN7ice4AVCI3okszfI/FE/KlZFVfSGrGdKwgUhnrvYRZzTu4Lyv EYKoMpbn1BagrLpXBuNetmGlKUjP1Fq7IhEAoXOJi/HvUMw4Pj9V0JLBSW8WuNXBXdx5 g6yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ErtlRouZ; 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 d23-v6si3992858pli.454.2018.04.13.08.07.16; Fri, 13 Apr 2018 08:07:31 -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=ErtlRouZ; 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 S1751625AbeDMPEe (ORCPT + 99 others); Fri, 13 Apr 2018 11:04:34 -0400 Received: from mail-ot0-f195.google.com ([74.125.82.195]:36184 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750849AbeDMPEb (ORCPT ); Fri, 13 Apr 2018 11:04:31 -0400 Received: by mail-ot0-f195.google.com with SMTP id n40-v6so10194162otd.3 for ; Fri, 13 Apr 2018 08:04:31 -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=15SqwTLW42bT5QCLF3CbZmfusJcYGHc8EvzKtTvmNEY=; b=ErtlRouZB5uQsRYCOe3zpRyi9vb5pu/wAttIvPl8vf8/KJDwQ42dIs2PRyDkfeeT1P I7JHByAYfUpI5kFqLVzf1DvaY5fjk/JsK0zhaaFMS6JYb0xHYttSopbFZPGV82I5F0vJ mH98/4MtjebtNsbe/OWSV2rs5Qf3aSf4LX68smpjcPrumDVia+pT6UCm+Tk+dcSTXhRj mlnRLZ/MQ4aAL+aOa1I/Pzg0R/M2dZfvFbrDrjCNVrAsPOY6B/rvDV+Dpuzs1FLEN6oE W1hMeeCI/eI1iBRaRze2CBcCoZAgV0o4GTbzlqWtvFniJQBHKpTy6rFdRwdZaazYLi8O r5Tw== 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=15SqwTLW42bT5QCLF3CbZmfusJcYGHc8EvzKtTvmNEY=; b=GF7HAbUcKA5WVTGZk7pFxON19ro92QaDWQQwybxiTkdoIhU1F1QbMk5Hu/i7gFBkLh nRAc609om/FNYxYdXU7QMK2zfZdyrjlKx3VBSqgUm2RT/6H7US5yfBXXwFIg2TAFQwsI Ey0foTudcH006iEjzWedZKJ07AXboPWVdmoiC8xwG6Cqe2SM3QHyQggV2U5e7Q+6B07/ FNw2Sk6+th5h8/IHYe2NQVhVoH9311G9t7K8/zTJLjz2hN1DD20DpEq0pN1K6KR5ol3G oCJXt78hwb7WF+jcI7ku2zdvrktdxef4DRGZfIJ6Hwlkry5GzRtMTz8/dvxirJhJrAxH /Pzg== X-Gm-Message-State: ALQs6tBjYo3f6eLikZESyNXlG2xO6Cmq/zqFMjdbchipB+HQnkIOX81U SV2lw0g29iTvGlupx+7tQ6lYABVeIrmUm75LtlLdHA== X-Received: by 2002:a9d:1691:: with SMTP id c17-v6mr4113276ote.115.1523631870668; Fri, 13 Apr 2018 08:04:30 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.73.133 with HTTP; Fri, 13 Apr 2018 08:04:09 -0700 (PDT) In-Reply-To: <20180413064917.GC17484@dhcp22.suse.cz> References: <20180412153941.170849-1-jannh@google.com> <13801e2a-c44d-e940-f872-890a0612a483@nvidia.com> <9c714917-fc29-4d12-b5e8-cff28761a2c1@gmail.com> <20180413064917.GC17484@dhcp22.suse.cz> From: Jann Horn Date: Fri, 13 Apr 2018 17:04:09 +0200 Message-ID: Subject: Re: [PATCH] mmap.2: MAP_FIXED is okay if the address range has been reserved To: Michal Hocko Cc: "Michael Kerrisk (man-pages)" , John Hubbard , linux-man , 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 Fri, Apr 13, 2018 at 8:49 AM, Michal Hocko wrote: > On Fri 13-04-18 08:43:27, Michael Kerrisk wrote: > [...] >> 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. > > Yes, that sounds reasonable to me. But that kind of sounds as if you can't avoid it before Linux 4.17, when actually, you just have to call mmap() with the address as hint, and if mmap() returns a different address, munmap() it and go on your normal error path.