From nobody Wed Nov 27 23:23:38 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 95A1E18873E for ; Mon, 7 Oct 2024 07:50:53 +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=1728287455; cv=none; b=HwSEyvSusrVB0uNB5zkS9zONJcMmUaMU3E8FEuZni/06/3b8jEkm0ZYKKNDLliK+OiHCZKhos/4k3Ja8WYlvfKIFISfMBI9qSF2VnF4/BE/4fWMDIGHL9DRDdFaGkkW/nx/11kJybkkH9TYNSqsFLIiizmpNUJF5Y6lT8rLrwc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728287455; c=relaxed/simple; bh=fJONQMVPYXZEetwgTFyRzSzzh7LsVRvyvn08ZVwZVaI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QyLru0gm5MA16ngBSW90MjLgcjsPLGSQqlzhqiJMnsonv2arNw6Upt5ZdOODK4WJz3n/a0RAgbkGt0jZbCd+SRJ3AMc5mLxpDJbZUdLqtHBX6B/JuQQUUhqDJWfjCT/noxMY8T0RrkQEl6fBTmmGHFIXl1MlCIDNu4un9KqqDC0= 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=ADp55/pX; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=1lcsC+83; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ADp55/pX; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=1lcsC+83; 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="ADp55/pX"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="1lcsC+83"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ADp55/pX"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="1lcsC+83" 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 E86AA1F84F; Mon, 7 Oct 2024 07:50:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728287451; 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=nToqOO7GlBoRNGFY8sGJEqoQNYfVFvYYnrXC4X6coa4=; b=ADp55/pX5WI3Mg9p7PK4RW8GW+Rn9bxI4wgI+2QNBq6Fe+4lbWESvGl+Utllq62MrtNWPk LB4wW1OQQDyXt1J0DpQ0hE9L5/KW2dCukUm8O4glSBuKyPypicn+56LITTQjvd1veOmfLa fsOiF7q3ZmEisIn4G3Vi8TEQyc/DUk0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728287451; 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=nToqOO7GlBoRNGFY8sGJEqoQNYfVFvYYnrXC4X6coa4=; b=1lcsC+839ZcPy/lvLPaLQ2i4gypqWEjq3jXCggK/8NOMN8nPKQ6m/eM6boA6rBSXNvnygJ GhKSYRbkGEIf8UBw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728287451; 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=nToqOO7GlBoRNGFY8sGJEqoQNYfVFvYYnrXC4X6coa4=; b=ADp55/pX5WI3Mg9p7PK4RW8GW+Rn9bxI4wgI+2QNBq6Fe+4lbWESvGl+Utllq62MrtNWPk LB4wW1OQQDyXt1J0DpQ0hE9L5/KW2dCukUm8O4glSBuKyPypicn+56LITTQjvd1veOmfLa fsOiF7q3ZmEisIn4G3Vi8TEQyc/DUk0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728287451; 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=nToqOO7GlBoRNGFY8sGJEqoQNYfVFvYYnrXC4X6coa4=; b=1lcsC+839ZcPy/lvLPaLQ2i4gypqWEjq3jXCggK/8NOMN8nPKQ6m/eM6boA6rBSXNvnygJ GhKSYRbkGEIf8UBw== 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 48676132BD; Mon, 7 Oct 2024 07:50: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 MH/ODtuSA2d6cQAAD6G6ig (envelope-from ); Mon, 07 Oct 2024 07:50: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 , Oscar Salvador Subject: [PATCH v4 1/9] mm/mmap: Teach generic_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Mon, 7 Oct 2024 09:50:29 +0200 Message-ID: <20241007075037.267650-2-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241007075037.267650-1-osalvador@suse.de> References: <20241007075037.267650-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 [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_SEVEN(0.00)[11]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -6.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 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 9c0fb43064b5..57fd5ab2abe7 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.1 From nobody Wed Nov 27 23:23:38 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 5FB441534E9 for ; Mon, 7 Oct 2024 07:50:54 +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=1728287456; cv=none; b=IJ3hGI8KfTcjHsis29bwtnPyGiPrgvHpIaGoZVsdREELrM9Qx+O5dZQz2Xb4IoAa8MDn0yfUeM0K/HmRXF//ojQzcwlfQXezZtDhNw0YPYSPJkzmFXzBIXSuLPaVSg5vFrRabMziCskVVclDdfMI7SGwkzU0XWWpnxYHfFOu+G4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728287456; c=relaxed/simple; bh=DxUv82Ohdth37zSpruS3Qq87fi6D52lQn0WSreNHUGY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ldG5yH6Fojcrroyx8qd8KlluVTGLLI0KMkANO4/YfCQn3wYrXeUA+LCMqWNCNOO4sSPIce0ALzKTc/sDTDxGUdciG1pb1uXbxxoOkP1DDOkZIAIsvWg/Cza/ctcd+0Ycx3y5TLF5wuO6nN0MOPksWWrTYLtMnJgjcua3p4KZGyE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A5FA721BF8; Mon, 7 Oct 2024 07:50:52 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 065B113A55; Mon, 7 Oct 2024 07:50: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 CN9COtuSA2d6cQAAD6G6ig (envelope-from ); Mon, 07 Oct 2024 07:50: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 , Oscar Salvador Subject: [PATCH v4 2/9] arch/s390: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Mon, 7 Oct 2024 09:50:30 +0200 Message-ID: <20241007075037.267650-3-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241007075037.267650-1-osalvador@suse.de> References: <20241007075037.267650-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Spam-Flag: NO X-Rspamd-Queue-Id: A5FA721BF8 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org Content-Type: text/plain; charset="utf-8" We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area{_topdown} to handle those. 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.1 From nobody Wed Nov 27 23:23:38 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 2E8F5189BBD for ; Mon, 7 Oct 2024 07:50:54 +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=1728287456; cv=none; b=ggWi3pUhjXZdVajCjFnxbkEq+v6ePoi18OOdW7nYqlO/bQGJ6T2+V+lv0ht8uEkKETpbE09vhLWjf+2t4Jd0EqjX1Q8Jmuj3alF5nXD+paJmAVSHgOkwR3biqxJLKZVgvvuBZhTM6FHfHRn+wo+sHKCRWwgfG+qbUNYYtViI/vA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728287456; c=relaxed/simple; bh=4yPV2ljQVPzjkU804QHABX4ogB3g52Ya+5xwA7QP138=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HQbovYs0vojsQW97ZuOObOxLuGYYAGZgEAO9kgBa5lw69yDiWw0bWWokBlYBOKNyIiMuoQK2SM3M/PSeaHCUz6VgsOV5bm6Hyt8aXgzP3iWRSeZXSK0nzw5GRsvg1hR3G99Q9C9pviNPd7idVa+yoqY5+jTOdCoDbUT6XBYdE5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 65D3B21C4D; Mon, 7 Oct 2024 07:50:53 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BACF4132BD; Mon, 7 Oct 2024 07:50: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 sP+YKtySA2d6cQAAD6G6ig (envelope-from ); Mon, 07 Oct 2024 07:50: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 , Oscar Salvador Subject: [PATCH v4 3/9] arch/x86: Teach arch_get_unmapped_area_vmflags to handle hugetlb mappings Date: Mon, 7 Oct 2024 09:50:31 +0200 Message-ID: <20241007075037.267650-4-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241007075037.267650-1-osalvador@suse.de> References: <20241007075037.267650-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 65D3B21C4D X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org 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.1 From nobody Wed Nov 27 23:23:38 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 CF42718B49C for ; Mon, 7 Oct 2024 07:50:55 +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=1728287457; cv=none; b=gCHtc29kwPW3k1bNrhvanmD+bhS1XaNso6ZDMO/LSGcHsZ9w4kUAvOOsYfGbNb16gr1vF2H03SxmCJsx9SafnhqlXh8odNYxlQcnZJRjIRongZqlOyw/srWpZg6RWYMiDUKFzwBP4tLLlkpEPrLHpFIm6/C3a74slbsEwIzi6y8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728287457; c=relaxed/simple; bh=YU+dJCCftwBRSn0Jm4GvAvaMzd7qL0FAcShiZZGtkUo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IWMnuGdZlClCRCvzu4yCYgsQCb8y6rMsEZr+Jgkd39MefJ5egD8OiAmOIRRlNUUTML2Rsmq6Ro5zUi6YnEuzQ9AaZFXgT+WlSYqjKdcZWfEYi5wtkpTjmZUNFoKwwtJDCdSBlqLLEFaTu3yVdP345gJwlNn3lr1EQA1bODOqF3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 249B21F8C2; Mon, 7 Oct 2024 07:50:54 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7864D132BD; Mon, 7 Oct 2024 07:50: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 sKuJGt2SA2d6cQAAD6G6ig (envelope-from ); Mon, 07 Oct 2024 07:50: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 , Oscar Salvador Subject: [PATCH v4 4/9] arch/sparc: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Mon, 7 Oct 2024 09:50:32 +0200 Message-ID: <20241007075037.267650-5-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241007075037.267650-1-osalvador@suse.de> References: <20241007075037.267650-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 249B21F8C2 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org 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. 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..fb31bc0c5b48 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_hugepage && (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.1 From nobody Wed Nov 27 23:23:38 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 9FAF818C915 for ; Mon, 7 Oct 2024 07:50:56 +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=1728287458; cv=none; b=QBum5pUcg0roPj/HNPAuds0CsDN9SPq2zKrmpeDTQaO+36Cbb/e+bEwiopLSpTNKhqHDkhISNPRlUxHqPhpJlA+Eocrs/vjE3+rvkIYM9pus2i/jgPpFb69KIUs7lXMI3rLS7UQoVOvpfJjyMRUXVHGp7uiPgVJxUTCXH9SQpFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728287458; c=relaxed/simple; bh=ugFwNQu8pkMdP1/lGatWN+zP4/mqxdaj1MqW9vclcdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jj0JgHXFu9QmJGcdOpJSZkGs+0NpBhkITQjmcwp3cAb8p9LwBonxRh8NCvNKlXM+IeVNCGdwTyvrCRZAr37bScYMd353qlpjPK8b2IkExwiQjEfs3H54Puig28NmXdRK4V+EQO5vms/kq2i0I7JL/Bll3uSc0NaPGORnAq7oTe8= 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=jjDvyrXZ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Is+1Jb6y; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jjDvyrXZ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Is+1Jb6y; 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="jjDvyrXZ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Is+1Jb6y"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jjDvyrXZ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Is+1Jb6y" 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 D800621F3D; Mon, 7 Oct 2024 07:50:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728287454; 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=PljpHijC2le6TjcuL38vbgVuWWQAUhtZMhhfqH3Mudw=; b=jjDvyrXZLGwRxc+rhEwW0WySw7JheFddYHFILlj3PfC7Y/9i690Lm64tsU5bBkQ46gwGVH /dsv1MVTizOb3LlOBcyDKQfcHu4kRD5rDT1/yl/yAbB4QU3WlxbCQ6IFYE+W+S2H6FosTw /JlR9d4fwEU/BV0lM0sI/ruESP2H/HE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728287454; 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=PljpHijC2le6TjcuL38vbgVuWWQAUhtZMhhfqH3Mudw=; b=Is+1Jb6y0qzHi/vp/JmfqJaQQVmgHUXIKRdJY8ZWMyL7a/Axz1IY3IbojyAKX1mGQF0rb1 Q0cv/yTKNl4NPgAg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728287454; 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=PljpHijC2le6TjcuL38vbgVuWWQAUhtZMhhfqH3Mudw=; b=jjDvyrXZLGwRxc+rhEwW0WySw7JheFddYHFILlj3PfC7Y/9i690Lm64tsU5bBkQ46gwGVH /dsv1MVTizOb3LlOBcyDKQfcHu4kRD5rDT1/yl/yAbB4QU3WlxbCQ6IFYE+W+S2H6FosTw /JlR9d4fwEU/BV0lM0sI/ruESP2H/HE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728287454; 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=PljpHijC2le6TjcuL38vbgVuWWQAUhtZMhhfqH3Mudw=; b=Is+1Jb6y0qzHi/vp/JmfqJaQQVmgHUXIKRdJY8ZWMyL7a/Axz1IY3IbojyAKX1mGQF0rb1 Q0cv/yTKNl4NPgAg== 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 380B0132BD; Mon, 7 Oct 2024 07:50: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 GJDPCt6SA2d6cQAAD6G6ig (envelope-from ); Mon, 07 Oct 2024 07:50: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 , Oscar Salvador Subject: [PATCH v4 5/9] arch/powerpc: Teach book3s64 arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Mon, 7 Oct 2024 09:50:33 +0200 Message-ID: <20241007075037.267650-6-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241007075037.267650-1-osalvador@suse.de> References: <20241007075037.267650-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 [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_SEVEN(0.00)[11]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; R_RATELIMIT(0.00)[to_ip_from(RLgqtx3dhxu3ne7bo4p8poxdrt)]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -6.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. 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.1 From nobody Wed Nov 27 23:23:38 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 2B09918CC17 for ; Mon, 7 Oct 2024 07:50:57 +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=1728287460; cv=none; b=R89+GirkE/pq2+GLQZyrhH3MWA8aiqU4+tvniAGhR7MYj3cqAWLvrYRMOiiX3vjOPkkrBsCBW4Q5dyS5KlXD5ixaCqZbKeSa0g0rQWeF3x7EvzZGPQDZxqhJ4hTmb1RJ18ubonZS3sCv4NaogxA3iBY7KiCnhRqtJkVKpS0R8SI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728287460; c=relaxed/simple; bh=twTHEFWL4O8LTfpTRNUTDbAKVndAW03EJ0W3m8j6LVk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CXA7zoGlzNjkyuPIxOM8QrcMz+fgWpLZjccq9HYK1RCwZkOzn82BsCkWvJZwwVePU3jfActTfAds1uH1ebwmxaDUqaXKuOFS7ZmtSTfaJ2RX3GhR4bVKhgWoKK1GZJu02Nt5CvNMraeRYX/elzpkMdnTAb/4ylh7DHX0tcxhr6Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AE63E1FD18; Mon, 7 Oct 2024 07:50:55 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id EB9AC13A55; Mon, 7 Oct 2024 07:50: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 oMimNt6SA2d6cQAAD6G6ig (envelope-from ); Mon, 07 Oct 2024 07:50: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 , Oscar Salvador Subject: [PATCH v4 6/9] mm: Make hugetlb mappings go through mm_get_unmapped_area_vmflags Date: Mon, 7 Oct 2024 09:50:34 +0200 Message-ID: <20241007075037.267650-7-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241007075037.267650-1-osalvador@suse.de> References: <20241007075037.267650-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Spam-Flag: NO X-Rspamd-Queue-Id: AE63E1FD18 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org 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 5cf327337e22..2c5f34e315d2 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.1 From nobody Wed Nov 27 23:23:38 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 299A418CC16 for ; Mon, 7 Oct 2024 07:50:58 +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=1728287460; cv=none; b=ckiu+euEH68Srts23Tx91eGTKuewLuEUjFPCX62slGZ0iI1hkXezrggjHlxma1kiFTF1mBz5wDLDEFwuQHvWQlxcPB3nzF+VV2P8yrkcDUWuSk4jom+XegR6GH7cqzsfHGXUguHhUdUT0mMkywJupTyZ8jy6C0KpKlPdGyorXMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728287460; c=relaxed/simple; bh=rYzhqHYrufnC3aVgmSofKG0w1LZy7myDL4fbdfZPJdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mZVW6Un128k5GyYNFB78fev67YD9+eE4Iu/RSHQG2ix3Vawjm9JCVFniwYumSAa+bM3ewykRh5EKHNAIyUz19sob/0abYQsJr2h8iq9NvkouY/s0zku1bVw2A8ctZLfk1t7fiteqmjn+BVW8eIOCdP8oeZG2sl075K+1/njS3rg= 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=pCbffnnO; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=yeHAAvDP; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=pCbffnnO; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=yeHAAvDP; 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="pCbffnnO"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="yeHAAvDP"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="pCbffnnO"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="yeHAAvDP" 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 6C4F11FD19; Mon, 7 Oct 2024 07:50:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728287456; 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=BOWmyOrUA49R+sE8zSPv6nz1xxCqaVW3asR97FSYM6k=; b=pCbffnnOCFTSKXs4J8B/LuqPT8kBLJXmfQmr2BaL66TTeQXzIaQFcaIMcB+P0aXYWGNf7b I0s6EApTHE6em5yJfPkARghd9VLNHiYpUtW6fVcS2dStoI/Q/7DYIU6WIM4waYcAOIOMaU 5xjEr/0pxAXlTKW40KmyXtC/BseUD5I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728287456; 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=BOWmyOrUA49R+sE8zSPv6nz1xxCqaVW3asR97FSYM6k=; b=yeHAAvDPTOQz2A2QfB9YcyolhAigtelpmsrZWnPsTJ/2buFmBF7G7ZHa0ZsGVx82FFI7C2 xSHcz+noKVsm2/Bw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728287456; 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=BOWmyOrUA49R+sE8zSPv6nz1xxCqaVW3asR97FSYM6k=; b=pCbffnnOCFTSKXs4J8B/LuqPT8kBLJXmfQmr2BaL66TTeQXzIaQFcaIMcB+P0aXYWGNf7b I0s6EApTHE6em5yJfPkARghd9VLNHiYpUtW6fVcS2dStoI/Q/7DYIU6WIM4waYcAOIOMaU 5xjEr/0pxAXlTKW40KmyXtC/BseUD5I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728287456; 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=BOWmyOrUA49R+sE8zSPv6nz1xxCqaVW3asR97FSYM6k=; b=yeHAAvDPTOQz2A2QfB9YcyolhAigtelpmsrZWnPsTJ/2buFmBF7G7ZHa0ZsGVx82FFI7C2 xSHcz+noKVsm2/Bw== 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 BDB4D132BD; Mon, 7 Oct 2024 07:50: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 6M5oK9+SA2d6cQAAD6G6ig (envelope-from ); Mon, 07 Oct 2024 07:50: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 , Oscar Salvador Subject: [PATCH v4 7/9] mm: Drop hugetlb_get_unmapped_area{_*} functions Date: Mon, 7 Oct 2024 09:50:35 +0200 Message-ID: <20241007075037.267650-8-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241007075037.267650-1-osalvador@suse.de> References: <20241007075037.267650-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 [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_SEVEN(0.00)[11]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; R_RATELIMIT(0.00)[to_ip_from(RLgqtx3dhxu3ne7bo4p8poxdrt)]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -6.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 2c5f34e315d2..935c0ed3aa1e 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.1 From nobody Wed Nov 27 23:23:38 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 C54BE18D655 for ; Mon, 7 Oct 2024 07:50:58 +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=1728287460; cv=none; b=Gp+mVIPsaxkI1XJX0D6E1BjsyangF1b62XuK3tjyE8Q5ZaWqCmf/VXPzRhj/JCeC80GgVvOtuwkoASNmDANEDHdsG8gxdXuY/e0CrRNtcZZxyqzycYXIWMLpwmR5RLZMVpn4cDbbCHR4lid4vdZYV5pKW2WsMz3hdMPCkPmFTGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728287460; c=relaxed/simple; bh=jpxy8c8KxUS5EMqXc3mRTdwNa7YtoT/tfQXcDMxAmZU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CTtOvrv4ldVNlzHC7HBZJaa5K49WBrQ8f1TtGdObj4lRT5fFLQ53YQwhS/FbEYV7p4Nfsly3z7hWGZ+GPp7gQxdQTZ0bVofwZlhQFZ7x8kzt8E71UdQim3iDc7rSd+2J7SQ4OY6EqID/eL4yJAtTGHz0O64Nc7zbsRZhRtc/Ni4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2D19F1FD1A; Mon, 7 Oct 2024 07:50:57 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 80B4D13A55; Mon, 7 Oct 2024 07:50:56 +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 uBSPHOCSA2d6cQAAD6G6ig (envelope-from ); Mon, 07 Oct 2024 07:50:56 +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 , Oscar Salvador Subject: [PATCH v4 8/9] arch/s390: Clean up hugetlb definitions Date: Mon, 7 Oct 2024 09:50:36 +0200 Message-ID: <20241007075037.267650-9-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241007075037.267650-1-osalvador@suse.de> References: <20241007075037.267650-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Spam-Flag: NO X-Rspamd-Queue-Id: 2D19F1FD1A X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org 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.1 From nobody Wed Nov 27 23:23:38 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 907F218E044 for ; Mon, 7 Oct 2024 07:50:59 +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=1728287462; cv=none; b=BIAPjq3aQpAUS23p3wjzVJiupysrUD/ZBVipXCY6H3MdiTHz71m2v8d6Yii04SFpBx6YPzKkDzC7XNXBUnAZ1b6mMDbOkdbCcYNvp4i2niyzzOc3VZ4QP++C4IrkUVR2HQ6VGtwB0Q0mPJ28q5kjP7JslszTbSVPJHxA4cZf5MY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728287462; c=relaxed/simple; bh=B573No0OnOnioP2j60fl32mF6Jwq+b29lrlYYnrxxAE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qch9HACL2YjOQA8yi9TKZ6554+vW2N7DRVY27GVmt9rTghofgDko0QTZheShwggdpwk5BWRFhqxnjsU7Z3J2AaMXYlEumfSsd6Iwoc5iYnGvWNNA3tD/R+BuNL3i2WE1pll73yOqnEfdeOiySTFedzleXjOuidjuHOgznv36UT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DF4751FD26; Mon, 7 Oct 2024 07:50:57 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3FF8C132BD; Mon, 7 Oct 2024 07:50:57 +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 cObODOGSA2d6cQAAD6G6ig (envelope-from ); Mon, 07 Oct 2024 07:50:57 +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 , Oscar Salvador Subject: [PATCH v4 9/9] mm: Consolidate common checks in hugetlb_get_unmapped_area Date: Mon, 7 Oct 2024 09:50:37 +0200 Message-ID: <20241007075037.267650-10-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241007075037.267650-1-osalvador@suse.de> References: <20241007075037.267650-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Spam-Flag: NO X-Rspamd-Queue-Id: DF4751FD26 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org 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 | 5 ----- 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(+), 65 deletions(-) diff --git a/arch/loongarch/include/asm/hugetlb.h b/arch/loongarch/include/= asm/hugetlb.h index 5da32c00d483..b837c65a4894 100644 --- a/arch/loongarch/include/asm/hugetlb.h +++ b/arch/loongarch/include/asm/hugetlb.h @@ -16,12 +16,7 @@ static inline int prepare_hugepage_range(struct file *fi= le, unsigned long len) { 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 935c0ed3aa1e..c6191a6118b8 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.1