From nobody Wed Dec 17 12:08:34 2025 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81A2318FDB1 for ; Wed, 10 Jul 2024 10:51:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608687; cv=none; b=hdZQLPlEWRbDmfz/F+N32asHkDKCOcXE716gXZW5JJKRwT6GjR1vWsmBl6OPkEu7uTOiuUDXdkr7t6XXuDndYHIG95uNZD+0vktOnASuP/5BM6BCH3cTsEXwYpv4+eYEeTVfWNFHKRy5yD5TCMv70+qvgn5C+XfzIcJDbxmfbM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608687; c=relaxed/simple; bh=Pt5S5a1N4lm9BD1+YJUC1nSGEeDhZMxvgo/OZAITNd4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o5RIOHV3JhnIjpRS0wUI9kZFFqp79vsHcxNd8ZRfxQLyAuNiJV3KaXhGZSZyiHPuisD5aCu9bRME6d18j0yb9NrQ9qz2UTOPIDMK7eU8bQ+7RgzASccnJLcugvk65RrEeZ5RyuAmjBLfozZW91og206uS0I7xy3A2TnE+cXSofE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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-out1.suse.de (Postfix) with ESMTPS id D223A21A3D; Wed, 10 Jul 2024 10:51:23 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C8C571369A; Wed, 10 Jul 2024 10:51:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id gMnALKpnjmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:22 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , David Hildenbrand , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [RFC PATCH 1/8] mm/mmap: Teach generic_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Wed, 10 Jul 2024 12:50:35 +0200 Message-ID: <20240710105042.30165-2-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240710105042.30165-1-osalvador@suse.de> References: <20240710105042.30165-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Queue-Id: D223A21A3D X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 X-Spam-Level: Content-Type: text/plain; charset="utf-8" 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); =20 +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 {}; =20 +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 =3D len; info.low_limit =3D mm->mmap_base; info.high_limit =3D mmap_end; + if (filp && is_file_hugepages(filp)) + info.align_mask =3D huge_page_mask_align(filp); return vm_unmapped_area(&info); } =20 @@ -1791,6 +1793,8 @@ generic_get_unmapped_area_topdown(struct file *filp, = unsigned long addr, info.length =3D len; info.low_limit =3D PAGE_SIZE; info.high_limit =3D arch_get_mmap_base(addr, mm->mmap_base); + if (filp && is_file_hugepages(filp)) + info.align_mask =3D huge_page_mask_align(filp); addr =3D vm_unmapped_area(&info); =20 /* --=20 2.45.2 From nobody Wed Dec 17 12:08:34 2025 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD5E4191464 for ; Wed, 10 Jul 2024 10:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608694; cv=none; b=Tp31VtN1iI2NSTUh9ASD2oWvR9soiZKKy54ZWm4/ivVEqZcRw7KFYr5XRBaPkFZSBG9PuJa+aYYzjeXgjwMYyuQPmRdPr3s+ATs4vs60yTmrswjjm+dvVp9GAowBvhWLGb9LKT/ctN7O3ETGFyQ3deqbf5kJzOUqu+nagufZ/Ns= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608694; c=relaxed/simple; bh=2TauxrxoL+LHouGn0r0YOhyAjtnpThDyasMCHFEcPao=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PisbfHeHb/FExv3V/76pOvwFVW6Nb46LKmxCiMLxL7+m7qNpgZGuRqbUaeJI+QA4BFvK1g5qYNs6kUHuPipPVjTbPrIz87SRfobqxfc7V/cBO4henCvOsht0DtRBNOz4tCAb5AUW0nAI6RWCb2Me8NBES5UfvyQQ/DUJ+cZqeV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=vWma3QMm; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=hdePWM/l; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=vWma3QMm; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=hdePWM/l; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="vWma3QMm"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="hdePWM/l"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="vWma3QMm"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="hdePWM/l" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 364F61F824; Wed, 10 Jul 2024 10:51:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608685; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MiX8eoexrmO/wjIpeeQ9glTEYeXiTS6tsv5T+BPJcGU=; b=vWma3QMmGeWRXJcr6gHXAh51UbyOC3/rO+Nxlq+dJJq+R+LMUKQD3tP2toFmn9IH4RsdtW XWOaFAZBQ7XWMwl6sf/zBMjtQlSOg7hRWPqODWwGD2lRvpSkFQGFg66rLqG3gJUQS7WeWN 5Sh9v+CKdJQ93f4u5gZe257D5HEOWzA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608685; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MiX8eoexrmO/wjIpeeQ9glTEYeXiTS6tsv5T+BPJcGU=; b=hdePWM/lQgzDbtl3y1qRTw5AcA/nnPR2xCuLciXlwjGsJ8dQFNayVGStGn0kpjV3Z5iagx rWKWfsL4/uk4quCQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608685; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MiX8eoexrmO/wjIpeeQ9glTEYeXiTS6tsv5T+BPJcGU=; b=vWma3QMmGeWRXJcr6gHXAh51UbyOC3/rO+Nxlq+dJJq+R+LMUKQD3tP2toFmn9IH4RsdtW XWOaFAZBQ7XWMwl6sf/zBMjtQlSOg7hRWPqODWwGD2lRvpSkFQGFg66rLqG3gJUQS7WeWN 5Sh9v+CKdJQ93f4u5gZe257D5HEOWzA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608685; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MiX8eoexrmO/wjIpeeQ9glTEYeXiTS6tsv5T+BPJcGU=; b=hdePWM/lQgzDbtl3y1qRTw5AcA/nnPR2xCuLciXlwjGsJ8dQFNayVGStGn0kpjV3Z5iagx rWKWfsL4/uk4quCQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0BB471369A; Wed, 10 Jul 2024 10:51:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id uIvoN6tnjmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:23 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , David Hildenbrand , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [RFC PATCH 2/8] arch/s390: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Wed, 10 Jul 2024 12:50:36 +0200 Message-ID: <20240710105042.30165-3-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240710105042.30165-1-osalvador@suse.de> References: <20240710105042.30165-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_SEVEN(0.00)[11]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Score: -6.80 X-Spam-Level: Content-Type: text/plain; charset="utf-8" We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area{_topdown} to handle those. s390 specific hugetlb function does not set info.align_offset, so do the same here for compatibility. Signed-off-by: Oscar Salvador --- arch/s390/mm/mmap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c index 206756946589..e98c00df586f 100644 --- a/arch/s390/mm/mmap.c +++ b/arch/s390/mm/mmap.c @@ -73,6 +73,8 @@ static inline unsigned long mmap_base(unsigned long rnd, =20 static int get_align_mask(struct file *filp, unsigned long flags) { + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); if (!(current->flags & PF_RANDOMIZE)) return 0; if (filp || (flags & MAP_SHARED)) @@ -106,7 +108,8 @@ unsigned long arch_get_unmapped_area(struct file *filp,= unsigned long addr, info.low_limit =3D mm->mmap_base; info.high_limit =3D TASK_SIZE; info.align_mask =3D get_align_mask(filp, flags); - info.align_offset =3D pgoff << PAGE_SHIFT; + if (!(file && is_file_hugepages(filp)) + info.align_offset =3D pgoff << PAGE_SHIFT; addr =3D vm_unmapped_area(&info); if (offset_in_page(addr)) return addr; @@ -144,7 +147,8 @@ unsigned long arch_get_unmapped_area_topdown(struct fil= e *filp, unsigned long ad info.low_limit =3D PAGE_SIZE; info.high_limit =3D mm->mmap_base; info.align_mask =3D get_align_mask(filp, flags); - info.align_offset =3D pgoff << PAGE_SHIFT; + if (!(file && is_file_hugepages(filp)) + info.align_offset =3D pgoff << PAGE_SHIFT; addr =3D vm_unmapped_area(&info); =20 /* --=20 2.45.2 From nobody Wed Dec 17 12:08:34 2025 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59707191474 for ; Wed, 10 Jul 2024 10:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608694; cv=none; b=gv0LvcKQw4UdtU0B3lVHvgqw2kAe6DMm9sDc2gGTNsMuWPDgGf+u84CKEsrJVmf06CdNMS7VTF851IyVOC7tfj0kKq/JeTm//HSpX7lHcTknrVqDwpwcewHiiX+6TbXY0irBRYz75ZaZzCnSay+UWyJDs+ZdHSZUXJbZlo5dNOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608694; c=relaxed/simple; bh=A5w0vGjs9nXoetdRG0NWdKucvagJT0jsZ+A+FVaHA9g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KpAUfYxykdRzvhNvR6vM5ASwL61kx4yU01pEULZyGcyhWTWWOBIw28NdU+CRQy3R3qY6HECacmlmfraebW+mmigd5wXAKNX6if1cLyXRUULwsXiAwVKUWcDtSJFQzORASmbJRe025wUDJrznlJrEwLDUU7prg3GKlAl75l6jTuw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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 78AA81F829; Wed, 10 Jul 2024 10:51:26 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 57AC51369A; Wed, 10 Jul 2024 10:51:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id AIHDEK1njmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:25 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , David Hildenbrand , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [RFC PATCH 3/8] arch/x86: Teach arch_get_unmapped_area_vmflags to handle hugetlb mappings Date: Wed, 10 Jul 2024 12:50:37 +0200 Message-ID: <20240710105042.30165-4-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240710105042.30165-1-osalvador@suse.de> References: <20240710105042.30165-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Queue-Id: 78AA81F829 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 X-Spam-Level: Content-Type: text/plain; charset="utf-8" We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area_{topdown_}vmflags to handle those. x86 specific hugetlb function does not set either info.start_gap or info.align_offset so the same here for compatibility. Signed-off-by: Oscar Salvador --- arch/x86/kernel/sys_x86_64.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c index 01d7cd85ef97..aa7491f036a7 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -18,6 +18,7 @@ #include #include #include +#include =20 #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); } =20 static int __init control_va_addr_alignment(char *str) @@ -148,12 +151,15 @@ arch_get_unmapped_area_vmflags(struct file *filp, uns= igned long addr, unsigned l info.length =3D len; info.low_limit =3D begin; info.high_limit =3D end; - info.align_offset =3D pgoff << PAGE_SHIFT; - info.start_gap =3D stack_guard_placement(vm_flags); + if (!(filp && is_file_hugepages(filp))) { + info.align_offset =3D pgoff << PAGE_SHIFT; + info.start_gap =3D stack_guard_placement(vm_flags); + } if (filp) { - info.align_mask =3D get_align_mask(); + info.align_mask =3D get_align_mask(filp); info.align_offset +=3D get_align_bits(); } + return vm_unmapped_area(&info); } =20 @@ -199,7 +205,10 @@ arch_get_unmapped_area_topdown_vmflags(struct file *fi= lp, unsigned long addr0, info.low_limit =3D PAGE_SIZE; =20 info.high_limit =3D get_mmap_base(0); - info.start_gap =3D stack_guard_placement(vm_flags); + if (!(filp && is_file_hugepages(filp))) { + info.start_gap =3D stack_guard_placement(vm_flags); + info.align_offset =3D pgoff << PAGE_SHIFT; + } =20 /* * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area @@ -211,9 +220,8 @@ arch_get_unmapped_area_topdown_vmflags(struct file *fil= p, unsigned long addr0, if (addr > DEFAULT_MAP_WINDOW && !in_32bit_syscall()) info.high_limit +=3D TASK_SIZE_MAX - DEFAULT_MAP_WINDOW; =20 - info.align_offset =3D pgoff << PAGE_SHIFT; if (filp) { - info.align_mask =3D get_align_mask(); + info.align_mask =3D get_align_mask(filp); info.align_offset +=3D get_align_bits(); } addr =3D vm_unmapped_area(&info); --=20 2.45.2 From nobody Wed Dec 17 12:08:34 2025 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60AB317BB20 for ; Wed, 10 Jul 2024 10:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608697; cv=none; b=fza1kSCNPUK59vrYr/Ba2c0JK4xhe4HJN1mZWdqBiAQO0rCibXeJ/UeezPFT0uU+Yxi9424PUOvM0pByWM+jM1X0PpObCyjH0aMZISJ4nP6ahCRay5sslVKT1oRdR6E2Jxq5ut0guNrWpm6vuo5JlJ2rdtGVSgR+MuodFCO6stA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608697; c=relaxed/simple; bh=icWu+biOg5ee4jEVy/sW+uVLSF874SO9q7O3bQu3qPI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ODOs31aduvQODlNQaoGp+5IEjRXFeXTSoWBGL6b4+VttKMQPPzOKuVizsfBpGIN2HUDZmKBK8qxpadq+EhL4xRBvNEpzAPzpdtWcZdRYizAuzKD2rdMg3h7S596xAMuqbZdaY5DdJ+ToqsByXpO61YF/2PB6PVju5aVJlerydYU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C1FB61F82A; Wed, 10 Jul 2024 10:51:27 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A45BA1369A; Wed, 10 Jul 2024 10:51:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GFhyIq5njmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:26 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , David Hildenbrand , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [RFC PATCH 4/8] arch/sparc: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Wed, 10 Jul 2024 12:50:38 +0200 Message-ID: <20240710105042.30165-5-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240710105042.30165-1-osalvador@suse.de> References: <20240710105042.30165-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Flag: NO X-Spam-Score: -4.00 X-Spam-Level: X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: C1FB61F82A X-Rspamd-Action: no action X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org Content-Type: text/plain; charset="utf-8" We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area{_topdown} to handle those. sparc specific hugetlb function does not set info.align_offset, and does not care about adjusting the align_mask for MAP_SHARED cases, so the same here for compatibility. Signed-off-by: Oscar Salvador --- arch/sparc/kernel/sys_sparc_32.c | 16 ++++++++++---- arch/sparc/kernel/sys_sparc_64.c | 36 +++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc= _32.c index 08a19727795c..fc33ac48ed28 100644 --- a/arch/sparc/kernel/sys_sparc_32.c +++ b/arch/sparc/kernel/sys_sparc_32.c @@ -42,12 +42,16 @@ SYSCALL_DEFINE0(getpagesize) unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr= , unsigned long len, unsigned long pgoff, unsigned long flags) { struct vm_unmapped_area_info info =3D {}; + bool file_hugepage =3D false; + + if (filp && is_file_hugepages(filp)) + file_hugepage =3D true; =20 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 =3D len; info.low_limit =3D addr; info.high_limit =3D TASK_SIZE; - info.align_mask =3D (flags & MAP_SHARED) ? - (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset =3D pgoff << PAGE_SHIFT; + if (!file_hugepage) { + info.align_mask =3D (flags & MAP_SHARED) ? + (PAGE_MASK & (SHMLBA - 1)) : 0; + info.align_offset =3D pgoff << PAGE_SHIFT; + } else { + info.align_mask =3D huge_page_mask_align(filp); + } return vm_unmapped_area(&info); } =20 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 ad= dr, return base + off; } =20 +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 =3D current->mm; @@ -94,12 +104,16 @@ unsigned long arch_get_unmapped_area(struct file *filp= , unsigned long addr, unsi unsigned long task_size =3D TASK_SIZE; int do_color_align; struct vm_unmapped_area_info info =3D {}; + bool file_hugepage =3D false; + + if (filp && is_file_hugepages(filp)) + file_hugepage =3D true; =20 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; =20 do_color_align =3D 0; - if (filp || (flags & MAP_SHARED)) + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align =3D 1; =20 if (addr) { @@ -129,8 +143,9 @@ unsigned long arch_get_unmapped_area(struct file *filp,= unsigned long addr, unsi info.length =3D len; info.low_limit =3D TASK_UNMAPPED_BASE; info.high_limit =3D min(task_size, VA_EXCLUDE_START); - info.align_mask =3D do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset =3D pgoff << PAGE_SHIFT; + info.align_mask =3D get_align_mask(filp, flags); + if (!file_hugepage) + info.align_offset =3D pgoff << PAGE_SHIFT; addr =3D vm_unmapped_area(&info); =20 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) { @@ -154,15 +169,19 @@ arch_get_unmapped_area_topdown(struct file *filp, con= st unsigned long addr0, unsigned long addr =3D addr0; int do_color_align; struct vm_unmapped_area_info info =3D {}; + bool file_hugepage =3D false =20 /* This should only ever run for 32-bit processes. */ BUG_ON(!test_thread_flag(TIF_32BIT)); =20 + if (filp && is_file_hugepages(filp)) + file_hugepage =3D 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; =20 do_color_align =3D 0; - if (filp || (flags & MAP_SHARED)) + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align =3D 1; =20 /* requesting a specific address */ @@ -192,8 +211,9 @@ arch_get_unmapped_area_topdown(struct file *filp, const= unsigned long addr0, info.length =3D len; info.low_limit =3D PAGE_SIZE; info.high_limit =3D mm->mmap_base; - info.align_mask =3D do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset =3D pgoff << PAGE_SHIFT; + info.align_mask =3D get_align_mask(filp, flags); + if (!file_hugepage) + info.align_offset =3D pgoff << PAGE_SHIFT; addr =3D vm_unmapped_area(&info); =20 /* --=20 2.45.2 From nobody Wed Dec 17 12:08:34 2025 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDC2384A2F for ; Wed, 10 Jul 2024 10:51:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608692; cv=none; b=Vz8KxeC9s3PMMJk4crKsEz6W162rtfJiDu4q18G6C5feAB7s7dq7Gp5XsOZcjuC3rlNnK1Wp0hxwo2bxcmoyDR2hgScnxLwzYbLSJ0AxGQVzlYudxhRMYXjP91G211H2uKbmPCylnSKM5o+VSATDvu/gk+N2O7VP6tOIRLGY/rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608692; c=relaxed/simple; bh=Bu39IAoeotpZQS+JPqNZI0U0fNYKWTYVrHQJZ/FZuEE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A4dgXG2c5yM6RZJ9yD3GA9siWHMcyNzRDUAT1TblIfQ6UAy4BJGNC1xWFhI9cXQRsRcsfyNv23rlYGJOUx1YyryFN0sXqOi2eLlSkR0BD+Gs8tS4bYrP8HpKj2s4rCrSJLi4xLU4+O6o2JSzgPjn7coZTBBqtIGMrA18b8hHhe4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=o/R9ZuDL; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Wx7vnkPn; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=o/R9ZuDL; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Wx7vnkPn; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="o/R9ZuDL"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Wx7vnkPn"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="o/R9ZuDL"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Wx7vnkPn" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0C7AA21A33; Wed, 10 Jul 2024 10:51:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608689; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4aP7LJidVwaEiyg2vEhcsAqZZw1DICdTCoxEateoTEY=; b=o/R9ZuDLTBFAeen3OTEvbuoQTG+0ttv6ilWicNUQx0VjjRe1d2Up3cp0/8+x3YfBH2uMnf JKDJhaY0AY4YzLPDKX0j1rcmcrJuf+OVuHyMr7/IGf2LIZ6jvsCqW7o7whTOLS2nT2d4NR NEI1eQn7lkOnn83FIhhH1NzCWEkh8qk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608689; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4aP7LJidVwaEiyg2vEhcsAqZZw1DICdTCoxEateoTEY=; b=Wx7vnkPnXLV89jq+HQkZWLMRhtuwOGjeItAZ0ibHsDgzQXaXRZmCXRBtyVOtI1O92c951J mfyReADNVpXDpSDA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608689; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4aP7LJidVwaEiyg2vEhcsAqZZw1DICdTCoxEateoTEY=; b=o/R9ZuDLTBFAeen3OTEvbuoQTG+0ttv6ilWicNUQx0VjjRe1d2Up3cp0/8+x3YfBH2uMnf JKDJhaY0AY4YzLPDKX0j1rcmcrJuf+OVuHyMr7/IGf2LIZ6jvsCqW7o7whTOLS2nT2d4NR NEI1eQn7lkOnn83FIhhH1NzCWEkh8qk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608689; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4aP7LJidVwaEiyg2vEhcsAqZZw1DICdTCoxEateoTEY=; b=Wx7vnkPnXLV89jq+HQkZWLMRhtuwOGjeItAZ0ibHsDgzQXaXRZmCXRBtyVOtI1O92c951J mfyReADNVpXDpSDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E57C31369A; Wed, 10 Jul 2024 10:51:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id oPBeM69njmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:27 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , David Hildenbrand , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [RFC PATCH 5/8] arch/powerpc: Teach book3s64 arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Wed, 10 Jul 2024 12:50:39 +0200 Message-ID: <20240710105042.30165-6-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240710105042.30165-1-osalvador@suse.de> References: <20240710105042.30165-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_SEVEN(0.00)[11]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Score: -6.80 X-Spam-Level: Content-Type: text/plain; charset="utf-8" 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/sl= ice.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 a= ddr, unsigned long len, } EXPORT_SYMBOL_GPL(slice_get_unmapped_area); =20 +#ifdef CONFIG_HUGETLB_PAGE +static int file_to_psize(struct file *file) +{ + struct hstate *hstate =3D 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); =20 - return slice_get_unmapped_area(addr, len, flags, - mm_ctx_user_psize(¤t->mm->context), 0); + if (filp && is_file_hugepages(filp)) + psize =3D file_to_psize(filp); + else + psize =3D mm_ctx_user_psize(¤t->mm->context); + + return slice_get_unmapped_area(addr, len, flags, psize, 0); } =20 unsigned long arch_get_unmapped_area_topdown(struct file *filp, @@ -652,11 +671,17 @@ unsigned long arch_get_unmapped_area_topdown(struct f= ile *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); =20 - return slice_get_unmapped_area(addr0, len, flags, - mm_ctx_user_psize(¤t->mm->context), 1); + if (filp && is_file_hugepages(filp)) + psize =3D file_to_psize(filp); + else + psize =3D mm_ctx_user_psize(¤t->mm->context); + + return slice_get_unmapped_area(addr0, len, flags, psize, 1); } =20 unsigned int notrace get_slice_psize(struct mm_struct *mm, unsigned long a= ddr) @@ -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_star= t)); } =20 -static int file_to_psize(struct file *file) -{ - struct hstate *hstate =3D hstate_file(file); - return shift_to_mmu_psize(huge_page_shift(hstate)); -} - unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long a= ddr, unsigned long len, unsigned long pgoff, unsigned long flags) --=20 2.45.2 From nobody Wed Dec 17 12:08:34 2025 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DFC418FA35 for ; Wed, 10 Jul 2024 10:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608694; cv=none; b=nzhOMfQD3vtNpOgl3kcHaLVvzfe3TkEM2ercjo2LsNJz0ktEgz8JSfzmNWnjsq2KBKyOcWsNY9jLcaoiwI0MCR7DE9FEJhKzSdO8DQo2lLMt0abu8ptiQ6W2gzqxq8Y0DSG3BBVRzgMZWMhM1g2E4QqgQxxA97kL7FZHZ4ndJWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608694; c=relaxed/simple; bh=8EpTZViwVDALiRXLwKup2VmuzlJLxBCGaukGdNYdmEU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F4AB8NnwY08z15bDLpfMpdGda598VL/94wRVNkdSYcfGmkqK0QOOgAlq5BDFaMpmFuMdVddysIX7NUzFmqzVgfrOlnmhM/IxVPcXaxpI1ZcMHh4O4RKNYzqh1Rpq5lIOfJmVqDnzYDHsIVHxR2pNkGAlQYl1EgL/UAgZB9b+Cco= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=fSC1Gv8H; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=bYfs3lDT; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=fSC1Gv8H; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=bYfs3lDT; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fSC1Gv8H"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="bYfs3lDT"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fSC1Gv8H"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="bYfs3lDT" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5224F21BBB; Wed, 10 Jul 2024 10:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608690; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ph9NUUUfzYdgAX+SWvx0C4X8fQI8fkpyj62wUbkyYlY=; b=fSC1Gv8HhwSvd1I/53WmRpPzjVucOsDas8A9DH6+m8UO0/3EcWcAfdBUqvLL3fVYEUdxfT EsPHGkqdoqpAUI+m/WEE1R03tBMUXoqLQQdRlXSPLZsfpwuMQc/78IfuRGhs4gwXuIQApN AHnPUdJV/mCCIE9Jew3Xrz/9bkaVxT0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608690; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ph9NUUUfzYdgAX+SWvx0C4X8fQI8fkpyj62wUbkyYlY=; b=bYfs3lDTbUwBqvuiMOVaLuUilJTPz7MxAdnYxiVBZOgU7ZnrtqSMbRBzsTaiu4XCP4upCW gI+uI2I6ZXW1VZDw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608690; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ph9NUUUfzYdgAX+SWvx0C4X8fQI8fkpyj62wUbkyYlY=; b=fSC1Gv8HhwSvd1I/53WmRpPzjVucOsDas8A9DH6+m8UO0/3EcWcAfdBUqvLL3fVYEUdxfT EsPHGkqdoqpAUI+m/WEE1R03tBMUXoqLQQdRlXSPLZsfpwuMQc/78IfuRGhs4gwXuIQApN AHnPUdJV/mCCIE9Jew3Xrz/9bkaVxT0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608690; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ph9NUUUfzYdgAX+SWvx0C4X8fQI8fkpyj62wUbkyYlY=; b=bYfs3lDTbUwBqvuiMOVaLuUilJTPz7MxAdnYxiVBZOgU7ZnrtqSMbRBzsTaiu4XCP4upCW gI+uI2I6ZXW1VZDw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 30AA81369A; Wed, 10 Jul 2024 10:51:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id WPJEB7FnjmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:29 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , David Hildenbrand , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [RFC PATCH 6/8] mm: Make hugetlb mappings go through mm_get_unmapped_area_vmflags Date: Wed, 10 Jul 2024 12:50:40 +0200 Message-ID: <20240710105042.30165-7-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240710105042.30165-1-osalvador@suse.de> References: <20240710105042.30165-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -6.80 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_SEVEN(0.00)[11]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; R_RATELIMIT(0.00)[to_ip_from(RL61jpu64h8b3ddwbzqogesdsf)]; RCVD_TLS_ALL(0.00)[] Content-Type: text/plain; charset="utf-8" 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_vmfl= ags but through mm_get_unmapped_area_vmflags. Create also a function called hugetlb_mmap_check_and_align() where a couple of safety checks are being done and the addr is aligned to the huge page size. Otherwise we will have to do this in every single function, which duplicates quite a lot of code. Signed-off-by: Oscar Salvador --- fs/hugetlbfs/inode.c | 22 ++++++++++++++-------- include/linux/hugetlb.h | 8 +++----- mm/mmap.c | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 412f295acebe..b2d7fcecdb15 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -257,15 +257,22 @@ generic_hugetlb_get_unmapped_area(struct file *file, = unsigned long addr, pgoff, flags); } =20 -#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 =3D 0; + struct hstate *h =3D 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 =3D ALIGN(addr, huge_page_size(h)); + + return addr0; } -#endif =20 /* * Someone wants to read @bytes from a HWPOISON hugetlb @page from @offset. @@ -1302,7 +1309,6 @@ static const struct file_operations hugetlbfs_file_op= erations =3D { .read_iter =3D hugetlbfs_read_iter, .mmap =3D hugetlbfs_file_mmap, .fsync =3D noop_fsync, - .get_unmapped_area =3D hugetlb_get_unmapped_area, .llseek =3D default_llseek, .fallocate =3D hugetlbfs_fallocate, .fop_flags =3D 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 */ =20 -#ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA -unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long a= ddr, - 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); =20 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) =3D NULL; =20 + bool is_hugetlb =3D false; unsigned long error =3D 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; =20 + if (file && is_file_hugepages(file)) + is_hugetlb =3D true; + if (file) { if (file->f_op->get_unmapped_area) get_area =3D file->f_op->get_unmapped_area; @@ -1885,11 +1889,20 @@ __get_unmapped_area(struct file *file, unsigned lon= g addr, unsigned long len, =20 if (get_area) { addr =3D 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 =3D 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 =3D hugetlb_mmap_check_and_align(file, addr, len, flags); + if (IS_ERR_VALUE(addr)) + return addr; + } addr =3D mm_get_unmapped_area_vmflags(current->mm, file, addr, len, pgoff, flags, vm_flags); } --=20 2.45.2 From nobody Wed Dec 17 12:08:34 2025 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5974D191476 for ; Wed, 10 Jul 2024 10:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608695; cv=none; b=Dmc+poiTkVs+dwFejBlfWoVjPHZ1K0YTlJ1GVl4DHew7sw5sgMT/e4rcQuwCiMA3h+v1JqXI58fV4cVY9HRuiaxIojSitz4bXP1B1x58zZo9DPcZTRWX8bGJKfYKUb4dyyEbCyMfUu5XPylCZjXKwP+s1VNhnRT2+qUZOKo8Wnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608695; c=relaxed/simple; bh=4mhBxwOD0sN1G4ERZaQDzSHWGuFhTUx1564DQRwnK2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YuBxk5MuMZEsdbxold0UsJbskXB+XaI759LScx2DQhlEwGJP7Ln2GOQWuT3+bIOm/jEx32gmWnhTLvB0+Pz95RFS36FVKPTVuZ0+CEYVsdg/HN/+uGlPS0HJPETs6mpbffFCvHaWLdxQNbLMo9LFAsjL3JtChh9RSi7lvh2U6fE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=dGsZpU/t; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=VIwwW1oL; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=dGsZpU/t; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=VIwwW1oL; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="dGsZpU/t"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="VIwwW1oL"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="dGsZpU/t"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="VIwwW1oL" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A47B81F82B; Wed, 10 Jul 2024 10:51:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608691; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5n8Jhuz8lWIN9hi2PwsThD9v5LavYKY6GCrzf/ZoXlA=; b=dGsZpU/tz1+fvxvfGpa3cGh389hlkHQ6dSvpeneXvhw6WVRuEAIEL9o9rT52wdC7LZANb8 5GFzvyX2srGEHJdndQfKEAF+5gkHu3MYr2nnYOEsK4E/YiDhJWfLxzj1R0J2xnt8NfmrBK mIG4BrzYMHY4XOvPM8muA1DqeIvFq/A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608691; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5n8Jhuz8lWIN9hi2PwsThD9v5LavYKY6GCrzf/ZoXlA=; b=VIwwW1oLPNUAbCMDKJGfhY2VH1eT8Suu+ZoE0N2I2GRMz6DjnM5cB0TI4ZwFU5CD1vwOW+ 8+lLsAXLyTGzvzDA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608691; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5n8Jhuz8lWIN9hi2PwsThD9v5LavYKY6GCrzf/ZoXlA=; b=dGsZpU/tz1+fvxvfGpa3cGh389hlkHQ6dSvpeneXvhw6WVRuEAIEL9o9rT52wdC7LZANb8 5GFzvyX2srGEHJdndQfKEAF+5gkHu3MYr2nnYOEsK4E/YiDhJWfLxzj1R0J2xnt8NfmrBK mIG4BrzYMHY4XOvPM8muA1DqeIvFq/A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608691; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5n8Jhuz8lWIN9hi2PwsThD9v5LavYKY6GCrzf/ZoXlA=; b=VIwwW1oLPNUAbCMDKJGfhY2VH1eT8Suu+ZoE0N2I2GRMz6DjnM5cB0TI4ZwFU5CD1vwOW+ 8+lLsAXLyTGzvzDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 75D621369A; Wed, 10 Jul 2024 10:51:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 0H5rGLJnjmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:30 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , David Hildenbrand , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [RFC PATCH 7/8] mm: Drop hugetlb_get_unmapped_area{_*} functions Date: Wed, 10 Jul 2024 12:50:41 +0200 Message-ID: <20240710105042.30165-8-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240710105042.30165-1-osalvador@suse.de> References: <20240710105042.30165-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_SEVEN(0.00)[11]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; R_RATELIMIT(0.00)[to_ip_from(RL61jpu64h8b3ddwbzqogesdsf)]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Score: -6.80 X-Spam-Level: Content-Type: text/plain; charset="utf-8" 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 =20 =20 -unsigned long -hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h =3D 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 =3D 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/sl= ice.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) =20 return 1UL << mmu_psize_to_shift(get_slice_psize(vma->vm_mm, vma->vm_star= t)); } - -unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long a= ddr, - 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; } =20 -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 =3D hstate_file(file); - struct vm_unmapped_area_info info =3D {}; - - info.length =3D len; - info.low_limit =3D current->mm->mmap_base; - info.high_limit =3D TASK_SIZE; - info.align_mask =3D 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 =3D hstate_file(file); - struct vm_unmapped_area_info info =3D {}; - unsigned long addr; - - info.flags =3D VM_UNMAPPED_AREA_TOPDOWN; - info.length =3D len; - info.low_limit =3D PAGE_SIZE; - info.high_limit =3D current->mm->mmap_base; - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - addr =3D 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 !=3D -ENOMEM); - info.flags =3D 0; - info.low_limit =3D TASK_UNMAPPED_BASE; - info.high_limit =3D TASK_SIZE; - addr =3D vm_unmapped_area(&info); - } - - return addr; -} - -unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long a= ddr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h =3D hstate_file(file); - struct mm_struct *mm =3D 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 =3D ALIGN(addr, huge_page_size(h)); - vma =3D find_vma(mm, addr); - if (TASK_SIZE - len >=3D addr && addr >=3D mmap_min_addr && - (!vma || addr + len <=3D vm_start_gap(vma))) - goto check_asce_limit; - } - - if (!test_bit(MMF_TOPDOWN, &mm->flags)) - addr =3D hugetlb_get_unmapped_area_bottomup(file, addr, len, - pgoff, flags); - else - addr =3D 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 =20 -/* 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 =3D hstate_file(filp); - unsigned long task_size =3D TASK_SIZE; - struct vm_unmapped_area_info info =3D {}; - - if (test_thread_flag(TIF_32BIT)) - task_size =3D STACK_TOP32; - - info.length =3D len; - info.low_limit =3D TASK_UNMAPPED_BASE; - info.high_limit =3D min(task_size, VA_EXCLUDE_START); - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - addr =3D vm_unmapped_area(&info); - - if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) { - VM_BUG_ON(addr !=3D -ENOMEM); - info.low_limit =3D VA_EXCLUDE_END; - info.high_limit =3D task_size; - addr =3D vm_unmapped_area(&info); - } - - return addr; -} - -static unsigned long -hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long a= ddr0, - const unsigned long len, - const unsigned long pgoff, - const unsigned long flags) -{ - struct hstate *h =3D hstate_file(filp); - struct mm_struct *mm =3D current->mm; - unsigned long addr =3D addr0; - struct vm_unmapped_area_info info =3D {}; - - /* This should only ever run for 32-bit processes. */ - BUG_ON(!test_thread_flag(TIF_32BIT)); - - info.flags =3D VM_UNMAPPED_AREA_TOPDOWN; - info.length =3D len; - info.low_limit =3D PAGE_SIZE; - info.high_limit =3D mm->mmap_base; - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - addr =3D 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 !=3D -ENOMEM); - info.flags =3D 0; - info.low_limit =3D TASK_UNMAPPED_BASE; - info.high_limit =3D STACK_TOP32; - addr =3D 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 =3D hstate_file(file); - struct mm_struct *mm =3D current->mm; - struct vm_area_struct *vma; - unsigned long task_size =3D TASK_SIZE; - - if (test_thread_flag(TIF_32BIT)) - task_size =3D 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 =3D ALIGN(addr, huge_page_size(h)); - vma =3D find_vma(mm, addr); - if (task_size - len >=3D addr && - (!vma || addr + len <=3D 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); -} =20 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 =20 -#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 =3D hstate_file(file); - struct vm_unmapped_area_info info =3D {}; - - info.length =3D len; - info.low_limit =3D get_mmap_base(1); - - /* - * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area - * in the full address space. - */ - info.high_limit =3D in_32bit_syscall() ? - task_size_32bit() : task_size_64bit(addr > DEFAULT_MAP_WINDOW); - - info.align_mask =3D 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 =3D hstate_file(file); - struct vm_unmapped_area_info info =3D {}; - - info.flags =3D VM_UNMAPPED_AREA_TOPDOWN; - info.length =3D len; - info.low_limit =3D PAGE_SIZE; - info.high_limit =3D 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 +=3D TASK_SIZE_MAX - DEFAULT_MAP_WINDOW; - - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - addr =3D 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 !=3D -ENOMEM); - info.flags =3D 0; - info.low_limit =3D TASK_UNMAPPED_BASE; - info.high_limit =3D TASK_SIZE_LOW; - addr =3D vm_unmapped_area(&info); - } =20 - 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 =3D hstate_file(file); - struct mm_struct *mm =3D 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 &=3D huge_page_mask(h); - if (!mmap_address_hint_valid(addr, len)) - goto get_unmapped_area; - - vma =3D find_vma(mm, addr); - if (!vma || addr + len <=3D 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 */ =20 #ifdef CONFIG_X86_64 bool __init arch_hugetlb_valid_size(unsigned long size) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index b2d7fcecdb15..722e60327615 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -171,92 +171,6 @@ static int hugetlbfs_file_mmap(struct file *file, stru= ct vm_area_struct *vma) * Called under mmap_write_lock(mm). */ =20 -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 =3D hstate_file(file); - struct vm_unmapped_area_info info =3D {}; - - info.length =3D len; - info.low_limit =3D current->mm->mmap_base; - info.high_limit =3D arch_get_mmap_end(addr, len, flags); - info.align_mask =3D 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 =3D hstate_file(file); - struct vm_unmapped_area_info info =3D {}; - - info.flags =3D VM_UNMAPPED_AREA_TOPDOWN; - info.length =3D len; - info.low_limit =3D PAGE_SIZE; - info.high_limit =3D arch_get_mmap_base(addr, current->mm->mmap_base); - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - addr =3D 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 !=3D -ENOMEM); - info.flags =3D 0; - info.low_limit =3D current->mm->mmap_base; - info.high_limit =3D arch_get_mmap_end(addr, len, flags); - addr =3D 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 =3D current->mm; - struct vm_area_struct *vma; - struct hstate *h =3D hstate_file(file); - const unsigned long mmap_end =3D 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 =3D ALIGN(addr, huge_page_size(h)); - vma =3D find_vma(mm, addr); - if (mmap_end - len >=3D addr && - (!vma || addr + len <=3D 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); =20 -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.pri= vate * of the hugetlb head page. Functions created via the below macros shoul= d be --=20 2.45.2 From nobody Wed Dec 17 12:08:34 2025 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C563C191F95 for ; Wed, 10 Jul 2024 10:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608696; cv=none; b=f2Bk6y6mfrnWo3zNxAPnWngmIA0+7/W5EbJHMJYy5AR0IfhGbwPgmn78BSQ8gX8wn5yi2GHrUi7przHfTbfRxMMvK3waFEscff5tO6uqa5Hjv8ScOo3lZ9ZkicyQ9B9uc9RMJYuz3G+rHHP9WmvJxESakd+Mjn/kbIznE1xs44Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608696; c=relaxed/simple; bh=ybqIPHDsajNAyasPWa/siY7VxuHeP9mYmsaiuNS9Z9s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kEmG5STOVo3cltCoc8ReMJV6lltjrC6A0Q25WpWk4GrP7GWeqsa0TjwR/lPC+SQWlz9MNjR7nNpkutvZvphYI8kenMcJR3yQ8cjdRV/8LEy3/Har9Yj6UWOBBgr8Tf88LLqA5aw6fS1XQpEyrC2y3CIaz2bjv5fLS48lBDmYS90= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=A98K2eBm; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=j/VNTJ8g; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=rs4IeFFz; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=t6BWMfnr; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="A98K2eBm"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="j/VNTJ8g"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="rs4IeFFz"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="t6BWMfnr" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E21F121A3D; Wed, 10 Jul 2024 10:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608693; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m7b0FFfloSBNSR2ZzezMp+fU3t5dKSCqfMIY6cE3U0k=; b=A98K2eBm6Gsqbion+I8upTty0hFnnNSEoZJDzP8V3Ba7Zd8avnjBnknSIEblzvcgRWO3f9 7xTFJhTCQjH2Hq6tGHv4juQDJiWHP/5vdUjuLKqRFfQi7Im1E9JCcrwRa5A09W2oFetiIB 11iXdwkRurVljAjqGqpWXIeVyeS4PtE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608693; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m7b0FFfloSBNSR2ZzezMp+fU3t5dKSCqfMIY6cE3U0k=; b=j/VNTJ8gVG5iHz8ywTjWTHn20BAe7Zgu3aD9+u+Ei2+8RVyx0Hfk6rgbHq0UxO64HONWBC p5bNzdbCwc84EBAw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720608692; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m7b0FFfloSBNSR2ZzezMp+fU3t5dKSCqfMIY6cE3U0k=; b=rs4IeFFzhz69FMWvI0QKY00JQtl778j3n78qia0/IsoPc0P6GNP6iBmn8UOFrweyMGe4Md Xy87v1OVVvjvvuz/nc7EKHWWeRkgAa2kustip+8z2BPVKzM/SHL5ubgqlYQKI9dcWh9rYW PQcxbkGSx8kMqhv9vEUcDHH4184Qnno= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720608692; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m7b0FFfloSBNSR2ZzezMp+fU3t5dKSCqfMIY6cE3U0k=; b=t6BWMfnrG2VPsHdWL347hUkhoiFuG1SE0aSsXFmtmrBxY0QA0RyX3XAgJUyybj2K3cD+H7 PsC15Z+C8sHLNvDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CB26D1369A; Wed, 10 Jul 2024 10:51:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 8L0uLbNnjmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:31 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , David Hildenbrand , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [RFC PATCH 8/8] mm: Consolidate common checks in hugetlb_mmap_check_and_align Date: Wed, 10 Jul 2024 12:50:42 +0200 Message-ID: <20240710105042.30165-9-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240710105042.30165-1-osalvador@suse.de> References: <20240710105042.30165-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -6.80 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_SEVEN(0.00)[11]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; R_RATELIMIT(0.00)[to_ip_from(RL61jpu64h8b3ddwbzqogesdsf)]; RCVD_TLS_ALL(0.00)[] Content-Type: text/plain; charset="utf-8" prepare_hugepage_range() performs almost the same checks for all architectures that define it, with the exception of mips and loongarch that also check for overflows. The rest checks for the addr and len to be properly aligned, so we can move that to the generic hugetlb_mmap_check_and_align() function and get rid of a fair amount of duplicated code. Signed-off-by: Oscar Salvador --- arch/loongarch/include/asm/hugetlb.h | 4 ---- arch/mips/include/asm/hugetlb.h | 4 ---- arch/parisc/include/asm/hugetlb.h | 15 --------------- arch/s390/include/asm/hugetlb.h | 16 ---------------- arch/sh/include/asm/hugetlb.h | 15 --------------- fs/hugetlbfs/inode.c | 8 ++++++-- include/asm-generic/hugetlb.h | 7 ------- 7 files changed, 6 insertions(+), 63 deletions(-) diff --git a/arch/loongarch/include/asm/hugetlb.h b/arch/loongarch/include/= asm/hugetlb.h index aa44b3fe43dd..107566c98938 100644 --- a/arch/loongarch/include/asm/hugetlb.h +++ b/arch/loongarch/include/asm/hugetlb.h @@ -18,10 +18,6 @@ static inline int prepare_hugepage_range(struct file *fi= le, unsigned long task_size =3D STACK_TOP; struct hstate *h =3D hstate_file(file); =20 - 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/hugetl= b.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 *fi= le, unsigned long task_size =3D STACK_TOP; struct hstate *h =3D hstate_file(file); =20 - 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/hu= getlb.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); =20 -/* - * 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/hugetl= b.h index ce5f4fe8be4d..38a10b47dc99 100644 --- a/arch/s390/include/asm/hugetlb.h +++ b/arch/s390/include/asm/hugetlb.h @@ -23,22 +23,6 @@ pte_t huge_ptep_get(pte_t *ptep); pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep); =20 -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - struct hstate *h =3D 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 =20 -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - if (len & ~HPAGE_MASK) - return -EINVAL; - if (addr & ~HPAGE_MASK) - return -EINVAL; - return 0; -} - #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 722e60327615..82ec499feb41 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -180,8 +180,12 @@ hugetlb_mmap_check_and_align(struct file *file, unsign= ed long addr, =20 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 =3D ALIGN(addr, huge_page_size(h)); =20 diff --git a/include/asm-generic/hugetlb.h b/include/asm-generic/hugetlb.h index 6dcf4d576970..d522581441e5 100644 --- a/include/asm-generic/hugetlb.h +++ b/include/asm-generic/hugetlb.h @@ -115,13 +115,6 @@ static inline int huge_pte_none_mostly(pte_t pte) static inline int prepare_hugepage_range(struct file *file, unsigned long addr, unsigned long len) { - struct hstate *h =3D hstate_file(file); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; - return 0; } #endif --=20 2.45.2