linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/boot/arch/variable: I don't think (void *) Pointers need to be cast
@ 2022-07-25  4:23 Li kunyu
  2022-08-03  9:33 ` Ingo Molnar
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Li kunyu @ 2022-07-25  4:23 UTC (permalink / raw)
  To: tglx, mingo, bp, x86; +Cc: linux-kernel, Li kunyu

I first observe (void *) type coercion and non coercion through assembly
language. It seems that there is no difference.
Then I output the assigned information through the print function and
found that the pointer that is not coerced is directly assigned when
executing the print function (opcode a1), while the coerced pointer
needs to execute the assembly instruction xlat (opcode d7), which seems
to be more efficient without coerced conversion.
At present, I just started to try to analyze this part of knowledge
(machine code), please forgive me if the analysis is wrong.

Signed-off-by: Li kunyu <kunyu@nfschina.com>
---
 arch/x86/boot/bitops.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
index 02e1dea11d94..8518ae214c9b 100644
--- a/arch/x86/boot/bitops.h
+++ b/arch/x86/boot/bitops.h
@@ -19,13 +19,13 @@
 
 static inline bool constant_test_bit(int nr, const void *addr)
 {
-	const u32 *p = (const u32 *)addr;
+	const u32 *p = addr;
 	return ((1UL << (nr & 31)) & (p[nr >> 5])) != 0;
 }
 static inline bool variable_test_bit(int nr, const void *addr)
 {
 	bool v;
-	const u32 *p = (const u32 *)addr;
+	const u32 *p = addr;
 
 	asm("btl %2,%1" CC_SET(c) : CC_OUT(c) (v) : "m" (*p), "Ir" (nr));
 	return v;
-- 
2.18.2


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

* Re: [PATCH] x86/boot/arch/variable: I don't think (void *) Pointers need to be cast
  2022-07-25  4:23 [PATCH] x86/boot/arch/variable: I don't think (void *) Pointers need to be cast Li kunyu
@ 2022-08-03  9:33 ` Ingo Molnar
  2022-08-03 15:42 ` [tip: x86/cleanups] x86/boot: Remove superfluous type casting from arch/x86/boot/bitops.h tip-bot2 for Li kunyu
  2022-08-15 19:25 ` tip-bot2 for Li kunyu
  2 siblings, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2022-08-03  9:33 UTC (permalink / raw)
  To: Li kunyu; +Cc: tglx, mingo, bp, x86, linux-kernel


* Li kunyu <kunyu@nfschina.com> wrote:

