From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Shukai Ni <shukai.ni@kuleuven.be>,
Robin Murphy <robin.murphy@arm.com>,
Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>
Cc: Halil Pasic <pasic@linux.ibm.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
Kiryl Shutsemau <kas@kernel.org>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
Elena Reshetova <elena.reshetova@intel.com>,
Carlos Bilbao <carlos.bilbao@kernel.org>,
linux-coco@lists.linux.dev, iommu@lists.linux.dev,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>,
Jason Gunthorpe <jgg@ziepe.ca>,
"Aneesh Kumar K.V" <aneesh.kumar@kernel.org>
Subject: Re: [PATCH] swiotlb: clear read bounce buffers on confidential guests
Date: Tue, 24 Nov 2026 16:17:20 +0100 [thread overview]
Message-ID: <42415609-c784-45d4-a79d-ef3cc5e6c3ef@samsung.com> (raw)
In-Reply-To: <20261123205302.1034348-1-shukai.ni@kuleuven.be>
Hi!
CCed Jason and Aneesh.
On 23.11.2026 21:53, Shukai Ni wrote:
> On confidential guests (AMD SEV, Intel TDX) all device DMA is bounced
> through swiotlb, whose pool is shared with and readable by the untrusted
> host. swiotlb_tbl_map_single() copies the destination buffer's current
> contents into the bounce buffer at map time even for DMA_FROM_DEVICE. For
> a reused read buffer that still holds private data, the host can read
> that data from the bounce buffer before the device overwrites it.
>
> For DMA_FROM_DEVICE into a host-shared pool, zero the bounce buffer
> instead. Zeroing rather than skipping the copy keeps a short read from
> returning a previous transfer's data.
>
> Fixes: ddbd89deb7d3 ("swiotlb: fix info leak with DMA_FROM_DEVICE")
> Cc: stable@vger.kernel.org
> Co-developed-by: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
> Signed-off-by: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
> Signed-off-by: Shukai Ni <shukai.ni@kuleuven.be>
I'm not sure if DMA-mapping or SWIOTLB is the right place for such fixups.
Drivers should be aware that doing DMA from unsecure device to the given
secure page might reveal its content to the host or other parties and
prepare for that (like zeroing that page).
> ---
>
> Notes:
> We are open to discussing a different approach: e.g. clearing the
> residual when read back, scrubbing slots on free, or extending zeroing
> for bidirectional DMA.
>
> drivers/iommu/dma-iommu.c | 3 ++-
> kernel/dma/swiotlb.c | 7 ++++++-
> 2 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index 78742aeba..42e0bfced 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -1187,7 +1187,8 @@ static phys_addr_t iommu_dma_map_swiotlb(struct device *dev, phys_addr_t phys,
> * Untrusted devices should not see padding areas with random leftover
> * kernel data, so zero the pre- and post-padding.
> * swiotlb_tbl_map_single() has initialized the bounce buffer proper to
> - * the contents of the original memory buffer.
> + * the contents of the original memory buffer, or to zero for a read on
> + * a confidential guest.
> */
> if (phys != (phys_addr_t)DMA_MAPPING_ERROR && dev_is_untrusted(dev)) {
> size_t start, virt = (size_t)phys_to_virt(phys);
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 786954bc5..351bc7c54 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -1630,8 +1630,13 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
> * the original data, even if it's garbage, is necessary to match
> * hardware behavior. Use of swiotlb is supposed to be transparent,
> * i.e. swiotlb must not corrupt memory by clobbering unwritten bytes.
> + * Exception: on a confidential guest the bounce buffer is host-shared,
> + * so for a read zero it before sharing.
> */
> - swiotlb_bounce(dev, tlb_addr, mapping_size, DMA_TO_DEVICE, pool);
> + if (dir == DMA_FROM_DEVICE && mem->cc_shared)
> + memset(pool->vaddr + tlb_addr - pool->start, 0, mapping_size);
> + else
> + swiotlb_bounce(dev, tlb_addr, mapping_size, DMA_TO_DEVICE, pool);
> return tlb_addr;
> }
>
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
next prev parent reply other threads:[~2026-11-24 15:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20261123205317eucas1p2f96032281e0f5e9f17acc7ec343acced@eucas1p2.samsung.com>
2026-11-23 20:53 ` [PATCH] swiotlb: clear read bounce buffers on confidential guests Shukai Ni
2026-11-23 22:18 ` Edgecombe, Rick P
2026-11-23 22:56 ` Shukai Ni
2026-11-24 16:13 ` Robin Murphy
2026-11-24 15:17 ` Marek Szyprowski [this message]
2026-11-24 15:36 ` Jason Gunthorpe
2026-11-24 16:11 ` Marek Szyprowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42415609-c784-45d4-a79d-ef3cc5e6c3ef@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=aneesh.kumar@kernel.org \
--cc=carlos.bilbao@kernel.org \
--cc=elena.reshetova@intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=jo.vanbulck@cs.kuleuven.be \
--cc=joro@8bytes.org \
--cc=kas@kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=pasic@linux.ibm.com \
--cc=rick.p.edgecombe@intel.com \
--cc=robin.murphy@arm.com \
--cc=shukai.ni@kuleuven.be \
--cc=stable@vger.kernel.org \
--cc=thomas.lendacky@amd.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox