From patchwork Wed Jul 10 10:50:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13729173 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 1F286C3DA45 for ; Wed, 10 Jul 2024 10:51:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E54886B009A; Wed, 10 Jul 2024 06:51:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E06506B00A0; Wed, 10 Jul 2024 06:51:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C08736B00A1; Wed, 10 Jul 2024 06:51:31 -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 9BF3B6B009A for ; Wed, 10 Jul 2024 06:51:31 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 272CBA4C8B for ; Wed, 10 Jul 2024 10:51:31 +0000 (UTC) X-FDA: 82323526782.19.442ABCE Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf21.hostedemail.com (Postfix) with ESMTP id EFA451C0027 for ; Wed, 10 Jul 2024 10:51:28 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.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=1720608657; 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=ShoxJLpkOW+OKsY5tmYdrRAt0I0v48ZTz5SGOs2Fhwk=; b=z8tJigPuBQNUOHTZjGhHbnSBz/NUJ4qipASQ9kE2w5PtaKo54HwW5NB1cDGoin3HHA6NIz jihtqgBztbKrvZECspSF9OYXDDbXxpvFL66aMrjybLtUYiqcmbe1KO2bXwL15f+PLZ1xWO PwzkErkP1t5Kz09Niq5aC23BHGqW3Vc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720608657; a=rsa-sha256; cv=none; b=rkWnXbX7kCgwtS8iIG/65mFF7s0Gux3n7VqneSQ7XT2cMu1gWpCnN8OYiqI3ARcHaq/8f4 QQFvU+mJvEcvyDb30teNRGM8XOahxaCELQ8HSwlxmYaf9ZOSGte3GVfYxeTg6LGfYWsDNy kowt5qi3twlbbk748bNV0cYyoDTCNi0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.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 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 C1FB61F82A; Wed, 10 Jul 2024 10:51:27 +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 A45BA1369A; Wed, 10 Jul 2024 10:51:26 +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 GFhyIq5njmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:26 +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 4/8] arch/sparc: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Wed, 10 Jul 2024 12:50:38 +0200 Message-ID: <20240710105042.30165-5-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EFA451C0027 X-Stat-Signature: amyefbnu9rn11ssou3upjqaywaymhsps X-HE-Tag: 1720608688-145321 X-HE-Meta: U2FsdGVkX18NS3dZkvJscnGhsBtgpvMsjmgMNaj+4PmScb6qATiEC9EAD6wWUGQxvNSoxHjk36mUAgs01z7nuKCTeH75fzNzHhH0Ce08CcY5fVCNiq7ASIEgBgDC2HUiIiDhSqEWuh/2V8jEws2IAm+YzqRiQeRMilVKOXzJTIfwZViaScbv3mp+3X6s3Kia8Wb3Iw9zZYjoWKQ9tUs3UVVgRVR+y3NR8v89KlOum8y9dg3aTDne8G4CV4bJX3vIUt13gThqzqcP/aIqECy9DIMcI4qF8+k7OadccAvo7sQDjNXFVya9CrwjJedKGZUCsa7ojPomTd0YmY+XzRmLBugVxuByz2GZ73QyJSC1whkqvRypEpqCHBgjLSY9iUJ60Wh4vDsAP/ZfTa9veoiNVP7PqIINuX98AihOrKjA8vVVGWX4v328S6Wc0FC2AoucGcde5eE6pgVzigOgZzmBCMa8tKSErsZFrnlmhenjNSWqnXUbCpErDC25i1JPRFATai05Lb8k52psgZPO4YGuWBL4Au3cBsy7KxzCLteiVAjw7DCNXqBo7tyqMw9PYKRFu/jXWUAoib25DfKG45LdAGLUXeoYW2mjH+8lM/iNgV9Voy49Gkg27cvgeAGBQQBc9OZJ4qIAZX8SMs3J0REpQIHR+jZ6t4E1OkvNPcpgxELPh4v5tZdOM+9e0sgBc6Y7l9ETTA2UtvnO5BQXwZJVYGIr3WqipJ0STmL1NPk3v9iZVnncdur1MPC5o9817Y39BSOWOQx4syza/L+TPHZ70AonSkwKRVphS4WrvOzW1KILScdp+K5gQ5rw1zEleLnUyyim7cWxLYCJWXPd70wx30dRAJlDU7UGOoqu7g/ggTyPwGGm5Hl5sNUoQjPYsjN7ENM+LvXwe3zfrX9P6xnW5m5FL1qar3b7xACLO21P0K01UaoQWaK5/2ooXAprLEKggvPsvJoVWgV53HNRsK/ A57krT/t ZpQckozk0gIlPc+nWUtKd0khoHu8sy7oPXKEhCPS1jJrllMFShO5KrqAOAca6BkWr3jZiP98WmJ+tT3QG3+A9kAwYLPuTPuldqjpWWg5ljED6S0ItQriUig5WHKzyUp/+kFxDjivkJW+fKkcQjCCaYfozPOaxMXKWzfgvwgGa9PFMioE= 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} to handle those. sparc specific hugetlb function does not set info.align_offset, and does not care about adjusting the align_mask for MAP_SHARED cases, so the same here for compatibility. Signed-off-by: Oscar Salvador --- arch/sparc/kernel/sys_sparc_32.c | 16 ++++++++++---- arch/sparc/kernel/sys_sparc_64.c | 36 +++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c index 08a19727795c..fc33ac48ed28 100644 --- a/arch/sparc/kernel/sys_sparc_32.c +++ b/arch/sparc/kernel/sys_sparc_32.c @@ -42,12 +42,16 @@ SYSCALL_DEFINE0(getpagesize) unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { struct vm_unmapped_area_info info = {}; + bool file_hugepage = false; + + if (filp && is_file_hugepages(filp)) + file_hugepage = true; if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -62,9 +66,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi info.length = len; info.low_limit = addr; info.high_limit = TASK_SIZE; - info.align_mask = (flags & MAP_SHARED) ? - (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset = pgoff << PAGE_SHIFT; + if (!file_hugepage) { + info.align_mask = (flags & MAP_SHARED) ? + (PAGE_MASK & (SHMLBA - 1)) : 0; + info.align_offset = pgoff << PAGE_SHIFT; + } else { + info.align_mask = huge_page_mask_align(filp); + } return vm_unmapped_area(&info); } diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c index d9c3b34ca744..81d8f5467dd8 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c @@ -87,6 +87,16 @@ static inline unsigned long COLOR_ALIGN(unsigned long addr, return base + off; } +static unsigned long get_align_mask(struct file *filp, unsigned long flags) +{ + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); + if (filp || (flags & MAP_SHARED)) + return PAGE_MASK & (SHMLBA - 1); + + return 0; +} + unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { struct mm_struct *mm = current->mm; @@ -94,12 +104,16 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi unsigned long task_size = TASK_SIZE; int do_color_align; struct vm_unmapped_area_info info = {}; + bool file_hugepage = false; + + if (filp && is_file_hugepages(filp)) + file_hugepage = true; if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -111,7 +125,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi return -ENOMEM; do_color_align = 0; - if (filp || (flags & MAP_SHARED)) + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align = 1; if (addr) { @@ -129,8 +143,9 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi info.length = len; info.low_limit = TASK_UNMAPPED_BASE; info.high_limit = min(task_size, VA_EXCLUDE_START); - info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset = pgoff << PAGE_SHIFT; + info.align_mask = get_align_mask(filp, flags); + if (!file_hugepage) + info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) { @@ -154,15 +169,19 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, unsigned long addr = addr0; int do_color_align; struct vm_unmapped_area_info info = {}; + bool file_hugepage = false /* This should only ever run for 32-bit processes. */ BUG_ON(!test_thread_flag(TIF_32BIT)); + if (filp && is_file_hugepages(filp)) + file_hugepage = true; + if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -172,7 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, return -ENOMEM; do_color_align = 0; - if (filp || (flags & MAP_SHARED)) + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align = 1; /* requesting a specific address */ @@ -192,8 +211,9 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.length = len; info.low_limit = PAGE_SIZE; info.high_limit = mm->mmap_base; - info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset = pgoff << PAGE_SHIFT; + info.align_mask = get_align_mask(filp, flags); + if (!file_hugepage) + info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); /*