Skip to contentSkip to conversation

target/arm: Reduce aa64_va_parameter overhead

PATCH Superseded Richard Henderson 2 participants 8 messages Feb 11, 2020 – Feb 16, 2020

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover target/arm: Reduce aa64_va_parameter overhead

Something I noticed while developing and testing VHE. For v2, fix select as a separate patch.

r~

Richard Henderson (2):
target/arm: Fix select for aa64_va_parameters_both target/arm: Split out aa64_va_parameter_tbi, aa64_va_parameter_tbid

 target/arm/internals.h |   3 -
 target/arm/helper.c    | 138 ++++++++++++++++++++++-------------------
 2 files changed, 73 insertions(+), 68 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/2 target/arm: Fix select for aa64_va_parameters_both

Select should always be 0 for a regime with one range.

---
 target/arm/helper.c | 46 +++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)
target/arm/helper.c +24 -22
index 7d15d5c933..a008c70c87 100644
@@ -10074,13 +10074,8 @@ ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va,
     bool tbi, tbid, epd, hpd, using16k, using64k;
     int select, tsz;
 
-    /*
-     * Bit 55 is always between the two regions, and is canonical for
-     * determining if address tagging is enabled.
-     */
-    select = extract64(va, 55, 1);
-
     if (!regime_has_2_ranges(mmu_idx)) {
+        select = 0;
         tsz = extract32(tcr, 0, 6);
         using64k = extract32(tcr, 14, 1);
         using16k = extract32(tcr, 15, 1);
@@ -10093,23 +10088,30 @@ ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va,
             tbid = extract32(tcr, 29, 1);
         }
         epd = false;
-    } else if (!select) {
-        tsz = extract32(tcr, 0, 6);
-        epd = extract32(tcr, 7, 1);
-        using64k = extract32(tcr, 14, 1);
-        using16k = extract32(tcr, 15, 1);
-        tbi = extract64(tcr, 37, 1);
-        hpd = extract64(tcr, 41, 1);
-        tbid = extract64(tcr, 51, 1);
     } else {
-        int tg = extract32(tcr, 30, 2);
-        using16k = tg == 1;
-        using64k = tg == 3;
-        tsz = extract32(tcr, 16, 6);
-        epd = extract32(tcr, 23, 1);
-        tbi = extract64(tcr, 38, 1);
-        hpd = extract64(tcr, 42, 1);
-        tbid = extract64(tcr, 52, 1);
+        /*
+         * Bit 55 is always between the two regions, and is canonical for
+         * determining if address tagging is enabled.
+         */
+        select = extract64(va, 55, 1);
+        if (!select) {
+            tsz = extract32(tcr, 0, 6);
+            epd = extract32(tcr, 7, 1);
+            using64k = extract32(tcr, 14, 1);
+            using16k = extract32(tcr, 15, 1);
+            tbi = extract64(tcr, 37, 1);
+            hpd = extract64(tcr, 41, 1);
+            tbid = extract64(tcr, 51, 1);
+        } else {
+            int tg = extract32(tcr, 30, 2);
+            using16k = tg == 1;
+            using64k = tg == 3;
+            tsz = extract32(tcr, 16, 6);
+            epd = extract32(tcr, 23, 1);
+            tbi = extract64(tcr, 38, 1);
+            hpd = extract64(tcr, 42, 1);
+            tbid = extract64(tcr, 52, 1);
+        }
     }
     tsz = MIN(tsz, 39);  /* TODO: ARMv8.4-TTST */
     tsz = MAX(tsz, 16);  /* TODO: ARMv8.2-LVA  */
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH v2 1/2] target/arm: Fix select for aa64_va_parameters_both

Quoted 4 lines · Richard Henderson

Select should always be 0 for a regime with one range.

This change makes sense, and matches what aa32_va_parameters() does, but I think we need to update some of the callsites.

