[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 01/11] xen/memory: Mask XENMEMF_node() to 8 bits



As it is, it's incredibly easy for a buggy call to XENMEMF_node() to
unintentionally overflow into bit 17 and beyond. Prevent it by masking,
just like MEMF_* does.

While at it, turn "x" into "n" and "f" to better indicate whether the
macro takes nodes or mem_flags (just like their MEMF_* counterparts).

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@xxxxxxxxx>
---
 xen/include/public/memory.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h
index bd9fc37b5297..077eef48c60d 100644
--- a/xen/include/public/memory.h
+++ b/xen/include/public/memory.h
@@ -32,8 +32,9 @@
 #define XENMEMF_address_bits(x)     (x)
 #define XENMEMF_get_address_bits(x) ((x) & 0xffu)
 /* NUMA node to allocate from. */
-#define XENMEMF_node(x)     (((x) + 1) << 8)
-#define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu)
+#define XENMEMF_node_mask   (0xffu)
+#define XENMEMF_node(n)     ((((n) + 1) & XENMEMF_node_mask) << 8)
+#define XENMEMF_get_node(f) ((((f) >> 8) - 1) & XENMEMF_node_mask)
 /* Flag to populate physmap with populate-on-demand entries */
 #define XENMEMF_populate_on_demand (1<<16)
 /* Flag to request allocation only from the node specified */
-- 
2.48.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.