Re: [PATCH v5 08/12] KVM: arm64: re-factor hyp.S debug register code

2015-06-04 Thread Christoffer Dall
On Thu, Jun 04, 2015 at 11:34:46AM +0100, Alex Bennée wrote:
> 
> Christoffer Dall  writes:
> 
> > On Fri, May 29, 2015 at 10:30:24AM +0100, Alex Bennée wrote:
> >> This is a pre-cursor to sharing the code with the guest debug support.
> >> This replaces the big macro that fishes data out of a fixed location
> >> with a more general helper macro to restore a set of debug registers. It
> >> uses macro substitution so it can be re-used for debug control and value
> >> registers. It does however rely on the debug registers being 64 bit
> >> aligned (as they happen to be in the hyp ABI).
> 
> Oops I'd better fix that commit comment.
> 
> >> 
> >> Signed-off-by: Alex Bennée 
> >> 
> >> ---
> >> v3:
> >>   - return to the patch series
> >>   - add save and restore targets
> >>   - change register use and document
> >> v4:
> >>   - keep original setup/restore names
> >>   - don't use split u32/u64 structure yet
> >> ---
> >>  arch/arm64/kvm/hyp.S | 519 
> >> ++-
> >>  1 file changed, 140 insertions(+), 379 deletions(-)
> >> 
> >> diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
> >> index 74e63d8..9c4897d 100644
> >> --- a/arch/arm64/kvm/hyp.S
> >> +++ b/arch/arm64/kvm/hyp.S
> >
> >
> > [...]
> >
> >> @@ -465,195 +318,52 @@
> >>msr mdscr_el1,  x25
> >>  .endm
> >>  
> >> -.macro restore_debug
> >> -  // x2: base address for cpu context
> >> -  // x3: tmp register
> >> -
> >> -  mrs x26, id_aa64dfr0_el1
> >> -  ubfxx24, x26, #12, #4   // Extract BRPs
> >> -  ubfxx25, x26, #20, #4   // Extract WRPs
> >> -  mov w26, #15
> >> -  sub w24, w26, w24   // How many BPs to skip
> >> -  sub w25, w26, w25   // How many WPs to skip
> >> -
> >> -  add x3, x2, #CPU_SYSREG_OFFSET(DBGBCR0_EL1)
> >> +.macro restore_debug type
> >> +// x4: pointer to register set
> >> +// x5: number of registers to skip
> >
> > nit: use tabs instead of spaces here...
> >
> >> +  // x6..x22 trashed
> >>  
> >
> > [...]
> >
> >> @@ -887,12 +597,63 @@ __restore_sysregs:
> >>restore_sysregs
> >>ret
> >>  
> >> +/* Save debug state */
> >>  __save_debug:
> >> -  save_debug
> >> +  // x0: base address for vcpu context
> >> +  // x2: ptr to current CPU context
> >> +  // x4/x5: trashed
> >
> > I had a bunch of questions here which I think you missed last time
> > around:
> >  1. why do we need the vcpu context?
> 
> We don't, I'll drop that
> 
> >  2. what does 'current' mean here?
> 
> Either the host or vcpu context depending which way we are currently going.
> 

drop 'current' please.

> >  3. you're also trashing everything that save_debug trashes, so x4/5,
> > x6-x22 trashed would be more correct
> 
> OK
> 
> >
> >> +
> >> +  mrs x26, id_aa64dfr0_el1
> >> +  ubfxx24, x26, #12, #4   // Extract BRPs
> >> +  ubfxx25, x26, #20, #4   // Extract WRPs
> >> +  mov w26, #15
> >> +  sub w24, w26, w24   // How many BPs to skip
> >> +  sub w25, w26, w25   // How many WPs to skip
> >> +
> >> +  mov x5, x24
> >> +  add x4, x2, #CPU_SYSREG_OFFSET(DBGBCR0_EL1)
> >> +  save_debug dbgbcr
> >> +  add x4, x2, #CPU_SYSREG_OFFSET(DBGBVR0_EL1)
> >> +  save_debug dbgbvr
> >> +
> >> +  mov x5, x25
> >> +  add x4, x2, #CPU_SYSREG_OFFSET(DBGWCR0_EL1)
> >> +  save_debug dbgwcr
> >> +  add x4, x2, #CPU_SYSREG_OFFSET(DBGWVR0_EL1)
> >> +  save_debug dbgwvr
> >> +
> >> +  mrs x21, mdccint_el1
> >> +  str x21, [x2, #CPU_SYSREG_OFFSET(MDCCINT_EL1)]
> >>ret
> >>  
> >> +/* Restore debug state */
> >>  __restore_debug:
> >> -  restore_debug
> >> +  // x0: base address for cpu context
> >> +  // x2: ptr to current CPU context
> >> +  // x4/x5: trashed
> >
> > and you missed these comments too, basically same stuff, but why was it
> > 'cpu' here and not 'vcpu' like above?
> 
> Again we use the functions both for restoring host and vcpu debug context.
> 
Well, the two functions operate on the same structures, so I would like
them to be consistent...

-Christoffer
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 08/12] KVM: arm64: re-factor hyp.S debug register code

