From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (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 14168381AEB for ; Wed, 15 Apr 2026 13:53:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776261209; cv=none; b=qBaawGCJR2nJe/7I8FFw4mi9Q5oG0ZvohTKgCr3FoWQHxt4+mhvmJCLyHiNge0XfDCjS+SQbqRqhpwuMGRY+sNYbZMlrRyIlJQCg8MLja0QSxGAcoVS8m9xuzT7EagR8IO00BnnbgQfMvsd7wPmMGpgRcGvctO8qLAAtcCfFyS0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776261209; c=relaxed/simple; bh=NjZRi6F3kjPLu2FB2YM0Y5WGi5mzKqvcdzvdrqVjHjY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=q2i1RgTn3NyQ9wp+idrJb9gnnv/T2yeGMZR7zVAgV7mFX2T+XW1SG9yDJuUnIhdiZOPR4ZNaa+gxHIFYqLysrzPKOv1KYfVZ2KlaU369Qf3a8HvXxbOrTLnhc9bxU2WJ9PzetAxtvG43f1zaICZDhFaHASc+IsiHIPRXS9kLsc0= 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=EnRJ5wXe; arc=none smtp.client-ip=209.85.222.182 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="EnRJ5wXe" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-8d00cf835b7so823025985a.1 for ; Wed, 15 Apr 2026 06:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1776261207; x=1776866007; 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=1ky21GsOcS92v/0GOErqE5gWkmJLAC8Aqv1PqW+bexE=; b=EnRJ5wXeNkWTJsRY21l65xqcZ6D2DuBC5T5jINyK1kGZWhaR7y1AQl7D7hZLV/F/XV B74wnfAGUHHmhMJh/u2oLilqSYVgJUBN6vww+RAdSfvp8tnNvik53puCG/I1tIHPrH5n LYjGLKqpmDXJOsG4NGdTyHeW0HXGDWB+QhNdrJAcjT79cV6yWXKv06xnP6/nsThxAeUA wyvvW3aEtBSrtpZ4fqxD/pKqH5tMVRDyH9dSsyBGF4WmnhKk/DYHbQ4S8/cnDxL2VFB5 icJj1UcdcmnVT728gJjHN7Rs0vv3a12cfuvxAPBt7RNfclj/9TOcI9n7f70K12XfdJdo dnFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776261207; x=1776866007; 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=1ky21GsOcS92v/0GOErqE5gWkmJLAC8Aqv1PqW+bexE=; b=PVCK9p79nYj/du7civIYl+6kEGxGH6l53IHbecdg/6PLWodN6ttULPPpYAG0UVFPik jMZ+SUflB7tuaV+nUlVRVqvcsesS45kODnClytiLhjPbcTnXUyu8AhdktvD4Vx5YhF3A iWJdnrheZ5o8iMYguo3qR5piCQpS/EH4up47bad70ZxW5BJjmv+4G0+eHGhy0uan86BG oXF943McJimy5tzhCFoe/9wub6Vu629AkK+T721jpYdaF7HqkgmwbXiMPz/TbPyaWsSK 1Z5kSqqkjk66LxzyK04bY9frmT8lVLBB8ccXr4+VB4rDzoF0BWm4cO11UTk/elSvH3Xz 4RRQ== X-Forwarded-Encrypted: i=1; AFNElJ+qRHfSjnQpppWuLFRaC7+Wn8/YqZ9bnMRIKy6REfuY6qRMRxLDVMfGgIgErIq5dPqOZCES6GMRrUJ1nXw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz3VD/x0ECEPN3ELm5ukIZELgUPhEkzTq9YVjtJt/LuIfnoDGcV zLWvXBH72of7okCXi4ZfSU+Qb85XVQZaxbzvb5I9Db02Lhmv9x2ykVpDVShtnfMMKaA= X-Gm-Gg: AeBDieuj7B43WdEMRwqxiIIS0ANtQcdcDzFAGKpv0hUJWrSR2xADKSr3uyQu4AghtFB JLmxiaVZLrcXX6vN8N0l9XTbCMdDdTea+8vGlwLefnYGHrfW8uu1Hg9e6j4Upraav4norQDTy4l hU/kKqecy0wt+BuVls3BdqBVPNNCrQGJkTVls5alPNqWFg3LpZ1b/yJS+BkCldNhYWhv4ybuEAp fQpHGEnURQG+4vuVtJjm+gP8/Jp8JZQZ05GNGGg5/mF0VMm+wxZCy23NPL/o6jzpnCjKDccQd6N V2LB1/+1TFeIWRuPsWyWA9Rs8mfn2UmuMK4Xv/YWHkhqe1QBNYmenHlF2HyvuL/ejETlkfPd2iu Vbq9kmHcvXzVka7C9wYInBr23o3SBd3mf/gn+rs5NbxJ35AM2nt2+nmlhZ37B44rmUmai42cxNP OtPhghFuN7b/p38AwYPNJv9zQOtvTxf6xidyTbXO8jdGR3TLlk9vXf1iE+d8fXY6XqJDRdz47UQ 3deLMAg2t2xot81 X-Received: by 2002:a05:620a:40c9:b0:8cd:94a5:2f32 with SMTP id af79cd13be357-8ddcd8f429dmr3139685385a.27.1776261206957; Wed, 15 Apr 2026 06:53:26 -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-8e4f243a4d4sm117991085a.30.2026.04.15.06.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2026 06:53:26 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wD0gH-00000000HDH-2vuh; Wed, 15 Apr 2026 10:53:25 -0300 Date: Wed, 15 Apr 2026 10:53:25 -0300 From: Jason Gunthorpe To: "Aneesh Kumar K.V" Cc: Mostafa Saleh , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, robin.murphy@arm.com, m.szyprowski@samsung.com, will@kernel.org, maz@kernel.org, suzuki.poulose@arm.com, catalin.marinas@arm.com, jiri@resnulli.us Subject: Re: [RFC PATCH v3 5/5] dma-mapping: Fix memory decryption issues Message-ID: <20260415135325.GH2577880@ziepe.ca> References: <20260408194750.2280873-1-smostafa@google.com> <20260408194750.2280873-6-smostafa@google.com> <20260413124248.GJ3694781@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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Apr 15, 2026 at 06:13:17PM +0530, Aneesh Kumar K.V wrote: > Jason Gunthorpe writes: > > > On Mon, Apr 13, 2026 at 12:49:34PM +0530, Aneesh Kumar K.V wrote: > >> > 2) Using phys_to_dma_unencrypted() is not enlighted about already > >> > decrypted memory and will use the wrong functions for that. > >> > >> Can you split this into a separate patch? I’m finding it difficult to > >> understand what the issue is here. Adding the unencrypted flag multiple > >> times to an address is not a problem in itself. Even so, I still do not > >> follow when we would end up doing that. > > > > I think my comments show how to address it right.. > > > >> phys_to_dma_direct should depend on the device state. > > > > No, it depends on what state the CPU address is, which in some flows > > would have depended on the device state, but by the time you get to > > generating a dma_addr_t it should be based 100% on the current state > > of the phys_addr and nothing else. > > > > Assuming that a T=0 device must be presented unencrypted memory is an > > easy hack but it doesn't work when we get to T=1 devices that can > > handle both encryped and decrypted memory. Then we need to track it > > explicitly. > > > > The only places we we should check the device state for T=0 is at the > > very top when we decide if we force it to swiotlb and inside swiotlb > > when we decide if the allocation should be decrypted. Everything else > > should flow from tracking the phy's state, and be tied into the new > > DMA ATTR UNENCRYPTED. > > > > For things like > > #define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, 0) > > Where do you suggest DMA_ATTR_CC_DECRYPTED be set? dma_map_single() assumes that a is encrypted. If the caller passes an a that it decrypted then it must pass DMA_ATTR_CC_DECRYPTED. It is NOT directly derived from force_dma_unencrypted(). If attr says encrypted and force_dma_unencrypted(), then we have to do swiotlb, we get a new address and we track the decrypted state of the new address along with it. Lower levels always receive an address and a 'is decrypted' flag to make their decisions. The place we check force_dma_unencrypted() is while branching to swiotlb. swiotlb might re-use DMA_ATTR_CC_DECRYPTED, or it might use the dma_page idea, but logically the address and a matching flag flow together through the call chains. Jason