[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20241128-caa8ebcbb224ba75d406a450-pchelkin@ispras.ru>
Date: Thu, 28 Nov 2024 11:50:30 +0300
From: Fedor Pchelkin <pchelkin@...ras.ru>
To: Christoph Hellwig <hch@....de>
Cc: Marek Szyprowski <m.szyprowski@...sung.com>,
Robin Murphy <robin.murphy@....com>, iommu@...ts.linux.dev,
linux-kernel@...r.kernel.org, lvc-project@...uxtesting.org
Subject: Re: [PATCH] dma-debug: fix physical address calculation for struct
dma_debug_entry
On Thu, 28. Nov 04:50, Christoph Hellwig wrote:
> Is it ok for you if I fold in the following cleanup to have a helper
> instead of the duplicate very dense expression?
>
> diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
> index 27ade2bab531..e43c6de2bce4 100644
> --- a/kernel/dma/debug.c
> +++ b/kernel/dma/debug.c
> @@ -1377,6 +1377,18 @@ void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
> }
> }
>
> +static phys_addr_t virt_to_paddr(void *virt)
> +{
> + struct page *page;
> +
> + if (is_vmalloc_addr(virt))
> + page = vmalloc_to_page(virt);
> + else
> + page = virt_to_page(virt);
> +
> + return page_to_phys(page) + offset_in_page(virt);
> +}
> +
> void debug_dma_alloc_coherent(struct device *dev, size_t size,
> dma_addr_t dma_addr, void *virt,
> unsigned long attrs)
> @@ -1399,9 +1411,7 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size,
>
> entry->type = dma_debug_coherent;
> entry->dev = dev;
> - entry->paddr = page_to_phys((is_vmalloc_addr(virt) ?
> - vmalloc_to_page(virt) : virt_to_page(virt))) +
> - offset_in_page(virt);
> + entry->paddr = virt_to_paddr(virt);
> entry->size = size;
> entry->dev_addr = dma_addr;
> entry->direction = DMA_BIDIRECTIONAL;
> @@ -1424,9 +1434,7 @@ void debug_dma_free_coherent(struct device *dev, size_t size,
> if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
> return;
>
> - ref.paddr = page_to_phys((is_vmalloc_addr(virt) ?
> - vmalloc_to_page(virt) : virt_to_page(virt))) +
> - offset_in_page(virt);
> + ref.paddr = virt_to_paddr(virt);
>
> if (unlikely(dma_debug_disabled()))
> return;
No problem. It actually looks more readable.
--
Thanks,
Fedor
Powered by blists - more mailing lists