tools: Copy linux/align.h into tools/
Subsystems (2)
PATCH 1/1 tools: Copy linux/align.h into tools/
This provides alignment macros for use in selftests.
Also clean up tools/include/linux/bitmap.h's inline definition of IS_ALIGNED().
--- tools/include/linux/align.h | 15 +++++++++++++++ tools/include/linux/bitmap.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tools/include/linux/align.h
tools/include/linux/align.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_ALIGN_H +#define _LINUX_ALIGN_H + +#include <linux/const.h> + +/* @a is a power of 2 value */ +#define ALIGN (x, a) __ALIGN_KERNEL((x), (a)) +#define ALIGN_DOWN (x, a) __ALIGN_KERNEL((x) - ((a) - 1), (a)) +#define __ALIGN_MASK (x, mask) __ALIGN_KERNEL_MASK((x), (mask)) +#define PTR_ALIGN (p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) +#define PTR_ALIGN_DOWN (p, a) ((typeof(p))ALIGN_DOWN((unsigned long)(p), (a))) +#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0) + +#endif /* _LINUX_ALIGN_H */
tools/include/linux/bitmap.h +1 -1
@@ -3,6 +3,7 @@#define _TOOLS_LINUX_BITMAP_H#include <string.h> +#include <linux/align.h> #include <linux/bitops.h> #include <linux/find.h> #include <stdlib.h>
@@ -126,7 +127,6 @@ static inline bool bitmap_and(unsigned long *dst, const unsigned long *src1,#define BITMAP_MEM_ALIGNMENT (8 * sizeof(unsigned long))#endif #define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1) -#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0)static inline bool bitmap_equal (const unsigned long *src1,const unsigned long *src2,unsigned int nbits)
Signature · 1 line
2.39.2.722.g9855ee24e9-goog
Quoted 11 lines · Ackerley Tng
This provides alignment macros for use in selftests.
Also clean up tools/include/linux/bitmap.h's inline definition of
IS_ALIGNED().Signed-off-by Ackerley Tng <[email protected]>--- tools/include/linux/align.h | 15 +++++++++++++++ tools/include/linux/bitmap.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tools/include/linux/align.h
Anyone object to pulling in align.h? I'd be more than happy to take this through the KVM tree, which is the motivation/context (we want to use the various macros in KVM selftests).
Thanks!
Quoted 7 lines · Ackerley Tng
This provides alignment macros for use in selftests.
Also clean up tools/include/linux/bitmap.h's inline definition of
IS_ALIGNED().Signed-off-by Ackerley Tng <[email protected]>---
FYI, an almost-equivalent change went through net/, commit 10a04ff09bcc ("tools:
move alignment-related macros to new <linux/align.h>"). It doesn't have these
#define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask)) #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) #define PTR_ALIGN_DOWN(p, a) ((typeof(p))ALIGN_DOWN((unsigned long)(p), (a)))
but I'm pretty sure your use case doesn't need them, so you should be good to go. And if not, it's easy enough to include a delta patch to add them.
Quoted 49 lines
tools/include/linux/align.h | 15 +++++++++++++++ tools/include/linux/bitmap.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tools/include/linux/align.htools/include/linux/align.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_ALIGN_H +#define _LINUX_ALIGN_H + +#include <linux/const.h> + +/* @a is a power of 2 value */ +#define ALIGN (x, a) __ALIGN_KERNEL((x), (a)) +#define ALIGN_DOWN (x, a) __ALIGN_KERNEL((x) - ((a) - 1), (a)) +#define __ALIGN_MASK (x, mask) __ALIGN_KERNEL_MASK((x), (mask)) +#define PTR_ALIGN (p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) +#define PTR_ALIGN_DOWN (p, a) ((typeof(p))ALIGN_DOWN((unsigned long)(p), (a))) +#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0) + +#endif /* _LINUX_ALIGN_H */ tools/include/linux/bitmap.h +1
-1@@ -3,6 +3,7 @@#define _TOOLS_LINUX_BITMAP_H#include <string.h> +#include <linux/align.h> #include <linux/bitops.h> #include <linux/find.h> #include <stdlib.h> @@ -126,7 +127,6 @@ static inline bool bitmap_and(unsigned long *dst, const unsigned long *src1,#define BITMAP_MEM_ALIGNMENT (8 * sizeof(unsigned long))#endif #define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1) -#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0)static inline bool bitmap_equal (const unsigned long *src1,const unsigned long *src2,unsigned int nbits)Signature · 1 line
2.39.2.722.g9855ee24e9-goog
Quoted 12 lines · Sean Christopherson
Quoted 7 lines · Ackerley Tng
This provides alignment macros for use in selftests.
Also clean up tools/include/linux/bitmap.h's inline definition of
IS_ALIGNED().Signed-off-by Ackerley Tng <[email protected]>---
FYI, an almost-equivalent change went through
net/, commit10a04ff09bcc("tools:
move alignment-related macros to new <linux/align.h>"). It doesn't have these
Quoted 7 lines
#define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask)) #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) #define PTR_ALIGN_DOWN(p, a) ((typeof(p))ALIGN_DOWN((unsigned long)(p), (a)))but I'm pretty sure your use case doesn't need them, so you should be good to go. And if not, it's easy enough to include a delta patch to add them.
Thanks for letting me know, please ignore the patch then :)
Quoted 49 lines
Quoted 49 lines
tools/include/linux/align.h | 15 +++++++++++++++ tools/include/linux/bitmap.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tools/include/linux/align.htools/include/linux/align.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_ALIGN_H +#define _LINUX_ALIGN_H + +#include <linux/const.h> + +/* @a is a power of 2 value */ +#define ALIGN (x, a) __ALIGN_KERNEL((x), (a)) +#define ALIGN_DOWN (x, a) __ALIGN_KERNEL((x) - ((a) - 1), (a)) +#define __ALIGN_MASK (x, mask) __ALIGN_KERNEL_MASK((x), (mask)) +#define PTR_ALIGN (p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) +#define PTR_ALIGN_DOWN (p, a) ((typeof(p))ALIGN_DOWN((unsigned long)(p), (a))) +#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0) + +#endif /* _LINUX_ALIGN_H */ tools/include/linux/bitmap.h +1
-1@@ -3,6 +3,7 @@#define _TOOLS_LINUX_BITMAP_H#include <string.h> +#include <linux/align.h> #include <linux/bitops.h> #include <linux/find.h> #include <stdlib.h> @@ -126,7 +127,6 @@ static inline bool bitmap_and(unsigned long *dst, const unsigned long *src1,#define BITMAP_MEM_ALIGNMENT (8 * sizeof(unsigned long))#endif #define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1) -#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0)static inline bool bitmap_equal (const unsigned long *src1,const unsigned long *src2,unsigned int nbits)Signature · 1 line
2.39.2.722.g9855ee24e9-goog