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

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


  • To: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 20 Sep 2022 16:54:19 +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=6G3yEysKcWHvEt7Q1nMK+ZOn5DTuf/Y+ezBhyIf1GT8=; b=M3gJ41A18mvAquCflCmdSYGsnUUVXUkvAe+8MNHCduBSzbIBdJj2lrg8bscSvyQ2r5pr4xJvet/+nxLDSvp/ir7RsrTMCnT0LDyZ62LAisASIz3vMPhuVgno8kNq3hJwDU5PLzxJb/AE/DA+0Kt/PcKGIafK/zsrM8kosqmuk8PB8L27SZiLLWsTUuZgtYrIVqh/3Sz5pk1J9ebAFLWhHiH3V4LLiyk5rxRNSHfpAOuGKG8sWbUGUBMuVeUmulLzMg0qDiFhIpnMXOL1e6oaNnzyyZvjZh08Kc5KqZ6oOSt8lT3R+48MgoNpoXrSy4tsJ/WuBdRiNbSoG7vte2qvDA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FN6fe6fZgaoWMS+LJGKZq6J/biEArqyL91s5ZsFf5dRMGW3l9dfFf62CYyYkjo23RDfLCYBosDtWb2XoCsx0UOADZorB5Qb9w18BqThz5uhtj1v0InvkvhmQGkQXagGEna/v8LS5hSdM6/tcZEhQB9C8aXxLop7PaFd4qJ6BABzgBLZtciZMJH7HrkjNVOSMCyduzh2NlJC6JEYElwOM/ItnothEZbdX49kPiVpuKX3Em4IadRNuM2qpuU6xuXtZOpDujOF9RTQ2tBuCqoyoRw5kfQeZzd23k2OoFwcKkQGeKD32bGlBEEMBfItmfMVNWPV2T1V6ZoBHVXtzvheqcQ==
  • 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, Tamas K Lengyel <tamas.lengyel@xxxxxxxxx>, Tamas K Lengyel <tamas.k.lengyel@xxxxxxxxx>
  • Delivery-date: Tue, 20 Sep 2022 14:54:33 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 20.09.2022 16:26, Boris Ostrovsky wrote:
> On 9/20/22 4:01 AM, Jan Beulich wrote:
>> On 20.09.2022 00:42, Boris Ostrovsky wrote:
>>> It is saving vpmu data from current pcpu's MSRs for a remote vcpu so @v
>>> in vmx_find_msr() is not @current:
>>>
>>>        vpmu_load()
>>>            ...
>>>            prev = per_cpu(last_vcpu, pcpu);
>>>            vpmu_save_force(prev)
>>>                core2_vpmu_save()
>>>                    __core2_vpmu_save()
>>>                        vmx_read_guest_msr()
>>>                            vmx_find_msr()
>>>
>>>
>>> The call to vmx_find_msr() was introduced by 755087eb9b10c. I wonder though 
>>> whether
>>> this call is needed when code path above is executed (i.e. when we are 
>>> saving
>>> remove vcpu)
>>
>> How could it not be needed? We need to obtain the guest value. The
>> thing I don't understand is why this forced saving is necessary,
>> when context_switch() unconditionally calls vpmu_switch_from().
> 
> 
> IIRC the logic is:
> 
> 1. vcpuA runs on pcpu0
> 2. vcpuA is de-scheduled and is selected to run on pcpu1. It has not yet 
> called vpmu_load() from pcpu1

The calling of vpmu_load() shouldn't matter here. What does matter is
that vpmu_save() was necessarily called already. Therefore I'm having
trouble seeing why ...

> 3. vcpuB is ready to run on pcpu0, calls vpmu_load()
> 4. vcpuB discovers that pcpu0's MSRs are still holding values from vcpuA
> 5. vcpuB calls vpmu_force_save(vcpuA) which stashes pcpu0's MSRs into vcpuA's 
> vpmu context.

... forced saving would be necessary here. What's necessary at this
point is only the loading of vcpuB's MSR values.

Jan



 


Rackspace

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