[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v5 05/12] arm/sve: save/restore SVE context switch


  • To: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Thu, 20 Apr 2023 07:55:01 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZCIp0LNKgmmQzKLmDUIZqNT0jh+9nsp5OHiCSiuEWrQ=; b=mNMBvozis/Zq1lHzxJya3+OcIo2sAHYzZguwABtfIBYS6lOlol1/cgvWCiPC3k7ln2P63Fq8ox0FHYHA9bWmswWa999G9A05g48cfnMCy7sGatRukaqZDfByNQRLS8u8bIz1crfnnyPUqyUCrvTjvToxoHJ+eJDl0DkdapgKcgJBndiq6eCbRJix9b3lF7ZtoYxL42/8/LauJH8DTdiqDcibQRjCuo0FaOq34YMltsdjO+63EOnSsvIXKcYMOmN/y1Wq+DMw6b5b1njZh8exV1CIozhn1IGQwP1RadTxmP2VxgLSyGhzr0Eq2YLPY9+AocvS7ULweb9CqKibiEmnuw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=epQnDpQkMI3NKuoxlF0vI5MDahbIZxIJO+PmjVjUtat7XgHAdTlIV+bZyCOs8lGMOMTYRNLzsOAKbD/JxqExPWm5Zg42f2z36kIkm4VB0gq6cQWOI2L4u3PP59883rURcea65666cb0/c4cSbR149wSLSLGpVBJuYAbpvYImMREGbKldEtjn2hRWRM2NfO5RzS70ib5a+0PfIH732pO01dp4Hv7h96keTDJ9NoR8dnLCK5MdgrAXl4i+mchg0KPmFyDmDgCXGmlluklXyr2M0cMCIFANr5nRHcvxpU/ofb1U+9ft40R0xqeM/yhmsOjNZUPadLsEoD9GRpcxoI9NSA==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Wei Chen <Wei.Chen@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 20 Apr 2023 07:55:15 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHZbSQq1oowf9vRd0a2ZPNGYXQmqK8xC64AgAE14QCAAAESAIABmpCAgAADSgA=
  • Thread-topic: [PATCH v5 05/12] arm/sve: save/restore SVE context switch

Hi Luca,

> On 20 Apr 2023, at 09:43, Luca Fancellu <Luca.Fancellu@xxxxxxx> wrote:
> 
> 
>>>>> +void sve_save_state(struct vcpu *v)
>>>>> +{
>>>>> +    unsigned int sve_vl_bits = sve_decode_vl(v->domain->arch.sve_vl);
>>>>> +    uint64_t *sve_ctx_zreg_end = v->arch.vfp.sve_context +
>>>>> +            (sve_zreg_ctx_size(sve_vl_bits) / sizeof(uint64_t));
>>>> 
>>>> You do quite some computation here for something which does not change
>>>> during the life of the VM.
>>>> Could we save the context_end in the vcpu instead and just do this
>>>> computation on init and free only ?
>>> 
>>> Yes sure, would you be ok to have it in struct vfp_state?
>> 
>> Yes definitely i would store it instead of the current sve_context.
>> 
> 
> Hi Bertrand,
> 
> These are the changes I’m doing to this patch to address your comment, are 
> you ok with them?
> 
> diff --git a/xen/arch/arm/arm64/sve.c b/xen/arch/arm/arm64/sve.c
> index f0eab18dc384..1fef466ba0aa 100644
> --- a/xen/arch/arm/arm64/sve.c
> +++ b/xen/arch/arm/arm64/sve.c
> @@ -91,35 +91,35 @@ int sve_context_init(struct vcpu *v)
>     if ( !ctx )
>         return -ENOMEM;
> 
> -    v->arch.vfp.sve_context = ctx;
> +    /* Point to the end of Z0-Z31 memory, just before FFR memory */
> +    v->arch.vfp.sve_zreg_ctx_end = ctx +
> +        (sve_zreg_ctx_size(sve_vl_bits) / sizeof(uint64_t));
> 
>     return 0;
> }
> 
> void sve_context_free(struct vcpu *v)
> {
> -    XFREE(v->arch.vfp.sve_context);
> +    unsigned int sve_vl_bits = sve_decode_vl(v->domain->arch.sve_vl);
> +
> +    /* Point back to the beginning of Z0-Z31 + FFR memory */
> +    v->arch.vfp.sve_zreg_ctx_end = v->arch.vfp.sve_zreg_ctx_end -
> +        (sve_zreg_ctx_size(sve_vl_bits) / sizeof(uint64_t));

Please use a local variable here instead.

For the rest all good yes, it makes the save/restore code simpler :-)

Thanks
Bertrand

> +
> +    XFREE(v->arch.vfp.sve_zreg_ctx_end);
> }
> 
> void sve_save_state(struct vcpu *v)
> {
> -    unsigned int sve_vl_bits = sve_decode_vl(v->domain->arch.sve_vl);
> -    uint64_t *sve_ctx_zreg_end = v->arch.vfp.sve_context +
> -            (sve_zreg_ctx_size(sve_vl_bits) / sizeof(uint64_t));
> -
>     v->arch.zcr_el1 = READ_SYSREG(ZCR_EL1);
> 
> -    sve_save_ctx(sve_ctx_zreg_end, v->arch.vfp.fpregs, 1);
> +    sve_save_ctx(v->arch.vfp.sve_zreg_ctx_end, v->arch.vfp.fpregs, 1);
> }
> 
> void sve_restore_state(struct vcpu *v)
> {
> -    unsigned int sve_vl_bits = sve_decode_vl(v->domain->arch.sve_vl);
> -    uint64_t *sve_ctx_zreg_end = v->arch.vfp.sve_context +
> -            (sve_zreg_ctx_size(sve_vl_bits) / sizeof(uint64_t));
> -
>     WRITE_SYSREG(v->arch.zcr_el1, ZCR_EL1);
>     WRITE_SYSREG(v->arch.zcr_el2, ZCR_EL2);
> 
> -    sve_load_ctx(sve_ctx_zreg_end, v->arch.vfp.fpregs, 1);
> +    sve_load_ctx(v->arch.vfp.sve_zreg_ctx_end, v->arch.vfp.fpregs, 1);
> }
> diff --git a/xen/arch/arm/include/asm/arm64/vfp.h 
> b/xen/arch/arm/include/asm/arm64/vfp.h
> index 8af714cb8ecc..4aa371e85d26 100644
> --- a/xen/arch/arm/include/asm/arm64/vfp.h
> +++ b/xen/arch/arm/include/asm/arm64/vfp.h
> @@ -13,10 +13,12 @@ struct vfp_state
>      */
>     uint64_t fpregs[64] __vfp_aligned;
>     /*
> -     * When SVE is enabled for the guest, sve_context contains memory to
> -     * save/restore Z0-Z31 registers and FFR.
> +     * When SVE is enabled for the guest, sve_zreg_ctx_end points to memory
> +     * where Z0-Z31 registers and FFR can be saved/restored, it points at the
> +     * end of the Z0-Z31 space and at the beginning of the FFR space, it's 
> done
> +     * like that to ease the save/restore assembly operations.
>      */
> -    uint64_t *sve_context;
> +    uint64_t *sve_zreg_ctx_end;
>     register_t fpcr;
>     register_t fpexc32_el2;
>     register_t fpsr;
> 
> 


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.