2015-06-04 Thread Alex Bennée

Christoffer Dall  writes:

> On Fri, May 29, 2015 at 10:30:24AM +0100, Alex Bennée wrote:
>> This is a pre-cursor to sharing the code with the guest debug support.
>> This replaces the big macro that fishes data out of a fixed location
>> with a more general helper macro to restore a set of debug registers. It
>> uses macro substitution so it can be re-used for debug control and value
>> registers. It does however rely on the debug registers being 64 bit
>> aligned (as they happen to be in the hyp ABI).

Oops I'd better fix that commit comment.

>> 
>> Signed-off-by: Alex Bennée 
>> 
>> ---
>> v3:
>>   - return to the patch series
>>   - add save and restore targets
>>   - change register use and document
>> v4:
>>   - keep original setup/restore names
>>   - don't use split u32/u64 structure yet
>> ---
>>  arch/arm64/kvm/hyp.S | 519 
>> ++-
>>  1 file changed, 140 insertions(+), 379 deletions(-)
>> 
>> diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
>> index 74e63d8..9c4897d 100644
>> --- a/arch/arm64/kvm/hyp.S
>> +++ b/arch/arm64/kvm/hyp.S
>
>
> [...]
>
>> @@ -465,195 +318,52 @@
>>  msr mdscr_el1,  x25
>>  .endm
>>  
>> -.macro restore_debug
>> -// x2: base address for cpu context
>> -// x3: tmp register
>> -
>> -mrs x26, id_aa64dfr0_el1
>> -ubfxx24, x26, #12, #4   // Extract BRPs
>> -ubfxx25, x26, #20, #4   // Extract WRPs
>> -mov w26, #15
>> -sub w24, w26, w24   // How many BPs to skip
>> -sub w25, w26, w25   // How many WPs to skip
>> -
>> -add x3, x2, #CPU_SYSREG_OFFSET(DBGBCR0_EL1)
>> +.macro restore_debug type
>> +// x4: pointer to register set
>> +// x5: number of registers to skip
>
> nit: use tabs instead of spaces here...
>
>> +// x6..x22 trashed
>>  
>
> [...]
>
>> @@ -887,12 +597,63 @@ __restore_sysregs:
>>  restore_sysregs
>>  ret
>>  
>> +/* Save debug state */
>>  __save_debug:
>> -save_debug
>> +// x0: base address for vcpu context
>> +// x2: ptr to current CPU context
>> +// x4/x5: trashed
>
> I had a bunch of questions here which I think you missed last time
> around:
>  1. why do we need the vcpu context?

We don't, I'll drop that

>  2. what does 'current' mean here?

Either the host or vcpu context depending which way we are currently going.

>  3. you're also trashing everything that save_debug trashes, so x4/5,
> x6-x22 trashed would be more correct

OK

