From: Pan Xinhui <xinhuix.pan@intel.com>
To: linux-kernel@vger.kernel.org
Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
x86@kernel.org, bp@suse.de, jgross@suse.com, mcgrof@suse.com,
decui@microsoft.com, ross.zwisler@linux.intel.com,
sfr@canb.auug.org.au, toshi.kani@hp.com,
"mnipxh@163.com" <mnipxh@163.com>
Subject: [PATCH] x86/mm/pat: let level meaningful even NULL return in, lookup_address_in_pgd
Date: Tue, 14 Jul 2015 20:46:06 +0800 [thread overview]
Message-ID: <55A5048E.3090403@intel.com> (raw)
If pmd or pud is not set, we may set a wrong page mapping level.
Base knowledge:
1) If we have passed pgd_none() check, then current level is at least
PG_LEVEL_1G.
2) If we have passed pud_large() ||!pud_present() check, then current
level is at least PG_LEVEL_2M.
This patch does not change the behavior when a non-NULL value is
returned.
Let's take bask knowledge 2 as an example.
We know *address* belongs to *pud*, however for some reasons *pmd* is
NULL. For example, this address has no physical pages mapped. What we
could benefit from this patch are below:
1) We can walk memory range easier.
If addressA passed to lookup_address(), and NULL returned. We can pass
addressA + level_to_size(level) to lookup_address() in next loop.
...
if (!pte) {
/* level_to_size has not been implemented in upstream*/
address += level_to_size(level);
continue;
}
...
2) keep same behavior because level is set to PG_LEVEL_4K even when pte
is NULL.
So let *level* meaningful even lookup_address_in_pgd return NULL by
moving the assignment before pud/pmd_offset.
Signed-off-by: Pan Xinhui <xinhuix.pan@intel.com>
---
arch/x86/mm/pageattr.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 727158c..a887704 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -336,19 +336,19 @@ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address,
if (pgd_none(*pgd))
return NULL;
+ *level = PG_LEVEL_1G;
pud = pud_offset(pgd, address);
if (pud_none(*pud))
return NULL;
- *level = PG_LEVEL_1G;
if (pud_large(*pud) || !pud_present(*pud))
return (pte_t *)pud;
+ *level = PG_LEVEL_2M;
pmd = pmd_offset(pud, address);
if (pmd_none(*pmd))
return NULL;
- *level = PG_LEVEL_2M;
if (pmd_large(*pmd) || !pmd_present(*pmd))
return (pte_t *)pmd;
--
1.9.1
next reply other threads:[~2015-07-14 12:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-14 12:46 Pan Xinhui [this message]
2015-07-17 14:50 ` [PATCH] x86/mm/pat: let level meaningful even NULL return in, lookup_address_in_pgd Thomas Gleixner
2015-07-20 3:27 ` Pan Xinhui
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=55A5048E.3090403@intel.com \
--to=xinhuix.pan@intel.com \
--cc=bp@suse.de \
--cc=decui@microsoft.com \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@suse.com \
--cc=mingo@redhat.com \
--cc=mnipxh@163.com \
--cc=ross.zwisler@linux.intel.com \
--cc=sfr@canb.auug.org.au \
--cc=tglx@linutronix.de \
--cc=toshi.kani@hp.com \
--cc=x86@kernel.org \
/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.