Received: by 10.192.165.156 with SMTP id m28csp1486060imm; Mon, 16 Apr 2018 23:24:38 -0700 (PDT) X-Google-Smtp-Source: AIpwx49bvVAJhTRZffsuY0xeqEmk+0ZUFXoseRhooX/iLMR1WQDoT2hHGdubfXlCBdP4PaMv/fcb X-Received: by 10.98.76.196 with SMTP id e65mr855946pfj.35.1523946278533; Mon, 16 Apr 2018 23:24:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523946278; cv=none; d=google.com; s=arc-20160816; b=enzOsBeNYCV6fyLJm6Bpi4CyKYwnu59UASzuYR1E31SmEXifkQsnTpMvEwmMz2a9W6 hh3gbE6knma9qNCnRV6Twv3abRH3CIhkYIoved0bn94AJrWsa0lGkGUAlnW7KztOTfmR 1gDjiqOgDPJ+nw+XZCcH/NrqVqXaiFlB4YynL6dIt+sJowsmONRKYDXi4a6VbxaKwPaa 0labjC4ZMuQZZ4o0BQFJ/Y7nPyrJOATUw45fz6WKsZc5YmX6QkZea8qaVUh9gCzfhJYx NOnZox7snDHuHMel1oLSGbZL16VQ8ml8PT0JrY681TwYMgqCy5Tekos7LqMgZlXvqDdx pA3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=mHHWAkN6CnpR3PrL+Z+P8GUiLOyIfvW8yU+D0Bp6pcI=; b=PwnOL9aNZ6/a4L2TVFW7ZZb/vjoE9dlOkXafftFh4jrCvMENHwtAK6RF8eeJxmAdJy i0TcE0EwEYPlKwXsoIQfU0clEboY6ztiZXV6ldHq3zn6I2V0k3SYQTrYgWZ9JQn1uIR/ QtVww3kiU4gc1LD30jLZkD3BeE6VdthiYHDR4aR9ZGOWP8e0yzq7ZGrV5QiMegpb1pbj O1cuUK6RkwkbzXknvA4teeIz3pGBwvICfPEeV6bGAobQ9Q5eJdTjAo4SIJ/Q8oAdvxoj 91eoaMlRuUfPRD8jAqK7pbvBzTtLfYU208+zFE0rKszgbcLG/qZ0tMerCLqkz7LVUQcn G5eg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h10si11175802pgn.30.2018.04.16.23.24.23; Mon, 16 Apr 2018 23:24:38 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751252AbeDQGXR (ORCPT + 99 others); Tue, 17 Apr 2018 02:23:17 -0400 Received: from mx2.suse.de ([195.135.220.15]:35875 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750831AbeDQGXP (ORCPT ); Tue, 17 Apr 2018 02:23:15 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4F63AAE1C; Tue, 17 Apr 2018 06:23:13 +0000 (UTC) Date: Tue, 17 Apr 2018 08:23:10 +0200 From: Michal Hocko To: Jann Horn Cc: "Michael Kerrisk (man-pages)" , John Hubbard , linux-man , Andrew Morton , Linux-MM , lkml , Linux API Subject: Re: [PATCH] mmap.2: MAP_FIXED is okay if the address range has been reserved Message-ID: <20180417062310.GW17484@dhcp22.suse.cz> References: <20180416100736.GG17484@dhcp22.suse.cz> <20180416191805.GS17484@dhcp22.suse.cz> <20180416195726.GT17484@dhcp22.suse.cz> <20180416211115.GU17484@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 16-04-18 23:12:48, Jann Horn wrote: > On Mon, Apr 16, 2018 at 11:11 PM, Michal Hocko wrote: > > On Mon 16-04-18 22:17:40, Jann Horn wrote: > >> On Mon, Apr 16, 2018 at 9:57 PM, Michal Hocko wrote: > >> > On Mon 16-04-18 21:30:09, Jann Horn wrote: > >> >> On Mon, Apr 16, 2018 at 9:18 PM, Michal Hocko wrote: > >> > [...] > >> >> > Yes, reasonably well written application will not have this problem. > >> >> > That, however, requires an external synchronization and that's why > >> >> > called it error prone and racy. I guess that was the main motivation for > >> >> > that part of the man page. > >> >> > >> >> What requires external synchronization? I still don't understand at > >> >> all what you're talking about. > >> >> > >> >> The following code: > >> >> > >> >> void *try_to_alloc_addr(void *hint, size_t len) { > >> >> char *x = mmap(hint, len, ...); > >> >> if (x == MAP_FAILED) return NULL; > >> >> if (x == hint) return x; > >> > > >> > Any other thread can modify the address space at this moment. > >> > >> But not parts of the address space that were returned by this mmap() call. > > ? > >> > Just > >> > consider that another thread would does mmap(x, MAP_FIXED) (or any other > >> > address overlapping [x, x+len] range) > >> > >> If the other thread does that without previously having created a > >> mapping covering the area in question, that would be a bug in the > >> other thread. > > > > MAP_FIXED is sometimes used without preallocated address ranges. > > Wow, really? Can you point to an example? Just from top of my head. Some of that is for historical reasons because the hint address used to be ignored on some operating systems so MAP_FIXED had to be used. Currently not user I guess but MAP_FIXED for addresses above 47b address space AFAIR. And I am pretty sure there would be much more if you actually browsed code search. -- Michal Hocko SUSE Labs