All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RFC: x86/jump_label: Mark arguments as const to satisfy asm constraints
@ 2021-02-11 21:48 Jason Gerecke
  2021-02-12 14:40 ` Steven Rostedt
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Jason Gerecke @ 2021-02-11 21:48 UTC (permalink / raw)
  To: linux-kernel, Peter Zijlstra, Josh Poimboeuf, Jason Baron
  Cc: Jason Gerecke, Steven Rostedt, Ard Biesheuvel

When compiling an external kernel module with `-O0` or `-O1`, the following
compile error may be reported:

    ./arch/x86/include/asm/jump_label.h:25:2: error: impossible constraint in ‘asm’
       25 |  asm_volatile_goto("1:"
          |  ^~~~~~~~~~~~~~~~~

It appears that these lower optimization levels prevent GCC from detecting
that the key/branch arguments can be treated as constants and used as
immediate operands. To work around this, explicitly add the `const` label.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
---
Marked RFC since I'm not familiar with this subsystem or the asm blocks that
are impacted. Extra-close inspection would be appreciated.

 arch/x86/include/asm/jump_label.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
index 06c3cc22a058..7f2006645d84 100644
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -20,7 +20,7 @@
 #include <linux/stringify.h>
 #include <linux/types.h>
 
-static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
+static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
 {
 	asm_volatile_goto("1:"
 		".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
@@ -36,7 +36,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
 	return true;
 }
 
-static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
+static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
 {
 	asm_volatile_goto("1:"
 		".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
-- 
2.30.1


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

* Re: [PATCH] RFC: x86/jump_label: Mark arguments as const to satisfy asm constraints
  2021-02-11 21:48 [PATCH] RFC: x86/jump_label: Mark arguments as const to satisfy asm constraints Jason Gerecke
@ 2021-02-12 14:40 ` Steven Rostedt
  2021-02-12 15:27   ` Peter Zijlstra
  2021-02-12 16:14 ` Josh Poimboeuf
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Steven Rostedt @ 2021-02-12 14:40 UTC (permalink / raw)
  To: Jason Gerecke
  Cc: linux-kernel, Peter Zijlstra, Josh Poimboeuf, Jason Baron,
	Jason Gerecke, Ard Biesheuvel, x86

On Thu, 11 Feb 2021 13:48:48 -0800
Jason Gerecke <killertofu@gmail.com> wrote:

