From patchwork Tue Sep 10 08:00:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13798082 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 7132DECE564 for ; Tue, 10 Sep 2024 08:01:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F142C8D002C; Tue, 10 Sep 2024 04:00:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E7AEA8D0029; Tue, 10 Sep 2024 04:00:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE22A8D002C; Tue, 10 Sep 2024 04:00:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 745F88D000E for ; Tue, 10 Sep 2024 04:00:55 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 24BBA80F61 for ; Tue, 10 Sep 2024 08:00:55 +0000 (UTC) X-FDA: 82548082470.05.3871A90 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf20.hostedemail.com (Postfix) with ESMTP id BA5411C000D for ; Tue, 10 Sep 2024 08:00:51 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="P3HH/9Ve"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=6+VaV++W; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="P3HH/9Ve"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=6+VaV++W; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf20.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725955248; a=rsa-sha256; cv=none; b=Wg/StVYnvlvOSgd6f8Vm9vE+VLpJFJPr9gCW1+SY4eUrw8C8PbZ4lRqSBnWuzKiCIEtr8H 41y5QM1N8DgojrehiHmc3T7ooxjoetubtOF60OkJxzm4I9jpcmtVH76aoFjw2gPeucik5o 2sxtDEycCszyp7bfIRUbFNUtb7QCUak= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="P3HH/9Ve"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=6+VaV++W; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="P3HH/9Ve"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=6+VaV++W; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf20.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725955248; 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=dh8ID66bUaRGXz2gnq8rzcTDLeuCZFk4H+eROj1OqJY=; b=x6GWFX5p4ya61UEubBbJUKd6MPWXU+HO5k6CyvPHuwNdH6BIUZPL5172PAqNeKm8l5dM02 s8t6Wo07tHHkEuCtf+ZO50uy/tOiuR+QSRpNxqzMJLZeZvdlDdtmPyYTRO5B1kL3jAxhtJ a2ZoGhVW31bmuTnZAK2ANeF007ZRTkE= 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 72B111F80A; Tue, 10 Sep 2024 08:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955249; 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=dh8ID66bUaRGXz2gnq8rzcTDLeuCZFk4H+eROj1OqJY=; b=P3HH/9VeO7/hs9W02KLJGbUQbz6TwJPMh5eQ2KsOessc88XZDb+B6rbkgJV7KGjJn2IK5n WwCZ4BHpYGeWoIN4Ie98Txw3mHCx4CHPS5VeOI1MGATKiQFg45BqH1XQVwFWME2xGaWt78 tzuUkn6bEwf6leksfA/2wbq3i2lZctU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955249; 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=dh8ID66bUaRGXz2gnq8rzcTDLeuCZFk4H+eROj1OqJY=; b=6+VaV++WekZwnCQTHieIrPzmnni7tH8IuusN+gNlU2UPhwMNZ6FIBnLeq4wzMa7ZyDqDBr Dalx+1Wzn0NIrvBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955249; 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=dh8ID66bUaRGXz2gnq8rzcTDLeuCZFk4H+eROj1OqJY=; b=P3HH/9VeO7/hs9W02KLJGbUQbz6TwJPMh5eQ2KsOessc88XZDb+B6rbkgJV7KGjJn2IK5n WwCZ4BHpYGeWoIN4Ie98Txw3mHCx4CHPS5VeOI1MGATKiQFg45BqH1XQVwFWME2xGaWt78 tzuUkn6bEwf6leksfA/2wbq3i2lZctU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955249; 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=dh8ID66bUaRGXz2gnq8rzcTDLeuCZFk4H+eROj1OqJY=; b=6+VaV++WekZwnCQTHieIrPzmnni7tH8IuusN+gNlU2UPhwMNZ6FIBnLeq4wzMa7ZyDqDBr Dalx+1Wzn0NIrvBw== 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 AC6E113A8F; Tue, 10 Sep 2024 08:00:48 +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 KOYuJ7D832Y2MQAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 08:00:48 +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 1/9] mm/mmap: Teach generic_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Tue, 10 Sep 2024 10:00:22 +0200 Message-ID: <20240910080030.1272373-2-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-Rspamd-Action: no action X-Rspam-User: X-Stat-Signature: z4s5qb4ci1c8k3oi39mw6x9h59sp1rb3 X-Rspamd-Queue-Id: BA5411C000D X-Rspamd-Server: rspam02 X-HE-Tag: 1725955251-408873 X-HE-Meta: U2FsdGVkX18EBVPGo5MWRsUiWN7BrjHcFT4hlLGGFlriEHAu9W1IN93s8mzMIFkQYEC32FQSkFvmfX4OPq2KoMGnsCqacihPUcYFaHI3t2ZaooLEZcXFOukGvpZhPA6gbQAPqyyFMzUK+sDOxvzNMrYpn1h3rKd++LngcVPHVeVSpLEVDFosLMM8197uIsMmOpXD/qGV4QHsqH66TqDpkS79GTe1SklfmRkmRFzvA5DUIAnpv/V+TNDjsjaZG7FMGOYt2DVC4nOU6JKxsSfBcli4V2JnmeafLucYJBysjnC/Twt8rk6iZP+W2F7BYBzBDRFZ/MBkNJZuV/mk1y6iW48gA+7y4FLB3p6fGdt/We4nj4PWi4XFmyi4wXRML9Clv52vRR1dQRwdUH6FLxeTMRlZth2GTnVIez9yepwtr3qs7lHdYMALlrirWF9YkDbGJtdEb7kU8yDv8atvTyTbXE7FJIcCR/m2+P1AmzWtcKvZrVnzL5LUV+9YprzgjwFed95LsDnVFrYVV8PEfTxzKRIb9p1wml0wnH8as2dZ12SzTl2i11MwjfKg4qV3oq4CBIcB1ZJ58P0UDndf0KpYLEoHR/BdipJaGPJdLv4xHi9Idjb01rF+u2UO7ufkBlCai/yfADcPhdISOHHxd6F80pEYaoMAoKLeOvBLjPyM9AS08MrPuGvRPkY4OkBDt/pwb8TDOBBkIliu7xLtIRSpBGMgQOhPMaRLfZw0ioCdlCb/L/MyBBjEfUTHK55v+Scf8wfEICOtMAmDXy7hT6tcOMaq4pY9xkGKlvC1AWTNmfU05GGYLI8rG0X9QLZ3UESOvUpSq1Innm4vbIInszVFNMmKr5UihH5DGfAV1AN7ulAlUvNxQvQlqjQ/c/jQJ41F5b5wH9mgYYVVyUStmbY2Qv1Q6LBOc8uHMuR9fiWJRbDOEKsABbGMhqVc5CjUjHx5KYjwF6m4KrC4WNWsjr6 o1mNI0Du 5FQGvskhl27IQ7gPknd2c1w6mjQieFc3P9IH8sUi9glMrVF0H5OpUHpxhve+y/SjtO/Bq7hIA+Yx6gYAau0VDa/cgoJFCSk5p4ExXUwwxKWQvoNpJpR+zczvHm7TIR5j0uoeVut036AiiUmd28BEHbK2puhDInuyoWFZnVOmQWwcphnhJUR87sowcOBeYDVt0S56dZKRpeWCId1sdg1hADGjOS7SU7knRrkx6u+Yj9O22TvoOG8j54w4OoH1Z3pAiZvT1HQQTl9I11ZutuPzHoEEk9w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to stop special casing hugetlb mappings and make them go through generic channels, so teach generic_get_unmapped_area{_topdown} to handle those. The main difference is that we set info.align_mask for huge mappings. Signed-off-by: Oscar Salvador --- include/linux/hugetlb.h | 10 ++++++++++ mm/mmap.c | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index e4697539b665..368d552e4860 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -1035,9 +1035,19 @@ void hugetlb_unregister_node(struct node *node); */ bool is_raw_hwpoison_page_in_hugepage(struct page *page); +static inline unsigned long huge_page_mask_align(struct file *file) +{ + return PAGE_MASK & ~huge_page_mask(hstate_file(file)); +} + #else /* CONFIG_HUGETLB_PAGE */ struct hstate {}; +static inline unsigned long huge_page_mask_align(struct file *file) +{ + return 0; +} + static inline struct hugepage_subpool *hugetlb_folio_subpool(struct folio *folio) { return NULL; diff --git a/mm/mmap.c b/mm/mmap.c index 270bd8d504b8..5f05df7d58f5 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -776,6 +776,8 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr, info.low_limit = mm->mmap_base; info.high_limit = mmap_end; info.start_gap = stack_guard_placement(vm_flags); + if (filp && is_file_hugepages(filp)) + info.align_mask = huge_page_mask_align(filp); return vm_unmapped_area(&info); } @@ -826,6 +828,8 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr, info.low_limit = PAGE_SIZE; info.high_limit = arch_get_mmap_base(addr, mm->mmap_base); info.start_gap = stack_guard_placement(vm_flags); + if (filp && is_file_hugepages(filp)) + info.align_mask = huge_page_mask_align(filp); addr = vm_unmapped_area(&info); /* From patchwork Tue Sep 10 08:00:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13798079 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 9056CECE582 for ; Tue, 10 Sep 2024 08:00:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E27298D0025; Tue, 10 Sep 2024 04:00:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD7208D000E; Tue, 10 Sep 2024 04:00:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C77EF8D0025; Tue, 10 Sep 2024 04:00:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A4DC28D000E for ; Tue, 10 Sep 2024 04:00:54 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3C955AA06C for ; Tue, 10 Sep 2024 08:00:54 +0000 (UTC) X-FDA: 82548082428.05.E9A9AE1 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf27.hostedemail.com (Postfix) with ESMTP id 0166740004 for ; Tue, 10 Sep 2024 08:00:51 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=EHkxGpw6; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Q9CnDgtj; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=EHkxGpw6; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Q9CnDgtj; spf=pass (imf27.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725955150; 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=Sr2a885zzyye8BXAHIM5ZgoDsL83/5XNiIIL6NfSFFI=; b=ucqAIn7vJixZYarjjfa3IVsQTI6xnRCHEMh5OLPLNHDaxkmULrsRsYKjfAdSiJ4JJ6bWd+ n38J+1Bd+/RGjpnWyJsHJIcQVkFu11hBrfAaZH46fyG4P+bP4NsqnMxNw4yjo+5LRItouN 9jp3UKaRlwcPLnrABnxLgBcijeBq4xo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725955150; a=rsa-sha256; cv=none; b=pIrhMDu07r6cwxEC0x2jdS5qJhQ4JJ3L/AUjQ5HGu9Z9YiT+HZv6t8JGvcNipA9WZSU+nR Qb8oNnl9ZnWfkqYZLs+wYuvynpxaaFMLwi8XOihRfpa2F35W/nbk78KPJcOHi2MM7df61O A/s/csA7rH4h64RUKehgxr+PfW98RcQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=EHkxGpw6; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Q9CnDgtj; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=EHkxGpw6; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Q9CnDgtj; spf=pass (imf27.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de 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 3525721A27; Tue, 10 Sep 2024 08:00:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955250; 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=Sr2a885zzyye8BXAHIM5ZgoDsL83/5XNiIIL6NfSFFI=; b=EHkxGpw6SXl/ZSTSwdFHmiqjuZYwYlDZuV8GMLVE2LwaWE2nmU9JioHe8WmAUmfETIqwDP cAioIqOiC1DYc5bdgzpHZhT73SJYRTjqHQQ3Ia0y9aKTKEob+MTPgj+PkphpQLQ0UGflQ7 m+216c9puWvPIyrkIIf5SLM4I3zikXc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955250; 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=Sr2a885zzyye8BXAHIM5ZgoDsL83/5XNiIIL6NfSFFI=; b=Q9CnDgtjmYwf/fFqqitTqsQlpYO+d9y2X477u0d6IW2VHKIomEkcmiU+tQWtOtY9uaZQLX zCQeNwwM8f69srCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955250; 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=Sr2a885zzyye8BXAHIM5ZgoDsL83/5XNiIIL6NfSFFI=; b=EHkxGpw6SXl/ZSTSwdFHmiqjuZYwYlDZuV8GMLVE2LwaWE2nmU9JioHe8WmAUmfETIqwDP cAioIqOiC1DYc5bdgzpHZhT73SJYRTjqHQQ3Ia0y9aKTKEob+MTPgj+PkphpQLQ0UGflQ7 m+216c9puWvPIyrkIIf5SLM4I3zikXc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955250; 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=Sr2a885zzyye8BXAHIM5ZgoDsL83/5XNiIIL6NfSFFI=; b=Q9CnDgtjmYwf/fFqqitTqsQlpYO+d9y2X477u0d6IW2VHKIomEkcmiU+tQWtOtY9uaZQLX zCQeNwwM8f69srCA== 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 7B79F13AB1; Tue, 10 Sep 2024 08:00:49 +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 KFhkG7H832Y2MQAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 08:00:49 +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 2/9] arch/s390: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Tue, 10 Sep 2024 10:00:23 +0200 Message-ID: <20240910080030.1272373-3-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-Rspamd-Queue-Id: 0166740004 X-Stat-Signature: g3ugwp9zmkobahbkgxg5qwwcrsgzhcxc X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725955251-244402 X-HE-Meta: U2FsdGVkX1+gWaZuFK94gpMnLIUC6IMkajBKi/M/o1Dotx91ixZfP1cixNK7AIz4555u0ESFF1cp3bM4h/E3l3EE456OWZI7/Z1ZeEARzIO8mGfyFF4sjG36GjH8U4ptBtTuD45OJ3YBO2M8ya2lEgAvxtWNyaTORzJPHxspVnecbvc0amg3Ua4d90HPMkySQzm6OsuqNQ4kWZG27rRTktjrdYOmzszPXiyWIzcBpWRtZcAVhzn40zsyI2i/Ds9g7CcvWVPxNqX/K2rPPyhaeh6KzIWG5g8uNft4JtSzv5vomUdzKl0rWRRe6nA5Ssc3s6HZJ6tHz/MN04YLKfeygIJJPe2DZXOx2GUaPSAr2+6tykc38HKuE+HelSQEV6FOvFadpMJBt1WQPZClUwHxn/cJH2X37GbZwGaSt2zdBn1f/5IYzw2u9kuMMQfRsyJt+X2eJTosoR8PO8AzJmIGArPyd9NWd4/DTmTwjoqYQeXMvU2mWKjaeq+eK+npuZflg3i1U/NAbvdHOj4ZAMoh3SWyWMaWh+9m48JZUiynrShtAeFRkC/p22B94Ym4+DxOiYUHJ7F27spv5NjPpQeBtV757rGKBt0BEWJDNo9DCbYtUo/NpvTq1rBGCpJYuYcLSM1TwCnMcQm2Z+L+1mbAPMcKUZmnelkANW/0LcCkN+JGJzyi35qbfqVyS0brX3dH9KoNCTZAFqhLa7aabyXXrcC4RJ2P6qvPifdCiHjli+RJar2A7tCyOXoPjzhD1Fshnh3j7ZqhKVAkhHcaaD+Xx13Q/WeSs8SE4bZQ8HEHVNzXlWwIReVd3+uw3+S9KaywjOKbHKClz8RJcBEsAzbV99KSaoR4P6P/Ue8JXqAcrjhoqR24hlPRKdQolKDaLYZMl4QNxzCpir3Ctd2uhzLQDKDuf+SgAX4AltXyxbu51B2Igj5BME62GzRZtjkH9iQ9slRNq0ohTAPiBooHx16 p94Xof4Q 4yTq2qEGJAw7o44ES4iqLk2vuAajPLCRvdjGA0hJ8m1cPS3ami/uKjqmXGYOgQGvrQPvotbxa+3vyT/y9KWxGCL7V/z5D4BuHMX2Mp680NGXHP9Uvgm+5r0FgfFlizZMCWt1GTCnospNb1RIoV3osSWThmQ9o3dHS2Aj6l7zjcotB7Sn0On3j++B3Q4vtlz2rq7rv8PXER4s7y0yKorUy9q5vkWqne10kQuej+IiHXONZBi5ztN2cpLWUoJF+dL2Vt9l+YMYk3bUVx5ow43e5hNZHTw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area{_topdown} to handle those. s390 specific hugetlb function does not set info.align_offset, so do the same here for compatibility. Signed-off-by: Oscar Salvador --- arch/s390/mm/mmap.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c index 96efa061ce01..33f3504be90b 100644 --- a/arch/s390/mm/mmap.c +++ b/arch/s390/mm/mmap.c @@ -17,6 +17,7 @@ #include #include #include +#include #include static unsigned long stack_maxrandom_size(void) @@ -73,6 +74,8 @@ static inline unsigned long mmap_base(unsigned long rnd, static int get_align_mask(struct file *filp, unsigned long flags) { + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); if (!(current->flags & PF_RANDOMIZE)) return 0; if (filp || (flags & MAP_SHARED)) @@ -106,7 +109,8 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, info.low_limit = mm->mmap_base; info.high_limit = TASK_SIZE; info.align_mask = get_align_mask(filp, flags); - info.align_offset = pgoff << PAGE_SHIFT; + if (!(filp && is_file_hugepages(filp))) + info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); if (offset_in_page(addr)) return addr; @@ -144,7 +148,8 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, unsigned long ad info.low_limit = PAGE_SIZE; info.high_limit = mm->mmap_base; info.align_mask = get_align_mask(filp, flags); - info.align_offset = pgoff << PAGE_SHIFT; + if (!(filp && is_file_hugepages(filp))) + info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); /* From patchwork Tue Sep 10 08:00:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13798080 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 E36CFECE564 for ; Tue, 10 Sep 2024 08:00:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 756208D0026; Tue, 10 Sep 2024 04:00:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F9BD8D0027; Tue, 10 Sep 2024 04:00:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 560D78D000E; Tue, 10 Sep 2024 04:00:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 379798D000E for ; Tue, 10 Sep 2024 04:00:55 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B794140A99 for ; Tue, 10 Sep 2024 08:00:54 +0000 (UTC) X-FDA: 82548082428.13.896CC54 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf28.hostedemail.com (Postfix) with ESMTP id 85370C000D for ; Tue, 10 Sep 2024 08:00:52 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1BAI1Uzw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=B1CHF1FU; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1BAI1Uzw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=B1CHF1FU; spf=pass (imf28.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725955201; 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=ECz/ucTq55vu26EzU15Ueg1Bt6OrgMPODU+khQ9gIJU=; b=lgR1IiJJygHf1TCZWAkFLA3AQoliZqu6YOr+K9I6wwv3j8K/6KP2HgtPTKXFMf1rRX3tKL YaP7+3RN/S1KqIcEE/W+BSrT4MWDOUCg9nsbObmgwANUfWmRtrFZwYlswj2VwX1NHiVj2I ecaHFSUlVwVAsfH/4LWQ/CTNWJWSYjs= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1BAI1Uzw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=B1CHF1FU; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1BAI1Uzw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=B1CHF1FU; spf=pass (imf28.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725955201; a=rsa-sha256; cv=none; b=lZHTrjecWu7L/8j5bZeNFMv6qEPcEfoW5hM4rTgsFYZfldKqiYRzE4kgz6q1lO6rqlQoqP QEOPZxSfL8enm+dd5y5lXbrCvTv6wF9L/DeqEASfjP1PBbf6W8bzUzXEvB8PzsTtAmMENj tDDNIj8rUKWuCr4ZAjJszReZSIb7lsE= 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 03C4121A3A; Tue, 10 Sep 2024 08:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955251; 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=ECz/ucTq55vu26EzU15Ueg1Bt6OrgMPODU+khQ9gIJU=; b=1BAI1UzwrJylDZdLs/tm23hsXSNM5Pt2JIUkgso7a+VmLemiWBz3yEbcqqCjmU/l4M2mCa RSou/oYGMbVAzURx2UqKdVYcTr6qpy84LMLQkwFTSfgbkpQaGa4htSr58WTCtPR/zJaWwx T4latjkh4xbhguWuW94bmXKU3ANXEqQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955251; 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=ECz/ucTq55vu26EzU15Ueg1Bt6OrgMPODU+khQ9gIJU=; b=B1CHF1FUCQgjAfBzphbfQXEqo50g2GfTlJhOUhGMVk2VrghOqDRTTokchbnS+RjmdkotaF MXaiHDXJymZZlVAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955251; 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=ECz/ucTq55vu26EzU15Ueg1Bt6OrgMPODU+khQ9gIJU=; b=1BAI1UzwrJylDZdLs/tm23hsXSNM5Pt2JIUkgso7a+VmLemiWBz3yEbcqqCjmU/l4M2mCa RSou/oYGMbVAzURx2UqKdVYcTr6qpy84LMLQkwFTSfgbkpQaGa4htSr58WTCtPR/zJaWwx T4latjkh4xbhguWuW94bmXKU3ANXEqQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955251; 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=ECz/ucTq55vu26EzU15Ueg1Bt6OrgMPODU+khQ9gIJU=; b=B1CHF1FUCQgjAfBzphbfQXEqo50g2GfTlJhOUhGMVk2VrghOqDRTTokchbnS+RjmdkotaF MXaiHDXJymZZlVAw== 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 49157132CB; Tue, 10 Sep 2024 08:00:50 +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 KG3tDrL832Y2MQAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 08:00:50 +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 3/9] arch/x86: Teach arch_get_unmapped_area_vmflags to handle hugetlb mappings Date: Tue, 10 Sep 2024 10:00:24 +0200 Message-ID: <20240910080030.1272373-4-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-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 85370C000D X-Stat-Signature: 1zy7rn7gwraa93w6tuo8axwkenx4u3rn X-HE-Tag: 1725955252-722435 X-HE-Meta: U2FsdGVkX19udSODPS3fnLkEWMiH6kqZEEWGd8UUchyJ2YkG6I5kqh28glIwzoInd3HfltkZGtR9cvR95S3OerrDsdHIlZbBA1gKd0CUX0vHr0vayf16qX+ynzUL7L13Ka01wTd08ZfKWAHa4eokDfQnaPX1ywjD1Gjund/tiuU3DezsHA7gbk4C/IXcRoSpZN8V57Oi0ox09jxFFdfhqEUHP7e+hmaINc04XkYVUaV2YqaN5AlnsSRKWHOxWgmF2ua99t+dpYGc9YgEFOoZuQKRadTg182aShv0Dhgh5UnInqQbE4t/dg4HTzpBQ8z3vlN4Qpihwg5BXMXXDzS+WFoNcdt/KpzJsY7h6TTXOxSckJHI4y+2Q31NKuYFFM+SclulwAwXAxqZ+r8VEjhl6KaUSVsOAXA5Gc8f0vKghKqDqUDGhQtqOh4j+BzplwqfVXLiJWIOOmx09AjsFTjUvea6Pb/tKvpOzlNrDRycSCKPYKE2iPJ9l9TjZ5NasU0Nm1VV2tYMJOi9SsLTlo3QYg2DyXFY7j7fy8yaEG0YNmC/p6VGo7CD0KJrYM0JHwQF2TtlhyvO1sRLVPRjgdBh0mLT7IFOfBI6S8vlJFp7pLqK6QUvkq4B8J3iN+tjdq+wvQ6XgNEAwyqT+sUh8KbjG/L80AkE9RFjkftjuo0AtO43pss8/5j1MSn2Vmk6p9OE9y3QMBoHxDoqSya2/809vtP6rdjOjJVB9Lif2Fy5BwzAYHBp6Bp1yuvGToTcQGrT5+YKFANbd97+7q75+v04tdH/8Z2OgXolo8Mm31+3V2y5iMQ1VH52lZcW24V4aXaIP89W5xZYmL4tmibRijVS+oaPpxMNTxsIFQ2Gq/OPbx3X9LWbgK5+FeuP6S0kImXQkcGee+vjWmTxTCV3iPcKUpq+Df0bryX7+mVy5tNlctscNrFy5H1akdHU5UeHWoARF53oW9HPcGIJadK2RdV q/y+yGll AGrGccuUsdEg5sckJX13hhBaPdnQ3cN0xHRSZ5wdh/m2+jB3qZKVx/bra3sjydMqk0Asl2kfivR+CaKEnYswCd4a8Qf7V4nWdvS7CSKlHXUp8CNWzaYqWVzB8ZEe/EKYhpm07Fccwp2JFQDve5ReY2ncwoEJqFTanAAIklaPTAYP167HijY3Y5S7ofWenfGc6BJK2e34tyhG9vbAh8s7RCgikDgSLrDRevhR2oqgitKhW5LGQ6DErpFgmDKVLURgbkRqPhru2xRh95l3QjzJzHavPPhmaRMcqLEJa2jElA/C5xI/rvEtegt4udA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area_{topdown_}vmflags to handle those. x86 specific hugetlb function does not set either info.start_gap or info.align_offset so the same here for 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 87f8c9a71c49..776ae6fa7f2d 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -25,8 +26,10 @@ /* * Align a virtual address to avoid aliasing in the I$ on AMD F15h. */ -static unsigned long get_align_mask(void) +static unsigned long get_align_mask(struct file *filp) { + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); /* handle 32- and 64-bit case with a single conditional */ if (va_align.flags < 0 || !(va_align.flags & (2 - mmap_is_ia32()))) return 0; @@ -49,7 +52,7 @@ static unsigned long get_align_mask(void) */ static unsigned long get_align_bits(void) { - return va_align.bits & get_align_mask(); + return va_align.bits & get_align_mask(NULL); } static int __init control_va_addr_alignment(char *str) @@ -148,12 +151,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, info.length = len; info.low_limit = begin; info.high_limit = end; - info.align_offset = pgoff << PAGE_SHIFT; - info.start_gap = stack_guard_placement(vm_flags); + if (!(filp && is_file_hugepages(filp))) { + info.align_offset = pgoff << PAGE_SHIFT; + info.start_gap = stack_guard_placement(vm_flags); + } if (filp) { - info.align_mask = get_align_mask(); + info.align_mask = get_align_mask(filp); info.align_offset += get_align_bits(); } + return vm_unmapped_area(&info); } @@ -199,7 +205,10 @@ arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr0, info.low_limit = PAGE_SIZE; info.high_limit = get_mmap_base(0); - info.start_gap = stack_guard_placement(vm_flags); + if (!(filp && is_file_hugepages(filp))) { + info.start_gap = stack_guard_placement(vm_flags); + info.align_offset = pgoff << PAGE_SHIFT; + } /* * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area @@ -211,9 +220,8 @@ arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr0, if (addr > DEFAULT_MAP_WINDOW && !in_32bit_syscall()) info.high_limit += TASK_SIZE_MAX - DEFAULT_MAP_WINDOW; - info.align_offset = pgoff << PAGE_SHIFT; if (filp) { - info.align_mask = get_align_mask(); + info.align_mask = get_align_mask(filp); info.align_offset += get_align_bits(); } addr = vm_unmapped_area(&info); From patchwork Tue Sep 10 08:00:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13798084 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 E1FB2ECE564 for ; Tue, 10 Sep 2024 08:01:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BB408D000E; Tue, 10 Sep 2024 04:00:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39FF68D0028; 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 F11F48D002B; Tue, 10 Sep 2024 04:00:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DE7848D002A for ; Tue, 10 Sep 2024 04:00:55 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 77E45160D14 for ; Tue, 10 Sep 2024 08:00:55 +0000 (UTC) X-FDA: 82548082470.29.E38AD0B Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf18.hostedemail.com (Postfix) with ESMTP id 458B31C000E for ; Tue, 10 Sep 2024 08:00:53 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=JX6qJdZZ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=hOaQUkQa; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=JX6qJdZZ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=hOaQUkQa; spf=pass (imf18.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725955151; 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=S1oClIMYimkY1FedyNCGpuuzi3Wzozij1uzLrl1txic=; b=0ioIym6ClcZzSqI8+5Y6wtjyt5eHFiUk7mO7oTc2zv5cFiEJwzTp5xiJK8J0IRROezgsrt 7QkqOAc8C569jYusSuiiW/06ar/TDA7J+6/DPjuEikAoZ02PIVE7KaAnM29frsHIQCsD+4 mWTiX2XzkT0miTcSj6Qg+MfHsCQC1so= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725955151; a=rsa-sha256; cv=none; b=K/TX322JM3YKFLbgJB2vgQE2jckiaDYOs2Pn2+lOgImGH+BkXi0jyuLfiR5aBfR6nSsw7P Lx1FNy5os54/kGf/y2LnpLhsM+WlLbEzV2MLpZRyRyayJWAzI9pCOwflkEal83Qj1VmriL IvW3cR60w0oew3aekHxtfpPcGZ1Yboo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=JX6qJdZZ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=hOaQUkQa; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=JX6qJdZZ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=hOaQUkQa; spf=pass (imf18.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de 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 C90EE21A3B; Tue, 10 Sep 2024 08:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955251; 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=S1oClIMYimkY1FedyNCGpuuzi3Wzozij1uzLrl1txic=; b=JX6qJdZZg49GAr/kJ8Z/HJu3vABzNuwAL3w6/ZfBiVZrkCePGFIlTZOAUJaE+qQE0Dh6SI qSIARGcCdfS6uUJz/Cw/6D7pmtoAzs1j5X6o88YswpntJBIEimOBMnB4RNmlNm5KjnpUoX VdfhYU9p6vVoA/z9bwHMgpWuC2AdgK4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955251; 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=S1oClIMYimkY1FedyNCGpuuzi3Wzozij1uzLrl1txic=; b=hOaQUkQa6nQYmz/CU3zMk/mPBJoTL+5uJfN4Lx25I9/NJ8lxpu+0rSbuefTrajLR1fxvzb 1FqEZAFuSpHicCAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955251; 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=S1oClIMYimkY1FedyNCGpuuzi3Wzozij1uzLrl1txic=; b=JX6qJdZZg49GAr/kJ8Z/HJu3vABzNuwAL3w6/ZfBiVZrkCePGFIlTZOAUJaE+qQE0Dh6SI qSIARGcCdfS6uUJz/Cw/6D7pmtoAzs1j5X6o88YswpntJBIEimOBMnB4RNmlNm5KjnpUoX VdfhYU9p6vVoA/z9bwHMgpWuC2AdgK4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955251; 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=S1oClIMYimkY1FedyNCGpuuzi3Wzozij1uzLrl1txic=; b=hOaQUkQa6nQYmz/CU3zMk/mPBJoTL+5uJfN4Lx25I9/NJ8lxpu+0rSbuefTrajLR1fxvzb 1FqEZAFuSpHicCAw== 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 17E8E13A8F; Tue, 10 Sep 2024 08:00:51 +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 4KbaArP832Y2MQAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 08:00:51 +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 4/9] arch/sparc: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Tue, 10 Sep 2024 10:00:25 +0200 Message-ID: <20240910080030.1272373-5-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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 458B31C000E X-Stat-Signature: r3hs73tdsg7x35xjq5rgmprjx75bm4t7 X-HE-Tag: 1725955253-739266 X-HE-Meta: U2FsdGVkX19+U4MtcZPoNsPSQwEJEAFGVjuRZslpQ5xk42sM6J6tDC8NFZ8IaZc6EBOgx5S9tOZvsnVDGGzoQKuCH4Ir838bQaktoOKlLeoozSARi7kHhW17iG20y8381yGzUtXBz3MTMTCSYxGZOiAh0dniJN6x96xFuCgqwOd/pZsXDrgxWueA44YZWw2LuJw7VbI/XPhVCrQWD1qx5vaUa5BGlyq76k1FRSy5yO5MJGc1CUYPYjPV7kil2hMOFFZB3YW/9FEUCbauvzlfnrArewH5/o3Sj3DBiAAb199kWcIuP44y7o6C0F0lLYSWWD0aTYZBhz7dVsssawDej62GH6Ntp5uK1Thmh7gV7yZz+tBf6O/Jeh8kOFbeWBA3BGtpEZAYC170pztTcLDICJtp0tBgedAoXCHiVAud09/UEx7elUnfMJdB/aX8Qb96RhoVcjgTrvTwSisf0w8NABkNFTCo6rz7XHDlFp4GbWdOgoDhTqBN4oXPnGv1q8KPF2zXGdjB7JdBEQMPfw1DEowxn7pXhJTR3z5IXbK/20bRsavebx8cgx35/vG5DLcdRhyyPMtSzmHYvAJkxhzB2uWG6NdHe5sw8AnCmav32AuA2GUalMA0rRFVDRR9yEltD4K8DDjocmR7aZY61YrQNhHA3VE5fWQa/948/8VDeYXhVy/LscRhmF0QQ/62dDDjLcCshi/1Y8bsP982PxfL+Prf3tUVXXS759BBldViPU8W6wZUMA9jqOtMUbv809H/p3tLSG+K86GiRy7GCJj7nzuUVwj46Hrtg28/t6f0q5W/Dpkyu9Tvl+juwdjssXC8raEzXnIcjdRudC8ffFWtWOh2UAnaqU2gKtyCC4eXRsiUlDIC7BBylQlKoMaoiql0MKp4gOK8tTAqfV5mW5ke9dUcJJGV+5Jvzg5wlNhLSrfMWsLUCdxLTA9RlQeg7aXBDXfkvDhgsnT/xk+1zOx oBUgb3oz w1CME+3E0RympmJLHev7080bSzJBWCyVyDpasrzVFB15gc7EdGaxubybDUy4Zl9XFDT8F4DgqGsNGvvaZobbBN5nMRVzBUyTD6zHcEt5XCYkAUgAqm4q2eJfouLJ/uNTSbYKM9WNfbT6wFaevmGzj8zAK5hVt6GQIxaSa42Q2H5Y6DrFaJ2eby8ykc7uGsxw7ULVEbIEoK7gAogQbaO6JCUOl3LALY2kL+POYH7y1KoxdJGUwRkDR06PawJQbvVb0rQLj5ul1Lu9yOVS0KWlN40S5m8mtBSbtC5jH X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area{_topdown} to handle those. sparc specific hugetlb function does not set info.align_offset, and does not care about adjusting the align_mask for MAP_SHARED cases, so the same here for compatibility. Signed-off-by: Oscar Salvador --- arch/sparc/kernel/sys_sparc_32.c | 17 +++++++++++---- arch/sparc/kernel/sys_sparc_64.c | 37 +++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c index 80822f922e76..959f3c2ca201 100644 --- a/arch/sparc/kernel/sys_sparc_32.c +++ b/arch/sparc/kernel/sys_sparc_32.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -42,12 +43,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, vm_flags_t vm_flags) { struct vm_unmapped_area_info info = {}; + bool file_hugepage = false; + + if (filp && is_file_hugepages(filp)) + file_hugepage = true; if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_huge_pages && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -62,9 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi info.length = len; info.low_limit = addr; info.high_limit = TASK_SIZE; - info.align_mask = (flags & MAP_SHARED) ? - (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset = pgoff << PAGE_SHIFT; + if (!file_hugepage) { + info.align_mask = (flags & MAP_SHARED) ? + (PAGE_MASK & (SHMLBA - 1)) : 0; + info.align_offset = pgoff << PAGE_SHIFT; + } else { + info.align_mask = huge_page_mask_align(filp); + } return vm_unmapped_area(&info); } diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c index acade309dc2f..c5a284df7b41 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -87,6 +88,16 @@ static inline unsigned long COLOR_ALIGN(unsigned long addr, return base + off; } +static unsigned long get_align_mask(struct file *filp, unsigned long flags) +{ + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); + if (filp || (flags & MAP_SHARED)) + return PAGE_MASK & (SHMLBA - 1); + + return 0; +} + unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags, vm_flags_t vm_flags) { struct mm_struct *mm = current->mm; @@ -94,12 +105,16 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi unsigned long task_size = TASK_SIZE; int do_color_align; struct vm_unmapped_area_info info = {}; + bool file_hugepage = false; + + if (filp && is_file_hugepages(filp)) + file_hugepage = true; if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -111,7 +126,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi return -ENOMEM; do_color_align = 0; - if (filp || (flags & MAP_SHARED)) + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align = 1; if (addr) { @@ -129,8 +144,9 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi info.length = len; info.low_limit = TASK_UNMAPPED_BASE; info.high_limit = min(task_size, VA_EXCLUDE_START); - info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset = pgoff << PAGE_SHIFT; + info.align_mask = get_align_mask(filp, flags); + if (!file_hugepage) + info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) { @@ -154,15 +170,19 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, unsigned long addr = addr0; int do_color_align; struct vm_unmapped_area_info info = {}; + bool file_hugepage = false; /* This should only ever run for 32-bit processes. */ BUG_ON(!test_thread_flag(TIF_32BIT)); + if (filp && is_file_hugepages(filp)) + file_hugepage = true; + if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -172,7 +192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, return -ENOMEM; do_color_align = 0; - if (filp || (flags & MAP_SHARED)) + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align = 1; /* requesting a specific address */ @@ -192,8 +212,9 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.length = len; info.low_limit = PAGE_SIZE; info.high_limit = mm->mmap_base; - info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset = pgoff << PAGE_SHIFT; + info.align_mask = get_align_mask(filp, flags); + if (!file_hugepage) + info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); /* From patchwork Tue Sep 10 08:00:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13798083 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 A2B86ECE582 for ; Tue, 10 Sep 2024 08:01:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4740F8D0029; Tue, 10 Sep 2024 04:00:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 131C08D002A; 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 C09268D000E; Tue, 10 Sep 2024 04:00:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E4D5C8D002B for ; Tue, 10 Sep 2024 04:00:56 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7F00C80EB5 for ; Tue, 10 Sep 2024 08:00:56 +0000 (UTC) X-FDA: 82548082512.15.D75C3F7 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf06.hostedemail.com (Postfix) with ESMTP id 3294B180016 for ; Tue, 10 Sep 2024 08:00:53 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ItqeHbI+; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=lIO2uYXK; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ItqeHbI+; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=lIO2uYXK; spf=pass (imf06.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725955227; 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=lPjsfCQSviNFBHuUqkfk5P5tQyuHiB7xifQvmojeMuQ=; b=hee5Be2KNMIfVEYNXVwEhaQ+sBoli1sKattTThpmFCkyI86aUdg93p+uXPTP0+LA4hnv0g VlCfHpywQG3nLn3bVZxeJbZmXMqJaCs/iiyPAzehuaw4TmJw/bxLani+LCxNYWnaKybwZG IKLUCH7SI4Pm+AJC1vKCy0o5K3w29c0= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ItqeHbI+; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=lIO2uYXK; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ItqeHbI+; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=lIO2uYXK; spf=pass (imf06.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725955227; a=rsa-sha256; cv=none; b=1n23ZiXQQEf3ALbgXvqRzJQSfiuQNsj38kCsG90hO5tRr2V/lewKlEBb6btWfRqrl3s69b khfRhStUWD1qT/x05DrQm3rTMlPU3NGLxrZgxEF0avHbeB+vJ8FxNyV0Q/jIu2Pz73Z/P1 azdBS5/GUYKZY8nP4JLcxoSsmmTcZlY= 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 A470F1F80B; Tue, 10 Sep 2024 08:00:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955252; 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=lPjsfCQSviNFBHuUqkfk5P5tQyuHiB7xifQvmojeMuQ=; b=ItqeHbI+GRbj3eHSk7v57wunACPQojKxsCDJTzlIKMrzNkxsdr1T62g/nz65YeakEebMDY E5Vsofuq9et42QNa/KWxgCIYEizqZZNdR7D1Do3AOoscL+tEpizKP5N+MmQyj59/UHTalg m9Q9rg1xJGZltuRNl9zju4xaQEmSC3w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955252; 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=lPjsfCQSviNFBHuUqkfk5P5tQyuHiB7xifQvmojeMuQ=; b=lIO2uYXKTWyWdv+ERVGq2fs1LKyuNHkzCTLZ5UbKiIBqlEb8Qt8jtmFNGkvBA3ujBAVCj2 r7y6P8mz5pteo9DA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955252; 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=lPjsfCQSviNFBHuUqkfk5P5tQyuHiB7xifQvmojeMuQ=; b=ItqeHbI+GRbj3eHSk7v57wunACPQojKxsCDJTzlIKMrzNkxsdr1T62g/nz65YeakEebMDY E5Vsofuq9et42QNa/KWxgCIYEizqZZNdR7D1Do3AOoscL+tEpizKP5N+MmQyj59/UHTalg m9Q9rg1xJGZltuRNl9zju4xaQEmSC3w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955252; 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=lPjsfCQSviNFBHuUqkfk5P5tQyuHiB7xifQvmojeMuQ=; b=lIO2uYXKTWyWdv+ERVGq2fs1LKyuNHkzCTLZ5UbKiIBqlEb8Qt8jtmFNGkvBA3ujBAVCj2 r7y6P8mz5pteo9DA== 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 DBB22132CB; Tue, 10 Sep 2024 08:00:51 +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 qG3GMrP832Y2MQAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 08:00:51 +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 5/9] arch/powerpc: Teach book3s64 arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Tue, 10 Sep 2024 10:00:26 +0200 Message-ID: <20240910080030.1272373-6-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: o4cubsgkykq18zpwba3rjtywd5dbqzbw X-Rspamd-Queue-Id: 3294B180016 X-Rspamd-Server: rspam11 X-HE-Tag: 1725955253-457701 X-HE-Meta: U2FsdGVkX18284vX2zDb43Ht36szhjhIzqmo/l/6ZQgcSZat9Ty/gxKojqQr1ozPe5B5j3vQit44CiGCJCdWZT+ByrmLvesqTJc3yV7inelZtwEkfvU/V261L9wIqLFuSyCHivONl54x66086Oo+Ku6qgXRZMRx4IXlJbtySeYuNkJHH5BZ8SNf0c2B196EPlDXHZl6gRKdwvqit3cXNKgR9g4hIo3ehbO5QcwWd1HSgiu/hXwxWi8qSSzBhnLuQr7atMKpG8G+l7vxLSZwOrVf45QCujYn+D2ytLJ4KE7SbZ8dCOSvQodQu6bf1lWkRYbJurLgfqwZ6eRq40+bw1FkQr+20MQJdtUj1pc3WgfBcgSJvOra6NbbBjU7Hfjnha/aMw+lqzB43LTD7X0XJ3R3e7GwP6pcd2K+xkBdCXEOMSuCyOXo3eem7HHVnvyDuFDOeaemJikKuEkeBz9Rvf6I3Ry9vbKfacbRTX05MZgXKZzWMB35ud58ncvVyqlHTK7CBgrllKewSWRBOoQyBTiCDJ/Ezng5AIJm4osxc3a9NtrrW+8b9AKzuqVBN4DKVIE+0SuB2PvkQI3iGH8lkUGQMNP09ALLK2ekI1gfeVMSVbsmbzChhUJDbxC0Fl1U+3UxYXg05cuxsSjcpcIHSXDrJx4/Hamqcq2kJo0Tl57JUFxIuEoZTIo6TlbPiXlZJi8gxbOzyv7fah5yw6MyPi6yy2NEC31jgbgTh0Jl6123Btk5GmqSGNy9H4v9XH/OIdsmTV5wvH2WnYcsY3V+hko0/8/AT7qTH7aj44Z4B4zByQbFIM1Z1iXzZMkB6Q5dVkdMHi/iqhbn1q9a6MyiRbQI8EzVQ8pGRVeqY9XF37bMxphH0ilzEP8A8Mk/f5o+YFjB6Go50+LYbCO4sJvY3x8deRXeS/8+D/9VZhxEPhIJoV9AFVviXpq4fvc8Z8DhT26YeQjoi1U0gRl23W8Z eFSHD0Ms YdPM8sO5Me0NTKYeQBWb163Dt7AiD5/72wSJGHelfn8b0SeUDHpBV+XZ6XHYrKu5ctSd7PtUJzQjTO2Z8O3VkArOVud1c+EYpU9VQjpfWzE3uTA4dqhn4pGZfOv4mDpeeedB+B+NFIUvZ9Ya0AiBbbCA6oYl/jL7FLpCIDi+ItvNoXXr4jTSOyJMX64Bh3ffjwOnT8IHER1jR2n9GDHDqnoyWV87SpzklIqpGgpEEMN1LXr6eM1nBvnIFOkIBporWjHRKp+TAgkCGNH+Ck4EpRNZp04ra9KpdstsawRMm/N9CP4s1dgsuq0u+zw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area{_topdown} to handle those. Reshuffle file_to_psize() definition so arch_get_unmapped_area{_topdown} can make use of it. Signed-off-by: Oscar Salvador --- arch/powerpc/mm/book3s64/slice.c | 40 ++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c index 87307d0fc3b8..3a858f6b7270 100644 --- a/arch/powerpc/mm/book3s64/slice.c +++ b/arch/powerpc/mm/book3s64/slice.c @@ -633,6 +633,20 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len, } EXPORT_SYMBOL_GPL(slice_get_unmapped_area); +#ifdef CONFIG_HUGETLB_PAGE +static int file_to_psize(struct file *file) +{ + struct hstate *hstate = hstate_file(file); + + return shift_to_mmu_psize(huge_page_shift(hstate)); +} +#else +static int file_to_psize(struct file *file) +{ + return 0; +} +#endif + unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, @@ -640,11 +654,17 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long flags, vm_flags_t vm_flags) { + unsigned int psize; + if (radix_enabled()) return generic_get_unmapped_area(filp, addr, len, pgoff, flags, vm_flags); - return slice_get_unmapped_area(addr, len, flags, - mm_ctx_user_psize(¤t->mm->context), 0); + if (filp && is_file_hugepages(filp)) + psize = file_to_psize(filp); + else + psize = mm_ctx_user_psize(¤t->mm->context); + + return slice_get_unmapped_area(addr, len, flags, psize, 0); } unsigned long arch_get_unmapped_area_topdown(struct file *filp, @@ -654,11 +674,17 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, const unsigned long flags, vm_flags_t vm_flags) { + unsigned int psize; + if (radix_enabled()) return generic_get_unmapped_area_topdown(filp, addr0, len, pgoff, flags, vm_flags); - return slice_get_unmapped_area(addr0, len, flags, - mm_ctx_user_psize(¤t->mm->context), 1); + if (filp && is_file_hugepages(filp)) + psize = file_to_psize(filp); + else + psize = mm_ctx_user_psize(¤t->mm->context); + + return slice_get_unmapped_area(addr0, len, flags, psize, 1); } unsigned int notrace get_slice_psize(struct mm_struct *mm, unsigned long addr) @@ -789,12 +815,6 @@ unsigned long vma_mmu_pagesize(struct vm_area_struct *vma) return 1UL << mmu_psize_to_shift(get_slice_psize(vma->vm_mm, vma->vm_start)); } -static int file_to_psize(struct file *file) -{ - struct hstate *hstate = hstate_file(file); - return shift_to_mmu_psize(huge_page_shift(hstate)); -} - unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) From patchwork 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-Queue-Id: DEFF4100011 X-Rspamd-Server: rspam02 X-HE-Tag: 1725955254-901912 X-HE-Meta: U2FsdGVkX199r5lFtDeo3aS6QhocSKnhXJiKRK1jMeRxMzvGKxcekWxh5HjjKnLhI7jvFQ5VzOOzAiS2IoupTju1CuiUHlOheNFhzeyT7wC6maPU2/Oaon3BfUQFj+tKmWr2BJyJod1+XnH7coDWNMo2HV1DWISl3neC6iSmKr3uT0zGVYtUMkt4ok5frcRI95vIVOQd0sVW/VFoj85D624gl5n8nenOQP3+WwELmTEmhDBf8vzaBGPZGPbKtIamJod80BAuQMMkuoflKAcdn+S6W80CpPHNb+o33Vr5Ru6Zvb5QbNSz9qW3sbAVr3Q09h1D4ho3d1hjFuSfei9CwibHAET91EVAqFZRcCg1VwHdS4fSP8RK9zvMXbrsgYPYKlQew7zLZRcU0+JzlJNqBFYKkIqUyPdxLGwlGcxULArTcKdztp9r4K6qJt9jjKSAsCe4fL/OY9jc9WRUXGsoK1EMB/QONutR+uJs79hEmIqmYHfXs96OUWyKj/lcO8s55ycQoGt09wMWY/wYqurPvhzzDz7+zJaLdpZOGpm22p6Zzh+Lvj7wd2DQMme4eyC60TQNQ4YEN43vXFNu3ZXxIBbi/wnqzp28xG2QtqNO62Q1cC+SXKzFDGh7cM8eBpFE+e0vxyr6btU/AcKpRACS0gmaosLujoRo5TJGs65KZWG5TH540x5ifSRP6U7tr4kW2beo4drb1V1SygvfE5tdzWteufQolo/Tjb0dJpo9RV8Qx544q01h9rbnBhPBOTtg11859fKVtdBeb0/heQj929WSve5p4ZyXwjeHKZU2TN2/pUiXEkrrqe5YuzBsFWZtyozMzo40CDvdhR8sRURMQLYifMUYEPN1UaRA1OCSmey/luoX4nz/wz4O2Y0pmxbxM7JaCefIIGrqqO6TdiEVErWknKK/RAuUjNJNa2zaBo4OxjC+wd4OHwMta2XdFku1iwvqQkE0yxWkDiEArsd jkqNuZBc kC1PeVXgiJDdCtIOWtMRixza5weG+hLcq0DG2+wH/hxPfL8YkgvZHz5blVsm3xHT/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, From patchwork Tue Sep 10 08:00:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13798086 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 0B0A4ECE564 for ; Tue, 10 Sep 2024 08:01:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEF698D002A; Tue, 10 Sep 2024 04:00:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF3FE8D002D; 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 974FE8D002A; Tue, 10 Sep 2024 04:00:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3BA8C8D002D for ; Tue, 10 Sep 2024 04:00:58 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F11AF140FA9 for ; Tue, 10 Sep 2024 08:00:57 +0000 (UTC) X-FDA: 82548082554.19.16BF7EF Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf27.hostedemail.com (Postfix) with ESMTP id B7C6D40020 for ; Tue, 10 Sep 2024 08:00:55 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1wH5bCcn; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="uYXsA/Cg"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1wH5bCcn; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="uYXsA/Cg"; spf=pass (imf27.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725955119; 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=F6pmHCjZz9XiyMR/0O/Qvzo1EPb+yKKEdFiJlEBHrks=; b=LatHg1CE6syFopLI451bUkg38GKEUEsIk7OFCTpEaO+ejK6L06yGFToufdHttkui03pkJt WA3I8S/CSIiaLDgCv+RLMp4fJp/kyLAt/LmyOcxDZXhyFMmNIgA8EletrPbeZBXcqbjJEH rJgTeawqitl7dTcq3oiH7Q3pTBDKuzc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1wH5bCcn; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="uYXsA/Cg"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1wH5bCcn; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="uYXsA/Cg"; spf=pass (imf27.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725955119; a=rsa-sha256; cv=none; b=4VKAEM/1MOyn8+UiJt9q4AaJVWZsB8a1JtzQbG062vo8/xYF4uIYvDmUh7QMy9zZKtbVsS P+H08n3DB6xudpzBxxc/nu45G+XlABIvrn+DPem4NhIE4Wu3XaRqKYJUfJOuhHA96TMxBn Sw/9tufKSGkTTw0RQO6mb2vK63s6E2Q= 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 43D2021A39; Tue, 10 Sep 2024 08:00:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955254; 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=F6pmHCjZz9XiyMR/0O/Qvzo1EPb+yKKEdFiJlEBHrks=; b=1wH5bCcnUIEbt8WMgMcetnvs0YU3g+QGV5lB4RVcNT++FFhMgQO9MQkTuZ+PuaZQcdaKGx +uXp6gArzp6dusgLSjblq7TzWe9fy1QQxg7fPgIgHe9rNMYrltBmtSOP5zkrx4jIJjqB1X Ca+kLDKXQqHYxVi3JyNiyzAGDB6Fovg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955254; 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=F6pmHCjZz9XiyMR/0O/Qvzo1EPb+yKKEdFiJlEBHrks=; b=uYXsA/Cg/4K9aFOZws9/C6LriNbC9e0Hryi0N6L9fyW2gApw10MmfBAFrIxqD8bjnEPUXC H13Z/dNveq/LRNCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955254; 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=F6pmHCjZz9XiyMR/0O/Qvzo1EPb+yKKEdFiJlEBHrks=; b=1wH5bCcnUIEbt8WMgMcetnvs0YU3g+QGV5lB4RVcNT++FFhMgQO9MQkTuZ+PuaZQcdaKGx +uXp6gArzp6dusgLSjblq7TzWe9fy1QQxg7fPgIgHe9rNMYrltBmtSOP5zkrx4jIJjqB1X Ca+kLDKXQqHYxVi3JyNiyzAGDB6Fovg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955254; 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=F6pmHCjZz9XiyMR/0O/Qvzo1EPb+yKKEdFiJlEBHrks=; b=uYXsA/Cg/4K9aFOZws9/C6LriNbC9e0Hryi0N6L9fyW2gApw10MmfBAFrIxqD8bjnEPUXC H13Z/dNveq/LRNCA== 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 8849A132CB; Tue, 10 Sep 2024 08:00:53 +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 OGhBHrX832Y2MQAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 08:00:53 +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 7/9] mm: Drop hugetlb_get_unmapped_area{_*} functions Date: Tue, 10 Sep 2024 10:00:28 +0200 Message-ID: <20240910080030.1272373-8-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-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B7C6D40020 X-Stat-Signature: a6bz7d7yx5xyrn4otqexouidt88645ir X-Rspam-User: X-HE-Tag: 1725955255-542324 X-HE-Meta: U2FsdGVkX1+eRGCjOLwDJJFRv4zWeB0hsuxUoLrQ5JNrx8d55XC3ug3yWN9Acww85n4J2PsGeadPKVxR39yeFb3yCwl0LPrWj8ObgMs947rNry00AbjFhlxEsnxtqmFuaSSl0sfYFMaqfBtS6E6G35e6mG7scSUTdXCzAc4p/T2/XOQnokHmssZGeyX4S647HkDjs9ptVQqxXqt10Ij9cUqLG4sNQ1pYe0BTXdT4yBkKi3IOYt/INx63SeOrV9qMe5oUkaPf9fWeGAxg0uDxfldGVrgXd63yRNN0rTheB844UKJZJFpKBSb32riPbJAChBuklnNugI/C23yKSgnn8I5D84A82qOqzPryT4BtMv5mnZ1KCnWCOBJ+5J7kyZzByIzQN9ZMHClIzASgB7CG0OykZW690h1y2m9mLlpwEhJvJrEAAU8ikgn9uiQG2aBcDWslPN4j/pt+iBCGaIKBjogM+XqHitx+8wxErzEVF2fShoiaK+BYsEEBgE/hJZpi0t1fI0pii2Y+QGNHV0BbVEDEK9K4NEmkh0g6QRHZy5RNvuT8W0QWvmJV3Hxj8D6xuw787ShSPZBoQmG6aKYGcWc6ciGQVK/yMVuEEu+gv/DtcRZgTrMeBpdG8MF1C2ow+h4ZIm33rfVfnZAuHByg1TrELtYWljg/zKa+UVW8YeRLNvqY1y6qkYkh03uJSxPDqoIPUEKk1hE98/2sWHrnl52/Avtsy4HVhmyTrpH8JOjDmtcx04vScGurAZjUuUuCQKWu5+SSivjk/c+nGZr+P/4auWktCgrmv8sMWN7ShtDY6lnwgEXr6TZ4DsgJJTAGi9KfH9PDsFLjpAN0N+T8afVjjzL9WUBe7Vt7yc/ptp2h58ZByegJ+DxMs4cwVs5kE1hTBnN0XQYPhUgcAHozxxa+3tz0dTHd6o8qo0ft+6B0P3p8OTsQFuv6Ss9hxYm3iuQjvoqiCv8tAO6gaKa hxgd4Sl5 WSS/J9pSJlUsyhx++LsUfsoEpEOIe0C7qhaOgB41gQ08PPzJgJBUUIxcpxQDWUTyw4/4Bbfx7+EHpplmAWFj3UhkyIQvdZuxUfjEVumr3KvC/U4VroHY8Y40XcG4EnczgqD4OwL4lFPMeLjRE81pZJDaJlS75FL3EwLb81bpYXM0RKvtM9xPfsR+mI7J+2Ew+kjnT1aipvleUDZo4Yo1JHMy5dtMMmy+CLU6b1N+sjUyzQupVZoym7NuRvL3RsfqqLoQLc2ZIwenSWIUdm9dIDFq6+4oBzXTpqUlo X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hugetlb mappings are now handled through normal channels just like any other mapping, so we no longer need hugetlb_get_unmapped_area* specific functions. Signed-off-by: Oscar Salvador --- arch/parisc/mm/hugetlbpage.c | 21 ------ arch/powerpc/mm/book3s64/slice.c | 10 --- arch/s390/mm/hugetlbpage.c | 85 ------------------------ arch/sparc/mm/hugetlbpage.c | 108 ------------------------------- arch/x86/mm/hugetlbpage.c | 101 ----------------------------- fs/hugetlbfs/inode.c | 96 ++------------------------- include/linux/hugetlb.h | 7 +- 7 files changed, 6 insertions(+), 422 deletions(-) diff --git a/arch/parisc/mm/hugetlbpage.c b/arch/parisc/mm/hugetlbpage.c index aa664f7ddb63..e9d18cf25b79 100644 --- a/arch/parisc/mm/hugetlbpage.c +++ b/arch/parisc/mm/hugetlbpage.c @@ -21,27 +21,6 @@ #include -unsigned long -hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (len > TASK_SIZE) - return -ENOMEM; - - if (flags & MAP_FIXED) - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - - if (addr) - addr = ALIGN(addr, huge_page_size(h)); - - /* we need to make sure the colouring is OK */ - return arch_get_unmapped_area(file, addr, len, pgoff, flags, 0); -} pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c index 3a858f6b7270..bc9a39821d1c 100644 --- a/arch/powerpc/mm/book3s64/slice.c +++ b/arch/powerpc/mm/book3s64/slice.c @@ -814,14 +814,4 @@ unsigned long vma_mmu_pagesize(struct vm_area_struct *vma) return 1UL << mmu_psize_to_shift(get_slice_psize(vma->vm_mm, vma->vm_start)); } - -unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, - unsigned long flags) -{ - if (radix_enabled()) - return generic_hugetlb_get_unmapped_area(file, addr, len, pgoff, flags); - - return slice_get_unmapped_area(addr, len, flags, file_to_psize(file), 1); -} #endif diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c index ded0eff58a19..7c79cf1bc7d7 100644 --- a/arch/s390/mm/hugetlbpage.c +++ b/arch/s390/mm/hugetlbpage.c @@ -242,88 +242,3 @@ bool __init arch_hugetlb_valid_size(unsigned long size) else return false; } - -static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file, - unsigned long addr, unsigned long len, - unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info = {}; - - info.length = len; - info.low_limit = current->mm->mmap_base; - info.high_limit = TASK_SIZE; - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - return vm_unmapped_area(&info); -} - -static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file, - unsigned long addr0, unsigned long len, - unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info = {}; - unsigned long addr; - - info.flags = VM_UNMAPPED_AREA_TOPDOWN; - info.length = len; - info.low_limit = PAGE_SIZE; - info.high_limit = current->mm->mmap_base; - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - addr = vm_unmapped_area(&info); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - if (addr & ~PAGE_MASK) { - VM_BUG_ON(addr != -ENOMEM); - info.flags = 0; - info.low_limit = TASK_UNMAPPED_BASE; - info.high_limit = TASK_SIZE; - addr = vm_unmapped_area(&info); - } - - return addr; -} - -unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (len > TASK_SIZE - mmap_min_addr) - return -ENOMEM; - - if (flags & MAP_FIXED) { - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - goto check_asce_limit; - } - - if (addr) { - addr = ALIGN(addr, huge_page_size(h)); - vma = find_vma(mm, addr); - if (TASK_SIZE - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma))) - goto check_asce_limit; - } - - if (!test_bit(MMF_TOPDOWN, &mm->flags)) - addr = hugetlb_get_unmapped_area_bottomup(file, addr, len, - pgoff, flags); - else - addr = hugetlb_get_unmapped_area_topdown(file, addr, len, - pgoff, flags); - if (offset_in_page(addr)) - return addr; - -check_asce_limit: - return check_asce_limit(mm, addr, len); -} diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c index cc91ca7a1e18..eee601a0d2cf 100644 --- a/arch/sparc/mm/hugetlbpage.c +++ b/arch/sparc/mm/hugetlbpage.c @@ -19,114 +19,6 @@ #include #include -/* Slightly simplified from the non-hugepage variant because by - * definition we don't have to worry about any page coloring stuff - */ - -static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp, - unsigned long addr, - unsigned long len, - unsigned long pgoff, - unsigned long flags) -{ - struct hstate *h = hstate_file(filp); - unsigned long task_size = TASK_SIZE; - struct vm_unmapped_area_info info = {}; - - if (test_thread_flag(TIF_32BIT)) - task_size = STACK_TOP32; - - info.length = len; - info.low_limit = TASK_UNMAPPED_BASE; - info.high_limit = min(task_size, VA_EXCLUDE_START); - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - addr = vm_unmapped_area(&info); - - if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) { - VM_BUG_ON(addr != -ENOMEM); - info.low_limit = VA_EXCLUDE_END; - info.high_limit = task_size; - addr = vm_unmapped_area(&info); - } - - return addr; -} - -static unsigned long -hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, - const unsigned long len, - const unsigned long pgoff, - const unsigned long flags) -{ - struct hstate *h = hstate_file(filp); - struct mm_struct *mm = current->mm; - unsigned long addr = addr0; - struct vm_unmapped_area_info info = {}; - - /* This should only ever run for 32-bit processes. */ - BUG_ON(!test_thread_flag(TIF_32BIT)); - - info.flags = VM_UNMAPPED_AREA_TOPDOWN; - info.length = len; - info.low_limit = PAGE_SIZE; - info.high_limit = mm->mmap_base; - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - addr = vm_unmapped_area(&info); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - if (addr & ~PAGE_MASK) { - VM_BUG_ON(addr != -ENOMEM); - info.flags = 0; - info.low_limit = TASK_UNMAPPED_BASE; - info.high_limit = STACK_TOP32; - addr = vm_unmapped_area(&info); - } - - return addr; -} - -unsigned long -hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - unsigned long task_size = TASK_SIZE; - - if (test_thread_flag(TIF_32BIT)) - task_size = STACK_TOP32; - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (len > task_size) - return -ENOMEM; - - if (flags & MAP_FIXED) { - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - return addr; - } - - if (addr) { - addr = ALIGN(addr, huge_page_size(h)); - vma = find_vma(mm, addr); - if (task_size - len >= addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } - if (!test_bit(MMF_TOPDOWN, &mm->flags)) - return hugetlb_get_unmapped_area_bottomup(file, addr, len, - pgoff, flags); - else - return hugetlb_get_unmapped_area_topdown(file, addr, len, - pgoff, flags); -} static pte_t sun4u_hugepage_shift_to_tte(pte_t entry, unsigned int shift) { diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c index 807a5859a3c4..58f7f2bd535d 100644 --- a/arch/x86/mm/hugetlbpage.c +++ b/arch/x86/mm/hugetlbpage.c @@ -19,107 +19,6 @@ #include #include -#ifdef CONFIG_HUGETLB_PAGE -static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file, - unsigned long addr, unsigned long len, - unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info = {}; - - info.length = len; - info.low_limit = get_mmap_base(1); - - /* - * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area - * in the full address space. - */ - info.high_limit = in_32bit_syscall() ? - task_size_32bit() : task_size_64bit(addr > DEFAULT_MAP_WINDOW); - - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - return vm_unmapped_area(&info); -} - -static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file, - unsigned long addr, unsigned long len, - unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info = {}; - - info.flags = VM_UNMAPPED_AREA_TOPDOWN; - info.length = len; - info.low_limit = PAGE_SIZE; - info.high_limit = get_mmap_base(0); - - /* - * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area - * in the full address space. - */ - if (addr > DEFAULT_MAP_WINDOW && !in_32bit_syscall()) - info.high_limit += TASK_SIZE_MAX - DEFAULT_MAP_WINDOW; - - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - addr = vm_unmapped_area(&info); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - if (addr & ~PAGE_MASK) { - VM_BUG_ON(addr != -ENOMEM); - info.flags = 0; - info.low_limit = TASK_UNMAPPED_BASE; - info.high_limit = TASK_SIZE_LOW; - addr = vm_unmapped_area(&info); - } - - return addr; -} - -unsigned long -hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - - if (len & ~huge_page_mask(h)) - return -EINVAL; - - if (len > TASK_SIZE) - return -ENOMEM; - - /* No address checking. See comment at mmap_address_hint_valid() */ - if (flags & MAP_FIXED) { - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - return addr; - } - - if (addr) { - addr &= huge_page_mask(h); - if (!mmap_address_hint_valid(addr, len)) - goto get_unmapped_area; - - vma = find_vma(mm, addr); - if (!vma || addr + len <= vm_start_gap(vma)) - return addr; - } - -get_unmapped_area: - if (!test_bit(MMF_TOPDOWN, &mm->flags)) - return hugetlb_get_unmapped_area_bottomup(file, addr, len, - pgoff, flags); - else - return hugetlb_get_unmapped_area_topdown(file, addr, len, - pgoff, flags); -} -#endif /* CONFIG_HUGETLB_PAGE */ #ifdef CONFIG_X86_64 bool __init arch_hugetlb_valid_size(unsigned long size) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 978f5d62c5cf..b6a619f5a85a 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -171,96 +171,10 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) * Called under mmap_write_lock(mm). */ -static unsigned long -hugetlb_get_unmapped_area_bottomup(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info = {}; - - info.length = len; - info.low_limit = current->mm->mmap_base; - info.high_limit = arch_get_mmap_end(addr, len, flags); - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - return vm_unmapped_area(&info); -} - -static unsigned long -hugetlb_get_unmapped_area_topdown(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info = {}; - - info.flags = VM_UNMAPPED_AREA_TOPDOWN; - info.length = len; - info.low_limit = PAGE_SIZE; - info.high_limit = arch_get_mmap_base(addr, current->mm->mmap_base); - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - addr = vm_unmapped_area(&info); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - if (unlikely(offset_in_page(addr))) { - VM_BUG_ON(addr != -ENOMEM); - info.flags = 0; - info.low_limit = current->mm->mmap_base; - info.high_limit = arch_get_mmap_end(addr, len, flags); - addr = vm_unmapped_area(&info); - } - - return addr; -} - -unsigned long -generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, - unsigned long flags) -{ - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma, *prev; - struct hstate *h = hstate_file(file); - const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (len > mmap_end - mmap_min_addr) - return -ENOMEM; - - if (flags & MAP_FIXED) { - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - return addr; - } - - if (addr) { - addr = ALIGN(addr, huge_page_size(h)); - vma = find_vma_prev(mm, addr, &prev); - if (mmap_end - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma)) && - (!prev || addr >= vm_end_gap(prev))) - 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_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long flags) +hugetlb_get_unmapped_area(struct file *file, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) { unsigned long addr0 = 0; struct hstate *h = hstate_file(file); @@ -272,7 +186,7 @@ __hugetlb_get_unmapped_area(struct file *file, unsigned long addr, if (addr) addr0 = ALIGN(addr, huge_page_size(h)); - return mm_get_unmapped_area_vmflags(current->mm, file, addr, len, pgoff, + return mm_get_unmapped_area_vmflags(current->mm, file, addr0, len, pgoff, flags, 0); } @@ -1308,7 +1222,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 3a81b6126f62..ae4fe8615bb6 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -547,15 +547,10 @@ static inline struct hstate *hstate_inode(struct inode *i) #endif /* !CONFIG_HUGETLBFS */ unsigned long -__generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, +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, - unsigned long len, unsigned long pgoff, - unsigned long flags); - /* * huegtlb page specific state flags. These flags are located in page.private * of the hugetlb head page. Functions created via the below macros should be From patchwork Tue Sep 10 08:00:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13798087 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 03581ECE564 for ; Tue, 10 Sep 2024 08:01:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 575388D002D; Tue, 10 Sep 2024 04:00:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 526838D002B; Tue, 10 Sep 2024 04:00:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 350628D002D; Tue, 10 Sep 2024 04:00:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 13B3D8D002B for ; Tue, 10 Sep 2024 04:00:59 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C35FEA0591 for ; Tue, 10 Sep 2024 08:00:58 +0000 (UTC) X-FDA: 82548082596.14.FA443FC Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf01.hostedemail.com (Postfix) with ESMTP id 953474000F for ; Tue, 10 Sep 2024 08:00:56 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=2GspKjyB; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=46XjDi1L; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=2GspKjyB; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=46XjDi1L; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf01.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725955142; 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=cZehZ4EsXNdPsp2SmJYWqrY7IQ/nAPk4m8G2oQEC7r0=; b=6Zt2cSf2AHT7rGFoNfCF1Z+mlfiigUBXRdVEdNfhdUkOFGwDqo4ZWuIiHP6MduWI4qbilR vZXPTVZHro102TJe+UJmIC29++4jHutH1d8aFMz5Kd/bmr3CGBDsN2esFuhtjmtV8szcTG k6einvE6sPu9JgMlW00hSWiGwNBr2OA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725955142; a=rsa-sha256; cv=none; b=V5Dgsg1bwjem6mYTb6U6/OHihXM7zQghSuRc5ktrRZpjyYPvVgfF3VUmLkhaNfVKjOuGFG ZxDhm3gX0vD2tXuMJLQ/sxvYIf78TELSmMZT/2XYQPa5lA3QNn8/pcnFnhFLeztlnLO448 c58hl3j72cNKySRkUCjtjsIqjUMf1og= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=2GspKjyB; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=46XjDi1L; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=2GspKjyB; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=46XjDi1L; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf01.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from imap1.dmz-prg2.suse.org (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 105471FCA1; Tue, 10 Sep 2024 08:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955255; 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=cZehZ4EsXNdPsp2SmJYWqrY7IQ/nAPk4m8G2oQEC7r0=; b=2GspKjyBKqqFxe6J1DYZgUt7DvA7nltJMalzuIJ7xo3JXKZ39gNXv7eWrs/2QvTNiNZY49 5eRX9WUghLbidkUb3XHIm1D3OMiXLlAzSjMSb4Z49ix/nZDyce7k/kQH2nU3scgZpt0IIa /0cQ/1e2GBzgHJJIXhBx+3Oe/gPJKJ0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955255; 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=cZehZ4EsXNdPsp2SmJYWqrY7IQ/nAPk4m8G2oQEC7r0=; b=46XjDi1Lyre8kIN5sYwUhsQrOs7xzmFJ2yXJZJdy64AF0WAM/YchqBkCReDZkjmbc5zsSe Tzh/ayIQQ2G32kBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955255; 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=cZehZ4EsXNdPsp2SmJYWqrY7IQ/nAPk4m8G2oQEC7r0=; b=2GspKjyBKqqFxe6J1DYZgUt7DvA7nltJMalzuIJ7xo3JXKZ39gNXv7eWrs/2QvTNiNZY49 5eRX9WUghLbidkUb3XHIm1D3OMiXLlAzSjMSb4Z49ix/nZDyce7k/kQH2nU3scgZpt0IIa /0cQ/1e2GBzgHJJIXhBx+3Oe/gPJKJ0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955255; 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=cZehZ4EsXNdPsp2SmJYWqrY7IQ/nAPk4m8G2oQEC7r0=; b=46XjDi1Lyre8kIN5sYwUhsQrOs7xzmFJ2yXJZJdy64AF0WAM/YchqBkCReDZkjmbc5zsSe Tzh/ayIQQ2G32kBQ== 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 5736713A8F; Tue, 10 Sep 2024 08:00:54 +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 0IV5Erb832Y2MQAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 08:00:54 +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 8/9] arch/s390: Clean up hugetlb definitions Date: Tue, 10 Sep 2024 10:00:29 +0200 Message-ID: <20240910080030.1272373-9-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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 953474000F X-Stat-Signature: n35xqau7fpxafakdijkqtawbh7maxa4i X-Rspam-User: X-HE-Tag: 1725955256-503067 X-HE-Meta: U2FsdGVkX1/d3wWQD7FpyCqkA94uwVj+jg6GXdtoCksFDRIwlCsU/BPagfUa/JNVBQ32Up81bYy1nuGo6z0K+kgxtKB8SBr+ieisAZmRUJnGfPxHchXv120ccVzokg6J2HZhq68T3o3hDhNkI1qT14teInlpYEyM0Lq/d5HF1M5UuAliCcS2U1ZZgaNlMoCWs6xSadzOoRJyHNH9i8knlKH31zSdk3g0369bWebLfXL8UfKOe/hw5hvbQ7Kyln3XOfc8WfAdxzQ9cXJQvF1WjPNTzUK/hSzrzJ9RNnKjA6N+V/OYLQHNOBmbkVv288M+qHebpCBp+bZlS0mbzLVpMgSOpPHl/CZtZtXQaotYHxjQTNGvcETocxOQps1Wc/DsE3nhiod25/w38p4la7tc8bZCt44cdyG8aKY1k3Alxs9a6c6PWnNAzAr0NshSD+9Z8xKSCS/iNsKn5hXkB+KiQiveNnA0wTkrn7YzVpOTCjxkBQalOyBXpzNKXIdii0meJO2Hd4gHxQjfqvjDHomzA2jg+Hfc1iYNJxJyUQFabt1ci7BrAzp5WpB9hM0q932usv3eSavwVAXPrDsHb3uuzM/DK20x9UAULJlZg0nHtH1KfrsXglDcOLrwoHYJvNdEe5Ab9lVlNn0XoL2Iqt4vUbuA+7qoStsI6KbFT8wN2K8uF+UTcFbGAY6TML8lSAQmq4KW88AhVtPBp7TghEA7AdZSD/Xhi0cyUGs2k2xU1BDs1hlwUN/23h39urBKWW76r58uI8mG4h07kSmYm8irLLc7Qbjz5x1XAZFYyrSKmnxkmQeRcJO0/MFH38vKOykS/OyyW7CugV6PItr0WfZIDOCM7Pbu2igJXc9CjhS5H09XunsKkQfPtST1moaOw7zcVTJxMcAc59Qn+2JuPl5LosPoHXw7Juh96cE2heZAjpTOlWE50To5HqxvPYce2BfYpp7uhhbCcK9Ufh8nWlY lIffnwfm B4eqyBBGBOoEjFmfZz7fBJBG8sqAwaFTvPk2lFVTw8Ew3ZdJpmdoRspPnPL2x7gABWu3eElRoDqCsezI1O8IuKHpQ8ry2TQMEwOGd+m6WCzHpJzeslQM9zNJ8aLUKKzfyTwWae5gM4gdenjEaCLHft03RlzIBBY+AL5JbA+fhxeUcnwB9fL5CyiXnEvvA8zTo5tFTtJpcJZl393vibHkap+ofHo9w5Dy/aBsXEeKaEm+HCS3sZQjFNTe5unnedUdVP9VK256z7spjI0g= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: s390 redefines functions that are already defined (and the same) in include/asm-generic/hugetlb.h. Do as the other architectures: 1) include include/asm-generic/hugetlb.h 2) drop the already defined functions in the generic hugetlb.h and 3) use the __HAVE_ARCH_HUGE_* macros to define our own. This gets rid of quite some code. Signed-off-by: Oscar Salvador --- arch/s390/include/asm/hugetlb.h | 58 +++++++++------------------------ include/asm-generic/hugetlb.h | 8 +++++ 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetlb.h index cf1b5d6fb1a6..37e80a32623a 100644 --- a/arch/s390/include/asm/hugetlb.h +++ b/arch/s390/include/asm/hugetlb.h @@ -12,21 +12,24 @@ #include #include -#define hugetlb_free_pgd_range free_pgd_range #define hugepages_supported() (MACHINE_HAS_EDAT1) +#define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte, unsigned long sz); void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte); -pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep); -pte_t huge_ptep_get_and_clear(struct mm_struct *mm, +#define __HAVE_ARCH_HUGE_PTEP_GET +extern pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep); +#define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR +extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep); /* * If the arch doesn't supply something else, assume that hugepage * size aligned regions are ok without further preparation. */ +#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE static inline int prepare_hugepage_range(struct file *file, unsigned long addr, unsigned long len) { @@ -45,6 +48,7 @@ static inline void arch_clear_hugetlb_flags(struct folio *folio) } #define arch_clear_hugetlb_flags arch_clear_hugetlb_flags +#define __HAVE_ARCH_HUGE_PTE_CLEAR static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep, unsigned long sz) { @@ -54,12 +58,14 @@ static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, set_pte(ptep, __pte(_SEGMENT_ENTRY_EMPTY)); } +#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) { return huge_ptep_get_and_clear(vma->vm_mm, address, ptep); } +#define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte, int dirty) @@ -72,6 +78,7 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, return changed; } +#define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { @@ -79,69 +86,36 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, __set_huge_pte_at(mm, addr, ptep, pte_wrprotect(pte)); } -static inline pte_t mk_huge_pte(struct page *page, pgprot_t pgprot) -{ - return mk_pte(page, pgprot); -} - +#define __HAVE_ARCH_HUGE_PTE_NONE static inline int huge_pte_none(pte_t pte) { return pte_none(pte); } +#define __HAVE_ARCH_HUGE_PTE_NONE_MOSTLY static inline int huge_pte_none_mostly(pte_t pte) { return huge_pte_none(pte); } -static inline int huge_pte_write(pte_t pte) -{ - return pte_write(pte); -} - -static inline int huge_pte_dirty(pte_t pte) -{ - return pte_dirty(pte); -} - -static inline pte_t huge_pte_mkwrite(pte_t pte) -{ - return pte_mkwrite_novma(pte); -} - -static inline pte_t huge_pte_mkdirty(pte_t pte) -{ - return pte_mkdirty(pte); -} - -static inline pte_t huge_pte_wrprotect(pte_t pte) -{ - return pte_wrprotect(pte); -} - -static inline pte_t huge_pte_modify(pte_t pte, pgprot_t newprot) -{ - return pte_modify(pte, newprot); -} - +#define __HAVE_ARCH_HUGE_PTE_MKUFFD_WP static inline pte_t huge_pte_mkuffd_wp(pte_t pte) { return pte; } +#define __HAVE_ARCH_HUGE_PTE_CLEAR_UFFD_WP static inline pte_t huge_pte_clear_uffd_wp(pte_t pte) { return pte; } +#define __HAVE_ARCH_HUGE_PTE_UFFD_WP static inline int huge_pte_uffd_wp(pte_t pte) { return 0; } -static inline bool gigantic_page_runtime_supported(void) -{ - return true; -} +#include #endif /* _ASM_S390_HUGETLB_H */ diff --git a/include/asm-generic/hugetlb.h b/include/asm-generic/hugetlb.h index 594d5905f615..67bbdafcfc22 100644 --- a/include/asm-generic/hugetlb.h +++ b/include/asm-generic/hugetlb.h @@ -42,20 +42,26 @@ static inline pte_t huge_pte_modify(pte_t pte, pgprot_t newprot) return pte_modify(pte, newprot); } +#ifndef __HAVE_ARCH_HUGE_PTE_MKUFFD_WP static inline pte_t huge_pte_mkuffd_wp(pte_t pte) { return huge_pte_wrprotect(pte_mkuffd_wp(pte)); } +#endif +#ifndef __HAVE_ARCH_HUGE_PTE_CLEAR_UFFD_WP static inline pte_t huge_pte_clear_uffd_wp(pte_t pte) { return pte_clear_uffd_wp(pte); } +#endif +#ifndef __HAVE_ARCH_HUGE_PTE_UFFD_WP static inline int huge_pte_uffd_wp(pte_t pte) { return pte_uffd_wp(pte); } +#endif #ifndef __HAVE_ARCH_HUGE_PTE_CLEAR static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, @@ -106,10 +112,12 @@ static inline int huge_pte_none(pte_t pte) #endif /* Please refer to comments above pte_none_mostly() for the usage */ +#ifndef __HAVE_ARCH_HUGE_PTE_NONE_MOSTLY static inline int huge_pte_none_mostly(pte_t pte) { return huge_pte_none(pte) || is_pte_marker(pte); } +#endif #ifndef __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE static inline int prepare_hugepage_range(struct file *file, From patchwork Tue Sep 10 08:00:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13798088 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 91677ECE564 for ; Tue, 10 Sep 2024 08:01:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48B568D002E; Tue, 10 Sep 2024 04:01:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EE868D002B; Tue, 10 Sep 2024 04:01:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F2958D002E; Tue, 10 Sep 2024 04:01:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F31FD8D002B for ; Tue, 10 Sep 2024 04:00:59 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B27A9A9FAD for ; Tue, 10 Sep 2024 08:00:59 +0000 (UTC) X-FDA: 82548082638.03.5B6FC3C Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf18.hostedemail.com (Postfix) with ESMTP id 641CD1C0023 for ; Tue, 10 Sep 2024 08:00:57 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=giYkk7zX; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=uCeWmHNi; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=giYkk7zX; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=uCeWmHNi; spf=pass (imf18.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725955230; 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=GLDltFrQL6gOEy4l6VLVTy9j8S44tPEMq7/+b46Xvkc=; b=HhCZlhac2rzla2+ZQ0NRsvzWQ68fObPv6jL+S/zEeoTQkddMg91W9UIICsHk5LGEmTTl3M 6bbddV6ro2KDDMO/eE490OfkyNAR3TIj2IBsTE8X36T479I7zE8WhDtIsyzXIJU15yv42c cOuIcl5b6BE6DhXcFgFgo/s3xc0XrDU= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=giYkk7zX; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=uCeWmHNi; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=giYkk7zX; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=uCeWmHNi; spf=pass (imf18.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725955230; a=rsa-sha256; cv=none; b=EXeHHR8CgZMCaYjgGeL+ET+VZam1+PsPuYtWgYOZSYzwskzKF4+kIH30UOyapNuIkLWxYd VDYpRUNOaTXLDhDH42blo7Rmg3BToJprJ4cbuUUKWrf74oOkSsjW9ckiRpzweHAP7SU52Y ghp9HcQiMK7EZNqs2EdE3BzKimC4TNI= 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 D57D421A41; Tue, 10 Sep 2024 08:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955255; 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=GLDltFrQL6gOEy4l6VLVTy9j8S44tPEMq7/+b46Xvkc=; b=giYkk7zXHO/VOT4TuhTNSNl4gT0+qh8Og4h40nMzbBJdkf0jxf2tIRrWuMdIcHLLJ3ihIQ 0GmSecGp3egdIS8gzGkUKxJco1eF08+P9TlvdVLnfhQa2MLPcUeju7n6vuCq7eV8VKGa/6 rl7Es7D5Cs8ORNk16yJgPHvjUsJyiPw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955255; 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=GLDltFrQL6gOEy4l6VLVTy9j8S44tPEMq7/+b46Xvkc=; b=uCeWmHNiOO0qicZD+hBu97YjyCz59gAOvid1pqOyFdSroieAtCXJKoYGD2jxi4WdYxl+ba 1P0uJ3A3Zi8NHpAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955255; 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=GLDltFrQL6gOEy4l6VLVTy9j8S44tPEMq7/+b46Xvkc=; b=giYkk7zXHO/VOT4TuhTNSNl4gT0+qh8Og4h40nMzbBJdkf0jxf2tIRrWuMdIcHLLJ3ihIQ 0GmSecGp3egdIS8gzGkUKxJco1eF08+P9TlvdVLnfhQa2MLPcUeju7n6vuCq7eV8VKGa/6 rl7Es7D5Cs8ORNk16yJgPHvjUsJyiPw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955255; 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=GLDltFrQL6gOEy4l6VLVTy9j8S44tPEMq7/+b46Xvkc=; b=uCeWmHNiOO0qicZD+hBu97YjyCz59gAOvid1pqOyFdSroieAtCXJKoYGD2jxi4WdYxl+ba 1P0uJ3A3Zi8NHpAA== 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 26273132CB; Tue, 10 Sep 2024 08:00:55 +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 GF00Brf832Y2MQAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 08:00:55 +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 9/9] mm: Consolidate common checks in hugetlb_get_unmapped_area Date: Tue, 10 Sep 2024 10:00:30 +0200 Message-ID: <20240910080030.1272373-10-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-Rspamd-Action: no action X-Rspam-User: X-Stat-Signature: 1n9fbw3im41jfqee7dq7zsqaoezwa9qe X-Rspamd-Queue-Id: 641CD1C0023 X-Rspamd-Server: rspam11 X-HE-Tag: 1725955257-210136 X-HE-Meta: U2FsdGVkX1+JwIZNsaX7Lstiw2XuJq8S9HpGN+jX9d4XuENfL1ygZ0SzGDHBpLjruMykmbm0l7fHlYkcA5aFTAkGwQ/Vz3XsXAZktst8EiBo3QntGLnFg6s1XkFK5aEx4Hc1QbcD2BT+RKHedcXwoYsnfGD4O7ns2KbHuMTP4/BhT3wIZQPzN/HPjNc1A95tHN4MIl4wREfxHaqoyIuysn2dZYh3bIY1ogzRXPWCtl8saWRXbGuze+ilgFK9JIVCswEhmOuronCWulX0f4HDYJ0kpMJfm27cdJNhlTCRltMzlz0upMFmyaV0L6lSiOCBSKJH5wmhHNRFsghEmhH3AY5iaDpx/d3K21h8NGAO36yX+Svlr9OxR7hgvNgDQ49oIxDj1ucH/AUrnjHViorw7eke2Bloa7cIAz1MXEIbaVId1Kj4QmWbed/P5hrg6DG1rVqyI/zoNtrXXJ4yD3mT74YwTjf1z0K0Di0wk6YrgmCioc/9RSlPV04xdgW1+VdN9ec8UBoJcjW5q6F+nznIWmXALq/8kwOgkJp+VTe11IEq8d26lyL3DQOTgHiTyXa66Bcc/I0cOvXiG+jI6sr3k0NE6bhIbQNLVQTJyhnx/SAaf3kBozAKoqz5e1uA+AqZ9SLRsU/OBKey/9dBqfFcZYVHsBDM2UWyoL0i38QrozM/T3B3xUFjia6WYv/E8DEY1bAl4J+92OEO3IsHaFbHNw0mASaWvMSrnrQYO8Ivbo4ABYa0Rk9XD86CUmPP9goO8Oa3nBCc274rJkgh9AThoEJnfiJ2+kQiPvou7+84iFt6c15uelzIHCNAZnKKZcdJlvr+isFG1+GMTjJgierCYoHv7ApFnY1y8L6L0k6bQN401jewrfFLiG/JP06qN953EwFzJCdrWqo8F98PXO3GPbpc2FkydXoxq9w5Z3QKFzeuPYUeeNh5m2vjeCHPJIBivMfHBiTE3c0vAjaSX1i dsa3LNQ4 Id5iby5XkFAznyLZngz4bk+mMSHQEEjxlnHWS1BN7U3s42PSTPVPNTCWTcOGC54CTWYb7oelHnhvyyLsVztwoJbYKISojLxjIofVHRI9DjZc9wc7X83OZetQHdzlDrqOnUCCUUy1Fof7Inyalf7M8ROCQa3akIZr3z+vCMRFRtse8CIe+y7rsg3DiLhAavWLI1MTJVOJx+wN8DM0Ul8kpXh6xavGoQ5pOlGNUGpwYRNbEF9ngN4qChsQoinl7ZUD5mdTgAXy6DIv1FmUWtUb/a88927nPIzxSwLoR X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: prepare_hugepage_range() performs almost the same checks for all architectures that define it, with the exception of mips and loongarch that also check for overflows. The rest checks for the addr and len to be properly aligned, so we can move that to hugetlb_get_unmapped_area() and get rid of a fair amount of duplicated code. Signed-off-by: Oscar Salvador --- arch/loongarch/include/asm/hugetlb.h | 4 ---- arch/mips/include/asm/hugetlb.h | 4 ---- arch/parisc/include/asm/hugetlb.h | 15 --------------- arch/s390/include/asm/hugetlb.h | 17 ----------------- arch/sh/include/asm/hugetlb.h | 15 --------------- fs/hugetlbfs/inode.c | 8 ++++++-- include/asm-generic/hugetlb.h | 7 ------- 7 files changed, 6 insertions(+), 64 deletions(-) diff --git a/arch/loongarch/include/asm/hugetlb.h b/arch/loongarch/include/asm/hugetlb.h index 5da32c00d483..bf41b024b6a4 100644 --- a/arch/loongarch/include/asm/hugetlb.h +++ b/arch/loongarch/include/asm/hugetlb.h @@ -18,10 +18,6 @@ static inline int prepare_hugepage_range(struct file *file, unsigned long task_size = STACK_TOP; struct hstate *h = hstate_file(file); - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; if (len > task_size) return -ENOMEM; if (task_size - len < addr) diff --git a/arch/mips/include/asm/hugetlb.h b/arch/mips/include/asm/hugetlb.h index fd69c8808554..6a63d82a8ab3 100644 --- a/arch/mips/include/asm/hugetlb.h +++ b/arch/mips/include/asm/hugetlb.h @@ -19,10 +19,6 @@ static inline int prepare_hugepage_range(struct file *file, unsigned long task_size = STACK_TOP; struct hstate *h = hstate_file(file); - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; if (len > task_size) return -ENOMEM; if (task_size - len < addr) diff --git a/arch/parisc/include/asm/hugetlb.h b/arch/parisc/include/asm/hugetlb.h index 72daacc472a0..5b3a5429f71b 100644 --- a/arch/parisc/include/asm/hugetlb.h +++ b/arch/parisc/include/asm/hugetlb.h @@ -12,21 +12,6 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep); -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - if (len & ~HPAGE_MASK) - return -EINVAL; - if (addr & ~HPAGE_MASK) - return -EINVAL; - return 0; -} - #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetlb.h index 37e80a32623a..6f815d4ba0ca 100644 --- a/arch/s390/include/asm/hugetlb.h +++ b/arch/s390/include/asm/hugetlb.h @@ -25,23 +25,6 @@ extern pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep); -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - struct hstate *h = hstate_file(file); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; - return 0; -} - static inline void arch_clear_hugetlb_flags(struct folio *folio) { clear_bit(PG_arch_1, &folio->flags); diff --git a/arch/sh/include/asm/hugetlb.h b/arch/sh/include/asm/hugetlb.h index 75028bd568ba..4a92e6e4d627 100644 --- a/arch/sh/include/asm/hugetlb.h +++ b/arch/sh/include/asm/hugetlb.h @@ -5,21 +5,6 @@ #include #include -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - if (len & ~HPAGE_MASK) - return -EINVAL; - if (addr & ~HPAGE_MASK) - return -EINVAL; - return 0; -} - #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index b6a619f5a85a..cd49d21e7284 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -181,8 +181,12 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr, if (len & ~huge_page_mask(h)) return -EINVAL; - if ((flags & MAP_FIXED) && prepare_hugepage_range(file, addr, len)) - return -EINVAL; + if (flags & MAP_FIXED) { + if (addr & ~huge_page_mask(h)) + return -EINVAL; + if (prepare_hugepage_range(file, addr, len)) + return -EINVAL; + } if (addr) addr0 = ALIGN(addr, huge_page_size(h)); diff --git a/include/asm-generic/hugetlb.h b/include/asm-generic/hugetlb.h index 67bbdafcfc22..f42133dae68e 100644 --- a/include/asm-generic/hugetlb.h +++ b/include/asm-generic/hugetlb.h @@ -123,13 +123,6 @@ static inline int huge_pte_none_mostly(pte_t pte) static inline int prepare_hugepage_range(struct file *file, unsigned long addr, unsigned long len) { - struct hstate *h = hstate_file(file); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; - return 0; } #endif