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

Re: [PATCH v2] x86/mem_sharing: support forks with active vPMU state


  • To: Tamas K Lengyel <tamas.lengyel@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 21 Jul 2022 12:19:22 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=BYQPAfY154PcZSxi7JMTTG068QuW44x+WnKsxhbnoKg=; b=MaxoEOIc/KAnrGf0EzI+Yv6ip3YPLdpMYHQ+tcvc6B+meSkYRPDQ9KXlbdinNKH9NkcZjfk5V1FMaMIr7T+f5qoZJNzmpQaHuf5Hg3KZp0fG4axLO73h9/jZd5RnX1A/Cbk6qpInDWwttKyS49iNCKVQ4PRJxdlhCnUKP8TIvQsc1bzM+8CydYrrmL1raD4jnu07eS4Sj7wl+wRGEH8gHD/7VNFFdWBQUnSDWTDoFEMPESfeqP/NTLthbnBNcsgcl72Stzb6/cWi9guQYdIoV0YXbRguilm7kZO7dZkGJieWBUIqFo+az2SqGCRKIJq7jZivgqht87/q91MgPeJWXQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ntljw+vnOapobpr/a6k3U0KLx2ud1n0qRjZv8Q28JFNg+HMUrHhowSLmohlIHlYTbQfWYtAdm/cu9TODAfmjhy4wb2ZFiy/nU+KpcPy4LO282r9+IBjjcmRu1047ZUheDD0HoExSFslIuEbRjoCX3rPkXo6QgqWhHHBySuiqn+PE7JGOrwIjgtwdD1l0qe/cMLISXgAchbsIuhJgbhvSsz1tPSF6e/KW0mGaXJ4/K/2kkR2D3NQO9IwZptXUfv/0wqkyv6Obmof18eljBmOnhd/N6gq47Pu7Ovw/XOZCJaAnfZlgBohQHuXxSpUz0BhXh6HlYoiZbAiV3TB2DnTMQQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Jun Nakajima <jun.nakajima@xxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>, Tamas K Lengyel <tamas@xxxxxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 21 Jul 2022 10:19:36 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 20.07.2022 20:47, Tamas K Lengyel wrote:
> --- a/xen/arch/x86/mm/mem_sharing.c
> +++ b/xen/arch/x86/mm/mem_sharing.c
> @@ -1653,6 +1653,46 @@ static void copy_vcpu_nonreg_state(struct vcpu 
> *d_vcpu, struct vcpu *cd_vcpu)
>      hvm_set_nonreg_state(cd_vcpu, &nrs);
>  }
>  
> +static int copy_vpmu(struct vcpu *d_vcpu, struct vcpu *cd_vcpu)
> +{
> +    struct vpmu_struct *d_vpmu = vcpu_vpmu(d_vcpu);
> +    struct vpmu_struct *cd_vpmu = vcpu_vpmu(cd_vcpu);

I would hope two of the four pointers could actually be constified.

> +    if ( !vpmu_are_all_set(d_vpmu, VPMU_INITIALIZED | 
> VPMU_CONTEXT_ALLOCATED) )
> +        return 0;
> +    if ( vpmu_allocate_context(cd_vcpu) )
> +        return -ENOMEM;

The function supplies an error code - please use it rather than
assuming it's always going to be -ENOMEM. Alternatively make the
function return bool. (Ideally the hook functions themselves would
be well-formed in this regard, but I realize that the Intel one is
pre-existing in its present undesirable shape.)

> +    /*
> +     * The VPMU subsystem only saves the context when the CPU does a context
> +     * switch. Otherwise, the relevant MSRs are not saved on vmexit.
> +     * We force a save here in case the parent CPU context is still loaded.
> +     */
> +    if ( vpmu_is_set(d_vpmu, VPMU_CONTEXT_LOADED) )
> +    {
> +        int pcpu = smp_processor_id();

unsigned int please.

> +        if ( d_vpmu->last_pcpu != pcpu )
> +        {
> +            on_selected_cpus(cpumask_of(d_vpmu->last_pcpu),
> +                             vpmu_save_force, (void *)d_vcpu, 1);

No need for the cast afaict.

> +            vpmu_reset(d_vpmu, VPMU_CONTEXT_LOADED);
> +        } else

Nit: Style.

> +            vpmu_save(d_vcpu);
> +    }
> +
> +    if ( vpmu_is_set(d_vpmu, VPMU_RUNNING) )
> +        vpmu_set(cd_vpmu, VPMU_RUNNING);
> +
> +    /* Make sure context gets (re-)loaded when scheduled next */
> +    vpmu_reset(cd_vpmu, VPMU_CONTEXT_LOADED);
> +
> +    memcpy(cd_vpmu->context, d_vpmu->context, d_vpmu->context_size);
> +    memcpy(cd_vpmu->priv_context, d_vpmu->priv_context, 
> d_vpmu->priv_context_size);

Nit: Long line.

Jan



 


Rackspace

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