xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: Corneliu ZUZU <czuzu@bitdefender.com>, xen-devel@lists.xen.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Tamas K Lengyel <tamas@tklengyel.com>,
	Razvan Cojocaru <rcojocaru@bitdefender.com>
Subject: Re: [PATCH 7/7] vm-event/arm: implement support for control-register write vm-events
Date: Fri, 17 Jun 2016 14:18:58 +0100	[thread overview]
Message-ID: <5763F8C2.60308@arm.com> (raw)
In-Reply-To: <196523e7-285c-51a3-c48a-eff45d40a342@bitdefender.com>

Hello Corneliu,

On 17/06/16 11:36, Corneliu ZUZU wrote:
> On 6/16/2016 7:49 PM, Julien Grall wrote:
>> On 16/06/16 15:13, Corneliu ZUZU wrote:

[...]

>> Please mention that PRRR and NMRR are aliased to respectively MAIR0
>> and MAIR1. This will avoid to spend time trying to understanding why
>> the spec says they are trapped but you don't "handle" them.
>
> I mentioned that in traps.h (see "AKA" comments). Will put the same
> comment here then.

I noticed it later. But it was not obvious to find.

[...]

>>> diff --git a/xen/arch/arm/vm_event.c b/xen/arch/arm/vm_event.c
>>> new file mode 100644
>>> index 0000000..3f23fec
>>> --- /dev/null
>>> +++ b/xen/arch/arm/vm_event.c
>>> @@ -0,0 +1,112 @@
>>
>> [...]
>>
>>> +#include <xen/vm_event.h>
>>> +#include <asm/traps.h>
>>> +
>>> +#if CONFIG_ARM_64
>>> +
>>> +#define MWSINF_SCTLR    32,SCTLR_EL1
>>> +#define MWSINF_TTBR0    64,TTBR0_EL1
>>> +#define MWSINF_TTBR1    64,TTBR1_EL1
>>> +#define MWSINF_TTBCR    64,TCR_EL1
>>> +
>>> +#elif CONFIG_ARM_32
>>> +
>>> +#define MWSINF_SCTLR    32,SCTLR
>>> +#define MWSINF_TTBR0    64,TTBR0
>>> +#define MWSINF_TTBR1    64,TTBR1
>>
>> The values are the same as for arm64 (*_EL1 is aliased to * for
>> arm32). Please avoid duplication.
>
> (see comment below about later reply)

Your later reply explain why you did not expose TTBR*_32 to ARM64, but 
does not explain why the 3 define above is the same as the ARM64.

