Skip to contentSkip to conversation

Report double word access atomicity on LPAE enabled targets through AUXV

PATCH New Vladimir Danushevsky 4 participants 13 messages Apr 8, 2013 – Apr 22, 2013 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

From: Vladimir Danushevsky <[email protected]>

Hi All,

One of the indirect LPAE features in a single-copy atomicity of LDRD/STRD instructions. This information is useful for some dynamic code generating applications (e.g. JIT compilers) to produce a more efficient access mechanism to atomic/volatile operands.

The feature is part of the design scheme therefore it's not related to the platform configuration i.e. whether CONFIG_ARM_LPAE is enabled or not.

The patch exposes that information through hwcap entry of an Auxiliary Vector.

---

--- linux-3.8.4_vanilla/arch/arm/include/uapi/asm/hwcap.h 2013-03-20 16:11:19.000000000 -0400

+++ linux-3.8.4/arch/arm/include/uapi/asm/hwcap.h 2013-03-26 16:32:18.266043699 -0400

@@ -25,6 +25,7 @@

#define HWCAP_IDIVT (1 << 18)

#define HWCAP_VFPD32 (1 << 19) /* set if VFP has 32 regs (not 16) */

#define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT)

+#define HWCAP_ATOMICD (1 << 20) /* ldrd/strd single-copy atomicity */

#endif /* _UAPI__ASMARM_HWCAP_H */

--- linux-3.8.4_vanilla/arch/arm/kernel/setup.c 2013-03-20 16:11:19.000000000 -0400

+++ linux-3.8.4/arch/arm/kernel/setup.c 2013-04-03 15:42:31.580525201 -0400

@@ -487,6 +487,10 @@ static void __init setup_processor(void)

        elf_hwcap &= ~HWCAP_THUMB;

#endif

+ /* check LPAE presence */

+ if (((read_cpuid_ext(CPUID_EXT_MMFR3) >> 28) & 0xf) > 0)

+ elf_hwcap |= HWCAP_ATOMICD;

+

        feat_v6_fixup();


        cacheid_init();

---

#1 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

Quoted 3 lines · Vladimir Danushevsky

From: Vladimir Danushevsky <[email protected]>

Hi All,

Hello,

Quoted 5 lines

One of the indirect LPAE features in a single-copy atomicity of LDRD/STRD instructions. This information is useful for some dynamic code generating applications (e.g. JIT compilers) to produce a more efficient access mechanism to atomic/volatile operands.

The feature is part of the design scheme therefore it's not related to the platform configuration i.e. whether CONFIG_ARM_LPAE is enabled or not.

The patch exposes that information through hwcap entry of an Auxiliary Vector.

Hmm, your commit text and patch format are both completely mangled. Furthermore, you've taken your patch against a -stable kernel, rather than the latest mainline release, so it doesn't apply anymore anyway.

However, I see what you're trying to do, and I've recently made use of this in our atomic64 implementation so that we avoid the exclusive instructions for atomic64_{read,set}.

Quoted 6 lines

--- linux-3.8.4_vanilla/arch/arm/kernel/setup.c 2013-03-20 16:11:19.000000000 -0400

+++ linux-3.8.4/arch/arm/kernel/setup.c 2013-04-03 15:42:31.580525201 -0400

(quoted diff) +0 -0
@@ -487,6 +487,10 @@ static void __init setup_processor(void)
 

Review static void __init setup_processor(void)

Quoted 10 lines
(quoted diff) +3 -0
        elf_hwcap &= ~HWCAP_THUMB;
 
 #endif
 
 
+        /* check LPAE presence */ 
 
+        if (((read_cpuid_ext(CPUID_EXT_MMFR3) >> 28) & 0xf) > 0)
 
+          elf_hwcap |= HWCAP_ATOMICD;

This is broken -- you're checking for supersection support (why?) rather than checking the vmsa field in MMFR0.

How about something like the patch below instead?

Will

--->8

arch/arm/include/uapi/asm/hwcap.h +1 -0
index 3688fd1..ecf0c6f 100644
@@ -25,6 +25,7 @@
 #define HWCAP_IDIVT    (1 << 18)
 #define HWCAP_VFPD32   (1 << 19)       /* set if VFP has 32 regs (not 16) */
 #define HWCAP_IDIV     (HWCAP_IDIVA | HWCAP_IDIVT)
