From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) (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 864E6380FC1 for ; Fri, 12 Jun 2026 16:48:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781282936; cv=none; b=KhvQ3ynUV5e4Hg+tZKh/d5vmX5xMRnD06fUCve/7Tl7qo/768XP6TXl3edvPhEu2DsL3Nk6tRbezBdU21pFrzUY7//noIaOwdtZ7de+chZhI/VeLX/jeSqleCdJHpzHm9bC1NkFx7KCWNcfnh56HlwTVkq6KNwKzcCS9X5CiRMA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781282936; c=relaxed/simple; bh=TkX9O7T8Njp2RpaI6bqoiyhikVlYYnGrUzfuC4IXf24=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rgrSdzYCj3evBiM+LRdE3jEshD2O4iOdRgplw5l/+UpzcgqlEsHZNr6pbajXTXYNoMpeo0QZC6YhIWLVSC3BXqpl49vfDiYcG1R14gE0Xhign9TSY0ltXVP9dtX8GyGzPHAt4OeXwNm3Exck7rOW4hOEecfH042D31HRvotbIPU= 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=hvpmkHi9; arc=none smtp.client-ip=209.85.160.178 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="hvpmkHi9" Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-517dc520840so11195171cf.3 for ; Fri, 12 Jun 2026 09:48:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1781282933; x=1781887733; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=O0KUzhoWSaFOIOwUG9N9tUwmS+pqPKv19ah9sw+5s5Y=; b=hvpmkHi9mm9dsngnmz6ZVptEEkwu+2AFHDzEpBpFsADIEYu+G/NGYOy8nsULM2WOPW dbwiynHX+WZ326hfaOzTZxd8PMBQjyetdnqMAu4qiiNYZ0S8TG2xO9+lWfj9KwiWVEXE oj/pJc9HDdo800rS8Pp4oMoqd7iD3Z180MCRWsRW1BA0qii7WwDIGRE9RN202qkSaj+o uy9y5aoO76teEv8GZS09jkv3wDkEeV5138bm69YZ4fUu7y/HLLTRdfgUffTB3ZFDDdKz SUJQe1u83thUjwB17CLq585jf6Cu6c15fTrw6KFg5mAcXBPVdywshXCXMX2rVF2M9aZv ToEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781282933; x=1781887733; h=in-reply-to:content-transfer-encoding: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=O0KUzhoWSaFOIOwUG9N9tUwmS+pqPKv19ah9sw+5s5Y=; b=I3Mudq5feVneYlqvFyKOYVDtGeiig7MUKs/1Ehsjy6YnSdy2YdtZm8ERO/KeZ62dsI YBKfe8DvBoJvsguuoLmSNme88rRFCtBUii84HeVIkRHwiduGs1V0RfemsWwYmMJAZmKB ysVCCuEm5npNiW6iA9BUy4e6elHLQGP24d2EPjL4WeAQW1wnJ8o5SkvJSSogZOUvfn+m XUOmNmSa2icZ35k6sV3eqR1dbFLvQxmtNx+bA1nYk+Qz4udpNNQQswDclN1KPpWmlQeT +hjPO8qBBTqJU63ahSP/1G5zsdY38Thy8zt5Celt2bjSZeanBNt+ISnEImDNkyg0mWKN w5kw== X-Gm-Message-State: AOJu0YzwAEh0Adz5hXfcMjOQSqJ/EyTXy6ZY/YsFeRPNTnr5P6a17x9q rkbBX1rDeyEmeR5Z2iBnzgKX9XaUBlIbMRr1IK+IOXaYRtGYj91e8vQJb858M8frYM8= X-Gm-Gg: Acq92OG9gkcEzr25jCV/wTSD/PDADFW6pWSMgNg5MMVgVpK8mY082n0EqM50dVpAvmb u8q1BevgA5AFY2zgZuBcAruvUGzjtkwX8ZB3M2PBXN5oJDPtIWbHAa36M+N6Tcxxp0x97oahz9Y WV5WATOO/m91kERagJnqdZZxzD3uqK52X+bhq2qE1LXwNUBsCCIRyfR7OeiDGzxuhayam6ALJWE 2E+NzFDf21Mj/h+sc0hljYPB8RA6/fYwBZlK+IxriV/VlLDoHW1USEt7Dk9vC3ritxzYyrCwvGU lv9FHDW2xCzXZ9gqSNAZs51BWDMTjFsfdV63Xk3BdF11eDSCg6AdtwHXEUZSbRmaS/scAp2KoGt gF63qkdEzFff7JdBsz1bQeyq++bdj4NjyAGerUMDYavrOxKaPlz/IM7UVremiDtAKG8gCghwYaZ EixLlopYhz632tRTU0nweGizvpo9cBwOQLHkEdHn42qfMRYXZkMT3oihDLq0wTY70PQfK4tcdHJ UbxSA== X-Received: by 2002:a05:622a:118f:b0:50f:b13e:b746 with SMTP id d75a77b69052e-519535e7c54mr5807451cf.44.1781282933376; Fri, 12 Jun 2026 09:48:53 -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 d75a77b69052e-517fb7dacdfsm26616601cf.20.2026.06.12.09.48.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2026 09:48:52 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wY53s-000000086Ac-03f2; Fri, 12 Jun 2026 13:48:52 -0300 Date: Fri, 12 Jun 2026 13:48:52 -0300 From: Jason Gunthorpe To: Rik van Riel , "Liam R. Howlett" Cc: 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 Subject: Re: [PATCH v3 3/3] iova: defer maple tree erase on GFP_ATOMIC failure Message-ID: <20260612164852.GL1066031@ziepe.ca> References: <20260603033653.4144138-1-riel@surriel.com> <20260603033653.4144138-4-riel@surriel.com> <20260609130418.GI2764304@ziepe.ca> <61d51d4b5779d80145ceb38e9632a7cc8a79dbec.camel@surriel.com> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <61d51d4b5779d80145ceb38e9632a7cc8a79dbec.camel@surriel.com> On Fri, Jun 12, 2026 at 12:02:55PM -0400, Rik van Riel wrote: > On Tue, 2026-06-09 at 10:04 -0300, Jason Gunthorpe wrote: > > On Tue, Jun 02, 2026 at 11:35:48PM -0400, Rik van Riel wrote: > > > +/* > > > + * Remove an IOVA entry from the maple tree. Returns true on > > > success. > > > + * On failure (maple tree node allocation under GFP_ATOMIC > > > failed), > > > + * returns false — the entry remains in the tree and the caller > > > must > > > + * not free the struct iova. > > > + */ > > > +static bool remove_iova(struct iova_domain *iovad, struct iova > > > *iova) > > >  { > > >   MA_STATE(mas, &iovad->mtree, iova->pfn_lo, iova->pfn_hi); > > >   > > > @@ -165,7 +175,36 @@ static void remove_iova(struct iova_domain > > > *iovad, struct iova *iova) > > >   if (iova->pfn_lo < iovad->dma_32bit_pfn) > > >   iovad->max32_alloc_size = iovad->dma_32bit_pfn; > > >   > > > - mas_store_gfp(&mas, NULL, GFP_ATOMIC); > > > + if (mas_store_gfp(&mas, NULL, GFP_ATOMIC)) > > > + return false; > > > > But why does it use mas_store(NULL) instead of mas_erase()? I thought > > the iova alloc/free has to be pair wise, we don't split allocations? > > > I just looked into this some more, and I was > confused earlier this week. > > The mas_erase() function calls mas_nomem(mas, GFP_KERNEL), > which is not safe to call while holding a spinlock. Oh, the kdoc doesn't say that, it doesn't return any error code if it can't allocate memory, and not a single caller checks for erase failures. I assumed internally it "somehow worked out" even though there are allocations in the callchains.. This is probably a better question for Liam? Can mtree_erase actually fail ENOMEM? Is it safe to call it in an atomic context? Jason