public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools: Copy linux/align.h into tools/
@ 2023-02-27 17:46 Ackerley Tng
  2023-03-24 23:34 ` Sean Christopherson
  2024-08-22 19:14 ` Sean Christopherson
  0 siblings, 2 replies; 4+ messages in thread
From: Ackerley Tng @ 2023-02-27 17:46 UTC (permalink / raw)
  To: yury.norov, andriy.shevchenko, linux, seanjc, linux-kselftest,
	linux-kernel
  Cc: 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 <ackerleytng@google.com>
---
 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

diff --git a/tools/include/linux/align.h b/tools/include/linux/align.h
new file mode 100644
index 000000000000..2b4acec7b95a
--- /dev/null
+++ b/tools/include/linux/align.h
@@ -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 */
diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h
index f3566ea0f932..8c6852dba04f 100644
--- a/tools/include/linux/bitmap.h
+++ b/tools/include/linux/bitmap.h
@@ -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)
-- 
2.39.2.722.g9855ee24e9-goog


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

* Re: [PATCH] tools: Copy linux/align.h into tools/
  2023-02-27 17:46 [PATCH] tools: Copy linux/align.h into tools/ Ackerley Tng
@ 2023-03-24 23:34 ` Sean Christopherson
  2024-08-22 19:14 ` Sean Christopherson
  1 sibling, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2023-03-24 23:34 UTC (permalink / raw)
  To: Ackerley Tng
  Cc: yury.norov, andriy.shevchenko, linux, linux-kselftest,
	linux-kernel

On Mon, Feb 27, 2023, Ackerley Tng wrote:
> 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 <ackerleytng@google.com>
> ---
>  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!

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

* Re: [PATCH] tools: Copy linux/align.h into tools/
  2023-02-27 17:46 [PATCH] tools: Copy linux/align.h into tools/ Ackerley Tng
  2023-03-24 23:34 ` Sean Christopherson
@ 2024-08-22 19:14 ` Sean Christopherson
  2024-08-22 20:43   ` Ackerley Tng
  1 sibling, 1 reply; 4+ messages in thread
From: Sean Christopherson @ 2024-08-22 19:14 UTC (permalink / raw)
  To: Ackerley Tng
  Cc: yury.norov, andriy.shevchenko, linux, linux-kselftest,
	linux-kernel

On Mon, Feb 27, 2023, Ackerley Tng wrote:
> 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 <ackerleytng@google.com>
> ---

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.

>  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
> 
> diff --git a/tools/include/linux/align.h b/tools/include/linux/align.h
> new file mode 100644
> index 000000000000..2b4acec7b95a
> --- /dev/null
> +++ b/tools/include/linux/align.h
> @@ -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 */
> diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h
> index f3566ea0f932..8c6852dba04f 100644
> --- a/tools/include/linux/bitmap.h
> +++ b/tools/include/linux/bitmap.h
> @@ -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)
> -- 
> 2.39.2.722.g9855ee24e9-goog
> 

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

* Re: [PATCH] tools: Copy linux/align.h into tools/
  2024-08-22 19:14 ` Sean Christopherson
@ 2024-08-22 20:43   ` Ackerley Tng
  0 siblings, 0 replies; 4+ messages in thread
From: Ackerley Tng @ 2024-08-22 20:43 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: yury.norov, andriy.shevchenko, linux, linux-kselftest,
	linux-kernel

Sean Christopherson <seanjc@google.com> writes:

> On Mon, Feb 27, 2023, Ackerley Tng wrote:
>> 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 <ackerleytng@google.com>
>> ---
>
> 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.
>

Thanks for letting me know, please ignore the patch then :)

>>  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
>> 
>> diff --git a/tools/include/linux/align.h b/tools/include/linux/align.h
>> new file mode 100644
>> index 000000000000..2b4acec7b95a
>> --- /dev/null
>> +++ b/tools/include/linux/align.h
>> @@ -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 */
>> diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h
>> index f3566ea0f932..8c6852dba04f 100644
>> --- a/tools/include/linux/bitmap.h
>> +++ b/tools/include/linux/bitmap.h
>> @@ -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)
>> -- 
>> 2.39.2.722.g9855ee24e9-goog
>> 

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

end of thread, other threads:[~2024-08-22 20:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-27 17:46 [PATCH] tools: Copy linux/align.h into tools/ Ackerley Tng
2023-03-24 23:34 ` Sean Christopherson
2024-08-22 19:14 ` Sean Christopherson
2024-08-22 20:43   ` Ackerley Tng

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