public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] x86: add pte_set_flags/clear_flags for pte flag manipulation
@ 2009-01-22 22:24 Jeremy Fitzhardinge
  2009-01-23  8:14 ` [Xen-devel] [PATCH 2/2] x86: add pte_set_flags/clear_flags for pteflag manipulation Jan Beulich
  0 siblings, 1 reply; 5+ messages in thread
From: Jeremy Fitzhardinge @ 2009-01-22 22:24 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Nick Piggin, Linux Kernel Mailing List, Xen-devel

It's not necessary to deconstruct and reconstruct a pte every time its
flags are being updated.  Introduce pte_set_flags and pte_clear_flags
to set and clear flags in a pte.  This allows the flag manipulation
code to be inlined, and avoids calls via paravirt-ops.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
 arch/x86/include/asm/pgtable.h |   38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

===================================================================
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -240,64 +240,78 @@
 		(_PAGE_PSE | _PAGE_PRESENT);
 }
 
+static inline pte_t pte_set_flags(pte_t pte, pteval_t set)
+{
+	pteval_t v = native_pte_val(pte);
+
+	return native_make_pte(v | set);
+}
+
+static inline pte_t pte_clear_flags(pte_t pte, pteval_t clear)
+{
+	pteval_t v = native_pte_val(pte);
+
+	return native_make_pte(v & ~clear);
+}
+
 static inline pte_t pte_mkclean(pte_t pte)
 {
-	return __pte(pte_val(pte) & ~_PAGE_DIRTY);
+	return pte_clear_flags(pte, _PAGE_DIRTY);
 }
 
 static inline pte_t pte_mkold(pte_t pte)
 {
-	return __pte(pte_val(pte) & ~_PAGE_ACCESSED);
+	return pte_clear_flags(pte, _PAGE_ACCESSED);
 }
 
 static inline pte_t pte_wrprotect(pte_t pte)
 {
-	return __pte(pte_val(pte) & ~_PAGE_RW);
+	return pte_clear_flags(pte, _PAGE_RW);
 }
 
 static inline pte_t pte_mkexec(pte_t pte)
 {
-	return __pte(pte_val(pte) & ~_PAGE_NX);
+	return pte_clear_flags(pte, _PAGE_NX);
 }
 
 static inline pte_t pte_mkdirty(pte_t pte)
 {
-	return __pte(pte_val(pte) | _PAGE_DIRTY);
+	return pte_set_flags(pte, _PAGE_DIRTY);
 }
 
 static inline pte_t pte_mkyoung(pte_t pte)
 {
-	return __pte(pte_val(pte) | _PAGE_ACCESSED);
+	return pte_set_flags(pte, _PAGE_ACCESSED);
 }
 
 static inline pte_t pte_mkwrite(pte_t pte)
 {
-	return __pte(pte_val(pte) | _PAGE_RW);
+	return pte_set_flags(pte, _PAGE_RW);
 }
 
 static inline pte_t pte_mkhuge(pte_t pte)
 {
-	return __pte(pte_val(pte) | _PAGE_PSE);
+	return pte_set_flags(pte, _PAGE_PSE);
 }
 
 static inline pte_t pte_clrhuge(pte_t pte)
 {
-	return __pte(pte_val(pte) & ~_PAGE_PSE);
+	return pte_clear_flags(pte, _PAGE_PSE);
 }
 
 static inline pte_t pte_mkglobal(pte_t pte)
 {
-	return __pte(pte_val(pte) | _PAGE_GLOBAL);
+	return pte_set_flags(pte, _PAGE_GLOBAL);
 }
 
 static inline pte_t pte_clrglobal(pte_t pte)
 {
-	return __pte(pte_val(pte) & ~_PAGE_GLOBAL);
+	return pte_clear_flags(pte, _PAGE_GLOBAL);
 }
 
 static inline pte_t pte_mkspecial(pte_t pte)
 {
-	return __pte(pte_val(pte) | _PAGE_SPECIAL);
+	return pte_set_flags(pte, _PAGE_SPECIAL);
 }
 
 extern pteval_t __supported_pte_mask;



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Xen-devel] [PATCH 2/2] x86: add pte_set_flags/clear_flags for pteflag manipulation
  2009-01-22 22:24 [PATCH 2/2] x86: add pte_set_flags/clear_flags for pte flag manipulation Jeremy Fitzhardinge
@ 2009-01-23  8:14 ` Jan Beulich
  2009-01-23 21:05   ` Jeremy Fitzhardinge
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Beulich @ 2009-01-23  8:14 UTC (permalink / raw)
  To: Ingo Molnar, Jeremy Fitzhardinge
  Cc: Xen-devel, Linux Kernel Mailing List, Nick Piggin

>>> Jeremy Fitzhardinge <jeremy@goop.org> 22.01.09 23:24 >>>
>+static inline pte_t pte_set_flags(pte_t pte, pteval_t set)
>+{
>+	pteval_t v = native_pte_val(pte);
>+
>+	return native_make_pte(v | set);
>+}
>+
>+static inline pte_t pte_clear_flags(pte_t pte, pteval_t clear)
>+{
>+	pteval_t v = native_pte_val(pte);
>+
>+	return native_make_pte(v & ~clear);
>+}

I think a comment (or event a BUG_ON()) should be added here to make
clear that this absolutely must not be used to toggle the present bit. I
even view toggling _PAGE_PSE as dangerous this way.

And alternative would be to make these macros and #undef them (or keep
them inline functions but add destructive #define-s) after all their users.

Jan


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Xen-devel] [PATCH 2/2] x86: add pte_set_flags/clear_flags  for pteflag manipulation
  2009-01-23  8:14 ` [Xen-devel] [PATCH 2/2] x86: add pte_set_flags/clear_flags for pteflag manipulation Jan Beulich
