From patchwork Mon Jul 29 09:10:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13744625 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 BC639C3DA4A for ; Mon, 29 Jul 2024 09:10:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A5AE6B0085; Mon, 29 Jul 2024 05:10:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0618F6B008C; Mon, 29 Jul 2024 05:10:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D36BD6B0085; Mon, 29 Jul 2024 05:10:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B2A846B0085 for ; Mon, 29 Jul 2024 05:10:38 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4391216020D for ; Mon, 29 Jul 2024 09:10:38 +0000 (UTC) X-FDA: 82392219756.14.7F0B45D Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf18.hostedemail.com (Postfix) with ESMTP id 3E4971C000E for ; Mon, 29 Jul 2024 09:10:35 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf18.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722244183; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BfkSOz2Y9ZrBcjfIMnhUE9RAoBJM1JlNNfTgf+rznQs=; b=nYPKyAKi8S1NF1hHjNwn6aVBDBsgSamXv4HJz9tvKTjNsRXO9+6xcXqkUj4DdLPY9unSnV voc5b4pAbaoHyD4FWuAwyt44UFt4T6wzTsV4zRaPG3GIUQ/90t0+bIwKZpb6w5VMgwWNzS fWNFAgm/3CCr9N97B2BbWq41Ga3UzWk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722244183; a=rsa-sha256; cv=none; b=PHsBa/JcW8Awo6GxFZTC3HqOyGrwvfg6WhnUmUCAO6L4be8F/dhagC4CWZqGH5/tuDGObN zwG9kAhT5Npdw3/DxbtNMGgU6MoxzA5U6D5l93jiPZgN49mJu/pBD2qpMdb+yaDY0Q5/sW 9mkbWUhG5KW8qOKuJw1zYlcQqCKi3Vs= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf18.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DAFA61F445; Mon, 29 Jul 2024 09:10:33 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 96A1C1397F; Mon, 29 Jul 2024 09:10:32 +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 ADa6Hohcp2Z4BgAAD6G6ig (envelope-from ); Mon, 29 Jul 2024 09:10:32 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , David Hildenbrand , Donet Tom , Matthew Wilcox , Vlastimil Babka , Michal Hocko , Oscar Salvador Subject: [PATCH v2 1/9] mm/mmap: Teach generic_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Mon, 29 Jul 2024 11:10:10 +0200 Message-ID: <20240729091018.2152-2-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240729091018.2152-1-osalvador@suse.de> References: <20240729091018.2152-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 3E4971C000E X-Stat-Signature: 45fnnphm4ymd1sr4qguoqcitqu7z8oqi X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722244235-783555 X-HE-Meta: U2FsdGVkX1+BSjhKsEx0oxhvjG/xH2yGMLyLc5OKwGCryMMjpAxzdEfmQ3PGDlCPPE9YSwLjJbUR1Z+DUPVstrzjViUPgIESoKZZ372sgWNVFwVhomaJrHMg0qyuaf3vu1LAHOu6WxE+7teCzWftqJvv2IVS1a51wYFFzXZ/K0KJO3GvEdX4NCT8eXznjiqydaIX93EO5ssrcBBDC9sb1FYJCrEtZFpK7GFxXjfRQVIWAE5YeHSINZV0uAjTYA1ArvIZbUONt1echPo0gfEQ9asUZ9tb2S1Pydy+8ham9QjQNZDFeb2mFmLS4Td5l+vkDSGp7U8pt25pVO2eVvHBjJeW5CwttH2EDOtTbIaGqwNKXPT/0a87Cv1dceTQfi9cuF+CxJ9VKuOeFj+KiPhRR9Ss8kaE5VMDM3QmGfFsjGMiFevwkqJCEbSElfI5dUcJtJSRJ3ZUAwrh3nZr1siL2DJiab71O5vlcQla1xnyatkOg3+p/1kxzEZ5qgBKqHIajVtjq44+BQ2DjJLzATd1rs7VNTdV5uBjC3Y4eEoWq/gNMvFs0tjm/G9efUH6iToYz6jF9KeNOHmHaZ1IHkJy38dywr5YR+Pdli2g6gErJhNAeTGvKKb2yEtuHxfnOSuYd3wvBii6yWSXU/s++noP9XTIXCmGK0NlWMeRq+IlzJrS/cTwezYmB12CRaFvtsHIRZ6kfN0JCPxqaLg93JWi85pcId+Q/f2Snd5wrNaYwqKALRfN/GBITtdtkY+UgAnNgFXxesLi7RuA3zc0K8o9mY15U6dTOvd4B39aS3xeZEL6iCJT5RvHK3cbMSNTP1zlctnkSwjA6iKd9Q+szYbWAkQ5Q1E+F4RRhy7CQu7Lak2U0FHwF4X2K3poVsLDLdb+lm/C0JiZoyBicRfUUF52TqmGOBJ3CChdwPf2W4ZpXhuqasNUt4Xu1bYmzn85gniGjx5p0tqKHO8pMrO0GY/ VrQ1qEki 6hZ61UH3HXIh128yISKHCCVTBgYybzoNZCa3I2D1yQTUN053fowLk8XtpG2RvtYkZDMwx5BlEu7Khr3HUyQhqZSPoTHeyQzQItcZMNNY31zxjmL5i4SjYEI4t8ht5VhoJUagkKPXmRHYqTjHq+EoAVkOmihCPRPFKxthje5Jocyh6UfA= 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 c9bf68c239a0..0ec14e5e0890 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -1007,9 +1007,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 b74d2967cfc0..7b623811d82a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -732,6 +732,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); } @@ -780,6 +782,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); /*