[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <23e5b6d8-c5d9-b43f-41cd-9d02d8ec0a7f@xen.org>
Date: Thu, 21 May 2020 09:01:31 +0100
From: Julien Grall <julien@....org>
To: Stefano Stabellini <sstabellini@...nel.org>, jgross@...e.com,
boris.ostrovsky@...cle.com, konrad.wilk@...cle.com
Cc: xen-devel@...ts.xenproject.org, linux-kernel@...r.kernel.org,
Stefano Stabellini <stefano.stabellini@...inx.com>
Subject: Re: [PATCH 01/10] swiotlb-xen: use vmalloc_to_page on vmalloc virt
addresses
Hi,
On 21/05/2020 00:45, Stefano Stabellini wrote:
> From: Boris Ostrovsky <boris.ostrovsky@...cle.com>
>
> Don't just assume that virt_to_page works on all virtual addresses.
> Instead add a is_vmalloc_addr check and use vmalloc_to_page on vmalloc
> virt addresses.
Can you provide an example where swiotlb is used with vmalloc()?
> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@...cle.com>
> Signed-off-by: Stefano Stabellini <stefano.stabellini@...inx.com>
> ---
> drivers/xen/swiotlb-xen.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index b6d27762c6f8..a42129cba36e 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -335,6 +335,7 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
> int order = get_order(size);
> phys_addr_t phys;
> u64 dma_mask = DMA_BIT_MASK(32);
> + struct page *pg;
>
> if (hwdev && hwdev->coherent_dma_mask)
> dma_mask = hwdev->coherent_dma_mask;
> @@ -346,9 +347,11 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
> /* Convert the size to actually allocated. */
> size = 1UL << (order + XEN_PAGE_SHIFT);
>
> + pg = is_vmalloc_addr(vaddr) ? vmalloc_to_page(vaddr) :
> + virt_to_page(vaddr);
Common DMA code seems to protect this check with CONFIG_DMA_REMAP. Is it
something we want to do it here as well? Or is there any other condition
where vmalloc can happen?
> if (!WARN_ON((dev_addr + size - 1 > dma_mask) ||
> range_straddles_page_boundary(phys, size)) &&
> - TestClearPageXenRemapped(virt_to_page(vaddr)))
> + TestClearPageXenRemapped(pg))
> xen_destroy_contiguous_region(phys, order);
>
> xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs);
>
Cheers,
--
Julien Grall
Powered by blists - more mailing lists