arm64: fix typo in I-cache policy detection
PATCH 1/3 arm64: fix typo in I-cache policy detection
This removes an unfortunately placed semi-colon resulting in all instruction caches being classified as AIVIVT.
--- arch/arm64/kernel/cpuinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/cpuinfo.c +1 -1
@@ -49,7 +49,7 @@ static void cpuinfo_detect_icache_policy(struct cpuinfo_arm64 *info)if (l1ip !=ICACHE_POLICY_PIPT )set_bit (ICACHEF_ALIASING , &__icache_flags); -if (l1ip ==ICACHE_POLICY_AIVIVT ); +if (l1ip ==ICACHE_POLICY_AIVIVT )set_bit (ICACHEF_AIVIVT , &__icache_flags);pr_info ("Detected %s I-cache on CPU%d" , icache_policy_str[l1ip], cpu);
Signature · 1 line
1.8.3.2
PATCH 2/3 arm64: add helper functions to read I-cache attributes
This adds helper functions and #defines to <asm/cachetype.h> to read the line size and the number of sets from the level 1 instruction cache.
--- arch/arm64/include/asm/cachetype.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
arch/arm64/include/asm/cachetype.h +28 -0
@@ -39,6 +39,34 @@extern unsigned long __icache_flags; +#define CCSIDR_EL1_LINESIZE_MASK 0x7 +#define CCSIDR_EL1_LINESIZE (x) (x & CCSIDR_EL1_LINESIZE_MASK) + +#define CCSIDR_EL1_NUMSETS_SHIFT 13 +#define CCSIDR_EL1_NUMSETS_MASK (0x7fff << CCSIDR_EL1_NUMSETS_SHIFT) +#define CCSIDR_EL1_NUMSETS (x) \ + ((x & CCSIDR_EL1_NUMSETS_MASK) >> CCSIDR_EL1_NUMSETS_SHIFT) + +static inline __attribute_const__ u32 icache_get_ccsidr(void) +{ +u32 ccsidr; + +/* Select L1 I-cache and read its size ID register */ + asm("msr csselr_el1, %x1; isb; mrs %x0, ccsidr_el1" + :"=r" (ccsidr) :"r" (0x1 )); +return ccsidr; +} + +static inline int icache_get_linesize (void ) +{ +return 16 <<CCSIDR_EL1_LINESIZE (icache_get_ccsidr ()); +} + +static inline int icache_get_numsets (void ) +{ +return 1 +CCSIDR_EL1_NUMSETS (icache_get_ccsidr ()); +} +/* * Whilst the D-side always behaves as PIPT on AArch64, aliasing is * permitted in the I-cache.
Signature · 1 line
1.8.3.2
Mark Rutland
reviewerPATCH 2/3 arm64: add helper functions to read I-cache attributes
Quoted 13 lines · Ard Biesheuvel
This adds helper functions and #defines to <
asm/cachetype.h> to read the line size and the number of sets from the level 1 instruction cache.Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm64/include/asm/cachetype.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)arch/arm64/include/asm/cachetype.h +0
-0
arch/arm64/include/asm/cachetype.h line 43
Quoted 5 lines
arch/arm64/include/asm/cachetype.h +2
-0@@ -39,6 +39,34 @@extern unsigned long __icache_flags; +#define CCSIDR_EL1_LINESIZE_MASK 0x7 +#define CCSIDR_EL1_LINESIZE (x) (x & CCSIDR_EL1_LINESIZE_MASK)
It's probably worth bracketing x in case these get used elsewhere.
arch/arm64/include/asm/cachetype.h line 56
Quoted 12 lines
arch/arm64/include/asm/cachetype.h +12
-0+#define CCSIDR_EL1_NUMSETS_SHIFT 13 +#define CCSIDR_EL1_NUMSETS_MASK (0x7fff << CCSIDR_EL1_NUMSETS_SHIFT) +#define CCSIDR_EL1_NUMSETS (x) \ + ((x & CCSIDR_EL1_NUMSETS_MASK) >> CCSIDR_EL1_NUMSETS_SHIFT) + +static inline __attribute_const__ u32 icache_get_ccsidr(void) +{ +u32 ccsidr; + +/* Select L1 I-cache and read its size ID register */ + asm("msr csselr_el1, %x1; isb; mrs %x0, ccsidr_el1" + :"=r" (ccsidr) :"r" (0x1 ));
Does GCC provide any guarantee about the upper bits in this case?
Can we not make both values u64 rather than forcing the use of x registers within the asm template?
Thanks,
Mark.
Quoted 20 lines
arch/arm64/include/asm/cachetype.h +13
-0+return ccsidr; +} + +static inline int icache_get_linesize (void ) +{ +return 16 <<CCSIDR_EL1_LINESIZE (icache_get_ccsidr ()); +} + +static inline int icache_get_numsets (void ) +{ +return 1 +CCSIDR_EL1_NUMSETS (icache_get_ccsidr ()); +} +/* * Whilst the D-side always behaves as PIPT on AArch64, aliasing is * permitted in the I-cache. Signature · 1 line
1.8.3.2
PATCH 2/3 arm64: add helper functions to read I-cache attributes
Quoted 15 lines · Mark Rutland
Quoted 14 lines · Ard Biesheuvel
This adds helper functions and #defines to <
asm/cachetype.h> to read the line size and the number of sets from the level 1 instruction cache.Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm64/include/asm/cachetype.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)arch/arm64/include/asm/cachetype.h +0
-0@@ -39,6 +39,34 @@
Quoted 7 lines
arch/arm64/include/asm/cachetype.h line 43
Quoted 4 lines
arch/arm64/include/asm/cachetype.h +2
-0extern unsigned long __icache_flags; +#define CCSIDR_EL1_LINESIZE_MASK 0x7 +#define CCSIDR_EL1_LINESIZE (x) (x & CCSIDR_EL1_LINESIZE_MASK)It's probably worth bracketing x in case these get used elsewhere.
OK
Quoted 15 lines
arch/arm64/include/asm/cachetype.h line 56
Quoted 12 lines
arch/arm64/include/asm/cachetype.h +12
-0+#define CCSIDR_EL1_NUMSETS_SHIFT 13 +#define CCSIDR_EL1_NUMSETS_MASK (0x7fff << CCSIDR_EL1_NUMSETS_SHIFT) +#define CCSIDR_EL1_NUMSETS (x) \ + ((x & CCSIDR_EL1_NUMSETS_MASK) >> CCSIDR_EL1_NUMSETS_SHIFT) + +static inline __attribute_const__ u32 icache_get_ccsidr(void) +{ +u32 ccsidr; + +/* Select L1 I-cache and read its size ID register */ + asm("msr csselr_el1, %x1; isb; mrs %x0, ccsidr_el1" + :"=r" (ccsidr) :"r" (0x1 ));Does GCC provide any guarantee about the upper bits in this case?
Quoted 3 lines
Can we not make both values u64 rather than forcing the use of x registers within the asm template?
Well, this appears to work fine, but making it explicit u64 seems like the safest option in any case so I am happy to change that.
Signature · 1 line
Ard.
Quoted 20 lines
Quoted 20 lines
arch/arm64/include/asm/cachetype.h +13
-1+return ccsidr; +} + +static inline int icache_get_linesize (void ) +{ +return 16 <<CCSIDR_EL1_LINESIZE (icache_get_ccsidr ()); +} + +static inline int icache_get_numsets (void ) +{ +return 1 +CCSIDR_EL1_NUMSETS (icache_get_ccsidr ()); +} +/* * Whilst the D-side always behaves as PIPT on AArch64, aliasing is * permitted in the I-cache. -- 1.8.3.2
PATCH 3/3 arm64: don't flag non-aliasing VIPT I-caches as aliasing
In reply to Ard BiesheuvelVIPT caches are non-aliasing if the index is derived from address bits that are always equal between VA and PA. Classifying these as aliasing results in unnecessary flushing which may hurt performance.
--- arch/arm64/kernel/cpuinfo.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/arm64/kernel/cpuinfo.c +7 -1
@@ -47,7 +47,13 @@ static void cpuinfo_detect_icache_policy(struct cpuinfo_arm64 *info)unsigned int cpu =smp_processor_id ();u32 l1ip =CTR_L1IP (info->reg_ctr); -if (l1ip !=ICACHE_POLICY_PIPT ) +/* +* VIPT caches are non-aliasing if the VA always equals the PA in all +* bit positions that are covered by the index, i.e., if num_sets_shift +* is less than or equal to PAGE_SHIFT minus line_size_shift. +*/ +if (l1ip !=ICACHE_POLICY_PIPT && !(l1ip ==ICACHE_POLICY_VIPT && +icache_get_linesize () *icache_get_numsets () <=PAGE_SIZE ))set_bit (ICACHEF_ALIASING , &__icache_flags);if (l1ip ==ICACHE_POLICY_AIVIVT )set_bit (ICACHEF_AIVIVT , &__icache_flags);
Signature · 1 line
1.8.3.2
Mark Rutland
reviewerPATCH 1/3 arm64: fix typo in I-cache policy detection
In reply to Ard BiesheuvelQuoted 2 lines · Ard Biesheuvel
This removes an unfortunately placed semi-colon resulting in all instruction caches being classified as AIVIVT.
Whoops, my bad. That obviously shouldn't have been there:
At least this results in a performance hit rather than completely erroneous operation.
Mark.
Quoted 23 lines
Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm64/kernel/cpuinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kernel/cpuinfo.c +1
-1@@ -49,7 +49,7 @@ static void cpuinfo_detect_icache_policy(struct cpuinfo_arm64 *info)if (l1ip !=ICACHE_POLICY_PIPT )set_bit (ICACHEF_ALIASING , &__icache_flags); -if (l1ip ==ICACHE_POLICY_AIVIVT ); +if (l1ip ==ICACHE_POLICY_AIVIVT )set_bit (ICACHEF_AIVIVT , &__icache_flags);pr_info ("Detected %s I-cache on CPU%d" , icache_policy_str[l1ip], cpu);Signature · 1 line
1.8.3.2