From: Sean Christopherson <seanjc@google.com>
To: Robin Murphy <robin.murphy@arm.com>
Cc: Christoph Hellwig <hch@lst.de>,
Marek Szyprowski <m.szyprowski@samsung.com>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
Yan Zhao <yan.y.zhao@intel.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] swiotlb: Rewrite comment explaining why the source is preserved on DMA_FROM_DEVICE
Date: Thu, 19 Oct 2023 16:25:44 -0700 [thread overview]
Message-ID: <ZTG6-GalaSf2lMBq@google.com> (raw)
In-Reply-To: <85e332bf-decf-427c-a2e5-95ab872d4ea6@arm.com>
On Wed, Oct 18, 2023, Robin Murphy wrote:
> On 2023-10-18 18:34, Sean Christopherson wrote:
> > diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> > index 01637677736f..e071415a75dc 100644
> > --- a/kernel/dma/swiotlb.c
> > +++ b/kernel/dma/swiotlb.c
> > @@ -1296,11 +1296,13 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
> > pool->slots[index + i].orig_addr = slot_addr(orig_addr, i);
> > tlb_addr = slot_addr(pool->start, index) + offset;
> > /*
> > - * When dir == DMA_FROM_DEVICE we could omit the copy from the orig
> > - * to the tlb buffer, if we knew for sure the device will
> > - * overwrite the entire current content. But we don't. Thus
> > - * unconditional bounce may prevent leaking swiotlb content (i.e.
> > - * kernel memory) to user-space.
> > + * When the device is writing memory, i.e. dir == DMA_FROM_DEVICE, copy
> > + * the original buffer to the TLB buffer before initiating DMA in order
> > + * to preserve the original's data if the device does a partial write,
> > + * i.e. if the device doesn't overwrite the entire buffer. Preserving
> > + * the original data, even if it's garbage, is necessary to match
> > + * hardware behavior (use of swiotlb is supposed to be transparent) and
>
> Super-nit: I think that last "and" is superfluous (i.e. unwritten memory not
> magically corrupting itself *is* the aforementioned hardware behaviour).
Ah yeah, agreed. How about this?
/*
* When the device is writing memory, i.e. dir == DMA_FROM_DEVICE, copy
* the original buffer to the TLB buffer before initiating DMA in order
* to preserve the original's data if the device does a partial write,
* i.e. if the device doesn't overwrite the entire buffer. Preserving
* 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.
*/
next prev parent reply other threads:[~2023-10-19 23:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-18 17:34 [PATCH] swiotlb: Rewrite comment explaining why the source is preserved on DMA_FROM_DEVICE Sean Christopherson
2023-10-18 17:52 ` Robin Murphy
2023-10-19 23:25 ` Sean Christopherson [this message]
2023-10-20 9:51 ` Robin Murphy
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=ZTG6-GalaSf2lMBq@google.com \
--to=seanjc@google.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=robin.murphy@arm.com \
--cc=torvalds@linux-foundation.org \
--cc=yan.y.zhao@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).