From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Baochen Qiang <quic_bqiang@quicinc.com>,
robin.murphy@arm.com, justin.he@arm.com, hch@lst.de
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dma-mapping: fix missing clear bdr in check_ram_in_range_map()
Date: Wed, 12 Mar 2025 13:48:16 +0100 [thread overview]
Message-ID: <6f6e2eaa-9f56-4400-a555-7264d4596233@samsung.com> (raw)
In-Reply-To: <20250307030350.69144-1-quic_bqiang@quicinc.com>
On 07.03.2025 04:03, Baochen Qiang wrote:
> As discussed in [1], if 'bdr' is set once, it would never get
> cleared, hence 0 is always returned.
>
> Refactor the range check hunk into a new helper dma_find_range(),
> which allows 'bdr' to be cleared in each iteration.
>
> Link: https://lore.kernel.org/all/64931fac-085b-4ff3-9314-84bac2fa9bdb@quicinc.com/ # [1]
> Fixes: a409d9600959 ("dma-mapping: fix dma_addressing_limited() if dma_range_map can't cover all system RAM")
> Suggested-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Baochen Qiang <quic_bqiang@quicinc.com>
Thanks, applied to dma-mapping-fixes branch.
> ---
> kernel/dma/direct.c | 28 ++++++++++++++++++----------
> 1 file changed, 18 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index 5b4e6d3bf7bc..b8fe0b3d0ffb 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -584,6 +584,22 @@ int dma_direct_supported(struct device *dev, u64 mask)
> return mask >= phys_to_dma_unencrypted(dev, min_mask);
> }
>
> +static const struct bus_dma_region *dma_find_range(struct device *dev,
> + unsigned long start_pfn)
> +{
> + const struct bus_dma_region *m;
> +
> + 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))
> + return m;
> + }
> +
> + return NULL;
> +}
> +
> /*
> * To check whether all ram resource ranges are covered by dma range map
> * Returns 0 when further check is needed
> @@ -593,20 +609,12 @@ 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;
> - const struct bus_dma_region *bdr = NULL;
> - const struct bus_dma_region *m;
> struct device *dev = data;
>
> 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);
> + const struct bus_dma_region *bdr;
>
> - if (start_pfn >= cpu_start_pfn &&
> - start_pfn - cpu_start_pfn < PFN_DOWN(m->size)) {
> - bdr = m;
> - break;
> - }
> - }
> + bdr = dma_find_range(dev, start_pfn);
> if (!bdr)
> return 1;
>
>
> base-commit: 7eb172143d5508b4da468ed59ee857c6e5e01da6
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
prev parent reply other threads:[~2025-03-12 12:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20250307030416eucas1p1503a42196fbcb4bbc561ada50683981b@eucas1p1.samsung.com>
2025-03-07 3:03 ` Baochen Qiang
2025-03-12 12:48 ` Marek Szyprowski [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=6f6e2eaa-9f56-4400-a555-7264d4596233@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux.dev \
--cc=justin.he@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=quic_bqiang@quicinc.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 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®