Skip to contentSkip to conversation

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

PATCH Applied Jason Gerecke 5 participants 7 messages Feb 11, 2021 – Mar 6, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RFC: 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.

Cc Steven Rostedt <[email protected]>
Cc Ard Biesheuvel <[email protected]>

---
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(-)
arch/x86/include/asm/jump_label.h +2 -2
index 06c3cc22a058..7f2006645d84 100644
@@ -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"
Signature · 1 line
2.30.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · On Thu, 11 Feb 2021 13:48:48 -0800 Jason Gerecke <[email protected]> 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.

-- Steve

Quoted 33 lines
Cc Steven Rostedt <[email protected]>
Cc Ard Biesheuvel <[email protected]>

---
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(-)
arch/x86/include/asm/jump_label.h +2 -2
index 06c3cc22a058..7f2006645d84 100644
@@ -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"
maintainer
#2 lore raw
Quoted 10 lines · Steven Rostedt
Quoted 7 lines · On Thu, 11 Feb 2021 13:48:48 -0800 Jason Gerecke <[email protected]> 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:"
          |  ^~~~~~~~~~~~~~~~~
Quoted 5 lines
Quoted 3 lines

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.

#3 lore raw
Quoted 16 lines · Peter Zijlstra
Quoted 14 lines · Steven Rostedt
Quoted 10 lines · On Thu, 11 Feb 2021 13:48:48 -0800 Jason Gerecke <[email protected]> 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.

Quoted 6 lines
Quoted 1 line

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.

Acked-by on v1 1/1
#4 lore raw
In reply to Jason Gerecke
Quoted 11 lines · Jason Gerecke

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.

Quoted 6 lines
Cc Steven Rostedt <[email protected]>
Cc Ard Biesheuvel <[email protected]>

---
Marked RFC since I'm not familiar with this subsystem or the asm blocks that are impacted. Extra-close inspection would be appreciated.

Signature · 1 line
Josh
merge bot Applied
#5 lore raw

[tip: locking/core] x86/jump_label: Mark arguments as const to satisfy asm constraints

In reply to Jason Gerecke
The following commit has been merged into the locking/core branch of tip:

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 <[email protected]>
AuthorDate:    Thu, 11 Feb 2021 13:48:48 -08:00
Committer:     Peter Zijlstra <[email protected]>
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.

---
 arch/x86/include/asm/jump_label.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/jump_label.h +2 -2
index 06c3cc2..7f20066 100644
@@ -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"
merge bot Applied
#6 lore raw

[tip: locking/core] x86/jump_label: Mark arguments as const to satisfy asm constraints

In reply to Jason Gerecke
The following commit has been merged into the locking/core branch of tip:

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 <[email protected]>
AuthorDate:    Thu, 11 Feb 2021 13:48:48 -08:00
Committer:     Ingo Molnar <[email protected]>
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.

---
 arch/x86/include/asm/jump_label.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/jump_label.h +2 -2
index 06c3cc2..7f20066 100644
@@ -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"