From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (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 A2298368D67 for ; Fri, 19 Jun 2026 12:08:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781870939; cv=none; b=B26Kvpo3jGFAcV6Je6eAeHlaQheDUY4khk3D8CSBf//7owPmeI8LSqT/67QAKHH+SqvGlX2rX+2dFlu0Idm9MdeyHVR6hb/qMCV5QK7g605KNeT9xYjstNuQkSmOHpU/fPewP8OQDxWvEhe3vMDRwTJjrxmb3hx9T889m1DZewA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781870939; c=relaxed/simple; bh=o8Jc2QAwPN2BwVS4+5xwf4PwyLzosFfb+u23wfEpPgc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ljWr7QL3bS5tqQkE/0E+p9s0p+g+eUINb0irOKelVea5rbdfkQH4tBT6r95PQnOtW3PmXkYWBHGC23VFuMN44qrHvThdNXobxHpdmoK/Nbpa0mRmyKDEOfs4lC8xK+th6hPtFTg8vRz1ODhY7WNNFfh2xsIvNxhjLXHNz22gpfw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=dD/b6oZ/; arc=none smtp.client-ip=209.85.160.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="dD/b6oZ/" Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-519ff1c8b8bso804441cf.3 for ; Fri, 19 Jun 2026 05:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1781870937; x=1782475737; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=KxIMevCtBRecK6uApaEbNoa3x3JR7ePePxN3sqqjDu8=; b=dD/b6oZ/rxNXfPSzWV/lrO8M1cVwecgQmB6nuiJAh5OzC3Ce+1bhR+w5sN61W2Rv2w XBNtRKKKTPIWXzYSG87MzravnQ+RphmbSUTCQHsWZL30ildGp2ZC/mK0IqCE7x8zvnql HO68Fc1dXNZ2dH7yUAQUclmp02C6bFqEBGLNsjfaZ2Mbv/kVUDmPuX9Y4IIE0iEs6PW9 wAnSrwtbq/qlKTcLIgL0XHIG5tIU7XWm8HNDV1QucMFsKERHsdxD7LWsBxCw+khX1b9A SZkLzW8lZNRQOFvGVfU/AObNOwaQ8v1QKknCs41KvSOTk4/m084xCLTk694Q2O07jYui HQuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781870937; x=1782475737; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KxIMevCtBRecK6uApaEbNoa3x3JR7ePePxN3sqqjDu8=; b=YGeV6utn2FjRUgt+M7xfsDMdOvH71i+utHLgCobjXcWZ2vEBw0P+kayZTKAu1YvEQ6 4OryUo6aNgmwSM5LXuCAjoyZcQyBvxSKW3pdnY964QP+Fimli+sbLP5MBh+ONp8/QUTZ 42bYNB8cKgVYFtrBI8iWLUGPcf/Szs3iwvHr9iwkaitdKRvl4oD7NT8KIXe+wTz+rnzA dnJivGCQDJv6H6KgwsSTRS1wq4mDInV8Fn3Ez4fL3l23B89192SIzN+Xe73fgSljD5mv N8sOL35KAtPDOXFMz6tZ8J5TdTbNDyDbePexhBb3k9aYAZ/3cY0FyCI9wq8r76lE9H40 GNqQ== X-Forwarded-Encrypted: i=1; AFNElJ94UXtD8rhyyLzXDDcOGST0bfauPA8Uv1FxwNLp1ZKrttrjoYUtxcMpoLxekwx+seuELxq/nr0tW7bl6kA=@vger.kernel.org X-Gm-Message-State: AOJu0YxFuNGP9id6MC9K2RdBYbHLLdWPKkE3jbkOnN/mc9H+ADQ6NoZT V/TdDnRIBeRuJZwYbQJXTEkDMvHSoUr1QRnvbbnx6SntFmwmptLXNtSz17rcbXR0+LY= X-Gm-Gg: AfdE7cn1+uHVNkHla/Vsgdf1g0B39xmhrDRMYjTT4BTt8VXABk6sIUQDn7GpaEdpjb8 gtO9XHNfdsbmBjDny9Oa5YdLKbn5lWCUm7c3X5q07eB7DV+7W4lbQ8QHaYvWuy2C53A9NiiSo9Z mKakcl9IUXk8z6TAhO/l1oDjuwzRcEzX7X4H3Y2stMZ7n+UVrFaer06LBjYhcgYlR/psj2OruRc 2wphOWRsLMzOeUYnEyTaxv5r6KhNsHg3NP8O4ewaw4u2iUfxO2GTPSCZ8LRn6Xa/oicxwWxosep GZpkSi0h4sphRWYmT0Vie6df4G/bnTJmTvAMgQnja4Dm3f6vFhL122W48wRrGGg67rtZ+jR42aA 7IvdRcHX8KATExjO5+EvJ0Kh00wqfM/QWwYq6WRV0MWGMSgw8kLrR2a/VJ1Vc1puOQsJJxRu4C+ N5iOSHQj2V/1JgWIHvaz+RlXTmxMFEO7uqy5z8PMYevknXQyVrDSCA87PWMVGkCvAIrQw= X-Received: by 2002:a05:622a:4a89:b0:516:e236:1d3e with SMTP id d75a77b69052e-519e4913049mr45445671cf.6.1781870935325; Fri, 19 Jun 2026 05:08:55 -0700 (PDT) Received: from ziepe.ca (crbknf0213w-47-54-130-67.pppoe-dynamic.high-speed.nl.bellaliant.net. [47.54.130.67]) by smtp.gmail.com with ESMTPSA id af79cd13be357-920a142f50asm221056385a.12.2026.06.19.05.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 05:08:54 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1waY1m-00000004SxI-0yoe; Fri, 19 Jun 2026 09:08:54 -0300 Date: Fri, 19 Jun 2026 09:08:54 -0300 From: Jason Gunthorpe To: "Liam R. Howlett" Cc: Rik van Riel , linux-kernel@vger.kernel.org, kernel-team@meta.com, robin.murphy@arm.com, joro@8bytes.org, will@kernel.org, iommu@lists.linux.dev, kyle@mcmartin.ca, Rik van Riel , maple-tree@lists.infradead.org Subject: Re: [PATCH v3 3/3] iova: defer maple tree erase on GFP_ATOMIC failure Message-ID: <20260619120854.GJ231643@ziepe.ca> References: <20260612164852.GL1066031@ziepe.ca> <20260612180303.GO1066031@ziepe.ca> <20260615115633.GQ1066031@ziepe.ca> <20260617180419.GA231643@ziepe.ca> <20260618152451.GE231643@ziepe.ca> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Jun 18, 2026 at 01:27:02PM -0400, Liam R. Howlett wrote: > On 26/06/18 12:24PM, Jason Gunthorpe wrote: > > On Thu, Jun 18, 2026 at 10:50:56AM -0400, Liam R. Howlett wrote: > > > > > > If that's the case it should be documented like this too :) > > > > > > Yeah, very much should add some notes here... but also maybe stop them > > > from doing it by adding this to mas_erase(): > > > > > > if (mt_external_lock(mas->tree)) > > > might_alloc(GFP_KERNEL); > > > > Yeah, and then I'd add a might_alloc() to mtree_erase() as well, it > > can always sleep.. > > mtree_erase() calls mas_erase(), so I think the one should be enough. I was thinking an unconditional one before locking: @@ -5919,6 +5919,8 @@ 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); Since with internal locking this can still sleep, and it has to be called in a sleepable context. The one in mas_erase() is conditional on external locking and is basically asserting the external lock is non-atomic. > > Okay, so to summarize: > > > > - mas_erase, mtree_erase cannot fail with ENOMEM. The check for ENOMEM > > inside should be changed to a WARN_ON to document this. > > Rational: in a GFP_KERNEL context it will sleep forever until it > > gets memory "too small to fail" > > The ENOMEM check inside mas_nomem() is still possible because we try > NOWAIT first, so it is possible that we hit a retry. > > The return from mas_nomem() without allocations should be impossible. > So if (!mas->sheaf && !mas->alloc) should be a WARN_ON_ONCE(). > > I believe this is what you meant anyways? Yeah, probably, or maybe this: if (mas_is_err(mas)) goto out; Can it ever be anything but -ENOMEM within mas_erase()? > So cleaning them up should be handled sooner rather than later. I'm > trying to figure out the best place to do this as I do not like the > retry with the timer idea. I would clean them up when gap searching to allocate a new thing. That is a safe place to fail and ensures the gaps are correct before checking them. Jason