From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 0F31B221FBB for ; Thu, 16 Apr 2026 08:35:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776328520; cv=none; b=iuXU+TaxbB3PP8EgF4DhMP+0z6EZZpP+BK+zq++7DxNfgS8XtJgVx6Mqxtj8IuDaFvurotChS316o+E9osDyYwMHc3ID1i+FDwQan1QDiC1jZXnSgsbe0BjtyMSb+mwbkQ6nWZqyONltpIefiV29d0ALylgm37s39/PvR2Z2/04= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776328520; c=relaxed/simple; bh=QVuygGU1ff2sGxNC8lLE1OKZw6HwO9c7JdEGE3NC6jU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HtqEzcXwqUjtcEW6/KOIYGdPrCduOPQkVeQl7PT2Hi7OKfqKrE7TN4B7eRPU37FzF79QOKkgxd4c0cM0+mpJeYk+M9jY45KyQaD7e0y/65p0kJEpM5/EsI16Z/CVJJUIe/VJHY4ngbsmjIPoCdkK3YmJIvZMAgVMhR3+odA1icw= 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=mlYBmPve; arc=none smtp.client-ip=209.85.128.45 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="mlYBmPve" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4887ec3d8e7so63475e9.0 for ; Thu, 16 Apr 2026 01:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776328517; x=1776933317; 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=Dj+m4YQEsurZA/e5WVnm4SkE+PtyoD5FKV7SijMxVME=; b=mlYBmPveIjur2scnUM3fblB0/9BFlvNfkyOvYb6p7akXN5qp52kaOkVmWD/qQXd2SY r5fhPsGHdC6Ldkyi0/KnX0BZ4xwWl6ePRdPqEsTZYolrB0qVOOpApbM2JdaAxmkzH4CK 02INj60+MTbw+FExYpfwzkqJ0v06//W8sSjhJrmfSZSK22bhpPIJ4ZlscLzotvsQJJrQ C692chsysDRSsBjLbcfP7SsLHeEGs2kCj2NtvOIqmIWF+86BMGIQUR9Nhe6MXb2LW5uW RA0GCKWbhX82YaRRzlllYU+wabkZUV3/zx3B9zlSPOMkoaQUSkxDfAZ/gi2QNsueiEK/ i6Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776328517; x=1776933317; 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=Dj+m4YQEsurZA/e5WVnm4SkE+PtyoD5FKV7SijMxVME=; b=ruxLAK0BB9tS0Ie4cIL65wD3yEXcOG2P2gZ9AZdGA8UT31IX+okzHhuBvw5TdciEwd bp5XF3hvle695wiD+Fl5Z1shkuNrLQAsUImv7zuKFRfgWigvAQGkoveZ/rNqW+3FeJT9 J6t2Eg9vCFLLrT7WBqGzsQOHDqzkhh2+XCJVgv/I9swfqO6uphdFXapE3WERFTcazgfg 1X4kwwYTt9r0SIJ/TnVovgZB3trU1gSB3crO5q9qzrka/kHMxzSJvxoKh0bAk3v+A+X4 tbBDnwlxu3Jw3OC0AlrDeGqZe5iBCd264ENeVxyQkQ3wHH9hzN4/57FaL6QgGxcudXhk argg== X-Forwarded-Encrypted: i=1; AFNElJ9zl7icmfPRUD9lFYIEKvXZ4yvToWh7pqHhN+9wzw/DzYMOd3qN4an4kbu5V+R8NR9X6AsgqU0KuE4F3uE=@vger.kernel.org X-Gm-Message-State: AOJu0Ywglaoa9nlT4GfqlQsbdFwrYTAO2tCSfuPgZfmVXeRKdPXLDR/Y gED71ix/DjmVXK83ILdnVQZx2OD8S3R/5U8swpP2mQsA8UrYA/mzLV1umVRNVnwmUg== X-Gm-Gg: AeBDievP32QYT/l6YFi+pTw0N0NnIpahkpwIYjQs+ATgSgw6x8PGLsCGgj9vuqJyzbA DopVei7qF2whUfxfIB7cGGK04ha0StWqy5/8hg/L2gc3ub3nMe7YpCW8/WnOlXsuGstLosMpwRa x8FIQYH15Gu9QruUnnuF/2l3K68dBudtgvc0Awdd742ZUOEAw5gfWPwmhx6/5aPVBKc7LjMhlCQ vWZ1CZULfcuSwiLy4tO84VsfsLKumVvi/RAamEo6eyzs8S1kz8XyOdNsR1jLbKfoNqsubtYfLbR ea2XfmnXM0/CoRCJE1ZlRpYMi0EcLUAdLi7ibsk60EcVixlJ4xWfiy9nEWeequRnLBm5GDQloMN jGAwkYhZ+RDV+PTblRwrkit+hAqj/boy/OIpQpW0sRyl8r4X95qD33BbtjT+63lTdBqFSwJ55wT Qxf0RPrK3RTA7rHs7HNcGyXauAOFuthC/OFup/ma4PtXoPg0++4FXf/h4sccQ1qxBzKGe9nBbG8 asROrLFGmea9Su2 X-Received: by 2002:a05:600d:640f:10b0:47e:dbb0:fbcd with SMTP id 5b1f17b1804b1-488f4ad95f8mr433145e9.6.1776328517140; Thu, 16 Apr 2026 01:35:17 -0700 (PDT) Received: from google.com (8.181.38.34.bc.googleusercontent.com. [34.38.181.8]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488f581652csm37377315e9.3.2026.04.16.01.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2026 01:35:16 -0700 (PDT) Date: Thu, 16 Apr 2026 08:35:12 +0000 From: Mostafa Saleh To: "Aneesh Kumar K.V" 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, catalin.marinas@arm.com, jiri@resnulli.us, jgg@ziepe.ca Subject: Re: [RFC PATCH v2 2/5] dma-mapping: Use the correct phys_to_dma() for DMA_RESTRICTED_POOL Message-ID: References: <20260330145043.1586623-1-smostafa@google.com> <20260330145043.1586623-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 Thu, Apr 16, 2026 at 12:20:09PM +0530, Aneesh Kumar K.V wrote: > Mostafa Saleh writes: > > > On Mon, Apr 13, 2026 at 11:38:36AM +0530, Aneesh Kumar K.V wrote: > >> Mostafa Saleh writes: > >> > >> > 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. > >> > > >> > Fixes: f4111e39a52a ("swiotlb: Add restricted DMA alloc/free support") > >> > 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); > >> > > >> > >> So what kind of device is this? Is it a trusted device that needs to use > >> swiotlb in unencrypted form?(is that a valid use case?) Can we add additional comment > >> explaining the type of device for which we are allocating the DMA > >> buffer? > > > > That’s used for devices that use restricted-dma pools which are > > currently always decrypted, typically virtio devices that are emulated > > by the untrusted host. > > > > Why would those devices not force unencrypted DMA? Sorry, I may not be > following all the details. The pool itself is decrypted by default, but > the device does not force unencrypted DMA?” > That’s the case at the moment for pKVM guests; that doesn’t use force_dma_unencrypted(), and just rely on swiotlb. When I was trying to enable that, I ended up with the double encryption issue fixed in this series. I believe that swiotlb and force_dma_unencrypted() are completely independent and the code shouldn’t make any assumptions about those, ideally force_dma_unencrypted() is a property of the device in a protected guest and swiotlb is per pool. Thanks, Mostafa > -aneesh