Re: [PATCH v3 2/2] dma-mapping: fix dma_addressing_limited() if dma_range_map can't cover all system RAM

From: Christoph Hellwig
Date: Mon Oct 23 2023 - 02:08:52 EST


> + */
> +static int check_ram_in_range_map(unsigned long start_pfn,
> + unsigned long nr_pages, void *data)
> +{
> + unsigned long end_pfn = start_pfn + nr_pages;
> + struct device *dev = (struct device *)data;

No need for the cast here.

> + struct bus_dma_region *bdr = NULL;
> + const struct bus_dma_region *m;
> +
> + while (start_pfn < end_pfn) {
> + for (m = dev->dma_range_map; PFN_DOWN(m->size); m++) {
> + unsigned long cpu_start_pfn = PFN_DOWN(m->cpu_start);
> +
> + if (start_pfn >= cpu_start_pfn
> + && start_pfn - cpu_start_pfn < PFN_DOWN(m->size)) {

Linux coding style keeps the && on the previous line.

> + bdr = (struct bus_dma_region *)m;

If you also declared bdr as const this should be able to do away with
the cast.

> bool dma_addressing_limited(struct device *dev)
> {
> - return min_not_zero(dma_get_mask(dev), dev->bus_dma_limit) <
> - dma_get_required_mask(dev);
> + if (min_not_zero(dma_get_mask(dev), dev->bus_dma_limit) <
> + dma_get_required_mask(dev))
> + return true;
> +
> + return !all_ram_in_dma_range_map(dev);

So, all the dma range map thing is really a dma-direct concept. So I
think here in dma_addressing_limited we should just do a:

if (likely(!ops))
return !dma_direct_all_ram_mapped(dev));
return false

with dma_direct_all_ram_mapped move to dma-direct.c.