From: Fedorov Sergey <s.fedorov@samsung.com>
To: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
a.basov@samsung.com,
"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
Johannes Winter <johannes.winter@iaik.tugraz.at>
Subject: Re: [Qemu-devel] [RFC PATCH 18/21] target-arm: switch banked CP registers
Date: Thu, 19 Dec 2013 11:27:33 +0400 [thread overview]
Message-ID: <52B29FE5.40705@samsung.com> (raw)
In-Reply-To: <CAEgOgz7SNq24uSMdPQru2JchKwL4SBDDWKZRjUtGQJYzgYhBCw@mail.gmail.com>
On 12/19/2013 08:37 AM, Peter Crosthwaite wrote:
> On Tue, Dec 3, 2013 at 6:48 PM, Sergey Fedorov <s.fedorov@samsung.com> wrote:
>> Banked coprocessor registers are switched on two cases:
>> 1) Entering or leaving CPU monitor mode with SCR.NS bit set;
>> 2) Setting SCR.NS bit not from CPU monitor mode
>>
>> Coprocessor register banking is done similar to CPU core register
>> banking. Some of SCTRL bits are common for secure and non-secure state.
>> Translation table base masks are updated on register switch instead
>> of TTBCR write.
>>
> So I was rather confused as to your banking scheme until I got to this
> patch. Now I see the implementation. You are mass-hot-swapping in the
> active state on critical CPU state changing events. ....
>
>> Signed-off-by: Sergey Fedorov <s.fedorov@samsung.com>
>> ---
>> target-arm/helper.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++-
>> 1 file changed, 76 insertions(+), 1 deletion(-)
>>
>> diff --git a/target-arm/helper.c b/target-arm/helper.c
>> index e1e9762..7bfadb0 100644
>> --- a/target-arm/helper.c
>> +++ b/target-arm/helper.c
>> @@ -11,6 +11,7 @@ static inline int get_phys_addr(CPUARMState *env, uint32_t address,
>> int access_type, int is_user,
>> hwaddr *phys_ptr, int *prot,
>> target_ulong *page_size);
>> +static void switch_cp15_regs(CPUARMState *env, int secure);
>> #endif
>>
>> static int vfp_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg)
>> @@ -1553,6 +1554,17 @@ static int sctlr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
>> }
>>
>> #ifndef CONFIG_USER_ONLY
>> +static int scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
>> +{
>> + if ((value & 1/*NS*/) && (env->uncached_cpsr & CPSR_M) != ARM_CPU_MODE_MON) {
>> + /* We are going to Non-secure state; switch banked system control registers */
>> + switch_cp15_regs(env, 0);
>> + }
>> +
>> + env->cp15.c1_scr = value;
>> + return 0;
>> +}
>> +
>> static int vbar_write(CPUARMState *env, const ARMCPRegInfo *ri,
>> uint64_t value)
>> {
>> @@ -1572,7 +1584,7 @@ static const ARMCPRegInfo tz_cp_reginfo[] = {
>> #ifndef CONFIG_USER_ONLY
>> { .name = "SCR", .cp = 15, .crn = 1, .crm = 1, .opc1 = 0, .opc2 = 0,
>> .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.c1_scr),
>> - .resetvalue = 0 },
>> + .writefn = scr_write, .resetvalue = 0 },
>> { .name = "VBAR", .cp = 15, .crn = 12, .crm = 0, .opc1 = 0, .opc2 = 0,
>> .access = PL1_RW, .type = ARM_CP_BANKED, .writefn = vbar_write,
>> .fieldoffset = offsetof(CPUARMState, cp15.c12_vbar),
>> @@ -2284,6 +2296,69 @@ void switch_mode(CPUARMState *env, int mode)
>> env->regs[13] = env->banked_r13[i];
>> env->regs[14] = env->banked_r14[i];
>> env->spsr = env->banked_spsr[i];
>> +
>> + if ((mode == ARM_CPU_MODE_MON || old_mode == ARM_CPU_MODE_MON) &&
>> + (env->cp15.c1_scr & 1/*NS*/)) {
>> + /* We are going to change Security state; switch banked system control registers */
>> + switch_cp15_regs(env, (mode == ARM_CPU_MODE_MON));
>> + }
>> +}
>> +
>> +void switch_cp15_regs(CPUARMState *env, int secure)
>> +{
>> + int i;
>> +
>> + /* Save current Security state registers */
>> + i = arm_is_secure(env) ? 0 : 1;
>> + env->cp15.banked_c0_cssel[i] = env->cp15.c0_cssel;
>> + env->cp15.banked_c1_sys[i] = env->cp15.c1_sys;
>> + env->cp15.banked_c2_base0[i] = env->cp15.c2_base0;
>> + env->cp15.banked_c2_base0_hi[i] = env->cp15.c2_base0_hi;
>> + env->cp15.banked_c2_base1[i] = env->cp15.c2_base1;
>> + env->cp15.banked_c2_base1_hi[i] = env->cp15.c2_base1_hi;
>> + env->cp15.banked_c2_control[i] = env->cp15.c2_control;
>> + env->cp15.banked_c3[i] = env->cp15.c3;
>> + env->cp15.banked_c5_data[i] = env->cp15.c5_data;
>> + env->cp15.banked_c5_insn[i] = env->cp15.c5_insn;
>> + env->cp15.banked_c6_data[i] = env->cp15.c6_data;
>> + env->cp15.banked_c6_insn[i] = env->cp15.c6_insn;
>> + env->cp15.banked_c7_par[i] = env->cp15.c7_par;
>> + env->cp15.banked_c7_par_hi[i] = env->cp15.c7_par_hi;
>> + env->cp15.banked_c13_context[i] = env->cp15.c13_context;
>> + env->cp15.banked_c13_fcse[i] = env->cp15.c13_fcse;
>> + env->cp15.banked_c13_tls1[i] = env->cp15.c13_tls1;
>> + env->cp15.banked_c13_tls2[i] = env->cp15.c13_tls2;
>> + env->cp15.banked_c13_tls3[i] = env->cp15.c13_tls3;
>> +
>> + /* Restore new Security state registers */
>> + i = secure ? 0 : 1;
>> + env->cp15.c0_cssel = env->cp15.banked_c0_cssel[i];
>> + /* Maintain the value of common bits */
>> + env->cp15.c1_sys &= 0x8204000;
>> + env->cp15.c1_sys |= env->cp15.banked_c1_sys[i] & ~0x8204000;
>> + env->cp15.c2_base0 = env->cp15.banked_c2_base0[i];
>> + env->cp15.c2_base0_hi = env->cp15.banked_c2_base0_hi[i];
>> + env->cp15.c2_base1 = env->cp15.banked_c2_base1[i];
>> + env->cp15.c2_base1_hi = env->cp15.banked_c2_base1_hi[i];
>> + {
>> + int maskshift;
>> + env->cp15.c2_control = env->cp15.banked_c2_control[i];
>> + maskshift = extract32(env->cp15.c2_control, 0, 3);
>> + env->cp15.c2_mask = ~(((uint32_t)0xffffffffu) >> maskshift);
>> + env->cp15.c2_base_mask = ~((uint32_t)0x3fffu >> maskshift);
>> + }
>> + env->cp15.c3 = env->cp15.banked_c3[i];
>> + env->cp15.c5_data = env->cp15.banked_c5_data[i];
>> + env->cp15.c5_insn = env->cp15.banked_c5_insn[i];
>> + env->cp15.c6_data = env->cp15.banked_c6_data[i];
>> + env->cp15.c6_insn = env->cp15.banked_c6_insn[i];
>> + env->cp15.c7_par = env->cp15.banked_c7_par[i];
>> + env->cp15.c7_par_hi = env->cp15.banked_c7_par_hi[i];
>> + env->cp15.c13_context = env->cp15.banked_c13_context[i];
>> + env->cp15.c13_fcse = env->cp15.banked_c13_fcse[i];
>> + env->cp15.c13_tls1 = env->cp15.banked_c13_tls1[i];
>> + env->cp15.c13_tls2 = env->cp15.banked_c13_tls2[i];
>> + env->cp15.c13_tls3 = env->cp15.banked_c13_tls3[i];
>> }
> And I think this is awkward. Can't we just teach TCG to get the right
> value out of the banked array and do away with these active copies
> completely? This greatly complicates the change pattern for adding a
> new banked CP.
>
> Regards,
> Peter
Yes, this banking scheme makes state changing events quite heavy. But
maintaining the active copies allows to keep translation table walking
code untouched. I think there is a trade-off between state changing and
translation table walking overheads.
I think the CP banking is the most fragile thing in this patch series
and this should become much better after review :)
Thanks!
>
>> static void v7m_push(CPUARMState *env, uint32_t val)
>> --
>> 1.7.9.5
>>
>>
--
Best regards,
Sergey Fedorov
next prev parent reply other threads:[~2013-12-19 7:27 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-03 8:48 [Qemu-devel] [RFC PATCH 00/21] target-arm: add CPU core TrustZone support Sergey Fedorov
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 01/21] target-arm: add TrustZone CPU feature Sergey Fedorov
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 02/21] target-arm: move SCR & VBAR into TrustZone register list Sergey Fedorov
2013-12-19 3:12 ` Peter Crosthwaite
2013-12-19 6:23 ` Fedorov Sergey
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 03/21] target-arm: adjust TTBCR for TrustZone feature Sergey Fedorov
2013-12-03 12:15 ` Peter Crosthwaite
2013-12-04 9:50 ` Fedorov Sergey
2013-12-04 10:52 ` Peter Crosthwaite
2013-12-19 3:18 ` Peter Crosthwaite
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 04/21] target-arm: preserve RAO/WI bits of ARMv7 SCTLR Sergey Fedorov
2013-12-03 12:17 ` Peter Crosthwaite
2013-12-04 9:55 ` Fedorov Sergey
2013-12-19 3:19 ` Peter Crosthwaite
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 05/21] target-arm: add CPU Monitor mode Sergey Fedorov
2013-12-03 12:20 ` Peter Crosthwaite
2013-12-03 12:51 ` Peter Maydell
2013-12-04 10:01 ` Fedorov Sergey
2013-12-04 10:58 ` Peter Crosthwaite
2013-12-04 11:18 ` Peter Maydell
2013-12-04 12:33 ` Fedorov Sergey
2013-12-04 12:35 ` Peter Maydell
2013-12-19 3:26 ` Peter Crosthwaite
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 06/21] target-arm: add arm_is_secure() helper Sergey Fedorov
2013-12-19 3:31 ` Peter Crosthwaite
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 07/21] target-arm: reject switching to monitor mode from non-secure state Sergey Fedorov
2013-12-19 3:44 ` Peter Crosthwaite
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 08/21] target-arm: adjust arm_current_pl() for TrustZone Sergey Fedorov
2013-12-03 12:23 ` Peter Crosthwaite
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 09/21] target-arm: adjust SCR CP15 register access rights Sergey Fedorov
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 10/21] target-arm: add non-secure Translation Block flag Sergey Fedorov
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 11/21] target-arm: implement CPACR register logic Sergey Fedorov
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 12/21] target-arm: add NSACR support Sergey Fedorov
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 13/21] target-arm: add SDER definition Sergey Fedorov
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 14/21] target-arm: split TLB for secure state Sergey Fedorov
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 15/21] target-arm: add banked coprocessor register type Sergey Fedorov
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 16/21] target-arm: convert appropriate coprocessor registers to banked type Sergey Fedorov
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 17/21] target-arm: use c13_context field for CONTEXTIDR Sergey Fedorov
2013-12-19 4:31 ` Peter Crosthwaite
2013-12-19 6:29 ` Fedorov Sergey
2013-12-19 6:32 ` Peter Crosthwaite
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 18/21] target-arm: switch banked CP registers Sergey Fedorov
2013-12-19 4:37 ` Peter Crosthwaite
2013-12-19 7:27 ` Fedorov Sergey [this message]
2013-12-19 11:38 ` Peter Maydell
2013-12-19 12:44 ` Peter Crosthwaite
2013-12-19 13:39 ` Fedorov Sergey
2013-12-19 14:01 ` Peter Crosthwaite
2013-12-19 14:09 ` Peter Maydell
2013-12-20 14:12 ` Fedorov Sergey
2013-12-20 14:33 ` Peter Maydell
2013-12-20 14:38 ` Fedorov Sergey
2013-12-20 16:18 ` Fedorov Sergey
2013-12-22 1:08 ` Peter Crosthwaite
2013-12-22 7:59 ` Peter Maydell
2013-12-23 7:28 ` Fedorov Sergey
2013-12-23 7:43 ` Fedorov Sergey
2013-12-23 9:05 ` Peter Maydell
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 19/21] target-arm: add MVBAR support Sergey Fedorov
2013-12-19 4:41 ` Peter Crosthwaite
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 20/21] target-arm: implement SMC instruction Sergey Fedorov
2013-12-03 8:48 ` [Qemu-devel] [RFC PATCH 21/21] target-arm: implement IRQ/FIQ routing to Monitor mode Sergey Fedorov
2013-12-04 10:08 ` [Qemu-devel] [RFC PATCH 00/21] target-arm: add CPU core TrustZone support Fedorov Sergey
2013-12-04 11:10 ` Peter Crosthwaite
2013-12-04 11:13 ` Peter Maydell
2013-12-04 12:48 ` Fedorov Sergey
2013-12-19 4:56 ` Peter Crosthwaite
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=52B29FE5.40705@samsung.com \
--to=s.fedorov@samsung.com \
--cc=a.basov@samsung.com \
--cc=johannes.winter@iaik.tugraz.at \
--cc=peter.crosthwaite@xilinx.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.