Received: by 10.192.165.156 with SMTP id m28csp866072imm; Fri, 13 Apr 2018 09:08:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/68m8Lg5wAkF3nME+UA5fGSpemip1kflCvpXNQoQrCxWif6+EML99pw+Qh1NdOy4wggfYr X-Received: by 2002:a17:902:6849:: with SMTP id f9-v6mr5805072pln.139.1523635711042; Fri, 13 Apr 2018 09:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523635711; cv=none; d=google.com; s=arc-20160816; b=Jr0h73hzynVMK/C3GTZlT2fKJppmot5slT2pdoiZ7ozJi2prWhCB1EkDuZ9zGNF8TX sFl6ffnZiWlm0tWF1lzwfy1gH0MhnF5fgzM/wQos1gf5px/NU1JYM/PwqwArkCH4TMPR 7gmsPwuhumWy0IS+xfLZ216WlmKlptp6eRezZLlLsSIZ1y7fIPiHDYlULm6FCXo3dDIN PsMp0j1PMcZSFySgwyIW//HIOQon4NV7IhrYLts6rzs7ntNhshBfghleEAwyDBl0bQDD bzruQ9fiBDHA8Da1CwL9L8VS+oGQLo1of/twBbhfRy88nmPlsiTjPlAsSOjDvC34ptKx 0XQw== 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=VgPw8MjPUd3IiLWABTg5h9VcXxgXGPvXbGvweY2jiG4=; b=enpXEWSuqjk3WOaiUmIlRRGLbHMtPM5GMBQqjqFCfMSWUTf5LENxW67rdluDHBHihh E/3gGelUGL1RsaOzbO6BSKqnoKjtYafk8cRq5/O295uWZVbrtUpYMwMiXpZElkSVbS2f ZgsVD1Wpk6PG9C7/0baRRHn+OjkMA/S0lS0Qw8HKhFyMzS+GMfmMSDdXQ+IyfChaQ11X 5rwjRZSuTGyONRvWBM1iX+dQJ045Vjgv2ZZSWTLd1uUVPbaOvf1ZIMlliTTkPRT8qOKZ plYdA9MXwgIp+ozLBieP/2FjjUOBo/KVqXvKp0K1jaoSjwm0VMyPexOannd7lnJgfGSG gh/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gBLc2iW8; 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 f15-v6si5677914plr.310.2018.04.13.09.08.14; Fri, 13 Apr 2018 09:08: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=gBLc2iW8; 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 S1752677AbeDMQFt (ORCPT + 99 others); Fri, 13 Apr 2018 12:05:49 -0400 Received: from mail-ot0-f194.google.com ([74.125.82.194]:37551 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752628AbeDMQFq (ORCPT ); Fri, 13 Apr 2018 12:05:46 -0400 Received: by mail-ot0-f194.google.com with SMTP id y46-v6so10421324otd.4 for ; Fri, 13 Apr 2018 09:05:46 -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=VgPw8MjPUd3IiLWABTg5h9VcXxgXGPvXbGvweY2jiG4=; b=gBLc2iW8FD0kopsBUyiFccW0yd7onyaW67WizgtVfTMw02Hi0sFm9B9ZCvNBR6VuzW 4nEsYs0GEtL3kRXAoFQua5b1L8hFMeho3X57RNRGPVdj6eL89Q1f2+4vhry4jPyTmuio 3xrnWYI/QLHZ9mU0+Xu6IL5EfP+5yrdlkO7gL+ruWI4Cbhm0vGLdC9GKFd3o40jCYMRE RH/8jYpXWizmNSM0VsimqbBgWuWbypnAfPoNIQPdNi84/FxgHvAdAJDaBmiJdhWRxfvc i5C875HQ7zte3PLjm/Eof8GVQtHpA7LP0EiJlttZGdjBCfH4/GJEmiWfugeYaEhr5cUZ fI7A== 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=VgPw8MjPUd3IiLWABTg5h9VcXxgXGPvXbGvweY2jiG4=; b=gCvPOL0zY5cTTAmdPAacUWBwsKmO3sDYnfPSt7QOHZMt62xdlKauxo9/VXipO+RUnD AXAXvOvDK9xM/2mPk7ROm+JyaQ6DPFvLxVIoGM+UOqtsepB4DKHIBDBS8AEbs4QL4MZN 5N7LksFRkru6c6MlfRXt/Cpm1UrZRnQ5P6H38X/+FEVy5TB60xpAQ+SYcnlEEcaTSfIZ /0zDb6xkNVwLqf5w6IDb9dPzoO9F35LVTscjRqcc8hsHkM/ozhsyBMgVzf+IATn/etDu /Lzv2ioqJQOxZBAJocwuuOEYEzC53pP0pG6Rx65V8L6tlAPP0x7IUv11a0HTJCaqOwhB rn4g== X-Gm-Message-State: ALQs6tCk6hsvTvIETx6Fkq1xM2srJcHeS2NSa2GhBVHFlUI1SSAut0la ZJQ2ZTtvNpIHw9x9SJmwuDYquiNo5TtrRwyhjmfGcQ== X-Received: by 2002:a9d:7047:: with SMTP id x7-v6mr3855085otj.254.1523635545319; Fri, 13 Apr 2018 09:05:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.73.133 with HTTP; Fri, 13 Apr 2018 09:05:24 -0700 (PDT) In-Reply-To: <20180413160435.GA17484@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> <20180413160435.GA17484@dhcp22.suse.cz> From: Jann Horn Date: Fri, 13 Apr 2018 18:05:24 +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 6:04 PM, Michal Hocko wrote: > On Fri 13-04-18 17:04:09, Jann Horn wrote: >> 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. > > This is still racy in multithreaded application which is the main point > of the whole section, no? No, it isn't.