+#define HWCAP_ATOMICD  (1 << 20)
 
 
 #endif /* _UAPI__ASMARM_HWCAP_H */
arch/arm/kernel/setup.c +7 -1
index d343a6c..cae7b9e 100644
@@ -355,7 +355,7 @@ void __init early_print(const char *str, ...)
 
 static void __init cpuid_init_hwcaps(void)
 {
-       unsigned int divide_instrs;
+       unsigned int divide_instrs, vmsa;
 
        if (cpu_architecture() < CPU_ARCH_ARMv7)
                return;
@@ -368,6 +368,11 @@ static void __init cpuid_init_hwcaps(void)
        case 1:
                elf_hwcap |= HWCAP_IDIVT;
        }
+
+       /* LPAE implies atomic ldrd/strd instructions */
+       vmsa = (read_cpuid_ext(CPUID_EXT_MMFR0) & 0xf) >> 0;
+       if (vmsa >= 5)
+               elf_hwcap |= HWCAP_ATOMICD;
 }
 
 static void __init feat_v6_fixup(void)
@@ -864,6 +869,7 @@ static const char *hwcap_str[] = {
        "vfpv4",
        "idiva",
        "idivt",
+       "atomicd",
        NULL
 };
 
#2 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

Quoted 9 lines · Will Deacon
Quoted 3 lines · Vladimir Danushevsky

From: Vladimir Danushevsky <[email protected]>

Hi All,

Hello,

Quoted 2 lines

One of the indirect LPAE features in a single-copy atomicity of LDRD/STRD instructions. This information is useful for some dynamic code generating applications (e.g. JIT compilers) to produce a more efficient access mechanism to atomic/volatile operands.

Quoted 7 lines
Quoted 3 lines

The feature is part of the design scheme therefore it's not related to the platform configuration i.e. whether CONFIG_ARM_LPAE is enabled or not.

The patch exposes that information through hwcap entry of an Auxiliary Vector.

Hmm, your commit text and patch format are both completely mangled. Furthermore, you've taken your patch against a -stable kernel, rather than the latest mainline release, so it doesn't apply anymore anyway.

Apologize for mutilating the patch text/body. My first post.

Quoted 18 lines

However, I see what you're trying to do, and I've recently made use of this in our atomic64 implementation so that we avoid the exclusive instructions for atomic64_{read,set}.

Quoted 13 lines

--- linux-3.8.4_vanilla/arch/arm/kernel/setup.c 2013-03-20 16:11:19.000000000 -0400

+++ linux-3.8.4/arch/arm/kernel/setup.c 2013-04-03 15:42:31.580525201 -0400

(quoted diff) +1 -0
@@ -487,6 +487,10 @@ static void __init setup_processor(void)
 
       elf_hwcap &= ~HWCAP_THUMB;
 
 #endif
 
 
+        /* check LPAE presence */ 
Quoted 8 lines

Review static void __init setup_processor(void)

Quoted 3 lines
(quoted diff) +2 -0
+        if (((read_cpuid_ext(CPUID_EXT_MMFR3) >> 28) & 0xf) > 0)
 
+          elf_hwcap |= HWCAP_ATOMICD;

This is broken -- you're checking for supersection support (why?) rather than checking the vmsa field in MMFR0.

How about something like the patch below instead?

The below patch is indeed more correct than the one originally suggested as long as MMFR0.VMSA values continue to represent an accumulating list of features (i.e. new supported values also imply long page format) which is probably true.

Thanks,
Vlad

Quoted 50 lines

Will

--->8

arch/arm/include/uapi/asm/hwcap.h +1 -0
index 3688fd1..ecf0c6f 100644
@@ -25,6 +25,7 @@
 #define HWCAP_IDIVT    (1 << 18)
 #define HWCAP_VFPD32   (1 << 19)       /* set if VFP has 32 regs (not 16) */
 #define HWCAP_IDIV     (HWCAP_IDIVA | HWCAP_IDIVT)
+#define HWCAP_ATOMICD  (1 << 20)
 
 
 #endif /* _UAPI__ASMARM_HWCAP_H */
