* [PATCH 1/6] x86: fix NX bit handling in change_page_attr
@ 2008-01-25 5:54 Huang, Ying
2008-01-25 7:32 ` Jeremy Fitzhardinge
0 siblings, 1 reply; 5+ messages in thread
From: Huang, Ying @ 2008-01-25 5:54 UTC (permalink / raw)
To: Ingo Molnar, H. Peter Anvin, Thomas Gleixner, Andi Kleen; +Cc: linux-kernel
This patch fixes a bug of change_page_attr/change_page_attr_addr on
Intel i386/x86_64 CPUs. After changing page attribute to be
executable with these functions, the page remains un-executable on
Intel i386/x86_64 CPU. Because on Intel i386/x86_64 CPU, only if the
"NX" bits of all three level page tables are cleared (PAE is enabled),
the corresponding page is executable (refer to section 4.13.2 of Intel
64 and IA-32 Architectures Software Developer's Manual). So, the bug
is fixed through clearing the "NX" bit of PMD when splitting the huge
PMD.
Signed-off-by: Huang Ying <ying.huang@intel.com>
---
arch/x86/mm/pageattr.c | 1 +
1 file changed, 1 insertion(+)
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -124,6 +124,7 @@ static int split_large_page(pte_t *kpte,
/*
* Install the new, split up pagetable:
*/
+ pgprot_val(ref_prot) &= ~_PAGE_NX;
__set_pmd_pte(kpte, address, mk_pte(base, ref_prot));
base = NULL;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/6] x86: fix NX bit handling in change_page_attr
2008-01-25 5:54 [PATCH 1/6] x86: fix NX bit handling in change_page_attr Huang, Ying
@ 2008-01-25 7:32 ` Jeremy Fitzhardinge
2008-01-25 8:46 ` Ingo Molnar
0 siblings, 1 reply; 5+ messages in thread
From: Jeremy Fitzhardinge @ 2008-01-25 7:32 UTC (permalink / raw)
To: Huang, Ying
Cc: Ingo Molnar, H. Peter Anvin, Thomas Gleixner, Andi Kleen,
linux-kernel
Huang, Ying wrote:
> This patch fixes a bug of change_page_attr/change_page_attr_addr on
> Intel i386/x86_64 CPUs. After changing page attribute to be
> executable with these functions, the page remains un-executable on
> Intel i386/x86_64 CPU. Because on Intel i386/x86_64 CPU, only if the
> "NX" bits of all three level page tables are cleared (PAE is enabled),
> the corresponding page is executable (refer to section 4.13.2 of Intel
> 64 and IA-32 Architectures Software Developer's Manual). So, the bug
> is fixed through clearing the "NX" bit of PMD when splitting the huge
> PMD.
>
> Signed-off-by: Huang Ying <ying.huang@intel.com>
>
> ---
> arch/x86/mm/pageattr.c | 1 +
> 1 file changed, 1 insertion(+)
>
> --- a/arch/x86/mm/pageattr.c
> +++ b/arch/x86/mm/pageattr.c
> @@ -124,6 +124,7 @@ static int split_large_page(pte_t *kpte,
> /*
> * Install the new, split up pagetable:
> */
> + pgprot_val(ref_prot) &= ~_PAGE_NX;
>
I don't think its a good idea to treat pgprot_val() as an lvalue - it
precludes it from being turned into an inline function. I know there
are numerous other places which do, but we should avoid making it worse.
J
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 1/6] x86: fix NX bit handling in change_page_attr
2008-01-25 7:32 ` Jeremy Fitzhardinge
@ 2008-01-25 8:46 ` Ingo Molnar
2008-01-25 10:32 ` Ingo Molnar
0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2008-01-25 8:46 UTC (permalink / raw)
To: Jeremy Fitzhardinge
Cc: Huang, Ying, Ingo Molnar, H. Peter Anvin, Thomas Gleixner,
Andi Kleen, linux-kernel
* Jeremy Fitzhardinge <jeremy@goop.org> wrote:
> Huang, Ying wrote:
>> This patch fixes a bug of change_page_attr/change_page_attr_addr on
>> Intel i386/x86_64 CPUs. After changing page attribute to be
>> executable with these functions, the page remains un-executable on
>> Intel i386/x86_64 CPU. Because on Intel i386/x86_64 CPU, only if the
>> "NX" bits of all three level page tables are cleared (PAE is
>> enabled), the corresponding page is executable (refer to section
>> 4.13.2 of Intel 64 and IA-32 Architectures Software Developer's
>> Manual). So, the bug is fixed through clearing the "NX" bit of PMD
>> when splitting the huge PMD.
oops, nice detail!
>> Signed-off-by: Huang Ying <ying.huang@intel.com>
>>
>> ---
>> arch/x86/mm/pageattr.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> --- a/arch/x86/mm/pageattr.c
>> +++ b/arch/x86/mm/pageattr.c
>> @@ -124,6 +124,7 @@ static int split_large_page(pte_t *kpte,
>> /*
>> * Install the new, split up pagetable:
>> */
>> + pgprot_val(ref_prot) &= ~_PAGE_NX;
>>
>
> I don't think its a good idea to treat pgprot_val() as an lvalue - it
> precludes it from being turned into an inline function. I know there
> are numerous other places which do, but we should avoid making it
> worse.
applied it with the following cleanup from Thomas:
static int split_large_page(pte_t *kpte, unsigned long address)
{
- pgprot_t ref_prot = pte_pgprot(pte_clrhuge(*kpte));
+ pgprot_t ref_prot;
...
+ ref_prot = pte_pgprot(pte_mkexec(pte_clrhuge(*kpte)));
i.e. it now goes through all the proper accessors.
Ingo
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 1/6] x86: fix NX bit handling in change_page_attr
2008-01-25 8:46 ` Ingo Molnar
@ 2008-01-25 10:32 ` Ingo Molnar
2008-01-25 20:05 ` Jeremy Fitzhardinge
0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2008-01-25 10:32 UTC (permalink / raw)
To: Jeremy Fitzhardinge
Cc: Huang, Ying, Ingo Molnar, H. Peter Anvin, Thomas Gleixner,
Andi Kleen, linux-kernel
* Ingo Molnar <mingo@elte.hu> wrote:
> ...
> + ref_prot = pte_pgprot(pte_mkexec(pte_clrhuge(*kpte)));
>
> i.e. it now goes through all the proper accessors.
i guess it would be nicer to have the proper accessors to just clear the
NX bit from ref-prot - instead of re-constructing the *kpte from
scratch. But i see no other way to do it right now than to access
pgprot_val() as an lvalue. Jeremy, what would be the best approach here?
Ingo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/6] x86: fix NX bit handling in change_page_attr
2008-01-25 10:32 ` Ingo Molnar
@ 2008-01-25 20:05 ` Jeremy Fitzhardinge
0 siblings, 0 replies; 5+ messages in thread
From: Jeremy Fitzhardinge @ 2008-01-25 20:05 UTC (permalink / raw)
To: Ingo Molnar
Cc: Huang, Ying, Ingo Molnar, H. Peter Anvin, Thomas Gleixner,
Andi Kleen, linux-kernel
Ingo Molnar wrote:
> * Ingo Molnar <mingo@elte.hu> wrote:
>
>
>> ...
>> + ref_prot = pte_pgprot(pte_mkexec(pte_clrhuge(*kpte)));
>>
>> i.e. it now goes through all the proper accessors.
>>
>
> i guess it would be nicer to have the proper accessors to just clear the
> NX bit from ref-prot - instead of re-constructing the *kpte from
> scratch. But i see no other way to do it right now than to access
> pgprot_val() as an lvalue. Jeremy, what would be the best approach here?
The pte_* accessors are really just helpers, so they're not mandatory.
Something like this would be fine:
refprot = __pgprot(pgprot_val(refprot) & ~_PAGE_NX);
This is identical to the lvalue form, but avoids using it as an lvalue.
J
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-01-25 20:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-25 5:54 [PATCH 1/6] x86: fix NX bit handling in change_page_attr Huang, Ying
2008-01-25 7:32 ` Jeremy Fitzhardinge
2008-01-25 8:46 ` Ingo Molnar
2008-01-25 10:32 ` Ingo Molnar
2008-01-25 20:05 ` Jeremy Fitzhardinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox