From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752822AbbCZTjH (ORCPT ); Thu, 26 Mar 2015 15:39:07 -0400 Received: from x35.xmailserver.org ([64.71.152.41]:55421 "EHLO x35.xmailserver.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752558AbbCZTjE (ORCPT ); Thu, 26 Mar 2015 15:39:04 -0400 X-AuthUser: davidel@xmailserver.org Date: Thu, 26 Mar 2015 12:39:00 -0700 (PDT) From: Davide Libenzi X-X-Sender: davide@davide-lnx3 To: David Rientjes cc: Hugh Dickins , Andrew Morton , KOSAKI Motohiro , Andrea Arcangeli , Joern Engel , Jianguo Wu , Eric B Munson , linux-mm@kvack.org, Linux Kernel Mailing List Subject: Re: [patch][resend] MAP_HUGETLB munmap fails with size not 2MB aligned In-Reply-To: Message-ID: References: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) X-GPG-FINGRPRINT: CFAE 5BEE FD36 F65E E640 56FE 0974 BF23 270F 474E X-GPG-PUBLIC_KEY: http://www.xmailserver.org/davidel.asc MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 26 Mar 2015, David Rientjes wrote: > Yes, this munmap() behavior of lengths <= hugepage_size - PAGE_SIZE for a > hugetlb vma is long standing and there may be applications that break as a > result of changing the behavior: a database that reserves all allocated > hugetlb memory with mmap() so that it always has exclusive access to those > hugepages, whether they are faulted or not, and maintains its own hugepage > pool (which is common), may test the return value of munmap() and depend > on it returning -EINVAL to determine if it is freeing memory that was > either dynamically allocated or mapped from the hugetlb reserved pool. You went a long way to create such a case. But, in your case, that application will erroneously considering hugepage mmaped memory, as dynamically allocated, since it will always get EINVAL, unless it passes an aligned size. Aligned size, which a fix like the one posted in the patch will still leave as success. OTOH, an application, which might be more common than the one you posted, which calls munmap() to release a pointer which it validly got from a previous mmap(), will leak huge pages as all the issued munmaps will fail. > If we were to go back in time and decide this when the munmap() behavior > for hugetlb vmas was originally introduced, that would be valid. The > problem is that it could lead to userspace breakage and that's a > non-starter. > > What we can do is improve the documentation and man-page to clearly > specify the long-standing behavior so that nobody encounters unexpected > results in the future. This way you will leave the mmap API with broken semantics. In any case, I am done arguing. I will leave to Andrew to sort it out, and to Michael Kerrisk to update the mmap man pages with the new funny behaviour. - Davide