From patchwork Tue Sep 10 08:00:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13798085 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 595DAECE564 for ; Tue, 10 Sep 2024 08:01:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A25348D0028; Tue, 10 Sep 2024 04:00:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F9298D002B; Tue, 10 Sep 2024 04:00:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2681B8D000E; Tue, 10 Sep 2024 04:00:58 -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 90DB78D0028 for ; Tue, 10 Sep 2024 04:00:57 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2F789160E92 for ; Tue, 10 Sep 2024 08:00:57 +0000 (UTC) X-FDA: 82548082554.02.53FBB3B Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf14.hostedemail.com (Postfix) with ESMTP id DEFF4100011 for ; Tue, 10 Sep 2024 08:00:54 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=oQWHLDDd; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="+X/5hx72"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=oQWHLDDd; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="+X/5hx72"; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf14.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725955251; a=rsa-sha256; cv=none; b=6dbIB/4q3eOzu9Ynx+teccJ2DWCQUyA8Obz7KlDOHrHz/4NUaxRNeAhBl1jfCc58TMnQ4H WUiMEsvYR7f9In753mhdwF/yiIe1hbbNFIGbVG07xpAvhX0K7ZnavU+D+ThROmUDnE8d9h 4rXGbz3GMV7VgQNWHoPyP2BnDD3zjyY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=oQWHLDDd; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="+X/5hx72"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=oQWHLDDd; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="+X/5hx72"; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf14.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725955251; 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=UOWMTJ6u3klMxfD86oEWdVkDNRrL55iQpRE7zIr7zbs=; b=pjIjTqKFzWwmiyS9CNQsqke0X7kzSC6jnDVSZWhk/HHgifVcm1Q2ZJ1t9eQ59YIe0NhrE8 rG59O5NbCdRVQK4PCdYn90fSpv0yLprUxq+GX3BqS0svJY6mSR33DjGlKxldY4vl2EJFJ8 Oadp/gNoPrpKJIU4aXSXndxYSdtfRH0= 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 729ED21A3D; Tue, 10 Sep 2024 08:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955253; 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=UOWMTJ6u3klMxfD86oEWdVkDNRrL55iQpRE7zIr7zbs=; b=oQWHLDDd4N1+3CUcsrROCuMC89cK1HbnGVB9kVwqYtvBbmMXlQx9qiB0lHS/mVjDOKpf/X S9O5ft5skcZ07Pcz8QjCCmtucnsz8rVewX0YYmVSObHmnzKfLIQzxCfL/av19cFEClCwuR Qpe6m2fQIGjR+yAxUQ+bfMnLCum21hc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955253; 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=UOWMTJ6u3klMxfD86oEWdVkDNRrL55iQpRE7zIr7zbs=; b=+X/5hx72CiALe9ui2f+0GZ3F7RnD/snURiHFvuoI9YH+caDjjVkQNKm1MKRYH9YXbjIa0U r5m9jQOiF+AoGSDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955253; 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=UOWMTJ6u3klMxfD86oEWdVkDNRrL55iQpRE7zIr7zbs=; b=oQWHLDDd4N1+3CUcsrROCuMC89cK1HbnGVB9kVwqYtvBbmMXlQx9qiB0lHS/mVjDOKpf/X S9O5ft5skcZ07Pcz8QjCCmtucnsz8rVewX0YYmVSObHmnzKfLIQzxCfL/av19cFEClCwuR Qpe6m2fQIGjR+yAxUQ+bfMnLCum21hc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955253; 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=UOWMTJ6u3klMxfD86oEWdVkDNRrL55iQpRE7zIr7zbs=; b=+X/5hx72CiALe9ui2f+0GZ3F7RnD/snURiHFvuoI9YH+caDjjVkQNKm1MKRYH9YXbjIa0U r5m9jQOiF+AoGSDQ== 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 B80F513A8F; Tue, 10 Sep 2024 08:00:52 +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 sBgDKrT832Y2MQAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 08:00:52 +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 , Vlastimil Babka , Michal Hocko , Lorenzo Stoakes , "Liam R . Howlett" , Oscar Salvador Subject: [PATCH v3 6/9] mm: Make hugetlb mappings go through mm_get_unmapped_area_vmflags Date: Tue, 10 Sep 2024 10:00:27 +0200 Message-ID: <20240910080030.1272373-7-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910080030.1272373-1-osalvador@suse.de> References: <20240910080030.1272373-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: ao5ydf6cxnxfyw5txmyfp7ip31jcjhkt X-Rspamd-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ZHz5blVsm3xHT/MDnm5MCvJ0cjBqLVzA1F35/fjkHwu9pRFg7hRBRCEZDmENKChI8jBO6kzGxi1yaDinhgY3BnEG4mTzF3aoC2wgHYDlkijXVlNa0i4Jk8fEZ9Rn8+/UrPXDJqYcVEwTM1Fv8K2mRdZ8r9+YIjm9LXsYEPLvz+NTipImCOGXDNHHqysVopkGRe1xUFHv1KUiiasyON+5HZOxERqy3sVtPOIxjVLtJsThGXMuYY3CMND/C8RrKZSST8femhcg== 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 | 24 ++++++++++++++++-------- include/linux/hugetlb.h | 9 ++++----- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 9f6cff356796..978f5d62c5cf 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -258,15 +258,23 @@ 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_get_unmapped_area(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 mm_get_unmapped_area_vmflags(current->mm, file, addr, len, pgoff, + flags, 0); } -#endif /* * Someone wants to read @bytes from a HWPOISON hugetlb @page from @offset. @@ -1300,7 +1308,7 @@ 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, + .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 368d552e4860..3a81b6126f62 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -546,11 +546,10 @@ 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 +__generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags); unsigned long generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr,