From patchwork Mon Oct 7 07:50:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13824289 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B462CFB43F for ; Mon, 7 Oct 2024 07:51:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76BA96B00F9; Mon, 7 Oct 2024 03:50:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D78F6B00FA; Mon, 7 Oct 2024 03:50:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AD386B00FB; Mon, 7 Oct 2024 03:50:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E6EAE6B00F9 for ; Mon, 7 Oct 2024 03:50:56 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B3DE6A8DD8 for ; Mon, 7 Oct 2024 07:50:56 +0000 (UTC) X-FDA: 82646034912.01.C0D699E Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf11.hostedemail.com (Postfix) with ESMTP id 9D47440011 for ; Mon, 7 Oct 2024 07:50:54 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf11.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728287429; a=rsa-sha256; cv=none; b=RH4wMkjEcYvJJxBWL3nVZSiQ7Td/VMFNmetaZgqLnvMYFLwHkn+yxP8j04/Zr69FJ4WpTN PCKj3Uwldzo0tRjt6UyLoSk4+0veNwDqKX6ZYEJmjZQ71rUslZ7q8wtceV8e1lzhSlHIt+ +wHsTpIjZuWMJZofiy7E94TXx+j6FDA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf11.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728287429; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4CVBfBerTQRyf1IgzEWS511wYXAZxzYRFHGOxP2aS3o=; b=F+jKQHjCdfOS9S+LFPW43+0hccCNaqN6rC7uRBDdsXILEyQktH+BPiiEFzehH39bL+ymrw iO7ioZdkpx0wx0fXTtjyYG0E6bRm6Kv/QULoVpFbc9OB1J49IqFP6Wp19nJv034owip+4w 7hL/+FIuok0zqHqxgxkda4husxvYgDM= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 65D3B21C4D; Mon, 7 Oct 2024 07:50:53 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BACF4132BD; Mon, 7 Oct 2024 07:50:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id sP+YKtySA2d6cQAAD6G6ig (envelope-from ); Mon, 07 Oct 2024 07:50:52 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , David Hildenbrand , Donet Tom , Vlastimil Babka , Michal Hocko , Lorenzo Stoakes , Oscar Salvador Subject: [PATCH v4 3/9] arch/x86: Teach arch_get_unmapped_area_vmflags to handle hugetlb mappings Date: Mon, 7 Oct 2024 09:50:31 +0200 Message-ID: <20241007075037.267650-4-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241007075037.267650-1-osalvador@suse.de> References: <20241007075037.267650-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspam-User: X-Stat-Signature: zng4nmfs7sbo9z16k4zugkiugwu8z9u6 X-Rspamd-Queue-Id: 9D47440011 X-Rspamd-Server: rspam02 X-HE-Tag: 1728287454-251267 X-HE-Meta: U2FsdGVkX1/cri2StJiWAJ7/54ZTb1jDw4lk8RCPm0PG9Gc6DSPrp3zRyCgjSHhieQ9CPa3AYGlxuHyq+jMEdOueuCO2EHuOagozwJTMZDamSGhlaiR60Xv+UyiDrmGecLAkILiIw6TFjXQQS8WCLql2im9YnIz80SEgyjZTcNm+qK8XsFCgmzU1GMpi8z7SxBW6W4Bfyo498YUDfMpkrmJ6WWZAplTkLNw45tsXmIz+sgyxLcrbeboIMzhEKWmll3S8n8htLB97EyGckaXyWsDYk3CR6wqDO9oG+hWv7A4iRjDvXcf2yC0IIzNGXh29ARvEzkeLeuZ3XjByBWKCsA+5uvWlKMvkB/fm1FCLeYjBZ0u/AVKfz8iixo1oqISSkx81ZcwjPGt67QcJHNOZgogwSGksoUC/+/CaS2MKXZqXXnT5FCvm7rEW9D3qsvK1Twj1wUwMHScp0tARVAAziK0f7nb9Egp9rw1Pg2JiHLPEdxNddKoOVUxdWmzQPL3nBuvNWsnDl0kOlCgpB1yMOHK93SH5vHkIqdt8WZFLkPycp/yATEC2UOzC69lQltu62I2jSTmiLTgVSK/TUC5YcO6fyDn1izUp/Y7P1+zA9WTTVVEx+1UMj8peUyEiRTM63RLQlRJiA3RxwSu1+MeXzNwOEIERO4tHgce1b1LkoJxK8DAsP3vh7sIpqOJXkzFrDmZ3mXN0PAvHAyhRezKB21KHb1zDeKXB9gW1aPda7xh21m2IikPNiYECKjKmAukZCKFyHMeRv1fSZ0jteDsWPdnEQ3M0sWLRGIkTFhtGd6Q1dEAMJ8XGjnhqA2aW1SMUXrXinFHQg8qtap7Oh6ENJOP28pF159X+8uxKIn3KQqbY1wVsrxNc/DQu7lG0DAvzlr9Bz54qQsU1hC1WBJfWiw/vxZ4E12KbKnuK2/Mu/gt0KqlvNXgQdGSzlgIoVlV8zMg1iMOxvHESYRVZstI pbv1xyNc AtS89qsOD7DEU6O3dIwlEmHOmLyYvKXe1XoTbvr9tlaaS/tN308ypj2PwnEaiAK3EosDN1SN2k0VlRY9wcXoakMwhuY6gUnNquxkcLLM/UlCucFzLE6pL3dGUZoS04xvpxs8HDG8HNKsEr8vCP7xF4U/3vWNACn3bnEK3QzVeqQpQ/SU= 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: List-Subscribe: List-Unsubscribe: We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area_{topdown_}vmflags to handle those. x86 specific hugetlb function does not set either info.start_gap or info.align_offset so the same here for compatibility. Signed-off-by: Oscar Salvador --- arch/x86/kernel/sys_x86_64.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c index 87f8c9a71c49..776ae6fa7f2d 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -25,8 +26,10 @@ /* * Align a virtual address to avoid aliasing in the I$ on AMD F15h. */ -static unsigned long get_align_mask(void) +static unsigned long get_align_mask(struct file *filp) { + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); /* handle 32- and 64-bit case with a single conditional */ if (va_align.flags < 0 || !(va_align.flags & (2 - mmap_is_ia32()))) return 0; @@ -49,7 +52,7 @@ static unsigned long get_align_mask(void) */ static unsigned long get_align_bits(void) { - return va_align.bits & get_align_mask(); + return va_align.bits & get_align_mask(NULL); } static int __init control_va_addr_alignment(char *str) @@ -148,12 +151,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, info.length = len; info.low_limit = begin; info.high_limit = end; - info.align_offset = pgoff << PAGE_SHIFT; - info.start_gap = stack_guard_placement(vm_flags); + if (!(filp && is_file_hugepages(filp))) { + info.align_offset = pgoff << PAGE_SHIFT; + info.start_gap = stack_guard_placement(vm_flags); + } if (filp) { - info.align_mask = get_align_mask(); + info.align_mask = get_align_mask(filp); info.align_offset += get_align_bits(); } + return vm_unmapped_area(&info); } @@ -199,7 +205,10 @@ arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr0, info.low_limit = PAGE_SIZE; info.high_limit = get_mmap_base(0); - info.start_gap = stack_guard_placement(vm_flags); + if (!(filp && is_file_hugepages(filp))) { + info.start_gap = stack_guard_placement(vm_flags); + info.align_offset = pgoff << PAGE_SHIFT; + } /* * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area @@ -211,9 +220,8 @@ arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr0, if (addr > DEFAULT_MAP_WINDOW && !in_32bit_syscall()) info.high_limit += TASK_SIZE_MAX - DEFAULT_MAP_WINDOW; - info.align_offset = pgoff << PAGE_SHIFT; if (filp) { - info.align_mask = get_align_mask(); + info.align_mask = get_align_mask(filp); info.align_offset += get_align_bits(); } addr = vm_unmapped_area(&info);