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 DE73B3F413B for ; Mon, 25 May 2026 16:55:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779728155; cv=none; b=et1Wi0n76Ow1523dQnx1LgitG6mgQQcfJ6gRdqPQfza8MYISvTtz6yRIdP6j0/Eu91bdC+7r3IHbr4dLY85RLRqF5fIBV7Eof32NLYIQYC0jALxMQlNQSFV8dXMG5HYgjB6aFjmXk/i16ZYVlO10M9WxB3MI4R2YGyPcukF0Swg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779728155; c=relaxed/simple; bh=BlzaaYDqmNskaOEzBTxtbkzwNhaa2XPVXMyejJDBL7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kqWwgOSEFNhho0ZI/MTp0g6//EdEiyAg235oteh3acaH4hHPVNYFr62Putk1cYrhK59EU/gutIeifWQbKONb4Yw2TfIp1bToTPieXHvGxCW5NdC1kL/SNuPi+Av07oe2KlAilVBRzYy6rTK7AOtsMWGA4xMgCVvL7nYElF9oYp0= 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 EDA686B871; Mon, 25 May 2026 16:55:45 +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 8924759D4B; Mon, 25 May 2026 16:55:45 +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 cPJaHxF/FGrlRAAAD6G6ig (envelope-from ); Mon, 25 May 2026 16:55:45 +0000 From: Oscar Salvador To: Andrew Morton Cc: David Hildenbrand , Michal Hocko , Muchun Song , Vlastimil Babka , Lorenzo Stoakes , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Oscar Salvador Subject: [RFC PATCH v3 2/8] mm: Add {pmd,pud}_huge_lock helper Date: Mon, 25 May 2026 18:55:22 +0200 Message-ID: <20260525165528.184397-3-osalvador@suse.de> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260525165528.184397-1-osalvador@suse.de> References: <20260525165528.184397-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-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Score: -4.00 X-Rspamd-Queue-Id: EDA686B871 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org 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 a171070e15f0..93637890cbeb 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -667,4 +667,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.53.0