From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED88AC388F3 for ; Tue, 1 Oct 2019 12:18:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A4B9A20700 for ; Tue, 1 Oct 2019 12:18:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="MDu/IhfX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4B9A20700 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 940CF8E0005; Tue, 1 Oct 2019 08:18:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CBE38E0001; Tue, 1 Oct 2019 08:18:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76A328E0005; Tue, 1 Oct 2019 08:18:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id 4E6148E0001 for ; Tue, 1 Oct 2019 08:18:38 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id E23D182437CF for ; Tue, 1 Oct 2019 12:18:37 +0000 (UTC) X-FDA: 75995119074.02.apple10_2e2f965c39b4a X-HE-Tag: apple10_2e2f965c39b4a X-Filterd-Recvd-Size: 7186 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Oct 2019 12:18:37 +0000 (UTC) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x91C8wjG175385; Tue, 1 Oct 2019 12:18:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=dcLYJvPK24WEL/GkiHEqYn8VO4YkXFlAa6MpcIoc3SY=; b=MDu/IhfXGIhNz//977B0rKXUpa1lZY1yJNdFTIPRlSe+ifg4CdYd6X0NMGjp2rs9i9qf cYVQZrY/6v9513GKS4GIUF4bwZKOS5lCfJai6w8F/VYycKUmBseZXR2FWOJmKzgippoH nwGvm6ymmn8L4A4E7EAe5LEbV2zVNFen0NwyVTQtjNORf35kYbbDjaHkK9tXnUBbdxph V62cqwMJUF52lzhGqAkHEqXZ1QBxPOL8QZQgaq5xBA8/s9qiu+Kp+EQxPdMuJkbyAkj2 zddo+lAVqOO6SnfvUK0UDQkTQfcl6zA+aHbRoEU3WSKGlVypn3gDxxTCnvurMRw21cJq Gw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2va05rnaks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Oct 2019 12:18:32 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x91C8hrB090887; Tue, 1 Oct 2019 12:18:31 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2vbsm1vfmd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Oct 2019 12:18:31 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x91CIT4o017825; Tue, 1 Oct 2019 12:18:29 GMT Received: from localhost.localdomain (/73.243.10.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Oct 2019 05:18:29 -0700 Subject: Re: [PATCH 14/15] mm: Align THP mappings for non-DAX To: "Kirill A. Shutemov" Cc: Matthew Wilcox , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20190925005214.27240-1-willy@infradead.org> <20190925005214.27240-15-willy@infradead.org> <20191001104558.rdcqhjdz7frfuhca@box> <20191001113216.3qbrkqmb2b2xtwkd@box> From: William Kucharski Message-ID: <5dc7b5c1-6d7d-90ee-9423-6eda9ecb005c@oracle.com> Date: Tue, 1 Oct 2019 06:18:28 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 MIME-Version: 1.0 In-Reply-To: <20191001113216.3qbrkqmb2b2xtwkd@box> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9396 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910010113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9396 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910010113 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 10/1/19 5:32 AM, Kirill A. Shutemov wrote: > On Tue, Oct 01, 2019 at 05:21:26AM -0600, William Kucharski wrote: >> >> >>> On Oct 1, 2019, at 4:45 AM, Kirill A. Shutemov wrote: >>> >>> On Tue, Sep 24, 2019 at 05:52:13PM -0700, Matthew Wilcox wrote: >>>> >>>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >>>> index cbe7d0619439..670a1780bd2f 100644 >>>> --- a/mm/huge_memory.c >>>> +++ b/mm/huge_memory.c >>>> @@ -563,8 +563,6 @@ unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, >>>> >>>> if (addr) >>>> goto out; >>>> - if (!IS_DAX(filp->f_mapping->host) || !IS_ENABLED(CONFIG_FS_DAX_PMD)) >>>> - goto out; >>>> >>>> addr = __thp_get_unmapped_area(filp, len, off, flags, PMD_SIZE); >>>> if (addr) >>> >>> I think you reducing ASLR without any real indication that THP is relevant >>> for the VMA. We need to know if any huge page allocation will be >>> *attempted* for the VMA or the file. >> >> Without a properly aligned address the code will never even attempt allocating >> a THP. >> >> I don't think rounding an address to one that would be properly aligned to map >> to a THP if possible is all that detrimental to ASLR and without the ability to >> pick an aligned address it's rather unlikely anyone would ever map anything to >> a THP unless they explicitly designate an address with MAP_FIXED. >> >> If you do object to the slight reduction of the ASLR address space, what >> alternative would you prefer to see? > > We need to know by the time if THP is allowed for this > file/VMA/process/whatever. Meaning that we do not give up ASLR entropy for > nothing. > > For instance, if THP is disabled globally, there is no reason to align the > VMA to the THP requirements. I understand, but this code is in thp_get_unmapped_area(), which is only called if THP is configured and the VMA can support it. I don't see it in Matthew's patchset, so I'm not sure if it was inadvertently missed in his merge or if he has other ideas for how it would eventually be called, but in my last patch revision the code calling it in do_mmap() looked like this: #ifdef CONFIG_RO_EXEC_FILEMAP_HUGE_FAULT_THP /* * If THP is enabled, it's a read-only executable that is * MAP_PRIVATE mapped, the length is larger than a PMD page * and either it's not a MAP_FIXED mapping or the passed address is * properly aligned for a PMD page, attempt to get an appropriate * address at which to map a PMD-sized THP page, otherwise call the * normal routine. */ if ((prot & PROT_READ) && (prot & PROT_EXEC) && (!(prot & PROT_WRITE)) && (flags & MAP_PRIVATE) && (!(flags & MAP_FIXED)) && len >= HPAGE_PMD_SIZE) { addr = thp_get_unmapped_area(file, addr, len, pgoff, flags); if (addr && (!(addr & ~HPAGE_PMD_MASK))) { /* * If we got a suitable THP mapping address, shut off * VM_MAYWRITE for the region, since it's never what * we would want. */ vm_maywrite = 0; } else addr = get_unmapped_area(file, addr, len, pgoff, flags); } else { #endif So I think that meets your expectations regarding ASLR. -- Bill