From patchwork Thu Jul 18 10:58:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13736388 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 4AC19C3DA49 for ; Thu, 18 Jul 2024 10:59:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3389F6B0092; Thu, 18 Jul 2024 06:59:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E9566B0093; Thu, 18 Jul 2024 06:59:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09EEB6B0095; Thu, 18 Jul 2024 06:59:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DE4AF6B0092 for ; Thu, 18 Jul 2024 06:59:20 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 989F9121A24 for ; Thu, 18 Jul 2024 10:59:20 +0000 (UTC) X-FDA: 82352576880.18.B17744E Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf04.hostedemail.com (Postfix) with ESMTP id 69C144001C for ; Thu, 18 Jul 2024 10:59:18 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ROL3Btep; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=oRwpoIhB; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ROL3Btep; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=oRwpoIhB; spf=pass (imf04.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=1721300338; 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=BHN99Otp08yvKHunYIWd3zL4cHzZBNMKDmIpLbdX684=; b=ZXSX6oH7wh5ezrMsera8nQrkh/y0IO53zDuGwuTN87hqC58if9USe49p2eYK5iGynoljs3 8x/GygRvijj0VQ96zaCzo5dLFmnRzl26WVf27dlxX+66zsdpZKBgun2Y5KQCKAQi2mU6tJ rK824HmSOGLUVdrrbZrwaSds6u712JU= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ROL3Btep; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=oRwpoIhB; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ROL3Btep; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=oRwpoIhB; spf=pass (imf04.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=1721300338; a=rsa-sha256; cv=none; b=oTRlR37QjCP5Dyl8IFbmjitegiY+cGAa1A7kWEQB5fXOi0IPb/d9eYE/tOkZ6Kv0SlJ9RX U2bndh+74jI2zKnUJC7Dx6E5B6rdaombI84fiWMfFtNNgrBPQ1bTMLqS1qO7bwXr+oWVXv p08MaK/HhURLJEQlaOTnODkhq7U6TjM= 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 B2CC421AF5; Thu, 18 Jul 2024 10:59:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300356; 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=BHN99Otp08yvKHunYIWd3zL4cHzZBNMKDmIpLbdX684=; b=ROL3BtepMH8hvdTP7yikKJC2Bjb9wtA9aU5ZNrKsCn3UdiH8tgTp7mWjKfzyR6YHaSdep2 G6hKQv7Z3pspF9/Z4RwVT8ZFhDH4P4+nr6cMUcLDjDjxYck1Kpk2zlruoAW4hpns58FdEh d3+2822x2EWq255lyXMNp4Gmi3DFQKo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300356; 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=BHN99Otp08yvKHunYIWd3zL4cHzZBNMKDmIpLbdX684=; b=oRwpoIhBYuLkTUNMIPtBuktOIT1rvbaVJ65aKpRzjqSSeEiTSL+RUohgMBZlb86A1noTlR tBdC3gAq5HtrS/Bw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300356; 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=BHN99Otp08yvKHunYIWd3zL4cHzZBNMKDmIpLbdX684=; b=ROL3BtepMH8hvdTP7yikKJC2Bjb9wtA9aU5ZNrKsCn3UdiH8tgTp7mWjKfzyR6YHaSdep2 G6hKQv7Z3pspF9/Z4RwVT8ZFhDH4P4+nr6cMUcLDjDjxYck1Kpk2zlruoAW4hpns58FdEh d3+2822x2EWq255lyXMNp4Gmi3DFQKo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300356; 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=BHN99Otp08yvKHunYIWd3zL4cHzZBNMKDmIpLbdX684=; b=oRwpoIhBYuLkTUNMIPtBuktOIT1rvbaVJ65aKpRzjqSSeEiTSL+RUohgMBZlb86A1noTlR tBdC3gAq5HtrS/Bw== 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 BCF64136F7; Thu, 18 Jul 2024 10:59:15 +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 8AwlKYP1mGbnVAAAD6G6ig (envelope-from ); Thu, 18 Jul 2024 10:59:15 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [PATCH 3/9] arch/x86: Teach arch_get_unmapped_area_vmflags to handle hugetlb mappings Date: Thu, 18 Jul 2024 12:58:57 +0200 Message-ID: <20240718105903.19617-4-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240718105903.19617-1-osalvador@suse.de> References: <20240718105903.19617-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 69C144001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GbhyXpDE8yZIc8dDjl3RrKx/VxlvSsf6Amkc1A1eP4AX8Eq4kmakIOoW0pDkeA+8YJZjNXOTqw9GF12w3xz/whgD9pexP6dTxQMkE4GjA+21YP5lrlVSXtdlbm93WXHLTxUiT4mLxHsiP/jeY0tLumpBRhg0SaycD+jciIZgy9j/C+wGDQ6QlrNz5a+30gtsaigyG8dtLQ0Fleui/ZexGAmze0AnqB96oQCkKD4ocNF/Mtv5iT0C3fmclinfVeIGxVtH 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);