From patchwork Mon Jul 29 09:10:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13744627 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 9FB2EC3DA61 for ; Mon, 29 Jul 2024 09:10:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 119356B008A; Mon, 29 Jul 2024 05:10:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C9536B0092; Mon, 29 Jul 2024 05:10:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5F966B0093; Mon, 29 Jul 2024 05:10:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BE2686B008A for ; Mon, 29 Jul 2024 05:10:40 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6E44312020B for ; Mon, 29 Jul 2024 09:10:40 +0000 (UTC) X-FDA: 82392219840.18.6C43411 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf02.hostedemail.com (Postfix) with ESMTP id 5126180018 for ; Mon, 29 Jul 2024 09:10:38 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf02.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722244235; a=rsa-sha256; cv=none; b=JiamAPPkZXc1Piju4lQoPhTj49h1GJrtGtBUTSsP/CiSYhKPbJl0VIb/ABOFAX4e9bBait 0jmjEU0lb3+f/WCljzCMAanZJKY2wvIjWFVQJrqlcpFkLPjIlSlS2LBKUHl8hamRYw4nZW Z7oXn3CjEe68TSCuOGfE1U57XJmgQGU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf02.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 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=1722244235; 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=BHN99Otp08yvKHunYIWd3zL4cHzZBNMKDmIpLbdX684=; b=Jk6PXq3a/QboVudUF4qp/r3n2HsfMJSz0Cf1tEFEE1fZEXbnWV/Ci24sew6cEOjYkig3Hw F+ZM18ZYLdxODkOml2z76hQ2nQ2XN5eM3N0qCNonTOUm8JF6PFZKy3jj42lz+ZGbLm9auz 8X6wrsDVRKEgplW3ywQdyc23zecCZ2E= 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-out2.suse.de (Postfix) with ESMTPS id CD03C1F790; Mon, 29 Jul 2024 09:10:36 +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 82F171368A; Mon, 29 Jul 2024 09:10:35 +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 UOzvGYtcp2Z4BgAAD6G6ig (envelope-from ); Mon, 29 Jul 2024 09:10:35 +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 , Matthew Wilcox , Vlastimil Babka , Michal Hocko , Oscar Salvador Subject: [PATCH v2 3/9] arch/x86: Teach arch_get_unmapped_area_vmflags to handle hugetlb mappings Date: Mon, 29 Jul 2024 11:10:12 +0200 Message-ID: <20240729091018.2152-4-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240729091018.2152-1-osalvador@suse.de> References: <20240729091018.2152-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-Rspamd-Queue-Id: 5126180018 X-Rspamd-Server: rspam01 X-Stat-Signature: 99zh33gqfpisfmch5fck1ef4aecbf54a X-HE-Tag: 1722244238-785395 X-HE-Meta: U2FsdGVkX19p8Rx2uKSvtAjY4HCwvCbwHBSkchsXFA50siR+AUMNoC1aOGb3lT4rxf4ZKKFzc6vTeKx3QN3rCt7GNLcNM3PvEEFKF8L6xgnP52/nwLOgnra5rzTjmIGwkUxT9pOa0SEaveHH8XwaUJ7hf/X9uPOjitOZ2+TsE8p2Nbp8knslwm0+bhG7DcWiie2HkPbAoFZb1OT/0FHbaj3nCjZhFurHny9w6dfulP3K+P80H37gx+J75cgNulKDG6qYTa/h2bcsGu6cScoagwdDHu+YkA3zivOrjmYXmXiM0H968IdT9llqK5AIQLTZn3/5ykJCAKJjo+VGd0TrW688bkNcSyxNPrYQb5OnjsWJIbERkIgkOlknFONi76bChTynm8fDJKvdGLSUBbJavTXJm4y0PLhXGkxjhVVtw+4h2gkgfi7Mc/WkgYQF8v4AOkB5ThKPWZv04jTAJvvU3ucPGffoHV7PTaG9h6fjSQPD2F8IRHTFV4+ipA34TlYjPSYti+dPiq5ujpf0XtdJSGQtEBinlJb+xVnds8EUxltsmErOWnMwP64NNhK4UArDCYkbYaFwbgb66J0PbygGR97BhDwP/48lPWAysm/W9+vdUCrcoxgRRePBerbR5tqJ5grNl5FKTej7i8pCu1+wO4diVufCe17JX+vtmTArUH0gt6qoTS/kAVEeOhbtHJjkjJnvyUZlkhi9cTuLOL0cx0EnvU4IPgc8+/BgjKoL2TeABvShYmnD0CfpardN2mYz+NkC8T9TZK3zt8VNKm6HZD/SaNc+71OEhOcIiYp4PQyW3U85DDyASZjsyUCt+Ybao4kd2POFgOWq2+R2vFvugZw1qQbFkNKcNePJ9/gkzk8w6dqap95Ef2R02EhS5Mqctj8Q1OJmumZVADg1c7DVnRuVpqlLX0dBqxWbG9KwiwwgJM769MQW8+zuDQHifAN+Uja8E/HLqQRuc8bmCxZ nVf1x9z+ h98adRblWnw0Ty7GkVjzp3fhBw+6NqnGXXncNicU6YThi/x6D/EQX0QIyZsnfsRDwsUCLmWsCFCwpdEp81hOUT0OUmbP7vN3jE4FntJ6Yos6pC4dxkFd+WesO+iQWYYJrPWU4A0xTO/4MdY9m9jdi60We6vPQxLCTWepfMeCrbuvfYo0= 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 compability. 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 01d7cd85ef97..aa7491f036a7 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_vmflags(struct file *filp, unsigned long addr, unsigned l 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_vmflags(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_vmflags(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);