arch/arm/kernel/setup.c +7 -1
index d343a6c..cae7b9e 100644
@@ -355,7 +355,7 @@ void __init early_print(const char *str, ...)
 
 static void __init cpuid_init_hwcaps(void)
 {
-       unsigned int divide_instrs;
+       unsigned int divide_instrs, vmsa;
 
       if (cpu_architecture() < CPU_ARCH_ARMv7)
               return;
@@ -368,6 +368,11 @@ static void __init cpuid_init_hwcaps(void)
       case 1:
               elf_hwcap |= HWCAP_IDIVT;
       }
+
+       /* LPAE implies atomic ldrd/strd instructions */
+       vmsa = (read_cpuid_ext(CPUID_EXT_MMFR0) & 0xf) >> 0;
+       if (vmsa >= 5)
+               elf_hwcap |= HWCAP_ATOMICD;
 }
 
 static void __init feat_v6_fixup(void)
@@ -864,6 +869,7 @@ static const char *hwcap_str[] = {
       "vfpv4",
       "idiva",
       "idivt",
+       "atomicd",
       NULL
 };
 
#3 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

In reply to Vladimir Danushevsky
Quoted 1 line · Vladimir Danushevsky

From: Vladimir Danushevsky <[email protected]>

Please don't obfuscate your email address like that - git won't parse it.

Quoted 1 line

Hi All,

We don't include such salutations in the commit message.

Quoted 10 lines

One of the indirect LPAE features in a single-copy atomicity of LDRD/STRD instructions. This information is useful for some dynamic code generating applications (e.g. JIT compilers) to produce a more efficient access mechanism to atomic/volatile operands.

The feature is part of the design scheme therefore it's not related to the platform configuration i.e. whether CONFIG_ARM_LPAE is enabled or not.

The patch exposes that information through hwcap entry of an Auxiliary Vector.

I think we're heading towards running out of hwcap bits to represent all these different features. Not there yet, but after this we only have 11 spare bits.

Maybe we need to switch to a more x86-centric method where we report this stuff in /proc/cpuinfo, and userspace parses this information out. If glibc already has code in there for x86, maybe we can reuse that?

Quoted 1 line

Again, don't obfuscate.

Quoted 1 line

---

diffstat?

Quoted 4 lines

--- linux-3.8.4_vanilla/arch/arm/include/uapi/asm/hwcap.h 2013-03-20 16:11:19.000000000 -0400

+++ linux-3.8.4/arch/arm/include/uapi/asm/hwcap.h 2013-03-26 16:32:18.266043699 -0400

This double-line spacing makes this patch impossible to apply.

Quoted 1 line

+ /* check LPAE presence */

If it's worth a comment, it's worth making it a good comment.

Review

Quoted 4 lines
(quoted diff) +2 -0
+        if (((read_cpuid_ext(CPUID_EXT_MMFR3) >> 28) & 0xf) > 0)
 
+          elf_hwcap |= HWCAP_ATOMICD;

We use tabs for indentation, not two spaces. Also, on the face of it ATOMICD isn't obvious what it means. Maybe HWCAP_LDRDSTRD would be better - it's only one character longer and truely reflects what you're trying to report - the presence of these two instructions.

#4 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

Quoted 9 lines · Russell King - ARM Linux
Quoted 1 line · Vladimir Danushevsky

From: Vladimir Danushevsky <[email protected]>

Please don't obfuscate your email address like that - git won't parse it.

Quoted 1 line

Hi All,

We don't include such salutations in the commit message.

I stand corrected for the comments above. Thanks.

Quoted 8 lines
Quoted 8 lines

One of the indirect LPAE features in a single-copy atomicity of LDRD/STRD instructions. This information is useful for some dynamic code generating applications (e.g. JIT compilers) to produce a more efficient access mechanism to atomic/volatile operands.

The feature is part of the design scheme therefore it's not related to the platform configuration i.e. whether CONFIG_ARM_LPAE is enabled or not.

Quoted 6 lines
Quoted 2 lines

The patch exposes that information through hwcap entry of an Auxiliary Vector.

I think we're heading towards running out of hwcap bits to represent all these different features. Not there yet, but after this we only have 11 spare bits.

yes we will eventually run out of the bits, but until that time only user level features need to be exposed through AUXV i.e. LPAE or HYP should not interest an user application.

Quoted 4 lines

Maybe we need to switch to a more x86-centric method where we report this stuff in /proc/cpuinfo, and userspace parses this information out. If glibc already has code in there for x86, maybe we can reuse that?

Doesn't x86 still report first 32 bits of HWCAP in the AUXV?

Quoted 4 lines
Quoted 2 lines

Again, don't obfuscate.

Noted.

Thanks,
Vlad

Quoted 24 lines
Quoted 2 lines

---

diffstat?

Quoted 4 lines

--- linux-3.8.4_vanilla/arch/arm/include/uapi/asm/hwcap.h 2013-03-20 16:11:19.000000000 -0400

+++ linux-3.8.4/arch/arm/include/uapi/asm/hwcap.h 2013-03-26 16:32:18.266043699 -0400

This double-line spacing makes this patch impossible to apply.

Quoted 1 line

+ /* check LPAE presence */

If it's worth a comment, it's worth making it a good comment.

Review

Quoted 4 lines
(quoted diff) +2 -0
+        if (((read_cpuid_ext(CPUID_EXT_MMFR3) >> 28) & 0xf) > 0)
 
+          elf_hwcap |= HWCAP_ATOMICD;

We use tabs for indentation, not two spaces. Also, on the face of it ATOMICD isn't obvious what it means. Maybe HWCAP_LDRDSTRD would be better - it's only one character longer and truely reflects what you're trying to report - the presence of these two instructions.

#5 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

In reply to Russell King - ARM Linux

Hi Russell,

Quoted 7 lines · Russell King - ARM Linux

I think we're heading towards running out of hwcap bits to represent all these different features. Not there yet, but after this we only have 11 spare bits.

Maybe we need to switch to a more x86-centric method where we report this stuff in /proc/cpuinfo, and userspace parses this information out. If glibc already has code in there for x86, maybe we can reuse that?

Why can't we just pass multiple AT_HWCAP entries in the auxv? It would require a small change to the ELF loader to allow an architecture to provide more than just ELF_HWCAP, but it's fairly straightforward and easy to propogate without breaking backwards compatibility.

Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+        if (((read_cpuid_ext(CPUID_EXT_MMFR3) >> 28) & 0xf) > 0)
 
+          elf_hwcap |= HWCAP_ATOMICD;

We use tabs for indentation, not two spaces. Also, on the face of it ATOMICD isn't obvious what it means. Maybe HWCAP_LDRDSTRD would be better - it's only one character longer and truely reflects what you're trying to report - the presence of these two instructions.

Actually, it's not just the presence of those instructions -- it's their behaviour wrt atomicity. They are only guaranteed to be atomic if the CPU in question supports LPAE. We could call it "lpae" but it might be set even when the kernel is using the short-descriptor format.

Will

#6 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

Hi Will,

Quoted 25 lines · Will Deacon

Hi Russell,

Quoted 7 lines · Russell King - ARM Linux

I think we're heading towards running out of hwcap bits to represent all these different features. Not there yet, but after this we only have 11 spare bits.

Maybe we need to switch to a more x86-centric method where we report this stuff in /proc/cpuinfo, and userspace parses this information out. If glibc already has code in there for x86, maybe we can reuse that?

Why can't we just pass multiple AT_HWCAP entries in the auxv? It would require a small change to the ELF loader to allow an architecture to provide more than just ELF_HWCAP, but it's fairly straightforward and easy to propogate without breaking backwards compatibility.

Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+        if (((read_cpuid_ext(CPUID_EXT_MMFR3) >> 28) & 0xf) > 0)
 
+          elf_hwcap |= HWCAP_ATOMICD;

We use tabs for indentation, not two spaces. Also, on the face of it ATOMICD isn't obvious what it means. Maybe HWCAP_LDRDSTRD would be better - it's only one character longer and truely reflects what you're trying to report - the presence of these two instructions.

Quoted 4 lines

Actually, it's not just the presence of those instructions -- it's their behaviour wrt atomicity. They are only guaranteed to be atomic if the CPU in question supports LPAE. We could call it "lpae" but it might be set even when the kernel is using the short-descriptor format.

