Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752587AbdLHUra (ORCPT ); Fri, 8 Dec 2017 15:47:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33748 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751474AbdLHUr1 (ORCPT ); Fri, 8 Dec 2017 15:47:27 -0500 Subject: Re: [PATCH 0/2] mm: introduce MAP_FIXED_SAFE To: Pavel Machek , Michael Ellerman Cc: Matthew Wilcox , Kees Cook , Cyril Hrubis , Michal Hocko , Linux API , Khalid Aziz , Andrew Morton , Russell King - ARM Linux , Andrea Arcangeli , Linux-MM , LKML , linux-arch , John Hubbard , Abdul Haleem , Joel Stanley References: <20171130065835.dbw4ajh5q5whikhf@dhcp22.suse.cz> <20171201152640.GA3765@rei> <87wp20e9wf.fsf@concordia.ellerman.id.au> <20171206045433.GQ26021@bombadil.infradead.org> <20171206070355.GA32044@bombadil.infradead.org> <87bmjbks4c.fsf@concordia.ellerman.id.au> <20171207195727.GA26792@bombadil.infradead.org> <87shclh3zc.fsf@concordia.ellerman.id.au> <20171208142714.GB7793@amd> From: Florian Weimer Message-ID: <289f0cc8-9e24-fc38-cb83-4223f9923940@redhat.com> Date: Fri, 8 Dec 2017 21:47:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171208142714.GB7793@amd> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 08 Dec 2017 20:47:27 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 974 Lines: 22 On 12/08/2017 03:27 PM, Pavel Machek wrote: > On Fri 2017-12-08 22:08:07, Michael Ellerman wrote: >> If we had a time machine, the right set of flags would be: >> >> - MAP_FIXED: don't treat addr as a hint, fail if addr is not free >> - MAP_REPLACE: replace an existing mapping (or force or clobber) > Actually, if we had a time machine... would we even provide > MAP_REPLACE functionality? Probably yes. ELF loading needs to construct a complex set of mappings from a single file. munmap (to create a hole) followed by mmap would be racy because another thread could have reused the gap in the meantime. The only alternative to overriding existing mappings would be mremap with MREMAP_FIXED, and that doesn't look like an improvement API-wise. (The glibc dynamic linker uses an mmap call with an increased length to reserve address space and then loads additional segments with MAP_FIXED at the offsets specified in the program header.) Thanks, Florian