From patchwork Wed Jul 10 10:50:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13729172 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 79374C3DA49 for ; Wed, 10 Jul 2024 10:51:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 838886B009F; Wed, 10 Jul 2024 06:51:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79B9B6B00A0; Wed, 10 Jul 2024 06:51:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A9556B00A1; Wed, 10 Jul 2024 06:51:30 -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 356B06B009F for ; Wed, 10 Jul 2024 06:51:30 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DAC5A141C1B for ; Wed, 10 Jul 2024 10:51:29 +0000 (UTC) X-FDA: 82323526698.24.A0E7A39 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf24.hostedemail.com (Postfix) with ESMTP id C2C7D18001A for ; Wed, 10 Jul 2024 10:51:27 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 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=1720608671; a=rsa-sha256; cv=none; b=w7OdZQj5hVtBjKBVCZAP1BDn9VOPiTSgG2fWN23h2dRwrYs356rTDESZmVmm14lvQgvn8G y/Khcjzzb1LQL6zQGvcvU8e5fdLe6R1MxTQZe0vA9XSMkEq0AWOpSgXeugBiyjkfqlaRz3 A/5h8my8pAEUVAtGUZivXJPulzjmNHA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 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=1720608671; 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=AtaykMEmsX4OA7BdJhl824p959EML0mly9B5ASKXNoU=; b=EWYtSqNDpzrFa7KWEBhL5KEXDbe+8QMxSOBOgd1M5md194AvkoiaWtXYfrV8Mz5x93cL6O 5q02fiHW0a4TXJrCbditsP/dJQweYpYSdgSVClwMASdiT13VHoQ3NjTpFRKtIhEqQgQXa3 esiCk41NQIPrMO81EsBNIb+MRWWFU14= 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 78AA81F829; Wed, 10 Jul 2024 10:51:26 +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 57AC51369A; Wed, 10 Jul 2024 10:51:25 +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 AIHDEK1njmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:25 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , David Hildenbrand , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [RFC PATCH 3/8] arch/x86: Teach arch_get_unmapped_area_vmflags to handle hugetlb mappings Date: Wed, 10 Jul 2024 12:50:37 +0200 Message-ID: <20240710105042.30165-4-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240710105042.30165-1-osalvador@suse.de> References: <20240710105042.30165-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-Stat-Signature: 7j8eqc6fq5e5fsbepejr1nie37r8z4uw X-Rspamd-Queue-Id: C2C7D18001A X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1720608687-555214 X-HE-Meta: U2FsdGVkX1/VHCt8+OInel4albZk5x3Ty0JWwUCkswV3kGIC0Y1DKW7XEusoTup0rdcpe4oc0Axs+6Npia0kg6zLsMw4me1+LtN8tXWEd+R2jC4HV71VgBV57oItixfCXQZ1ldo/xb0XK6DKvYDTgEm8wb7rhg31CJ2ScNnkhecHJqDu17Ekec57VdBORl+PtDkbYYyM5mCbJLfZyUAIV4lSwHiuHfx/vW8fOulqE87Cu+emMSPCrRWk2FwV1JHI35+j1JvTVjtHRTbJ6l0BvRfE6GsyDYMvadUtse1P91x7c9Ru0YBUztjAMo0YgzYIrSIfVnPe4+0EUYwUe9lDT50Jmu9lEnNyZE/NArB90+5JVKjO8KFbWv5vXx8l1vnHxnM36nGod2+yfzSvZXNlKwRGmlmF+WxboJUB+RG4+8jU9vhqbFRLyNjXGRAEBOxcASpSBcLwXKpmVSLCKcnFWO/oOCqDm/tdhIh0Zczr33E3Lhi/95fkt0gN+XOOkCy5pvnLTsXx/wYWyXaGxpIkArrT37pe+OWsrjfPgHp95iIzmyHvT7kT/0lYD/JdWE3wIzkjdHfoQAxZxzSrNAflCn2JWU6tr5Vot8mfZb0Ku18DzJfS+K91f6jaGEcPnurEGJnHfDeCFYS2fuT/oivb1hQIZxw0bMD3AcOb0GfyjRpS8hZQr0AGYyEZd+zYLhOYfsFR6ax5wZ5KScCrXxFAOUKu7vWNSCwefGkt00Jr4VDRPRhi6kBM9J0MLO/ukD6wXQrlhgLRHJAaLBpu5BWs1By6LRkmXC1uhxYjWmXwgxxe8jgmj4OE16TWDOT6wCPqIzZAmdB0oPUpWbgiMTPzkK6p6ZQt5vcVWYh5e12Be2IJSub2WiM/a4/uhmPMDfkFUymmrrsrqm/0cYyfUMG53EX7J+ULK9bOmFu7+ICycWQMhwwRl7Wt8sNVyfvM8YFUQWwMpnLL4ZQrUjCtDQm IaNijYMN d6tIujsgQnFhmrin0uAzQ0wJHv4Hh2ZYqCX1Xn0ZkeXq2VOvDCCQ3iaisHoALH3XZH2obvnTNVAezn1khwMk8a8gzWpZm5hKvZoCp6T+4Zp3+Xw0lUXSBKyvzXXeGErG1RiI716XpcQcXMbqy9M8YQLJerASpo28GnSuWSqBSq3021aI= 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 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);