diff mbox series

[RFC,v2,23/26] KVM: arm64: Refactor __populate_fault_info()

Message ID 20210108121524.656872-24-qperret@google.com
State New
Headers show
Series KVM/arm64: A stage 2 for the host | expand

Commit Message

Quentin Perret Jan. 8, 2021, 12:15 p.m. UTC
Refactor __populate_fault_info() to introduce __get_fault_info() which
will be used once the host is wrapped in a stage 2.

Signed-off-by: Quentin Perret <qperret@google.com>
---
 arch/arm64/kvm/hyp/include/hyp/switch.h | 36 +++++++++++++++----------
 1 file changed, 22 insertions(+), 14 deletions(-)

Comments

Will Deacon Feb. 3, 2021, 3:58 p.m. UTC | #1
On Fri, Jan 08, 2021 at 12:15:21PM +0000, Quentin Perret wrote:
> Refactor __populate_fault_info() to introduce __get_fault_info() which

> will be used once the host is wrapped in a stage 2.

> 

> Signed-off-by: Quentin Perret <qperret@google.com>

> ---

>  arch/arm64/kvm/hyp/include/hyp/switch.h | 36 +++++++++++++++----------

>  1 file changed, 22 insertions(+), 14 deletions(-)

> 

> diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h

> index 84473574c2e7..e9005255d639 100644

> --- a/arch/arm64/kvm/hyp/include/hyp/switch.h

> +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h

> @@ -157,19 +157,9 @@ static inline bool __translate_far_to_hpfar(u64 far, u64 *hpfar)

>  	return true;

>  }

>  

> -static inline bool __populate_fault_info(struct kvm_vcpu *vcpu)

> +static inline bool __get_fault_info(u64 esr, u64 *far, u64 *hpfar)


Could this take a pointer to a struct kvm_vcpu_fault_info instead?

Will
Quentin Perret Feb. 4, 2021, 2:18 p.m. UTC | #2
On Wednesday 03 Feb 2021 at 15:58:32 (+0000), Will Deacon wrote:
> On Fri, Jan 08, 2021 at 12:15:21PM +0000, Quentin Perret wrote:

> > Refactor __populate_fault_info() to introduce __get_fault_info() which

> > will be used once the host is wrapped in a stage 2.

> > 

> > Signed-off-by: Quentin Perret <qperret@google.com>

> > ---

> >  arch/arm64/kvm/hyp/include/hyp/switch.h | 36 +++++++++++++++----------

> >  1 file changed, 22 insertions(+), 14 deletions(-)

> > 

> > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h

> > index 84473574c2e7..e9005255d639 100644

> > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h

> > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h

> > @@ -157,19 +157,9 @@ static inline bool __translate_far_to_hpfar(u64 far, u64 *hpfar)

> >  	return true;

> >  }

> >  

> > -static inline bool __populate_fault_info(struct kvm_vcpu *vcpu)

> > +static inline bool __get_fault_info(u64 esr, u64 *far, u64 *hpfar)

> 

> Could this take a pointer to a struct kvm_vcpu_fault_info instead?


The disr_el1 field will be unused in this case, but yes, that should
work.

Cheers,
Quentin
diff mbox series

Patch

diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h
index 84473574c2e7..e9005255d639 100644
--- a/arch/arm64/kvm/hyp/include/hyp/switch.h
+++ b/arch/arm64/kvm/hyp/include/hyp/switch.h
@@ -157,19 +157,9 @@  static inline bool __translate_far_to_hpfar(u64 far, u64 *hpfar)
 	return true;
 }
 
-static inline bool __populate_fault_info(struct kvm_vcpu *vcpu)
+static inline bool __get_fault_info(u64 esr, u64 *far, u64 *hpfar)
 {
-	u8 ec;
-	u64 esr;
-	u64 hpfar, far;
-
-	esr = vcpu->arch.fault.esr_el2;
-	ec = ESR_ELx_EC(esr);
-
-	if (ec != ESR_ELx_EC_DABT_LOW && ec != ESR_ELx_EC_IABT_LOW)
-		return true;
-
-	far = read_sysreg_el2(SYS_FAR);
+	*far = read_sysreg_el2(SYS_FAR);
 
 	/*
 	 * The HPFAR can be invalid if the stage 2 fault did not
@@ -185,12 +175,30 @@  static inline bool __populate_fault_info(struct kvm_vcpu *vcpu)
 	if (!(esr & ESR_ELx_S1PTW) &&
 	    (cpus_have_final_cap(ARM64_WORKAROUND_834220) ||
 	     (esr & ESR_ELx_FSC_TYPE) == FSC_PERM)) {
-		if (!__translate_far_to_hpfar(far, &hpfar))
+		if (!__translate_far_to_hpfar(*far, hpfar))
 			return false;
 	} else {
-		hpfar = read_sysreg(hpfar_el2);
+		*hpfar = read_sysreg(hpfar_el2);
 	}
 
+	return true;
+}
+
+static inline bool __populate_fault_info(struct kvm_vcpu *vcpu)
+{
+	u8 ec;
+	u64 esr;
+	u64 hpfar, far;
+
+	esr = vcpu->arch.fault.esr_el2;
+	ec = ESR_ELx_EC(esr);
+
+	if (ec != ESR_ELx_EC_DABT_LOW && ec != ESR_ELx_EC_IABT_LOW)
+		return true;
+
+	if (!__get_fault_info(esr, &far, &hpfar))
+		return false;
+
 	vcpu->arch.fault.far_el2 = far;
 	vcpu->arch.fault.hpfar_el2 = hpfar;
 	return true;