Received: by 10.192.165.156 with SMTP id m28csp862779imm; Fri, 13 Apr 2018 09:05:59 -0700 (PDT) X-Google-Smtp-Source: AIpwx48e4c2a4kY6elT4lgAsp+k6GOta1Xn0sxfKnH10OwgMUffpAf7dKSe4yBoauen1+GPdBRfS X-Received: by 2002:a17:902:444:: with SMTP id 62-v6mr5721110ple.127.1523635559481; Fri, 13 Apr 2018 09:05:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523635559; cv=none; d=google.com; s=arc-20160816; b=uDUKFVD5zBprI8elIhm+2BkGxwC50ZyjvpWzLmxDiS1UHPVW3T1c22TrvO/OZPjZB7 a1gzDCzuReB75Uf1FUorD+bsYsUTSg7W63uUN6fEKH3L0PBE5V9Fx72dC6iR4zNRbpkJ 6WVUXuZ2YZzAN4biNlumU+euORvYYiJce0uhm9GSTqjinSgKDhuyPaJWyLEFWHP5p1QU AafEas1ICwK0HH2N9u6DhNBpJTPcc2keAINdLyGtbNkr9lrBsDd5x44jdMt5hHA2sR7g 3eJ6vLkZ+Ba42pCqfddGaD3rcw+j2cDZ3GezPgnPeZEyx7N0jSruomZ0EWILTaNMjt88 aTKQ== 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=bcSGDZUF6vGURU2UdCkCpwCcbz8XxZmpg8n3yVqAkdk=; b=h6B+CP8RQq+jBWmu2ZWyTEpIRMUNJT+pa+A6mjHSzObn/lZJWcdAXr7HzRQgnzoKIp ZyF7PncC9Is3uuSG3Zz2FCHVISGkxkeTnG305ZptrENr7MnecUejlwSW61d5WRpY05Up UlxTBkOZIR2dWpHnl0bJNd4BcOSgu5Z0WcbXE9QY+JRFmwBZkC9azg/NOBczkhvjPHaQ N7u0FU414ecoVfObTCQhbN496keBmp1zAhvBoHM7eZ6Tr4wNFW0zfMoTTR4kL/Ye14U5 Sp3NIEIv4fFzivPA0IWonf7nop2dcxpicJJi/Ppu87nl8U7WrlwtADqaXAZi3VkrGOiu kVUg== 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 k19si4726949pff.41.2018.04.13.09.05.41; Fri, 13 Apr 2018 09:05:59 -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 S1752586AbeDMQEl (ORCPT + 99 others); Fri, 13 Apr 2018 12:04:41 -0400 Received: from mx2.suse.de ([195.135.220.15]:36362 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751421AbeDMQEh (ORCPT ); Fri, 13 Apr 2018 12:04:37 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1E4A2AC9F; Fri, 13 Apr 2018 16:04:36 +0000 (UTC) Date: Fri, 13 Apr 2018 18:04:35 +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: <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> 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 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? -- Michal Hocko SUSE Labs