@ 2009-01-23 21:05   ` Jeremy Fitzhardinge
  2009-01-26  7:51     ` [Xen-devel] [PATCH 2/2] x86: add pte_set_flags/clear_flags forpteflag manipulation Jan Beulich
  0 siblings, 1 reply; 5+ messages in thread
From: Jeremy Fitzhardinge @ 2009-01-23 21:05 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Ingo Molnar, Xen-devel, Linux Kernel Mailing List, Nick Piggin

Jan Beulich wrote:
> I think a comment (or event a BUG_ON()) should be added here to make
> clear that this absolutely must not be used to toggle the present bit. I
> even view toggling _PAGE_PSE as dangerous this way.
>
> And alternative would be to make these macros and #undef them (or keep
> them inline functions but add destructive #define-s) after all their users.
>   

I don't see any particular problem with changing PSE or even Present 
with these functions; they don't operate on live in-memory ptes, so its 
not like they could ever be used to modify a pte unless followed with 
some kind of set_pte operation.  It is unwise to change any pte flag 
without knowing what you're doing (though P or PSE would probably have 
less subtle effects than some of the others).

But it probably wouldn't hurt to have a __ prefix to indicate they're 
"internal" and not for general use.

    J

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Xen-devel] [PATCH 2/2] x86: add pte_set_flags/clear_flags  forpteflag manipulation
  2009-01-23 21:05   ` Jeremy Fitzhardinge
@ 2009-01-26  7:51     ` Jan Beulich
  2009-01-26 19:54       ` Jeremy Fitzhardinge
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Beulich @ 2009-01-26  7:51 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: Ingo Molnar, Xen-devel, Linux Kernel Mailing List, Nick Piggin

>>> Jeremy Fitzhardinge <jeremy@goop.org> 23.01.09 22:05 >>>
>Jan Beulich wrote:
>> I think a comment (or event a BUG_ON()) should be added here to make
>> clear that this absolutely must not be used to toggle the present bit. I
>> even view toggling _PAGE_PSE as dangerous this way.
>>
>> And alternative would be to make these macros and #undef them (or keep
>> them inline functions but add destructive #define-s) after all their users.
>>   
>
>I don't see any particular problem with changing PSE or even Present 
>with these functions; they don't operate on live in-memory ptes, so its 
>not like they could ever be used to modify a pte unless followed with 
>some kind of set_pte operation.  It is unwise to change any pte flag 
>without knowing what you're doing (though P or PSE would probably have 
>less subtle effects than some of the others).

Whether a pte is live doesn't matter here: If you change P on Xen, the
frame number representation *must* change from/to PFN to/from MFN.
In no case (other than iomem pages) is it allowed to flip just this bit.

Jan


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Xen-devel] [PATCH 2/2] x86: add  pte_set_flags/clear_flags  forpteflag manipulation
  2009-01-26  7:51     ` [Xen-devel] [PATCH 2/2] x86: add pte_set_flags/clear_flags forpteflag manipulation Jan Beulich
@ 2009-01-26 19:54       ` Jeremy Fitzhardinge
  0 siblings, 0 replies; 5+ messages in thread
From: Jeremy Fitzhardinge @ 2009-01-26 19:54 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Ingo Molnar, Xen-devel, Linux Kernel Mailing List, Nick Piggin

Jan Beulich wrote:
> Whether a pte is live doesn't matter here: If you change P on Xen, the
> frame number representation *must* change from/to PFN to/from MFN.
> In no case (other than iomem pages) is it allowed to flip just this bit.

Yes, true. Same with _PAGE_SPECIAL, which is actually flipped by code 
here.  I guess a warning here might be useful, but really the calling 
code needs to be properly disciplined; after all setting P on a swap 
entry is no fun either.

    J

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-01-26 19:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-22 22:24 [PATCH 2/2] x86: add pte_set_flags/clear_flags for pte flag manipulation Jeremy Fitzhardinge
2009-01-23  8:14 ` [Xen-devel] [PATCH 2/2] x86: add pte_set_flags/clear_flags for pteflag manipulation Jan Beulich
2009-01-23 21:05   ` Jeremy Fitzhardinge
2009-01-26  7:51     ` [Xen-devel] [PATCH 2/2] x86: add pte_set_flags/clear_flags forpteflag manipulation Jan Beulich
2009-01-26 19:54       ` Jeremy Fitzhardinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox