From patchwork Tue Sep 10 08:00:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13798080 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 E36CFECE564 for ; Tue, 10 Sep 2024 08:00:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 756208D0026; Tue, 10 Sep 2024 04:00:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F9BD8D0027; Tue, 10 Sep 2024 04:00:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 560D78D000E; Tue, 10 Sep 2024 04:00:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 379798D000E for ; Tue, 10 Sep 2024 04:00:55 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B794140A99 for ; Tue, 10 Sep 2024 08:00:54 +0000 (UTC) X-FDA: 82548082428.13.896CC54 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf28.hostedemail.com (Postfix) with ESMTP id 85370C000D for ; Tue, 10 Sep 2024 08:00:52 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1BAI1Uzw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=B1CHF1FU; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1BAI1Uzw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=B1CHF1FU; spf=pass (imf28.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725955201; 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:dkim-signature; bh=ECz/ucTq55vu26EzU15Ueg1Bt6OrgMPODU+khQ9gIJU=; b=lgR1IiJJygHf1TCZWAkFLA3AQoliZqu6YOr+K9I6wwv3j8K/6KP2HgtPTKXFMf1rRX3tKL YaP7+3RN/S1KqIcEE/W+BSrT4MWDOUCg9nsbObmgwANUfWmRtrFZwYlswj2VwX1NHiVj2I ecaHFSUlVwVAsfH/4LWQ/CTNWJWSYjs= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1BAI1Uzw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=B1CHF1FU; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1BAI1Uzw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=B1CHF1FU; spf=pass (imf28.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725955201; a=rsa-sha256; cv=none; b=lZHTrjecWu7L/8j5bZeNFMv6qEPcEfoW5hM4rTgsFYZfldKqiYRzE4kgz6q1lO6rqlQoqP QEOPZxSfL8enm+dd5y5lXbrCvTv6wF9L/DeqEASfjP1PBbf6W8bzUzXEvB8PzsTtAmMENj tDDNIj8rUKWuCr4ZAjJszReZSIb7lsE= Received: from imap1.dmz-prg2.suse.org (unknown [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 03C4121A3A; Tue, 10 Sep 2024 08:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955251; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECz/ucTq55vu26EzU15Ueg1Bt6OrgMPODU+khQ9gIJU=; b=1BAI1UzwrJylDZdLs/tm23hsXSNM5Pt2JIUkgso7a+VmLemiWBz3yEbcqqCjmU/l4M2mCa RSou/oYGMbVAzURx2UqKdVYcTr6qpy84LMLQkwFTSfgbkpQaGa4htSr58WTCtPR/zJaWwx T4latjkh4xbhguWuW94bmXKU3ANXEqQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955251; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECz/ucTq55vu26EzU15Ueg1Bt6OrgMPODU+khQ9gIJU=; b=B1CHF1FUCQgjAfBzphbfQXEqo50g2GfTlJhOUhGMVk2VrghOqDRTTokchbnS+RjmdkotaF MXaiHDXJymZZlVAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955251; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECz/ucTq55vu26EzU15Ueg1Bt6OrgMPODU+khQ9gIJU=; b=1BAI1UzwrJylDZdLs/tm23hsXSNM5Pt2JIUkgso7a+VmLemiWBz3yEbcqqCjmU/l4M2mCa RSou/oYGMbVAzURx2UqKdVYcTr6qpy84LMLQkwFTSfgbkpQaGa4htSr58WTCtPR/zJaWwx T4latjkh4xbhguWuW94bmXKU3ANXEqQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955251; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECz/ucTq55vu26EzU15Ueg1Bt6OrgMPODU+khQ9gIJU=; b=B1CHF1FUCQgjAfBzphbfQXEqo50g2GfTlJhOUhGMVk2VrghOqDRTTokchbnS+RjmdkotaF MXaiHDXJymZZlVAw== 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 49157132CB; Tue, 10 Sep 2024 08:00:50 +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 KG3tDrL832Y2MQAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 08:00:50 +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 , "Liam R . Howlett" , Oscar Salvador Subject: [PATCH v3 3/9] arch/x86: Teach arch_get_unmapped_area_vmflags to handle hugetlb mappings Date: Tue, 10 Sep 2024 10:00:24 +0200 Message-ID: <20240910080030.1272373-4-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910080030.1272373-1-osalvador@suse.de> References: <20240910080030.1272373-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 85370C000D X-Stat-Signature: 1zy7rn7gwraa93w6tuo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jB3qZKVx/bra3sjydMqk0Asl2kfivR+CaKEnYswCd4a8Qf7V4nWdvS7CSKlHXUp8CNWzaYqWVzB8ZEe/EKYhpm07Fccwp2JFQDve5ReY2ncwoEJqFTanAAIklaPTAYP167HijY3Y5S7ofWenfGc6BJK2e34tyhG9vbAh8s7RCgikDgSLrDRevhR2oqgitKhW5LGQ6DErpFgmDKVLURgbkRqPhru2xRh95l3QjzJzHavPPhmaRMcqLEJa2jElA/C5xI/rvEtegt4udA== 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);