From: Wei Chen <Wei.Chen@arm.com>
To: xen-devel@lists.xen.org
Cc: sstabellini@kernel.org, wei.chen@arm.com, steve.capper@arm.com,
Kaly.Xin@arm.com, julien.grall@arm.com, nd@arm.com
Subject: [PATCH v2 04/19] xen/arm: Restore HCR_EL2 register
Date: Thu, 30 Mar 2017 17:13:14 +0800 [thread overview]
Message-ID: <1490865209-18283-5-git-send-email-Wei.Chen@arm.com> (raw)
In-Reply-To: <1490865209-18283-1-git-send-email-Wei.Chen@arm.com>
Different domains may have different HCR_EL2 flags. For example, the
64-bit domain needs HCR_RW flag but the 32-bit does not need it. So
we give each domain a default HCR_EL2 value and save it in the vCPU's
context.
HCR_EL2 register has only one bit can be updated automatically without
explicit write (HCR_VSE). But we haven't used this bit currently, so
we can consider that the HCR_EL2 register will not be modified while
the guest is running. So save the HCR_EL2 while guest exiting to
hypervisor is not neccessary. We just have to restore this register for
each vCPU while context switching.
The p2m_restore_state which will be invoked in context switch progress
has included the writing of HCR_EL2 already. It updates the HCR_EL2.RW
bit to tell the hardware how to interpret the stage-1 page table as the
encodings are different between AArch64 and AArch32. We can reuse this
write to restore the HCR_EL2 for each vCPU. Of course, the value of each
vCPU's HCR_EL2 should be adjusted to have proper HCR_EL2.RW bit in this
function. In the later patch of this series, we will set the HCR_EL2.RW
for each vCPU while the domain is creating.
Signed-off-by: wei chen <Wei.Chen@arm.com>
---
v1->v2:
1. Use vwfi to set HCR_EL2 for each vCPU directly.
2. Back HCR_EL2 for idle vCPU to avoid using p2m_restore_state with
an uninitialized HCR_EL2 value in context.
3. Remove writing to HCR_EL2 from leave_hypervisor_tail.
4. Update commit message to explain why restore HCR_EL2 in
p2m_restore_state.
---
xen/arch/arm/domain.c | 4 ++++
xen/arch/arm/domain_build.c | 7 +++++++
xen/arch/arm/p2m.c | 9 +++------
xen/include/asm-arm/domain.h | 3 +++
4 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index a327a3b..c69e204 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -527,6 +527,10 @@ int vcpu_initialise(struct vcpu *v)
v->arch.actlr = READ_SYSREG32(ACTLR_EL1);
+ v->arch.hcr_el2 = HCR_PTW|HCR_BSU_INNER|HCR_AMO|HCR_IMO|HCR_FMO|HCR_VM|
+ (vwfi != NATIVE ? (HCR_TWI|HCR_TWE) : 0) |
+ HCR_TSC|HCR_TAC|HCR_SWIO|HCR_TIDCP|HCR_FB;
+
processor_vcpu_initialise(v);
if ( (rc = vcpu_vgic_init(v)) != 0 )
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index de59e5f..8af223e 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2171,6 +2171,13 @@ int construct_dom0(struct domain *d)
return rc;
/*
+ * The HCR_EL2 will temporarily switch to dom0's HCR_EL2 value
+ * by p2m_restore_state. We have to save HCR_EL2 to idle vCPU's
+ * context for restoring it in later.
+ */
+ current->arch.hcr_el2 = READ_SYSREG(HCR_EL2);
+
+ /*
* The following loads use the domain's p2m and require current to
* be a vcpu of the domain, temporarily switch
*/
diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index 6263760..83c4b7d 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -128,27 +128,24 @@ void p2m_save_state(struct vcpu *p)
void p2m_restore_state(struct vcpu *n)
{
- register_t hcr;
struct p2m_domain *p2m = &n->domain->arch.p2m;
uint8_t *last_vcpu_ran;
if ( is_idle_vcpu(n) )
return;
- hcr = READ_SYSREG(HCR_EL2);
-
WRITE_SYSREG64(p2m->vttbr, VTTBR_EL2);
isb();
if ( is_32bit_domain(n->domain) )
- hcr &= ~HCR_RW;
+ n->arch.hcr_el2 &= ~HCR_RW;
else
- hcr |= HCR_RW;
+ n->arch.hcr_el2 |= HCR_RW;
WRITE_SYSREG(n->arch.sctlr, SCTLR_EL1);
isb();
- WRITE_SYSREG(hcr, HCR_EL2);
+ WRITE_SYSREG(n->arch.hcr_el2, HCR_EL2);
isb();
last_vcpu_ran = &p2m->last_vcpu_ran[smp_processor_id()];
diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h
index 09fe502..7b1dacc 100644
--- a/xen/include/asm-arm/domain.h
+++ b/xen/include/asm-arm/domain.h
@@ -204,6 +204,9 @@ struct arch_vcpu
register_t tpidr_el1;
register_t tpidrro_el0;
+ /* HYP configuration */
+ register_t hcr_el2;
+
uint32_t teecr, teehbr; /* ThumbEE, 32-bit guests only */
#ifdef CONFIG_ARM_32
/*
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-03-30 9:13 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-30 9:13 [PATCH v2 00/19] Provide a command line option to choose how to handle SErrors Wei Chen
2017-03-30 9:13 ` [PATCH v2 01/19] xen/arm: Save ESR_EL2 to avoid using mismatched value in syndrome check Wei Chen
2017-03-30 13:31 ` Julien Grall
2017-03-31 3:26 ` Wei Chen
2017-03-30 9:13 ` [PATCH v2 02/19] xen/arm: Remove vwfi while setting HCR_EL2 in init_traps Wei Chen
2017-03-30 17:05 ` Julien Grall
2017-03-30 22:29 ` Stefano Stabellini
2017-03-31 5:58 ` Wei Chen
2017-03-31 8:34 ` Julien Grall
2017-03-30 9:13 ` [PATCH v2 03/19] xen/arm: Move parse_vwfi from trap.c to domain.c Wei Chen
2017-03-30 9:13 ` Wei Chen [this message]
2017-03-30 17:07 ` [PATCH v2 04/19] xen/arm: Restore HCR_EL2 register Julien Grall
2017-03-30 22:03 ` Stefano Stabellini
2017-03-31 2:10 ` Wei Chen
2017-03-31 8:39 ` Julien Grall
2017-03-31 8:59 ` Wei Chen
2017-03-30 9:13 ` [PATCH v2 05/19] xen/arm: Avoid setting/clearing HCR_RW at every context switch Wei Chen
2017-03-30 17:12 ` Julien Grall
2017-03-30 21:21 ` Stefano Stabellini
2017-03-30 9:13 ` [PATCH v2 06/19] xen/arm: Save HCR_EL2 when a guest took the SError Wei Chen
2017-03-30 9:13 ` [PATCH v2 07/19] xen/arm: Introduce a virtual abort injection helper Wei Chen
2017-03-30 17:20 ` Julien Grall
2017-03-30 21:24 ` Stefano Stabellini
2017-03-31 5:25 ` Wei Chen
2017-03-30 9:13 ` [PATCH v2 08/19] xen/arm: Introduce a command line parameter for SErrors/Aborts Wei Chen
2017-03-30 17:39 ` Julien Grall
2017-03-31 5:28 ` Wei Chen
2017-03-30 9:13 ` [PATCH v2 09/19] xen/arm: Introduce a initcall to update cpu_hwcaps by serror_op Wei Chen
2017-03-30 17:51 ` Julien Grall
2017-03-30 18:02 ` Julien Grall
2017-03-30 21:28 ` Stefano Stabellini
2017-03-31 8:50 ` Julien Grall
2017-03-30 9:13 ` [PATCH v2 10/19] xen/arm64: Use alternative to skip the check of pending serrors Wei Chen
2017-03-30 9:13 ` [PATCH v2 11/19] xen/arm32: " Wei Chen
2017-03-30 18:06 ` Julien Grall
2017-03-30 21:29 ` Stefano Stabellini
2017-03-31 5:33 ` Wei Chen
2017-03-30 9:13 ` [PATCH v2 12/19] xen/arm: Move macro VABORT_GEN_BY_GUEST to common header Wei Chen
2017-03-30 21:36 ` Stefano Stabellini
2017-03-31 5:35 ` Wei Chen
2017-03-30 9:13 ` [PATCH v2 13/19] xen/arm: Introduce new helpers to handle guest/hyp SErrors Wei Chen
2017-03-30 9:13 ` [PATCH v2 14/19] xen/arm: Replace do_trap_guest_serror with new helpers Wei Chen
2017-03-30 9:13 ` [PATCH v2 15/19] xen/arm: Unmask the Abort/SError bit in the exception entries Wei Chen
2017-03-30 9:13 ` [PATCH v2 16/19] xen/arm: Introduce a helper to synchronize SError Wei Chen
2017-03-30 18:28 ` Julien Grall
2017-03-30 18:32 ` Julien Grall
2017-03-30 18:37 ` Julien Grall
2017-03-31 5:51 ` Wei Chen
2017-03-31 10:55 ` Wei Chen
2017-03-31 11:06 ` Julien Grall
2017-03-31 11:09 ` Wei Chen
2017-03-30 9:13 ` [PATCH v2 17/19] xen/arm: Isolate the SError between the context switch of 2 vCPUs Wei Chen
2017-03-30 21:49 ` Stefano Stabellini
2017-03-30 22:00 ` Julien Grall
2017-03-31 5:52 ` Wei Chen
2017-03-30 9:13 ` [PATCH v2 18/19] xen/arm: Prevent slipping hypervisor SError to guest Wei Chen
2017-03-30 9:13 ` [PATCH v2 19/19] xen/arm: Handle guest external abort as guest SError Wei Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1490865209-18283-5-git-send-email-Wei.Chen@arm.com \
--to=wei.chen@arm.com \
--cc=Kaly.Xin@arm.com \
--cc=julien.grall@arm.com \
--cc=nd@arm.com \
--cc=sstabellini@kernel.org \
--cc=steve.capper@arm.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).