From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (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 64D1B3D9DB3 for ; Tue, 14 Jul 2026 12:23:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784031822; cv=none; b=ae0AXOqwmg+b1uhOrWyVHDXcZ2FkZDuigpB49Q8EfmWL2MAP6xxIAQJ8M0222qSXTlMUSFGnqX3pnOckUpjcP636Q1De/Cl11rBydq+sbN/k6Zg+KS3FzZziEKuwNWiU6BMvqi5nlN2Qm5cfku6OkIFpDNe9YtUpTykmmDHb/K8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784031822; c=relaxed/simple; bh=DFDuu4u3kEC19GzAK9vAdZ2AnSTtPZQ33CXAXmTNzxg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lW2AQUYLA7NCJkbw2HE3iugJWjmuwUr3/jmSMAUgT/V7e9jUAcPSHdELABc/Z7wZlEaI86OI9IAEYVLR2qxgFTry1sxCp9a3vbZOjlTwXyFlOKoSWbpYlIboj6e7MBwDP+mAk0MfODEOOLog8VWsb6H9AvXYQZZazjjxmyBdwzg= 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=cFaKBzdo; arc=none smtp.client-ip=209.85.160.177 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="cFaKBzdo" Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-51c2808dbc3so25240671cf.1 for ; Tue, 14 Jul 2026 05:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1784031816; x=1784636616; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=XrBPfnLDD8eQ7eCQ6RhRSXn0CPQXVWcRtTZW3fZ/anA=; b=cFaKBzdo9yl1w7KYnC8lvfszIozjiapNQNWHPK841tYddlBGhI7IWwgMf1clObOBIl OG38iBC2jQT6dm7BTaOO6a/5a9VPFwmcXIWcc8fTvmvNypRMP5+kftwfgtRsO6LPQ7tQ 7KS45Sic8szMRdnWKd66XMq1TqYimgbL9dinQK+Afipb5QI02BNGfhDISvqKZJHTDYc/ roc4Lpb8DARan9pU99l+NH14Qs5VwmQamfr9DDY9v3dz6KK3z7jxFkzzpq4we5HXeSkZ utMY3n6ocl1nS0bscSLBD3DFSXEq1ECwUM9vY1izK1ZEY2TCyqQxAjftUNZDkQ4snm1Q tphw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784031816; x=1784636616; h=in-reply-to:content-disposition:content-type: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 :content-type; bh=XrBPfnLDD8eQ7eCQ6RhRSXn0CPQXVWcRtTZW3fZ/anA=; b=SjgLAipalywYSAlpnntIQvK+YUCSG7ggKmK4AOU3g8iqZBBvh3hpqeJf6vcmkFN3oc +/KWtoU2L4IUxiOq66W3EHUPxiMpb2YZj4nNswdfoa8hG1YCdlcXSzkI1VwtoTolphRz giqnlB9VH1xVpkiutm6uGoJvlcfOfceqwFPsPhA1UC3FAktzPlVVxSpdOy/y65sywMUo MLYzMO0Gbg7hGGGqIMhdDK9I4VaMU9r6osCZYIHymnutJ2R5xZtTnu4KnGivHJC7NZ8p Z5yz1OquADffkYFYU+B4JNa4a0FeKuIhnBxSo/Q9HL2RhE7lcut7IyxMrhiTYV1fG3El 9GGg== X-Forwarded-Encrypted: i=1; AHgh+Rr6855pt0i77kUZC4MFE6ATOg8O1qw0eYbcrG6jFEZnGJhUe3ZILe5rci20jfhLzrcc0r2/h8A4ZjAZmjY=@vger.kernel.org X-Gm-Message-State: AOJu0YwWeTbIYg7WPtnRQMlTcIIPeecT1XkBdvhTQyrRRBcfShvXhdqy awuXyd9o43J78wx7ot9I6MExZgESaXsPY6i/3+FWIm9WLAKBbJ19XFN/THhuqnsTKVY= X-Gm-Gg: AfdE7cmkbP9qlv3g2Jkyfle9lpP5JpmKVrzbdNE102zq0d+4IUcH2MWNwMnW02dxDXk 92HMlIWSF2Qh/7WDAnaedm2fdfW5/qaiIS0IVmeTOM1IbQvDB7C/SBTjqIgdfS/DajFKsilhfBK i7bKJwe/k5ig0Kt5YACNREGVDhmc7cPa3AEUPhdCRZg/dNEzZhe60D1Ev1w7wTLDH+jBtGZp/E1 42VUwG/AuN8WiBG6fDcTO1QMJHRkQ+eqWL/H2r+jrjbEHvws3O2GYdyxF7ruEMwHhQ9KhgBnz1c BRsXKW6RAwS7zgBEBgkSemncxBqRjzDj1ygV2RCDlq8OjkhhvoObRvOFnuCRaGAHGi9+/ssAud5 DWCdJFjDWQgUK1h+otwF+GWJuimmfv2hE8F3ik+meL53+4FL1X1jG+8Lqn4kJ X-Received: by 2002:ac8:578b:0:b0:51a:8c97:9375 with SMTP id d75a77b69052e-51e42494cb4mr15995711cf.61.1784031816150; Tue, 14 Jul 2026 05:23:36 -0700 (PDT) Received: from ziepe.ca ([159.2.72.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-51caacad30asm109896611cf.9.2026.07.14.05.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 05:23:35 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wjcAg-0000000FRbN-3RTk; Tue, 14 Jul 2026 09:23:34 -0300 Date: Tue, 14 Jul 2026 09:23:34 -0300 From: Jason Gunthorpe To: "Aneesh Kumar K.V" Cc: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, Robin Murphy , Marek Szyprowski , Will Deacon , Marc Zyngier , Steven Price , Suzuki K Poulose , Catalin Marinas , Jiri Pirko , Mostafa Saleh , Petr Tesarik , Alexey Kardashevskiy , Dan Williams , Xu Yilun , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , x86@kernel.org, Michael Kelley Subject: Re: [PATCH v7 04/22] dma: free atomic pool pages by physical address Message-ID: <20260714122334.GF3133966@ziepe.ca> References: <20260701054926.825925-1-aneesh.kumar@kernel.org> <20260701054926.825925-5-aneesh.kumar@kernel.org> <20260713181059.GL3133966@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 Tue, Jul 14, 2026 at 09:27:01AM +0530, Aneesh Kumar K.V wrote: > Jason Gunthorpe writes: > > > On Wed, Jul 01, 2026 at 11:19:08AM +0530, Aneesh Kumar K.V (Arm) wrote: > >> dma_direct_alloc_pages() may satisfy atomic allocations from the coherent > >> atomic pools. The pool allocation is keyed by the virtual address stored in > >> the gen_pool, but the pages API returns only the backing struct page. > >> > >> On architectures with CONFIG_DMA_DIRECT_REMAP, atomic pool chunks are added > >> to the gen_pool using their remapped virtual address. > >> dma_direct_free_pages() reconstructs a linear-map address with > >> page_address(page) and passes that to dma_free_from_pool(). That address > >> does not match the gen_pool virtual range, so the pool lookup can fail and > >> the code can fall through to freeing a pool-owned page through the normal > >> page allocator path. > >> > >> Add a page-based pool free helper that looks up the owning pool chunk by > >> physical address, translates it back to the gen_pool virtual address, and > >> frees that address to the pool. Use it from dma_direct_free_pages() while > >> keeping the existing virtual-address helper for coherent allocation frees. > >> > >> Tested-by: Michael Kelley > >> Tested-by: Mostafa Saleh > >> Signed-off-by: Aneesh Kumar K.V (Arm) > >> --- > >> include/linux/dma-map-ops.h | 1 + > >> kernel/dma/direct.c | 4 +-- > >> kernel/dma/pool.c | 54 +++++++++++++++++++++++++++++++++++++ > >> 3 files changed, 57 insertions(+), 2 deletions(-) > > > > This seems pretty suboptimal? > > > > If !CONFIG_DMA_DIRECT_REMAP then page_to_virt() was used to compute > > the genpool's addr so dma_free_from_pool_page() can use the same > > logic, which is how things must be working at all today > > > > The CONFIG_DMA_DIRECT_REMAP scenario does look broken, so I'm > > surprised there isn't a Fixes line on this commit? I don't have an > > opinion on the search, but since alloc_pages() is used there is 8 > > bytes in the struct page that could be used to store the remapped > > vaddr to avoid the search if someday someone wants to improve > > this. Maybe a small comment hinting that direction would be a nice > > addition. > > Something like > > +/* > + * FIXME!! We could avoid this by storing the remapped virtual address in > + * struct page and using that for lookup. > + */ > bool dma_free_from_pool_page(struct device *dev, struct page *page, size_t size) Plus some if (!IS_ENABLED()) that does the direct lookup I would just use : not !! :) Jason