From: ddutile@redhat•com (Don Dutile)
To: linux-arm-kernel@lists•infradead.org
Subject: [PATCH] Fix for the arm64 kern_addr_valid() function
Date: Tue, 29 Apr 2014 10:34:40 -0400 [thread overview]
Message-ID: <535FB880.6040601@redhat.com> (raw)
In-Reply-To: <20140429142542.GI17007@arm.com>
On 04/29/2014 10:25 AM, Catalin Marinas wrote:
> On Wed, Apr 16, 2014 at 08:51:44AM +0100, Will Deacon wrote:
>> On Tue, Apr 15, 2014 at 06:53:24PM +0100, Dave Anderson wrote:
>>> Fix for the arm64 kern_addr_valid() function to recognize
>>> virtual addresses in the kernel logical memory map. The
>>> function fails as written because it does not check whether
>>> the addresses in that region are mapped at the pmd level to
>>> 2MB or 512MB pages, continues the page table walk to the
>>> pte level, and issues a garbage value to pfn_valid().
>>>
>>> Tested on 4K-page and 64K-page kernels.
>>>
>>> Signed-off-by: Dave Anderson <anderson@redhat•com>
>>> ---
>>> arch/arm64/mm/mmu.c | 3 +++
>>> 1 file changed, 3 insertions(+)
>>>
>>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
>>> index 6b7e895..0a472c4 100644
>>> --- a/arch/arm64/mm/mmu.c
>>> +++ b/arch/arm64/mm/mmu.c
>>> @@ -374,6 +374,9 @@ int kern_addr_valid(unsigned long addr)
>>> if (pmd_none(*pmd))
>>> return 0;
>>>
>>> + if (pmd_sect(*pmd))
>>> + return pfn_valid(pmd_pfn(*pmd));
>>> +
>>> pte = pte_offset_kernel(pmd, addr);
>>> if (pte_none(*pte))
>>> return 0;
>>
>> Whilst this patch looks fine to me, I wonder whether walking the page tables
>> is really necessary for this function? The only user is fs/proc/kcore.c,
>> which basically wants to know if a lowmem address is actually backed by
>> physical memory. Our current implementation of kern_addr_valid will return
>> true even for MMIO mappings,
>
> There is still a pfn_valid() check, so MMIO mappings wouldn't return
> true.
>
>> whilst I think we could actually just do
>> something like:
>>
>>
>> if ((((long)addr) >> VA_BITS) != -1UL)
>> return 0;
>>
>> return pfn_valid(__pa(addr) >> PAGE_SHIFT);
>>
>> Am I missing something here?
>
> __pa(addr) isn't valid for vmalloc/ioremap addresses (which would pass
> the VA_BITS test above).
>
> I would go with Dave's original patch for now. We've discussing change
> the memory map a bit for the kernel at some point in the future with
> PHYS_OFFSET always 0 and the kernel text/data mapped at a different
> address from PAGE_OFFSET (similar to x86_64). If we get there, this
> function would work unmodified.
>
+1.
I would prefer Dave's cleaner solution that is not dependent on
current assumptions.
next prev parent reply other threads:[~2014-04-29 14:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-15 17:53 [PATCH] Fix for the arm64 kern_addr_valid() function Dave Anderson
2014-04-16 7:51 ` Will Deacon
2014-04-16 13:35 ` Dave Anderson
2014-04-29 14:25 ` Catalin Marinas
2014-04-29 14:34 ` Don Dutile [this message]
2014-04-29 15:00 ` Will Deacon
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=535FB880.6040601@redhat.com \
--to=ddutile@redhat$(echo .)com \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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