From patchwork Mon Jul 29 09:10:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13744628 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 286F2C3DA61 for ; Mon, 29 Jul 2024 09:10:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CF4C6B0092; Mon, 29 Jul 2024 05:10:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 77F626B0093; Mon, 29 Jul 2024 05:10:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5843C6B0095; Mon, 29 Jul 2024 05:10:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3782E6B0092 for ; Mon, 29 Jul 2024 05:10:42 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D89BA801FC for ; Mon, 29 Jul 2024 09:10:41 +0000 (UTC) X-FDA: 82392219882.29.A179FEC Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf05.hostedemail.com (Postfix) with ESMTP id B8BFA100003 for ; Mon, 29 Jul 2024 09:10:39 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.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=1722244186; 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=KPjpjgmqDfRdVPMwY8SIrDz1ElJHQdBJQeTCq0Yrxzo=; b=hv5H9LXUAtOgLnvVP/E2W1F+JWmf44OXq95/kKgwAIHeeg/Rh5mvNX/6xOL+f9KY8wAeIi afD1pUnASTlt1nQi5rP69FPx3mhkizbWcUEqi9m9WojMhZYD4epDOmUXC5XrNA7GdZkutk l4eM2tS8hOOh8QT6cEeTcIUk7ElvBlg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722244186; a=rsa-sha256; cv=none; b=pyvrsRdgvACYlqerucRa5CQOlDpl3+2zAbSQyc/tgCmRsf2/KL6BUMGGEt+ebHARi4G2K+ 3pI5KJANUU2j2vuYKmQhisXeYICoS+FIb74iGNiALtLWnq7gw89rzMBRxqGrBTTgmtKAWP 4arIQOqBrPBqkw+RkbJoUQ7HMxIpFac= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.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 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 70CFD21BCC; Mon, 29 Jul 2024 09:10:38 +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 03FE91368A; Mon, 29 Jul 2024 09:10:36 +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 IHMSN4xcp2Z4BgAAD6G6ig (envelope-from ); Mon, 29 Jul 2024 09:10:36 +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 4/9] arch/sparc: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Mon, 29 Jul 2024 11:10:13 +0200 Message-ID: <20240729091018.2152-5-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-Stat-Signature: 3kaaagnmw1pyzbrnmij9uq6wwp8ihybi X-Rspamd-Queue-Id: B8BFA100003 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722244239-557582 X-HE-Meta: U2FsdGVkX1/sX6Bg7Dk9boK3Ke+DuycLhd1wld4Um/nC0snJsAgt00UTJKhEMEgBdkmfWbvXXc3YSA91IKjpKbnMX3QMTPvTjcI6VaYehxEX0nBZsn58Z0jy/bBlNfNj+TbLUaIOLnKlTxJB9TggtUNc++pn6reVdyZrjl5kiw4Q8pZEvINY0kB64ZUY0XSUueMi/suToe53a3Jrc45einBRx3C+F6B5+AOspzjLfukmCnoPJ7LNzTFDtsi+opzoNNk7QKyAXomA8ybgX4pQrCmH1W2tq6Hse7kEFe8/uBMz+Mk3Ao326Ubsl1tgQSAAGe1jSTVnv7+mCfEeYrsC6LYlEvmjCuhbCFXnOKUQpWK//wzCXlCJDtfQ/7/+kNemKvzDM6WvPyzYHVbjzFY5Qbj9Vhl5hZp6Ju4+WXz+2DTi/ROyOR53sHqwCIRHPhUk0VKztyPfGFQTTwqnVYhgP+rOsumKKj7vz/0U4zFH2sHV2d3tkpBGlNxFfzq/lENWwX3eDX8ofY71aN9jYZjq0HB68SA/d8mnKyfwUhy30Bw7+4IkvJOGBFqMfzrwlSL7r1eZ2j15RVvaacnD5Byqh0OQshosrCR3OXPhMZEACbD5mABsQQgVl3DDNcsN1GKKu2buzF0tvqPO91W3ii6I6DDXmfL0Bp8ivv3OGCr5ggTHSbmtRfUITC90aPn7MKg7Y/5hc3cZ6byXgT2ur1QX7RAqb2/WtaxrSGQpFHqF02KoERnD4PXoXgIDFl6HBbQlHh1mWjYW525wKVXMV0GlfBdfWJhWJUL4Csb1f3f6ZhZsTn17BR2AOSRoejflquojnrHv614JeVE4AzLD5gDmJbzm2Dl8bQU47kP2adxf8cP7bOK6S9eP40GGW3FBub2mr2Cp8AO9BfTTUpgDm4BFzzDwXEh2rRzjxI22y3aQXuO7JdHz5ZbZRqHE9sZFEB1H2md6PFNzDWQ413MUZ88 XD0uThVB mtQYZuxTiNe78x3kwX2NE/AOKbNCmOUbnsiWoyCuWQAafObgPwq2lgUL0k5yykbHVmuO8vbDxen/lAILWvrJwa1TRkgkJnwR4BNBf1jkM50UbdjNSQVmI0zaAhvfhMrvLvBsCQTt6XpKGk1tvc7gND1dZP8RuAeHcusqF0h3pQ3QgDBQ= 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 compability. Signed-off-by: Oscar Salvador --- arch/sparc/kernel/sys_sparc_32.c | 17 +++++++++++---- arch/sparc/kernel/sys_sparc_64.c | 37 +++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c index 08a19727795c..852b340a7f9b 100644 --- a/arch/sparc/kernel/sys_sparc_32.c +++ b/arch/sparc/kernel/sys_sparc_32.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -42,12 +43,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 +67,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..1b271db41542 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -87,6 +88,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 +105,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 +126,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 +144,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 +170,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 +192,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 +212,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); /*