From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 621D847CC70 for ; Tue, 30 Jun 2026 19:09:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782846552; cv=none; b=sMLiNdCGUNm4XAaPOdIafwUgMuKqDaE3mHfV9uN44SV6/1cm0ykYA4FM8cp4dn9SsOwtoCQ4UBVRS8BWFIFx3ebmFGdPVcIX+TpGg1TZLP3+fqLwq65sMZX2TIQFJIo1Zc/DzovnaPs3aspp570RMde0tF75g2ghwIqwxy5lYCc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782846552; c=relaxed/simple; bh=p2VKKTFlKw4zuQXCoWDTmE8TT8gQpUBlUaRFcABW//w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rYq5iTNO9NtWMH+dkqOIEKF4k4hFiZIt3hM1k95T1kw3MlB4o5dowmayId3sNm4BQ/vxsDfg4s6HWmRppRZX+kkRgcYyyvUXIZCTIB/8y3hYQFZ/G0UmAvfqcY0Xi+jv072iIq9t21X3HF99Uwk6NpTEz2MdN1Xx9rNOMSrSHN0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=4tLZSjXo; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="4tLZSjXo" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=KDmgxBpe1durDwt0gaYecCUhfDj8JsczELCLT5SFoSk=; b=4tLZSjXoKHf5V87h0xOQ3U5F7e 6BUOeNDg325KevFUnZIY/JAQ6ZtBzfQQyLuWCwjLitSCOYjFHb9aBuHayWbqAoNtkMunv7o+GwUVF xarp21lvOnonMgGlK6PL/Fy/0x6UkY9AdLc/pMZjaugmP5n66Ot9bujX2l7sUE1EGXnHxsh9543Sq Vmzx3ywH4dokQz6GTz6AGsT6zgDlwJiCsk4/M0dtinD4x97nP77Jx8FWlFKMMGh8HTCTOQO35wZuG HevaGVpvg330Xer/JGQBKTPLTwhWBYNVIf9n46CRJp5Ei7FSirfUlu9VbkLOsL/f0sHk23dhWVI9f T5esrqig==; Received: from [38.23.173.23] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wedpW-000000005zJ-2sGV; Tue, 30 Jun 2026 19:09:10 +0000 From: "Liam R. Howlett (Oracle)" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, "Liam R. Howlett (Oracle)" , Jason Gunthorpe , Rik van Riel Subject: [PATCH v2 13/19] maple_tree: Document that erase may use GFP_KERNEL for allocations Date: Tue, 30 Jun 2026 15:08:37 -0400 Message-ID: <20260630190843.3563858-14-liam@infradead.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260630190843.3563858-1-liam@infradead.org> References: <20260630190843.3563858-1-liam@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit State that the mas_erase() and mtree_erase() functions may use GFP_KERNEL on allocation retry. Don't just depend on people reading the documentation by adding a check that will warn of the use. Cc: Jason Gunthorpe Cc: Rik van Riel Signed-off-by: Liam R. Howlett (Oracle) --- lib/maple_tree.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 1bc177bf42f9f..15e8081f61808 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5657,6 +5657,10 @@ EXPORT_SYMBOL_GPL(mas_find_range_rev); * Searches for @mas->index, sets @mas->index and @mas->last to the range and * erases that range. * + * Note that erase requires allocations and will use GFP_KERNEL to do so if + * necessary. If the allocation fails, the internal lock will be dropped to + * retry. + * * Return: the entry that was erased or %NULL, @mas->index and @mas->last are updated. */ void *mas_erase(struct ma_state *mas) @@ -5665,13 +5669,21 @@ void *mas_erase(struct ma_state *mas) unsigned long index = mas->index; MA_WR_STATE(wr_mas, mas, NULL); + /* + * In low memory situations, the allocation is retried with the gfp flag + * GFP_KERNEL. The internal spinlock is dropped in mas_nomem(), however + * the external lock is not dropped. + */ + if (mt_external_lock(mas->tree)) + might_alloc(GFP_KERNEL); + if (!mas_is_active(mas) || !mas_is_start(mas)) mas->status = ma_start; write_retry: entry = mas_state_walk(mas); if (!entry) - return NULL; + goto out; /* Must reset to ensure spanning writes of last slot are detected */ mas_reset(mas); @@ -5682,8 +5694,10 @@ void *mas_erase(struct ma_state *mas) goto write_retry; } - if (mas_is_err(mas)) + if (mas_is_err(mas)) { + entry = NULL; goto out; + } mas_wr_store_entry(&wr_mas); out: @@ -6011,6 +6025,10 @@ EXPORT_SYMBOL(mtree_alloc_rrange); * Erasing is the same as a walk to an entry then a store of a NULL to that * ENTIRE range. In fact, it is implemented as such using the advanced API. * + * Note that erase requires allocations and will use GFP_KERNEL to do so if + * necessary. If the allocation fails, the internal lock will be dropped to + * retry. + * * Return: The entry stored at the @index or %NULL */ void *mtree_erase(struct maple_tree *mt, unsigned long index) @@ -6020,6 +6038,7 @@ void *mtree_erase(struct maple_tree *mt, unsigned long index) MA_STATE(mas, mt, index, index); trace_ma_op(TP_FCT, &mas); + might_alloc(GFP_KERNEL); mtree_lock(mt); entry = mas_erase(&mas); mtree_unlock(mt); -- 2.47.3