From mboxrd@z Thu Jan 1 00:00:00 1970 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 3CE731A724C for ; Sat, 6 Jun 2026 03:50:36 +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=1780717837; cv=none; b=vAMj7jZcM0mFOr96yxxjg1eEs5TeA/vAOn2VwEovGwoDVxdYIqfl76nKlRcdl37X5uKC+QUhBq38O8k8HYJ8mZ33FELuwjWxOwhUy8K+mAQXgaQJodggECnBctWimh6Wyr9gHftcVLBSir9DHoI4yk5f0aaIO9Fivt04w0Dwq2Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780717837; c=relaxed/simple; bh=xPQl1xgk4KnDJEvzwWJrdltJ95l76KBvHNy64vdYsh4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=unIBVBFgt6idO3u+/hQTHs7P4rZWIl7MlfGMJK2uaUGPrYMx7UYWZGDnCP+iwJOagR8cp3oT3sjjKWxLVr2Tb9oKIc/TP76s1GvQc7z8unl++9jFkwO21iYpev0XW6UpAya/UJZHHfzmlSaN/dy6067bLXbCdxw6G7U/OyJfviE= 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=huQW4xxB; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=f+E3cFfL; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=huQW4xxB; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=f+E3cFfL; 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="huQW4xxB"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="f+E3cFfL"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="huQW4xxB"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="f+E3cFfL" 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 3B4326B341; Sat, 6 Jun 2026 03:50:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1780717834; 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=gILGC54YllDJCaWwgWBdRVH7kRRphrRc85OeaLBmt3c=; b=huQW4xxBTIAxaRXB6trlcWTcgaUaAaV9BXoNXC+qlzO0FoFjGyfQQWHzIVbiy93Z+plCnf DC96+q3GgcTW2J/zwWxNju9i6sfu/aUpgFJAwnTL962qUUdstWzfq3pTKH7PY8Y/7/Qijy hCPoM9wwt81oTTeAUBV3By1P2t7DkuQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1780717834; 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=gILGC54YllDJCaWwgWBdRVH7kRRphrRc85OeaLBmt3c=; b=f+E3cFfL/kX2m7aCDvhoFJLgaOw6mhwc28JiYQ9htfE6abNmw+UhbGaDSWGtoDhzCVdosz krxUmuMFyIz9vlDQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=huQW4xxB; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=f+E3cFfL DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1780717834; 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=gILGC54YllDJCaWwgWBdRVH7kRRphrRc85OeaLBmt3c=; b=huQW4xxBTIAxaRXB6trlcWTcgaUaAaV9BXoNXC+qlzO0FoFjGyfQQWHzIVbiy93Z+plCnf DC96+q3GgcTW2J/zwWxNju9i6sfu/aUpgFJAwnTL962qUUdstWzfq3pTKH7PY8Y/7/Qijy hCPoM9wwt81oTTeAUBV3By1P2t7DkuQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1780717834; 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=gILGC54YllDJCaWwgWBdRVH7kRRphrRc85OeaLBmt3c=; b=f+E3cFfL/kX2m7aCDvhoFJLgaOw6mhwc28JiYQ9htfE6abNmw+UhbGaDSWGtoDhzCVdosz krxUmuMFyIz9vlDQ== 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 5B7EE779A9; Sat, 6 Jun 2026 03:50:33 +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 KIiMEwmZI2poQwAAD6G6ig (envelope-from ); Sat, 06 Jun 2026 03:50:33 +0000 From: Oscar Salvador To: Andrew Morton Cc: Dave Hansen , Karsten Desler , Muchun Song , David Hildenbrand , Lorenzo Stoakes , Vlastimil Babka , "Liam R . Howlett" , Andreas Larsson , "David S . Miller" , Huacai Chen , Alexander Gordeev , Gerald Schaefer , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Oscar Salvador Subject: [PATCH 1/8] mm,hugetlb: Encode extra padding for aligning directly in hugetlb_get_unmapped_area Date: Sat, 6 Jun 2026 05:49:56 +0200 Message-ID: <20260606035003.529685-2-osalvador@suse.de> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260606035003.529685-1-osalvador@suse.de> References: <20260606035003.529685-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: 8bit X-Spam-Flag: NO X-Rspamd-Action: no action X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCPT_COUNT_TWELVE(0.00)[16]; ARC_NA(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLydsffr49uzh5ztt7hyfaj4uc)]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 3B4326B341 X-Spam-Score: -3.01 Currently, for hugetlb mappings arches query the align_mask needed in order to satisfy allocating a gap for the mapping, as it counts the worst-case scenario which is being off by one page from boundary of the next hugetlb aligned address. Later on, unmapped_area{_topdown} add this 'align_mask' on top of the mapping's length we requested to count for worst-case scenario and get a gap big enough, and then do the proper masking off once we get the address. This means we have to special case hugetlb in quite a few places to first 1) ignore align_offset and 2) return a proper align_mask, but we can just do as THP mappings do and encode the align_mask directly in hugetlb_get_unmapped_area and pass that down to mm_get_unmapped_area_vmflags. Once we get the address, we can properly mask it off before handing it over to userspace. This also allows us to fix a regression on AMD15h family for hugetlb mappings [1]. [1] https://lore.kernel.org/linux-mm/20260527143643.GO31091@soohrt.org/ Fixes: 7bd3f1e1a9ae ("mm: make hugetlb mappings go through mm_get_unmapped_area_vmflags") Reported-by: Karsten Desler Closes: https://lore.kernel.org/linux-mm/20260527143643.GO31091@soohrt.org/ Signed-off-by: Oscar Salvador Acked-by: Dave Hansen --- fs/hugetlbfs/inode.c | 25 ++++++++++++++++++++++++- include/linux/hugetlb.h | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 78d61bf2bd9b..da9bfb5b79f7 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -184,7 +184,30 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr, if (addr) addr0 = ALIGN(addr, huge_page_size(h)); - return mm_get_unmapped_area_vmflags(file, addr0, len, pgoff, flags, 0); + /* + * hugetlb mappings need to be huge page aligned. + * mm_get_unmapped_area_vmflags() only gives back PAGE_SIZE aligned + * areas. + * + * Extend the requested unmapped area for the worse case scenario: + * the address comes back and needs to be aligned up to by one small + * page short of a large page. + */ + len += huge_page_size(h) - PAGE_SIZE; + /* + * pgoff is being used for coloring, but hugetlb mappings need strict + * alignment, so it is always ignored by special casing it down the road. + * Set it to 0 here, so we do not need to be hugetlb-aware later on. + */ + pgoff = 0; + addr0 = mm_get_unmapped_area_vmflags(file, addr0, len, pgoff, flags, 0); + if (IS_ERR_VALUE(addr0)) + return addr0; + + /* Align the address to the next huge_page_size boundary */ + addr0 = ALIGN(addr0, huge_page_size(h)); + + return addr0; } /* diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 5957bc25efa8..924e9a464214 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -1085,7 +1085,7 @@ bool is_raw_hwpoison_page_in_hugepage(struct page *page); static inline unsigned long huge_page_mask_align(struct file *file) { - return PAGE_MASK & ~huge_page_mask(hstate_file(file)); + return 0; } #else /* CONFIG_HUGETLB_PAGE */ -- 2.35.3