Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8380679ybn; Tue, 1 Oct 2019 07:22:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzM6OeXfkY8zuz7dp56/knD5k/EwiHZaL8pt9zjVV5Lv/8NP52/ZnHP4w3hyal8cgNHGBhf X-Received: by 2002:a17:906:19c9:: with SMTP id h9mr24144068ejd.193.1569939726963; Tue, 01 Oct 2019 07:22:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569939726; cv=none; d=google.com; s=arc-20160816; b=Vai87Em6XcbqfX4DPzixdAx0EjLwYIF8FDVya5TJQumCnDX5vuRjvDA/e0VOop7n9F mDlkNZYlqp8denVJULfIfOQ6xPCz4PO61xQJLx511rrvl09Hu9X8EGANMZXhKIEIYXl5 n7ghi1+2GP4GRQq15lkRvf7Wcafvkx1mMyFEGguuBb8t/0qIJSC2eccKpbB2CTDM+W5S PbQ9sgcgKKzJ/s42Gf8fXKrsgfyULZdsHFrk1TT9X9zYiEK+mnYx2zIHJIVThY7TXVX2 uv5OWAi8ojXbNfMAkNd68edCf2G9XTAP2w4Ph0XuRbens8Tc3uSDX1fTUcR28LtYJ+dP Znaw== 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:dkim-signature; bh=jW7eXDdGpzoPqCGQ/N/Pe4qVEBLi12b1nAQpyDAd19Q=; b=DJ0UPuifHeaufcNeAUV5zys9y7EmJCAlJOZH9D4n35ySKt5zTOWkSW4frtMnvuJaOe Klv/9w00F3Js6VtDlkqUviCscN7DOzR8BWP6dEprX5ClG+Zto+jkkvwsyewbjuT1mFYD egncBkBkTqrdNnvjT9K6wBtx8Tu19stYByHrZODkkoz6y+1AYWHewWK+SRgLOMgWIiez 1TA2lX1mXcOdAKbj+IgFneeOLlN/ksR/aW/daT5yM9DtISJsUdpyu6Lu+TkNR81Vx0sf lcA5AnFKnfIP3GciGAIWwcVPd4ERMEkyDX0gS+f/HzNUTqj6p17g7FgYqAWpFum90zHk NH9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=saWObvKZ; 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 k1si8915864ejj.174.2019.10.01.07.21.41; Tue, 01 Oct 2019 07:22:06 -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; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=saWObvKZ; 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 S2388957AbfJAOUV (ORCPT + 99 others); Tue, 1 Oct 2019 10:20:21 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:38887 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727055AbfJAOUU (ORCPT ); Tue, 1 Oct 2019 10:20:20 -0400 Received: by mail-ed1-f68.google.com with SMTP id l21so12074245edr.5 for ; Tue, 01 Oct 2019 07:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=jW7eXDdGpzoPqCGQ/N/Pe4qVEBLi12b1nAQpyDAd19Q=; b=saWObvKZ+2SD8KboWxSXVO4qJxtT2dlC90wePqcBMjuIQ16RhK1fhrPTLJrwlldyQf ELqbo5Zcx/a0uGVlJDOC7M9+6tIvOz1d5MOefIkpGNakWSPKTla9TB8saKYRQnnpsA0k OTl9mp1bToCTT2Za3zOjdzA+aS61WXFprYGqtObLzk3dRe7tS/P7H88cYkXApEwLVksm 5ADB2qQWBR1fp7sgE35A6Fo9GOvEuxEmzQx8wUyUj+RyAxAww7KG3kXgmWywMS3YDcpy qIZTVPd/WYVKU2OIHHdS284uCNknaakxIFU/AFUYPUueVMfJqrn/zhKTp+9AiBmtPGca jBjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=jW7eXDdGpzoPqCGQ/N/Pe4qVEBLi12b1nAQpyDAd19Q=; b=BxnbN39Zz1ZMGpkyOl5RTpNnnU+dwBzrkOtxUkSbG0s0gGoW0UcbugrbXmRucXUeb0 RUY5Q5GaodaH+te3S++HVqNLfinE2oDkTUS11VD08YK6pTlKfKMfSRAApB/8veFxaSPt 8I49G3CyfjaOdn0fdTFEHBBgADHnx+3LHT2zc07WoBenb9mEh0LbK7/GlqJdF3Bg0yMi aSbzS+LHHHvESbQd/tUSJyLeEL2Nbx7vMHIgWUVuOTdNLHUU8Doe5K1Ih2995nQEizsw CljdPpifhIhMgr0z4xuGH7Wx8flFHvZqZtH6ClwqZJClLbYFRpbdQcq9qgjtl1fQ05C8 BnZw== X-Gm-Message-State: APjAAAXYBgB8ACAiIdIDYqekBSJBbiIqmsyphI9GQxUR1f3KZdGCi40C 4eOEmkWxPsyVP204nUfLu/I/3g== X-Received: by 2002:aa7:dc55:: with SMTP id g21mr25526019edu.210.1569939618577; Tue, 01 Oct 2019 07:20:18 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id o26sm3143696edi.23.2019.10.01.07.20.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Oct 2019 07:20:17 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 51D61102FB8; Tue, 1 Oct 2019 17:20:18 +0300 (+03) Date: Tue, 1 Oct 2019 17:20:18 +0300 From: "Kirill A. Shutemov" To: William Kucharski Cc: Matthew Wilcox , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 14/15] mm: Align THP mappings for non-DAX Message-ID: <20191001142018.wpordswdkadac6kt@box> References: <20190925005214.27240-1-willy@infradead.org> <20190925005214.27240-15-willy@infradead.org> <20191001104558.rdcqhjdz7frfuhca@box> <20191001113216.3qbrkqmb2b2xtwkd@box> <5dc7b5c1-6d7d-90ee-9423-6eda9ecb005c@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5dc7b5c1-6d7d-90ee-9423-6eda9ecb005c@oracle.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 01, 2019 at 06:18:28AM -0600, William Kucharski wrote: > > > 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) { len and MAP_FIXED is already handled by thp_get_unmapped_area(). if (prot & (PROT_READ|PROT_WRITE|PROT_READ) == (PROT_READ|PROT_EXEC) && (flags & MAP_PRIVATE)) { > addr = thp_get_unmapped_area(file, addr, len, pgoff, flags); > > if (addr && (!(addr & ~HPAGE_PMD_MASK))) { This check is broken. For instance, if pgoff is one, (addr & ~HPAGE_PMD_MASK) has to be equal to PAGE_SIZE to have chance to get a huge page in the mapping. > /* > * 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; Wouldn't it break uprobe, for instance? > } else > addr = get_unmapped_area(file, addr, len, pgoff, flags); > } else { > #endif > > So I think that meets your expectations regarding ASLR. > > -- Bill -- Kirill A. Shutemov