From mboxrd@z Thu Jan 1 00:00:00 1970 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 E4F223630BC for ; Sun, 12 Apr 2026 17:43:14 +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=1776015796; cv=none; b=FVWiKsCBhNEpZKsmvVfYeuPCLdFP2jEACV6dPP2LJCMjexsEjTYMyyq9m//9wiw4SbiShKY2/2HxJ4OskdmCBtfX3ljeinoibnzeGdRkkhqqMXOCebcJ20AdF2qX1SbXrCE1iaGvHOrd1IAHX/OitgLyd+mAW/CwKWcaMiQnIIE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776015796; c=relaxed/simple; bh=9K/vWN1GNqmBL5aoNyPnKnm/4TeONdhpy+O6bS9nEIs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H7Hbu6dkEwS2/OY5pcz46BSxDUZbhoPSBiQ5fmNUvcrsT6Mnhcj8lq/2yvuetJv0aGfHQd5paPfQ5n/nymANxIBxZQnj0kEzB0s7soTM1jrntuqIjHl29wLlasalyY4w7ERaj9T8EXT+5yXerQgKPN9IgCQ/E0wB2sPqGt6cCzM= 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=AuJPD9CS; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=u45SU55D; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=AuJPD9CS; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=u45SU55D; 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="AuJPD9CS"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="u45SU55D"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="AuJPD9CS"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="u45SU55D" 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 2801C5BD83; Sun, 12 Apr 2026 17:43:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1776015782; 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=bdCTR0tCpwfzVsn5q0RVh1DnLiRFbAD92h9WzaCJKOs=; b=AuJPD9CSFTtu9WM+XaKpk2j0S0KF74+Ghh+JguxmJ8jMocklMU5tZH41YDzhA4/WpzMIsJ lHhPKbMwXSVr9JZ9ALm8Dv5My10g+p4HR3uYdlkOOFRiOPbsfO4RgpdW/6XDnJ3CRYftFd OcIcQ8pw4uWfaY53Huukxd4eEL51kqU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1776015782; 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=bdCTR0tCpwfzVsn5q0RVh1DnLiRFbAD92h9WzaCJKOs=; b=u45SU55D/mS/OVH6cBFwsQVgMBlY/UZZVshfmjx/jDoSoWpVcOsRw/EhFbbjcq5ns/iXER 4UJxH74uH0OqgvBg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1776015782; 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=bdCTR0tCpwfzVsn5q0RVh1DnLiRFbAD92h9WzaCJKOs=; b=AuJPD9CSFTtu9WM+XaKpk2j0S0KF74+Ghh+JguxmJ8jMocklMU5tZH41YDzhA4/WpzMIsJ lHhPKbMwXSVr9JZ9ALm8Dv5My10g+p4HR3uYdlkOOFRiOPbsfO4RgpdW/6XDnJ3CRYftFd OcIcQ8pw4uWfaY53Huukxd4eEL51kqU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1776015782; 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=bdCTR0tCpwfzVsn5q0RVh1DnLiRFbAD92h9WzaCJKOs=; b=u45SU55D/mS/OVH6cBFwsQVgMBlY/UZZVshfmjx/jDoSoWpVcOsRw/EhFbbjcq5ns/iXER 4UJxH74uH0OqgvBg== 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 A3E984AA48; Sun, 12 Apr 2026 17:43:01 +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 4PBPJaXZ22miRQAAD6G6ig (envelope-from ); Sun, 12 Apr 2026 17:43:01 +0000 From: Oscar Salvador To: Andrew Morton Cc: David Hildenbrand , Michal Hocko , Vlastimil Babka , Muchun Song , Lorenzo Stoakes , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Oscar Salvador Subject: [RFC PATCH 2/7] mm: Add {pmd,pud}_huge_lock helper Date: Sun, 12 Apr 2026 19:42:39 +0200 Message-ID: <20260412174244.133715-3-osalvador@suse.de> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260412174244.133715-1-osalvador@suse.de> References: <20260412174244.133715-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-Score: -2.80 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[9]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO HugeTLB and THP use the same lock for pud and pmd, so create two helpers that can be directly used by both of them, as they will be used in the generic pagewalkers. Signed-off-by: Oscar Salvador --- include/linux/mm_inline.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index fa2d6ba811b5..3ac77b50e91f 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -655,4 +655,36 @@ static inline size_t num_pages_contiguous(struct page **pages, size_t nr_pages) return i; } +static inline spinlock_t *pmd_huge_lock(pmd_t *pmd, struct vm_area_struct *vma) +{ + spinlock_t *ptl; + + if (pmd_present(*pmd) || !pmd_none(*pmd)) { + ptl = pmd_lock(vma->vm_mm, pmd); + if (pmd_present(*pmd) && pmd_leaf(*pmd)) + return ptl; + else if (!pmd_present(*pmd) && !pmd_none(*pmd)) + return ptl; + spin_unlock(ptl); + } + + return NULL; +} + +static inline spinlock_t *pud_huge_lock(pud_t *pud, struct vm_area_struct *vma) +{ + spinlock_t *ptl; + + if (pud_present(*pud) || !pud_none(*pud)) { + ptl = pud_lock(vma->vm_mm, pud); + if (pud_present(*pud) && pud_leaf(*pud)) + return ptl; + else if (!pud_present(*pud) && !pud_none(*pud)) + return ptl; + spin_unlock(ptl); + } + + return NULL; +} + #endif -- 2.35.3