(1) In get_phys_addr_lpae() we have the check:

        if (-top_bits != param.select || (param.select && !ttbr1_valid)) {

where ttbr1_valid is the return value of (effectively)
aarch64 ? regime_has_2_ranges() : (el != 2);
but I think it's no longer possible to get here with param.select == 1 and !ttbr1_valid, so this becomes a dead check.
(Side note, could we pull "ttbr1_valid = regime_has_2_ranges(mmu_idx);" out of the "if (aarch64) {...} else {...}" ? -- I think it works for aarch32 too, right?)

(2) in pauth_original_ptr() we do

    uint64_t extfield = -param.select;

but in the pseudocode Auth() function the extfield is unconditionally calculated based on bit 55 of the address, regardless of whether the regime has 1 range or 2. So I think this code can't use param.select any more but should simply pull out and replicate bit 55 of its 'ptr' argument, now that param.select is not simply the value of bit 55.

Change 1 would need to be done after this patch and change 2 before it.

thanks
-- PMM

Reviewed-by
#3 lore raw

Re: [PATCH v2 1/2] target/arm: Fix select for aa64_va_parameters_both

Quoted 10 lines · Peter Maydell
Quoted 4 lines · Richard Henderson

Select should always be 0 for a regime with one range.

This change makes sense, and matches what aa32_va_parameters() does, but I think we need to update some of the callsites.

Assuming those changes are done in separate patches, for this patch itself:

thanks
-- PMM

#4 lore raw

Re: [PATCH v2 1/2] target/arm: Fix select for aa64_va_parameters_both

In reply to Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 4 lines · Richard Henderson

Select should always be 0 for a regime with one range.

This change makes sense, and matches what aa32_va_parameters() does, but I think we need to update some of the callsites.

Quoted 8 lines

(1) In get_phys_addr_lpae() we have the check:

        if (-top_bits != param.select || (param.select && !ttbr1_valid)) {

where ttbr1_valid is the return value of (effectively)
aarch64 ? regime_has_2_ranges() : (el != 2);
but I think it's no longer possible to get here with param.select == 1 and !ttbr1_valid, so this becomes a dead check.

...or should the code instead be checking literal pointer bit 55 against ttbr1_valid now ?

thanks
-- PMM

#5 lore raw

Re: [PATCH v2 1/2] target/arm: Fix select for aa64_va_parameters_both

Quoted 16 lines · Peter Maydell
Quoted 15 lines · Peter Maydell
Quoted 4 lines · Richard Henderson

Select should always be 0 for a regime with one range.

This change makes sense, and matches what aa32_va_parameters() does, but I think we need to update some of the callsites.

(1) In get_phys_addr_lpae() we have the check:

        if (-top_bits != param.select || (param.select && !ttbr1_valid)) {
Quoted 7 lines
Quoted 4 lines

where ttbr1_valid is the return value of (effectively)
aarch64 ? regime_has_2_ranges() : (el != 2);
but I think it's no longer possible to get here with param.select == 1 and !ttbr1_valid, so this becomes a dead check.

...or should the code instead be checking literal pointer bit 55 against ttbr1_valid now ?

No, I think the first expression now covers everything, as you suggested in the first reply.

r~

#6 lore raw

PATCH v2 2/2 target/arm: Split out aa64_va_parameter_tbi, aa64_va_parameter_tbid

In reply to Richard Henderson

For the purpose of rebuild_hflags_a64, we do not need to compute all of the va parameters, only tbi. Moreover, we can compute them in a form that is more useful to storing in hflags.

This eliminates the need for aa64_va_parameter_both, so fold that in to aa64_va_parameter. The remaining calls to aa64_va_parameter are in get_phys_addr_lpae and in pauth_helper.c.

This reduces the total cpu consumption of aa64_va_parameter in a kernel boot plus a kvm guest kernel boot from 3% to 0.5%.

---
 target/arm/internals.h |  3 --
 target/arm/helper.c    | 68 +++++++++++++++++++++++-------------------
 2 files changed, 37 insertions(+), 34 deletions(-)
target/arm/internals.h +0 -3
index 6d4a942bde..6ac84bbca7 100644
@@ -1042,15 +1042,12 @@ typedef struct ARMVAParameters {
     unsigned tsz    : 8;
     unsigned select : 1;
     bool tbi        : 1;
-    bool tbid       : 1;
     bool epd        : 1;
     bool hpd        : 1;
     bool using16k   : 1;
     bool using64k   : 1;
 } ARMVAParameters;
 
-ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va,
-                                        ARMMMUIdx mmu_idx);
 ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va,
                                    ARMMMUIdx mmu_idx, bool data);
 
target/arm/helper.c +37 -31

125 lines not on this page · raw message

Signature · 1 line
2.20.1
Reviewed-by on v2 2/2
#7 lore raw

Re: [PATCH v2 2/2] target/arm: Split out aa64_va_parameter_tbi, aa64_va_parameter_tbid

Quoted 5 lines · Richard Henderson

For the purpose of rebuild_hflags_a64, we do not need to compute all of the va parameters, only tbi. Moreover, we can compute them in a form that is more useful to storing in hflags.

Quoted 8 lines

This eliminates the need for aa64_va_parameter_both, so fold that in to aa64_va_parameter. The remaining calls to aa64_va_parameter are in get_phys_addr_lpae and in pauth_helper.c.

This reduces the total cpu consumption of aa64_va_parameter in a kernel boot plus a kvm guest kernel boot from 3% to 0.5%.

thanks
-- PMM