From: Joel Fernandes <joelf@ti.com>
To: Russell King - ARM Linux <linux@arm.linux.org.uk>
Cc: "linux-omap@vger.kernel.org" <linux-omap@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: dma_unmap causing issues with __get_free_pages
Date: Thu, 15 Aug 2013 10:43:37 -0500 [thread overview]
Message-ID: <520CF729.3030704@ti.com> (raw)
In-Reply-To: <20130815115545.GD25647@n2100.arm.linux.org.uk>
Hi Russell,
On 08/15/2013 06:55 AM, Russell King - ARM Linux wrote:
> On Thu, Aug 15, 2013 at 02:35:59AM -0500, Joel Fernandes wrote:
>> Hi,
>>
>> I'm having some trouble with using the dma_map/unmap API.
>>
>> On unmapping a particular page using dma_unmap, it seems that the
>> PG_dcache_clean flag is set in the page->flags. This is set by the
>> following statement in __dma_page_dev_to_cpu function in
>> arch/arm/mm/dma-mapping.c
>> set_bit(PG_dcache_clean, &page->flags);
>>
>> Due to this, on any subsequent page allocations using __get_free_pages,
>> the following BUG gets triggered.
>
> Are you calling dma_unmap() after the page has been freed?
>
>> What is correct way to fix this? Why does the page allocator think its a
>> BAD page descriptor after the unmap?
>
> Well, on free, this is done:
>
> if (page->flags & PAGE_FLAGS_CHECK_AT_PREP)
> page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP;
>
> which clears PG_arch_1. On allocation:
>
> if (unlikely(page_mapcount(page) |
> (page->mapping != NULL) |
> (atomic_read(&page->_count) != 0) |
> (page->flags & PAGE_FLAGS_CHECK_AT_PREP) |
> (mem_cgroup_bad_page_check(page)))) {
> bad_page(page);
> return 1;
> }
>
> As PG_arch_1 is part of the PAGE_FLAGS_CHECK_AT_PREP mask, this means that
> when a page is freed, it has PG_arch_1 cleared. Therefore, if on allocation
> the page now has this bit set, it means that something touched the page
> after it was freed. Quite simply, the page was freed while still being
> in use. That's very bad and needs fixing.
>
Absolutely you nailed it! I was doing alloc, map, free, unmap, changed
this to alloc, map, unmap, free and its working fine now and I learnt a
thing or 2 about page->flags. Thanks!
-Joel
prev parent reply other threads:[~2013-08-15 15:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-15 7:35 dma_unmap causing issues with __get_free_pages Joel Fernandes
2013-08-15 11:55 ` Russell King - ARM Linux
2013-08-15 15:43 ` Joel Fernandes [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=520CF729.3030704@ti.com \
--to=joelf@ti.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).