All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] target/arm: Fix SCR_EL3 migration issue
@ 2021-01-28 14:31 michael.nawrocki--- via
  2021-01-28 14:31 ` [PATCH 1/1] target/arm: Add raw_writefn to SCR_EL3 register michael.nawrocki--- via
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: michael.nawrocki--- via @ 2021-01-28 14:31 UTC (permalink / raw)
  To: qemu-arm; +Cc: qemu-trivial, peter.maydell, qemu-devel, Mike Nawrocki

The SCR_EL3 register reset value (0)  and the value produced when
writing 0 via the scr_write function (set as writefn in the register
struct) differ. This causes migration to fail.

I believe the solution is to specify a raw_writefn for that register.

Failing invocation:
$ qemu-system-arm -machine vexpress-a9 -cpu cortex-a9 -nographic
QEMU 5.2.0 monitor - type 'help' for more information
(qemu) migrate "exec:cat > img"
(qemu) q
$ qemu-system-arm -machine vexpress-a9 -cpu cortex-a9 -nographic -incoming "exec:cat img"
qemu-system-arm: error while loading state for instance 0x0 of device 'cpu'
qemu-system-arm: load of migration failed: Operation not permitted


Mike Nawrocki (1):
  target/arm: Add raw_writefn to SCR_EL3 register

 target/arm/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.20.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/1] target/arm: Add raw_writefn to SCR_EL3 register
  2021-01-28 14:31 [PATCH 0/1] target/arm: Fix SCR_EL3 migration issue michael.nawrocki--- via
@ 2021-01-28 14:31 ` michael.nawrocki--- via
  2021-02-02 11:29   ` Peter Maydell
  2021-01-28 14:38 ` [PATCH 0/1] target/arm: Fix SCR_EL3 migration issue Peter Maydell
  2021-02-03 16:28 ` Philippe Mathieu-Daudé
  2 siblings, 1 reply; 8+ messages in thread
From: michael.nawrocki--- via @ 2021-01-28 14:31 UTC (permalink / raw)
  To: qemu-arm; +Cc: qemu-trivial, peter.maydell, qemu-devel, Mike Nawrocki

Fixes an issue in migration where the reset value of SCR and the value
produced by scr_write via the writefn for SCR_EL3 mismatch.

Signed-off-by: Mike Nawrocki <michael.nawrocki@gtri.gatech.edu>
---
 target/arm/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/arm/helper.c b/target/arm/helper.c
index d2ead3fcbd..e3c4fe76cb 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -5785,7 +5785,7 @@ static const ARMCPRegInfo el3_cp_reginfo[] = {
     { .name = "SCR_EL3", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 1, .opc2 = 0,
       .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.scr_el3),
-      .resetvalue = 0, .writefn = scr_write },
+      .resetvalue = 0, .writefn = scr_write, .raw_writefn = raw_write },
     { .name = "SCR",  .type = ARM_CP_ALIAS | ARM_CP_NEWEL,
       .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 0,
       .access = PL1_RW, .accessfn = access_trap_aa32s_el1,
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/1] target/arm: Fix SCR_EL3 migration issue
  2021-01-28 14:31 [PATCH 0/1] target/arm: Fix SCR_EL3 migration issue michael.nawrocki--- via
  2021-01-28 14:31 ` [PATCH 1/1] target/arm: Add raw_writefn to SCR_EL3 register michael.nawrocki--- via
