All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jia He <justin.he@arm.com>
Cc: Christoph Hellwig <hch@lst.de>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Robin Murphy <robin.murphy@arm.com>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org, nd@arm.com
Subject: Re: [PATCH v3 2/2] dma-mapping: fix dma_addressing_limited() if dma_range_map can't cover all system RAM
Date: Mon, 23 Oct 2023 08:08:45 +0200	[thread overview]
Message-ID: <20231023060845.GA11907@lst.de> (raw)
In-Reply-To: <20231016125254.1875-3-justin.he@arm.com>

> + */
> +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.


      reply	other threads:[~2023-10-23  6:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-16 12:52 [PATCH v3 0/2] fix dma_addressing_limited() if dma_range_map Jia He
2023-10-16 12:52 ` [PATCH v3 1/2] dma-mapping: export dma_addressing_limited() Jia He
2023-10-23  6:09   ` Christoph Hellwig
2023-10-25 15:11     ` Justin He
2023-10-16 12:52 ` [PATCH v3 2/2] dma-mapping: fix dma_addressing_limited() if dma_range_map can't cover all system RAM Jia He
2023-10-23  6:08   ` Christoph Hellwig [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=20231023060845.GA11907@lst.de \
    --to=hch@lst.de \
    --cc=iommu@lists.linux.dev \
    --cc=justin.he@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=nd@arm.com \
    --cc=robin.murphy@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.