From: Stefano Stabellini <stefano.stabellini@xilinx.com>
To: Christoph Hellwig <hch@lst.de>
Cc: xen-devel@lists.xenproject.org, iommu@lists.linux-foundation.org,
Stefano Stabellini <stefano.stabellini@xilinx.com>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: Re: xen-swiotlb vs phys_to_dma
Date: Fri, 2 Oct 2020 13:21:25 -0700 (PDT) [thread overview]
Message-ID: <alpine.DEB.2.21.2010021313010.10908@sstabellini-ThinkPad-T480s> (raw)
In-Reply-To: <20201002123436.GA30329@lst.de>
On Fri, 2 Oct 2020, Christoph Hellwig wrote:
> Hi Stefano,
>
> I've looked over xen-swiotlb in linux-next, that is with your recent
> changes to take dma offsets into account. One thing that puzzles me
> is that xen_swiotlb_map_page passes virt_to_phys(xen_io_tlb_start) as
> the tbl_dma_addr argument to swiotlb_tbl_map_single, despite the fact
> that the argument is a dma_addr_t and both other callers translate
> from a physical to the dma address. Was this an oversight?
Hi Christoph,
It was not an oversight, it was done on purpose, although maybe I could
have been wrong. There was a brief discussion on this topic here:
https://marc.info/?l=linux-kernel&m=159011972107683&w=2
https://marc.info/?l=linux-kernel&m=159018047129198&w=2
I'll repeat and summarize here for convenience.
swiotlb_init_with_tbl is called by xen_swiotlb_init, passing a virtual
address (xen_io_tlb_start), which gets converted to phys and stored in
io_tlb_start as a physical address at the beginning of swiotlb_init_with_tbl.
Afterwards, xen_swiotlb_map_page calls swiotlb_tbl_map_single. The
second parameter, dma_addr_t tbl_dma_addr, is used to calculate the
right slot in the swiotlb buffer to use, comparing it against
io_tlb_start.
Thus, I think it makes sense for xen_swiotlb_map_page to call
swiotlb_tbl_map_single passing an address meant to be compared with
io_tlb_start, which is __pa(xen_io_tlb_start), so
virt_to_phys(xen_io_tlb_start) seems to be what we want.
However, you are right that it is strange that tbl_dma_addr is a
dma_addr_t, and maybe it shouldn't be? Maybe the tbl_dma_addr parameter
to swiotlb_tbl_map_single should be a phys address instead?
Or it could be swiotlb_init_with_tbl to be wrong and it should take a
dma address to initialize the swiotlb buffer.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-10-03 0:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-02 12:34 xen-swiotlb vs phys_to_dma Christoph Hellwig
2020-10-02 20:21 ` Stefano Stabellini [this message]
2020-10-06 8:26 ` Christoph Hellwig
2020-10-06 20:46 ` Stefano Stabellini
2020-10-07 6:00 ` Christoph Hellwig
2020-10-07 17:15 ` Stefano Stabellini
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=alpine.DEB.2.21.2010021313010.10908@sstabellini-ThinkPad-T480s \
--to=stefano.stabellini@xilinx.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=konrad.wilk@oracle.com \
--cc=xen-devel@lists.xenproject.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;
as well as URLs for NNTP newsgroup(s).