Skip to contentSkip to conversation

linux-next: manual merge of the xen-tip tree with the tip tree

DISCUSSION Applied Stephen Rothwell 6 participants 13 messages Aug 12, 2015 – Aug 13, 2015

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

Hi all,

Today's linux-next merge of the xen-tip tree got a conflict in:

arch/x86/xen/enlighten.c

between commit:

9261e050b686 ("x86/asm/tsc, x86/paravirt: Remove read_tsc() and read_tscp() paravirt hooks")

from the tip tree and commit:

cd6f350a5460 ("xen/PMU: Initialization code for Xen PMU")

from the xen-tip tree.

I fixed it up (see below) and can carry the fix as necessary (no action is required).

Signature · 20 lines
Cheers,
Stephen Rothwell                    [email protected]

diff --cc arch/x86/xen/enlighten.c
index d9cfa452da9d,a1c2e46206a9..000000000000
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@@ -1215,8 -1179,11 +1219,8 @@@ static const struct pv_cpu_ops xen_cpu_
  	.read_msr = xen_read_msr_safe,
  	.write_msr = xen_write_msr_safe,
  
- 	.read_pmc = native_read_pmc,
 -	.read_tsc = native_read_tsc,
+ 	.read_pmc = xen_read_pmc,
  
 -	.read_tscp = native_read_tscp,
 -
  	.iret = xen_iret,
  #ifdef CONFIG_X86_64
  	.usergs_sysret32 = xen_sysret32,
#1 lore raw
Quoted 10 lines · Stephen Rothwell

Hi all,

Today's linux-next merge of the xen-tip tree got a conflict in:

arch/x86/xen/enlighten.c

between commit:

   9261e050b686 ("x86/asm/tsc, x86/paravirt: Remove read_tsc() and read_tscp() paravirt hooks")
Quoted 8 lines

from the tip tree and commit:

cd6f350a5460 ("xen/PMU: Initialization code for Xen PMU")

from the xen-tip tree.

I fixed it up (see below) and can carry the fix as necessary (no action is required).

Thanks, this looks good.

Incidentally, 11276d53 ("locking/static_keys: Add a new static_key interface") breaks old-ish compilers (gcc version 4.4.4 20100503 (Red Hat 4.4.4-2) (GCC)):

CC arch/x86/kernel/nmi.o
In file included from /home/build/linux-boris/include/linux/jump_label.h:109,
from
/home/build/linux-boris/arch/x86/include/asm/spinlock.h:5,

                 from /home/build/linux-boris/include/linux/spinlock.h:88,
                 from /home/build/linux-boris/arch/x86/kernel/nmi.c:14:

/home/build/linux-boris/arch/x86/include/asm/jump_label.h: In function ‘nmi_handle’:
/home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: warning: asm operand 0 probably doesn’t match constraints /home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: error: impossible constraint in ‘asm’ make[3]: *** [arch/x86/kernel/nmi.o] Error 1
make[2]: *** [arch/x86/kernel] Error 2
make[1]: *** [arch/x86] Error 2

-boris

Quoted 6 lines

-- Cheers, Stephen Rothwell [email protected] diff --cc
arch/x86/xen/enlighten.c index d9cfa452da9d,a1c2e46206a9..000000000000
--- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@@
-1215,8 -1179,11 +1219,8 @@@ static const struct pv_cpu_ops xen_cpu_
.read_msr = xen_read_msr_safe, .write_msr = xen_write_msr_safe, - .read_pmc = native_read_pmc, - .read_tsc = native_read_tsc, + .read_pmc = xen_read_pmc, - .read_tscp = native_read_tscp, - .iret = xen_iret, #ifdef CONFIG_X86_64 .usergs_sysret32 = xen_sysret32,

maintainer
#2 lore raw
Quoted 13 lines · Boris Ostrovsky

Incidentally, 11276d53 ("locking/static_keys: Add a new static_key interface") breaks old-ish compilers (gcc version 4.4.4 20100503 (Red Hat 4.4.4-2) (GCC)):

