Skip to contentSkip to conversation

x86/page: Implement {get, set}_pte_flags() as static inlines

PATCH In review Andrew Cooper 3 participants 3 messages Sep 7, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/page: Implement {get, set}_pte_flags() as static inlines

This resolves 11 Coverity issues along the lines of the following:

1600 for ( i = 0; i < NR_RESERVED_GDT_PAGES; i++ )

CID: Operands don't affect result (CONSTANT_EXPRESSION_RESULT)result_independent_of_operands: ((33U /* 1U | 0x20U */) | (({...}) ? 8388608U /* 1U << 23 */ : 0) | 0x40U | 2U) & 4095 is always 0x63 regardless of the values of its operands. This occurs as the bitwise second operand of "|".

1601 l1e_write(pl1e + FIRST_RESERVED_GDT_PAGE + i,
1602 l1e_from_pfn(mfn + i, __PAGE_HYPERVISOR_RW));

This is presumably because once preprocessed, the association of joint logic inside {get,set}_pte_flags() is lost.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/include/asm-x86/x86_64/page.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
xen/include/asm-x86/x86_64/page.h +10 -2
index 1151ce9..1fe4531 100644
@@ -121,8 +121,16 @@ typedef l4_pgentry_t root_pgentry_t;
  */
 
 /* Extract flags into 24-bit integer, or turn 24-bit flags into a pte mask. */
-#define get_pte_flags(x) (((int)((x) >> 40) & ~0xFFF) | ((int)(x) & 0xFFF))
-#define put_pte_flags(x) (((intpte_t)((x) & ~0xFFF) << 40) | ((x) & 0xFFF))
+#ifndef __ASSEMBLY__
+static inline unsigned int get_pte_flags(intpte_t x)
+{
+    return ((x >> 40) & ~0xfff) | (x & 0xfff);
+}
+static inline intpte_t put_pte_flags(unsigned int x)
+{
+    return (((intpte_t)x & ~0xfff) << 40) | (x & 0xfff);
+}
+#endif
 
 /*
  * Protection keys define a new 4-bit protection key field
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 07.09.17 at 15:39, <[email protected]> wrote:
xen/include/asm-x86/x86_64/page.h +0 -2
@@ -121,8 +121,16 @@ typedef l4_pgentry_t root_pgentry_t;
  */
 
 /* Extract flags into 24-bit integer, or turn 24-bit flags into a pte mask. */
-#define get_pte_flags(x) (((int)((x) >> 40) & ~0xFFF) | ((int)(x) & 0xFFF))
-#define put_pte_flags(x) (((intpte_t)((x) & ~0xFFF) << 40) | ((x) & 0xFFF))

xen/include/asm-x86/x86_64/page.h typedef l4_pgentry_t root_pgentry_t; · line 133

Quoted 10 lines
xen/include/asm-x86/x86_64/page.h +10 -0
+#ifndef __ASSEMBLY__
+static inline unsigned int get_pte_flags(intpte_t x)
+{
+    return ((x >> 40) & ~0xfff) | (x & 0xfff);
+}
+static inline intpte_t put_pte_flags(unsigned int x)
+{
+    return (((intpte_t)x & ~0xfff) << 40) | (x & 0xfff);
+}
+#endif

With ideally a blank line added between the two

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Andrew Cooper
Quoted 13 lines · Andrew Cooper

This resolves 11 Coverity issues along the lines of the following:

1600 for ( i = 0; i < NR_RESERVED_GDT_PAGES; i++ )

CID: Operands don't affect result (CONSTANT_EXPRESSION_RESULT)result_independent_of_operands: ((33U /* 1U | 0x20U */) | (({...}) ? 8388608U /* 1U << 23 */ : 0) | 0x40U | 2U) & 4095 is always 0x63 regardless of the values of its operands. This occurs as the bitwise second operand of "|".

1601 l1e_write(pl1e + FIRST_RESERVED_GDT_PAGE + i,
1602 l1e_from_pfn(mfn + i, __PAGE_HYPERVISOR_RW));

Quoted 6 lines

This is presumably because once preprocessed, the association of joint logic inside {get,set}_pte_flags() is lost.

No functional change.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel