target/arm: Add support for FEAT_TLBIOS and FEAT_TLBIRANGE
v3 cover target/arm: Add support for FEAT_TLBIOS and FEAT_TLBIRANGE
ARMv8.4 adds the mandatory FEAT_TLBIOS and FEAT_TLBIRANGE. They provides TLBI maintenance instructions that extend to the Outer Shareable domain and that apply to a range of input addresses.
Changes from v2 to v3:
o Change the functions in cputlb.c to do a full flush. This should only be a short-term implementation.
Testing:
o Ran scripts/checkpatch.pl: functions in exec-all.h fail, but I think that's acceptable?
o Built all targets
o Ran test code that executed the new instructions
o Ran "make test"
Rebecca Cran (3):
target/arm: Add support for FEAT_TLBIRANGE target/arm: Add support for FEAT_TLBIOS
target/arm: set ID_AA64ISAR0.TLB to 2 for max AARCH64 CPU type
accel/tcg/cputlb.c | 22 ++ include/exec/exec-all.h | 41 +++ target/arm/cpu.h | 11 + target/arm/cpu64.c | 1 + target/arm/helper.c | 323 ++++++++++++++++++++ 5 files changed, 398 insertions(+)
Signature · 1 line
2.26.2
PATCH v3 1/3 target/arm: Add support for FEAT_TLBIRANGE
ARMv8.4 adds the mandatory FEAT_TLBIRANGE. It provides TLBI maintenance instructions that apply to a range of input addresses.
--- accel/tcg/cputlb.c | 22 ++ include/exec/exec-all.h | 41 ++++ target/arm/cpu.h | 5 + target/arm/helper.c | 248 ++++++++++++++++++++ 4 files changed, 316 insertions(+)
accel/tcg/cputlb.c +22 -0
@@ -623,6 +623,28 @@ void tlb_flush_page(CPUState *cpu, target_ulong addr)tlb_flush_page_by_mmuidx (cpu, addr,ALL_MMUIDX_BITS ); } +void tlb_flush_page_range_by_mmuidx (CPUState *cpu,target_ulong addr, +unsigned int num_pages,uint16_t idxmap) +{ +/* +* We currently do a full flush, but for performance this should be +* updated to only flush the requested pages, taking TBI into account. +*/ +tlb_flush_by_mmuidx (cpu, idxmap); +} + +void tlb_flush_page_range_by_mmuidx_all_cpus_synced (CPUState *src_cpu, +target_ulong addr, +unsigned int num_pages, +uint16_t idxmap) +{ +/* +* We currently do a full flush, but for performance this should be +* updated to only flush the requested pages, taking TBI into account. +*/ +tlb_flush_by_mmuidx_all_cpus_synced (src_cpu, idxmap); +} +void tlb_flush_page_by_mmuidx_all_cpus (CPUState *src_cpu,target_ulong addr,uint16_t idxmap) {
include/exec/exec-all.h +41 -0
53 lines not on this page · raw message
target/arm/cpu.h +5 -0
@@ -4038,6 +4038,11 @@ static inline bool isar_feature_aa64_pauth_arch(const ARMISARegisters *id)return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,APA ) !=0 ; } +static inline bool isar_feature_aa64_tlbirange (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64isar0,ID_AA64ISAR0 ,TLB ) ==2 ; +} +static inline bool isar_feature_aa64_sb (const ARMISARegisters *id) {return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,SB ) !=0 ;
target/arm/helper.c +248 -0
266 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v3 1/3] target/arm: Add support for FEAT_TLBIRANGE
accel/tcg/cputlb.c void tlb_flush_page(CPUState *cpu, target_ulong addr) · line 627
Quoted 2 lines · Rebecca Cran
accel/tcg/cputlb.c +2
-0+void tlb_flush_page_range_by_mmuidx (CPUState *cpu,target_ulong addr, +unsigned int num_pages,uint16_t idxmap)
I am not keen on this interface. I think you should take either start+end addresses (inclusive) or start+length (in bytes).
Using num_pages, and as an unsigned int, seems too easy to fail when applied to a different guest.
accel/tcg/cputlb.c void tlb_flush_page(CPUState *cpu, target_ulong addr) · line 634
Quoted 7 lines
accel/tcg/cputlb.c +7
-0+{ +/* +* We currently do a full flush, but for performance this should be +* updated to only flush the requested pages, taking TBI into account. +*/ +tlb_flush_by_mmuidx (cpu, idxmap); +}
And if you're going to cop-out like this, you might as well just do it in target/arm and not add these new interfaces at all.
Quoted 6 lines
target/arm/helper.c +6
-0+#ifdef TARGET_AARCH64 +static unsigned int tlbi_aa64_range_get_num_pages (CPUARMState *env, +uint64_t value, +uint64_t addr) +{ +unsigned int page_size;
target/arm/helper.c static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 4777
Quoted 10 lines
target/arm/helper.c +10
-0+unsigned int page_shift; +unsigned int page_size_granule; +uint64_t num; +uint64_t scale; +uint64_t exponent; +uint64_t high_addr; + + num = (value >>39 ) &0xF ; + scale = (value >>44 ) &0x3 ; + page_size_granule = (value >>46 ) &0x3 ;
extract64()
Quoted 10 lines
target/arm/helper.c +10
-0+ +switch (page_size_granule) { +case 1 : + page_size =4096 ; + page_shift =12 ; +break ; +case 2 : + page_size =16384 ; + page_shift =14 ; +break ;
target/arm/helper.c static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 4797
Quoted 10 lines
target/arm/helper.c +10
-0+case 3 : + page_size =65536 ; + page_shift =16 ; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"Invalid page size granule %d\n" , + page_size_granule); + +raise_exception (env,EXCP_UDEF ,syn_uncategorized (), +exception_target_el (env));
You can't raise an exception from here, because you don't have all of the context for unwinding the tcg state. Which you cannot access from within the callback of an ARMCPRegInfo.
The manual says that if TG does not correspond to the granule size of the actual translation then "the architecture does not require that the instruction invalidates any entries". "Reserved" can be safely assumed to "not correspond", so I think you could just as easily return 0 here, after logging the guest error.
target/arm/helper.c static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 4805
Quoted 3 lines
target/arm/helper.c +3
-0+ high_addr = addr + (((num +1 ) << exponent) * page_size); + +return (high_addr - addr) >> page_shift;
I'll note that it would be much easier for you to return a byte value for the length, and that you don't actually need to pass in addr at all.
Quoted 1 line
+
uint64_taddr = (value &0xFFFFFFFFFUL) <<TARGET_PAGE_BITS;
The manual does not explicitly say, but I'm certain that this should be a signed address, when regime_has_2_ranges(). Otherwise it would be impossible to flush a range of kernel addresses.
But all of this is moot if we're just going to flush all pages. At which point you might as well simply re-use tlbi_aa64_vmalle1_write et al. Place your TODO comment in front of tlbirange_reginfo[] instead of buried n-levels further down.
r~
Re: [PATCH v3 1/3] target/arm: Add support for FEAT_TLBIRANGE
Quoted 68 lines · Richard Henderson
Quoted 3 lines · Rebecca Cran
+void tlb_flush_page_range_by_mmuidx(CPUState *cpu,
target_ulongaddr, + unsigned intnum_pages,uint16_tidxmap)I am not keen on this interface. I think you should take either start+end addresses (inclusive) or start+length (in bytes).
Using
num_pages, and as an unsigned int, seems too easy to fail when applied to a different guest.accel/tcg/cputlb.c void tlb_flush_page(CPUState *cpu, target_ulong addr) · line 634
Quoted 7 lines
accel/tcg/cputlb.c +7
-0+{ + /* + * We currently do a full flush, but for performance this should be + * updated to only flush the requested pages, taking TBI into account. + */ + tlb_flush_by_mmuidx(cpu, idxmap); +}And if you're going to cop-out like this, you might as well just do it in target/arm and not add these new interfaces at all.
Quoted 6 lines
target/arm/helper.c +6
-0+#ifdef TARGET_AARCH64 +static unsigned int tlbi_aa64_range_get_num_pages (CPUARMState *env, + uint64_t value, + uint64_t addr) +{ + unsigned int page_size;target/arm/helper.c static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 4777
Quoted 10 lines
target/arm/helper.c +10
-0+ unsigned int page_shift; + unsigned int page_size_granule; + uint64_t num; + uint64_t scale; + uint64_t exponent; + uint64_t high_addr; + + num = (value >> 39) & 0xF; + scale = (value >> 44) & 0x3; + page_size_granule = (value >> 46) & 0x3;
extract64()Quoted 10 lines
target/arm/helper.c +10
-0+ + switch (page_size_granule) { + case 1: + page_size = 4096; + page_shift = 12; + break; + case 2: + page_size = 16384; + page_shift = 14; + break;target/arm/helper.c static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 4797
Quoted 10 lines
target/arm/helper.c +10
-0+ case 3: + page_size = 65536; + page_shift = 16; + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "Invalid page size granule %d\n", + page_size_granule); + + raise_exception(env, EXCP_UDEF, syn_uncategorized(), + exception_target_el(env));You can't raise an exception from here, because you don't have all of the context for unwinding the tcg state. Which you cannot access from within the callback of an ARMCPRegInfo.
The manual says that if TG does not correspond to the granule size of the actual translation then "the architecture does not require that the instruction invalidates any entries". "Reserved" can be safely assumed to "not correspond", so I think you could just as easily return 0 here, after logging the guest error.
Quoted 3 lines
+
high_addr= addr + (((num + 1) << exponent) *page_size); +
+ return (high_addr- addr) >>page_shift;
Quoted 7 lines
I'll note that it would be much easier for you to return a byte value for the length, and that you don't actually need to pass in addr at all.
Quoted 1 line
+
uint64_taddr = (value &0xFFFFFFFFFUL) <<TARGET_PAGE_BITS;The manual does not explicitly say, but I'm certain that this should be a signed address, when regime_has_2_ranges(). Otherwise it would be impossible to flush a range of kernel addresses.
But all of this is moot if we're just going to flush all pages. At which point you might as well simply re-use
tlbi_aa64_vmalle1_writeet al. Place your TODO comment in front of tlbirange_reginfo[] instead of buried n-levels further down.
Thanks for the comments. I'll continue working on the full/proper implementation (including changing the interface to remove num_pages) and send out a v4.
Signature · 1 line
Rebecca Cran
Re: [PATCH v3 1/3] target/arm: Add support for FEAT_TLBIRANGE
In reply to Richard HendersonQuoted 8 lines · Richard Henderson
Quoted 3 lines · Rebecca Cran
+void tlb_flush_page_range_by_mmuidx(CPUState *cpu,
target_ulongaddr, + unsigned intnum_pages,uint16_tidxmap)I am not keen on this interface. I think you should take either start+end addresses (inclusive) or start+length (in bytes).
Using
num_pages, and as an unsigned int, seems too easy to fail when applied to a different guest.
Do you mean pushing the knowledge of the number of pages to invalidate down to cputlb.c? Because I'm thinking there has to be a loop somewhere that invalidates each page if a full flush isn't being done?
Signature · 1 line
Rebecca Cran
Re: [PATCH v3 1/3] target/arm: Add support for FEAT_TLBIRANGE
Quoted 10 lines · Rebecca Cran
Quoted 7 lines · Richard Henderson
Quoted 2 lines · Rebecca Cran
+void tlb_flush_page_range_by_mmuidx(CPUState *cpu,
target_ulongaddr, + unsigned intnum_pages,uint16_tidxmap)I am not keen on this interface. I think you should take either start+end addresses (inclusive) or start+length (in bytes).
Using
num_pages, and as an unsigned int, seems too easy to fail when applied to a different guest.Do you mean pushing the knowledge of the number of pages to invalidate down to
cputlb.c?
Yes.
In particular, your interface does not allow a single call to invalidate 1/2 of the total address space. Because the type for num_pages isn't large enough.
There's nothing else in the cputlb interface that is page-based, except for "flush one page", and I thought that either
target_ulong addr, target_ulong length, unsigned bits
would be a clearer interface to use.
Quoted 1 line
Because I'm thinking there has to be a loop somewhere that invalidates each page if a full flush isn't being done?
Certainly.
r~
Re: [PATCH v3 1/3] target/arm: Add support for FEAT_TLBIRANGE
In reply to Richard HendersonQuoted 5 lines · Richard Henderson
Quoted 1 line · Rebecca Cran
+
uint64_taddr = (value &0xFFFFFFFFFUL) <<TARGET_PAGE_BITS;The manual does not explicitly say, but I'm certain that this should be a signed address, when regime_has_2_ranges(). Otherwise it would be impossible to flush a range of kernel addresses.
I see other functions have
uint64_t pageaddr = sextract(value...);
Would that be sufficient here too, or do we need to check regime_has_2_ranges()?
Signature · 1 line
Rebecca Cran
Re: [PATCH v3 1/3] target/arm: Add support for FEAT_TLBIRANGE
Quoted 5 lines · Rebecca Cran
Quoted 4 lines · Richard Henderson
Quoted 1 line · Rebecca Cran
+
uint64_taddr = (value &0xFFFFFFFFFUL) <<TARGET_PAGE_BITS;
Quoted 7 lines
Quoted 1 line
The manual does not explicitly say, but I'm certain that this should be a signed address, when regime_has_2_ranges(). Otherwise it would be impossible to flush a range of kernel addresses.
I see other functions have
uint64_tpageaddr = sextract(value...);Would that be sufficient here too, or do we need to check
regime_has_2_ranges()?
We need to check the regime.
r~
Re: [PATCH v3 1/3] target/arm: Add support for FEAT_TLBIRANGE
Quoted 8 lines · Richard Henderson
Quoted 7 lines · Rebecca Cran
Quoted 5 lines · Richard Henderson
Quoted 1 line · Rebecca Cran
+
uint64_taddr = (value &0xFFFFFFFFFUL) <<TARGET_PAGE_BITS;The manual does not explicitly say, but I'm certain that this should be a signed address, when regime_has_2_ranges(). Otherwise it would be impossible to flush a range of kernel addresses.
Quoted 7 lines
Quoted 5 lines
I see other functions have
uint64_tpageaddr = sextract(value...);Would that be sufficient here too, or do we need to check
regime_has_2_ranges()?We need to check the regime.
Thanks. I've just sent out a v4 patch, which I hope is closer to being correct.
Signature · 1 line
Rebecca Cran
PATCH v3 2/3 target/arm: Add support for FEAT_TLBIOS
In reply to Rebecca CranARMv8.4 adds the mandatory FEAT_TLBIOS. It provides TLBI maintenance instructions that extend to the Outer Shareable domain.
--- target/arm/cpu.h | 6 ++ target/arm/helper.c | 75 ++++++++++++++++++++ 2 files changed, 81 insertions(+)
target/arm/cpu.h +6 -0
@@ -4043,6 +4043,12 @@ static inline bool isar_feature_aa64_tlbirange(const ARMISARegisters *id)return FIELD_EX64 (id->id_aa64isar0,ID_AA64ISAR0 ,TLB ) ==2 ; } +static inline bool isar_feature_aa64_tlbios (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64isar0,ID_AA64ISAR0 ,TLB ) ==1 || +FIELD_EX64 (id->id_aa64isar0,ID_AA64ISAR0 ,TLB ) ==2 ; +} +static inline bool isar_feature_aa64_sb (const ARMISARegisters *id) {return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,SB ) !=0 ;
target/arm/helper.c +75 -0
87 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v3 2/3] target/arm: Add support for FEAT_TLBIOS
target/arm/cpu.h static inline bool isar_feature_aa64_tlbirange(const ARMISARegisters *id) · line 4050
Quoted 5 lines · Rebecca Cran
target/arm/cpu.h +5
-0+static inline bool isar_feature_aa64_tlbios (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64isar0,ID_AA64ISAR0 ,TLB ) ==1 || +FIELD_EX64 (id->id_aa64isar0,ID_AA64ISAR0 ,TLB ) ==2 ; +}
The correct test here is != 0. See D13.1.3 Principles of the ID scheme for fields in ID registers.
r~
PATCH v3 3/3 target/arm: set ID_AA64ISAR0.TLB to 2 for max AARCH64 CPU type
In reply to Rebecca CranIndicate support for FEAT_TLBIOS and FEAT_TLBIRANGE by setting ID_AA64ISAR0.TLB to 2 for the max AARCH64 CPU type.
--- target/arm/cpu64.c | 1 + 1 file changed, 1 insertion(+)
target/arm/cpu64.c +1 -0
@@ -651,6 +651,7 @@ static void aarch64_max_initfn(Object *obj) t =FIELD_DP64 (t,ID_AA64ISAR0 ,DP ,1 ); t =FIELD_DP64 (t,ID_AA64ISAR0 ,FHM ,1 ); t =FIELD_DP64 (t,ID_AA64ISAR0 ,TS ,2 );/* v8.5-CondM */ + t =FIELD_DP64 (t,ID_AA64ISAR0 ,TLB ,2 ); t =FIELD_DP64 (t,ID_AA64ISAR0 ,RNDR ,1 ); cpu->isar.id_aa64isar0 = t;
Signature · 1 line
2.26.2
Re: [PATCH v3 3/3] target/arm: set ID_AA64ISAR0.TLB to 2 for max AARCH64 CPU type
target/arm/cpu64.c static void aarch64_max_initfn(Object *obj) · line 654
Quoted 5 lines · Rebecca Cran
target/arm/cpu64.c +1
-0@@ -651,6 +651,7 @@ static void aarch64_max_initfn(Object *obj) t =FIELD_DP64 (t,ID_AA64ISAR0 ,DP ,1 ); t =FIELD_DP64 (t,ID_AA64ISAR0 ,FHM ,1 ); t =FIELD_DP64 (t,ID_AA64ISAR0 ,TS ,2 );/* v8.5-CondM */ + t =FIELD_DP64 (t,ID_AA64ISAR0 ,TLB ,2 );
Just add /* FEAT_TLBIRANGE */ on the line here.
Otherwise,
r~