@ 2021-01-28 14:38 ` Peter Maydell
  2021-02-03 16:28 ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2021-01-28 14:38 UTC (permalink / raw)
  To: Mike Nawrocki; +Cc: QEMU Trivial, qemu-arm, QEMU Developers

On Thu, 28 Jan 2021 at 14:31, Mike Nawrocki
<michael.nawrocki@gtri.gatech.edu> wrote:
>
> The SCR_EL3 register reset value (0)  and the value produced when
> writing 0 via the scr_write function (set as writefn in the register
> struct) differ. This causes migration to fail.
>
> I believe the solution is to specify a raw_writefn for that register.
>
> Failing invocation:
> $ qemu-system-arm -machine vexpress-a9 -cpu cortex-a9 -nographic
> QEMU 5.2.0 monitor - type 'help' for more information
> (qemu) migrate "exec:cat > img"
> (qemu) q
> $ qemu-system-arm -machine vexpress-a9 -cpu cortex-a9 -nographic -incoming "exec:cat img"
> qemu-system-arm: error while loading state for instance 0x0 of device 'cpu'
> qemu-system-arm: load of migration failed: Operation not permitted

I'll review the patch later, but for the moment just a note that
I'm pretty sure this is not the only issue you'll run into with
trying to migrate an AArch32 TrustZone-enabled CPU.
https://bugs.launchpad.net/qemu/+bug/1839807 has the details
but in summary we aren't migrating the Secure banked contents
of cp15 registers which are banked Secure/Non-Secure. The
symptom will be that migration succeeds but the guest doesn't
behave correctly on the destination/after state restore.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/1] target/arm: Add raw_writefn to SCR_EL3 register
  2021-01-28 14:31 ` [PATCH 1/1] target/arm: Add raw_writefn to SCR_EL3 register michael.nawrocki--- via
@ 2021-02-02 11:29   ` Peter Maydell
  2021-02-03 14:50     ` michael.nawrocki--- via
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2021-02-02 11:29 UTC (permalink / raw)
  To: Mike Nawrocki; +Cc: QEMU Trivial, qemu-arm, Richard Henderson, QEMU Developers

On Thu, 28 Jan 2021 at 14:31, Mike Nawrocki
<michael.nawrocki@gtri.gatech.edu> wrote:
>
> Fixes an issue in migration where the reset value of SCR and the value
> produced by scr_write via the writefn for SCR_EL3 mismatch.
>
> Signed-off-by: Mike Nawrocki <michael.nawrocki@gtri.gatech.edu>
> ---
>  target/arm/helper.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/arm/helper.c b/target/arm/helper.c
> index d2ead3fcbd..e3c4fe76cb 100644
> --- a/target/arm/helper.c
> +++ b/target/arm/helper.c
> @@ -5785,7 +5785,7 @@ static const ARMCPRegInfo el3_cp_reginfo[] = {
>      { .name = "SCR_EL3", .state = ARM_CP_STATE_AA64,
>        .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 1, .opc2 = 0,
>        .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.scr_el3),
> -      .resetvalue = 0, .writefn = scr_write },
> +      .resetvalue = 0, .writefn = scr_write, .raw_writefn = raw_write },
>      { .name = "SCR",  .type = ARM_CP_ALIAS | ARM_CP_NEWEL,
>        .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 0,
>        .access = PL1_RW, .accessfn = access_trap_aa32s_el1,
> --

I think the problem here is not the lack of a raw_writefn,
but that we're not handling the RES1 bits [5:4] in SCR_EL3 correctly.
Specifically:

 * if the CPU is AArch64-only then the resetvalue for SCR_EL3 should
   not be 0, but 0x30 (but if the CPU has AArch32 at all then it should
   still be 0)
 * scr_write() should not be saying "force the FW and AW bits to 1 if
   written as an AArch64 register". It can, but is not obliged to,
   do this if the CPU is AArch64-only; it must not if the CPU has
   AArch32, even if the register is being accessed via its AArch64 form.

This is because RES1 has some complicated semantics for bits like
this which are "RES1 only in some architectural contexts" (this is all
defined in the Glossary entry in the v8A Arm ARM), which basically
means that if AArch32 is supported then the bit has to be reads-as-written
from the AArch64 side.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/1] target/arm: Add raw_writefn to SCR_EL3 register
  2021-02-02 11:29   ` Peter Maydell
@ 2021-02-03 14:50     ` michael.nawrocki--- via
  2021-02-03 15:04       ` Peter Maydell
  0 siblings, 1 reply; 8+ messages in thread
From: michael.nawrocki--- via @ 2021-02-03 14:50 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Trivial, qemu-arm, Richard Henderson, QEMU Developers

On 2/2/21 6:29 AM, Peter Maydell wrote:
> On Thu, 28 Jan 2021 at 14:31, Mike Nawrocki
> <michael.nawrocki@gtri.gatech.edu> wrote:
>>
>> Fixes an issue in migration where the reset value of SCR and the value
>> produced by scr_write via the writefn for SCR_EL3 mismatch.
>>
>> Signed-off-by: Mike Nawrocki <michael.nawrocki@gtri.gatech.edu>
>> ---
>>   target/arm/helper.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/target/arm/helper.c b/target/arm/helper.c
>> index d2ead3fcbd..e3c4fe76cb 100644
>> --- a/target/arm/helper.c
>> +++ b/target/arm/helper.c
>> @@ -5785,7 +5785,7 @@ static const ARMCPRegInfo el3_cp_reginfo[] = {
>>       { .name = "SCR_EL3", .state = ARM_CP_STATE_AA64,
>>         .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 1, .opc2 = 0,
>>         .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.scr_el3),
>> -      .resetvalue = 0, .writefn = scr_write },
>> +      .resetvalue = 0, .writefn = scr_write, .raw_writefn = raw_write },
>>       { .name = "SCR",  .type = ARM_CP_ALIAS | ARM_CP_NEWEL,
>>         .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 0,
>>         .access = PL1_RW, .accessfn = access_trap_aa32s_el1,
>> --
> 
> I think the problem here is not the lack of a raw_writefn,
> but that we're not handling the RES1 bits [5:4] in SCR_EL3 correctly.
> Specifically:
> 
>   * if the CPU is AArch64-only then the resetvalue for SCR_EL3 should
>     not be 0, but 0x30 (but if the CPU has AArch32 at all then it should
>     still be 0)
>   * scr_write() should not be saying "force the FW and AW bits to 1 if
>     written as an AArch64 register". It can, but is not obliged to,
>     do this if the CPU is AArch64-only; it must not if the CPU has
>     AArch32, even if the register is being accessed via its AArch64 form.
> 
> This is because RES1 has some complicated semantics for bits like
> this which are "RES1 only in some architectural contexts" (this is all
> defined in the Glossary entry in the v8A Arm ARM), which basically
> means that if AArch32 is supported then the bit has to be reads-as-written
> from the AArch64 side.
> 
> thanks
> -- PMM
> 

I see what you mean. Does QEMU support AArch64-only CPU models, and if 
so, is there a way to determine if the CPU has AArch32?

Thanks,
Mike


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/1] target/arm: Add raw_writefn to SCR_EL3 register
  2021-02-03 14:50     ` michael.nawrocki--- via
