From nobody Sat Nov 30 10:33:30 2024 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B8A313AA32 for ; Tue, 10 Sep 2024 08:00:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955253; cv=none; b=uE0hJQe0ZlwASmWEOaWeZ9TDrRr2kGDsIyVo0+JGWfO9rHBtbuLP/X24TrgcW0BzIQm/AQJWI8dazZBnRhLYQ27HNpFpY7sXIJlSNxyVJv9u7oUw/b7r4w5JdpVbUOZVyw4+pO/Ji00AYQ6DJ6YGge0SV4WjIGznoKEbWw62gYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955253; c=relaxed/simple; bh=pqoaLw1t9RK9CZsOwL8Ql0wF8GPNRmejWUcFpoXzbx8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K4KJoWr9uvDHGg1G+0pWDI4Qe/fHGLxhSUFyO3yrTj+0+pjQW5ZkIRAuIjzMQRADjJvZvHg3/r/QwaNiffFzI1nbhJATh6t4iA+v9d3Aj5WPpOKgcCSxdX4KWY8ThKuQ1RxvVpMRVSOqqB4qSmr3LRNCsD4MHet27lmph+2006o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=P3HH/9Ve; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=6+VaV++W; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=P3HH/9Ve; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=6+VaV++W; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="P3HH/9Ve"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="6+VaV++W"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="P3HH/9Ve"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="6+VaV++W" 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== Authentication-Results: smtp-out2.suse.de; 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-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 72B111F80A X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[12]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,suse.de:mid,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; TO_DN_SOME(0.00)[]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Flag: NO Content-Type: text/plain; charset="utf-8" We want to stop special casing hugetlb mappings and make them go through generic channels, so teach generic_get_unmapped_area{_topdown} to handle those. The main difference is that we set info.align_mask for huge mappings. Signed-off-by: Oscar Salvador --- include/linux/hugetlb.h | 10 ++++++++++ mm/mmap.c | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 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); =20 +static inline unsigned long huge_page_mask_align(struct file *file) +{ + return PAGE_MASK & ~huge_page_mask(hstate_file(file)); +} + #else /* CONFIG_HUGETLB_PAGE */ struct hstate {}; =20 +static inline unsigned long huge_page_mask_align(struct file *file) +{ + return 0; +} + static inline struct hugepage_subpool *hugetlb_folio_subpool(struct folio = *folio) { return NULL; diff --git a/mm/mmap.c b/mm/mmap.c index 270bd8d504b8..5f05df7d58f5 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -776,6 +776,8 @@ generic_get_unmapped_area(struct file *filp, unsigned l= ong addr, info.low_limit =3D mm->mmap_base; info.high_limit =3D mmap_end; info.start_gap =3D stack_guard_placement(vm_flags); + if (filp && is_file_hugepages(filp)) + info.align_mask =3D huge_page_mask_align(filp); return vm_unmapped_area(&info); } =20 @@ -826,6 +828,8 @@ generic_get_unmapped_area_topdown(struct file *filp, un= signed long addr, info.low_limit =3D PAGE_SIZE; info.high_limit =3D arch_get_mmap_base(addr, mm->mmap_base); info.start_gap =3D stack_guard_placement(vm_flags); + if (filp && is_file_hugepages(filp)) + info.align_mask =3D huge_page_mask_align(filp); addr =3D vm_unmapped_area(&info); =20 /* --=20 2.46.0 From nobody Sat Nov 30 10:33:30 2024 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AFEE14EC64 for ; Tue, 10 Sep 2024 08:00:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955253; cv=none; b=jLVGvJwaZYifikC0aoKBJiain9QXYoozDNGf+eeUGVfP0BFQFIRn4hYdiYbgFNoNtCgJH79H31GRrpx7bA83CDzGwF28qFFS29SUFUtLHFAI7N1BpcYsTK/Il1hSV80GaCl6RSskalwvWUAMcCesLQwa/3pxEhn347O6yZ9+D34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955253; c=relaxed/simple; bh=8RpvInZ904rjzrYDd/w9cypzUFS8kt+qxF7wc6Gm3Zk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hsroh0gqsEPM/96dsOHGkFUMPwcAumNkiiMCohowXqOTlwFBjqylC0UNkk4mgRVArq2GvLMpu59nMvPjcNnS7WPkSo0gdg1fy1Q3esWFLlsHZp+4woju4afM8KqBJVBcgZXKWQ/kiGmXFRTr7GnK2B5d11qSsFEzi7AjtlYlN9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=EHkxGpw6; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Q9CnDgtj; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=EHkxGpw6; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Q9CnDgtj; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="EHkxGpw6"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Q9CnDgtj"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="EHkxGpw6"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Q9CnDgtj" 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== Authentication-Results: smtp-out1.suse.de; none 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWELVE(0.00)[12]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO Content-Type: text/plain; charset="utf-8" We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area{_topdown} to handle those. s390 specific hugetlb function does not set info.align_offset, so do the same here for compatibility. Signed-off-by: Oscar Salvador --- arch/s390/mm/mmap.c | 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 =20 static unsigned long stack_maxrandom_size(void) @@ -73,6 +74,8 @@ static inline unsigned long mmap_base(unsigned long rnd, =20 static int get_align_mask(struct file *filp, unsigned long flags) { + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); if (!(current->flags & PF_RANDOMIZE)) return 0; if (filp || (flags & MAP_SHARED)) @@ -106,7 +109,8 @@ unsigned long arch_get_unmapped_area(struct file *filp,= unsigned long addr, info.low_limit =3D mm->mmap_base; info.high_limit =3D TASK_SIZE; info.align_mask =3D get_align_mask(filp, flags); - info.align_offset =3D pgoff << PAGE_SHIFT; + if (!(filp && is_file_hugepages(filp))) + info.align_offset =3D pgoff << PAGE_SHIFT; addr =3D vm_unmapped_area(&info); if (offset_in_page(addr)) return addr; @@ -144,7 +148,8 @@ unsigned long arch_get_unmapped_area_topdown(struct fil= e *filp, unsigned long ad info.low_limit =3D PAGE_SIZE; info.high_limit =3D mm->mmap_base; info.align_mask =3D get_align_mask(filp, flags); - info.align_offset =3D pgoff << PAGE_SHIFT; + if (!(filp && is_file_hugepages(filp))) + info.align_offset =3D pgoff << PAGE_SHIFT; addr =3D vm_unmapped_area(&info); =20 /* --=20 2.46.0 From nobody Sat Nov 30 10:33:30 2024 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDC40566A for ; Tue, 10 Sep 2024 08:00:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955254; cv=none; b=jwxkVsRFIa3RFcDtVNwvEvddFQ8olgRhS9ua39FvBNGmWRdVt8OqtOoAoFD58xSWqsDhlG/5rAnr2flGbLR+OQswXfYdsWn+3HEK5iM+dlcKyJVM7AbkEN/2yAytJoZJxVNbo6W9H7+v2cy5WjBK8ar4SUsq0w7lX3ZybenBeN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955254; c=relaxed/simple; bh=o+ngPJR/WTqap1k53gNnSK7reZMLey1PyYgL/WO6GlQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VS4Lbj8zbWjgNSaXkt7UdZUESsjvb927rudDoxteVxVOdFDEO9FCf6SD4bKykZBR5cOaJaIKDUadws06hLLfSogqMRZpH97U2Gkxl8OOvzufy1WZKUhGWOLnr+wk5kydRgN7k3YkVb91A01hxAmQBdX02XdGf9tEXWwv7u2vL5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=1BAI1Uzw; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=B1CHF1FU; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=1BAI1Uzw; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=B1CHF1FU; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="1BAI1Uzw"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="B1CHF1FU"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="1BAI1Uzw"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="B1CHF1FU" 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== Authentication-Results: smtp-out1.suse.de; none 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWELVE(0.00)[12]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: Content-Type: text/plain; charset="utf-8" We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area_{topdown_}vmflags to handle those. x86 specific hugetlb function does not set either info.start_gap or info.align_offset so the same here for compatibility. Signed-off-by: Oscar Salvador --- arch/x86/kernel/sys_x86_64.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c index 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 =20 #include #include @@ -25,8 +26,10 @@ /* * Align a virtual address to avoid aliasing in the I$ on AMD F15h. */ -static unsigned long get_align_mask(void) +static unsigned long get_align_mask(struct file *filp) { + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); /* handle 32- and 64-bit case with a single conditional */ if (va_align.flags < 0 || !(va_align.flags & (2 - mmap_is_ia32()))) return 0; @@ -49,7 +52,7 @@ static unsigned long get_align_mask(void) */ static unsigned long get_align_bits(void) { - return va_align.bits & get_align_mask(); + return va_align.bits & get_align_mask(NULL); } =20 static int __init control_va_addr_alignment(char *str) @@ -148,12 +151,15 @@ arch_get_unmapped_area(struct file *filp, unsigned lo= ng addr, unsigned long len, info.length =3D len; info.low_limit =3D begin; info.high_limit =3D end; - info.align_offset =3D pgoff << PAGE_SHIFT; - info.start_gap =3D stack_guard_placement(vm_flags); + if (!(filp && is_file_hugepages(filp))) { + info.align_offset =3D pgoff << PAGE_SHIFT; + info.start_gap =3D stack_guard_placement(vm_flags); + } if (filp) { - info.align_mask =3D get_align_mask(); + info.align_mask =3D get_align_mask(filp); info.align_offset +=3D get_align_bits(); } + return vm_unmapped_area(&info); } =20 @@ -199,7 +205,10 @@ arch_get_unmapped_area_topdown(struct file *filp, unsi= gned long addr0, info.low_limit =3D PAGE_SIZE; =20 info.high_limit =3D get_mmap_base(0); - info.start_gap =3D stack_guard_placement(vm_flags); + if (!(filp && is_file_hugepages(filp))) { + info.start_gap =3D stack_guard_placement(vm_flags); + info.align_offset =3D pgoff << PAGE_SHIFT; + } =20 /* * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area @@ -211,9 +220,8 @@ arch_get_unmapped_area_topdown(struct file *filp, unsig= ned long addr0, if (addr > DEFAULT_MAP_WINDOW && !in_32bit_syscall()) info.high_limit +=3D TASK_SIZE_MAX - DEFAULT_MAP_WINDOW; =20 - info.align_offset =3D pgoff << PAGE_SHIFT; if (filp) { - info.align_mask =3D get_align_mask(); + info.align_mask =3D get_align_mask(filp); info.align_offset +=3D get_align_bits(); } addr =3D vm_unmapped_area(&info); --=20 2.46.0 From nobody Sat Nov 30 10:33:30 2024 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1273183CB8 for ; Tue, 10 Sep 2024 08:00:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955255; cv=none; b=aLT2CPoGoROPgpHPqWkacoYAPEocBxaT490hOnVyTm3F363XEAPRUupJNuoLi8rlaWRg4Fw9sbEP7a1ds9u/fhrE5rU7naJuXQbvEYdA5BMw/ak2cbf8l7fhQtOAf8WcgHQrO4ujDqfopEOztRdbwJrW3HUC2rukvaD++J6iFLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955255; c=relaxed/simple; bh=sCgVlyt+vgal6HBCJ1zUZbSAxG8QQT+5FDjXRszW6i4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kIeBrlSXZN4NLoB6h43uWaGJF2dklv86Csl7z3AyYtxChBQy2NiVy6x6TAyYnXXA1DS3IJ3+44jEKTtUr0Y7p1L2jy6TAugbim4ZUhWTwAtxoTPnnQQJxDp/YjfkvrF/CKUGd93isIOabwHczzX06eZFnOjij/PlRaegsGBlbLA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=JX6qJdZZ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=hOaQUkQa; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=JX6qJdZZ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=hOaQUkQa; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="JX6qJdZZ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="hOaQUkQa"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="JX6qJdZZ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="hOaQUkQa" 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== Authentication-Results: smtp-out1.suse.de; none 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_TWELVE(0.00)[12]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLgqtx3dhxu3ne7bo4p8poxdrt)]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO Content-Type: text/plain; charset="utf-8" We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area{_topdown} to handle those. sparc specific hugetlb function does not set info.align_offset, and does not care about adjusting the align_mask for MAP_SHARED cases, so the same here for compatibility. Signed-off-by: Oscar Salvador --- arch/sparc/kernel/sys_sparc_32.c | 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 =20 #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 v= m_flags) { struct vm_unmapped_area_info info =3D {}; + bool file_hugepage =3D false; + + if (filp && is_file_hugepages(filp)) + file_hugepage =3D true; =20 if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_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 =3D len; info.low_limit =3D addr; info.high_limit =3D TASK_SIZE; - info.align_mask =3D (flags & MAP_SHARED) ? - (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset =3D pgoff << PAGE_SHIFT; + if (!file_hugepage) { + info.align_mask =3D (flags & MAP_SHARED) ? + (PAGE_MASK & (SHMLBA - 1)) : 0; + info.align_offset =3D pgoff << PAGE_SHIFT; + } else { + info.align_mask =3D huge_page_mask_align(filp); + } return vm_unmapped_area(&info); } =20 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc= _64.c index 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 =20 #include #include @@ -87,6 +88,16 @@ static inline unsigned long COLOR_ALIGN(unsigned long ad= dr, return base + off; } =20 +static unsigned long get_align_mask(struct file *filp, unsigned long flags) +{ + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); + if (filp || (flags & MAP_SHARED)) + return PAGE_MASK & (SHMLBA - 1); + + return 0; +} + unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr= , unsigned long len, unsigned long pgoff, unsigned long flags, vm_flags_t v= m_flags) { struct mm_struct *mm =3D current->mm; @@ -94,12 +105,16 @@ unsigned long arch_get_unmapped_area(struct file *filp= , unsigned long addr, unsi unsigned long task_size =3D TASK_SIZE; int do_color_align; struct vm_unmapped_area_info info =3D {}; + bool file_hugepage =3D false; + + if (filp && is_file_hugepages(filp)) + file_hugepage =3D true; =20 if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -111,7 +126,7 @@ unsigned long arch_get_unmapped_area(struct file *filp,= unsigned long addr, unsi return -ENOMEM; =20 do_color_align =3D 0; - if (filp || (flags & MAP_SHARED)) + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align =3D 1; =20 if (addr) { @@ -129,8 +144,9 @@ unsigned long arch_get_unmapped_area(struct file *filp,= unsigned long addr, unsi info.length =3D len; info.low_limit =3D TASK_UNMAPPED_BASE; info.high_limit =3D min(task_size, VA_EXCLUDE_START); - info.align_mask =3D do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset =3D pgoff << PAGE_SHIFT; + info.align_mask =3D get_align_mask(filp, flags); + if (!file_hugepage) + info.align_offset =3D pgoff << PAGE_SHIFT; addr =3D vm_unmapped_area(&info); =20 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) { @@ -154,15 +170,19 @@ arch_get_unmapped_area_topdown(struct file *filp, con= st unsigned long addr0, unsigned long addr =3D addr0; int do_color_align; struct vm_unmapped_area_info info =3D {}; + bool file_hugepage =3D false; =20 /* This should only ever run for 32-bit processes. */ BUG_ON(!test_thread_flag(TIF_32BIT)); =20 + if (filp && is_file_hugepages(filp)) + file_hugepage =3D true; + if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -172,7 +192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const= unsigned long addr0, return -ENOMEM; =20 do_color_align =3D 0; - if (filp || (flags & MAP_SHARED)) + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align =3D 1; =20 /* requesting a specific address */ @@ -192,8 +212,9 @@ arch_get_unmapped_area_topdown(struct file *filp, const= unsigned long addr0, info.length =3D len; info.low_limit =3D PAGE_SIZE; info.high_limit =3D mm->mmap_base; - info.align_mask =3D do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset =3D pgoff << PAGE_SHIFT; + info.align_mask =3D get_align_mask(filp, flags); + if (!file_hugepage) + info.align_offset =3D pgoff << PAGE_SHIFT; addr =3D vm_unmapped_area(&info); =20 /* --=20 2.46.0 From nobody Sat Nov 30 10:33:30 2024 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9533A185942 for ; Tue, 10 Sep 2024 08:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955256; cv=none; b=HjKRfvUNd5bc18/ie1YiCsVbefTGpPQXJ9FTaWx4N3/lqAPfNiHNmEKmjsKnhGELPtZF5WMGve7KqTFIINHkzXF1VMIDgg0WX6QDpJ7tyIJPXQWmgj3WONuCNT1jrV31XqT08S+V8bWGZ2KC4D6Kdy0P5sRuTOKCqI3hBgAunCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955256; c=relaxed/simple; bh=65iiIC6vTesNB2Wn9xPCeMa4g3pLb8SgV97O7hV+yzc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cny9QZdXs3oLM5Nnl5CSZRfnTEcVNAFpYKZNOX+mSNH7HTIjkQ2TcV7gvN8yFSDgDXr7760L62yAN8yjNpqtsrxAH4ldwjM8QEx3BzSGwtJyyk7Yspk+YLXfOSHRR94CxUyo2qJbtvLlb4UZWk2B8/JSAFfN+DfxptZLoIIhpwg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ItqeHbI+; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=lIO2uYXK; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ItqeHbI+; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=lIO2uYXK; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ItqeHbI+"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="lIO2uYXK"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ItqeHbI+"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="lIO2uYXK" 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== Authentication-Results: smtp-out2.suse.de; none 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_TWELVE(0.00)[12]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLgqtx3dhxu3ne7bo4p8poxdrt)]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: Content-Type: text/plain; charset="utf-8" We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area{_topdown} to handle those. Reshuffle file_to_psize() definition so arch_get_unmapped_area{_topdown} can make use of it. Signed-off-by: Oscar Salvador --- arch/powerpc/mm/book3s64/slice.c | 40 ++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/sl= ice.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 ad= dr, unsigned long len, } EXPORT_SYMBOL_GPL(slice_get_unmapped_area); =20 +#ifdef CONFIG_HUGETLB_PAGE +static int file_to_psize(struct file *file) +{ + struct hstate *hstate =3D hstate_file(file); + + return shift_to_mmu_psize(huge_page_shift(hstate)); +} +#else +static int file_to_psize(struct file *file) +{ + return 0; +} +#endif + unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, @@ -640,11 +654,17 @@ unsigned long arch_get_unmapped_area(struct file *fil= p, 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= ); =20 - return slice_get_unmapped_area(addr, len, flags, - mm_ctx_user_psize(¤t->mm->context), 0); + if (filp && is_file_hugepages(filp)) + psize =3D file_to_psize(filp); + else + psize =3D mm_ctx_user_psize(¤t->mm->context); + + return slice_get_unmapped_area(addr, len, flags, psize, 0); } =20 unsigned long arch_get_unmapped_area_topdown(struct file *filp, @@ -654,11 +674,17 @@ unsigned long arch_get_unmapped_area_topdown(struct f= ile *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); =20 - return slice_get_unmapped_area(addr0, len, flags, - mm_ctx_user_psize(¤t->mm->context), 1); + if (filp && is_file_hugepages(filp)) + psize =3D file_to_psize(filp); + else + psize =3D mm_ctx_user_psize(¤t->mm->context); + + return slice_get_unmapped_area(addr0, len, flags, psize, 1); } =20 unsigned int notrace get_slice_psize(struct mm_struct *mm, unsigned long a= ddr) @@ -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_star= t)); } =20 -static int file_to_psize(struct file *file) -{ - struct hstate *hstate =3D hstate_file(file); - return shift_to_mmu_psize(huge_page_shift(hstate)); -} - unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long a= ddr, unsigned long len, unsigned long pgoff, unsigned long flags) --=20 2.46.0 From nobody Sat Nov 30 10:33:30 2024 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A0331862B3 for ; Tue, 10 Sep 2024 08:00:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955256; cv=none; b=dPfSKJ9xYtbu6Byv+gVoiYtuVTlSYrX+ZY+9tGKxhltDytvpgErfIRKAmLwUHQOGQpWY55p0IFK700GW5TI8KCZ/m2FNXy7r4XaWtBLkqb/kDtmmL0u2h8hqWng2YpM+63HnlTrAX+KjfFzMbPqJs4MrcD/hFq2EgXI1gZp4zUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955256; c=relaxed/simple; bh=VNHI6gtINqZ8KBQ6rJcl5wrE9sYAmdnM6oF9pW3kR88=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pCRuOEjJV8jc0Nqu0K2MMW4DCkGjnndUJe7gw93zBLsqhagH69cYYWELLxiyWgipZ9+G/olgBJqpYzxbj4v79jR/2BlQKkBjqepD1dbpI9eTWahuqiyWJkst5jUY7uBsAznRR+40iS2QMd8LRhIx3ztnDJ/S/T1EGiOhTMBmXbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=oQWHLDDd; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=+X/5hx72; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=oQWHLDDd; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=+X/5hx72; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="oQWHLDDd"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="+X/5hx72"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="oQWHLDDd"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="+X/5hx72" 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== Authentication-Results: smtp-out1.suse.de; none 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_TWELVE(0.00)[12]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLgqtx3dhxu3ne7bo4p8poxdrt)]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: Content-Type: text/plain; charset="utf-8" Hugetlb mappings will no longer be special cased but rather go through the generic mm_get_unmapped_area_vmflags function. For that to happen, let us remove the .get_unmapped_area from hugetlbfs_file_operations struct, and hint __get_unmapped_area that it should not send hugetlb mappings through thp_get_unmapped_area_vmfl= ags but through mm_get_unmapped_area_vmflags. Create also a function called hugetlb_mmap_check_and_align() where a couple of safety checks are being done and the addr is aligned to the huge page size. Otherwise we will have to do this in every single function, which duplicates quite a lot of code. Signed-off-by: Oscar Salvador --- fs/hugetlbfs/inode.c | 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); } =20 -#ifndef HAVE_ARCH_HUGETLB_UNMAPPED_AREA -static unsigned long -hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, - unsigned long flags) +unsigned long +__hugetlb_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 =3D 0; + struct hstate *h =3D hstate_file(file); + + if (len & ~huge_page_mask(h)) + return -EINVAL; + if ((flags & MAP_FIXED) && prepare_hugepage_range(file, addr, len)) + return -EINVAL; + if (addr) + addr0 =3D ALIGN(addr, huge_page_size(h)); + + return mm_get_unmapped_area_vmflags(current->mm, file, addr, len, pgoff, + flags, 0); } -#endif =20 /* * Someone wants to read @bytes from a HWPOISON hugetlb @page from @offset. @@ -1300,7 +1308,7 @@ static const struct file_operations hugetlbfs_file_op= erations =3D { .read_iter =3D hugetlbfs_read_iter, .mmap =3D hugetlbfs_file_mmap, .fsync =3D noop_fsync, - .get_unmapped_area =3D hugetlb_get_unmapped_area, + .get_unmapped_area =3D __hugetlb_get_unmapped_area, .llseek =3D default_llseek, .fallocate =3D hugetlbfs_fallocate, .fop_flags =3D FOP_HUGE_PAGES, diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 368d552e4860..3a81b6126f62 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -546,11 +546,10 @@ static inline struct hstate *hstate_inode(struct inod= e *i) } #endif /* !CONFIG_HUGETLBFS */ =20 -#ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA -unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long a= ddr, - unsigned long len, unsigned long pgoff, - unsigned long flags); -#endif /* HAVE_ARCH_HUGETLB_UNMAPPED_AREA */ +unsigned long +__generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags); =20 unsigned long generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, --=20 2.46.0 From nobody Sat Nov 30 10:33:30 2024 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 172F8186E56 for ; Tue, 10 Sep 2024 08:00:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955258; cv=none; b=lmCKSw910MfVpcbS4ByaL5LIKHCVFCtPlRgQp20Esd0rAw73eQQOv0Ba4qrIs2sNbt7eJ2daIKU2WDnspNWbFosRZhYTPkPvPMJ5S45zNi1NoKst3r1DOuQC0szHAaqfpuwP6wIFfDexdBydzkkGaDiOgoH/uVsR5QXiZh4/1Gg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955258; c=relaxed/simple; bh=sRfKQZvUI5mHLvXU/4qH6x62FsOmiRTGLDNMjvtLvrA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PL7pVHDEuioz7vGLBKvgXi7w6RWe+vJqPrkUs6niqbfJEHZM+1/ITVqHrwtrrqF5FXZA9E2AVWVu0E8WEaZzNu2i1zENLpAu3poPjHflzH+TYrv9UijRfB1+HuxCRDVPmFoL9Tpu/5D5NCKeIVAg0+nMWiIxMNVHT4sqbLBsV+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=1wH5bCcn; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=uYXsA/Cg; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=1wH5bCcn; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=uYXsA/Cg; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="1wH5bCcn"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="uYXsA/Cg"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="1wH5bCcn"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="uYXsA/Cg" 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== Authentication-Results: smtp-out1.suse.de; none 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_TWELVE(0.00)[12]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLgqtx3dhxu3ne7bo4p8poxdrt)]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO Content-Type: text/plain; charset="utf-8" Hugetlb mappings are now handled through normal channels just like any other mapping, so we no longer need hugetlb_get_unmapped_area* specific functions. Signed-off-by: Oscar Salvador --- arch/parisc/mm/hugetlbpage.c | 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 =20 =20 -unsigned long -hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h =3D hstate_file(file); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (len > TASK_SIZE) - return -ENOMEM; - - if (flags & MAP_FIXED) - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - - if (addr) - addr =3D ALIGN(addr, huge_page_size(h)); - - /* we need to make sure the colouring is OK */ - return arch_get_unmapped_area(file, addr, len, pgoff, flags, 0); -} =20 =20 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/sl= ice.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) =20 return 1UL << mmu_psize_to_shift(get_slice_psize(vma->vm_mm, vma->vm_star= t)); } - -unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long a= ddr, - unsigned long len, unsigned long pgoff, - unsigned long flags) -{ - if (radix_enabled()) - return generic_hugetlb_get_unmapped_area(file, addr, len, pgoff, flags); - - return slice_get_unmapped_area(addr, len, flags, file_to_psize(file), 1); -} #endif diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c index 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 =3D hstate_file(file); - struct vm_unmapped_area_info info =3D {}; - - info.length =3D len; - info.low_limit =3D current->mm->mmap_base; - info.high_limit =3D TASK_SIZE; - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - return vm_unmapped_area(&info); -} - -static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file, - unsigned long addr0, unsigned long len, - unsigned long pgoff, unsigned long flags) -{ - struct hstate *h =3D hstate_file(file); - struct vm_unmapped_area_info info =3D {}; - unsigned long addr; - - info.flags =3D VM_UNMAPPED_AREA_TOPDOWN; - info.length =3D len; - info.low_limit =3D PAGE_SIZE; - info.high_limit =3D current->mm->mmap_base; - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - addr =3D vm_unmapped_area(&info); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - if (addr & ~PAGE_MASK) { - VM_BUG_ON(addr !=3D -ENOMEM); - info.flags =3D 0; - info.low_limit =3D TASK_UNMAPPED_BASE; - info.high_limit =3D TASK_SIZE; - addr =3D vm_unmapped_area(&info); - } - - return addr; -} - -unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long a= ddr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h =3D hstate_file(file); - struct mm_struct *mm =3D current->mm; - struct vm_area_struct *vma; - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (len > TASK_SIZE - mmap_min_addr) - return -ENOMEM; - - if (flags & MAP_FIXED) { - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - goto check_asce_limit; - } - - if (addr) { - addr =3D ALIGN(addr, huge_page_size(h)); - vma =3D find_vma(mm, addr); - if (TASK_SIZE - len >=3D addr && addr >=3D mmap_min_addr && - (!vma || addr + len <=3D vm_start_gap(vma))) - goto check_asce_limit; - } - - if (!test_bit(MMF_TOPDOWN, &mm->flags)) - addr =3D hugetlb_get_unmapped_area_bottomup(file, addr, len, - pgoff, flags); - else - addr =3D hugetlb_get_unmapped_area_topdown(file, addr, len, - pgoff, flags); - if (offset_in_page(addr)) - return addr; - -check_asce_limit: - return check_asce_limit(mm, addr, len); -} diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c index cc91ca7a1e18..eee601a0d2cf 100644 --- a/arch/sparc/mm/hugetlbpage.c +++ b/arch/sparc/mm/hugetlbpage.c @@ -19,114 +19,6 @@ #include #include =20 -/* Slightly simplified from the non-hugepage variant because by - * definition we don't have to worry about any page coloring stuff - */ - -static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp, - unsigned long addr, - unsigned long len, - unsigned long pgoff, - unsigned long flags) -{ - struct hstate *h =3D hstate_file(filp); - unsigned long task_size =3D TASK_SIZE; - struct vm_unmapped_area_info info =3D {}; - - if (test_thread_flag(TIF_32BIT)) - task_size =3D STACK_TOP32; - - info.length =3D len; - info.low_limit =3D TASK_UNMAPPED_BASE; - info.high_limit =3D min(task_size, VA_EXCLUDE_START); - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - addr =3D vm_unmapped_area(&info); - - if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) { - VM_BUG_ON(addr !=3D -ENOMEM); - info.low_limit =3D VA_EXCLUDE_END; - info.high_limit =3D task_size; - addr =3D vm_unmapped_area(&info); - } - - return addr; -} - -static unsigned long -hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long a= ddr0, - const unsigned long len, - const unsigned long pgoff, - const unsigned long flags) -{ - struct hstate *h =3D hstate_file(filp); - struct mm_struct *mm =3D current->mm; - unsigned long addr =3D addr0; - struct vm_unmapped_area_info info =3D {}; - - /* This should only ever run for 32-bit processes. */ - BUG_ON(!test_thread_flag(TIF_32BIT)); - - info.flags =3D VM_UNMAPPED_AREA_TOPDOWN; - info.length =3D len; - info.low_limit =3D PAGE_SIZE; - info.high_limit =3D mm->mmap_base; - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - addr =3D vm_unmapped_area(&info); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - if (addr & ~PAGE_MASK) { - VM_BUG_ON(addr !=3D -ENOMEM); - info.flags =3D 0; - info.low_limit =3D TASK_UNMAPPED_BASE; - info.high_limit =3D STACK_TOP32; - addr =3D vm_unmapped_area(&info); - } - - return addr; -} - -unsigned long -hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h =3D hstate_file(file); - struct mm_struct *mm =3D current->mm; - struct vm_area_struct *vma; - unsigned long task_size =3D TASK_SIZE; - - if (test_thread_flag(TIF_32BIT)) - task_size =3D STACK_TOP32; - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (len > task_size) - return -ENOMEM; - - if (flags & MAP_FIXED) { - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - return addr; - } - - if (addr) { - addr =3D ALIGN(addr, huge_page_size(h)); - vma =3D find_vma(mm, addr); - if (task_size - len >=3D addr && - (!vma || addr + len <=3D vm_start_gap(vma))) - return addr; - } - if (!test_bit(MMF_TOPDOWN, &mm->flags)) - return hugetlb_get_unmapped_area_bottomup(file, addr, len, - pgoff, flags); - else - return hugetlb_get_unmapped_area_topdown(file, addr, len, - pgoff, flags); -} =20 static pte_t sun4u_hugepage_shift_to_tte(pte_t entry, unsigned int shift) { diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c index 807a5859a3c4..58f7f2bd535d 100644 --- a/arch/x86/mm/hugetlbpage.c +++ b/arch/x86/mm/hugetlbpage.c @@ -19,107 +19,6 @@ #include #include =20 -#ifdef CONFIG_HUGETLB_PAGE -static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file, - unsigned long addr, unsigned long len, - unsigned long pgoff, unsigned long flags) -{ - struct hstate *h =3D hstate_file(file); - struct vm_unmapped_area_info info =3D {}; - - info.length =3D len; - info.low_limit =3D get_mmap_base(1); - - /* - * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area - * in the full address space. - */ - info.high_limit =3D in_32bit_syscall() ? - task_size_32bit() : task_size_64bit(addr > DEFAULT_MAP_WINDOW); - - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - return vm_unmapped_area(&info); -} - -static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file, - unsigned long addr, unsigned long len, - unsigned long pgoff, unsigned long flags) -{ - struct hstate *h =3D hstate_file(file); - struct vm_unmapped_area_info info =3D {}; - - info.flags =3D VM_UNMAPPED_AREA_TOPDOWN; - info.length =3D len; - info.low_limit =3D PAGE_SIZE; - info.high_limit =3D get_mmap_base(0); - - /* - * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area - * in the full address space. - */ - if (addr > DEFAULT_MAP_WINDOW && !in_32bit_syscall()) - info.high_limit +=3D TASK_SIZE_MAX - DEFAULT_MAP_WINDOW; - - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - addr =3D vm_unmapped_area(&info); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - if (addr & ~PAGE_MASK) { - VM_BUG_ON(addr !=3D -ENOMEM); - info.flags =3D 0; - info.low_limit =3D TASK_UNMAPPED_BASE; - info.high_limit =3D TASK_SIZE_LOW; - addr =3D vm_unmapped_area(&info); - } - - return addr; -} - -unsigned long -hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h =3D hstate_file(file); - struct mm_struct *mm =3D current->mm; - struct vm_area_struct *vma; - - if (len & ~huge_page_mask(h)) - return -EINVAL; - - if (len > TASK_SIZE) - return -ENOMEM; - - /* No address checking. See comment at mmap_address_hint_valid() */ - if (flags & MAP_FIXED) { - if (prepare_hugepage_range(file, addr, len)) - return -EINVAL; - return addr; - } - - if (addr) { - addr &=3D huge_page_mask(h); - if (!mmap_address_hint_valid(addr, len)) - goto get_unmapped_area; - - vma =3D find_vma(mm, addr); - if (!vma || addr + len <=3D vm_start_gap(vma)) - return addr; - } - -get_unmapped_area: - if (!test_bit(MMF_TOPDOWN, &mm->flags)) - return hugetlb_get_unmapped_area_bottomup(file, addr, len, - pgoff, flags); - else - return hugetlb_get_unmapped_area_topdown(file, addr, len, - pgoff, flags); -} -#endif /* CONFIG_HUGETLB_PAGE */ =20 #ifdef CONFIG_X86_64 bool __init arch_hugetlb_valid_size(unsigned long size) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 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, str= uct vm_area_struct *vma) * Called under mmap_write_lock(mm). */ =20 -static unsigned long -hugetlb_get_unmapped_area_bottomup(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h =3D hstate_file(file); - struct vm_unmapped_area_info info =3D {}; - - info.length =3D len; - info.low_limit =3D current->mm->mmap_base; - info.high_limit =3D arch_get_mmap_end(addr, len, flags); - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - return vm_unmapped_area(&info); -} - -static unsigned long -hugetlb_get_unmapped_area_topdown(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - struct hstate *h =3D hstate_file(file); - struct vm_unmapped_area_info info =3D {}; - - info.flags =3D VM_UNMAPPED_AREA_TOPDOWN; - info.length =3D len; - info.low_limit =3D PAGE_SIZE; - info.high_limit =3D arch_get_mmap_base(addr, current->mm->mmap_base); - info.align_mask =3D PAGE_MASK & ~huge_page_mask(h); - addr =3D vm_unmapped_area(&info); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - if (unlikely(offset_in_page(addr))) { - VM_BUG_ON(addr !=3D -ENOMEM); - info.flags =3D 0; - info.low_limit =3D current->mm->mmap_base; - info.high_limit =3D arch_get_mmap_end(addr, len, flags); - addr =3D vm_unmapped_area(&info); - } - - return addr; -} - -unsigned long -generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, - unsigned long flags) -{ - struct mm_struct *mm =3D current->mm; - struct vm_area_struct *vma, *prev; - struct hstate *h =3D hstate_file(file); - const unsigned long mmap_end =3D arch_get_mmap_end(addr, len, flags); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (len > 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 =3D ALIGN(addr, huge_page_size(h)); - vma =3D find_vma_prev(mm, addr, &prev); - if (mmap_end - len >=3D addr && addr >=3D mmap_min_addr && - (!vma || addr + len <=3D vm_start_gap(vma)) && - (!prev || addr >=3D 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 =3D 0; struct hstate *h =3D hstate_file(file); @@ -272,7 +186,7 @@ __hugetlb_get_unmapped_area(struct file *file, unsigned= long addr, if (addr) addr0 =3D ALIGN(addr, huge_page_size(h)); =20 - 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); } =20 @@ -1308,7 +1222,7 @@ static const struct file_operations hugetlbfs_file_op= erations =3D { .read_iter =3D hugetlbfs_read_iter, .mmap =3D hugetlbfs_file_mmap, .fsync =3D noop_fsync, - .get_unmapped_area =3D __hugetlb_get_unmapped_area, + .get_unmapped_area =3D hugetlb_get_unmapped_area, .llseek =3D default_llseek, .fallocate =3D hugetlbfs_fallocate, .fop_flags =3D FOP_HUGE_PAGES, diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 3a81b6126f62..ae4fe8615bb6 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -547,15 +547,10 @@ static inline struct hstate *hstate_inode(struct inod= e *i) #endif /* !CONFIG_HUGETLBFS */ =20 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); =20 -unsigned long -generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, - unsigned long flags); - /* * huegtlb page specific state flags. These flags are located in page.pri= vate * of the hugetlb head page. Functions created via the below macros shoul= d be --=20 2.46.0 From nobody Sat Nov 30 10:33:30 2024 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04AA3187878 for ; Tue, 10 Sep 2024 08:00:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955258; cv=none; b=Nxi9S5KqoHJBLFLnS425wiiHaMQ4zH32v6Kej9GN3NQ+yqKtzXHWW9qvfeuustuZlzeMmVz7D1jdCE72TJtx+hF+aVNysrjSScnFV64Z4dsPakPE+ZR8jeXQ9Bduwu0Wr8a9JM+1ZrWgpFBk+FSZV1m+WGvwmeBZYUewhwSJq18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955258; c=relaxed/simple; bh=GcaYi8gCPYa728c/VEK/Ws0wFwHwpHFoNttiC5aK+d8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uggOz+yc88b/Kt+hd4AcBTUlNCgWq+ZxYmEfv4lQBdEDW0tafHUkm86WqtFsCsQ7zBSb2OkMftD08Tf92X5hZOYfUc0MMle72ieGDxD8FIPCj9sAe+b35I3Z5QguY4bgKAOFwNddozV/75yOK0EBJW/0NPNukcjSjsJ11ukcNQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=2GspKjyB; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=46XjDi1L; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=2GspKjyB; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=46XjDi1L; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="2GspKjyB"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="46XjDi1L"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="2GspKjyB"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="46XjDi1L" 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== Authentication-Results: smtp-out2.suse.de; none 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_TWELVE(0.00)[12]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLgqtx3dhxu3ne7bo4p8poxdrt)]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: Content-Type: text/plain; charset="utf-8" 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/hugetl= b.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 =20 -#define hugetlb_free_pgd_range free_pgd_range #define hugepages_supported() (MACHINE_HAS_EDAT1) =20 +#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); =20 /* * If the arch doesn't supply something else, assume that hugepage * size aligned regions are ok without further preparation. */ +#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE static inline int prepare_hugepage_range(struct file *file, unsigned long addr, unsigned long len) { @@ -45,6 +48,7 @@ static inline void arch_clear_hugetlb_flags(struct folio = *folio) } #define arch_clear_hugetlb_flags arch_clear_hugetlb_flags =20 +#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)); } =20 +#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); } =20 +#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_ar= ea_struct *vma, return changed; } =20 +#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_st= ruct *mm, __set_huge_pte_at(mm, addr, ptep, pte_wrprotect(pte)); } =20 -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); } =20 +#define __HAVE_ARCH_HUGE_PTE_NONE_MOSTLY static inline int huge_pte_none_mostly(pte_t pte) { return huge_pte_none(pte); } =20 -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; } =20 +#define __HAVE_ARCH_HUGE_PTE_CLEAR_UFFD_WP static inline pte_t huge_pte_clear_uffd_wp(pte_t pte) { return pte; } =20 +#define __HAVE_ARCH_HUGE_PTE_UFFD_WP static inline int huge_pte_uffd_wp(pte_t pte) { return 0; } =20 -static inline bool gigantic_page_runtime_supported(void) -{ - return true; -} +#include =20 #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); } =20 +#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 =20 +#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 =20 +#ifndef __HAVE_ARCH_HUGE_PTE_UFFD_WP static inline int huge_pte_uffd_wp(pte_t pte) { return pte_uffd_wp(pte); } +#endif =20 #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 =20 /* 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 =20 #ifndef __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE static inline int prepare_hugepage_range(struct file *file, --=20 2.46.0 From nobody Sat Nov 30 10:33:30 2024 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93ECD188591 for ; Tue, 10 Sep 2024 08:00:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955260; cv=none; b=nTxV6Ne7sLSXhs6CBnZj7F1wDbZs/fHZv7cijd1tcnzgPqU+HYkwZTcvIpvaUDXx+04ZJsdz3Qg34RUx8I5pxIkGllLtiQArJMwwYaKcTbKW9Kg5BeAiJP6OwsF8728JMG12Jh0dukYl7+G9rONfQPlet3al5nJYbTBmHHmaNN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725955260; c=relaxed/simple; bh=8eEqmN4G8Rn5jUT514gJxGi/t89cOnF4YrN75lqHmb4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YPeK1s1609OV7AYsC9SkOJGed9CaNEGaEmczc2gMMDZ+Te2hSUIJOx7s8Oxn9JrDmRzej9zfg88Oqax+5KGoJes7aQM2Xmg7B4oZHNZxhsixNHjeJStlDc+nOUCUP5PeMtoTnZx1H14kqp/QgUVZ15deagwrDeY2mBCl7zA8jaY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=giYkk7zX; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=uCeWmHNi; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=giYkk7zX; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=uCeWmHNi; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="giYkk7zX"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="uCeWmHNi"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="giYkk7zX"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="uCeWmHNi" 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== Authentication-Results: smtp-out1.suse.de; 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-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: D57D421A41 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCPT_COUNT_TWELVE(0.00)[12]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_EQ_ENVFROM(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLsw5aryjsbtotqfh5i7tfsykm)]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:email,suse.de:dkim,suse.de:mid] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Flag: NO Content-Type: text/plain; charset="utf-8" prepare_hugepage_range() performs almost the same checks for all architectures that define it, with the exception of mips and loongarch that also check for overflows. The rest checks for the addr and len to be properly aligned, so we can move that to 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 *fi= le, unsigned long task_size =3D STACK_TOP; struct hstate *h =3D hstate_file(file); =20 - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; if (len > task_size) return -ENOMEM; if (task_size - len < addr) diff --git a/arch/mips/include/asm/hugetlb.h b/arch/mips/include/asm/hugetl= b.h index fd69c8808554..6a63d82a8ab3 100644 --- a/arch/mips/include/asm/hugetlb.h +++ b/arch/mips/include/asm/hugetlb.h @@ -19,10 +19,6 @@ static inline int prepare_hugepage_range(struct file *fi= le, unsigned long task_size =3D STACK_TOP; struct hstate *h =3D hstate_file(file); =20 - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; if (len > task_size) return -ENOMEM; if (task_size - len < addr) diff --git a/arch/parisc/include/asm/hugetlb.h b/arch/parisc/include/asm/hu= getlb.h index 72daacc472a0..5b3a5429f71b 100644 --- a/arch/parisc/include/asm/hugetlb.h +++ b/arch/parisc/include/asm/hugetlb.h @@ -12,21 +12,6 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long= addr, pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep); =20 -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - if (len & ~HPAGE_MASK) - return -EINVAL; - if (addr & ~HPAGE_MASK) - return -EINVAL; - return 0; -} - #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetl= b.h index 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, unsigne= d long addr, pte_t *ptep extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep); =20 -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - struct hstate *h =3D hstate_file(file); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; - return 0; -} - static inline void arch_clear_hugetlb_flags(struct folio *folio) { clear_bit(PG_arch_1, &folio->flags); diff --git a/arch/sh/include/asm/hugetlb.h b/arch/sh/include/asm/hugetlb.h index 75028bd568ba..4a92e6e4d627 100644 --- a/arch/sh/include/asm/hugetlb.h +++ b/arch/sh/include/asm/hugetlb.h @@ -5,21 +5,6 @@ #include #include =20 -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - if (len & ~HPAGE_MASK) - return -EINVAL; - if (addr & ~HPAGE_MASK) - return -EINVAL; - return 0; -} - #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 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, =20 if (len & ~huge_page_mask(h)) return -EINVAL; - if ((flags & MAP_FIXED) && prepare_hugepage_range(file, addr, len)) - return -EINVAL; + if (flags & MAP_FIXED) { + if (addr & ~huge_page_mask(h)) + return -EINVAL; + if (prepare_hugepage_range(file, addr, len)) + return -EINVAL; + } if (addr) addr0 =3D ALIGN(addr, huge_page_size(h)); =20 diff --git a/include/asm-generic/hugetlb.h b/include/asm-generic/hugetlb.h index 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 =3D hstate_file(file); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; - return 0; } #endif --=20 2.46.0