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: fbz4xbfjr51tq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pnumFPbsbgv6+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); /*