> When compiling an external kernel module with `-O0` or `-O1`, the following
> compile error may be reported:
> 
>     ./arch/x86/include/asm/jump_label.h:25:2: error: impossible constraint in ‘asm’
>        25 |  asm_volatile_goto("1:"
>           |  ^~~~~~~~~~~~~~~~~
> 
> It appears that these lower optimization levels prevent GCC from detecting
> that the key/branch arguments can be treated as constants and used as
> immediate operands. To work around this, explicitly add the `const` label.

Yes this makes sense. The "i" constraint needs to be a constant.

Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

> 
> Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> ---
> Marked RFC since I'm not familiar with this subsystem or the asm blocks that
> are impacted. Extra-close inspection would be appreciated.
> 
>  arch/x86/include/asm/jump_label.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
> index 06c3cc22a058..7f2006645d84 100644
> --- a/arch/x86/include/asm/jump_label.h
> +++ b/arch/x86/include/asm/jump_label.h
> @@ -20,7 +20,7 @@
>  #include <linux/stringify.h>
>  #include <linux/types.h>
>  
> -static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
> +static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
>  {
>  	asm_volatile_goto("1:"
>  		".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
> @@ -36,7 +36,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
>  	return true;
>  }
>  
> -static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
> +static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
>  {
>  	asm_volatile_goto("1:"
>  		".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"


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

* Re: [PATCH] RFC: x86/jump_label: Mark arguments as const to satisfy asm constraints
  2021-02-12 14:40 ` Steven Rostedt
@ 2021-02-12 15:27   ` Peter Zijlstra
  2021-02-12 15:55     ` Jason Gerecke
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Zijlstra @ 2021-02-12 15:27 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Jason Gerecke, linux-kernel, Josh Poimboeuf, Jason Baron,
	Jason Gerecke, Ard Biesheuvel, x86

On Fri, Feb 12, 2021 at 09:40:59AM -0500, Steven Rostedt wrote:
> On Thu, 11 Feb 2021 13:48:48 -0800
> Jason Gerecke <killertofu@gmail.com> wrote:
> 
> > When compiling an external kernel module with `-O0` or `-O1`, the following
> > compile error may be reported:
> > 
> >     ./arch/x86/include/asm/jump_label.h:25:2: error: impossible constraint in ‘asm’
> >        25 |  asm_volatile_goto("1:"
> >           |  ^~~~~~~~~~~~~~~~~
> > 
> > It appears that these lower optimization levels prevent GCC from detecting
> > that the key/branch arguments can be treated as constants and used as
> > immediate operands. To work around this, explicitly add the `const` label.
> 
> Yes this makes sense. The "i" constraint needs to be a constant.

Right, using -O[01] seems a little daft though. But yeah, that patch is
correct and won't cause harm.

I've queued it for after the next merge window.

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

* Re: [PATCH] RFC: x86/jump_label: Mark arguments as const to satisfy asm constraints
  2021-02-12 15:27   ` Peter Zijlstra
@ 2021-02-12 15:55     ` Jason Gerecke
  0 siblings, 0 replies; 7+ messages in thread
From: Jason Gerecke @ 2021-02-12 15:55 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Steven Rostedt, LKML, Josh Poimboeuf, Jason Baron, Jason Gerecke,
	Ard Biesheuvel, x86

On Fri, Feb 12, 2021 at 7:27 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Fri, Feb 12, 2021 at 09:40:59AM -0500, Steven Rostedt wrote:
> > On Thu, 11 Feb 2021 13:48:48 -0800
> > Jason Gerecke <killertofu@gmail.com> wrote:
> >
> > > When compiling an external kernel module with `-O0` or `-O1`, the following
> > > compile error may be reported:
> > >
> > >     ./arch/x86/include/asm/jump_label.h:25:2: error: impossible constraint in ‘asm’
> > >        25 |  asm_volatile_goto("1:"
> > >           |  ^~~~~~~~~~~~~~~~~
> > >
> > > It appears that these lower optimization levels prevent GCC from detecting
> > > that the key/branch arguments can be treated as constants and used as
> > > immediate operands. To work around this, explicitly add the `const` label.
> >
> > Yes this makes sense. The "i" constraint needs to be a constant.
>
> Right, using -O[01] seems a little daft though. But yeah, that patch is
> correct and won't cause harm.
>
> I've queued it for after the next merge window.

Thanks. Only reason I even tried compiling at those levels was to play
around with GCC's new static analyzer options. They seem to be
ineffective at more normal optimization levels.

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

* Re: [PATCH] RFC: x86/jump_label: Mark arguments as const to satisfy asm constraints
  2021-02-11 21:48 [PATCH] RFC: x86/jump_label: Mark arguments as const to satisfy asm constraints Jason Gerecke
  2021-02-12 14:40 ` Steven Rostedt
@ 2021-02-12 16:14 ` Josh Poimboeuf
  2021-03-03  8:15 ` [tip: locking/core] " tip-bot2 for Jason Gerecke
  2021-03-06 11:54 ` tip-bot2 for Jason Gerecke
  3 siblings, 0 replies; 7+ messages in thread
From: Josh Poimboeuf @ 2021-02-12 16:14 UTC (permalink / raw)
  To: Jason Gerecke
  Cc: linux-kernel, Peter Zijlstra, Jason Baron, Jason Gerecke,
	Steven Rostedt, Ard Biesheuvel

On Thu, Feb 11, 2021 at 01:48:48PM -0800, Jason Gerecke wrote:
> When compiling an external kernel module with `-O0` or `-O1`, the following
> compile error may be reported:
> 
>     ./arch/x86/include/asm/jump_label.h:25:2: error: impossible constraint in ‘asm’
>        25 |  asm_volatile_goto("1:"
>           |  ^~~~~~~~~~~~~~~~~
> 
> It appears that these lower optimization levels prevent GCC from detecting
> that the key/branch arguments can be treated as constants and used as
> immediate operands. To work around this, explicitly add the `const` label.
> 
> Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> ---
> Marked RFC since I'm not familiar with this subsystem or the asm blocks that
> are impacted. Extra-close inspection would be appreciated.

Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>

-- 
Josh


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

* [tip: locking/core] x86/jump_label: Mark arguments as const to satisfy asm constraints
  2021-02-11 21:48 [PATCH] RFC: x86/jump_label: Mark arguments as const to satisfy asm constraints Jason Gerecke
  2021-02-12 14:40 ` Steven Rostedt
  2021-02-12 16:14 ` Josh Poimboeuf
@ 2021-03-03  8:15 ` tip-bot2 for Jason Gerecke
  2021-03-06 11:54 ` tip-bot2 for Jason Gerecke
  3 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Jason Gerecke @ 2021-03-03  8:15 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Jason Gerecke, Peter Zijlstra (Intel), Steven Rostedt (VMware),
	Josh Poimboeuf, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     566a9522381495d27b596ee3bdc9578ba02a895d
Gitweb:        https://git.kernel.org/tip/566a9522381495d27b596ee3bdc9578ba02a895d
Author:        Jason Gerecke <killertofu@gmail.com>
AuthorDate:    Thu, 11 Feb 2021 13:48:48 -08:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 02 Mar 2021 15:06:34 +01:00

x86/jump_label: Mark arguments as const to satisfy asm constraints

When compiling an external kernel module with `-O0` or `-O1`, the following
compile error may be reported:

    ./arch/x86/include/asm/jump_label.h:25:2: error: impossible constraint in ‘asm’
       25 |  asm_volatile_goto("1:"
          |  ^~~~~~~~~~~~~~~~~

It appears that these lower optimization levels prevent GCC from detecting
that the key/branch arguments can be treated as constants and used as
immediate operands. To work around this, explicitly add the `const` label.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lkml.kernel.org/r/20210211214848.536626-1-jason.gerecke@wacom.com
---
 arch/x86/include/asm/jump_label.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
index 06c3cc2..7f20066 100644
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -20,7 +20,7 @@
 #include <linux/stringify.h>
 #include <linux/types.h>
 
-static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
+static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
 {
 	asm_volatile_goto("1:"
 		".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
@@ -36,7 +36,7 @@ l_yes:
 	return true;
 }
 
-static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
+static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
 {
 	asm_volatile_goto("1:"
 		".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"

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

* [tip: locking/core] x86/jump_label: Mark arguments as const to satisfy asm constraints
  2021-02-11 21:48 [PATCH] RFC: x86/jump_label: Mark arguments as const to satisfy asm constraints Jason Gerecke
                   ` (2 preceding siblings ...)
  2021-03-03  8:15 ` [tip: locking/core] " tip-bot2 for Jason Gerecke
@ 2021-03-06 11:54 ` tip-bot2 for Jason Gerecke
  3 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Jason Gerecke @ 2021-03-06 11:54 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Jason Gerecke, Peter Zijlstra (Intel),
	Ingo Molnar, Steven Rostedt (VMware),
	Josh Poimboeuf, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     864b435514b286c0be2a38a02f487aa28d990ef8
Gitweb:        https://git.kernel.org/tip/864b435514b286c0be2a38a02f487aa28d990ef8
Author:        Jason Gerecke <killertofu@gmail.com>
AuthorDate:    Thu, 11 Feb 2021 13:48:48 -08:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Sat, 06 Mar 2021 12:51:00 +01:00

x86/jump_label: Mark arguments as const to satisfy asm constraints

When compiling an external kernel module with `-O0` or `-O1`, the following
compile error may be reported:

    ./arch/x86/include/asm/jump_label.h:25:2: error: impossible constraint in ‘asm’
       25 |  asm_volatile_goto("1:"
          |  ^~~~~~~~~~~~~~~~~

It appears that these lower optimization levels prevent GCC from detecting
that the key/branch arguments can be treated as constants and used as
immediate operands. To work around this, explicitly add the `const` label.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lkml.kernel.org/r/20210211214848.536626-1-jason.gerecke@wacom.com
---
 arch/x86/include/asm/jump_label.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
index 06c3cc2..7f20066 100644
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -20,7 +20,7 @@
 #include <linux/stringify.h>
 #include <linux/types.h>
 
-static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
+static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
 {
 	asm_volatile_goto("1:"
 		".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
@@ -36,7 +36,7 @@ l_yes:
 	return true;
 }
 
-static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
+static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
 {
 	asm_volatile_goto("1:"
 		".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"

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

end of thread, other threads:[~2021-03-06 11:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-11 21:48 [PATCH] RFC: x86/jump_label: Mark arguments as const to satisfy asm constraints Jason Gerecke
2021-02-12 14:40 ` Steven Rostedt
2021-02-12 15:27   ` Peter Zijlstra
2021-02-12 15:55     ` Jason Gerecke
2021-02-12 16:14 ` Josh Poimboeuf
2021-03-03  8:15 ` [tip: locking/core] " tip-bot2 for Jason Gerecke
2021-03-06 11:54 ` tip-bot2 for Jason Gerecke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.