>
>> +
>> +mrs x26, id_aa64dfr0_el1
>> +ubfxx24, x26, #12, #4   // Extract BRPs
>> +ubfxx25, x26, #20, #4   // Extract WRPs
>> +mov w26, #15
>> +sub w24, w26, w24   // How many BPs to skip
>> +sub w25, w26, w25   // How many WPs to skip
>> +
>> +mov x5, x24
>> +add x4, x2, #CPU_SYSREG_OFFSET(DBGBCR0_EL1)
>> +save_debug dbgbcr
>> +add x4, x2, #CPU_SYSREG_OFFSET(DBGBVR0_EL1)
>> +save_debug dbgbvr
>> +
>> +mov x5, x25
>> +add x4, x2, #CPU_SYSREG_OFFSET(DBGWCR0_EL1)
>> +save_debug dbgwcr
>> +add x4, x2, #CPU_SYSREG_OFFSET(DBGWVR0_EL1)
>> +save_debug dbgwvr
>> +
>> +mrs x21, mdccint_el1
>> +str x21, [x2, #CPU_SYSREG_OFFSET(MDCCINT_EL1)]
>>  ret
>>  
>> +/* Restore debug state */
>>  __restore_debug:
>> -restore_debug
>> +// x0: base address for cpu context
>> +// x2: ptr to current CPU context
>> +// x4/x5: trashed
>
> and you missed these comments too, basically same stuff, but why was it
> 'cpu' here and not 'vcpu' like above?

Again we use the functions both for restoring host and vcpu debug context.

>
> note again, that you're explicitly touching x24, xx25, and x26 here as
> well, so shouldn't they be listed as trashed?
>
>> +
>> +mrs x26, id_aa64dfr0_el1
>> +ubfxx24, x26, #12, #4   // Extract BRPs
>> +ubfxx25, x26, #20, #4   // Extract WRPs
>> +mov w26, #15
>> +sub w24, w26, w24   // How many BPs to skip
>> +sub w25, w26, w25   // How many WPs to skip
>> +
>> +mov x5, x24
>> +add x4, x2, #CPU_SYSREG_OFFSET(DBGBCR0_EL1)
>> +restore_debug dbgbcr
>> +add x4, x2, #CPU_SYSREG_OFFSET(DBGBVR0_EL1)
>> +restore_debug dbgbvr
>> +
>> +mov x5, x25
>> +add x4, x2, #CPU_SYSREG_OFFSET(DBGWCR0_EL1)
>> +restore_debug dbgwcr
>> +add x4, x2, #CPU_SYSREG_OFFSET(DBGWVR0_EL1)
>> +restore_debug dbgwvr
>> +
>> +ldr x21, [x2, #CPU_SYSREG_OFFSET(MDCCINT_EL1)]
>> +msr mdccint_el1, x21
>> +
>>  ret
>>  
>>  __save_fpsimd:
>
> Thanks,
> -Christoffer

-- 
Alex Bennée
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 08/12] KVM: arm64: re-factor hyp.S debug register code

2015-06-04 Thread Christoffer Dall
On Fri, May 29, 2015 at 10:30:24AM +0100, Alex Bennée wrote:
> This is a pre-cursor to sharing the code with the guest debug support.
> This replaces the big macro that fishes data out of a fixed location
> with a more general helper macro to restore a set of debug registers. It
> uses macro substitution so it can be re-used for debug control and value
> registers. It does however rely on the debug registers being 64 bit
> aligned (as they happen to be in the hyp ABI).
> 
> Signed-off-by: Alex Bennée 
> 
> ---
> v3:
>   - return to the patch series
>   - add save and restore targets
>   - change register use and document
> v4:
>   - keep original setup/restore names
>   - don't use split u32/u64 structure yet
> ---
>  arch/arm64/kvm/hyp.S | 519 
> ++-
>  1 file changed, 140 insertions(+), 379 deletions(-)
> 
> diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
> index 74e63d8..9c4897d 100644
> --- a/arch/arm64/kvm/hyp.S
> +++ b/arch/arm64/kvm/hyp.S


[...]

> @@ -465,195 +318,52 @@
>   msr mdscr_el1,  x25
>  .endm
>  
> -.macro restore_debug
> - // x2: base address for cpu context
> - // x3: tmp register
> -
> - mrs x26, id_aa64dfr0_el1
> - ubfxx24, x26, #12, #4   // Extract BRPs
> - ubfxx25, x26, #20, #4   // Extract WRPs
> - mov w26, #15
> - sub w24, w26, w24   // How many BPs to skip
> - sub w25, w26, w25   // How many WPs to skip
> -
> - add x3, x2, #CPU_SYSREG_OFFSET(DBGBCR0_EL1)
> +.macro restore_debug type
> +// x4: pointer to register set
> +// x5: number of registers to skip

nit: use tabs instead of spaces here...

> + // x6..x22 trashed
>  

[...]

> @@ -887,12 +597,63 @@ __restore_sysregs:
>   restore_sysregs
>   ret
>  
> +/* Save debug state */
>  __save_debug:
> - save_debug
> + // x0: base address for vcpu context
> + // x2: ptr to current CPU context
> + // x4/x5: trashed

I had a bunch of questions here which I think you missed last time
around:
 1. why do we need the vcpu context?
 2. what does 'current' mean here?
 3. you're also trashing everything that save_debug trashes, so x4/5,
x6-x22 trashed would be more correct

> +
> + mrs x26, id_aa64dfr0_el1
> + ubfxx24, x26, #12, #4   // Extract BRPs
> + ubfxx25, x26, #20, #4   // Extract WRPs
> + mov w26, #15
> + sub w24, w26, w24   // How many BPs to skip
> + sub w25, w26, w25   // How many WPs to skip
> +
> + mov x5, x24
> + add x4, x2, #CPU_SYSREG_OFFSET(DBGBCR0_EL1)
> + save_debug dbgbcr
> + add x4, x2, #CPU_SYSREG_OFFSET(DBGBVR0_EL1)
> + save_debug dbgbvr
> +
> + mov x5, x25
> + add x4, x2, #CPU_SYSREG_OFFSET(DBGWCR0_EL1)
> + save_debug dbgwcr
> + add x4, x2, #CPU_SYSREG_OFFSET(DBGWVR0_EL1)
> + save_debug dbgwvr
> +
> + mrs x21, mdccint_el1
> + str x21, [x2, #CPU_SYSREG_OFFSET(MDCCINT_EL1)]
>   ret
>  
> +/* Restore debug state */
>  __restore_debug:
> - restore_debug
> + // x0: base address for cpu context
> + // x2: ptr to current CPU context
> + // x4/x5: trashed

and you missed these comments too, basically same stuff, but why was it
'cpu' here and not 'vcpu' like above?

note again, that you're explicitly touching x24, xx25, and x26 here as
well, so shouldn't they be listed as trashed?

> +
> + mrs x26, id_aa64dfr0_el1
> + ubfxx24, x26, #12, #4   // Extract BRPs
> + ubfxx25, x26, #20, #4   // Extract WRPs
> + mov w26, #15
> + sub w24, w26, w24   // How many BPs to skip
> + sub w25, w26, w25   // How many WPs to skip
> +
> + mov x5, x24
> + add x4, x2, #CPU_SYSREG_OFFSET(DBGBCR0_EL1)
> + restore_debug dbgbcr
> + add x4, x2, #CPU_SYSREG_OFFSET(DBGBVR0_EL1)
> + restore_debug dbgbvr
> +
> + mov x5, x25
> + add x4, x2, #CPU_SYSREG_OFFSET(DBGWCR0_EL1)
> + restore_debug dbgwcr
> + add x4, x2, #CPU_SYSREG_OFFSET(DBGWVR0_EL1)
> + restore_debug dbgwvr
> +
> + ldr x21, [x2, #CPU_SYSREG_OFFSET(MDCCINT_EL1)]
> + msr mdccint_el1, x21
> +
>   ret
>  
>  __save_fpsimd:

Thanks,
-Christoffer
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 08/12] KVM: arm64: re-factor hyp.S debug register code

2015-05-29 Thread Alex Bennée
This is a pre-cursor to sharing the code with the guest debug support.
This replaces the big macro that fishes data out of a fixed location
with a more general helper macro to restore a set of debug registers. It
uses macro substitution so it can be re-used for debug control and value
registers. It does however rely on the debug registers being 64 bit
aligned (as they happen to be in the hyp ABI).

Signed-off-by: Alex Bennée 

---
v3:
  - return to the patch series
  - add save and restore targets
  - change register use and document
v4:
  - keep original setup/restore names
  - don't use split u32/u64 structure yet
---
 arch/arm64/kvm/hyp.S | 519 ++-
 1 file changed, 140 insertions(+), 379 deletions(-)

diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
index 74e63d8..9c4897d 100644
--- a/arch/arm64/kvm/hyp.S
+++ b/arch/arm64/kvm/hyp.S
@@ -228,199 +228,52 @@
stp x24, x25, [x3, #160]
 .endm
 
-.macro save_debug
-   // x2: base address for cpu context
-   // x3: tmp register
-
-   mrs x26, id_aa64dfr0_el1
-   ubfxx24, x26, #12, #4   // Extract BRPs
-   ubfxx25, x26, #20, #4   // Extract WRPs
-   mov w26, #15
-   sub w24, w26, w24   // How many BPs to skip
-   sub w25, w26, w25   // How many WPs to skip
-
-   add x3, x2, #CPU_SYSREG_OFFSET(DBGBCR0_EL1)
-
-   adr x26, 1f
-   add x26, x26, x24, lsl #2
-   br  x26
-1:
-   mrs x20, dbgbcr15_el1
-   mrs x19, dbgbcr14_el1
-   mrs x18, dbgbcr13_el1
-   mrs x17, dbgbcr12_el1
-   mrs x16, dbgbcr11_el1
-   mrs x15, dbgbcr10_el1
-   mrs x14, dbgbcr9_el1
-   mrs x13, dbgbcr8_el1
-   mrs x12, dbgbcr7_el1
-   mrs x11, dbgbcr6_el1
-   mrs x10, dbgbcr5_el1
-   mrs x9, dbgbcr4_el1
-   mrs x8, dbgbcr3_el1
-   mrs x7, dbgbcr2_el1
-   mrs x6, dbgbcr1_el1
-   mrs x5, dbgbcr0_el1
-
-   adr x26, 1f
-   add x26, x26, x24, lsl #2
-   br  x26
-
-1:
-   str x20, [x3, #(15 * 8)]
-   str x19, [x3, #(14 * 8)]
-   str x18, [x3, #(13 * 8)]
-   str x17, [x3, #(12 * 8)]
-   str x16, [x3, #(11 * 8)]
-   str x15, [x3, #(10 * 8)]
-   str x14, [x3, #(9 * 8)]
-   str x13, [x3, #(8 * 8)]
-   str x12, [x3, #(7 * 8)]
-   str x11, [x3, #(6 * 8)]
-   str x10, [x3, #(5 * 8)]
-   str x9, [x3, #(4 * 8)]
-   str x8, [x3, #(3 * 8)]
-   str x7, [x3, #(2 * 8)]
-   str x6, [x3, #(1 * 8)]
-   str x5, [x3, #(0 * 8)]
-
-   add x3, x2, #CPU_SYSREG_OFFSET(DBGBVR0_EL1)
-
-   adr x26, 1f
-   add x26, x26, x24, lsl #2
-   br  x26
-1:
-   mrs x20, dbgbvr15_el1
-   mrs x19, dbgbvr14_el1
-   mrs x18, dbgbvr13_el1
-   mrs x17, dbgbvr12_el1
-   mrs x16, dbgbvr11_el1
-   mrs x15, dbgbvr10_el1
-   mrs x14, dbgbvr9_el1
-   mrs x13, dbgbvr8_el1
-   mrs x12, dbgbvr7_el1
-   mrs x11, dbgbvr6_el1
-   mrs x10, dbgbvr5_el1
-   mrs x9, dbgbvr4_el1
-   mrs x8, dbgbvr3_el1
-   mrs x7, dbgbvr2_el1
-   mrs x6, dbgbvr1_el1
-   mrs x5, dbgbvr0_el1
-
-   adr x26, 1f
-   add x26, x26, x24, lsl #2
-   br  x26
-
-1:
-   str x20, [x3, #(15 * 8)]
-   str x19, [x3, #(14 * 8)]
-   str x18, [x3, #(13 * 8)]
-   str x17, [x3, #(12 * 8)]
-   str x16, [x3, #(11 * 8)]
-   str x15, [x3, #(10 * 8)]
-   str x14, [x3, #(9 * 8)]
-   str x13, [x3, #(8 * 8)]
-   str x12, [x3, #(7 * 8)]
-   str x11, [x3, #(6 * 8)]
-   str x10, [x3, #(5 * 8)]
-   str x9, [x3, #(4 * 8)]
-   str x8, [x3, #(3 * 8)]
-   str x7, [x3, #(2 * 8)]
-   str x6, [x3, #(1 * 8)]
-   str x5, [x3, #(0 * 8)]
-
-   add x3, x2, #CPU_SYSREG_OFFSET(DBGWCR0_EL1)
-
-   adr x26, 1f
-   add x26, x26, x25, lsl #2
-   br  x26
+.macro save_debug type
+   // x4: pointer to register set
+   // x5: number of registers to skip
+   // x6..x22 trashed
+
+   adr x22, 1f
+   add x22, x22, x5, lsl #2
+   br  x22
 1:
-   mrs x20, dbgwcr15_el1
-   mrs x19, dbgwcr14_el1
-   mrs x18, dbgwcr13_el1
-   mrs x17, dbgwcr12_el1
-   mrs x16, dbgwcr11_el1
-   mrs x15, dbgwcr10_el1
-   mrs x14, dbgwcr9_el1
-   mrs x13, dbgwcr8_el1
-   mrs x12, dbgwcr7_el1
-   mrs x11, dbgwcr6_el1
-   mrs x10, dbgwcr5_el1
-   mrs x9, dbgwcr4_el1
-   mrs x8, dbgwcr3_el1
-   mrs x7, dbgwcr2_el1
-   mrs x6, dbgwcr1_el1
-   mrs x5, dbgwcr0_el1
-
-   adr x26, 1f
-   add x26, x26, x25,