@ 2021-02-03 15:04       ` Peter Maydell
  2021-02-03 16:58         ` michael.nawrocki--- via
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2021-02-03 15:04 UTC (permalink / raw)
  To: Michael Nawrocki
  Cc: QEMU Trivial, qemu-arm, Richard Henderson, QEMU Developers

On Wed, 3 Feb 2021 at 14:50, Michael Nawrocki
<michael.nawrocki@gtri.gatech.edu> wrote:
>
> On 2/2/21 6:29 AM, Peter Maydell wrote:
> I see what you mean. Does QEMU support AArch64-only CPU models, and if
> so, is there a way to determine if the CPU has AArch32?

We don't have any currently, but in theory the support is there
and we'll likely end up adding some in future.

More specifically, in this case what you want to know is "can
the guest ever see the AArch32 view of SCR_EL3", which is
"is there support for AArch32 at EL1 or above"?", which you can
check for in the EL1 field of ID_AA64PFR0.

So you need a function similar to the existing isar_feature_aa64_aa32(),
but which cecks the EL1 field instead of the EL0 field (you could
call it isar_feature_aa64_aa32_el1()). Then you can test it with
 cpu_isar_feature(aa64_aa32_el1, cpu).

NB that you must only call it when you know that the CPU has
AArch64, ie when arm_feature(env, ARM_FEATURE_AARCH64) is true.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/1] target/arm: Fix SCR_EL3 migration issue
  2021-01-28 14:31 [PATCH 0/1] target/arm: Fix SCR_EL3 migration issue michael.nawrocki--- via
  2021-01-28 14:31 ` [PATCH 1/1] target/arm: Add raw_writefn to SCR_EL3 register michael.nawrocki--- via
  2021-01-28 14:38 ` [PATCH 0/1] target/arm: Fix SCR_EL3 migration issue Peter Maydell
