From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (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 254463E2770 for ; Wed, 20 May 2026 13:40:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779284448; cv=none; b=VAiXi+7hkfWEW/FptKNhe0ajhzMhe7fD6d9UZIhsqftCVHrGI5FPD5PHoxYxLC6sSPrQFv6IcQPFgFMWwjtFISQ6RhGyq+Eqq7hY4eNGcOlJDXGKrQsaIltcmJUY2FB/yFj5TtT88WBhJ8zH+TWIcADkqnNNUxKHojNm0xRqkew= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779284448; c=relaxed/simple; bh=gECXMGpw9B7sH8oWBrgJbLY+YztieOR6VxnjmWmVTTU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Yv2sM/LfJMDFj/PXGVuDoEhwSKEYWfkvPDTPxfX5MVDBTFnsKDqNNvbyp51FX5NGq4SxgcnuSUQ64egbWbv+LZwukQinj+b1Faf6Xy/ckesGIe7fy9BMdah6e9+BnZFemzeQg22CDyi1e0pIcM6AzdND1Uf1gFQsiXpV/A2vpqo= 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=GRJry4BV; arc=none smtp.client-ip=209.85.219.52 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="GRJry4BV" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-8b98482b253so79711656d6.1 for ; Wed, 20 May 2026 06:40:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1779284441; x=1779889241; 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=W+SwQbDLFG0Y+rBu9pL52xRO2ueMe5MsHi84X45A//o=; b=GRJry4BVIMcY40woHuF/zrD7rHNKtx9oAQ/gKnuFPXFk4H0K9uHggvOJpVwrb2QgLq lO8c6mvV/ABUv8n4k+SyqZkXJT51g2uremUxRWIAhsCIVKJPTvjSWDdLzl6QV/Ci6Lg0 Fb6Qjiy2xhOUk6wVB3bRW42UMNUQM77n99Ax6D58oUqel5fNZeNRY7awW4RLrg2RpREa cf/JCLEhyoSzGHnKlUNJJrigUIIVdsYwmKhrX8qR6L8BIAHuYMlrVISaB0v0DdiCK9iU uQm5PNMv2eoWVBAFv8s+i/Bt9GdL9IPmuE0+saMojYNmXTYuMVfwq3Ov+51OvHaptyhl l5Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779284441; x=1779889241; 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=W+SwQbDLFG0Y+rBu9pL52xRO2ueMe5MsHi84X45A//o=; b=JNwckx8B0H4PETYlS/8/Dg8kxFXDxpToEH4tKwCn6N2w6xmE8Q+lhJlbQQHR1aBqeX r+2d51H5aB27lymRj54lNcqKW5xCFEv0ARe0IuByRHWosWwsXyxWYBqM1i5ioUSmITWp pjRlfK4xrHZbsJepqNWvClJoxjTOa2Vpdi+Yfm+EIdsSD3BzA/a2iZbZ3uF9anWjV7+g PPTwORFeidzRj6FuhuR026vxPRGiXesAI6BubPS577WHpZsYlADgYLWoMaebC/Ar4Shq HWsCmHr9Q/h7BMZcgYgBpb5KeNu+EG5cPjr8/u0Y29Xxk+tq0iWA0d75NBGJokfwIwCQ ujeA== X-Forwarded-Encrypted: i=1; AFNElJ+imem2cvEy7si3+e0S+GLwGHoBEE8KzuePc60r0GIBCMDRllPjPVusd+Km7rvmDSCXWyWbaGUMLY2pmmo=@vger.kernel.org X-Gm-Message-State: AOJu0YxBUTIsDUwnehds93fUG32ccRSEpmxNPE0l8au/xt6Xup0QXPJM BuatkT83BtwSBx1JpNswEIYQBcb9Q2V9UCpZyXZhGvS5ZyrmF2yN5HtOZhcAVygk2EY= X-Gm-Gg: Acq92OEd6FmcU+R8F79bFoceEsn6ExuE/+ZJjQp/jwnTbwOgtAOlzsZNGP4eLRd9b++ Ebl0NegwJQoONsGhSoJftqTUmMXL+fLAePzv/tr7ljTvEbeG/TGnM2iC8G0oB1IprtQvEfZkEVX pkG40ChECp37q517x7yBEKzV38rEDo/E38F7GL1l8HcLN2aSfLyxOKr7KJgGE3wCGbRZzozzmuG cWAV8xdyEiTSrbPJelKHIr3bOHBjaVHUkR56DTPcrR5cl7af1/J/lYDxg5t8Zd4qfKdIN+g/oQg onhXBCFfWn24OG3va1hmPJGc4+U7gWHfWmyP3qNXMahVqcyZTkQ97cBo/Gyj/S3dguJmYfKlbQj gYNg+inNNKwd2G111GElIBTrryoWfPpTV6USsljJg225sHc0nhBk/V6mDzcHPk0DlzFRE3GTbAA h1cnq/9q8VPVRiIotMEXyY/oWqbSFdaDwqAbBstX3MFPNfDtFpa0Gi8uIywTngbBBj/V+5CT1qN eN6jkjdZQd0Iiau X-Received: by 2002:a05:6214:5c42:b0:8ca:16fd:7297 with SMTP id 6a1803df08f44-8ca16fd752cmr347910676d6.30.1779284440966; Wed, 20 May 2026 06:40:40 -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 6a1803df08f44-8ca360ac735sm122405916d6.19.2026.05.20.06.40.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 06:40:40 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wPhA7-0000000HB8S-389S; Wed, 20 May 2026 10:40:39 -0300 Date: Wed, 20 May 2026 10:40:39 -0300 From: Jason Gunthorpe To: "Aneesh Kumar K.V" Cc: Mostafa Saleh , 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 , 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 Subject: Re: [PATCH v4 04/13] dma: swiotlb: track pool encryption state and honor DMA_ATTR_CC_SHARED Message-ID: <20260520134039.GT7702@ziepe.ca> References: <20260519152741.GM7702@ziepe.ca> <20260519161120.GO7702@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, May 20, 2026 at 09:27:27AM +0530, Aneesh Kumar K.V wrote: > Jason Gunthorpe writes: > > > On Tue, May 19, 2026 at 09:35:30PM +0530, Aneesh Kumar K.V wrote: > >> Yes, that also resulted in simpler and cleaner code. > >> > >> swiotlb_tbl_map_single > >> /* > >> * If the physical address is encrypted but the device requires > >> * decrypted DMA, use a decrypted io_tlb_mem and update the > >> * attributes so the caller knows that a decrypted io_tlb_mem > >> * was used. > >> */ > >> if (!(*attrs & DMA_ATTR_CC_SHARED) && force_dma_unencrypted(dev)) > >> *attrs |= DMA_ATTR_CC_SHARED; > >> > >> if (mem->unencrypted != !!(*attrs & DMA_ATTR_CC_SHARED)) > >> return (phys_addr_t)DMA_MAPPING_ERROR; > > > > Yeah, exactly that is so much clearer now that the mem->unecrypted is > > tied directly. > > > > That logic is reversed though, the incoming ATTR_CC doesn't matter for > > swiotlb, that is just the source of the memcpy. > > > > /* swiotlb pool is incorrect for this device */ > > if (mem->unencrypted != force_dma_unencrypted(dev)) > > return (phys_addr_t)DMA_MAPPING_ERROR; > > > > /* Force attrs to match the kind of memory in the pool */ > > if (mem->unencrypted) > > *attrs |= DMA_ATTR_CC_SHARED; > > else > > *attrs &= ~DMA_ATTR_CC_SHARED; > > > > > > Attrs should be forced to whatever memory swiotlb selected. > > > > But that will not handle a T=1 device that wants to use swiotlb to > bounce unencrypted memory. That is: > > force_dma_unencrypted(dev) == 0 /* T=1 device */ > attrs = DMA_ATTR_CC_SHARED; > > In that case, it should use an unencrypted io_tlb_mem: > mem->unencrypted == 1 No! The DMA_ATTR_CC_SHARED only states the nature of the source memory, the DMA transfer will always happen under T=1 It is perfectly fine to memcpy from shared to private and do a T=1 DMA from the private memory if we have to bounce. Jason