From patchwork Wed Jul 10 10:50:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13729170 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 E8426C41513 for ; Wed, 10 Jul 2024 10:51:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF6C56B009C; Wed, 10 Jul 2024 06:51:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CA4B86B009D; Wed, 10 Jul 2024 06:51:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF5076B009E; Wed, 10 Jul 2024 06:51:27 -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 8AF476B009C for ; Wed, 10 Jul 2024 06:51:27 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3DEDAA29E2 for ; Wed, 10 Jul 2024 10:51:27 +0000 (UTC) X-FDA: 82323526614.07.0A35C73 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf03.hostedemail.com (Postfix) with ESMTP id 402E020006 for ; Wed, 10 Jul 2024 10:51:24 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf03.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720608659; a=rsa-sha256; cv=none; b=COdCTzCRI+TGeH66vaBiZB4xSrHsGw7Zy1BJ9MM8R3ZBsz3K/kM2IJ9Dzj0V44SfOZC8W1 Qh0edU9ZQJRgWh3u/2NXRzYnRwtnBdOjNZBCD8PO8YTKZw93O9NS61gVfc+C3wWtAGk6QY gVHyXUt7A2ADuApG5tZObuG+PM75zog= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf03.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720608659; 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=XSQhKhxsB8mJo06ul8PeKZx+ybzEA5hBxV4gU2MOqSA=; b=lZ1RGS2oaAXzNkPcPkon393BW9vNjGhnYzN338yTKLtkBFy+lzU5ANq7Y6poqGyTP4IbGw fKJlxuggBPh09kZrTmSTle/EmcriMQp/uatDZkADWrKTuEM6fx0En92w7zb47Ep60XZuuT M2B5gUSeD4korSCDwzHMt32k52nifrc= 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 D223A21A3D; Wed, 10 Jul 2024 10:51:23 +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 C8C571369A; Wed, 10 Jul 2024 10:51:22 +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 gMnALKpnjmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:22 +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 1/8] mm/mmap: Teach generic_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Wed, 10 Jul 2024 12:50:35 +0200 Message-ID: <20240710105042.30165-2-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-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 402E020006 X-Stat-Signature: 4hjybegrxrfnw1deytuzzqisguyf37un X-Rspam-User: X-HE-Tag: 1720608684-156361 X-HE-Meta: U2FsdGVkX1+O/Po1iCi2ygkl+9qNWmHoqHjwbuIIEcfh12rZNcsI+b3GUq4xBnQNMWe9I9YdwepX4+W7OR5MI47d2vSKou9mrPGbL5w+Rm+yIF2HFIH/VHmfktR5bOiJ/XDzm7zd36Wclasm/4JxVZg8ibA+N1kBioFVxEJ4x8rBEoKQffcCLdAhuaxnYZ51a1NbTHf08JC7tDrpBUhhNOKsGTrU85eMD23rcB/Wx/fhFOkacCkbxRX0vhAmBSKWG4ixq6z9VUtteJkg304O9NVug+YlS2r6pQo+ezt+00XLg8aKpMwBJeNg4omwaUW+nV9hu7sQDtVeAIlm9XO25xFxdbm8gzNObz4itDN02EgloNiz3I/TMsROp+dEx/SucN4aJgJLfUPj6ZwAKTXzlent1xiNOHwBtD/Fpbn7WxBUnwxP3o7lMjYJBNjWfPO0U9kmwXBbwsH0b0V4TjABBpIOvgGO4nLpF0U/Ck77VLjx1YWZY3/b65nxQRDhrqsDs33YPeLM00e4mPd/0HpmAXs5OQwIVrhWzHUNKwDVqpkAJ50IdcmkBIbkNw03jRtJOA6AJbf5qP4Ql2tYUlfiqNWusdlNEQVm/H1DwCFYULalLWspxZOS/gwwUI7jajX0gptTcapJmzYlODN0EBqW0MiiQ7SOqoWMX9E42DZJDfMFayUxHaJRmLRI4hDhXoneDmGA4ERb3VdXk3hCzmA2YIbidwYI+xnKXPA0t591Mv1XZzVL0CpEHqwhK+C8FAI6OXbxAKRqEYjDV5Qdq54EzaqRP5h4lvaZDgFvUXKMJmhwQSQJ8LPeqit0eL+O8iilUVzGGnnJ372CIu1BhjFqkcvE7b9hWBaWWpTnv+ikylnnI2mIua1uyL987DbrMYdKTh5tXgyYRsRecV6V3ENO6wEk6GQtSlXQfrG1ZT/5HGh04GvQs/lapJDFW2LgpNKDKip0EWYnodUimimjbhE bM9gyjrt IlsYbVLDokBLTFONFIwtg/ZisyVrpUrRxQn85SRchlu6x+uRQgu53Loh9muPbgXZsR8vfZGFJkIX4JUhQFZdgZbHlNqsA6BXyuTnOWlEfL+zbh/AVKfmhGqPXwfMwl1OyTZH0WzJZSiZtQZBHguMgx4U476nSX/1weVBL7jZ4wh8EHQQ= 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 generic_get_unmapped_area{_topdown} to handle those. The main difference is that we set info.align_mask for huge mappings. Signed-off-by: Oscar Salvador --- include/linux/hugetlb.h | 10 ++++++++++ mm/mmap.c | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 2b3c3a404769..1c7b0b32ff7e 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -1029,9 +1029,19 @@ void hugetlb_unregister_node(struct node *node); */ bool is_raw_hwpoison_page_in_hugepage(struct page *page); +static inline unsigned long huge_page_mask_align(struct file *file) +{ + return PAGE_MASK & ~huge_page_mask(hstate_file(file)); +} + #else /* CONFIG_HUGETLB_PAGE */ struct hstate {}; +static inline unsigned long huge_page_mask_align(struct file *file) +{ + return 0; +} + static inline struct hugepage_subpool *hugetlb_folio_subpool(struct folio *folio) { return NULL; diff --git a/mm/mmap.c b/mm/mmap.c index 83b4682ec85c..09131b705e7b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1743,6 +1743,8 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr, info.length = len; info.low_limit = mm->mmap_base; info.high_limit = mmap_end; + if (filp && is_file_hugepages(filp)) + info.align_mask = huge_page_mask_align(filp); return vm_unmapped_area(&info); } @@ -1791,6 +1793,8 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr, info.length = len; info.low_limit = PAGE_SIZE; info.high_limit = arch_get_mmap_base(addr, mm->mmap_base); + if (filp && is_file_hugepages(filp)) + info.align_mask = huge_page_mask_align(filp); addr = vm_unmapped_area(&info); /* From patchwork Wed Jul 10 10:50:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13729171 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 0D61AC3DA49 for ; Wed, 10 Jul 2024 10:51:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61A056B009E; Wed, 10 Jul 2024 06:51:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A1556B009F; Wed, 10 Jul 2024 06:51:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F15D6B00A0; Wed, 10 Jul 2024 06:51:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1AC526B009E for ; Wed, 10 Jul 2024 06:51:29 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A33AF817D8 for ; Wed, 10 Jul 2024 10:51:28 +0000 (UTC) X-FDA: 82323526656.23.21F0D79 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf25.hostedemail.com (Postfix) with ESMTP id 80DD1A000A for ; Wed, 10 Jul 2024 10:51:26 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=vWma3QMm; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="hdePWM/l"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=vWma3QMm; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="hdePWM/l"; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf25.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720608661; a=rsa-sha256; cv=none; b=yLSGlZ/Kv2nxlQ3hdr/SYJUeK7WYUDTGXNBhwnHefBua3ZWNXKXPdzH2TYs2+tikeHqpHY Hq3iqrDaRlYJMeUbpuEdDwdvVPjIUxkKNx7iZbvTTFt8Dl94K2Qw+omY6QTiWmusTWDwXD qA0SIkuAaAc/a/p6RB/89Zl1QGAEZ18= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=vWma3QMm; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="hdePWM/l"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=vWma3QMm; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="hdePWM/l"; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf25.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720608661; 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=MiX8eoexrmO/wjIpeeQ9glTEYeXiTS6tsv5T+BPJcGU=; b=zqBXEJhN4Zj2xBZBolBfnLQmRZIbFLxAC53mYLmG4czroUcpQEhxcxvBP9myXwXklLWqho kQO8lSEtfnk8rMSAoyJFw8gOgUpEk1M2AbMbXVL2WAQBUzO92E3d3Yh+nQYLi8oY6eS4xI t0RniS4T/gsNho0Shk8XsfGJ96yOWF0= 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-out2.suse.de (Postfix) with ESMTPS id 364F61F824; Wed, 10 Jul 2024 10:51:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608685; 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=MiX8eoexrmO/wjIpeeQ9glTEYeXiTS6tsv5T+BPJcGU=; b=vWma3QMmGeWRXJcr6gHXAh51UbyOC3/rO+Nxlq+dJJq+R+LMUKQD3tP2toFmn9IH4RsdtW XWOaFAZBQ7XWMwl6sf/zBMjtQlSOg7hRWPqODWwGD2lRvpSkFQGFg66rLqG3gJUQS7WeWN 5Sh9v+CKdJQ93f4u5gZe257D5HEOWzA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608685; 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=MiX8eoexrmO/wjIpeeQ9glTEYeXiTS6tsv5T+BPJcGU=; b=hdePWM/lQgzDbtl3y1qRTw5AcA/nnPR2xCuLciXlwjGsJ8dQFNayVGStGn0kpjV3Z5iagx rWKWfsL4/uk4quCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608685; 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=MiX8eoexrmO/wjIpeeQ9glTEYeXiTS6tsv5T+BPJcGU=; b=vWma3QMmGeWRXJcr6gHXAh51UbyOC3/rO+Nxlq+dJJq+R+LMUKQD3tP2toFmn9IH4RsdtW XWOaFAZBQ7XWMwl6sf/zBMjtQlSOg7hRWPqODWwGD2lRvpSkFQGFg66rLqG3gJUQS7WeWN 5Sh9v+CKdJQ93f4u5gZe257D5HEOWzA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608685; 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=MiX8eoexrmO/wjIpeeQ9glTEYeXiTS6tsv5T+BPJcGU=; b=hdePWM/lQgzDbtl3y1qRTw5AcA/nnPR2xCuLciXlwjGsJ8dQFNayVGStGn0kpjV3Z5iagx rWKWfsL4/uk4quCQ== 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 0BB471369A; Wed, 10 Jul 2024 10:51:23 +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 uIvoN6tnjmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:23 +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 2/8] arch/s390: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Wed, 10 Jul 2024 12:50:36 +0200 Message-ID: <20240710105042.30165-3-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-Server: rspam12 X-Rspamd-Queue-Id: 80DD1A000A X-Stat-Signature: kjff4m8cj7w85tgsofq6si9kgpm4rzcm X-Rspam-User: X-HE-Tag: 1720608686-280706 X-HE-Meta: U2FsdGVkX1/nLpa5tnVrtLG505/50KC6/mg+bYwkfTdDr9XLtYcndEzXtD4UldPNqY/OCEohqQUoBy3MFLLItvemEImClsHvZkU5HrcI1isuwfaUH5YKbWN0J6g+YvWTogO/xx49ifqIk2ZF4P0PYYwADoPrmJipnWX/kA0O8mEccEZptSXNSaWfd1iT/xcgKZ8bkrWattnl3pP9TKxQnw3X7M3fI5C8DFyU0WDfB/HNqVVBeNtDE6JMFV59XGHX3h3rkVE2njYF4LLmd46xt3kT5lsYfL2TJUbXaAhDc4GLd6AkOX8Fki8020r2ohS4OeuXAVQ6oorBLHKBwR7C8hdJ1N27o8W1WaJHOv5QohLBNXWvbCZT1bnawvyrPVk/JVrDDQEG5XaeE6u61Jbemv5x0KJJkPv1oFQ3JHHvd1dxcy6h4Pf2d0+5GX060eFcmzpuUz8PV7AaZhFD2+dS+dBU/bqqj4pPWtgTZODi7zIiIJI3uPWU/SVmhfiK3vNUy26K2dCyRzgcNFDOmDlIFZBkpRy1GjwCgdJkOOPadZecQxC8+p50t8UhFEE+KbrsKPj9U0z/CM/bAqSMwoo3Wk5j1Y9U+rInbfggu2PnF1nPErn8+Of27hD5Xt4iCvkSWOUAU6zgzI0iUev+0je/ehvDQjbd+NpHDtoWS8AGuLJPWHaJcc0gh2oNxRgWjCjRc1i9Q6+yUZ6Zgo5zXkhQL4fv8zFz08Ulvf9jX5/2DRAtZ2CD1jPllUpzkQ5u7YR2HrQjtxq4Y0z2Z6IImzfK9/tJX7YlJQIubMYzUgssO5L0mPJB717+swojXGi4Dc3S32xDARvALEXdFtB3SVU8EP6DcQI2izbF17qWpI89XtDasA2TXA0vlaVyIPe8T5mV47+qVanaLb8Vce7BdNLD9o1ZKGgVjtVx5pa27rzrtSnDzVzhMdIfxYcXI+Cj3ZOu/FjT9qW1s2mQguX3EEi 6ILXm58i k0/2fwpVGU20fJkXVP2KaRgaj1XWI59dqm/wrIm1boKHK0+6kh2j60r2kdSuEt8gW2GstZMeCuI14WZ+4/71aqmdG2TiLZtoWMrRCeKA34KYksUNZyS9c2QRcPIf4o9/dWCRSeI1ozsJYuza3GQKf9sneXOFKTwggyOBobYMS6XRHmfgrD63XvprtlnCY9juSgU1Qymeph5eikcGxzjrlPePq9tj4pNgjifRcl98Z3CUNRha/bTYj5NYTGxE5I8Pt5qOMgmcwfBkr6vOIrioa+jA5BcWf2X/vU91Y 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. s390 specific hugetlb function does not set info.align_offset, so do the same here for compatibility. Signed-off-by: Oscar Salvador --- arch/s390/mm/mmap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c index 206756946589..e98c00df586f 100644 --- a/arch/s390/mm/mmap.c +++ b/arch/s390/mm/mmap.c @@ -73,6 +73,8 @@ static inline unsigned long mmap_base(unsigned long rnd, static int get_align_mask(struct file *filp, unsigned long flags) { + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); if (!(current->flags & PF_RANDOMIZE)) return 0; if (filp || (flags & MAP_SHARED)) @@ -106,7 +108,8 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, info.low_limit = mm->mmap_base; info.high_limit = TASK_SIZE; info.align_mask = get_align_mask(filp, flags); - info.align_offset = pgoff << PAGE_SHIFT; + if (!(file && is_file_hugepages(filp)) + info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); if (offset_in_page(addr)) return addr; @@ -144,7 +147,8 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, unsigned long ad info.low_limit = PAGE_SIZE; info.high_limit = mm->mmap_base; info.align_mask = get_align_mask(filp, flags); - info.align_offset = pgoff << PAGE_SHIFT; + if (!(file && is_file_hugepages(filp)) + info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); /* 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); 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); /* From patchwork Wed Jul 10 10:50:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13729174 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 65EF5C3DA42 for ; Wed, 10 Jul 2024 10:51:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D1346B00A0; Wed, 10 Jul 2024 06:51:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 15C756B00A2; Wed, 10 Jul 2024 06:51:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA3FD6B00A3; Wed, 10 Jul 2024 06:51:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C360A6B00A0 for ; Wed, 10 Jul 2024 06:51:32 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 755A8141C0F for ; Wed, 10 Jul 2024 10:51:32 +0000 (UTC) X-FDA: 82323526824.03.05BB5BE Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf02.hostedemail.com (Postfix) with ESMTP id 5405880012 for ; Wed, 10 Jul 2024 10:51:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="o/R9ZuDL"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Wx7vnkPn; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="o/R9ZuDL"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Wx7vnkPn; spf=pass (imf02.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=1720608659; 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=4aP7LJidVwaEiyg2vEhcsAqZZw1DICdTCoxEateoTEY=; b=ThdS9pourtQ6RwZuVlQJppgyvS0ogoyLUDr0zDuBrQncevr0eV5JN5Iy6aDo0pPSy4kWlp iMDVe3K0b9bgBWUbCIIEZ4ZoKVKeJDybZxgZ/4mzTBySLg/eHyL9S3rXqQrsTeXjEBRqr8 XqYGO5EhD2pPySl4G29yXkjBSxUw1QE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720608659; a=rsa-sha256; cv=none; b=SFck6e25CqEfL4ZeIBN0eFXZZm/E/Kx/LtFe35HgQMuzVq3XK3N0BcsZUDx7Ya0vqF0zJy IWIF/Numtn+L9TpWomw/Ux8q/nQyPje6BVaqcSEaWlMnKbLAaOx3sIC4m2S8szgivWHnwc CdYpRBFEZQkNvXy1U38NoCK4hfGEbUA= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="o/R9ZuDL"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Wx7vnkPn; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="o/R9ZuDL"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Wx7vnkPn; spf=pass (imf02.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 (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 0C7AA21A33; Wed, 10 Jul 2024 10:51:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608689; 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=4aP7LJidVwaEiyg2vEhcsAqZZw1DICdTCoxEateoTEY=; b=o/R9ZuDLTBFAeen3OTEvbuoQTG+0ttv6ilWicNUQx0VjjRe1d2Up3cp0/8+x3YfBH2uMnf JKDJhaY0AY4YzLPDKX0j1rcmcrJuf+OVuHyMr7/IGf2LIZ6jvsCqW7o7whTOLS2nT2d4NR NEI1eQn7lkOnn83FIhhH1NzCWEkh8qk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608689; 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=4aP7LJidVwaEiyg2vEhcsAqZZw1DICdTCoxEateoTEY=; b=Wx7vnkPnXLV89jq+HQkZWLMRhtuwOGjeItAZ0ibHsDgzQXaXRZmCXRBtyVOtI1O92c951J mfyReADNVpXDpSDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608689; 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=4aP7LJidVwaEiyg2vEhcsAqZZw1DICdTCoxEateoTEY=; b=o/R9ZuDLTBFAeen3OTEvbuoQTG+0ttv6ilWicNUQx0VjjRe1d2Up3cp0/8+x3YfBH2uMnf JKDJhaY0AY4YzLPDKX0j1rcmcrJuf+OVuHyMr7/IGf2LIZ6jvsCqW7o7whTOLS2nT2d4NR NEI1eQn7lkOnn83FIhhH1NzCWEkh8qk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608689; 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=4aP7LJidVwaEiyg2vEhcsAqZZw1DICdTCoxEateoTEY=; b=Wx7vnkPnXLV89jq+HQkZWLMRhtuwOGjeItAZ0ibHsDgzQXaXRZmCXRBtyVOtI1O92c951J mfyReADNVpXDpSDA== 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 E57C31369A; Wed, 10 Jul 2024 10:51:27 +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 oPBeM69njmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:27 +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 5/8] arch/powerpc: Teach book3s64 arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Wed, 10 Jul 2024 12:50:39 +0200 Message-ID: <20240710105042.30165-6-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5405880012 X-Stat-Signature: d57tc751btpxps5o38xruot5864ybjww X-HE-Tag: 1720608690-109706 X-HE-Meta: U2FsdGVkX19sRVzUtpzqMqTEofcXkbHIgAc8rlL5pVaOp6uE6IXj/T7aMep/Q/Bu8b8KbN/YO/OUZh5M76OGPnIAG3bi6LVWlqkVVVs681IcjVj5j3OxmkaIWxpZwE+cxsiKyKTM9W3Px8vFNa8H8csMVSG7qjrI3CvwK2NVNcSkE/LIb9ySp26gVrDIhrc94UFcf7H/orDIFT6yLMfd4G+ecARJS82Vghet4zu9tyQp3MgwD7uAg0uwsO1mGwhsk502HIpjZwWnJyISuz1NVed3VvkRVZuLbUIEYvB14s+GzoEPwZMDeFOlJMnNf+L2EgUJw4bJrCScU/yCks4XEFO9OXWKxxxgXv3DE+yzapNFMfFCv0DKcfpVgcAu17yf2aKA/8XEvxrLj0XGx7Pl55Ai3Amds1r7waToF8P/p50cYsy+/rPHSIBApKmqiYJdY0dwIvh1GFusyKRau7pOK/2iSPySuFvX8aMe/i8obaBoiYJ15j0vI58Wprs5SHheAE1/3UHLQ/wJEvyx698HPwX2nIWzLEpcTxXzLLxu4xvqhzVtQ9VtcS0itHUCaW86uA9RZvhygrPpc/EJNH7gGF7G2WpTeWs48qQy+O7Tq+Tk71DIcgTeQ30saR8zTvR5xDZkU7dXMLSWE1LYuOHH7jkVGr817IOkvXs33ZBadyIqxpuUspglfShJGRXduH3XvldaCiVNrxHPhvPiIeGkJnUI69tAF5GAFPHNJ73mI7hFyayXqH6rb+Eq4MW0IvlPwEfKyiYhPipmNy+qUJ2YwjtTy+z7rgeFHa3ejPaweszlJVLbUVeCciQNoTfEg+/+cQZ9BLnyvRGrG1DTEwCpw+MK1CgbfPcy/HMfo9gLh4W6EjjPu0uLVqhAAOHC0uNEEd0RUwneKZJBpUA1d2ADk2x4nHtjjrWb+9S9DE9YinTOaWBg5wzW96w+0VtKrwLqhgQ1HxELCNVMC/nzsOU 6vPaNZnf jn88NFXzHT8yAykXzOlfTyaV57v+9EpDWReQ3gsr6s8G6ZX+NDadE2HKNkqMHzQMbUhSAMMdpKAJQiZT0bJl0iLffXRvrnfP40uiwLXZf3YgcURk5RJWyrHC1UFlWyHDJ9rFWB4LTUctjVkFL+rFSYg/Ksi2g5qHrx3Cotu+5/ej10elbyg2QTLiyB0bLpqzsHIGL8MzvDtbK+DOeSZ8J0g0Xa2HXOPOCGeEtVV3/TLLwahqRwJv9ntSkJRhJqdz9+AKONh6yvvhjGfclX6hrxcgLo22K0uxtCjfu 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. Reshuffle file_to_psize() definition so arch_get_unmapped_area{_topdown} can make use of it. Signed-off-by: Oscar Salvador --- arch/powerpc/mm/book3s64/slice.c | 39 ++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c index ef3ce37f1bb3..6914b8de627c 100644 --- a/arch/powerpc/mm/book3s64/slice.c +++ b/arch/powerpc/mm/book3s64/slice.c @@ -633,17 +633,36 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len, } EXPORT_SYMBOL_GPL(slice_get_unmapped_area); +#ifdef CONFIG_HUGETLB_PAGE +static int file_to_psize(struct file *file) +{ + struct hstate *hstate = hstate_file(file); + return shift_to_mmu_psize(huge_page_shift(hstate)); +} +#else +static int file_to_psize(struct file *file) +{ + return 0; +} +#endif + unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { + unsigned int psize; + if (radix_enabled()) return generic_get_unmapped_area(filp, addr, len, pgoff, flags); - return slice_get_unmapped_area(addr, len, flags, - mm_ctx_user_psize(¤t->mm->context), 0); + if (filp && is_file_hugepages(filp)) + psize = file_to_psize(filp); + else + psize = mm_ctx_user_psize(¤t->mm->context); + + return slice_get_unmapped_area(addr, len, flags, psize, 0); } unsigned long arch_get_unmapped_area_topdown(struct file *filp, @@ -652,11 +671,17 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, const unsigned long pgoff, const unsigned long flags) { + unsigned int psize; + if (radix_enabled()) return generic_get_unmapped_area_topdown(filp, addr0, len, pgoff, flags); - return slice_get_unmapped_area(addr0, len, flags, - mm_ctx_user_psize(¤t->mm->context), 1); + if (filp && is_file_hugepages(filp)) + psize = file_to_psize(filp); + else + psize = mm_ctx_user_psize(¤t->mm->context); + + return slice_get_unmapped_area(addr0, len, flags, psize, 1); } unsigned int notrace get_slice_psize(struct mm_struct *mm, unsigned long addr) @@ -787,12 +812,6 @@ unsigned long vma_mmu_pagesize(struct vm_area_struct *vma) return 1UL << mmu_psize_to_shift(get_slice_psize(vma->vm_mm, vma->vm_start)); } -static int file_to_psize(struct file *file) -{ - struct hstate *hstate = hstate_file(file); - return shift_to_mmu_psize(huge_page_shift(hstate)); -} - unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) From patchwork Wed Jul 10 10:50:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13729175 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 8F7FFC3DA42 for ; Wed, 10 Jul 2024 10:51:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63EF16B00A2; Wed, 10 Jul 2024 06:51:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 57A846B00A3; Wed, 10 Jul 2024 06:51:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 37C4D6B00A4; Wed, 10 Jul 2024 06:51:34 -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 16AAD6B00A2 for ; Wed, 10 Jul 2024 06:51:34 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C7B3A1C1B15 for ; Wed, 10 Jul 2024 10:51:33 +0000 (UTC) X-FDA: 82323526866.13.D3814A9 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf16.hostedemail.com (Postfix) with ESMTP id 9B92A18001B for ; Wed, 10 Jul 2024 10:51:31 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=fSC1Gv8H; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=bYfs3lDT; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=fSC1Gv8H; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=bYfs3lDT; spf=pass (imf16.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=1720608676; 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=Ph9NUUUfzYdgAX+SWvx0C4X8fQI8fkpyj62wUbkyYlY=; b=o18gCJf8umAA9IWuGJD2vHj0qAGAohpV4xMG0iyUlLvWXA8NzAezdrteUOmsFh86Rgz6hb rpmx/g9TSXxGYYEZVEiEt30I/clTX2XSJ6d5JcFgNtxNX5oGSwpa3I1ZwqQxZkbCWePN1w 9iithzGtNgyaaKsXFLyynQCbvX0oyLg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=fSC1Gv8H; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=bYfs3lDT; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=fSC1Gv8H; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=bYfs3lDT; spf=pass (imf16.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=1720608676; a=rsa-sha256; cv=none; b=XXFHeD64/Cmz31TdRbTeCbkjaCv/nWVT8jujs1fB+9Qigval5U5+8I0595QKoPJ08cS7Td nuVSmaDpT7tdi1xJb7/0h7fuuA1+g6TxTBgr+c4bJdi/VWcD0Sqg0l19bQcyrpACVC9PvC Ic0WRz+U5CL2ndn+Cp42Tw8yWPQKPoY= 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 5224F21BBB; Wed, 10 Jul 2024 10:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608690; 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=Ph9NUUUfzYdgAX+SWvx0C4X8fQI8fkpyj62wUbkyYlY=; b=fSC1Gv8HhwSvd1I/53WmRpPzjVucOsDas8A9DH6+m8UO0/3EcWcAfdBUqvLL3fVYEUdxfT EsPHGkqdoqpAUI+m/WEE1R03tBMUXoqLQQdRlXSPLZsfpwuMQc/78IfuRGhs4gwXuIQApN AHnPUdJV/mCCIE9Jew3Xrz/9bkaVxT0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608690; 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=Ph9NUUUfzYdgAX+SWvx0C4X8fQI8fkpyj62wUbkyYlY=; b=bYfs3lDTbUwBqvuiMOVaLuUilJTPz7MxAdnYxiVBZOgU7ZnrtqSMbRBzsTaiu4XCP4upCW gI+uI2I6ZXW1VZDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608690; 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=Ph9NUUUfzYdgAX+SWvx0C4X8fQI8fkpyj62wUbkyYlY=; b=fSC1Gv8HhwSvd1I/53WmRpPzjVucOsDas8A9DH6+m8UO0/3EcWcAfdBUqvLL3fVYEUdxfT EsPHGkqdoqpAUI+m/WEE1R03tBMUXoqLQQdRlXSPLZsfpwuMQc/78IfuRGhs4gwXuIQApN AHnPUdJV/mCCIE9Jew3Xrz/9bkaVxT0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608690; 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=Ph9NUUUfzYdgAX+SWvx0C4X8fQI8fkpyj62wUbkyYlY=; b=bYfs3lDTbUwBqvuiMOVaLuUilJTPz7MxAdnYxiVBZOgU7ZnrtqSMbRBzsTaiu4XCP4upCW gI+uI2I6ZXW1VZDw== 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 30AA81369A; Wed, 10 Jul 2024 10:51:29 +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 WPJEB7FnjmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:29 +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 6/8] mm: Make hugetlb mappings go through mm_get_unmapped_area_vmflags Date: Wed, 10 Jul 2024 12:50:40 +0200 Message-ID: <20240710105042.30165-7-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-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 9B92A18001B X-Stat-Signature: topuq3rwxhsz5bmqdtmjs4c46ygobpze X-HE-Tag: 1720608691-695205 X-HE-Meta: U2FsdGVkX1+SR/6t/POLT5C1yv+fuQ6vCHtC2HoYrIv52ZTQAm+MwugpaFMHNsQ4UfyB6PqAfusDjib8LT62U1UVJwgiFTXoEfpTRRQ1UpDYfRWH8wT5zW/whexXmbnl/GkXM/rzZZ39gp4RWVPDBbQ463X6QeGHGpRJOS4AVEEHdV3vBI6a1bZjdTD5mpfiVz783yPr4LcrBwhjimLhb6MgxKli2p0WGt8SrxX0LFE3BE4SOmvmeytdgpU2sH4Y16/bVCObIvP47wYXIHrG6vrVEDRR5rNm/9umBZwPkPo7Br4C5bGNJAm0g88KxayoYSt1anlhBWPdNSourKAJjgWkHadGCavf+PIydJlPGIaF7sGmibCdhzFtEWV1h6H0IYUhWzZvyZC2c7fRcmXnaC4zuOlX2+mcrZqI9b3oYjMr+FoR+Z2XLPq0JEXWwhtGDHvFN75u4TZi84vuIvdXBXw+5XMdA17N7f8Hax2VeLL1lcoZFVilIViSVNFY73jqLoiVEW2WplVCo258rqOLExMnKT/0tC8r5DPHbMwc9JPV7r8o4Nk39ZqvzQiM/4YAd2nsKicPqhwAMt/JLbcb+g6f0Qz6emWJ4XxDW/bOSYpS3a6WaLQRXTHbc/BXwGGYCARxTU6HXzyhjywaAiHGoLn8/gLPJtFSWORzsqr7qW5a9qEvZzz5P25srfI8t63+aXYT0Zuzpfgvf042RBPRa6d989+MY980YtG0HG3fjMHJuXAcUte7uqvQ02VTcHMGcCouQ+B3zMzCkS3UdfjKnK6MqnvcK/SyEJmopfN1kFohZL4tLxahcoNKtRKNxZY3FXrfd98A0rBqKBVwq4rTq+JEjFRg804nHo4tEXUm1iM4D00IQ/LIKtQW/NGQqiRNHaGorV64DKkDnmncKYE2K380r66TpP+Cvtf5GgOZ1+hHiuV9qDhwmp6d2We+ekhNrapWSjK6QVQvnKNjxix SZt3wHeq bxMcdMGaYsTANfgGU2frOh2q6UoEn7GKg76xPZjuMRC8sHVdvrLmk5DjW9rH6vranG+GOqYwN/3adjOsUQ6jNpFUpwUF8WP5qzPtHl3P1TtdcMozEKL0YitCBZgaWTq0f5hUsUFZaFwSZLYbCUBlH8/PpD2Q6cnHCiYTyM3GcJoTK9P2JTbGa9WM68sL8gnuw5g+zeBWBrJMYVcFK9uZa2tdcFCeYPSHKwsYoExd/q66SpuWZPnO9VpUjXVX4IrqFKi5XqadL22PinD9g8EEYHleG2Q== 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: Hugetlb mappings will no longer be special cased but rather go through the generic mm_get_unmapped_area_vmflags function. For that to happen, let us remove the .get_unmapped_area from hugetlbfs_file_operations struct, and hint __get_unmapped_area that it should not send hugetlb mappings through thp_get_unmapped_area_vmflags but through mm_get_unmapped_area_vmflags. Create also a function called hugetlb_mmap_check_and_align() where a couple of safety checks are being done and the addr is aligned to the huge page size. Otherwise we will have to do this in every single function, which duplicates quite a lot of code. Signed-off-by: Oscar Salvador --- fs/hugetlbfs/inode.c | 22 ++++++++++++++-------- include/linux/hugetlb.h | 8 +++----- mm/mmap.c | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 412f295acebe..b2d7fcecdb15 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -257,15 +257,22 @@ generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, pgoff, flags); } -#ifndef HAVE_ARCH_HUGETLB_UNMAPPED_AREA -static unsigned long -hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, - unsigned long flags) +unsigned long +hugetlb_mmap_check_and_align(struct file *file, unsigned long addr, + unsigned long len, unsigned long flags) { - return generic_hugetlb_get_unmapped_area(file, addr, len, pgoff, flags); + unsigned long addr0 = 0; + struct hstate *h = hstate_file(file); + + if (len & ~huge_page_mask(h)) + return -EINVAL; + if ((flags & MAP_FIXED) && prepare_hugepage_range(file, addr, len)) + return -EINVAL; + if (addr) + addr0 = ALIGN(addr, huge_page_size(h)); + + return addr0; } -#endif /* * Someone wants to read @bytes from a HWPOISON hugetlb @page from @offset. @@ -1302,7 +1309,6 @@ static const struct file_operations hugetlbfs_file_operations = { .read_iter = hugetlbfs_read_iter, .mmap = hugetlbfs_file_mmap, .fsync = noop_fsync, - .get_unmapped_area = hugetlb_get_unmapped_area, .llseek = default_llseek, .fallocate = hugetlbfs_fallocate, .fop_flags = FOP_HUGE_PAGES, diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 1c7b0b32ff7e..9183ef95dfb6 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -555,11 +555,9 @@ static inline struct hstate *hstate_inode(struct inode *i) } #endif /* !CONFIG_HUGETLBFS */ -#ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA -unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, - unsigned long flags); -#endif /* HAVE_ARCH_HUGETLB_UNMAPPED_AREA */ +unsigned long +hugetlb_mmap_check_and_align(struct file *file, unsigned long addr, + unsigned long len, unsigned long flags); unsigned long generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, diff --git a/mm/mmap.c b/mm/mmap.c index 09131b705e7b..8130b25b8cf5 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1860,6 +1860,7 @@ __get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long, unsigned long, unsigned long) = NULL; + bool is_hugetlb = false; unsigned long error = arch_mmap_check(addr, len, flags); if (error) return error; @@ -1868,6 +1869,9 @@ __get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, if (len > TASK_SIZE) return -ENOMEM; + if (file && is_file_hugepages(file)) + is_hugetlb = true; + if (file) { if (file->f_op->get_unmapped_area) get_area = file->f_op->get_unmapped_area; @@ -1885,11 +1889,20 @@ __get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, if (get_area) { addr = get_area(file, addr, len, pgoff, flags); - } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { + } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && !is_hugetlb) { /* Ensures that larger anonymous mappings are THP aligned. */ addr = thp_get_unmapped_area_vmflags(file, addr, len, pgoff, flags, vm_flags); } else { + /* + * Consolidate hugepages checks in one place, and also align addr + * to hugepage size. + */ + if (is_hugetlb) { + addr = hugetlb_mmap_check_and_align(file, addr, len, flags); + if (IS_ERR_VALUE(addr)) + return addr; + } addr = mm_get_unmapped_area_vmflags(current->mm, file, addr, len, pgoff, flags, vm_flags); } From patchwork Wed Jul 10 10:50:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13729176 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 79953C3DA42 for ; Wed, 10 Jul 2024 10:51:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA2486B00A4; Wed, 10 Jul 2024 06:51:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E05D16B00A5; Wed, 10 Jul 2024 06:51:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C09BE6B00A6; Wed, 10 Jul 2024 06:51:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 977A86B00A4 for ; Wed, 10 Jul 2024 06:51:35 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1BF7DC1CDC for ; Wed, 10 Jul 2024 10:51:35 +0000 (UTC) X-FDA: 82323526950.26.0E1681E Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf28.hostedemail.com (Postfix) with ESMTP id EB88CC0009 for ; Wed, 10 Jul 2024 10:51:32 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="dGsZpU/t"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=VIwwW1oL; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="dGsZpU/t"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=VIwwW1oL; spf=pass (imf28.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=1720608651; 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=5n8Jhuz8lWIN9hi2PwsThD9v5LavYKY6GCrzf/ZoXlA=; b=lS+BvwWqlht7MrHc9p4OdcVcXLUQPZLJEtFp4iKDteNxa002rQr8kdpVxXRLnJ+oAclCrH iop2qG72paoTm4EIw0eCyl+n2C/pSgvXPd2zbBQEXQVwge2U/J+32X98J5Q0qt4qFYm61p wZ+yUv03yjBdyWleRWufa3CEJMIrZPk= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="dGsZpU/t"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=VIwwW1oL; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="dGsZpU/t"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=VIwwW1oL; spf=pass (imf28.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=1720608651; a=rsa-sha256; cv=none; b=ajC4rbfnPH0jZ1KZA2Wo1QWQrgOQCjZz/SWUElInOur+We5J9Oj8hCrAiBtOUU9dYmyxk0 RoZ7c05Qece2Qbphn5ScegCDOI/kEJpU/hploMwPpCm/zuVKhB2YDjiKUDLF5ZZ/HgNQyh Ncd2szYzi64vD9QXxug15EaGKF27cUc= 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-out2.suse.de (Postfix) with ESMTPS id A47B81F82B; Wed, 10 Jul 2024 10:51:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608691; 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=5n8Jhuz8lWIN9hi2PwsThD9v5LavYKY6GCrzf/ZoXlA=; b=dGsZpU/tz1+fvxvfGpa3cGh389hlkHQ6dSvpeneXvhw6WVRuEAIEL9o9rT52wdC7LZANb8 5GFzvyX2srGEHJdndQfKEAF+5gkHu3MYr2nnYOEsK4E/YiDhJWfLxzj1R0J2xnt8NfmrBK mIG4BrzYMHY4XOvPM8muA1DqeIvFq/A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608691; 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=5n8Jhuz8lWIN9hi2PwsThD9v5LavYKY6GCrzf/ZoXlA=; b=VIwwW1oLPNUAbCMDKJGfhY2VH1eT8Suu+ZoE0N2I2GRMz6DjnM5cB0TI4ZwFU5CD1vwOW+ 8+lLsAXLyTGzvzDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608691; 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=5n8Jhuz8lWIN9hi2PwsThD9v5LavYKY6GCrzf/ZoXlA=; b=dGsZpU/tz1+fvxvfGpa3cGh389hlkHQ6dSvpeneXvhw6WVRuEAIEL9o9rT52wdC7LZANb8 5GFzvyX2srGEHJdndQfKEAF+5gkHu3MYr2nnYOEsK4E/YiDhJWfLxzj1R0J2xnt8NfmrBK mIG4BrzYMHY4XOvPM8muA1DqeIvFq/A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608691; 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=5n8Jhuz8lWIN9hi2PwsThD9v5LavYKY6GCrzf/ZoXlA=; b=VIwwW1oLPNUAbCMDKJGfhY2VH1eT8Suu+ZoE0N2I2GRMz6DjnM5cB0TI4ZwFU5CD1vwOW+ 8+lLsAXLyTGzvzDA== 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 75D621369A; Wed, 10 Jul 2024 10:51:30 +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 0H5rGLJnjmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:30 +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 7/8] mm: Drop hugetlb_get_unmapped_area{_*} functions Date: Wed, 10 Jul 2024 12:50:41 +0200 Message-ID: <20240710105042.30165-8-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-Server: rspam06 X-Rspamd-Queue-Id: EB88CC0009 X-Stat-Signature: j7co649mnmdphh55u4ad9f37qdnszfgo X-Rspam-User: X-HE-Tag: 1720608692-367380 X-HE-Meta: U2FsdGVkX1/CdLxXsg0h9W1OZMpe9LVEsC/+Npf2KpiruBCJuD2klueFBT06XxL1n/kiq0mTmk/VQbH6EM0Jx7hh4R2L8td2HBB7wZSUqVUOGxM5EEbOXErXUvkWNaubZJCc7OFVH7aNF0T9RfJ7VzVLadlf9+yKEkODQC3ELATzGC8kctRKbRus+o0ubsr51Jcpp4gv26hGaxjUNwpqzK3F0H1+Lbzizv7o0Ac3n9qrHRGOswddCTdDFuaxNmiYk+/SzMAHuEolBVM5YPPNQ3nlk3AGx4de+hHCV7sg+B6W5UKweCbtlqhVZjP4AXfEsn/tetsgAGZEo3ZwEN55459kJ3D0rMPuMqcjXqo7ryFRi2PYazRyJGWin6wXnwIfsUlT53xWSUuWpP7xI8KoefDvNHfl8UsMqUlJWBLfXiZ1JIrwACKFb0op7oU2172wLTI6JqiyYVNg3CLTZdw3Hhu+MZY/vQZpymAUpLzcN2EVGwBrIWApLBrf5AQvnEtgqe0oPACPcy0wVxlYR/xl5EU6R34CBYXD1hgtlKYg3SolHKS2X7gBrEdGrRTN7VrouiQKjJCKsGG43bhCGVVpK5t7AjCHv8sCeN0nLyushuDukqOijAL8/Evs/FTLlwaegad481Otw03mKeg5SKrKGjfwuhBaf+AlCczb9nKxAz4YNbVMztebKYmRIZb7IMYeOSrwMlZsyEhDriOdNL+JWw3NowcVhEXk5vO6SFDKfdH63KEDVZ+/4eeUPu5ljPpcE9koq7uvkHcV8Juj8Mx/akWh74WlPyGr0yxXqfoejogH3U2tSmYSNANLeDfQzJ5Qc42u6uSNg68xmg6XryERYiL96j4h+7TuahdtnietoiD6ISqEbzbEzUmOmYvK2tGN7q6v6Qwrn51ivL3pt2798BaNJ3NhsqZJNa7ooiL9h4oDw+cyh1C+/nn7+HHCKolnciacn7HtnAaiiDygDsE LuhuvaL5 iy+qZ604Dbwahidm+ITPY4iS+fMYRFW1D709hUa5hv2zHZAz8NZQF8JIy1XUVx1eaYgZHaCmndfZhDW6cdcMe8S33e1rEoni1ZASEwAVq9zoS5LnKpKMeepPKSrj23RHc9sajCXAVvcSofCihJbvgQAbcqqgU8LXbz7djG4FWjHHwhdwhAG3MgxM2BNKfD0XEtw/HrSsyzUDWQgX9f2+i01pAqAY3eV5/UXFVEYkllUaWtRGzPGDd49Z/17GEzwlRY2ls1Q3VDSK4hp0xQFIZNNiBDg== 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: Hugetlb mappings are now handled through normal channels just like any other mapping, so we no longer need hugetlb_get_unmapped_area* specific functions. Signed-off-by: Oscar Salvador --- arch/parisc/mm/hugetlbpage.c | 23 ------- arch/powerpc/mm/book3s64/slice.c | 10 --- arch/s390/mm/hugetlbpage.c | 84 ------------------------ arch/sparc/mm/hugetlbpage.c | 108 ------------------------------- arch/x86/mm/hugetlbpage.c | 100 ---------------------------- fs/hugetlbfs/inode.c | 86 ------------------------ include/linux/hugetlb.h | 5 -- 7 files changed, 416 deletions(-) diff --git a/arch/parisc/mm/hugetlbpage.c b/arch/parisc/mm/hugetlbpage.c index 0356199bd9e7..69c463d6ffd6 100644 --- a/arch/parisc/mm/hugetlbpage.c +++ b/arch/parisc/mm/hugetlbpage.c @@ -21,29 +21,6 @@ #include -unsigned long -hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (len > TASK_SIZE) - return -ENOMEM; - - if (flags & MAP_FIXED) - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - - if (addr) - addr = ALIGN(addr, huge_page_size(h)); - - /* we need to make sure the colouring is OK */ - return arch_get_unmapped_area(file, addr, len, pgoff, flags); -} - - pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long addr, unsigned long sz) { diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c index 6914b8de627c..6ce16bc330a2 100644 --- a/arch/powerpc/mm/book3s64/slice.c +++ b/arch/powerpc/mm/book3s64/slice.c @@ -811,14 +811,4 @@ unsigned long vma_mmu_pagesize(struct vm_area_struct *vma) return 1UL << mmu_psize_to_shift(get_slice_psize(vma->vm_mm, vma->vm_start)); } - -unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, - unsigned long flags) -{ - if (radix_enabled()) - return generic_hugetlb_get_unmapped_area(file, addr, len, pgoff, flags); - - return slice_get_unmapped_area(addr, len, flags, file_to_psize(file), 1); -} #endif diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c index 2675aab4acc7..e8d91428f3d1 100644 --- a/arch/s390/mm/hugetlbpage.c +++ b/arch/s390/mm/hugetlbpage.c @@ -243,87 +243,3 @@ bool __init arch_hugetlb_valid_size(unsigned long size) return false; } -static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file, - unsigned long addr, unsigned long len, - unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info = {}; - - info.length = len; - info.low_limit = current->mm->mmap_base; - info.high_limit = TASK_SIZE; - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - return vm_unmapped_area(&info); -} - -static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file, - unsigned long addr0, unsigned long len, - unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info = {}; - unsigned long addr; - - info.flags = VM_UNMAPPED_AREA_TOPDOWN; - info.length = len; - info.low_limit = PAGE_SIZE; - info.high_limit = current->mm->mmap_base; - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - addr = vm_unmapped_area(&info); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - if (addr & ~PAGE_MASK) { - VM_BUG_ON(addr != -ENOMEM); - info.flags = 0; - info.low_limit = TASK_UNMAPPED_BASE; - info.high_limit = TASK_SIZE; - addr = vm_unmapped_area(&info); - } - - return addr; -} - -unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (len > TASK_SIZE - mmap_min_addr) - return -ENOMEM; - - if (flags & MAP_FIXED) { - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - goto check_asce_limit; - } - - if (addr) { - addr = ALIGN(addr, huge_page_size(h)); - vma = find_vma(mm, addr); - if (TASK_SIZE - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma))) - goto check_asce_limit; - } - - if (!test_bit(MMF_TOPDOWN, &mm->flags)) - addr = hugetlb_get_unmapped_area_bottomup(file, addr, len, - pgoff, flags); - else - addr = hugetlb_get_unmapped_area_topdown(file, addr, len, - pgoff, flags); - if (offset_in_page(addr)) - return addr; - -check_asce_limit: - return check_asce_limit(mm, addr, len); -} diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c index cc91ca7a1e18..eee601a0d2cf 100644 --- a/arch/sparc/mm/hugetlbpage.c +++ b/arch/sparc/mm/hugetlbpage.c @@ -19,114 +19,6 @@ #include #include -/* Slightly simplified from the non-hugepage variant because by - * definition we don't have to worry about any page coloring stuff - */ - -static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp, - unsigned long addr, - unsigned long len, - unsigned long pgoff, - unsigned long flags) -{ - struct hstate *h = hstate_file(filp); - unsigned long task_size = TASK_SIZE; - struct vm_unmapped_area_info info = {}; - - if (test_thread_flag(TIF_32BIT)) - task_size = STACK_TOP32; - - info.length = len; - info.low_limit = TASK_UNMAPPED_BASE; - info.high_limit = min(task_size, VA_EXCLUDE_START); - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - addr = vm_unmapped_area(&info); - - if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) { - VM_BUG_ON(addr != -ENOMEM); - info.low_limit = VA_EXCLUDE_END; - info.high_limit = task_size; - addr = vm_unmapped_area(&info); - } - - return addr; -} - -static unsigned long -hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, - const unsigned long len, - const unsigned long pgoff, - const unsigned long flags) -{ - struct hstate *h = hstate_file(filp); - struct mm_struct *mm = current->mm; - unsigned long addr = addr0; - struct vm_unmapped_area_info info = {}; - - /* This should only ever run for 32-bit processes. */ - BUG_ON(!test_thread_flag(TIF_32BIT)); - - info.flags = VM_UNMAPPED_AREA_TOPDOWN; - info.length = len; - info.low_limit = PAGE_SIZE; - info.high_limit = mm->mmap_base; - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - addr = vm_unmapped_area(&info); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - if (addr & ~PAGE_MASK) { - VM_BUG_ON(addr != -ENOMEM); - info.flags = 0; - info.low_limit = TASK_UNMAPPED_BASE; - info.high_limit = STACK_TOP32; - addr = vm_unmapped_area(&info); - } - - return addr; -} - -unsigned long -hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - unsigned long task_size = TASK_SIZE; - - if (test_thread_flag(TIF_32BIT)) - task_size = STACK_TOP32; - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (len > task_size) - return -ENOMEM; - - if (flags & MAP_FIXED) { - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - return addr; - } - - if (addr) { - addr = ALIGN(addr, huge_page_size(h)); - vma = find_vma(mm, addr); - if (task_size - len >= addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } - if (!test_bit(MMF_TOPDOWN, &mm->flags)) - return hugetlb_get_unmapped_area_bottomup(file, addr, len, - pgoff, flags); - else - return hugetlb_get_unmapped_area_topdown(file, addr, len, - pgoff, flags); -} static pte_t sun4u_hugepage_shift_to_tte(pte_t entry, unsigned int shift) { diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c index 807a5859a3c4..e0c03fe3a994 100644 --- a/arch/x86/mm/hugetlbpage.c +++ b/arch/x86/mm/hugetlbpage.c @@ -19,107 +19,7 @@ #include #include -#ifdef CONFIG_HUGETLB_PAGE -static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file, - unsigned long addr, unsigned long len, - unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info = {}; - - info.length = len; - info.low_limit = get_mmap_base(1); - - /* - * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area - * in the full address space. - */ - info.high_limit = in_32bit_syscall() ? - task_size_32bit() : task_size_64bit(addr > DEFAULT_MAP_WINDOW); - - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - return vm_unmapped_area(&info); -} - -static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file, - unsigned long addr, unsigned long len, - unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info = {}; - - info.flags = VM_UNMAPPED_AREA_TOPDOWN; - info.length = len; - info.low_limit = PAGE_SIZE; - info.high_limit = get_mmap_base(0); - - /* - * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area - * in the full address space. - */ - if (addr > DEFAULT_MAP_WINDOW && !in_32bit_syscall()) - info.high_limit += TASK_SIZE_MAX - DEFAULT_MAP_WINDOW; - - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - addr = vm_unmapped_area(&info); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - if (addr & ~PAGE_MASK) { - VM_BUG_ON(addr != -ENOMEM); - info.flags = 0; - info.low_limit = TASK_UNMAPPED_BASE; - info.high_limit = TASK_SIZE_LOW; - addr = vm_unmapped_area(&info); - } - return addr; -} - -unsigned long -hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - - if (len & ~huge_page_mask(h)) - return -EINVAL; - - if (len > TASK_SIZE) - return -ENOMEM; - - /* No address checking. See comment at mmap_address_hint_valid() */ - if (flags & MAP_FIXED) { - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - return addr; - } - - if (addr) { - addr &= huge_page_mask(h); - if (!mmap_address_hint_valid(addr, len)) - goto get_unmapped_area; - - vma = find_vma(mm, addr); - if (!vma || addr + len <= vm_start_gap(vma)) - return addr; - } - -get_unmapped_area: - if (!test_bit(MMF_TOPDOWN, &mm->flags)) - return hugetlb_get_unmapped_area_bottomup(file, addr, len, - pgoff, flags); - else - return hugetlb_get_unmapped_area_topdown(file, addr, len, - pgoff, flags); -} -#endif /* CONFIG_HUGETLB_PAGE */ #ifdef CONFIG_X86_64 bool __init arch_hugetlb_valid_size(unsigned long size) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index b2d7fcecdb15..722e60327615 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -171,92 +171,6 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) * Called under mmap_write_lock(mm). */ -static unsigned long -hugetlb_get_unmapped_area_bottomup(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info = {}; - - info.length = len; - info.low_limit = current->mm->mmap_base; - info.high_limit = arch_get_mmap_end(addr, len, flags); - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - return vm_unmapped_area(&info); -} - -static unsigned long -hugetlb_get_unmapped_area_topdown(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info = {}; - - info.flags = VM_UNMAPPED_AREA_TOPDOWN; - info.length = len; - info.low_limit = PAGE_SIZE; - info.high_limit = arch_get_mmap_base(addr, current->mm->mmap_base); - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - addr = vm_unmapped_area(&info); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - if (unlikely(offset_in_page(addr))) { - VM_BUG_ON(addr != -ENOMEM); - info.flags = 0; - info.low_limit = current->mm->mmap_base; - info.high_limit = arch_get_mmap_end(addr, len, flags); - addr = vm_unmapped_area(&info); - } - - return addr; -} - -unsigned long -generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, - unsigned long flags) -{ - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - struct hstate *h = hstate_file(file); - const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (len > TASK_SIZE) - return -ENOMEM; - - if (flags & MAP_FIXED) { - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - return addr; - } - - if (addr) { - addr = ALIGN(addr, huge_page_size(h)); - vma = find_vma(mm, addr); - if (mmap_end - len >= addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } - - /* - * Use MMF_TOPDOWN flag as a hint to use topdown routine. - * If architectures have special needs, they should define their own - * version of hugetlb_get_unmapped_area. - */ - if (test_bit(MMF_TOPDOWN, &mm->flags)) - return hugetlb_get_unmapped_area_topdown(file, addr, len, - pgoff, flags); - return hugetlb_get_unmapped_area_bottomup(file, addr, len, - pgoff, flags); -} - unsigned long hugetlb_mmap_check_and_align(struct file *file, unsigned long addr, unsigned long len, unsigned long flags) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 9183ef95dfb6..a83a2b331bab 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -559,11 +559,6 @@ unsigned long hugetlb_mmap_check_and_align(struct file *file, unsigned long addr, unsigned long len, unsigned long flags); -unsigned long -generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, - unsigned long flags); - /* * huegtlb page specific state flags. These flags are located in page.private * of the hugetlb head page. Functions created via the below macros should be From patchwork Wed Jul 10 10:50:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13729177 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 9F16CC3DA42 for ; Wed, 10 Jul 2024 10:51:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECA366B00A5; Wed, 10 Jul 2024 06:51:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E79A96B00A6; Wed, 10 Jul 2024 06:51:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF0FE6B00A7; Wed, 10 Jul 2024 06:51:36 -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 AF1196B00A5 for ; Wed, 10 Jul 2024 06:51:36 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6D6C81C325A for ; Wed, 10 Jul 2024 10:51:36 +0000 (UTC) X-FDA: 82323526992.21.31E33C3 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf14.hostedemail.com (Postfix) with ESMTP id 47D0E10001B for ; Wed, 10 Jul 2024 10:51:33 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=A98K2eBm; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="j/VNTJ8g"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=rs4IeFFz; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=t6BWMfnr; spf=pass (imf14.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=1720608662; 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=m7b0FFfloSBNSR2ZzezMp+fU3t5dKSCqfMIY6cE3U0k=; b=n3vRJqsA4JA3KQz0hQ9HkNmRvmZuj5Yp0oa3oj1FfvxBcZ62CTGmVPwbZ8alQbhzf0MTmh YvheKDCuS61J/xiq6wVnJUEDwCxC9l3iHmEE4a6dlc0zLth/7UhOUyR96BeSfp03rvLORX 6gTvs4i/0MIkVKm7oeIOsyCmDk+qL/s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720608662; a=rsa-sha256; cv=none; b=eLQTqyQKQKT6OP+Jqt+Pt/Yuf/k/MSKMKhoGWERJpYGGLuc/G27WVrdUNUb42MWQ178X9d qd4mzswI0IuzJ+XDdTAJv8FWzeElquGnr+P3Vlpojg+OSyV01DQfRtjpGbq0defiWtNu8O qZPJzM6KoxylfQp54Wem/URTUSya+4Y= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=A98K2eBm; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="j/VNTJ8g"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=rs4IeFFz; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=t6BWMfnr; spf=pass (imf14.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 (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 E21F121A3D; Wed, 10 Jul 2024 10:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608693; 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=m7b0FFfloSBNSR2ZzezMp+fU3t5dKSCqfMIY6cE3U0k=; b=A98K2eBm6Gsqbion+I8upTty0hFnnNSEoZJDzP8V3Ba7Zd8avnjBnknSIEblzvcgRWO3f9 7xTFJhTCQjH2Hq6tGHv4juQDJiWHP/5vdUjuLKqRFfQi7Im1E9JCcrwRa5A09W2oFetiIB 11iXdwkRurVljAjqGqpWXIeVyeS4PtE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608693; 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=m7b0FFfloSBNSR2ZzezMp+fU3t5dKSCqfMIY6cE3U0k=; b=j/VNTJ8gVG5iHz8ywTjWTHn20BAe7Zgu3aD9+u+Ei2+8RVyx0Hfk6rgbHq0UxO64HONWBC p5bNzdbCwc84EBAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608692; 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=m7b0FFfloSBNSR2ZzezMp+fU3t5dKSCqfMIY6cE3U0k=; b=rs4IeFFzhz69FMWvI0QKY00JQtl778j3n78qia0/IsoPc0P6GNP6iBmn8UOFrweyMGe4Md Xy87v1OVVvjvvuz/nc7EKHWWeRkgAa2kustip+8z2BPVKzM/SHL5ubgqlYQKI9dcWh9rYW PQcxbkGSx8kMqhv9vEUcDHH4184Qnno= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608692; 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=m7b0FFfloSBNSR2ZzezMp+fU3t5dKSCqfMIY6cE3U0k=; b=t6BWMfnrG2VPsHdWL347hUkhoiFuG1SE0aSsXFmtmrBxY0QA0RyX3XAgJUyybj2K3cD+H7 PsC15Z+C8sHLNvDA== 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 CB26D1369A; Wed, 10 Jul 2024 10:51:31 +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 8L0uLbNnjmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:31 +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 8/8] mm: Consolidate common checks in hugetlb_mmap_check_and_align Date: Wed, 10 Jul 2024 12:50:42 +0200 Message-ID: <20240710105042.30165-9-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-Stat-Signature: 1p8fwkymtqc4rphu7duup7yp7hwtgeco X-Rspamd-Queue-Id: 47D0E10001B X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1720608693-23800 X-HE-Meta: U2FsdGVkX18if2CRlRTeAq3/FBiWTwHIio7+Vrb+eJD6DUJktwIUe7dV6glGkOoOUHCDXwP7LChxB8+3xUyZBfl2Dnis4gWxuSk2/wFdTAKeLYJtvQsBqsSZx5jj9n086dc3Eo1S+v+30x61KfnooEGEi20gtlCiyIJiH7XqNFAypDVi86FDemd31cyvuq3ZbfAiLhThKN9f4ktifAPbVIUSRw/0x84xNsPn0ErzomLSLbsJ6pk2zo3HpFfXnDpHy1DZa+T2U6J0rQ/JtfdRPPHi0RNn4ipEoxB++DlRh8EWaYsLyItcQ51Tusu6ch+qvMHWrdpCbzkGUKpA62YOiV0vzl7Kbt4aoFo/SP+s7wUoeTh677OaUtKCFTpB9gnRB/zm/mFkemsEJnyHJvhU15FecbExQHyoeyd0WWJr0eWJQCyccHvq2FlfMXV+4nA9BFhGDJY3GxwsY/GdRsH+lnxhVRMLGijWE8FTl8ob+LiPvgcozJ+ZM+1oMn6S2K/ezDC6MJQuuhjHBPvcLWAKAGPfx5J2Ya50dmexZFKfRHIZ+YVpgc7RAAnm5l6bjriCruGmfG17caLRQ+NPumXhjrFMYC1rOzXZ5GItwAH0GNc+HKsB8DTsA1yhgr3HZbmcr/S2zJTXBZdwM/v7EHiOyFADxRtfy5VCuREKIMwUrbk3/xezToArrzXJecPnFsgLRlnL3ql/d/4choxARnbH0BpBRYy6VV+DBJTAwTuJHvE4hDIQIHbrxwfVIKR4TuEJJciJisLRg433ObHLIPsRnz+IpSHwEbvcMdWSjr8jfKbJ5adksmTp8U2jSroXgvVllIzZOaY//Qx4FUcsR5Z9I8tQmgJPbL86it2bqqo4sV9SIEDhuO6za5aO1NKIyuzQVb/1YaarqD1YCeh0+fIH5awMmivOLH78/C7ODnAhsrb4B2zljoDME2ym4YyNr/gtefH5a91KvNOIvpXJm/e m6N5o71B JAch5O5h8V6/32PNOu+WSIuUDXAcSfeH7ei14J07KI+wygJC5J1pYguwzksDplhyVZxeLf3R63kDBUSPz42axrgwhpnL/Kc/4vIDlJbmxK0wCm/AlDFlWCfEOHCa4egkIispBP+pGv3QfKApCIhm80rt6F6k+D+I9yfB6u4P3VxcaNEPYgK9kLerEF3DyNqdO+bTgLMIrD9ftLRUIj0f1CQ6X80rRwdUfD3qnd6TqOBaEsBTSAZRwyLceJnycXz1YOdNeYOtXBFvqq9RyskYxl2r4Jg== 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: prepare_hugepage_range() performs almost the same checks for all architectures that define it, with the exception of mips and loongarch that also check for overflows. The rest checks for the addr and len to be properly aligned, so we can move that to the generic hugetlb_mmap_check_and_align() function and get rid of a fair amount of duplicated code. Signed-off-by: Oscar Salvador --- arch/loongarch/include/asm/hugetlb.h | 4 ---- arch/mips/include/asm/hugetlb.h | 4 ---- arch/parisc/include/asm/hugetlb.h | 15 --------------- arch/s390/include/asm/hugetlb.h | 16 ---------------- arch/sh/include/asm/hugetlb.h | 15 --------------- fs/hugetlbfs/inode.c | 8 ++++++-- include/asm-generic/hugetlb.h | 7 ------- 7 files changed, 6 insertions(+), 63 deletions(-) diff --git a/arch/loongarch/include/asm/hugetlb.h b/arch/loongarch/include/asm/hugetlb.h index aa44b3fe43dd..107566c98938 100644 --- a/arch/loongarch/include/asm/hugetlb.h +++ b/arch/loongarch/include/asm/hugetlb.h @@ -18,10 +18,6 @@ static inline int prepare_hugepage_range(struct file *file, unsigned long task_size = STACK_TOP; struct hstate *h = hstate_file(file); - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; if (len > task_size) return -ENOMEM; if (task_size - len < addr) diff --git a/arch/mips/include/asm/hugetlb.h b/arch/mips/include/asm/hugetlb.h index fd69c8808554..6a63d82a8ab3 100644 --- a/arch/mips/include/asm/hugetlb.h +++ b/arch/mips/include/asm/hugetlb.h @@ -19,10 +19,6 @@ static inline int prepare_hugepage_range(struct file *file, unsigned long task_size = STACK_TOP; struct hstate *h = hstate_file(file); - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; if (len > task_size) return -ENOMEM; if (task_size - len < addr) diff --git a/arch/parisc/include/asm/hugetlb.h b/arch/parisc/include/asm/hugetlb.h index 72daacc472a0..5b3a5429f71b 100644 --- a/arch/parisc/include/asm/hugetlb.h +++ b/arch/parisc/include/asm/hugetlb.h @@ -12,21 +12,6 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep); -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - if (len & ~HPAGE_MASK) - return -EINVAL; - if (addr & ~HPAGE_MASK) - return -EINVAL; - return 0; -} - #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetlb.h index ce5f4fe8be4d..38a10b47dc99 100644 --- a/arch/s390/include/asm/hugetlb.h +++ b/arch/s390/include/asm/hugetlb.h @@ -23,22 +23,6 @@ pte_t huge_ptep_get(pte_t *ptep); pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep); -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - struct hstate *h = hstate_file(file); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; - return 0; -} - static inline void arch_clear_hugetlb_flags(struct folio *folio) { clear_bit(PG_arch_1, &folio->flags); diff --git a/arch/sh/include/asm/hugetlb.h b/arch/sh/include/asm/hugetlb.h index 75028bd568ba..4a92e6e4d627 100644 --- a/arch/sh/include/asm/hugetlb.h +++ b/arch/sh/include/asm/hugetlb.h @@ -5,21 +5,6 @@ #include #include -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - if (len & ~HPAGE_MASK) - return -EINVAL; - if (addr & ~HPAGE_MASK) - return -EINVAL; - return 0; -} - #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 722e60327615..82ec499feb41 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -180,8 +180,12 @@ hugetlb_mmap_check_and_align(struct file *file, unsigned long addr, if (len & ~huge_page_mask(h)) return -EINVAL; - if ((flags & MAP_FIXED) && prepare_hugepage_range(file, addr, len)) - return -EINVAL; + if (flags & MAP_FIXED) { + if (addr & ~huge_page_mask(h)) + return -EINVAL; + if (prepare_hugepage_range(file, addr, len)) + return -EINVAL; + } if (addr) addr0 = ALIGN(addr, huge_page_size(h)); diff --git a/include/asm-generic/hugetlb.h b/include/asm-generic/hugetlb.h index 6dcf4d576970..d522581441e5 100644 --- a/include/asm-generic/hugetlb.h +++ b/include/asm-generic/hugetlb.h @@ -115,13 +115,6 @@ static inline int huge_pte_none_mostly(pte_t pte) static inline int prepare_hugepage_range(struct file *file, unsigned long addr, unsigned long len) { - struct hstate *h = hstate_file(file); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; - return 0; } #endif