CC arch/x86/kernel/nmi.o
In file included from /home/build/linux-boris/include/linux/jump_label.h:109,
from
/home/build/linux-boris/arch/x86/include/asm/spinlock.h:5,

                 from /home/build/linux-boris/include/linux/spinlock.h:88,
                 from /home/build/linux-boris/arch/x86/kernel/nmi.c:14:
Quoted 9 lines

/home/build/linux-boris/arch/x86/include/asm/jump_label.h: In function ‘nmi_handle’:
/home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: warning: asm operand 0 probably doesn’t match constraints /home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: error:
impossible constraint in ‘asm’
make[3]: *** [arch/x86/kernel/nmi.o] Error 1
make[2]: *** [arch/x86/kernel] Error 2
make[1]: *** [arch/x86] Error 2

Ugh bugger.

I bet its that: &((char *)key)[branch] business, an earlier variant thereof tripped up more recent GCCs too.

So its an __always_inline function, and both argument are always compile time constants, @key is the address of an object in static storage (a global) and @branch is a simple 0/1 at the call site.

Now we wish to compute (unsigned long)key + branch at compile/link time to feed to the assembler as an immediate, which should be possible, given its all 'constants'.

It just appears GCC is having a hard time with this.

Let me see if I have a sufficiently old GCC around to play with.

maintainer
#3 lore raw
Quoted 34 lines · Peter Zijlstra
Quoted 13 lines · Boris Ostrovsky

Incidentally, 11276d53 ("locking/static_keys: Add a new static_key interface") breaks old-ish compilers (gcc version 4.4.4 20100503 (Red Hat 4.4.4-2) (GCC)):

CC arch/x86/kernel/nmi.o
In file included from /home/build/linux-boris/include/linux/jump_label.h:109,
from
/home/build/linux-boris/arch/x86/include/asm/spinlock.h:5,

                 from /home/build/linux-boris/include/linux/spinlock.h:88,
                 from /home/build/linux-boris/arch/x86/kernel/nmi.c:14:
Quoted 9 lines

/home/build/linux-boris/arch/x86/include/asm/jump_label.h: In function ‘nmi_handle’:
/home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: warning: asm operand 0 probably doesn’t match constraints /home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: error:
impossible constraint in ‘asm’
make[3]: *** [arch/x86/kernel/nmi.o] Error 1
make[2]: *** [arch/x86/kernel] Error 2
make[1]: *** [arch/x86] Error 2

Ugh bugger.

I bet its that: &((char *)key)[branch] business, an earlier variant thereof tripped up more recent GCCs too.

So its an __always_inline function, and both argument are always compile time constants, @key is the address of an object in static storage (a global) and @branch is a simple 0/1 at the call site.

Quoted 7 lines

Now we wish to compute (unsigned long)key + branch at compile/link time to feed to the assembler as an immediate, which should be possible, given its all 'constants'.

It just appears GCC is having a hard time with this.

Let me see if I have a sufficiently old GCC around to play with.

So both my 4.4 compilers:

gcc-4.4 (Ubuntu/Linaro 4.4.7-8ubuntu1) 4.4.7
gcc-4.4 (Debian 4.4.7-2) 4.4.7

Do not have CC_HAVE_ASM_GOTO at all, and my gcc-4.6 (my next oldest compiler) doesn't have trouble building this.

maintainer
#4 lore raw
In reply to Peter Zijlstra
Quoted 34 lines · Peter Zijlstra
Quoted 13 lines · Boris Ostrovsky

Incidentally, 11276d53 ("locking/static_keys: Add a new static_key interface") breaks old-ish compilers (gcc version 4.4.4 20100503 (Red Hat 4.4.4-2) (GCC)):

CC arch/x86/kernel/nmi.o
In file included from /home/build/linux-boris/include/linux/jump_label.h:109,
from
/home/build/linux-boris/arch/x86/include/asm/spinlock.h:5,

                 from /home/build/linux-boris/include/linux/spinlock.h:88,
                 from /home/build/linux-boris/arch/x86/kernel/nmi.c:14:
