public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: catalin.marinas@arm•com (Catalin Marinas)
To: linux-arm-kernel@lists•infradead.org
Subject: [PATCH] arm64: Correct virt_addr_valid
Date: Thu, 12 Dec 2013 17:57:54 +0000	[thread overview]
Message-ID: <20131212175753.GG3382@arm.com> (raw)
In-Reply-To: <20131211211333.GI4360@n2100.arm.linux.org.uk>

On Wed, Dec 11, 2013 at 09:13:33PM +0000, Russell King - ARM Linux wrote:
> There is actually a concern here, and that's if the v:p translation isn't
> linear, could it return false results?
> 
> According to my grep skills, we have one platform where this is true -
> Realview:
> 
>  * 256MB @ 0x00000000 -> PAGE_OFFSET
>  * 512MB @ 0x20000000 -> PAGE_OFFSET + 0x10000000
>  * 256MB @ 0x80000000 -> PAGE_OFFSET + 0x30000000
> 
> The v:p translation is done via:
> 
>          ((virt) >= PAGE_OFFSET2 ? (virt) - PAGE_OFFSET2 + 0x80000000 : \
>           (virt) >= PAGE_OFFSET1 ? (virt) - PAGE_OFFSET1 + 0x20000000 : \
>           (virt) - PAGE_OFFSET)
> 
> Now the questions - what do values below PAGE_OFFSET give us?  Very
> large numbers, which pfn_valid() should return false for.  What about
> values > PAGE_OFFSET2 + 256MB?  The same.
> 
> So this all _looks_ fine.  Wait a moment, what about highmem?  Let's say
> that the last 256MB is only available as highmem, and let's go back to
> Laura's patch:
> 
> old:
> #define	virt_addr_valid(kaddr)	(((void *)(kaddr) >= (void *)PAGE_OFFSET) && \
> 				 ((void *)(kaddr) < (void *)high_memory))
> new:
> #define	virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
> 
> The former _excludes_ highmem, but the latter _includes_ it.
> 
> virt_addr_valid(v) should only ever return _true_ for the lowmem area,
> never anywhere else - that's part of its point.  It's there to answer
> the question "is this a valid virtual pointer which I can dereference".
> 
> So... We actually need a combination of both of these tests.

Just to avoid any confusion, on arm64 we don't have non-linear v:p
translation as there is plenty of VA space to live with holes. So the
original patch is fine.

On 32-bit, it could be a problem if you have holes in the VA space, so
it needs both high_memory and pfn_valid checks.

-- 
Catalin

  reply	other threads:[~2013-12-12 17:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-11  1:23 [PATCH] arm: Correct virt_addr_valid Laura Abbott
2013-12-11  1:23 ` [PATCH] arm64: " Laura Abbott
2013-12-11 10:44   ` Will Deacon
2013-12-11 11:06     ` Russell King - ARM Linux
2013-12-11 17:26       ` Will Deacon
2013-12-11 21:13         ` Russell King - ARM Linux
2013-12-12 17:57           ` Catalin Marinas [this message]
2013-12-12 18:02             ` Russell King - ARM Linux
2013-12-12 22:09               ` Laura Abbott
2013-12-13 11:57                 ` Catalin Marinas
2013-12-16 18:28                   ` Laura Abbott
2013-12-17 14:19                     ` Catalin Marinas
2013-12-11 17:35     ` Laura Abbott

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=20131212175753.GG3382@arm.com \
    --to=catalin.marinas@arm$(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