From patchwork Sat Oct 9 09:26:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rongwei Wang X-Patchwork-Id: 12547383 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56DACC4332F for ; Sat, 9 Oct 2021 09:27:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DD69A60EE4 for ; Sat, 9 Oct 2021 09:27:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DD69A60EE4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3FD21900004; Sat, 9 Oct 2021 05:27:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 352DF900003; Sat, 9 Oct 2021 05:27:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CD21900002; Sat, 9 Oct 2021 05:27:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id 073F86B0071 for ; Sat, 9 Oct 2021 05:27:07 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9ED25182B254E for ; Sat, 9 Oct 2021 09:27:06 +0000 (UTC) X-FDA: 78676370052.03.31CAFFE Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by imf01.hostedemail.com (Postfix) with ESMTP id A005F5079EF3 for ; Sat, 9 Oct 2021 09:27:05 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=rongwei.wang@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0Ur5qOcb_1633771618; Received: from localhost.localdomain(mailfrom:rongwei.wang@linux.alibaba.com fp:SMTPD_---0Ur5qOcb_1633771618) by smtp.aliyun-inc.com(127.0.0.1); Sat, 09 Oct 2021 17:27:02 +0800 From: Rongwei Wang To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: akpm@linux-foundation.org, willy@infradead.org, viro@zeniv.linux.org.uk, song@kernel.org, william.kucharski@oracle.com, hughd@google.com, shy828301@gmail.com, linmiaohe@huawei.com, peterx@redhat.com Subject: [PATCH 3/3] mm, thp: make mapping address of PIC binaries THP align Date: Sat, 9 Oct 2021 17:26:58 +0800 Message-Id: <20211009092658.59665-4-rongwei.wang@linux.alibaba.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211009092658.59665-1-rongwei.wang@linux.alibaba.com> References: <20211009092658.59665-1-rongwei.wang@linux.alibaba.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A005F5079EF3 X-Stat-Signature: pzi49qc3rmabm7hfg818b3afs1bsbpyw Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf01.hostedemail.com: domain of rongwei.wang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=rongwei.wang@linux.alibaba.com X-HE-Tag: 1633771625-598806 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: For binaries that are compiled with '--pie -fPIC' and with LOAD alignment smaller than 2M (typically 4K, 64K), the load address is least likely to be 2M aligned. This changes the maximum_alignment of such binaries to 2M to facilitate file THP for .text section as far as possible. Signed-off-by: Gang Deng Signed-off-by: Xu Yu Signed-off-by: Rongwei Wang --- fs/binfmt_elf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index a813b70f594e..78795572d877 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1136,6 +1136,11 @@ static int load_elf_binary(struct linux_binprm *bprm) retval = -EINVAL; goto out_free_dentry; } +#ifdef CONFIG_HUGETEXT + if (hugetext_enabled() && interpreter && + total_size >= HPAGE_PMD_SIZE) + load_bias &= HPAGE_PMD_MASK; +#endif } error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,