From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 3A61A3D6CC4 for ; Wed, 11 Mar 2026 12:28:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773232106; cv=none; b=XzoQlDXk//6DoG+Ui51QE55tJ5pAbQHkSqU/6l2xKD8NpQShcDk+cCeOKvvVSRynuMF+pG6yzHfh5399QdsjQW9WwdYS5hC2JfRcsYsIOmtr/qI9WoSzAcAnFfMF7ydNTb3MKjXenp7e65+LusuvLclWpGY4vYnj6/zAOR334ro= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773232106; c=relaxed/simple; bh=DhLAY5LO0/YfI0VhfhrLmhY7xiirkeGZQW0pYY3E/ds=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IZUaYoMc1C1QjgILwSvHvfRLVP2plhJym4USUF2MPzpfR4jKoG8ousnInglQS4VHKUiMPWUXcLYHCbnW/SC3NlwcHgQyEKnZq/bSxWulFMC96xM84vWCxjlDA/AhjiXp/VTmhULxSvJBnp2VBy1KDMmpZIZqGZ4J+rnLeGuXaD4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FYyBigGb; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FYyBigGb" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4852ef20fe8so61315e9.1 for ; Wed, 11 Mar 2026 05:28:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773232104; x=1773836904; 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=Z2mPFpxlHPadjopfqDbZ+cCX20y11ulYzb87JTfKSeg=; b=FYyBigGbpqILTe/3WV3rwbM3W6bz2o7+a2jpIwlcoOergb0KGwssQW9nDdVyUqNG0F S0uCKTMdmdq3alAnbNya8IGQADpbJ1C9ln+A6jPTKz77Jm573nuBQB3+UoifKfg1Mpc4 b2ZrcgxL3Il/Ky3bIhLPGpisE563M7wC3+ZJu++McpK+34pLD49AJuMm403Z/iAgcRnd Gpgs81qDtM+ML4e86vFnDZphikOFWhz1MPlqurvlNh2cRiU2ROsYc+ZKhRZLagnga4JO SZXHbDDBvOLkcilBTBPWlee3TkrpZRcHlYGAT48IGsIDPiDT0UNvS1uIO/9l0SSk3ubT 7kjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773232104; x=1773836904; 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=Z2mPFpxlHPadjopfqDbZ+cCX20y11ulYzb87JTfKSeg=; b=B/dpUsSLUZMWNibVEBpmx8Qg7gy9I2RBSZ3n5KGuj5xL4sVDuyejQGzBVAPSIj7qb+ gyRZvUAnz+UYyiWkpT7VxqU20V0SGViruAcXDBk7nOYDZql7KuwQ3nTDP9z0nd/ThZK/ PDrbfwBW5bokSoHpM8pdS3+lV7vn216PPTIfsvy5yaUGYqRrocJ4stTc5V4HuTrpzWki lotxGfdWOMzL5nR7YnDc3tUHojuveMq73ZvHOxfIHmvhgbIET+9n5w5i4e7XYcg8wv5N 6BsW2mKWYU94xMbAZaoAzeCotJQN2Z8MrYmTK6d4jopxk7s5z1o9ki0fzDQEzjyXGP3s nJTQ== X-Forwarded-Encrypted: i=1; AJvYcCXBrNI5ZJ3RHS0Y4Rtph84vjRjx/41cXtirhxmN2hkBPRKtBgaGYSGfTu40ZErKg9OqzZ2cY5LlkPZv1us=@vger.kernel.org X-Gm-Message-State: AOJu0Yzdr3ifjp1nu4ODI9Crypnj2xzA8I7zI8JNAct+Cm/9Jsa2EJM7 g7N8b8zGEBObYlIEPDeXlBcHYVQXfHYTgtM/kPeenVQannHzwFo41ExTYit+1+ZJDg== X-Gm-Gg: ATEYQzy/dlQ2YKaWabaBFXh5gvdgkz43sRzb0WDx0kVQMMJH5rkkXK5S5Anf8C8elvd 34Z0gZNy9wpDzs7Ldon88w1D9E3oSPfjehLIWwWhaucKe2C48l3z7WVScHC+u/iGFzaA0X3AFjJ ElRDAaa/m7cF7srK1lhcdeo8+oIlKBkxnnDu5pOKXQD1T04OXUG+p/3YK+GYFTpFMFnF2/3TRn3 x0+hd9gFhUWcOaXZelRTho4WQO3Zd2eK6UzuSR0pu8eUBg/BZsv63RPzMes3841bIYGkZmGUCV3 DockqyQ2c8YqmrI6FmqEBsM90OBq/oA0ea7l5CS/IPHXgQ4tXlfR9nOkif8XwMBcY8j5wuLLNmV UBAnV3ptf0PkVNFGfGMCuWcgyOPV6I9bkGjMzkpsDja/hjj2pg4W+Eo0bYJppvwUv2J5QnCLUkT Nmru23lNiyLZdF9mXuIvQVVnOcXB8k36b2aAQUkoGVmj8eKCIEG4D3kJulH71yZ04whVo= X-Received: by 2002:a05:600c:64cc:b0:477:86fd:fb48 with SMTP id 5b1f17b1804b1-4854b0be077mr706795e9.9.1773232103179; Wed, 11 Mar 2026 05:28:23 -0700 (PDT) Received: from google.com (54.95.38.34.bc.googleusercontent.com. [34.38.95.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4854b66e3f8sm47492435e9.14.2026.03.11.05.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 05:28:22 -0700 (PDT) Date: Wed, 11 Mar 2026 12:28:18 +0000 From: Mostafa Saleh To: Catalin Marinas Cc: 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 Subject: Re: [RFC PATCH 2/2] dma-mapping: Use the correct phys_to_dma() for DMA_RESTRICTED_POOL Message-ID: References: <20260305170335.963568-1-smostafa@google.com> <20260305170335.963568-3-smostafa@google.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: On Tue, Mar 10, 2026 at 01:08:00PM +0000, Catalin Marinas wrote: > On Thu, Mar 05, 2026 at 05:03:35PM +0000, Mostafa Saleh wrote: > > As restricted dma pools are always decrypted, in swiotlb.c it uses > > phys_to_dma_unencrypted() for address conversion. > > > > However, in DMA-direct, calls to phys_to_dma_direct() with > > force_dma_unencrypted() returning false, will fallback to > > phys_to_dma() which is inconsistent for memory allocated from > > restricted dma pools. > > > > Signed-off-by: Mostafa Saleh > > --- > > kernel/dma/direct.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > > index 27d804f0473f..1a402bb956d9 100644 > > --- a/kernel/dma/direct.c > > +++ b/kernel/dma/direct.c > > @@ -26,7 +26,7 @@ u64 zone_dma_limit __ro_after_init = DMA_BIT_MASK(24); > > static inline dma_addr_t phys_to_dma_direct(struct device *dev, > > phys_addr_t phys) > > { > > - if (force_dma_unencrypted(dev)) > > + if (force_dma_unencrypted(dev) || is_swiotlb_for_alloc(dev)) > > return phys_to_dma_unencrypted(dev, phys); > > return phys_to_dma(dev, phys); > > } > > I couldn't fully get my head around the DMA API but I think all the > pools and bounce buffers are decrypted and protected guests (or realms > for Arm CCA) should always return true for force_dma_unencrypted(). If > that's the case, the above change wouldn't be necessary. I can see that > arm64 only does this for CCA and not pKVM guests. > Yes, that’s the problem, pKVM relies on SWIOTLB to use decrypted buffers and not force_dma_unencrypted() in DMA-direct. So, at the moment pKVM guests actually call: - phys_to_dma_unencrypted(): From swiotlb code - phys_to_dma(): From Direct-DMA code Which is in-consistent, but only works as the pKVM memory encryption/ decryption is in-place, so there is no address conversion. I was looking into setting force_dma_unencrypted() to true for pKVM, which then resulted in the bug of double-decryption I am trying to solve with patch-1. I think the main problem is that SWIOTLB(restricted DMA) decrypts stuff unconditionally, so we have to treat is_swiotlb_for_alloc() the same way as force_dma_unencrypted(). That is what these 2 patches do, otherwise we teach SWIOTLB code about force_dma_unencrypted(). Thanks, Mostafa > Device assignment is another story that requires reworking those DMA > pools to support encrypted buffers. > > -- > Catalin