Quoted 9 lines

/home/build/linux-boris/arch/x86/include/asm/jump_label.h: In function ‘nmi_handle’:
/home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: warning: asm operand 0 probably doesn’t match constraints /home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: error:
impossible constraint in ‘asm’
make[3]: *** [arch/x86/kernel/nmi.o] Error 1
make[2]: *** [arch/x86/kernel] Error 2
make[1]: *** [arch/x86] Error 2

Ugh bugger.

I bet its that: &((char *)key)[branch] business, an earlier variant thereof tripped up more recent GCCs too.

So its an __always_inline function, and both argument are always compile time constants, @key is the address of an object in static storage (a global) and @branch is a simple 0/1 at the call site.

Quoted 7 lines

Now we wish to compute (unsigned long)key + branch at compile/link time to feed to the assembler as an immediate, which should be possible, given its all 'constants'.

It just appears GCC is having a hard time with this.

Let me see if I have a sufficiently old GCC around to play with.

Could you feed the below to your compiler? Its a bit cumbersome, but its the next best I could come up with...

---
 arch/x86/include/asm/jump_label.h | 56 ++++++++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 15 deletions(-)
arch/x86/include/asm/jump_label.h +41 -15
index 28d7a857f9d1..76c769ae4200 100644
@@ -16,15 +16,30 @@
 # define STATIC_KEY_INIT_NOP GENERIC_NOP5_ATOMIC
 #endif
 