@ 2021-02-03 16:28 ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-02-03 16:28 UTC (permalink / raw)
  To: avocado-devel
  Cc: qemu-trivial, peter.maydell, qemu-arm, qemu-devel, Mike Nawrocki

Cc'ing avocado-devel for test idea.

On 1/28/21 3:31 PM, michael.nawrocki--- via wrote:
> The SCR_EL3 register reset value (0)  and the value produced when
> writing 0 via the scr_write function (set as writefn in the register
> struct) differ. This causes migration to fail.
> 
> I believe the solution is to specify a raw_writefn for that register.
> 
> Failing invocation:
> $ qemu-system-arm -machine vexpress-a9 -cpu cortex-a9 -nographic
> QEMU 5.2.0 monitor - type 'help' for more information
> (qemu) migrate "exec:cat > img"
> (qemu) q
> $ qemu-system-arm -machine vexpress-a9 -cpu cortex-a9 -nographic -incoming "exec:cat img"
> qemu-system-arm: error while loading state for instance 0x0 of device 'cpu'
> qemu-system-arm: load of migration failed: Operation not permitted
> 
> 
> Mike Nawrocki (1):
>   target/arm: Add raw_writefn to SCR_EL3 register
> 
>  target/arm/helper.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/1] target/arm: Add raw_writefn to SCR_EL3 register
  2021-02-03 15:04       ` Peter Maydell
@ 2021-02-03 16:58         ` michael.nawrocki--- via
  0 siblings, 0 replies; 8+ messages in thread
From: michael.nawrocki--- via @ 2021-02-03 16:58 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Trivial, qemu-arm, Richard Henderson, QEMU Developers

On 2/3/21 10:04 AM, Peter Maydell wrote:
> On Wed, 3 Feb 2021 at 14:50, Michael Nawrocki
> <michael.nawrocki@gtri.gatech.edu> wrote:
>>
>> On 2/2/21 6:29 AM, Peter Maydell wrote:
>> I see what you mean. Does QEMU support AArch64-only CPU models, and if
>> so, is there a way to determine if the CPU has AArch32?
> 
> We don't have any currently, but in theory the support is there
> and we'll likely end up adding some in future.
> 
> More specifically, in this case what you want to know is "can
> the guest ever see the AArch32 view of SCR_EL3", which is
> "is there support for AArch32 at EL1 or above"?", which you can
> check for in the EL1 field of ID_AA64PFR0.
> 
> So you need a function similar to the existing isar_feature_aa64_aa32(),
> but which cecks the EL1 field instead of the EL0 field (you could
> call it isar_feature_aa64_aa32_el1()). Then you can test it with
>   cpu_isar_feature(aa64_aa32_el1, cpu).
> 
> NB that you must only call it when you know that the CPU has
> AArch64, ie when arm_feature(env, ARM_FEATURE_AARCH64) is true.
> 
> thanks
> -- PMM
> 

Thanks, that's very helpful. I submitted a patch v2 that I believe 
encapsulates this discussion.

Thanks,
Mike


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-02-03 17:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-28 14:31 [PATCH 0/1] target/arm: Fix SCR_EL3 migration issue michael.nawrocki--- via
2021-01-28 14:31 ` [PATCH 1/1] target/arm: Add raw_writefn to SCR_EL3 register michael.nawrocki--- via
2021-02-02 11:29   ` Peter Maydell
2021-02-03 14:50     ` michael.nawrocki--- via
2021-02-03 15:04       ` Peter Maydell
2021-02-03 16:58         ` michael.nawrocki--- via
2021-01-28 14:38 ` [PATCH 0/1] target/arm: Fix SCR_EL3 migration issue Peter Maydell
2021-02-03 16:28 ` Philippe Mathieu-Daudé

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.