> I first observe (void *) type coercion and non coercion through assembly
> language. It seems that there is no difference.
> Then I output the assigned information through the print function and
> found that the pointer that is not coerced is directly assigned when
> executing the print function (opcode a1), while the coerced pointer
> needs to execute the assembly instruction xlat (opcode d7), which seems
> to be more efficient without coerced conversion.
> At present, I just started to try to analyze this part of knowledge
> (machine code), please forgive me if the analysis is wrong.
> 
> Signed-off-by: Li kunyu <kunyu@nfschina.com>
> ---
>  arch/x86/boot/bitops.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
> index 02e1dea11d94..8518ae214c9b 100644
> --- a/arch/x86/boot/bitops.h
> +++ b/arch/x86/boot/bitops.h
> @@ -19,13 +19,13 @@
>  
>  static inline bool constant_test_bit(int nr, const void *addr)
>  {
> -	const u32 *p = (const u32 *)addr;
> +	const u32 *p = addr;
>  	return ((1UL << (nr & 31)) & (p[nr >> 5])) != 0;
>  }
>  static inline bool variable_test_bit(int nr, const void *addr)
>  {
>  	bool v;
> -	const u32 *p = (const u32 *)addr;
> +	const u32 *p = addr;
>  
>  	asm("btl %2,%1" CC_SET(c) : CC_OUT(c) (v) : "m" (*p), "Ir" (nr));
>  	return v;

It's true that the forced-type casting of 'addr' is unnecessary in the 
cases above, I'm not sure how the kernel would end up with an XLAT 
instruction being generated in that sequence.

But your patch is a good cleanup in its own right - I've applied the patch 
below to tip:x86/cleanups, with a different changelog.

Thanks,

	Ingo

===================>
From: Li kunyu <kunyu@nfschina.com>
Date: Mon, 25 Jul 2022 12:23:58 +0800
Subject: [PATCH] x86/boot: Remove superfluous type casting from arch/x86/boot/bitops.h

'const void *' will auto-type-convert to just about any other const pointer type,
no need to force it.

[ mingo: Rewrote the changelog. ]

Signed-off-by: Li kunyu <kunyu@nfschina.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20220725042358.3377-1-kunyu@nfschina.com
---
 arch/x86/boot/bitops.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
index 02e1dea11d94..8518ae214c9b 100644
--- a/arch/x86/boot/bitops.h
+++ b/arch/x86/boot/bitops.h
@@ -19,13 +19,13 @@
 
 static inline bool constant_test_bit(int nr, const void *addr)
 {
-	const u32 *p = (const u32 *)addr;
+	const u32 *p = addr;
 	return ((1UL << (nr & 31)) & (p[nr >> 5])) != 0;
 }
 static inline bool variable_test_bit(int nr, const void *addr)
 {
 	bool v;
-	const u32 *p = (const u32 *)addr;
+	const u32 *p = addr;
 
 	asm("btl %2,%1" CC_SET(c) : CC_OUT(c) (v) : "m" (*p), "Ir" (nr));
 	return v;

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

* [tip: x86/cleanups] x86/boot: Remove superfluous type casting from arch/x86/boot/bitops.h
  2022-07-25  4:23 [PATCH] x86/boot/arch/variable: I don't think (void *) Pointers need to be cast Li kunyu
  2022-08-03  9:33 ` Ingo Molnar
@ 2022-08-03 15:42 ` tip-bot2 for Li kunyu
  2022-08-15 19:25 ` tip-bot2 for Li kunyu
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot2 for Li kunyu @ 2022-08-03 15:42 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Li kunyu, Ingo Molnar, x86, linux-kernel

The following commit has been merged into the x86/cleanups branch of tip:

Commit-ID:     a50be38f617b11b451c0a432c574859419e69471
Gitweb:        https://git.kernel.org/tip/a50be38f617b11b451c0a432c574859419e69471
Author:        Li kunyu <kunyu@nfschina.com>
AuthorDate:    Mon, 25 Jul 2022 12:23:58 +08:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 03 Aug 2022 11:32:29 +02:00

x86/boot: Remove superfluous type casting from arch/x86/boot/bitops.h

'const void *' will auto-type-convert to just about any other const pointer type,
no need to force it.

[ mingo: Rewrote the changelog. ]

Signed-off-by: Li kunyu <kunyu@nfschina.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20220725042358.3377-1-kunyu@nfschina.com
---
 arch/x86/boot/bitops.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
index 02e1dea..8518ae2 100644
--- a/arch/x86/boot/bitops.h
+++ b/arch/x86/boot/bitops.h
@@ -19,13 +19,13 @@
 
 static inline bool constant_test_bit(int nr, const void *addr)
 {
-	const u32 *p = (const u32 *)addr;
+	const u32 *p = addr;
 	return ((1UL << (nr & 31)) & (p[nr >> 5])) != 0;
 }
 static inline bool variable_test_bit(int nr, const void *addr)
 {
 	bool v;
-	const u32 *p = (const u32 *)addr;
+	const u32 *p = addr;
 
 	asm("btl %2,%1" CC_SET(c) : CC_OUT(c) (v) : "m" (*p), "Ir" (nr));
 	return v;

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

* [tip: x86/cleanups] x86/boot: Remove superfluous type casting from arch/x86/boot/bitops.h
  2022-07-25  4:23 [PATCH] x86/boot/arch/variable: I don't think (void *) Pointers need to be cast Li kunyu
  2022-08-03  9:33 ` Ingo Molnar
  2022-08-03 15:42 ` [tip: x86/cleanups] x86/boot: Remove superfluous type casting from arch/x86/boot/bitops.h tip-bot2 for Li kunyu
@ 2022-08-15 19:25 ` tip-bot2 for Li kunyu
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot2 for Li kunyu @ 2022-08-15 19:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Li kunyu, Ingo Molnar, Borislav Petkov, x86, linux-kernel

The following commit has been merged into the x86/cleanups branch of tip:

Commit-ID:     039f0e054a29d06970892240d70143150d2aaec2
Gitweb:        https://git.kernel.org/tip/039f0e054a29d06970892240d70143150d2aaec2
Author:        Li kunyu <kunyu@nfschina.com>
AuthorDate:    Mon, 25 Jul 2022 12:23:58 +08:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Mon, 15 Aug 2022 19:17:43 +02:00

x86/boot: Remove superfluous type casting from arch/x86/boot/bitops.h

'const void *' will auto-type-convert to just about any other const
pointer type, no need to force it.

  [ mingo: Rewrote the changelog. ]

Signed-off-by: Li kunyu <kunyu@nfschina.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/20220725042358.3377-1-kunyu@nfschina.com
---
 arch/x86/boot/bitops.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
index 02e1dea..8518ae2 100644
--- a/arch/x86/boot/bitops.h
+++ b/arch/x86/boot/bitops.h
@@ -19,13 +19,13 @@
 
 static inline bool constant_test_bit(int nr, const void *addr)
 {
-	const u32 *p = (const u32 *)addr;
+	const u32 *p = addr;
 	return ((1UL << (nr & 31)) & (p[nr >> 5])) != 0;
 }
 static inline bool variable_test_bit(int nr, const void *addr)
 {
 	bool v;
-	const u32 *p = (const u32 *)addr;
+	const u32 *p = addr;
 
 	asm("btl %2,%1" CC_SET(c) : CC_OUT(c) (v) : "m" (*p), "Ir" (nr));
 	return v;

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

end of thread, other threads:[~2022-08-15 21:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-25  4:23 [PATCH] x86/boot/arch/variable: I don't think (void *) Pointers need to be cast Li kunyu
2022-08-03  9:33 ` Ingo Molnar
2022-08-03 15:42 ` [tip: x86/cleanups] x86/boot: Remove superfluous type casting from arch/x86/boot/bitops.h tip-bot2 for Li kunyu
2022-08-15 19:25 ` tip-bot2 for Li kunyu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).