From: Robin Murphy <robin.murphy@arm.com>
To: Zhaoyang Huang <huangzhaoyang@gmail.com>, Christoph Hellwig <hch@lst.de>
Cc: "zhaoyang.huang" <zhaoyang.huang@unisoc.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
steve.kang@unisoc.com
Subject: Re: [PATCH] kernel: dma: let dma use vmalloc area
Date: Mon, 27 Nov 2023 11:24:33 +0000 [thread overview]
Message-ID: <6415df67-8d5f-44e5-8ca6-57007adf9aae@arm.com> (raw)
In-Reply-To: <CAGWkznFf5hdFRomLXDzoxEKVgiKY--DFbHjRLAMvgvodA01EFw@mail.gmail.com>
On 2023-11-27 8:56 am, Zhaoyang Huang wrote:
> On Mon, Nov 27, 2023 at 3:14 PM Christoph Hellwig <hch@lst.de> wrote:
>>
>> On Mon, Nov 27, 2023 at 11:09:30AM +0800, zhaoyang.huang wrote:
>>> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
>>>
>>> memremap within dma_init_coherent_memory will map the given phys_addr
>>> into vmalloc area if the pa is not found during iterating iomem_resources,
>>> which conflict the rejection of vmalloc area in dma_map_single_attrs.
>>
>> I can't parse this sentence.
> Sorry for the confusion, please find below codes for more information.
> dma_init_coherent_memory
> memremap
> addr = ioremap_wt(offset, size);
> What I mean is addr is a vmalloc address, which is implicitly mapped
> by dma's framework and not be aware of to the driver.
>>
>>> IMO, it is find to let all valid virtual address be valid for DMA as the
>>> user will keep corresponding RAM safe for transfer.
>>
>> No, vmalloc address can't be passed to map_single. You need to pass
>> the page to dma_map_page, and explicitly mange cache consistency
>> using the invalidate_kernel_vmap_range and flush_kernel_vmap_range
>> helpers.
> Please correct me if I am wrong. According to my understanding, cache
> consistency could be solved inside dma_map_page via either
> dma_direct_map_page(swio/arch_sync_dma_for_device) or ops->map_page.
> The original thought of rejecting vmalloc is that this pa is not safe
> as this mapping could go in any time. What I am suggesting is to let
> this kind of va be enrolled.
No, the point is that dma_map_single() uses virt_to_page(), and
virt_to_page() is definitely not valid for vmalloc addresses. At worst
it may blow up in itself with an out-of-bounds dereference; at best it's
going to return a completely bogus page pointer which may then make
dma_map_page() fall over.
Thanks,
Robin.
>
> static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
> size_t size, enum dma_data_direction dir, unsigned long attrs)
> {
> /* DMA must never operate on areas that might be remapped. */
> if (dev_WARN_ONCE(dev, is_vmalloc_addr(ptr),
> "rejecting DMA map of vmalloc memory\n"))
> return DMA_MAPPING_ERROR;
>
>>
>
prev parent reply other threads:[~2023-11-27 11:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-27 3:09 zhaoyang.huang
2023-11-27 3:29 ` Zhaoyang Huang
2023-11-27 7:14 ` Christoph Hellwig
2023-11-27 8:56 ` Zhaoyang Huang
2023-11-27 9:32 ` Christoph Hellwig
2023-11-27 11:24 ` Robin Murphy [this message]
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=6415df67-8d5f-44e5-8ca6-57007adf9aae@arm.com \
--to=robin.murphy@arm.com \
--cc=hch@lst.de \
--cc=huangzhaoyang@gmail.com \
--cc=iommu@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=steve.kang@unisoc.com \
--cc=zhaoyang.huang@unisoc.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
all inboxes | Powered by JetHome®