From nobody Wed Dec 17 14:02:37 2025 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60AB317BB20 for ; Wed, 10 Jul 2024 10:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608697; cv=none; b=fza1kSCNPUK59vrYr/Ba2c0JK4xhe4HJN1mZWdqBiAQO0rCibXeJ/UeezPFT0uU+Yxi9424PUOvM0pByWM+jM1X0PpObCyjH0aMZISJ4nP6ahCRay5sslVKT1oRdR6E2Jxq5ut0guNrWpm6vuo5JlJ2rdtGVSgR+MuodFCO6stA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720608697; c=relaxed/simple; bh=icWu+biOg5ee4jEVy/sW+uVLSF874SO9q7O3bQu3qPI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ODOs31aduvQODlNQaoGp+5IEjRXFeXTSoWBGL6b4+VttKMQPPzOKuVizsfBpGIN2HUDZmKBK8qxpadq+EhL4xRBvNEpzAPzpdtWcZdRYizAuzKD2rdMg3h7S596xAMuqbZdaY5DdJ+ToqsByXpO61YF/2PB6PVju5aVJlerydYU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C1FB61F82A; Wed, 10 Jul 2024 10:51:27 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A45BA1369A; Wed, 10 Jul 2024 10:51:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GFhyIq5njmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:26 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , David Hildenbrand , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [RFC PATCH 4/8] arch/sparc: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Wed, 10 Jul 2024 12:50:38 +0200 Message-ID: <20240710105042.30165-5-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240710105042.30165-1-osalvador@suse.de> References: <20240710105042.30165-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Flag: NO X-Spam-Score: -4.00 X-Spam-Level: X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: C1FB61F82A X-Rspamd-Action: no action X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org Content-Type: text/plain; charset="utf-8" We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area{_topdown} to handle those. sparc specific hugetlb function does not set info.align_offset, and does not care about adjusting the align_mask for MAP_SHARED cases, so the same here for compatibility. Signed-off-by: Oscar Salvador --- arch/sparc/kernel/sys_sparc_32.c | 16 ++++++++++---- arch/sparc/kernel/sys_sparc_64.c | 36 +++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc= _32.c index 08a19727795c..fc33ac48ed28 100644 --- a/arch/sparc/kernel/sys_sparc_32.c +++ b/arch/sparc/kernel/sys_sparc_32.c @@ -42,12 +42,16 @@ SYSCALL_DEFINE0(getpagesize) unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr= , unsigned long len, unsigned long pgoff, unsigned long flags) { struct vm_unmapped_area_info info =3D {}; + bool file_hugepage =3D false; + + if (filp && is_file_hugepages(filp)) + file_hugepage =3D true; =20 if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -62,9 +66,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, = unsigned long addr, unsi info.length =3D len; info.low_limit =3D addr; info.high_limit =3D TASK_SIZE; - info.align_mask =3D (flags & MAP_SHARED) ? - (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset =3D pgoff << PAGE_SHIFT; + if (!file_hugepage) { + info.align_mask =3D (flags & MAP_SHARED) ? + (PAGE_MASK & (SHMLBA - 1)) : 0; + info.align_offset =3D pgoff << PAGE_SHIFT; + } else { + info.align_mask =3D huge_page_mask_align(filp); + } return vm_unmapped_area(&info); } =20 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc= _64.c index d9c3b34ca744..81d8f5467dd8 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c @@ -87,6 +87,16 @@ static inline unsigned long COLOR_ALIGN(unsigned long ad= dr, return base + off; } =20 +static unsigned long get_align_mask(struct file *filp, unsigned long flags) +{ + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); + if (filp || (flags & MAP_SHARED)) + return PAGE_MASK & (SHMLBA - 1); + + return 0; +} + unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr= , unsigned long len, unsigned long pgoff, unsigned long flags) { struct mm_struct *mm =3D current->mm; @@ -94,12 +104,16 @@ unsigned long arch_get_unmapped_area(struct file *filp= , unsigned long addr, unsi unsigned long task_size =3D TASK_SIZE; int do_color_align; struct vm_unmapped_area_info info =3D {}; + bool file_hugepage =3D false; + + if (filp && is_file_hugepages(filp)) + file_hugepage =3D true; =20 if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -111,7 +125,7 @@ unsigned long arch_get_unmapped_area(struct file *filp,= unsigned long addr, unsi return -ENOMEM; =20 do_color_align =3D 0; - if (filp || (flags & MAP_SHARED)) + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align =3D 1; =20 if (addr) { @@ -129,8 +143,9 @@ unsigned long arch_get_unmapped_area(struct file *filp,= unsigned long addr, unsi info.length =3D len; info.low_limit =3D TASK_UNMAPPED_BASE; info.high_limit =3D min(task_size, VA_EXCLUDE_START); - info.align_mask =3D do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset =3D pgoff << PAGE_SHIFT; + info.align_mask =3D get_align_mask(filp, flags); + if (!file_hugepage) + info.align_offset =3D pgoff << PAGE_SHIFT; addr =3D vm_unmapped_area(&info); =20 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) { @@ -154,15 +169,19 @@ arch_get_unmapped_area_topdown(struct file *filp, con= st unsigned long addr0, unsigned long addr =3D addr0; int do_color_align; struct vm_unmapped_area_info info =3D {}; + bool file_hugepage =3D false =20 /* This should only ever run for 32-bit processes. */ BUG_ON(!test_thread_flag(TIF_32BIT)); =20 + if (filp && is_file_hugepages(filp)) + file_hugepage =3D true; + if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -172,7 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const= unsigned long addr0, return -ENOMEM; =20 do_color_align =3D 0; - if (filp || (flags & MAP_SHARED)) + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align =3D 1; =20 /* requesting a specific address */ @@ -192,8 +211,9 @@ arch_get_unmapped_area_topdown(struct file *filp, const= unsigned long addr0, info.length =3D len; info.low_limit =3D PAGE_SIZE; info.high_limit =3D mm->mmap_base; - info.align_mask =3D do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset =3D pgoff << PAGE_SHIFT; + info.align_mask =3D get_align_mask(filp, flags); + if (!file_hugepage) + info.align_offset =3D pgoff << PAGE_SHIFT; addr =3D vm_unmapped_area(&info); =20 /* --=20 2.45.2