+struct foo {
+	u8 zero;
+	u8 one;
+};
+
 static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
 {
-	asm_volatile_goto("1:"
-		".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
-		".pushsection __jump_table,  \"aw\" \n\t"
-		_ASM_ALIGN "\n\t"
-		_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
-		".popsection \n\t"
-		: :  "i" (&((char *)key)[branch]) : : l_yes);
+	if (!branch) {
+		asm_volatile_goto("1:"
+				".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
+				".pushsection __jump_table,  \"aw\" \n\t"
+				_ASM_ALIGN "\n\t"
+				_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+				".popsection \n\t"
+				: :  "i" (&((struct foo *)key)->zero) : : l_yes);
+	} else {
+		asm_volatile_goto("1:"
+				".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
+				".pushsection __jump_table,  \"aw\" \n\t"
+				_ASM_ALIGN "\n\t"
+				_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+				".popsection \n\t"
+				: :  "i" (&((struct foo *)key)->one) : : l_yes);
+	}
 
 	return false;
 l_yes:
@@ -33,14 +48,25 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
 
 static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
 {
-	asm_volatile_goto("1:"
-		".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
-		"2:\n\t"
-		".pushsection __jump_table,  \"aw\" \n\t"
-		_ASM_ALIGN "\n\t"
-		_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
-		".popsection \n\t"
-		: :  "i" (&((char *)key)[branch]) : : l_yes);
+	if (!branch) {
+		asm_volatile_goto("1:"
+				".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
+				"2:\n\t"
+				".pushsection __jump_table,  \"aw\" \n\t"
+				_ASM_ALIGN "\n\t"
+				_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+				".popsection \n\t"
+				: :  "i" (&((struct foo *)key)->zero) : : l_yes);
+	} else {
+		asm_volatile_goto("1:"
+				".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
+				"2:\n\t"
+				".pushsection __jump_table,  \"aw\" \n\t"
+				_ASM_ALIGN "\n\t"
+				_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+				".popsection \n\t"
+				: :  "i" (&((struct foo *)key)->one) : : l_yes);
+	}
 
 	return false;
 l_yes:
#5 lore raw
Quoted 38 lines · Peter Zijlstra
Quoted 37 lines · Peter Zijlstra
Quoted 13 lines · Boris Ostrovsky

Incidentally, 11276d53 ("locking/static_keys: Add a new static_key interface") breaks old-ish compilers (gcc version 4.4.4 20100503 (Red Hat 4.4.4-2) (GCC)):

CC arch/x86/kernel/nmi.o
In file included from /home/build/linux-boris/include/linux/jump_label.h:109,
from
/home/build/linux-boris/arch/x86/include/asm/spinlock.h:5,

                  from /home/build/linux-boris/include/linux/spinlock.h:88,
                  from /home/build/linux-boris/arch/x86/kernel/nmi.c:14:
Quoted 9 lines

/home/build/linux-boris/arch/x86/include/asm/jump_label.h: In function ‘nmi_handle’:
/home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: warning: asm operand 0 probably doesn’t match constraints /home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: error:
impossible constraint in ‘asm’
make[3]: *** [arch/x86/kernel/nmi.o] Error 1
make[2]: *** [arch/x86/kernel] Error 2
make[1]: *** [arch/x86] Error 2

Ugh bugger.

I bet its that: &((char *)key)[branch] business, an earlier variant thereof tripped up more recent GCCs too.

So its an __always_inline function, and both argument are always compile time constants, @key is the address of an object in static storage (a global) and @branch is a simple 0/1 at the call site.

Now we wish to compute (unsigned long)key + branch at compile/link time to feed to the assembler as an immediate, which should be possible, given its all 'constants'.

Quoted 5 lines
Quoted 3 lines

It just appears GCC is having a hard time with this.

Let me see if I have a sufficiently old GCC around to play with.

Could you feed the below to your compiler? Its a bit cumbersome, but its the next best I could come up with...

No, it produces the same error. This is Fedora 13, btw, uses gcc 4.4.4.

-boris

Quoted 81 lines
---
  arch/x86/include/asm/jump_label.h | 56 ++++++++++++++++++++++++++++-----------
  1 file changed, 41 insertions(+), 15 deletions(-)
arch/x86/include/asm/jump_label.h +41 -15
index 28d7a857f9d1..76c769ae4200 100644
@@ -16,15 +16,30 @@
  # define STATIC_KEY_INIT_NOP GENERIC_NOP5_ATOMIC
  #endif
 
+struct foo {
+	u8 zero;
+	u8 one;
+};
+
  static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
  {
-	asm_volatile_goto("1:"
-		".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
-		".pushsection __jump_table,  \"aw\" \n\t"
-		_ASM_ALIGN "\n\t"
-		_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
-		".popsection \n\t"
-		: :  "i" (&((char *)key)[branch]) : : l_yes);
+	if (!branch) {
+		asm_volatile_goto("1:"
+				".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
+				".pushsection __jump_table,  \"aw\" \n\t"
+				_ASM_ALIGN "\n\t"
+				_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+				".popsection \n\t"
+				: :  "i" (&((struct foo *)key)->zero) : : l_yes);
+	} else {
+		asm_volatile_goto("1:"
+				".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
+				".pushsection __jump_table,  \"aw\" \n\t"
+				_ASM_ALIGN "\n\t"
+				_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+				".popsection \n\t"
+				: :  "i" (&((struct foo *)key)->one) : : l_yes);
+	}
 
  	return false;
  l_yes:
@@ -33,14 +48,25 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
 
  static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
  {
-	asm_volatile_goto("1:"
-		".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
-		"2:\n\t"
-		".pushsection __jump_table,  \"aw\" \n\t"
-		_ASM_ALIGN "\n\t"
-		_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
-		".popsection \n\t"
-		: :  "i" (&((char *)key)[branch]) : : l_yes);
+	if (!branch) {
+		asm_volatile_goto("1:"
+				".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
+				"2:\n\t"
+				".pushsection __jump_table,  \"aw\" \n\t"
+				_ASM_ALIGN "\n\t"
+				_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+				".popsection \n\t"
+				: :  "i" (&((struct foo *)key)->zero) : : l_yes);
+	} else {
+		asm_volatile_goto("1:"
+				".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
+				"2:\n\t"
+				".pushsection __jump_table,  \"aw\" \n\t"
+				_ASM_ALIGN "\n\t"
+				_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+				".popsection \n\t"
+				: :  "i" (&((struct foo *)key)->one) : : l_yes);
+	}
 
  	return false;
  l_yes:
#6 lore raw
Quoted 47 lines · Boris Ostrovsky
Quoted 46 lines · Peter Zijlstra
Quoted 44 lines · Peter Zijlstra
Quoted 15 lines · Boris Ostrovsky

Incidentally, 11276d53 ("locking/static_keys: Add a new static_key interface") breaks old-ish compilers (gcc version 4.4.4 20100503 (Red Hat
4.4.4-2) (GCC)):

CC arch/x86/kernel/nmi.o
In file included from /home/build/linux-boris/include/linux/jump_label.h:109,
from
/home/build/linux-boris/arch/x86/include/asm/spinlock.h:5,
from
/home/build/linux-boris/include/linux/spinlock.h:88,

                  from /home/build/linux-boris/arch/x86/kernel/nmi.c:14:
Quoted 10 lines

/home/build/linux-boris/arch/x86/include/asm/jump_label.h: In function ‘nmi_handle’:
/home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: warning:
asm
operand 0 probably doesn’t match constraints /home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: error:
impossible constraint in ‘asm’
make[3]: *** [arch/x86/kernel/nmi.o] Error 1
make[2]: *** [arch/x86/kernel] Error 2
make[1]: *** [arch/x86] Error 2

Ugh bugger.

I bet its that: &((char *)key)[branch] business, an earlier variant thereof tripped up more recent GCCs too.

So its an __always_inline function, and both argument are always compile time constants, @key is the address of an object in static storage (a global) and @branch is a simple 0/1 at the call site.

Now we wish to compute (unsigned long)key + branch at compile/link time to feed to the assembler as an immediate, which should be possible, given its all 'constants'.

It just appears GCC is having a hard time with this.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Let me see if I have a sufficiently old GCC around to play with.

Could you feed the below to your compiler? Its a bit cumbersome, but its the next best I could come up with...

No, it produces the same error. This is Fedora 13, btw, uses gcc 4.4.4.

Is the problem just that it's being misdetected as supporting asm goto? What does gcc -E say?

--Andy

#7 lore raw
Quoted 46 lines · Andy Lutomirski
Quoted 44 lines · Boris Ostrovsky
Quoted 43 lines · Peter Zijlstra
Quoted 42 lines · Peter Zijlstra
Quoted 15 lines · Boris Ostrovsky

Incidentally, 11276d53 ("locking/static_keys: Add a new static_key interface") breaks old-ish compilers (gcc version 4.4.4 20100503 (Red Hat
4.4.4-2) (GCC)):

CC arch/x86/kernel/nmi.o
In file included from /home/build/linux-boris/include/linux/jump_label.h:109,
from
/home/build/linux-boris/arch/x86/include/asm/spinlock.h:5,
from
/home/build/linux-boris/include/linux/spinlock.h:88,

                   from /home/build/linux-boris/arch/x86/kernel/nmi.c:14:
Quoted 10 lines

/home/build/linux-boris/arch/x86/include/asm/jump_label.h: In function ‘nmi_handle’:
/home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: warning:
asm
operand 0 probably doesn’t match constraints /home/build/linux-boris/arch/x86/include/asm/jump_label.h:21: error:
impossible constraint in ‘asm’
make[3]: *** [arch/x86/kernel/nmi.o] Error 1
make[2]: *** [arch/x86/kernel] Error 2
make[1]: *** [arch/x86] Error 2

Ugh bugger.

I bet its that: &((char *)key)[branch] business, an earlier variant thereof tripped up more recent GCCs too.

So its an __always_inline function, and both argument are always compile time constants, @key is the address of an object in static storage (a global) and @branch is a simple 0/1 at the call site.

Now we wish to compute (unsigned long)key + branch at compile/link time to feed to the assembler as an immediate, which should be possible, given its all 'constants'.

It just appears GCC is having a hard time with this.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Let me see if I have a sufficiently old GCC around to play with.

Could you feed the below to your compiler? Its a bit cumbersome, but its the next best I could come up with...

No, it produces the same error. This is Fedora 13, btw, uses gcc 4.4.4.

Is the problem just that it's being misdetected as supporting asm goto? What does gcc -E say?

static inline __attribute__((no_instrument_function)) __attribute__((always_inline)) bool arch_static_branch(struct static_key *key, bool branch)
{
do { asm goto("1:" ".byte " "0x0f,0x1f,0x44,0x00,0" "\n\t"
".pushsection __jump_table, \"aw\" \n\t" " " ".balign 8" " " "\n\t" " " ".quad" " " "1b, %l[l_yes], %c0 \n\t" ".popsection \n\t" : : "i" (&((char *)key)[branch]) : : l_yes); asm (""); } while (0)

return false;
l_yes:
return true;
}

-boris

#8 lore raw
In reply to Boris Ostrovsky

One option might be to do the addition in assembly, i.e.:

"i" (key), "i" (index)

... and put the addition into the assembly source.

Quoted 145 lines · Boris Ostrovsky
Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Boris Ostrovsky

Incidentally, 11276d53 ("locking/static_keys: Add a new static_key interface") breaks old-ish compilers (gcc version 4.4.4 20100503

(Red Hat

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

4.4.4-2) (GCC)):

CC arch/x86/kernel/nmi.o
In file included from /home/build/linux-boris/include/linux/jump_label.h:109,
from
/home/build/linux-boris/arch/x86/include/asm/spinlock.h:5,
from

/home/build/linux-boris/include/linux/spinlock.h:88,

Quoted 1 line
Quoted 1 line
Quoted 1 line

from

/home/build/linux-boris/arch/x86/kernel/nmi.c:14:

Quoted 1 line
Quoted 1 line
Quoted 1 line

/home/build/linux-boris/arch/x86/include/asm/jump_label.h: In

function

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

‘nmi_handle’:
/home/build/linux-boris/arch/x86/include/asm/jump_label.h:21:

warning: asm

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

operand 0 probably doesn’t match constraints /home/build/linux-boris/arch/x86/include/asm/jump_label.h:21:

error:

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines

impossible constraint in ‘asm’
make[3]: *** [arch/x86/kernel/nmi.o] Error 1
make[2]: *** [arch/x86/kernel] Error 2
make[1]: *** [arch/x86] Error 2

Ugh bugger.

I bet its that: &((char *)key)[branch] business, an earlier variant thereof tripped up more recent GCCs too.

So its an __always_inline function, and both argument are always

compile

Quoted 1 line
Quoted 1 line

time constants, @key is the address of an object in static storage

(a

Quoted 3 lines
Quoted 3 lines

global) and @branch is a simple 0/1 at the call site.

Now we wish to compute (unsigned long)key + branch at compile/link

time

Quoted 8 lines
Quoted 6 lines

to feed to the assembler as an immediate, which should be possible, given its all 'constants'.

It just appears GCC is having a hard time with this.

Let me see if I have a sufficiently old GCC around to play with.

Could you feed the below to your compiler? Its a bit cumbersome, but its the next best I could come up with...

No, it produces the same error. This is Fedora 13, btw, uses gcc 4.4.4.

-boris

Quoted 3 lines
---
  arch/x86/include/asm/jump_label.h | 56

++++++++++++++++++++++++++++-----------

Review

Quoted 3 lines
  1 file changed, 41 insertions(+), 15 deletions(-)
(quoted diff) +0 -0

b/arch/x86/include/asm/jump_label.h

arch/x86/include/asm/jump_label.h line 24

Quoted 13 lines

index 28d7a857f9d1..76c769ae4200 100644

arch/x86/include/asm/jump_label.h +5 -0
@@ -16,15 +16,30 @@
  # define STATIC_KEY_INIT_NOP GENERIC_NOP5_ATOMIC
  #endif
 
+struct foo {
+	u8 zero;
+	u8 one;
+};
+
  static __always_inline bool arch_static_branch(struct static_key

*key, bool branch)

arch/x86/include/asm/jump_label.h static __always_inline bool

Quoted 29 lines
arch/x86/include/asm/jump_label.h +17 -7
  {
-	asm_volatile_goto("1:"
-		".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
-		".pushsection __jump_table,  \"aw\" \n\t"
-		_ASM_ALIGN "\n\t"
-		_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
-		".popsection \n\t"
-		: :  "i" (&((char *)key)[branch]) : : l_yes);
+	if (!branch) {
+		asm_volatile_goto("1:"
+				".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
+				".pushsection __jump_table,  \"aw\" \n\t"
+				_ASM_ALIGN "\n\t"
+				_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+				".popsection \n\t"
+				: :  "i" (&((struct foo *)key)->zero) : : l_yes);
+	} else {
+		asm_volatile_goto("1:"
+				".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
+				".pushsection __jump_table,  \"aw\" \n\t"
+				_ASM_ALIGN "\n\t"
+				_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+				".popsection \n\t"
+				: :  "i" (&((struct foo *)key)->one) : : l_yes);
+	}
 
  	return false;
  l_yes:
@@ -33,14 +48,25 @@ static __always_inline bool

arch_static_branch(struct static_key *key, bool bran

arch/x86/include/asm/jump_label.h static __always_inline bool · line 48

Quoted 2 lines
arch/x86/include/asm/jump_label.h +0 -0
  static __always_inline bool arch_static_branch_jump(struct

static_key *key, bool branch)

Quoted 31 lines
arch/x86/include/asm/jump_label.h +19 -8
  {
-	asm_volatile_goto("1:"
-		".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
-		"2:\n\t"
-		".pushsection __jump_table,  \"aw\" \n\t"
-		_ASM_ALIGN "\n\t"
-		_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
-		".popsection \n\t"
-		: :  "i" (&((char *)key)[branch]) : : l_yes);
+	if (!branch) {
+		asm_volatile_goto("1:"
+				".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
+				"2:\n\t"
+				".pushsection __jump_table,  \"aw\" \n\t"
+				_ASM_ALIGN "\n\t"
+				_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+				".popsection \n\t"
+				: :  "i" (&((struct foo *)key)->zero) : : l_yes);
+	} else {
+		asm_volatile_goto("1:"
+				".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
+				"2:\n\t"
+				".pushsection __jump_table,  \"aw\" \n\t"
+				_ASM_ALIGN "\n\t"
+				_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+				".popsection \n\t"
+				: :  "i" (&((struct foo *)key)->one) : : l_yes);
+	}
 
  	return false;
  l_yes:
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
maintainer
#9 lore raw
Quoted 5 lines · H. Peter Anvin

One option might be to do the addition in assembly, i.e.:

"i" (key), "i" (index)

... and put the addition into the assembly source.

Like so? Seems to build on gcc-4.6.

---
 arch/x86/include/asm/jump_label.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/jump_label.h +4 -4
index 28d7a857f9d1..5daeca3d0f9e 100644
@@ -22,9 +22,9 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
 		".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
 		".pushsection __jump_table,  \"aw\" \n\t"
 		_ASM_ALIGN "\n\t"
-		_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+		_ASM_PTR "1b, %l[l_yes], %c0 + %c1 \n\t"
 		".popsection \n\t"
-		: :  "i" (&((char *)key)[branch]) : : l_yes);
+		: :  "i" (key), "i" (branch) : : l_yes);
 
 	return false;
 l_yes:
@@ -38,9 +38,9 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool
 		"2:\n\t"
 		".pushsection __jump_table,  \"aw\" \n\t"
 		_ASM_ALIGN "\n\t"
-		_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+		_ASM_PTR "1b, %l[l_yes], %c0 + %c1 \n\t"
 		".popsection \n\t"
-		: :  "i" (&((char *)key)[branch]) : : l_yes);
+		: :  "i" (key), "i" (branch) : : l_yes);
 
 	return false;
 l_yes:
#10 lore raw
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · H. Peter Anvin

One option might be to do the addition in assembly, i.e.:

"i" (key), "i" (index)

... and put the addition into the assembly source.

Like so? Seems to build on gcc-4.6.

Yes, this builds on 4.4.4. as well.

-boris

Quoted 33 lines
---
  arch/x86/include/asm/jump_label.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/jump_label.h +4 -4
index 28d7a857f9d1..5daeca3d0f9e 100644
@@ -22,9 +22,9 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
  		".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
  		".pushsection __jump_table,  \"aw\" \n\t"
  		_ASM_ALIGN "\n\t"
-		_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+		_ASM_PTR "1b, %l[l_yes], %c0 + %c1 \n\t"
  		".popsection \n\t"
-		: :  "i" (&((char *)key)[branch]) : : l_yes);
+		: :  "i" (key), "i" (branch) : : l_yes);
 
  	return false;
  l_yes:
@@ -38,9 +38,9 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool
  		"2:\n\t"
  		".pushsection __jump_table,  \"aw\" \n\t"
  		_ASM_ALIGN "\n\t"
-		_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+		_ASM_PTR "1b, %l[l_yes], %c0 + %c1 \n\t"
  		".popsection \n\t"
-		: :  "i" (&((char *)key)[branch]) : : l_yes);
+		: :  "i" (key), "i" (branch) : : l_yes);
 
  	return false;
  l_yes:
maintainer Tested-by Boris Ostrovsky
#11 lore raw
Quoted 10 lines · Boris Ostrovsky
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · H. Peter Anvin

One option might be to do the addition in assembly, i.e.:

"i" (key), "i" (index)

... and put the addition into the assembly source.

Like so? Seems to build on gcc-4.6.

Yes, this builds on 4.4.4. as well.

Thanks, Ingo / Hpa, can you make the below patch appear in the right tip branch?

---
Subject: jump_label, x86: Fix asm for older GCCs
From: Peter Zijlstra <[email protected]>
Date: Wed Aug 12 20:58:48 CEST 2015

Boris reported that: gcc version 4.4.4 20100503 (Red Hat 4.4.4-2) fails to build. The problem appears that even though @key and @branch are compile time constants it doesn't see: &((char *)key)[branch] as an immediate. More recent GCCs don't appear to have this problem.

In particular, Red Hat backported the asm goto feature into 4.4, 'normal' 4.4 compilers will not have this feature and thus not run into this asm.

The solution is to supply both values to the asm as immediates and do the addition in asm.

---
 arch/x86/include/asm/jump_label.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/jump_label.h +4 -4
@@ -22,9 +22,9 @@ static __always_inline bool arch_static_
 		".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
 		".pushsection __jump_table,  \"aw\" \n\t"
 		_ASM_ALIGN "\n\t"
