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

Re: [PATCH v2] x86/vpmu: Fix race-condition in vpmu_load


  • To: Tamas K Lengyel <tamas.lengyel@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 26 Sep 2022 16:12:05 +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=DSRAV75Y5wCa+r/oerAKcadQ7Kh0D2ALzJ5y9/KYUlY=; b=Pl4RpAOzn2ZYcQSDfuWGE8BxtHLAT2nwxHAL/Qwt2mDaHvUI08VEeFvY0vhoLZhC58S6L4P7JFNTaMgwSiyFG4qUwJXm+yh9WAzkgajH/ylBo7S45amlWsv5v5JrV7nn+/TA+5tNCX7avuCnr7l7uYhOTH9D5eGN1I0CWnOlJhU0fZ0N29zeYKkxChhJTMe7jwQy+3K8yjTvZ+WGoliNXJblJd8CrL1v4pYipmhEZCujDP1XprF+L20Rav/uPzKu9ObYAjYLS/rLw0YczE2ZynRXHeH+adBDineiRQoyztJl34vHSyLTUaiaSyuATM7wnSBmgeSygcvAN73TUu3Zhg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SGjedAt5LvOUbUoZZWL1nrjqk1q/xovloSOD3YVRp/eVa64ydm0p8S+Z5SrVDvQLLaNndV+EsI12LntULKzJ9aSdUPvkgLp1RjjBUG5d0Vm/5S12bgMC5M2bSgJjWC0rcOtUzoiD57sMqdTFRhEJntCqrKKV/FeOz42VBZ2kjTwLg4J8L42gC1Q8WrQoh7npX+mv9IyXYN8Ozks+hSJZX7fyBkPXTit8+I51fKjD8e8Spauk1vXdLS6NiZjmrl4QFcawdRuBLyrAQyqcyrv4robe7XRtmZWyG/+CTZLLHReCaxKg1FOibuTjlzebq982OVSCk3uuj+Nlm02qwfGdyA==
  • 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>, xen-devel@xxxxxxxxxxxxxxxxxxxx, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
  • Delivery-date: Mon, 26 Sep 2022 14:12:11 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 22.09.2022 22:48, Tamas K Lengyel wrote:
> --- a/xen/arch/x86/cpu/vpmu.c
> +++ b/xen/arch/x86/cpu/vpmu.c
> @@ -376,57 +376,24 @@ void vpmu_save(struct vcpu *v)
>      vpmu->last_pcpu = pcpu;
>      per_cpu(last_vcpu, pcpu) = v;
>  
> +    vpmu_set(vpmu, VPMU_CONTEXT_SAVE);
> +
>      if ( alternative_call(vpmu_ops.arch_vpmu_save, v, 0) )
>          vpmu_reset(vpmu, VPMU_CONTEXT_LOADED);
>  
> +    vpmu_reset(vpmu, VPMU_CONTEXT_SAVE);
> +
>      apic_write(APIC_LVTPC, PMU_APIC_VECTOR | APIC_LVT_MASKED);
>  }
>  
>  int vpmu_load(struct vcpu *v, bool_t from_guest)
>  {
>      struct vpmu_struct *vpmu = vcpu_vpmu(v);
> -    int pcpu = smp_processor_id(), ret;
> -    struct vcpu *prev = NULL;
> +    int ret;
>  
>      if ( !vpmu_is_set(vpmu, VPMU_CONTEXT_ALLOCATED) )
>          return 0;
>  
> -    /* First time this VCPU is running here */
> -    if ( vpmu->last_pcpu != pcpu )
> -    {
> -        /*
> -         * Get the context from last pcpu that we ran on. Note that if 
> another
> -         * VCPU is running there it must have saved this VPCU's context 
> before
> -         * startig to run (see below).
> -         * There should be no race since remote pcpu will disable interrupts
> -         * before saving the context.
> -         */
> -        if ( vpmu_is_set(vpmu, VPMU_CONTEXT_LOADED) )
> -        {
> -            on_selected_cpus(cpumask_of(vpmu->last_pcpu),
> -                             vpmu_save_force, (void *)v, 1);
> -            vpmu_reset(vpmu, VPMU_CONTEXT_LOADED);
> -        }
> -    } 
> -
> -    /* Prevent forced context save from remote CPU */
> -    local_irq_disable();
> -
> -    prev = per_cpu(last_vcpu, pcpu);
> -
> -    if ( prev != v && prev )
> -    {
> -        vpmu = vcpu_vpmu(prev);
> -
> -        /* Someone ran here before us */
> -        vpmu_save_force(prev);
> -        vpmu_reset(vpmu, VPMU_CONTEXT_LOADED);
> -
> -        vpmu = vcpu_vpmu(v);
> -    }
> -
> -    local_irq_enable();
> -
>      /* Only when PMU is counting, we load PMU context immediately. */
>      if ( !vpmu_is_set(vpmu, VPMU_RUNNING) ||
>           (!has_vlapic(vpmu_vcpu(vpmu)->domain) &&

What about the other two uses of vpmu_save_force() in this file? I looks
to me as if only the use in mem_sharing.c needs to be retained.

Also, going forward, please Cc Boris right on new iterations of this fix
(if any; I'm not going to exclude I'm wrong with the above and all is
fine with this version).

Jan



 


Rackspace

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