From mboxrd@z Thu Jan 1 00:00:00 1970 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 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Florian Weimer Subject: Re: [PATCH 0/2] mm: introduce MAP_FIXED_SAFE Date: Fri, 8 Dec 2017 21:47:21 +0100 Message-ID: <289f0cc8-9e24-fc38-cb83-4223f9923940@redhat.com> 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> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20171208142714.GB7793@amd> Content-Language: en-US Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org 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 List-Id: linux-api@vger.kernel.org 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi0-f71.google.com (mail-oi0-f71.google.com [209.85.218.71]) by kanga.kvack.org (Postfix) with ESMTP id CAC7D6B0038 for ; Fri, 8 Dec 2017 15:47:28 -0500 (EST) Received: by mail-oi0-f71.google.com with SMTP id q67so5378467oig.14 for ; Fri, 08 Dec 2017 12:47:28 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id r47si3021531otc.479.2017.12.08.12.47.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Dec 2017 12:47:27 -0800 (PST) Subject: Re: [PATCH 0/2] mm: introduce MAP_FIXED_SAFE 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 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 Sender: owner-linux-mm@kvack.org List-ID: 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 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 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org