>
>>
>>> +#define MWSINF_TTBR0_32 32,TTBR0_32
>>> +#define MWSINF_TTBR1_32 32,TTBR1_32
>>> +#define MWSINF_TTBCR    32,TTBCR
>>> +
>>> +#endif
>>> +
>>> +#define MWS_EMUL_(val, sz, r...) WRITE_SYSREG##sz((uint##sz##_t)
>>> (val), r)
>>
>> The cast is not necessary.
>>
>>> +#define MWS_EMUL(r) CALL_MACRO(MWS_EMUL_, w->value, MWSINF_##r)
>>> +
>>> +static inline void vcpu_enter_write_data(struct vcpu *v)
>>> +{
>>> +    struct monitor_write_data *w = &v->arch.vm_event.write_data;
>>> +
>>> +    if ( likely(MWS_NOWRITE == w->status) )
>>> +        return;
>>> +
>>> +    switch ( w->status )
>>> +    {
>>> +    case MWS_SCTLR:
>>> +        MWS_EMUL(SCTLR);
>>> +        break;
>>> +    case MWS_TTBR0:
>>> +        MWS_EMUL(TTBR0);
>>> +        break;
>>> +    case MWS_TTBR1:
>>> +        MWS_EMUL(TTBR1);
>>> +        break;
>>> +#if CONFIG_ARM_32
>>> +    case MWS_TTBR0_32:
>>> +        MWS_EMUL(TTBR0_32);
>>> +        break;
>>> +    case MWS_TTBR1_32:
>>> +        MWS_EMUL(TTBR1_32);
>>> +        break;
>>> +#endif
>>
>> Aarch32 kernel can return on an AArch64 Xen. This means that
>> TTBR{0,1}_32 could be trapped and the write therefore be properly
>> emulated.
>
> MCR TTBRx writes from AArch32 guests appear as writes of the low 32-bits
> of AArch64 TTBRx_EL1 (architecturally mapped).
> MCRR TTBRx writes from AArch32 guests appear as writes to AArch64
> TTBRx_EL1.
> Therefore, in the end the register we need to write is still TTBRx_EL1.

Why would you want to notify write to TTBR*_32 when Xen is running in 
AArch32 mode and none in Aaarch64 mode?

The vm-events for an AArch32 guests should be exactly the same
regardless of Xen mode (i.e AArch32 vs AArch64).

[...]

>>
>>> @@ -0,0 +1,253 @@
>>
>> [...]
>>
>>> +/*
>>> + * Emulation of system-register trapped writes that do not cause
>>> + * VM_EVENT_REASON_WRITE_CTRLREG monitor vm-events.
>>> + * Such writes are collaterally trapped due to setting the
>>> HCR_EL2.TVM bit.
>>> + *
>>> + * Regarding aarch32 domains, note that from Xen's perspective
>>> system-registers
>>> + * of such domains are architecturally-mapped to aarch64 registers
>>> in one of
>>> + * three ways:
>>> + *  - low 32-bits mapping   (e.g. aarch32 DFAR -> aarch64
>>> FAR_EL1[31:0])
>>> + *  - high 32-bits mapping  (e.g. aarch32 IFAR -> aarch64
>>> FAR_EL1[63:32])
>>> + *  - full mapping          (e.g. aarch32 SCTLR -> aarch64 SCTLR_EL1)
>>> + *
>>> + * Hence we define 2 macro variants:
>>> + *  - TVM_EMUL_SZ variant, for full mappings
>>> + *  - TVM_EMUL_LH variant, for low/high 32-bits mappings
>>> + */
>>> +#define TVM_EMUL_SZ(regs, hsr, val, sz,
>>> r...)                           \
>>> +{ \
>>> +    if ( psr_mode_is_user(regs)
>>> )                                       \
>>
>> Those registers are not accessible at EL0.
>
> Hmm, I have this question noted.
> I remember finding from the manuals that a write from user-mode of those
> regs would still trap to EL2, but I didn't test that yet.
> Will put that to test and come back with results for v2.

Testing will not tell you if a trap will occur or not. The ARM ARM may 
define it as IMPLEMENTATION DEFINED.

 From my understanding of the ARMv7 spec (B1.14.1 and B1.14.13 in ARM 
DDI 0406C.c), the instruction at PL0 (user mode) will not trap to the 
hypervisor:

"Setting HCR.TVM to 1 means that any attempt, to write to a Non-secure 
memory control register from a Non-secure
PL1 or PL0 mode, that this reference manual does not describe as 
UNDEFINED , generates a Hyp Trap exception."

For ARMv8 (See description of HCR_EL2.TVM D7-1971 in ARM DDI 0487A.j), 
only NS EL1 write to the registers will be trapped.

>>
>>> +        return inject_undef_exception(regs,
>>> hsr);                       \
>>> +    WRITE_SYSREG##sz((uint##sz##_t) (val), r);
>>
>> [...]
>>
>>> diff --git a/xen/include/asm-arm/vm_event.h
>>> b/xen/include/asm-arm/vm_event.h
>>> index 4e5a272..edf9654 100644
>>> --- a/xen/include/asm-arm/vm_event.h
>>> +++ b/xen/include/asm-arm/vm_event.h
>>> @@ -30,6 +30,12 @@ static inline int vm_event_init_domain(struct
>>> domain *d)
>>>
>>>   static inline void vm_event_cleanup_domain(struct domain *d)
>>>   {
>>> +    struct vcpu *v;
>>> +
>>> +    for_each_vcpu ( d, v )
>>> +        memset(&v->arch.vm_event, 0, sizeof(v->arch.vm_event));
>>> +
>>> +    memset(&d->arch.monitor, 0, sizeof(d->arch.monitor));
>>>       memset(&d->monitor, 0, sizeof(d->monitor));
>>>   }
>>>
>>> @@ -41,7 +47,13 @@ static inline void
>>> vm_event_toggle_singlestep(struct domain *d, struct vcpu *v)
>>>   static inline
>>>   void vm_event_register_write_resume(struct vcpu *v,
>>> vm_event_response_t *rsp)
>>>   {
>>> -    /* Not supported on ARM. */
>>> +    /* X86 VM_EVENT_REASON_MOV_TO_MSR could (but shouldn't) end-up
>>> here too. */
>>
>> This should be an ASSERT/BUG_ON then.
>
> We can't ASSERT/BUG_ON here because rsp->reason is controlled by the
> toolstack user.

Your comment says "shouldn't" which I interpret as this would be a bug 
if VM_EVENT_REASON_MOV_TO_MSR ends up here.

If not a BUG_ON, at least returning an error. We should not silently 
ignore something that shouldn't happen.

> This has to do with the implementation of vm_event_resume.
> What I think we should do instead is to surround "case
> VM_EVENT_REASON_MOV_TO_MSR" there with #ifdef CONFIG_X86.
> Would that be suitable?

x86 vm-event reason should never be accessible on ARM (similarly for ARM 
vm-event on x86). So the hypervisor should return an error if someone is 
calling with the wrong vm-event.

Regards,

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2016-06-17 13:18 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-16 14:04 [PATCH 0/7] vm-event: Implement ARM support for control-register writes Corneliu ZUZU
2016-06-16 14:06 ` [PATCH 1/7] minor (formatting) fixes Corneliu ZUZU
2016-06-16 14:24   ` Jan Beulich
2016-06-16 19:19     ` Corneliu ZUZU
2016-06-17  7:06       ` Jan Beulich
2016-06-17 10:46         ` Corneliu ZUZU
2016-06-16 16:02   ` Tamas K Lengyel
2016-06-17  8:33     ` Corneliu ZUZU
2016-06-17  8:36       ` Razvan Cojocaru
2016-06-17  9:29         ` Andrew Cooper
2016-06-17  9:35           ` Jan Beulich
2016-06-17  9:33         ` Jan Beulich
2016-06-17  9:36           ` Razvan Cojocaru
2016-06-17  9:40             ` Jan Beulich
2016-06-17  9:42               ` Razvan Cojocaru
2016-06-17 19:05           ` Tamas K Lengyel
2016-06-16 14:07 ` [PATCH 2/7] vm-event: VM_EVENT_FLAG_DENY requires VM_EVENT_FLAG_VCPU_PAUSED Corneliu ZUZU
2016-06-16 16:11   ` Tamas K Lengyel
2016-06-17  8:43     ` Corneliu ZUZU
2016-06-21 11:26     ` Corneliu ZUZU
2016-06-21 15:09       ` Tamas K Lengyel
2016-06-22  8:34         ` Corneliu ZUZU
2016-06-16 14:08 ` [PATCH 3/7] vm-event: introduce vm_event_vcpu_enter Corneliu ZUZU
2016-06-16 14:51   ` Jan Beulich
2016-06-16 20:10     ` Corneliu ZUZU
2016-06-16 20:33       ` Razvan Cojocaru
2016-06-17 10:41         ` Corneliu ZUZU
2016-06-17  7:17       ` Jan Beulich
2016-06-17 11:13         ` Corneliu ZUZU
2016-06-17 11:27           ` Jan Beulich
2016-06-17 12:13             ` Corneliu ZUZU
2016-06-16 16:17   ` Tamas K Lengyel
2016-06-17  9:19     ` Corneliu ZUZU
2016-06-17  8:55   ` Julien Grall
2016-06-17 11:40     ` Corneliu ZUZU
2016-06-17 13:22       ` Julien Grall
2016-06-16 14:09 ` [PATCH 4/7] vm-event/x86: use vm_event_vcpu_enter properly Corneliu ZUZU
2016-06-16 15:00   ` Jan Beulich
2016-06-16 20:20     ` Corneliu ZUZU
2016-06-17  7:20       ` Jan Beulich
2016-06-17 11:23         ` Corneliu ZUZU
2016-06-16 16:27   ` Tamas K Lengyel
2016-06-17  9:24     ` Corneliu ZUZU
2016-06-16 14:10 ` [PATCH 5/7] x86: replace monitor_write_data.do_write with enum Corneliu ZUZU
2016-06-16 14:12 ` [PATCH 6/7] vm-event/arm: move hvm_event_cr->common vm_event_monitor_cr Corneliu ZUZU
2016-06-16 15:16   ` Jan Beulich
2016-06-17  8:25     ` Corneliu ZUZU
2016-06-17  8:38       ` Jan Beulich
2016-06-17 11:31         ` Corneliu ZUZU
2016-06-21  7:08       ` Corneliu ZUZU
2016-06-21  7:20         ` Jan Beulich
2016-06-21 15:22           ` Tamas K Lengyel
2016-06-22  6:33             ` Jan Beulich
2016-06-16 16:55   ` Tamas K Lengyel
2016-06-17 10:37     ` Corneliu ZUZU
2016-06-16 14:13 ` [PATCH 7/7] vm-event/arm: implement support for control-register write vm-events Corneliu ZUZU
2016-06-16 14:26   ` Julien Grall
2016-06-16 19:24     ` Corneliu ZUZU
2016-06-16 21:28       ` Julien Grall
2016-06-17 11:46         ` Corneliu ZUZU
2016-06-16 16:49   ` Julien Grall
2016-06-17 10:36     ` Corneliu ZUZU
2016-06-17 13:18       ` Julien Grall [this message]
2016-06-22 16:35       ` Corneliu ZUZU
2016-06-22 17:17         ` Julien Grall
2016-06-22 18:39           ` Corneliu ZUZU
2016-06-22 19:37             ` Corneliu ZUZU
2016-06-22 19:41               ` Julien Grall
2016-06-23  5:31                 ` Corneliu ZUZU
2016-06-23  5:49                   ` Corneliu ZUZU
2016-06-23 11:11                     ` Julien Grall
2016-06-24  9:32                       ` Corneliu ZUZU
2016-06-23 11:00           ` Julien Grall

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=5763F8C2.60308@arm.com \
    --to=julien.grall@arm.com \
    --cc=czuzu@bitdefender.com \
    --cc=rcojocaru@bitdefender.com \
    --cc=sstabellini@kernel.org \
    --cc=tamas@tklengyel.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).