From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 4A903346E74 for ; Wed, 10 Jun 2026 16:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781109720; cv=none; b=LRjiTMl+AfjuiHY5mphz3pV1gy0PkHa/4imeI6ObfUPZk06YPLmt73+jXSoVn7YK5DoEyT7Y64wiXXuWs2dfMIBn3OUNVHxYgL5yWQlBGQbw9u9WJXKUxU425P5uPt3vpeeqbRyp+xhtbkvdqt4z5xd3BwzNKCQOl7espuPoLHs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781109720; c=relaxed/simple; bh=aoQpijLFpdT37b0Bpmvd//AN2Bj/cbJFhcJiveomuZs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=R1/6CIm47MpkRnpPJiYu+4SY4zyd1UkL++QP7RanKrmorhYk33zcT6xae90szLePOzMT+sx90h4n2gg3zO2V32LM2Mr2fZfrLSMsTjOdUd8qLy/yaa3BRLM1dvJh60tEsOVX3Hhx5fVQMlCySuxIvY1rZXWTMy2qYpoW/Lu0dco= 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=ePgZUVaw; arc=none smtp.client-ip=209.85.222.169 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="ePgZUVaw" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-91563382bcfso798573985a.0 for ; Wed, 10 Jun 2026 09:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1781109715; x=1781714515; 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=DeYS8psnLhx+0nTbu07Q/N5cf93jt28LjVA9fcxz2cA=; b=ePgZUVawYPbsrSBAs1+ufW/++SlkIwy9fb4yUF71wgYO+1AsAIgKBUk56YtYGkcB+l dp1zbb2FS1RDOGyIIr0P6YA6+joWGD3iaKIgaS5ef6m6gszeds4O9Vo4IP8Cnn7Jj+6t xCaMYX6UGj0hmLye1jAgp1FmLnOKYB9XFUiN/YOSN8purqtrC3W03JSVCbo58Hne9c11 mC5nspB211YrW3azqWMva1DIkHa9Pc2btZcQWzOII/HULAfWlbAsOcovwQo7xeEocfM2 pyY69FUbp4uY9rkbiFUVVYg29BeuEEmBurv0OTWrvZ/cCgs7O9KsypecEs66/emhiF5f AXcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781109715; x=1781714515; 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=DeYS8psnLhx+0nTbu07Q/N5cf93jt28LjVA9fcxz2cA=; b=p7MzdPfibnpk+gsAlRQyiX3AJVR6iTnfOU2BJTJXbO0UKjDooXohPBPz0czz0r0SB8 4c5OPdUbavlVRxDCBASlg4gFpOvCda6jE/mY4cnSuh26/y2fAhubLNjZMhSUeKo0nWY1 bzSgtGDJVtxAS3vaaMJcxy8Q1B3OJJCOEbOMA74dtX0W7tsZSYtudplkiUTU3GGKoU9M 1jXoF+pXIPMjqSvp8ud6PZEk+cr7ajgQwiUA1RatDhcPKfBgSP2cLTMD27fHwS7vkOOh pOUux17+UBsWQvzPU3p4VkYzbJt9/hGuZpnjIVmhr6on7a1LVKPI/23JOnHkvVWzLuA2 bipA== X-Forwarded-Encrypted: i=1; AFNElJ8OG5nc768gNDit8txkwTsOcHbQc/cskLe97Rxh65DAc5nQ97KnQ/dw0uklP+/o+lQI4PIEY0t3/ZSU2cI=@vger.kernel.org X-Gm-Message-State: AOJu0YwHNErb8PvzDWGrRY9123oYB3Xxy2m//xU4+EX+01NeX7ICwXK/ WuCsnBYpls4TrgEWbV/u1rzRhifyM36fgEeBY4zcztWbH9IjwvO2U4/AwHudoe3INK0= X-Gm-Gg: Acq92OHDziE8uq4GPJu18SPrw9KKBe/vgFLqkyIn4mGm3fHlCS5fu15Utpp9dQHeIkJ 8/KwwDmDyYZ3QNhCT70sQlUHcuXUTmTxLw+5yQyiF/g6w55WiOzlZXL/BcpCN2ENHudDMlE6gR8 S2hf4PlX4lrU3lJHdYNvqJPqAc8lupZdXqUw7OxzymF+pXfbZ1ZMiyqOBEA3Dl4EWv//vCiBHZw r+U3ovphJtuTF9ThkBYXwW4Yen3JErKkP9KBQK238WZMTWw+YI5XG5G4qmqcZs23sFGVbJbwW0H lPhbiHCaVBwajLl9BcdgtFwEyYgA53Ev3KGH4I51XADHl3/ZfeicrtCOcutkpQ3tNWiKZBaf+0I a5DHEaF8XUj6SLCSUB57EZmUJRXgR0gqNceWETgDuKfYf9CUIcitVjhOMbeLOUpybhwxMRGCIAq pR5J25yuEeSyPjgaQH+hFXTrn1M7P2+uWixPP4qzfgd1zIBuBzMvOAycfF2TYDsmvoj+G+ZLBzJ eh/ZgFP0oj2ADUm X-Received: by 2002:a05:620a:a414:20b0:914:afc1:c66d with SMTP id af79cd13be357-915a9c75c96mr3039706285a.11.1781109715064; Wed, 10 Jun 2026 09:41: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-9158a22dbbesm2438570085a.13.2026.06.10.09.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 09:41:54 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wXM01-000000048i4-3DtT; Wed, 10 Jun 2026 13:41:53 -0300 Date: Wed, 10 Jun 2026 13:41:53 -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, Jiri Pirko , Michael Kelley Subject: Re: [PATCH v6 04/20] dma-pool: track decrypted atomic pools and select them via attrs Message-ID: <20260610164153.GQ2764304@ziepe.ca> References: <20260604083959.1265923-1-aneesh.kumar@kernel.org> <20260604083959.1265923-5-aneesh.kumar@kernel.org> <20260609143242.GK2764304@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 Wed, Jun 10, 2026 at 01:37:26PM +0530, Aneesh Kumar K.V wrote: > Jason Gunthorpe writes: > > > On Thu, Jun 04, 2026 at 02:09:43PM +0530, Aneesh Kumar K.V (Arm) wrote: > >> struct page *dma_alloc_from_pool(struct device *dev, size_t size, > >> - void **cpu_addr, gfp_t gfp, > >> + void **cpu_addr, gfp_t gfp, unsigned long attrs, > >> bool (*phys_addr_ok)(struct device *, phys_addr_t, size_t)) > >> { > >> - struct gen_pool *pool = NULL; > >> + struct dma_gen_pool *dma_pool = NULL; > >> struct page *page; > >> bool pool_found = false; > >> > >> - while ((pool = dma_guess_pool(pool, gfp))) { > >> + while ((dma_pool = dma_guess_pool(dma_pool, gfp))) { > >> + > >> + if (dma_pool->unencrypted != !!(attrs & DMA_ATTR_CC_SHARED)) > >> + continue; > > > > I don't think you should be overloading DMA_ATTR_CC_SHARED like this. > > > > /* > > * DMA_ATTR_CC_SHARED is not a caller-visible dma_alloc_*() > > * attribute. The direct allocator uses it internally after it has > > * decided that the backing pages must be shared/decrypted, so the > > * rest of the allocation path can consistently select DMA addresses, > > * choose compatible pools and restore encryption on free. > > */ > > if (attrs & DMA_ATTR_CC_SHARED) > > return NULL; > > > > if (force_dma_unencrypted(dev)) { > > attrs |= DMA_ATTR_CC_SHARED; > > mark_mem_decrypt = true; > > } > > > > It is fine to have a bit inside the attrs that is only used by the > > internal logic, but it needs to have a clearer name > > __DMA_ATTR_REQUIRE_CC_SHARED perhaps. > > > > Are you suggesting adding another attribute in addition to > DMA_ATTR_CC_SHARED? > > Is the idea that __DMA_ATTR_REQUIRE_CC_SHARED would be used in the > allocation path to request a CC_SHARED allocation, while > DMA_ATTR_CC_SHARED would be used in the mapping path to describe the > attribute of the address? Yeah, it is a thought at least Maybe a comment is good enough. I just find it hard to follow when we have this dual usage. Like the code above for dma_pool->unencrypted is completely wrong if it is an "attribute of an address". Easy to cut & paste that into the wrong context. Especially if you move things up higher.. having the alloc set both CC_SHARED and REQUIRE_CC_SHARED or maybe ALLOC_CC_SHARED would make it clearer that the alloc code lives under that callchain Jason