-		_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+		_ASM_PTR "1b, %l[l_yes], %c0 + %c1 \n\t"
 		".popsection \n\t"
-		: :  "i" (&((char *)key)[branch]) : : l_yes);
+		: :  "i" (key), "i" (branch) : : l_yes);
 
 	return false;
 l_yes:
@@ -38,9 +38,9 @@ static __always_inline bool arch_static_
 		"2:\n\t"
 		".pushsection __jump_table,  \"aw\" \n\t"
 		_ASM_ALIGN "\n\t"
-		_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
+		_ASM_PTR "1b, %l[l_yes], %c0 + %c1 \n\t"
 		".popsection \n\t"
-		: :  "i" (&((char *)key)[branch]) : : l_yes);
+		: :  "i" (key), "i" (branch) : : l_yes);
 
 	return false;
 l_yes:
Applied
#12 lore raw
Quoted 7 lines · Peter Zijlstra
Quoted 6 lines · Boris Ostrovsky
Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · H. Peter Anvin

One option might be to do the addition in assembly, i.e.:

"i" (key), "i" (index)

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

... and put the addition into the assembly source.

Like so? Seems to build on gcc-4.6.

Yes, this builds on 4.4.4. as well.

Thanks, Ingo / Hpa, can you make the below patch appear in the right tip branch?

Applied, it will show up as the following commit:

d420acd816c0 ("jump_label/x86: Work around asm build bug on older/backported GCCs")

Thanks,

Ingo