From patchwork Thu Jul 18 10:58:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13736386 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 5E2E6C3DA49 for ; Thu, 18 Jul 2024 10:59:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 757A26B0088; Thu, 18 Jul 2024 06:59:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61D556B0089; Thu, 18 Jul 2024 06:59:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 495A96B008C; Thu, 18 Jul 2024 06:59:18 -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 2CCA86B0088 for ; Thu, 18 Jul 2024 06:59:18 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D4F71141A64 for ; Thu, 18 Jul 2024 10:59:17 +0000 (UTC) X-FDA: 82352576754.04.46B44EC Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf13.hostedemail.com (Postfix) with ESMTP id B598920016 for ; Thu, 18 Jul 2024 10:59:15 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="nvdQENm/"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=9IkidMmH; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="nvdQENm/"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=9IkidMmH; spf=pass (imf13.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=1721300335; 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=XSQhKhxsB8mJo06ul8PeKZx+ybzEA5hBxV4gU2MOqSA=; b=wV4YLpcnWsPm5Jte8KVmdkiaGDCWeueuNMkFfvic2JHED9zFnX2SNQDy0ZCY+obD3Wylyg WF+7/RdvRe5rbJbCb0ZtHbGPNOaoWWxJ+RAQqVLls+hcgu/M9kO31c5rinwWcHzAs+uy/L JxrOXDuA/y7a9JXANGKVD30r4mci2RI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="nvdQENm/"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=9IkidMmH; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="nvdQENm/"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=9IkidMmH; spf=pass (imf13.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=1721300335; a=rsa-sha256; cv=none; b=k4VjZIKfWZEUCwKpC8zdvLyGVZIdXzNrvHXAWxyUrDRzIefJc2x15UhoTrgB7sLRFU85u1 WML/9XGRRNM/czyGmf65cGTlzUTAKapT2gSTeCw3RFDEVIHHKV31cpm1sWhdlnD0KVuzFj TwECLu+/yy852bdgrY9hGTlIe8E39e0= 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 6CB0421AA9; Thu, 18 Jul 2024 10:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300354; 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=XSQhKhxsB8mJo06ul8PeKZx+ybzEA5hBxV4gU2MOqSA=; b=nvdQENm/WtvNG/dv2P5+3UqhZFMf2Y8s0sZ8K90ln3xgURBZ2hb1dnl4Hj6dymaS6b+jUt PvjWP0Yg+Do11iu40ovq8B2aGDoLjb7cksW+f3TRLsdwd1MwenIeTnL7yZwh1MuSFLdmkY 5fA6aeMpteIKD1q8BCV2nXBFlgLpT00= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300354; 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=XSQhKhxsB8mJo06ul8PeKZx+ybzEA5hBxV4gU2MOqSA=; b=9IkidMmHNUBfTTwfSjBvZ3ED1oSXhhnLI2xazYggzQA+zDCLc87V3X7HL0YelcV/xU7nV0 flWYiVxJq9gr/8BQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300354; 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=XSQhKhxsB8mJo06ul8PeKZx+ybzEA5hBxV4gU2MOqSA=; b=nvdQENm/WtvNG/dv2P5+3UqhZFMf2Y8s0sZ8K90ln3xgURBZ2hb1dnl4Hj6dymaS6b+jUt PvjWP0Yg+Do11iu40ovq8B2aGDoLjb7cksW+f3TRLsdwd1MwenIeTnL7yZwh1MuSFLdmkY 5fA6aeMpteIKD1q8BCV2nXBFlgLpT00= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300354; 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=XSQhKhxsB8mJo06ul8PeKZx+ybzEA5hBxV4gU2MOqSA=; b=9IkidMmHNUBfTTwfSjBvZ3ED1oSXhhnLI2xazYggzQA+zDCLc87V3X7HL0YelcV/xU7nV0 flWYiVxJq9gr/8BQ== 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 69839136F7; Thu, 18 Jul 2024 10:59:13 +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 qBggFYH1mGbnVAAAD6G6ig (envelope-from ); Thu, 18 Jul 2024 10:59:13 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [PATCH 1/9] mm/mmap: Teach generic_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Thu, 18 Jul 2024 12:58:55 +0200 Message-ID: <20240718105903.19617-2-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240718105903.19617-1-osalvador@suse.de> References: <20240718105903.19617-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: B598920016 X-Stat-Signature: fbz4xbfjr51tqrjyixtyxgojiwi79mgw X-HE-Tag: 1721300355-401286 X-HE-Meta: U2FsdGVkX19Wo9xlldpfLgBisbq6Q61uWWiil2k4/+57zWgvQ9OtSi302C08eUjcBFNBfWJZmWZgNn7Yp9kdhdhJLk75f0OJ7nQig/1iW78iMByRm3WyG3I5elvw8rF365NjqNhxdZl3L2AIfY2+dqSmuG2pxpQOk5CRJ+rC+N+Ka5AG+YQeF/1PaedgdlGT8nrZ8c/pYScjlOFNToELXGDlR/GA8Sus10QBRRpOpVr0WbAuTBtioEeJSnOSvPHzT/BTOHL1LtFGvJWN6RNgSRrxoJuPZRCtvwi94m40as8VcdkKOXBBqd2wkTW/zdnO44MDeEhc96gEqGPUCaHO+v3o40ogIiWtWM28PUHwe5X5XB0gHev0Cij5X48uqQ6JmYg+44kCSEwWXH4kIrxABXrthPPQYcaYMSqcJqabVGVt2Ikatd60ovAko4a+9S9W6VtxRMQeU5esUc4rJgXnMQaCqinbu4FdXHmbkZwXOPtVmNJ0JC9kS5m875cTMQslspbtjzdYkjPsgswQMOwUrFH1Pt5gXbGMzyfviJ8opa0HLMN+w4p4LGSC62yzJLYvqXzTNm12LuiYKNkI62TaRG1u+WhGRsyjw/IObrtpFdaogBs4PYW9ufGkCj6yLeGtDnQm8lijMdkdTEAuKUHw16YKUfEwZ32UZDAr/TDDR6CCxIsafmU9dwAbBznTlfGVufFnNoGVTN8tiyyn3VvDdTT/9j9ng5u1VkaCqYcY323BlG126gyfwu78mZs4bt+BTjpvYbvFUH4e1Zo3dEJxENg2yBEEwXDQAkbhKRN9VTnMC2hnxUhB95dMvyOFdQ8h6s1m8q2DHeHbnxHtYXK8kWeIpmgKZoY/ajxWJS0bnj8TxsaxfZOFy+gwc/8z3JGCi0IP0ZQxOQHMRx5icnbXENBO8vluz0m6xcN9qUM+sl7Aov9B4usX9c5kvyAsv4RCXSZ7vQSNhu8jNGctnHX OSqPJx+V 6RycVP9Syzd6EwAmoPvMeZvE8hQ2gEg5FJBPKLwdhSq/EpnumFPbsbgv6+JyK7MdrA6nSAf4Y0fO7rWpdCd8n5igXqRhRkV+FrB8Ln2idauHkMFKs68YB6bwJToqKK9cVvITx4ySsLT0GYN4ZUen24igcRmY2NAO31j+fvNBOiIo4Vykvsy2RZQGS2gBU4dI1FS90hduAW8m9xuAyG256TADiOPgGZ7TZY3kqlttkelBzv6zKK0H+Pyn3abCeFwDTg86LDp6q+uxdRSr+SEjbTyxAAA== 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 Thu Jul 18 10:58:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13736387 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 5F9E5C3DA61 for ; Thu, 18 Jul 2024 10:59:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B01B46B0089; Thu, 18 Jul 2024 06:59:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB2BB6B008C; Thu, 18 Jul 2024 06:59:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 953176B0092; Thu, 18 Jul 2024 06:59:19 -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 776066B0089 for ; Thu, 18 Jul 2024 06:59:19 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3D4251A1ADE for ; Thu, 18 Jul 2024 10:59:19 +0000 (UTC) X-FDA: 82352576838.17.6EDA716 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf26.hostedemail.com (Postfix) with ESMTP id 232CE14000C for ; Thu, 18 Jul 2024 10:59:16 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=RCEaPyHR; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=CDuhEnaY; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=RCEaPyHR; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=CDuhEnaY; spf=pass (imf26.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=1721300336; a=rsa-sha256; cv=none; b=r49/o4gBb86xVcXHS8n+n8wHXdSFbNyWZ5hXLAtq3YPlgq8W/fYgH52Pjtk3pwhFhMnPdx +E9Fzxgu6h/+VWoWEHP4UbM/UkTe1KeSXxVXadQwfmFFCXU2gofTmxjpRcCT56flTgNGLf Q8PHdAxzX/A7eZvfNcCszHnkKpUC/TA= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=RCEaPyHR; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=CDuhEnaY; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=RCEaPyHR; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=CDuhEnaY; spf=pass (imf26.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=1721300336; 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=/YtBEq+futfpDK6VnLTGAsLUUeg4b//ccUCfgdjh03Q=; b=YSpcYi17GOd1OaxScuvf+e00JkM2XqEkNsra72g5Lj5n+BNamPxNK+JXrWABzbXXfb1T+E vdE7AFRJwn3ZgIpR6V9GyNYxc39M0Mb6pH+tdqpt4WvUyBDSUgp4MYjaIWDguZwFZ9K9z7 gNQP85R/75L6sYZcUvrf4WsZUDIF/Ts= 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 95F9D21AD8; Thu, 18 Jul 2024 10:59:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300355; 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=/YtBEq+futfpDK6VnLTGAsLUUeg4b//ccUCfgdjh03Q=; b=RCEaPyHRDPlkfDCvQ819eOOfEcQ+0vrYU9ule7hx6xQDWOaYKbsDWj91KHSrZBm7Wa2ZXA 2sBeiZo8RXWvY2KC7S4RFP1na2xHi76mIPDQZXi8H1waAaTvryQGy/U2nNHYxzKcY6m1LJ GvGpWCJmuek9+pIN3/WXYVxlDw31Xxw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300355; 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=/YtBEq+futfpDK6VnLTGAsLUUeg4b//ccUCfgdjh03Q=; b=CDuhEnaYXEELncVh53GTkwlfSqTOIGXNHABa1+qHjSgFOe/UogyIgh9YcMFJ7OOOCdr6In 3SislPYiilqx9GAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300355; 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=/YtBEq+futfpDK6VnLTGAsLUUeg4b//ccUCfgdjh03Q=; b=RCEaPyHRDPlkfDCvQ819eOOfEcQ+0vrYU9ule7hx6xQDWOaYKbsDWj91KHSrZBm7Wa2ZXA 2sBeiZo8RXWvY2KC7S4RFP1na2xHi76mIPDQZXi8H1waAaTvryQGy/U2nNHYxzKcY6m1LJ GvGpWCJmuek9+pIN3/WXYVxlDw31Xxw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300355; 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=/YtBEq+futfpDK6VnLTGAsLUUeg4b//ccUCfgdjh03Q=; b=CDuhEnaYXEELncVh53GTkwlfSqTOIGXNHABa1+qHjSgFOe/UogyIgh9YcMFJ7OOOCdr6In 3SislPYiilqx9GAg== 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 97C4E136F7; Thu, 18 Jul 2024 10:59:14 +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 eCHDIIL1mGbnVAAAD6G6ig (envelope-from ); Thu, 18 Jul 2024 10:59:14 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [PATCH 2/9] arch/s390: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Thu, 18 Jul 2024 12:58:56 +0200 Message-ID: <20240718105903.19617-3-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240718105903.19617-1-osalvador@suse.de> References: <20240718105903.19617-1-osalvador@suse.de> MIME-Version: 1.0 X-Stat-Signature: qzgp5utn4uhr4wsmm9uw786ixxu75p1o X-Rspamd-Queue-Id: 232CE14000C X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1721300356-976199 X-HE-Meta: U2FsdGVkX1+vv/VDj8MxnX8XQok3eohelXzfZRxkoCoXdo13ZcgCw5RQTCi9sP6Vh7cDO5cyAMqxjEl/Kqire/eQ/1P4TWAcVdtub6I0hMtJkyM8AE/NQqwo8y0lLq6U+CviqaWLq3CdglvhaDsWGk8oTJ3XLc/JCwYqrzHj50PWoKgQdGWYgGUEd0OPsUkV9imjAJSPtcgYBuHQqyRaljEOwFHWc4o/hZ2LWF4ISzTU0D9Ip8T14DQT4oDcltKF5n7A4ys85mJIPUTI16h4BGDfs0pgkZjM2itWdN7OdDO4p2cw9VOewElYEVBh31HgmVwEp69S6LqlX/f2e/5VaOXInl9pNFkgHVVyiqjz7vyW7mgbIFf0nC+c6+6EVEplGuWWsJ29RcIcR6dRJLNFTVmQ2LwsBC0SS5pffzLKK4mkq4t6MtBF8dap+4tP3o9DcZ3H/sXsXRWKZg54hIRJx6NJAfYWVgqT+v9YcB6vdCgZctk09NBh3NJgC8/Ep2r5Xyv5ivE56ZkHCk0ROuve88L+a6H3g9ABFpRKrJWWLJb8+Rh8WjNra8KEbAGtNjxToAyrNItSWI8y1Eow/UWs1BqYxx6PU01LsUIPLb26xiz/2myFkkeCgjw1BDdg5HaGNAdKJiK1mnkp5PBWfrSYXPoShQcRPAGmivDctmS+WR+2McBczXLchsPgMNmDNRZNeRWVdh/71lxRjpz0hTZWdAgNyLhw00MuISb0iSrZHKFew7nvMbPnuQo8zwRAq97ajj3300I4kIweUwYLkOkyL6BlVoBCD65QsmehvWy4U5JxJD5u7hmZflHHMBjBoR7vz2NdQK4nqQY9qi0PZgUQDSGLZaTiC97QsX8GrhiAN+9rDnM4LWK+vfApEpkB1G65X5CmVahkEtiIpDHB/GTKwUG/fqH3sEuNHSdE2WhJQXJBn2DnW8NWeOiX/oDR+IIn0Iz4th2ojQ8WM6ls1xD pmw8bPCK lYhk4g++0tK+nDu/0sY3vRu8NlubjQwvvuyi0fMtZYFc0klByLd+Z5dLS0MxA2X2CexvB0SzwKShuO0Ab2ovKdv94NGoZT9tn0A5T8YHU8vbcXIGHiuwHNl01QDe/o0mEwAf53mLafZVVPWfSyqhv0UHzNtk5TQ72W6lBZqpkUVE6uLjODFizg69BG7Jnu6sNY987wKeeauQ4YD+Ha7GlJV1Ch9vehrWcuN06aRL0gUC1BZFmvElwzH3W5Yv31AZqHgy1z+NFMdKITiJLe0vGyAKKJQ== 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 compability. Signed-off-by: Oscar Salvador --- arch/s390/mm/mmap.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c index 206756946589..408b5a541a28 100644 --- a/arch/s390/mm/mmap.c +++ b/arch/s390/mm/mmap.c @@ -17,6 +17,7 @@ #include #include #include +#include #include static unsigned long stack_maxrandom_size(void) @@ -73,6 +74,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 +109,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 (!(filp && is_file_hugepages(filp))) + info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); if (offset_in_page(addr)) return addr; @@ -144,7 +148,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 (!(filp && is_file_hugepages(filp))) + info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); /* From patchwork Thu Jul 18 10:58:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13736388 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AC19C3DA49 for ; Thu, 18 Jul 2024 10:59:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3389F6B0092; Thu, 18 Jul 2024 06:59:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E9566B0093; Thu, 18 Jul 2024 06:59:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09EEB6B0095; Thu, 18 Jul 2024 06:59:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DE4AF6B0092 for ; Thu, 18 Jul 2024 06:59:20 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 989F9121A24 for ; Thu, 18 Jul 2024 10:59:20 +0000 (UTC) X-FDA: 82352576880.18.B17744E Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf04.hostedemail.com (Postfix) with ESMTP id 69C144001C for ; Thu, 18 Jul 2024 10:59:18 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ROL3Btep; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=oRwpoIhB; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ROL3Btep; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=oRwpoIhB; spf=pass (imf04.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721300338; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BHN99Otp08yvKHunYIWd3zL4cHzZBNMKDmIpLbdX684=; b=ZXSX6oH7wh5ezrMsera8nQrkh/y0IO53zDuGwuTN87hqC58if9USe49p2eYK5iGynoljs3 8x/GygRvijj0VQ96zaCzo5dLFmnRzl26WVf27dlxX+66zsdpZKBgun2Y5KQCKAQi2mU6tJ rK824HmSOGLUVdrrbZrwaSds6u712JU= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ROL3Btep; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=oRwpoIhB; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ROL3Btep; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=oRwpoIhB; spf=pass (imf04.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721300338; a=rsa-sha256; cv=none; b=oTRlR37QjCP5Dyl8IFbmjitegiY+cGAa1A7kWEQB5fXOi0IPb/d9eYE/tOkZ6Kv0SlJ9RX U2bndh+74jI2zKnUJC7Dx6E5B6rdaombI84fiWMfFtNNgrBPQ1bTMLqS1qO7bwXr+oWVXv p08MaK/HhURLJEQlaOTnODkhq7U6TjM= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B2CC421AF5; Thu, 18 Jul 2024 10:59:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300356; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BHN99Otp08yvKHunYIWd3zL4cHzZBNMKDmIpLbdX684=; b=ROL3BtepMH8hvdTP7yikKJC2Bjb9wtA9aU5ZNrKsCn3UdiH8tgTp7mWjKfzyR6YHaSdep2 G6hKQv7Z3pspF9/Z4RwVT8ZFhDH4P4+nr6cMUcLDjDjxYck1Kpk2zlruoAW4hpns58FdEh d3+2822x2EWq255lyXMNp4Gmi3DFQKo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300356; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BHN99Otp08yvKHunYIWd3zL4cHzZBNMKDmIpLbdX684=; b=oRwpoIhBYuLkTUNMIPtBuktOIT1rvbaVJ65aKpRzjqSSeEiTSL+RUohgMBZlb86A1noTlR tBdC3gAq5HtrS/Bw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300356; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BHN99Otp08yvKHunYIWd3zL4cHzZBNMKDmIpLbdX684=; b=ROL3BtepMH8hvdTP7yikKJC2Bjb9wtA9aU5ZNrKsCn3UdiH8tgTp7mWjKfzyR6YHaSdep2 G6hKQv7Z3pspF9/Z4RwVT8ZFhDH4P4+nr6cMUcLDjDjxYck1Kpk2zlruoAW4hpns58FdEh d3+2822x2EWq255lyXMNp4Gmi3DFQKo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300356; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BHN99Otp08yvKHunYIWd3zL4cHzZBNMKDmIpLbdX684=; b=oRwpoIhBYuLkTUNMIPtBuktOIT1rvbaVJ65aKpRzjqSSeEiTSL+RUohgMBZlb86A1noTlR tBdC3gAq5HtrS/Bw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BCF64136F7; Thu, 18 Jul 2024 10:59:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 8AwlKYP1mGbnVAAAD6G6ig (envelope-from ); Thu, 18 Jul 2024 10:59:15 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [PATCH 3/9] arch/x86: Teach arch_get_unmapped_area_vmflags to handle hugetlb mappings Date: Thu, 18 Jul 2024 12:58:57 +0200 Message-ID: <20240718105903.19617-4-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240718105903.19617-1-osalvador@suse.de> References: <20240718105903.19617-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 69C144001C X-Stat-Signature: 7bgbe5caqrofbeqgzfxxh9dqbz6xn457 X-HE-Tag: 1721300358-108655 X-HE-Meta: U2FsdGVkX19HYntYjWDnxSqTR/xbyfnGeoHcDRbyTYF6nnUmBxupcf/3mTmGY4iu0fIUZ//1AZbe53o35EIBqSoX5CUEVDBDth6p+jzNZwXON23Why7HDdkZRiFkVndb1igGBGR+Zf744av3a7z8wcEqBcXKaVmvZXoMz0agf/Vo32Y+N0ZIQIbl5llVtGBdSq+JoN15zJ6NiI96pFRg8YMTTA8IQZSOkjx+Xx1xfIoa6O4mHuFwExadKNKRunEuvf1C+fVCIx5r/ENhlQDp3vASzf+T65NRINYMdVcTc+ZqLYMQ6nJzuDvSYmt7ajtBjyMUnmHBJ4JI02O3MWnrU8VBdKUCt1hvUE1eGlzNDeFmYWiHkYSIGO39bOPaJHG4RNZdn1w5+v6VlGXZ2N4C2AcdOzkFtxb5doOTISGAjyOcZSZ8VSuiYIfG3xlM3Wyqpa/JP1RHbSWMmWxdRLMseL9WofSHT1SJVY+sRVgLAW37IdCTmJG2CNSd9heNPwU0rPIaGWDZu5MxZgPaVDdnhbGDC2iZBosdGEbgyXdolnmbVSUhaadlu2XUNcdLVJ9lZFMowW8LSND8cI5/WCU558pt6QLFApS60XEuKkdst7eU3lVJsxMqqsDAz9SmZZasUnmFtEemS54HCUweS953Rw0sNcL0N4HnqiERzGflZtkYTKruo5IHoDDXKvP5AhwYMe8FAITthB+LK8qere0hbOdYlckjJDLagxp8/fvazFhAXBjH55i81CRIQXdjXsQiS0YOOlGF3Wpl8dmaiudxfWenAWslb6UX1Aod6wFTJheeNSNHtDhzX4g7TjzhO+YymZ7vZHVN49zHLuBci/vKIspkPAW4/w7fNWMiauf7V2v/aFJq+DNidMO//zWqA6BsnhWXzbPrkplXAOjMv8+ksSWi0NLwTWzkMwCRifzUEnbLRi+yXEhMKrChPury0GPfVYA8c9O8QHsmOn5n7ml Yzbf8QYL iRZRngX8yE09GMExygvmyiLCVx6BaZHTfGbhyXpDE8yZIc8dDjl3RrKx/VxlvSsf6Amkc1A1eP4AX8Eq4kmakIOoW0pDkeA+8YJZjNXOTqw9GF12w3xz/whgD9pexP6dTxQMkE4GjA+21YP5lrlVSXtdlbm93WXHLTxUiT4mLxHsiP/jeY0tLumpBRhg0SaycD+jciIZgy9j/C+wGDQ6QlrNz5a+30gtsaigyG8dtLQ0Fleui/ZexGAmze0AnqB96oQCkKD4ocNF/Mtv5iT0C3fmclinfVeIGxVtH X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area_{topdown_}vmflags to handle those. x86 specific hugetlb function does not set either info.start_gap or info.align_offset so the same here for compability. Signed-off-by: Oscar Salvador --- arch/x86/kernel/sys_x86_64.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c index 01d7cd85ef97..aa7491f036a7 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -25,8 +26,10 @@ /* * Align a virtual address to avoid aliasing in the I$ on AMD F15h. */ -static unsigned long get_align_mask(void) +static unsigned long get_align_mask(struct file *filp) { + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); /* handle 32- and 64-bit case with a single conditional */ if (va_align.flags < 0 || !(va_align.flags & (2 - mmap_is_ia32()))) return 0; @@ -49,7 +52,7 @@ static unsigned long get_align_mask(void) */ static unsigned long get_align_bits(void) { - return va_align.bits & get_align_mask(); + return va_align.bits & get_align_mask(NULL); } static int __init control_va_addr_alignment(char *str) @@ -148,12 +151,15 @@ arch_get_unmapped_area_vmflags(struct file *filp, unsigned long addr, unsigned l info.length = len; info.low_limit = begin; info.high_limit = end; - info.align_offset = pgoff << PAGE_SHIFT; - info.start_gap = stack_guard_placement(vm_flags); + if (!(filp && is_file_hugepages(filp))) { + info.align_offset = pgoff << PAGE_SHIFT; + info.start_gap = stack_guard_placement(vm_flags); + } if (filp) { - info.align_mask = get_align_mask(); + info.align_mask = get_align_mask(filp); info.align_offset += get_align_bits(); } + return vm_unmapped_area(&info); } @@ -199,7 +205,10 @@ arch_get_unmapped_area_topdown_vmflags(struct file *filp, unsigned long addr0, info.low_limit = PAGE_SIZE; info.high_limit = get_mmap_base(0); - info.start_gap = stack_guard_placement(vm_flags); + if (!(filp && is_file_hugepages(filp))) { + info.start_gap = stack_guard_placement(vm_flags); + info.align_offset = pgoff << PAGE_SHIFT; + } /* * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area @@ -211,9 +220,8 @@ arch_get_unmapped_area_topdown_vmflags(struct file *filp, unsigned long addr0, if (addr > DEFAULT_MAP_WINDOW && !in_32bit_syscall()) info.high_limit += TASK_SIZE_MAX - DEFAULT_MAP_WINDOW; - info.align_offset = pgoff << PAGE_SHIFT; if (filp) { - info.align_mask = get_align_mask(); + info.align_mask = get_align_mask(filp); info.align_offset += get_align_bits(); } addr = vm_unmapped_area(&info); From patchwork Thu Jul 18 10:58:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13736389 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 C20D8C3DA49 for ; Thu, 18 Jul 2024 10:59:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E365A6B0093; Thu, 18 Jul 2024 06:59:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBFCE6B0095; Thu, 18 Jul 2024 06:59:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9ACC6B0096; Thu, 18 Jul 2024 06:59:21 -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 9523D6B0093 for ; Thu, 18 Jul 2024 06:59:21 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 50FBF81A79 for ; Thu, 18 Jul 2024 10:59:21 +0000 (UTC) X-FDA: 82352576922.19.E6D115A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf27.hostedemail.com (Postfix) with ESMTP id 1E14B40011 for ; Thu, 18 Jul 2024 10:59:18 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=UnjJIEr7; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=NbhZQkeV; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=UnjJIEr7; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=NbhZQkeV; spf=pass (imf27.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=1721300327; 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=S3eV4tzn99V5QCNtsrHXIAbjIOXiUl0vRGMsjIKRQw0=; b=46vmLB0EUKvE0Szz/Y9LRAPq+BL5pW24AOybndqXxdmqSLlN0oItT2fqJ+KhpOflFZXp95 7OEEltGUjw9H7cQxR4LvExKj4qqWlBd+CBSNu1345bKKm0Sr2DMClcCTXsceDheSVphi+p w2ZNzMjKQtOdn0whSVscCZ5HePnK9TQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=UnjJIEr7; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=NbhZQkeV; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=UnjJIEr7; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=NbhZQkeV; spf=pass (imf27.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=1721300327; a=rsa-sha256; cv=none; b=MH5VHN8UAUR9OuS/CB5d2Xu+iRhi7QCcfoCgA6gNlKkJO9tOC05ZFlyPd4AjC7vUIJjDm9 zpsdThu8Rhd+WSU1jRcqZ6otwPsowQ0bsVkIghZ8oq9/ZKYh59AzpFdBm67wpBRb7iIww2 3MupqXqUOp9pjMU8ZzrhzihH6x4c1Ro= 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 DA05D21AF6; Thu, 18 Jul 2024 10:59:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300357; 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=S3eV4tzn99V5QCNtsrHXIAbjIOXiUl0vRGMsjIKRQw0=; b=UnjJIEr7+U+Yrn6jxxs3zgpZTb5TccLLns7pS78W/SYDCVTvs4A7gnL3OmtFUjvDi1S2wU lNxFD702yo/uvM2yCjGBBMeMjSk0NyaHmii5DSTOLypLmsSxCbVG6983rKJSa3ckiYTTvC 0z7Kh0Lm2g4IgLHNZtfEMCAtXyxpfYQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300357; 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=S3eV4tzn99V5QCNtsrHXIAbjIOXiUl0vRGMsjIKRQw0=; b=NbhZQkeVeCNXG/5vzvKd+hQQ5SapWr4Znt38EgWYmc+HQiaV0WXSpR3JdMor0elYCnFmiy jXbfPE4afZn32cBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300357; 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=S3eV4tzn99V5QCNtsrHXIAbjIOXiUl0vRGMsjIKRQw0=; b=UnjJIEr7+U+Yrn6jxxs3zgpZTb5TccLLns7pS78W/SYDCVTvs4A7gnL3OmtFUjvDi1S2wU lNxFD702yo/uvM2yCjGBBMeMjSk0NyaHmii5DSTOLypLmsSxCbVG6983rKJSa3ckiYTTvC 0z7Kh0Lm2g4IgLHNZtfEMCAtXyxpfYQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300357; 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=S3eV4tzn99V5QCNtsrHXIAbjIOXiUl0vRGMsjIKRQw0=; b=NbhZQkeVeCNXG/5vzvKd+hQQ5SapWr4Znt38EgWYmc+HQiaV0WXSpR3JdMor0elYCnFmiy jXbfPE4afZn32cBg== 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 D5364137EB; Thu, 18 Jul 2024 10:59:16 +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 UEFJL4T1mGbnVAAAD6G6ig (envelope-from ); Thu, 18 Jul 2024 10:59:16 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [PATCH 4/9] arch/sparc: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Thu, 18 Jul 2024 12:58:58 +0200 Message-ID: <20240718105903.19617-5-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240718105903.19617-1-osalvador@suse.de> References: <20240718105903.19617-1-osalvador@suse.de> MIME-Version: 1.0 X-Stat-Signature: g67oypw8bb3xsgi4f1cfxa5xw6tszbx5 X-Rspam-User: X-Rspamd-Queue-Id: 1E14B40011 X-Rspamd-Server: rspam02 X-HE-Tag: 1721300358-997867 X-HE-Meta: U2FsdGVkX19EcV9E7eKsy0uTbNLz5MdXU8aBIUqXFTxer/X5ais+Z8xJhzeyzGZzwuK9+UotyJoQQ/XNv+qz8xrVX4vqZkN2tPJJBS7tVtKPBWgwZIRfRQ//lzTT3EYV/ennB7L+RfoEYyBUlaPzgXb+71ZyceyraCLMko5z2A+VMO3nFgdPlDA+wuXCDsYwlZZRrbClDsGNugXXAtrvhCdBwSfL9xSWmBpDF9qYNxWe1SvDVa/EN7uNFKxGgwFVCO9chv/hD12jIct++TXPkqo7SGWs1XrT8gXQei68j5hNsZA8M4Dj0BKHGXGtsXtEoKb+3lSoLBGYhxU00PX0lmuajTLLY8HUluSmqBSHK1zazzJTRKQW9z/fe8iJiY1QoRjHNivKv0gjat1kSt2uZ/4WGujr5seYl871eVHUBoei9Onl6KqDe8f+QwRSEKVyZyHXcqon2Ukp175Fae3RQsX0bwkZSKUD9Yhaipr/jKH4+Tha8ngbJ57IbJiyi5uS0A9sLxCGVv/OyRc/KqXX0wkHZufggt9CVoIdedZnMaU4S6Sm+USyFC9rUS5gnohfeyXEiBFxvHis0UZkYKMbP+g63uP/8jKjwhl/W+G9AShLojmeTi6xCzsrr4IXf2Li4CF/N+dhSD5ia40NPnmCk2R7nxwTKYi8fw7otnc3cHZBeq/w120QRXaNz8pNCMYg64u9zIPpDgQcqRs8bj2CfJXgMGv+R3k9CV9UKVV+00OShJjDa1iQLC+cz4sTYyphQP7j8wJgORs05EJJY6n3El2JO5ySzlmwoIN67K0rGwRxdLIdF9rwUcxV8KX7A3O5RQzKljbyKulstv13X3aMjLb+d2TTle1AJrrk1KuxxXPTCbZyRx2UttEzx3h6O1x6H9em/zQsjTT1wDrgMVL9QPeKTpVm8pWH6q8QfJiumPLv7Ig7wUanc+2ZUGGb4iZ9WiW10fSg5JZcB56YKz7 UMOWh3Fq cI/JUvU6uFpq72wmhzf1ynz26pHOYvdXeCThxA7frX3DiL3CY4qYXuufMQE2MDHGEZrMmYBTzvJ/CdhnC82WrAiIlem05ktkbhj1J/oNq+cEUiKtp2OWGmGoRdOEJleJMjvlueRfT0Hbx3AquC6e23WBzEs1Dk1c7HmWEEca5lahKLi94mjntr3gmH+lZgKreSRzsKLL8tUo89YY8dAzovcYrExm0yYrPAIO3L9YImLyzxtq9dtEPsgKTh8a/pLqiftFJuQm1Kvnub46wzMi9ClywBw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area{_topdown} to handle those. sparc specific hugetlb function does not set info.align_offset, and does not care about adjusting the align_mask for MAP_SHARED cases, so the same here for compability. Signed-off-by: Oscar Salvador --- arch/sparc/kernel/sys_sparc_32.c | 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 Thu Jul 18 10:58:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13736390 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 E5535C3DA49 for ; Thu, 18 Jul 2024 10:59:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 201246B0096; Thu, 18 Jul 2024 06:59:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B0B16B0098; Thu, 18 Jul 2024 06:59:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02A696B0099; Thu, 18 Jul 2024 06:59:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D227E6B0096 for ; Thu, 18 Jul 2024 06:59:22 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9298D1A1AE4 for ; Thu, 18 Jul 2024 10:59:22 +0000 (UTC) X-FDA: 82352576964.15.D1C8C96 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf19.hostedemail.com (Postfix) with ESMTP id 5F74E1A0025 for ; Thu, 18 Jul 2024 10:59:20 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=d+qT7m4R; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=RfoQg8un; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=d+qT7m4R; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=RfoQg8un; spf=pass (imf19.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=1721300340; 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=hZh5aoiceQyAWYDBybNaHpgAQxfK9WhW2gk+fDxbQqCLQHGOGCXlwU1C2xH9nYqaNnW1Gv 9AryP5N0yy2pRRmgHHqpqLApvJ75i38ROQ5b5gR1ZYqTfYXBWgs+kDQBb29ULaatqeVgBB IZrz6OB5PcNsP2i9fldQ4pS/fhuz2eY= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=d+qT7m4R; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=RfoQg8un; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=d+qT7m4R; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=RfoQg8un; spf=pass (imf19.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=1721300340; a=rsa-sha256; cv=none; b=pkWG/kL7PPA3sfdeulNyzrj2kiw4dLh7hHPhvLI2EDAM+0gqSkIwzEx+BEHdHDZZmcdX/Y qEsS300LPOLDYpuSwNIQ5oIsrO0rYhldC+dCKpeGoZMYnyQ9sLvVpb6wnctrnYVQ13LvMU /duMKksxKgAd9Jmv9P+zn9rFCJYC4bo= 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 11B8E1FBB9; Thu, 18 Jul 2024 10:59:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300359; 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=d+qT7m4RpuC6EVZ9Nq36ak8RH1R06p1MZpQhX6/5OnJrFM+TMzDEbOlYJOnnMf53JQ18gA 6UO8ijGQ+RQrVs6wlAdXj/I+G+awA3+FT+wBSvbQpEUb1Hiao8qP1zqiFXlZMlXyc5NW6K Pqi+YricO9OYQ9/hVMHCN1yOZemWs8s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300359; 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=RfoQg8un5zhYCA7bHCAPVoc/BT3n427oAmpgk3WAUkd672G0mnyM+WWXJUO/6+8Ksk08Cc f4O3wWrTNuyEuUAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300359; 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=d+qT7m4RpuC6EVZ9Nq36ak8RH1R06p1MZpQhX6/5OnJrFM+TMzDEbOlYJOnnMf53JQ18gA 6UO8ijGQ+RQrVs6wlAdXj/I+G+awA3+FT+wBSvbQpEUb1Hiao8qP1zqiFXlZMlXyc5NW6K Pqi+YricO9OYQ9/hVMHCN1yOZemWs8s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300359; 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=RfoQg8un5zhYCA7bHCAPVoc/BT3n427oAmpgk3WAUkd672G0mnyM+WWXJUO/6+8Ksk08Cc f4O3wWrTNuyEuUAg== 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 07B60136F7; Thu, 18 Jul 2024 10:59:17 +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 kCFWOYX1mGbnVAAAD6G6ig (envelope-from ); Thu, 18 Jul 2024 10:59:17 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [PATCH 5/9] arch/powerpc: Teach book3s64 arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Thu, 18 Jul 2024 12:58:59 +0200 Message-ID: <20240718105903.19617-6-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240718105903.19617-1-osalvador@suse.de> References: <20240718105903.19617-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Action: no action X-Spamd-Bar: / X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 5F74E1A0025 X-Stat-Signature: p7n9xm9wmep6nmhrzgyqixr3c8ogwkm8 X-HE-Tag: 1721300360-775611 X-HE-Meta: U2FsdGVkX1948kh6V8lrhtqo9vKoioRxxGc2XwKlO5DvX7IADfHa82ZyFMcBgMFpVzNxEvwoSNqoGQz5aGSWXkazoh47vcv2KpQf+U0SbEhspGt7hJeYzvFTL01QRB+L38eP9MFQCpfjSRbGUYT4Q0FYLUOCocbmNTA3r1NMvExQRS+SPzocGVPZDpslQNZjO+VRfEXOKqqQ1bIzVm78iqJ66/sf7G/eZo32vwJzGGyKY0RZDBMWil8+NC2ops1wJVA6EzzvFNLTINb2PQ2oyxBGkMjosHSq3GqEl9OrjAu61sGXpa78lNM9e+aSF2ZEpg1DJNEb+S5oc784Zu/irADtK05jm/QyGmd5aNOA6uzsAsa90jSCtmUV2/EvHhvEGpfa9zUi8dtsfJrMTd8Nwd3teztJ19fQh8nOoT0HwRE9yxhRkVvYM9wsbUzP/qk9VSxACQf85Erfijo9fUaBiRAPxHmxDHLHrk0AQdVoNt+01VblIDppiVFYkR8iX2z5qrYH7vLsAXThvX1pBzOyFO4P+LRPrcaYQuyku2sqssWoAG4J9+qbNM034GxMAwLYDQH6JiSqaKKXkauRzY89/Py92RT9cZgIvVEC7Gmr9ygu5JwfqvdODIt04Ylvmksy+nYQHt08zmuJ8CARs713ZA7DPNiwi4FEkrE672QXbK2PpdMAyErr+xGakKz+KFqYS3muh/bn8WzQ36eKWIr/+LPARy87uD9/ox4lP4so2UcXDS9Y4aKX4BLllG8ZLHPqXK3j79khC8U7/Ci52kcYWhr9nbZE693vvvikn5e7O5Kun2vDXhmzVSYE9vXnFKyspmo9BrvbyMz+UpuFe/hJs87UbIniB80LVt/jsrsdcV1LKoy1lUAJKFibYXLmTGGdTri9nh8kXyNcP5onagaEvpkSMWvm6urh4CcBycFbNHECwIDSkfG/KS3PuA9KBxebOzw+kHyGOsXFuKHcBNS 3xOy1H3K cXF+aUWHIMOX0pDWMqHd3+sOd+QvAYIgQBtpWdMJ3SeeSBSdeC9BztTMUjUbzFNL7qQLe4UKBUHYOKuSmuTAqwUJ5ipjh/ClgxvAb00SSRcbLGdKSUadaiYin5vPgTY3QYlxXGEVha7hipVIwziWtGm7liT4kDPwDZU1Rp5VKw9XXbutIPiTsyBeAUTa4wApHN8KukrVECODKX7AwlHfkI/SLEqqZgPjecNk6b+H/iCvfDs2nIMKdNIVFhVkfx3VBrJJfEJTzHq9qVL5CTHPaX5V7vkf085DWIC/j 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 Thu Jul 18 10:59:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13736391 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 24F1EC3DA49 for ; Thu, 18 Jul 2024 10:59:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D6276B0098; Thu, 18 Jul 2024 06:59:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3862A6B0099; Thu, 18 Jul 2024 06:59:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DA556B009A; Thu, 18 Jul 2024 06:59:24 -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 EE4806B0098 for ; Thu, 18 Jul 2024 06:59:23 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B4A5B141A02 for ; Thu, 18 Jul 2024 10:59:23 +0000 (UTC) X-FDA: 82352577006.28.B8A60D2 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf14.hostedemail.com (Postfix) with ESMTP id 7FEDE100011 for ; Thu, 18 Jul 2024 10:59:21 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=z5eI1VcQ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=X4rbEJ+Y; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=z5eI1VcQ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=X4rbEJ+Y; spf=pass (imf14.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=1721300320; 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=6sPGyH5z7l/pm0TX/hh9KWyWWpcRI/yb9hB1nzYK2f0=; b=ttByvhrTeGkqZtNsF+3/MlLUnK69A7NPJ1eTlBBD+e1Wv6M+ZQFQCV4I85fzykgyDJXXrW 1RseJEeK2wzmhFovh6v6CblZMg1oYwz7dlUtZF/WmW6nNoF9MbxpNfratwwebjMZ7HvctP U0/Pzjly6PMYFW5TBP17O/kJqnbXaiQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721300320; a=rsa-sha256; cv=none; b=XiIKbE1v3/N2bK7lRzRvXLi4r9zuvemkRjTE5uiI0LVeDAV9tqoWbPAEqjy7rcvnzRe7/p a1qcttduuh1Nf7avxY5sZeMEr2IabgBw9YSKLE6pODObmq4PrnxedFMR4TFBK9Kctem0+y jQUZPUFUXyrUSgjdrTVh+0JlqqkNs/Q= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=z5eI1VcQ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=X4rbEJ+Y; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=z5eI1VcQ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=X4rbEJ+Y; spf=pass (imf14.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 (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 407C91FBBE; Thu, 18 Jul 2024 10:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300360; 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=6sPGyH5z7l/pm0TX/hh9KWyWWpcRI/yb9hB1nzYK2f0=; b=z5eI1VcQIrnLNx2Z0oK330o9OEByJyUoURwS49Ys44trBlZ/l7ix0vn9EWT1GWuyZGhjUs r2LtEo47jmzw0u57xl9/9M8Q4UxrQIwAjGjEYaGcxEfach1ESHp437POhkkzYPZCF5ZD9y Y2LHEodX4at6FpHiaDavKdKcccmTfqA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300360; 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=6sPGyH5z7l/pm0TX/hh9KWyWWpcRI/yb9hB1nzYK2f0=; b=X4rbEJ+Yn1vnB9FjpFiteKUi4ZJqJ/ZU1kpljjScD/+NNRgV18aVF/aYxaHV6hClFIckw8 3Yf5i9Bv93dYvSBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300360; 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=6sPGyH5z7l/pm0TX/hh9KWyWWpcRI/yb9hB1nzYK2f0=; b=z5eI1VcQIrnLNx2Z0oK330o9OEByJyUoURwS49Ys44trBlZ/l7ix0vn9EWT1GWuyZGhjUs r2LtEo47jmzw0u57xl9/9M8Q4UxrQIwAjGjEYaGcxEfach1ESHp437POhkkzYPZCF5ZD9y Y2LHEodX4at6FpHiaDavKdKcccmTfqA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300360; 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=6sPGyH5z7l/pm0TX/hh9KWyWWpcRI/yb9hB1nzYK2f0=; b=X4rbEJ+Yn1vnB9FjpFiteKUi4ZJqJ/ZU1kpljjScD/+NNRgV18aVF/aYxaHV6hClFIckw8 3Yf5i9Bv93dYvSBg== 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 2F5E7136F7; Thu, 18 Jul 2024 10:59:19 +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 YEPXB4f1mGbnVAAAD6G6ig (envelope-from ); Thu, 18 Jul 2024 10:59:19 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [PATCH 6/9] mm: Make hugetlb mappings go through mm_get_unmapped_area_vmflags Date: Thu, 18 Jul 2024 12:59:00 +0200 Message-ID: <20240718105903.19617-7-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240718105903.19617-1-osalvador@suse.de> References: <20240718105903.19617-1-osalvador@suse.de> MIME-Version: 1.0 X-Stat-Signature: byfsuwuee6aqzr5n18c6qt1jqognx45j X-Rspamd-Queue-Id: 7FEDE100011 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1721300361-713546 X-HE-Meta: U2FsdGVkX18PuGJUv6DG6vVn18Bwn54L7+bFAlXdYPFB0Qyw1kSyqsAFaShZOcBDMiehUVsxU9bQfG2uWag18vc0NYH1ncU3lrmwq4+PnZ8IZ5KS2U39u6xKBo3ARVn9yDR91G9SUWEMVlKixuJG+rb8I/fvUHTiGmu75YH3odAbm6bt3v7HMOizDpXRdosUNAcUVFjgvwtSgIMfGshd5OrKwbHTATrtIMczmiPiaNihhxRscFGcQ1FeewbmYrcGinsEwj9jTlV1W2ad3h2ArzSrfKSf4WW3ec5XTpO28pRdX1/qj7217cwvWuwoGExpwv8SwXDiazOlMnLXg4Jd6OPoqFnv0zECwGTV0naneHgG0dXctGvSLg2y6Tttye+EpXHCCUdo2UlN/HUQELXVO2rzyg6WWrF2lS2oypynPKpY5OgZzPhLiSZgwZtxHt+qVGksWRT05/TsvW2gJOecnFW5JvD9XgnPX1y3qtl5nLxuR/YBzvIv8eAxBIpZqLfbs9hMp2uCPZwSthn4+NsoqFS/9D3/pI1cJMmVsri9H3JgJaSHX5eAKYwa+xjg/83hLiE2/bxDlLc6LT9rwo+4Dpf6iL1+T2Z9O9v4lCgnxZJQA0GeCrwRPqjYWdd/vNE8QpDGSyibayEl/YRiOGfHhKlLL9/xL1A+uXNd6U7tjrra04P9TN3l5oKVhkSbm/tgnFz9Zrzp27eOoyPt7T8YWf51FRaMq6RlwR1DEj/sSeN1wmDmuIPtcn9ZKrP4zi5L+N85q/5NL+E/lWBM9a5a9NqaidPpBgH7zWAySgeTHvKt7BpXf6o4/A+a+WRYpj3WgVarcZbMPcQHenyHrp0nVnWxRUSMWuihwKuGbHMqvNqDbnW5ns6HT9ASErprvfGrlT4eIYJOQg+wJ+TzdTxe5xb4HJicV7jvdCVx+R/kWSGc4fg9Vvct1oHKDU7rCYM8aXh/o4a3XO1iFawwZZf 1dZyjQSf +/bFU0LJNQzsDfKmOvC2w9DRwlHiRslgzU3HMl5ZovVk+Xzl9hWy2hwgNR5EWJj0qmlO7QIzShbY2oTC4uJF0E4sLrBCqva4eJ8JjcbSN5WaIjJVwYRNowL3uNa/wMTRs8ZqwysC73JNIdww62QuQ3MwLRxpYVTar9b7C2x/ZpLHDFm4ozVyNL96OK8tfAm2eHHbYDBbxZoygxyMJOK8VW4qXNNk9bf0BVzcxRi90F5ttl4v3OEdK8bTBS/Ua0zd+yXmcsRCGxNxfHxSCwZNzpSXCPQ== 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 81dab95f67ed..d02b4bc6c5e9 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 Thu Jul 18 10:59:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13736392 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 1ACCDC3DA49 for ; Thu, 18 Jul 2024 10:59:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B51896B009A; Thu, 18 Jul 2024 06:59:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFF4D6B009C; Thu, 18 Jul 2024 06:59:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 952356B009B; Thu, 18 Jul 2024 06:59:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6CBF86B0099 for ; Thu, 18 Jul 2024 06:59:25 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E6D891A1AE9 for ; Thu, 18 Jul 2024 10:59:24 +0000 (UTC) X-FDA: 82352577048.20.5B63CBE Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf20.hostedemail.com (Postfix) with ESMTP id CA13C1C0010 for ; Thu, 18 Jul 2024 10:59:22 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=0BqZ54Zw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=3+XbXImQ; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=0BqZ54Zw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=3+XbXImQ; spf=pass (imf20.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=1721300322; 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=ARCGlBH+AErS8v8bA8FKvTTqiUoGdHpGs2CLrGa0UzE=; b=cQDM5SPKOM7M9IhFFK3ex5/2Wvi7IqwIoSM8NY/SVq/UG8PyYkE163gG3ImqFkOD3Fci9D YLoccJExDMnUVIk2bQ2BMBoi6papxunMOr/5sClgI29rROQEym8m6T6Pnqr95evk70Efn+ a//ZnkvMIv2s4a7Ahg4uNwSPZA07dYI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721300322; a=rsa-sha256; cv=none; b=Spjq1e7kVZhTEOM70YLhX7TyZlKlSFaGCZdoCb7MysPLdjbnackxpZgijZ34kr1D5JZbjY SbAQWck6Dxj/AxsgUJEMI6wIx0rX2E/LPXKt14Ymuz8ekZ/L8k9NL9nZl0Y0yo1W+4+3oN X/AlbNa/bUs1nIizQYzTkdsLrn6utCc= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=0BqZ54Zw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=3+XbXImQ; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=0BqZ54Zw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=3+XbXImQ; spf=pass (imf20.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 (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 789DF1FBB6; Thu, 18 Jul 2024 10:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300361; 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=ARCGlBH+AErS8v8bA8FKvTTqiUoGdHpGs2CLrGa0UzE=; b=0BqZ54ZwKBBe20BdIk0KLtnLclnG8vutmLC2UoziN9moLue+NCej2qJbUunAsIM/I/sPAF x5q5b7Hrkag+a5RNvj//GbJpnpyCGvxvRdgSLRs3deMS0DSxkyvd8IU1IGSt26gLxs4iMd xjDZM4qG5biNC4dHmaJpXf5NhudzX8I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300361; 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=ARCGlBH+AErS8v8bA8FKvTTqiUoGdHpGs2CLrGa0UzE=; b=3+XbXImQeSNN+5dnreGiTedzW+WLgV8UEQMOxsVdE3MgrleO7d7TxUt1rUHi+pMV6GNW0K nJm1JGT6M9RbtmAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300361; 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=ARCGlBH+AErS8v8bA8FKvTTqiUoGdHpGs2CLrGa0UzE=; b=0BqZ54ZwKBBe20BdIk0KLtnLclnG8vutmLC2UoziN9moLue+NCej2qJbUunAsIM/I/sPAF x5q5b7Hrkag+a5RNvj//GbJpnpyCGvxvRdgSLRs3deMS0DSxkyvd8IU1IGSt26gLxs4iMd xjDZM4qG5biNC4dHmaJpXf5NhudzX8I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300361; 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=ARCGlBH+AErS8v8bA8FKvTTqiUoGdHpGs2CLrGa0UzE=; b=3+XbXImQeSNN+5dnreGiTedzW+WLgV8UEQMOxsVdE3MgrleO7d7TxUt1rUHi+pMV6GNW0K nJm1JGT6M9RbtmAg== 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 70EBA136F7; Thu, 18 Jul 2024 10:59:20 +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 4BqjFoj1mGbnVAAAD6G6ig (envelope-from ); Thu, 18 Jul 2024 10:59:20 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [PATCH 7/9] mm: Drop hugetlb_get_unmapped_area{_*} functions Date: Thu, 18 Jul 2024 12:59:01 +0200 Message-ID: <20240718105903.19617-8-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240718105903.19617-1-osalvador@suse.de> References: <20240718105903.19617-1-osalvador@suse.de> MIME-Version: 1.0 X-Stat-Signature: dutaifeaqkt9hk6exqyo9ttyzsoya4ee X-Rspamd-Queue-Id: CA13C1C0010 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1721300362-538739 X-HE-Meta: U2FsdGVkX19NVJqRofWx+Gj/0lCqMiSe6aVxP+hC3K5+cihIkdncbiL6Al9tMhCxBZQTD1WL81apA1BQ6ryorUY+CRhgB8rmZWX+l+OAWJFPu1uVFQM0AP+YOtSVNoYS/KbKFDKnMFC4zAI/6DZJyORsNbacywM6NhnfkR2pFTGvHDws/N1igdXJDE15iZT9Rb2o+GF8LNPvJ8C922+JggJPLOzPesCD8P0qcumdhCrjAWWWDSWt2l2+TXOQkjw219h3PZbOvww9wi0HK0UqNQ40OhQU+j/1EDLhrVKtfIU/7M5rqPitCo8LQo8QmBHR0I0JjuGhlg4rJrgDzfmwJjzuSjr9ZayHCKx5tijcitx2h69G8LPLAiH9qcpYytXgmycdluBMnu1SiTMFRZ/z1EmnP8t+7k16firNKwjnGqvat2yg5TCoEBIP+iZScQYH5uix4ogi56QEQdHDOob55/HtUY0G6C0wzXU850K7JX8EZrIgdh0rSWDKMaqVHX5MWfOjgLidHxw9l6OLBM8oRme/A4uORQobfdnMIDYth43Om7TmOxBAUqf7kqtVxvPcgGGHbrypyhylteTWMi2F/F4TK7n2GigKxtWhTMKKfY/WZflm3L61IHIFYmlMWHh19iVm2HleP/CDEOGMoeKQx7kTarm2HKCwgGlCPORPeHRJ7oTnVJdKxTpOSHp18sn5u22ABaeuIO0h9kqrnp32GnjgieNnalDqIBsSFBnZo5m5k8jH1pYG/V61aOCcagHKYFVMjTKuC2XX6jjNa8hfOtkNdnyxlqlCiBGE7VMgBgRoRmSHm1dFbmjfuh2KCeVPUDjcxO50uL4sqE3JfxhAyyLnouDJkFUKwNqSNfOOJG+EGo7uur03DiekJdC8C4ZfGS3ln1gfIW8goOFJTM1rVnJi2/vYn4t9QrRK8e13eBhbgMuZy/uyo/B0krgINL8uKpobRRG6I//JVQzKi8j +gSok57x xkbK5cnexNRVUTGBUG8Tiq+eRGa2EaY5UCHrB2nywJjR4Dxxt0m8u+7iePtNi2f6MoFVlq1z8Y26xZW/PTqHHS5H5Pz5B/F2tBHjP4TSuFYCUCEPdxYymFqILsM4ivafvo+lj3lQHQkhKHTDGgirSwiYqYpjD6NPuw8z6DhWJIvrXSfz8hwL5KwjsTezqwSYVBOzjE5rjcUJxzfebUu3hSDRsz1a5dNk276f93fcuTr4X0JlcDF2In1NP4DgmkUhyV5gy1XmgaSxJ9xSMqueLy8qDU9vfW+EjrYeM 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 d02b4bc6c5e9..4902220adf42 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 Thu Jul 18 10:59:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13736394 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 D4551C3DA49 for ; Thu, 18 Jul 2024 10:59:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C5E06B009B; Thu, 18 Jul 2024 06:59:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 204F46B009E; Thu, 18 Jul 2024 06:59:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 003A06B009C; Thu, 18 Jul 2024 06:59:27 -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 BD2BF6B009C for ; Thu, 18 Jul 2024 06:59:27 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 819BD1A1AF0 for ; Thu, 18 Jul 2024 10:59:27 +0000 (UTC) X-FDA: 82352577174.18.5FCE15F Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf04.hostedemail.com (Postfix) with ESMTP id 5B31740005 for ; Thu, 18 Jul 2024 10:59:24 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=sFCULHDi; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=5QSTbzcB; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=sFCULHDi; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=5QSTbzcB; spf=pass (imf04.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=1721300323; 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=uA6OghgZH0iRGnLvFrby5KN/hDL1p1cPRMCb0kQhP1A=; b=GhdNNvRoN/3fEGFVAKJ4G+Fx1mjOQYxfcWKe0KRvZbEcT3nCK1UVmRottJC7FOLZOM4+bJ plpH39v9sq+8s9T0RaebQU6eWfMNWgNfihpKs7opxxZ8YIsR/g26RUZP5NpDgb30vE7jeZ PwjBC8MzVsXBbZoHiWtN8osswKWUZcA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721300323; a=rsa-sha256; cv=none; b=o0P9KO6jU7lMLLPb8/RUpzQ+uF8R2SoEPLr0D5V2rJzFNou62Om6XkwLmyA2zgT7LEwWTS TPU4I8T12nwX3+aLX9G9FEpjVni27g3YpZyn4hxvKYhrDqHVM26pIvGniyiZJcxWEhtxZ7 RB3nksMMfIvJ2pPu0omsqURmNZCmi1c= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=sFCULHDi; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=5QSTbzcB; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=sFCULHDi; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=5QSTbzcB; spf=pass (imf04.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 (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 BC3251FBCD; Thu, 18 Jul 2024 10:59:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300362; 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=uA6OghgZH0iRGnLvFrby5KN/hDL1p1cPRMCb0kQhP1A=; b=sFCULHDiYLCidOxZWgtfh+8VF1osEgqzbFRVwpMV9QRjNlbaZ3kT8iCeHMxAJ5Ws8ceVFG crJawzL+uzhe8HxDL94Smc0nLVnBgybmnC3WTBa8z75qmnOu06PefkJVJDi0r3AGR7lm3O bDd4hTQNl5F0P1anhubvcKH3KCVrjjs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300362; 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=uA6OghgZH0iRGnLvFrby5KN/hDL1p1cPRMCb0kQhP1A=; b=5QSTbzcBcLeISf+fa8flAihLmfARAv/AUKET9MsutkpyhqD68D3LrgM4+taA+r4HbIPTo5 nU2ZnLM9vGHpwnCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300362; 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=uA6OghgZH0iRGnLvFrby5KN/hDL1p1cPRMCb0kQhP1A=; b=sFCULHDiYLCidOxZWgtfh+8VF1osEgqzbFRVwpMV9QRjNlbaZ3kT8iCeHMxAJ5Ws8ceVFG crJawzL+uzhe8HxDL94Smc0nLVnBgybmnC3WTBa8z75qmnOu06PefkJVJDi0r3AGR7lm3O bDd4hTQNl5F0P1anhubvcKH3KCVrjjs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300362; 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=uA6OghgZH0iRGnLvFrby5KN/hDL1p1cPRMCb0kQhP1A=; b=5QSTbzcBcLeISf+fa8flAihLmfARAv/AUKET9MsutkpyhqD68D3LrgM4+taA+r4HbIPTo5 nU2ZnLM9vGHpwnCQ== 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 9C885136F7; Thu, 18 Jul 2024 10:59:21 +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 cFt8IYn1mGbnVAAAD6G6ig (envelope-from ); Thu, 18 Jul 2024 10:59:21 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [PATCH 8/9] arch/s390: Clean up hugetlb definitions Date: Thu, 18 Jul 2024 12:59:02 +0200 Message-ID: <20240718105903.19617-9-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240718105903.19617-1-osalvador@suse.de> References: <20240718105903.19617-1-osalvador@suse.de> MIME-Version: 1.0 X-Stat-Signature: 8sth9kcp9awdpn6zmds5x7x9qcg5yw5j X-Rspamd-Queue-Id: 5B31740005 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1721300364-434085 X-HE-Meta: U2FsdGVkX19dIeoT0KmNhkca2+XbS1Zmw6wfb0AqboBy5I7LKWiDGfiwL5afPgzU0QX49Yu8fP6R33fMhhHUtge+ZlYy6Lw4KhepaJ1h/8RZSYtLh0J85aH3eDU/A3xvma0FSphw6MjgziFCGnigdVjf21P73pSUDm4ufQsfNUwVp40Ug+lHLl/vSxtJlzBtEDYC3CmiJcaZ1X6l8LkayDfzuSWA/A+EjSxiErLk+f4L/hF6lxylv3LJ4FA9VzqC3tpeBFMUqKr3yVeNyO2tlRhFsAXCCNqeZeLqlNYxRcljt/8Q2qzDm8Tv5jm7A1EyQRTTiAvRNPwX4PgAd+KlcGd1ZCUtCqs/7s8WLrmjSYQOgjkTnK0ZH7MEOpOJJT8PgQAHjVSlBXaVzHoVWxBJ4UWtfV0l7bGGwDYIXbPShPy7CYtdO/WOtySuykyvBtA1QK3yIhgJThNRkFk7gncgGIyXANIdcK695icI2ZyK8QUi1ciXuX8kvunOrkDW50h9In+J3pZfo+emYzOBm1gy1ujAguyEdDtdLBnvLhIaVlcao5U5mOQlq0pHEoVSEW8in5+zSb9efrKtUkhhYWacLUKHZf6TmAu2V8IoJgVmpEhOpiCIoWb3CCGwpe07dnTenQxk/niTz4XTSXMpntSfaCQvVjAj8JmjYVMhPVCmopUAxCRLmFse5GOwbDzagmXMsPX7Gqz5taqlvv3Cn0t27pamWA2bSoF4laYI0GvfkIXZzwgLI95chC5dq3b2M/ThG3oE2RWUvploVJCBz+Xk2h9/SPu3fPkpVDnVx39wEV8Ep97H1Qg/IyalBT2rjCgtjdlhVDIwr8TWAmfRyjDjb6XqPL9U+vrIu63xBQzlLcOPC84M+izjSLHYNEnqdzr4N6LzeIuNsc5j50+kOET4fruqEw2CG4RLt2NNz3rlf/L0zP7+nEgO2OwGLspbYBBGV5afg1bD7wzA5vkASaM Zt2xeNbZ IsFfmqL3nT9DikfZSIcyChZ4satWqWf8Yb62uAy3phPlV2zhF9XFct1HqJjv7wUhKASpzqT6nk3tzDky82ZsP9m3m3vKvH6CA91JgkctuhIwMm+irBHRMgAve4ysAv/0El2jpsxm22P7JwL2Nh6/AiaQQAytfj/Y0OfuFn/w1WIP5YUQ1JpGkn6ZIxCUYq/UKbaGeZQv4MOKkDrJvzjXXF7SZG6v0hnl3scCdOa1mQslJKmM= 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: s390 redefines functions that are already defined (and the same) in include/asm-generic/hugetlb.h. Do as the other architectures: 1) include include/asm-generic/hugetlb.h 2) drop the already defined functions in the generic hugetlb.h and 3) use the __HAVE_ARCH_HUGE_* macros to define our own. This gets rid of quite some code. Signed-off-by: Oscar Salvador --- arch/s390/include/asm/hugetlb.h | 58 +++++++++------------------------ include/asm-generic/hugetlb.h | 8 +++++ 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetlb.h index ce5f4fe8be4d..f01b101c80b7 100644 --- a/arch/s390/include/asm/hugetlb.h +++ b/arch/s390/include/asm/hugetlb.h @@ -12,21 +12,24 @@ #include #include -#define hugetlb_free_pgd_range free_pgd_range #define hugepages_supported() (MACHINE_HAS_EDAT1) +#define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte, unsigned long sz); void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte); -pte_t huge_ptep_get(pte_t *ptep); -pte_t huge_ptep_get_and_clear(struct mm_struct *mm, +#define __HAVE_ARCH_HUGE_PTEP_GET +extern pte_t huge_ptep_get(pte_t *ptep); +#define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR +extern 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) { @@ -45,6 +48,7 @@ static inline void arch_clear_hugetlb_flags(struct folio *folio) } #define arch_clear_hugetlb_flags arch_clear_hugetlb_flags +#define __HAVE_ARCH_HUGE_PTE_CLEAR static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep, unsigned long sz) { @@ -54,12 +58,14 @@ static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, set_pte(ptep, __pte(_SEGMENT_ENTRY_EMPTY)); } +#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) { return huge_ptep_get_and_clear(vma->vm_mm, address, ptep); } +#define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte, int dirty) @@ -72,6 +78,7 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, return changed; } +#define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { @@ -79,69 +86,36 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, __set_huge_pte_at(mm, addr, ptep, pte_wrprotect(pte)); } -static inline pte_t mk_huge_pte(struct page *page, pgprot_t pgprot) -{ - return mk_pte(page, pgprot); -} - +#define __HAVE_ARCH_HUGE_PTE_NONE static inline int huge_pte_none(pte_t pte) { return pte_none(pte); } +#define __HAVE_ARCH_HUGE_PTE_NONE_MOSTLY static inline int huge_pte_none_mostly(pte_t pte) { return huge_pte_none(pte); } -static inline int huge_pte_write(pte_t pte) -{ - return pte_write(pte); -} - -static inline int huge_pte_dirty(pte_t pte) -{ - return pte_dirty(pte); -} - -static inline pte_t huge_pte_mkwrite(pte_t pte) -{ - return pte_mkwrite_novma(pte); -} - -static inline pte_t huge_pte_mkdirty(pte_t pte) -{ - return pte_mkdirty(pte); -} - -static inline pte_t huge_pte_wrprotect(pte_t pte) -{ - return pte_wrprotect(pte); -} - -static inline pte_t huge_pte_modify(pte_t pte, pgprot_t newprot) -{ - return pte_modify(pte, newprot); -} - +#define __HAVE_ARCH_HUGE_PTE_MKUFFD_WP static inline pte_t huge_pte_mkuffd_wp(pte_t pte) { return pte; } +#define __HAVE_ARCH_HUGE_PTE_CLEAR_UFFD_WP static inline pte_t huge_pte_clear_uffd_wp(pte_t pte) { return pte; } +#define __HAVE_ARCH_HUGE_PTE_UFFD_WP static inline int huge_pte_uffd_wp(pte_t pte) { return 0; } -static inline bool gigantic_page_runtime_supported(void) -{ - return true; -} +#include #endif /* _ASM_S390_HUGETLB_H */ diff --git a/include/asm-generic/hugetlb.h b/include/asm-generic/hugetlb.h index 6dcf4d576970..0b89d36a4310 100644 --- a/include/asm-generic/hugetlb.h +++ b/include/asm-generic/hugetlb.h @@ -42,20 +42,26 @@ static inline pte_t huge_pte_modify(pte_t pte, pgprot_t newprot) return pte_modify(pte, newprot); } +#ifndef __HAVE_ARCH_HUGE_PTE_MKUFFD_WP static inline pte_t huge_pte_mkuffd_wp(pte_t pte) { return huge_pte_wrprotect(pte_mkuffd_wp(pte)); } +#endif +#ifndef __HAVE_ARCH_HUGE_PTE_CLEAR_UFFD_WP static inline pte_t huge_pte_clear_uffd_wp(pte_t pte) { return pte_clear_uffd_wp(pte); } +#endif +#ifndef __HAVE_ARCH_HUGE_PTE_UFFD_WP static inline int huge_pte_uffd_wp(pte_t pte) { return pte_uffd_wp(pte); } +#endif #ifndef __HAVE_ARCH_HUGE_PTE_CLEAR static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, @@ -106,10 +112,12 @@ static inline int huge_pte_none(pte_t pte) #endif /* Please refer to comments above pte_none_mostly() for the usage */ +#ifndef __HAVE_ARCH_HUGE_PTE_NONE_MOSTLY static inline int huge_pte_none_mostly(pte_t pte) { return huge_pte_none(pte) || is_pte_marker(pte); } +#endif #ifndef __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE static inline int prepare_hugepage_range(struct file *file, From patchwork Thu Jul 18 10:59:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13736393 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 96052C3DA49 for ; Thu, 18 Jul 2024 10:59:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0073E6B009D; Thu, 18 Jul 2024 06:59:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF6B56B009F; Thu, 18 Jul 2024 06:59:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6D026B009E; Thu, 18 Jul 2024 06:59:27 -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 A45286B009B for ; Thu, 18 Jul 2024 06:59:27 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 54060121A47 for ; Thu, 18 Jul 2024 10:59:27 +0000 (UTC) X-FDA: 82352577174.23.F80774F Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf10.hostedemail.com (Postfix) with ESMTP id 2FBD7C001E for ; Thu, 18 Jul 2024 10:59:24 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=i7YlcF6j; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=zUWKNZPd; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=dNFZLmEG; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=q+V6AbMK; spf=pass (imf10.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=1721300345; 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=RffRCKVkf4tOMl6I565jAg9VCZIGD0dLIYK/HF2buBQ=; b=3KD0W1WyfapC/WLDnVoWC6/On1wzzXIEdVrtR6RXigHM96REbWCwl5OOHbmd56WvykXpVb vf8YANPxen5JVjCDtPtMJcioZ3Dt0qS0I8KLkLYz5tiu9xg4PIyAT/+yAdcUb5Q7vjN5C5 k6o0LS1Hglx1vQzd0b+/SP/WYfrnRp0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=i7YlcF6j; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=zUWKNZPd; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=dNFZLmEG; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=q+V6AbMK; spf=pass (imf10.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=1721300345; a=rsa-sha256; cv=none; b=0E9CQEeUtblQNqlVchXFKf9ApyrB1rwEOpQU6SPOI4Ztlki1B5D5jTPSyBqlVZOEb1H6yb rMw9vNM+Ohio1yEEX28Kqr6ydcwHcn+/50p/PsQpGhMsly3kFnIp+3Hf9yUE86vlzaNxCz qYW+Cf+zO6QARj5v3X77eZ8ZtiTgYho= 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 DA41721AD8; Thu, 18 Jul 2024 10:59:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300364; 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=RffRCKVkf4tOMl6I565jAg9VCZIGD0dLIYK/HF2buBQ=; b=i7YlcF6j7N95/M1bzdjQk/afWpIjGNnzYBM7IKxJRilPCZADsZR+KAOy5MPqVuth0UC3TY VYbeTdWmkl+pGUD0B02lHJKDykyJ4mHqRy2ei6PELxhKkgMVbqk+zBvdeVIxHX5Pmx6PzB /clXhZ28nwy4pf4/mEKapyjVALPXJ4I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300364; 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=RffRCKVkf4tOMl6I565jAg9VCZIGD0dLIYK/HF2buBQ=; b=zUWKNZPd5+IxiEQPxQAclcXFDg9fvY1JH7A4xLgRpX8D9a4jdMse3U81Xed5E26wfiTaTM ueLaKILTzBMa29Ag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300363; 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=RffRCKVkf4tOMl6I565jAg9VCZIGD0dLIYK/HF2buBQ=; b=dNFZLmEGJP9bLQS+FwbrILkK+PuB/MFoTFYzQLTLyte33tBS8Jghb6eq8gGvG6NwrF8iUi UvH8JkYJ4dhwtjDz/cLRYPq4DrVY0Z9JHYS9nNdwt/Qtthx4ZZhNk6PlfIpt1+rn7HWqgQ RSbSjoCT21Fn0hS0n6+/V+B6fd7WXnA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300363; 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=RffRCKVkf4tOMl6I565jAg9VCZIGD0dLIYK/HF2buBQ=; b=q+V6AbMKo0wQpmJoguEfMZf6MSJe6F0vmu3igxL+4bW6YzWJtlwnQuOjWkyvfoA3p9pMU4 3/lzuvOjos2TJhDw== 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 CD9F2137EB; Thu, 18 Jul 2024 10:59: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 2MgSLor1mGbnVAAAD6G6ig (envelope-from ); Thu, 18 Jul 2024 10:59:22 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [PATCH 9/9] mm: Consolidate common checks in hugetlb_mmap_check_and_align Date: Thu, 18 Jul 2024 12:59:03 +0200 Message-ID: <20240718105903.19617-10-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240718105903.19617-1-osalvador@suse.de> References: <20240718105903.19617-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2FBD7C001E X-Stat-Signature: wy463sk5aoksbgpxboumu485p8jdhdir X-HE-Tag: 1721300364-571567 X-HE-Meta: U2FsdGVkX180Yi6k8B/HuqSYfb9TuwNg/eCH5SqW9AWm9ZlyO+17n3jWVU+aYz4OPKpgZ0gi4Trt36EJDR/FrFpYt2300dlHv7fMcEJTCeRGHd5KxvDOWhsv7HsxpDO6hVykjV0kw5PXI1K/QAmWlnKHZjXRmlMdKGu6fqfVDQTYxaMTYsUkaeRJuyJ1S3Jp1z92ksVZro4LaLxmWDc5EqQj/06AWzCuVWzEzgXdK2vrhz7MrLFWZx6VUKyo+D8+rPZ+fHSYrF6LBe3heIfV1v4+RpgQurzWNy/AhPXoGB6ZJzCdNRFslDf+dU52aN9rrxeXNMBHCDo1DxQicx2Jcouzl7sIMJ3S1U2C+Gw8n37IMDLvrHKC1kEo5iCcwWGhZuIStPibBbzAK8XjDF2PPosUsT7Vq85YzNkNeKySgw9EouDENFCykCde0Ot/c0CJzF6O+q2RCJjG3ebFNUPMf4RBZCym1pPSpw5wiDTuc5uSU0ObLF/4R69076ILmpiZkvN0Jb99P40XjTYZOpF1genuWar1Y0r4fj5K7IGDeeDzTs4vbSSnSazqju6iBxhzv4Bqcuw9g68QTJizy55smIm5Nhcya609wSyrZgLEfE1ymJ5Bc4fH5hUJr1iCz5Nx1WNl5LdJ16GCc3Tab0mXd+aEqjm20CEkesW9UDbpKVpBxqVZ5wfln68xbSkGrHosnXaalCV+YKlU6wg+YkRCuOnklcL6yqHyEJOtfBJAcPGWEyy4wLjwzQ6oV+0MPGG1lEB/4TRzgyRCj45HMZOHE6P1c98cRjgBg/+Ift7Af36qEG0++/UgvjSKDvn4EPMJeaaM35Yj8FGAfT8NaQ04N1zt3BDK+V0hFTCsYllQoRuMME8TU7KIDe4lkyhNn79hOkglNoHIOtIIZ1ZmQd9KMViM2Q3jUFgCHDFUaQRQUIg1evOlQWOGznbreobtk2gWY/s4TDsZScAVnnQnklI 9z9BBS18 GZbTyxsdRRSy57a60n35KM2uunqlRNuKDNGemT6/zgMpKb6UY8fa3HjB8maF1hoOpbk+A7v8OF2h9c0NtE1ECZNojtlLyJcrXQKR+lXv6WHNO9S0Akfb6nNf2gd7AnHF+bcbP6eybYHoM2ed3OXzZyuhWkdZOijVaMXMuAkefC//GP+R84R8KzMtLx6DhEiAANprJcnBHrMs03D1fbANYm7bN0vjXCMBCPKNAc1ZUOfBsz+kv5V5CsrtRkSp2nvMLC+bJPDfaUtzga3I+ohmARQYosg== 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 | 17 ----------------- arch/sh/include/asm/hugetlb.h | 15 --------------- fs/hugetlbfs/inode.c | 8 ++++++-- include/asm-generic/hugetlb.h | 7 ------- 7 files changed, 6 insertions(+), 64 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 f01b101c80b7..d4277e5a27d9 100644 --- a/arch/s390/include/asm/hugetlb.h +++ b/arch/s390/include/asm/hugetlb.h @@ -25,23 +25,6 @@ extern pte_t huge_ptep_get(pte_t *ptep); extern 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) -{ - 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 4902220adf42..38b8a9a63ba2 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 0b89d36a4310..0ca5da28fb01 100644 --- a/include/asm-generic/hugetlb.h +++ b/include/asm-generic/hugetlb.h @@ -123,13 +123,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