I also think that ATOMICD would describe the intended behavior better.

Below is a modified patch based on suggestions so far:

 include/uapi/asm/hwcap.h |    1 +
 kernel/setup.c           |   13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
arch/arm/include/uapi/asm/hwcap.h +1 -0
diff -uprN -X linux-3.9-rc6/Documentation/dontdiff linux-3.9-rc6-vanilla/arch/arm/include/uapi/asm/hwcap.h linux-3.9-rc6/arch/arm/include/uapi/asm/hwcap.h
@@ -25,6 +25,7 @@
 #define HWCAP_IDIVT	(1 << 18)
 #define HWCAP_VFPD32	(1 << 19)	/* set if VFP has 32 regs (not 16) */
 #define HWCAP_IDIV	(HWCAP_IDIVA | HWCAP_IDIVT)
+#define HWCAP_ATOMICD	(1 << 20)	/* atomic behavior of ldrd/strd */
 
 
 #endif /* _UAPI__ASMARM_HWCAP_H */
arch/arm/kernel/setup.c +10 -1
diff -uprN -X linux-3.9-rc6/Documentation/dontdiff linux-3.9-rc6-vanilla/arch/arm/kernel/setup.c linux-3.9-rc6/arch/arm/kernel/setup.c
@@ -355,7 +355,7 @@ void __init early_print(const char *str,
 
 static void __init cpuid_init_hwcaps(void)
 {
-	unsigned int divide_instrs;
+	unsigned int divide_instrs, vmsa;
 
 	if (cpu_architecture() < CPU_ARCH_ARMv7)
 		return;
@@ -368,6 +368,14 @@ static void __init cpuid_init_hwcaps(voi
 	case 1:
 		elf_hwcap |= HWCAP_IDIVT;
 	}
+
+        /*
+         * LDRD/STRD instructions are single-copy atomic on LPAE enabled targets
+         * as long as double-word alignment is kept. Report that feature.
+         */
+        vmsa = (read_cpuid_ext(CPUID_EXT_MMFR0) & 0xf) >> 0;
+        if (vmsa >= 5)
+                elf_hwcap |= HWCAP_ATOMICD;
 }
 
 static void __init feat_v6_fixup(void)
@@ -506,7 +514,7 @@ static void __init setup_processor(void)
 #ifndef CONFIG_ARM_THUMB
 	elf_hwcap &= ~(HWCAP_THUMB | HWCAP_IDIVT);
 #endif
 
 	feat_v6_fixup();
 
 	cacheid_init();
@@ -864,6 +872,7 @@ static const char *hwcap_str[] = {
 	"vfpv4",
 	"idiva",
 	"idivt",
+	"atomicd",
 	NULL
 };
 
Quoted 2 lines

Will

#7 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

Quoted 1 line · Vladimir Danushevsky

Below is a modified patch based on suggestions so far:

You need to add a description, maybe just the comment that you already added in the code.

Quoted 5 lines
 include/uapi/asm/hwcap.h |    1 +
 kernel/setup.c           |   13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

Otherwise,

#8 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

In reply to Vladimir Danushevsky
Quoted 7 lines · Vladimir Danushevsky
Quoted 4 lines · Will Deacon

Actually, it's not just the presence of those instructions -- it's their behaviour wrt atomicity. They are only guaranteed to be atomic if the CPU in question supports LPAE. We could call it "lpae" but it might be set even when the kernel is using the short-descriptor format.

I also think that ATOMICD would describe the intended behavior better.

I started having second thoughts about the name, on the offchance that some other feature introduced with LPAE is found to be useful to userspace. Then userspace would end up checking ATOMICD in order to determine something different, which is counter-intuitive.

Maybe there is no other `killer feature' for userspace with LPAE, but at least we'd be reporting what the hardware says, rather than the small bit which we're interested in.

Patch below...

Will

--->8

commit c6eaaa758c7956b18aa0cfabe9500ef73514b319

Author: Will Deacon <[email protected]>
Date:   Mon Apr 8 17:13:12 2013 +0100

ARM: elf: add new hwcap for identifying atomic ldrd/strd instructions

CPUs implementing LPAE have atomic ldrd/strd instructions, meaning that userspace software can avoid having to use the exclusive variants of these instructions if they wish.

This patch advertises the atomicity of these instructions via the hwcaps, so userspace can detect this CPU feature.

arch/arm/include/uapi/asm/hwcap.h +1 -1
index 3688fd1..6d34d08 100644
@@ -25,6 +25,6 @@
 #define HWCAP_IDIVT    (1 << 18)
 #define HWCAP_VFPD32   (1 << 19)       /* set if VFP has 32 regs (not 16) */
 #define HWCAP_IDIV     (HWCAP_IDIVA | HWCAP_IDIVT)
-
+#define HWCAP_LPAE     (1 << 20)
 
 #endif /* _UAPI__ASMARM_HWCAP_H */
arch/arm/kernel/setup.c +7 -1
index eaa7900..57a53c5 100644
@@ -356,7 +356,7 @@ void __init early_print(const char *str, ...)
 
 static void __init cpuid_init_hwcaps(void)
 {
-       unsigned int divide_instrs;
+       unsigned int divide_instrs, vmsa;
 
        if (cpu_architecture() < CPU_ARCH_ARMv7)
                return;
@@ -369,6 +369,11 @@ static void __init cpuid_init_hwcaps(void)
        case 1:
                elf_hwcap |= HWCAP_IDIVT;
        }
+
+       /* LPAE implies atomic ldrd/strd instructions */
+       vmsa = (read_cpuid_ext(CPUID_EXT_MMFR0) & 0xf) >> 0;
+       if (vmsa >= 5)
+               elf_hwcap |= HWCAP_LPAE;
 }
 
 static void __init feat_v6_fixup(void)
@@ -875,6 +880,7 @@ static const char *hwcap_str[] = {
        "vfpv4",
        "idiva",
        "idivt",
+       "atomicd",
        NULL
 };
 
#9 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

Quoted 1 line · Will Deacon

Patch below...

[...]

Quoted 1 line

+#define HWCAP_LPAE (1 << 20)

[...]

arch/arm/kernel/setup.c static const char *hwcap_str[] = { · line 885

Quoted 7 lines
arch/arm/kernel/setup.c +1 -0
@@ -875,6 +880,7 @@ static const char *hwcap_str[] = {
        "vfpv4",
        "idiva",
        "idivt",
+       "atomicd",
        NULL
 };

You can tell I was in two minds about this, but that string should read "lpae".

Will

#10 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

In reply to Will Deacon
Quoted 44 lines · Will Deacon
Quoted 7 lines · Vladimir Danushevsky
Quoted 4 lines · Will Deacon

Actually, it's not just the presence of those instructions -- it's their behaviour wrt atomicity. They are only guaranteed to be atomic if the CPU in question supports LPAE. We could call it "lpae" but it might be set even when the kernel is using the short-descriptor format.

I also think that ATOMICD would describe the intended behavior better.

I started having second thoughts about the name, on the offchance that some other feature introduced with LPAE is found to be useful to userspace. Then userspace would end up checking ATOMICD in order to determine something different, which is counter-intuitive.

Maybe there is no other `killer feature' for userspace with LPAE, but at least we'd be reporting what the hardware says, rather than the small bit which we're interested in.

Patch below...

Will

--->8

commit c6eaaa758c7956b18aa0cfabe9500ef73514b319

Author: Will Deacon <[email protected]>
Date:   Mon Apr 8 17:13:12 2013 +0100

ARM: elf: add new hwcap for identifying atomic ldrd/strd instructions

CPUs implementing LPAE have atomic ldrd/strd instructions, meaning that userspace software can avoid having to use the exclusive variants of these instructions if they wish.

This patch advertises the atomicity of these instructions via the hwcaps, so userspace can detect this CPU feature.

arch/arm/include/uapi/asm/hwcap.h +0 -0
index 3688fd1..6d34d08 100644

arch/arm/include/uapi/asm/hwcap.h line 28

Quoted 5 lines
arch/arm/include/uapi/asm/hwcap.h +1 -1
@@ -25,6 +25,6 @@
 #define HWCAP_IDIVT    (1 << 18)
 #define HWCAP_VFPD32   (1 << 19)       /* set if VFP has 32 regs (not 16) */
 #define HWCAP_IDIV     (HWCAP_IDIVA | HWCAP_IDIVT)
-
+#define HWCAP_LPAE     (1 << 20)

I would rather add individual entries like atomicd. User space does not need to know whether LPAE is supported or not.

Signature · 1 line
Catalin
#11 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

Quoted 2 lines · Catalin Marinas

I would rather add individual entries like atomicd. User space does not need to know whether LPAE is supported or not.

I'm not sure that userspace should know this detail.

| LDM, LDC, LDC2, LDRD, STM, STC, STC2, STRD, PUSH, POP, RFE, SRS, VLDM,
| VLDR, VSTM, and VSTR instructions are executed as a sequence of word-
| aligned word accesses. Each 32-bit word access is guaranteed to be
| single-copy atomic. The architecture does not require subsequences
| of two or more word accesses from the sequence to be single-copy
| atomic.
| 
| In an implementation that includes the Large Physical Address Extension,
| LDRD and STRD accesses to 64-bit aligned locations are 64-bit single-copy
| atomic as seen by translation table walks and accesses to translation
| tables.
| ...
| Load/store multiple instructions, such as LDM, LDRD, STM, and STRD,
| generate multiple word accesses, each of which is a separate access
| for the purpose of determining ordering.

Note carefully the wording in the ARM ARM in the second paragraph - it's not saying that LDRD and STRD accesses are single-copy atomic to all viewers, but it's limited to the translation tables.

Sure, you can argue that the translation tables are just normal memory accesses, but in that case why use the above wording if not to permit them to be multiple-copy accesses as stated in the paragraph above and elsewhere in the ARM ARM in the paragraph below.

Maybe an error in the ARM ARM? It doesn't seem wise through to permit userspace to assume that LDRD/STRD are atomic in userspace given the above wording unless the ARM ARM gets fixed.

#12 lore raw

PATCH 1/1 Report double word access atomicity on LPAE enabled targets through AUXV

Quoted 5 lines · Russell King - ARM Linux
Quoted 2 lines · Catalin Marinas

I would rather add individual entries like atomicd. User space does not need to know whether LPAE is supported or not.

I'm not sure that userspace should know this detail.

Which detail, LPAE or atomic double accesses?

Quoted 16 lines
| LDM, LDC, LDC2, LDRD, STM, STC, STC2, STRD, PUSH, POP, RFE, SRS, VLDM,
| VLDR, VSTM, and VSTR instructions are executed as a sequence of word-
| aligned word accesses. Each 32-bit word access is guaranteed to be
| single-copy atomic. The architecture does not require subsequences
| of two or more word accesses from the sequence to be single-copy
| atomic.
| 
| In an implementation that includes the Large Physical Address Extension,
| LDRD and STRD accesses to 64-bit aligned locations are 64-bit single-copy
| atomic as seen by translation table walks and accesses to translation
| tables.
| ...
| Load/store multiple instructions, such as LDM, LDRD, STM, and STRD,
| generate multiple word accesses, each of which is a separate access
| for the purpose of determining ordering.
Quoted 3 lines

Note carefully the wording in the ARM ARM in the second paragraph - it's not saying that LDRD and STRD accesses are single-copy atomic to all viewers, but it's limited to the translation tables.

Yes, I raised this (in private I think) when Will proposed similar kernel changes. But we discussed with the ARM architecture guys and even though the ARM ARM states that this, in practice the CPUs just implement full 64-bit atomic accesses.

Quoted 8 lines

Sure, you can argue that the translation tables are just normal memory accesses, but in that case why use the above wording if not to permit them to be multiple-copy accesses as stated in the paragraph above and elsewhere in the ARM ARM in the paragraph below.

Maybe an error in the ARM ARM? It doesn't seem wise through to permit userspace to assume that LDRD/STRD are atomic in userspace given the above wording unless the ARM ARM gets fixed.

Not an error in the ARM ARM but I don't think ARM is going to extend this definition (not an easy process for such modifications). For practical purposes, CPUs with LPAE implement 64-bit atomics and it's of real benefit for some user-space cases.

Maybe a better alternative would be to add it via __v7_proc on individual CPUs (A7 and A15).

Signature · 1 line
Catalin